version:2.2.6

update:
fix:在线状态更新
add:增加清除极光别名过多
This commit is contained in:
tt committed 2021-09-17 18:26:42 +08:00
1 parent a318e07db9
commit 0c27e60b29
33 files changed
+1189 -488

No files matched your search

@@ -19,6 +19,7 @@ import androidx.appcompat.app.AppCompatActivity;
import com.mjsheng.myappstore.BuildConfig;
import com.mjsheng.myappstore.R;
import com.lzy.okgo.model.HttpHeaders;
import com.mjsheng.myappstore.base.BaseApplication;
import com.mjsheng.myappstore.service.LogcatService;
import com.mjsheng.myappstore.utils.JGYUtils;
import com.mjsheng.myappstore.utils.Logutils;
@@ -80,26 +81,26 @@ public class HomeActivity extends AppCompatActivity {
// Utils.getHardware(this);
// setWebView();
// hideStatusBar();
Logutils.e(TAG, "DebugTest: " + HttpHeaders.getUserAgent());
Logutils.i(TAG, "DebugTest: " + HttpHeaders.getUserAgent());
// boolean qch_force_app = Settings.System.putString(getContentResolver(), "qch_launcher_icon_app", "");
Logutils.e(TAG, "DebugTest: qch_launcher_icon_app:" + Settings.System.getString(getContentResolver(), "qch_launcher_icon_app"));
Logutils.e(TAG, "DebugTest: qch_hide_NavigationBar: " + Settings.System.getString(getContentResolver(), "qch_hide_NavigationBar"));
Logutils.i(TAG, "DebugTest: qch_launcher_icon_app:" + Settings.System.getString(getContentResolver(), "qch_launcher_icon_app"));
Logutils.i(TAG, "DebugTest: qch_hide_NavigationBar: " + Settings.System.getString(getContentResolver(), "qch_hide_NavigationBar"));
String only_jgy_shortcut_list = Settings.System.getString(getContentResolver(), "only_jgy_shortcut_list");
Logutils.e(TAG, "debugTest: only_jgy_shortcut_list:" + only_jgy_shortcut_list);
Logutils.i(TAG, "debugTest: only_jgy_shortcut_list:" + only_jgy_shortcut_list);
String qch_app_forbid = Settings.System.getString(getContentResolver(), "qch_app_forbid");
Logutils.e(TAG, "debugTest: qch_app_forbid:" + qch_app_forbid);
Logutils.e(TAG, "debugTest: ip = " + JGYUtils.getInstance().getIPAddress());
Log.e(TAG, "debugTest: getPackage = " + Utils.getPackage());
Log.e(TAG, "debugTest: getMacAddress = " + Utils.getAndroid10MAC(this));
// Log.e(TAG, "debugTest: iptables = " + CmdUtil.execute("iptables -L -n" ).toString());
Logutils.i(TAG, "debugTest: qch_app_forbid:" + qch_app_forbid);
Logutils.i(TAG, "debugTest: ip = " + JGYUtils.getInstance().getIPAddress());
Logutils.i(TAG, "debugTest: getPackage = " + Utils.getPackage());
Logutils.i(TAG, "debugTest: getMacAddress = " + Utils.getAndroid10MAC(this));
// Logutils.i(TAG, "debugTest: iptables = " + CmdUtil.execute("iptables -L -n" ).toString());
Log.e(TAG, "debugTest: " + Utils.getAndroid10MAC(this));
Log.e(TAG, "debugTest: " + JPushInterface.getRegistrationID(this));
Log.e(TAG, "debugTest: " + Utils.getCustomVersion());
Log.e(TAG, "debugTest: " + BuildConfig.VERSION_NAME);
Log.e(TAG, "debugTest: " + Utils.getAPPVersionName(this));
Log.e(TAG, "debugTest: " + Utils.getAndroid7MAC());
Log.e(TAG, "debugTest: launcher3 " + JGYUtils.getInstance().getStartClassName("com.android.launcher3"));
Logutils.i(TAG, "debugTest: " + Utils.getAndroid10MAC(this));
Logutils.i(TAG, "debugTest: " + JPushInterface.getRegistrationID(this));
Logutils.i(TAG, "debugTest: " + Utils.getCustomVersion());
Logutils.i(TAG, "debugTest: " + BuildConfig.VERSION_NAME);
Logutils.i(TAG, "debugTest: " + Utils.getAPPVersionName(this));
Logutils.i(TAG, "debugTest: " + Utils.getAndroid7MAC());
Logutils.i(TAG, "debugTest: launcher3 " + JGYUtils.getInstance().getStartClassName("com.android.launcher3"));
// try {
// new CacheUtils().cleanApplicationUserData(HomeActivity.this, "com.android.launcher3");
// } catch (Exception e) {
@@ -108,6 +109,8 @@ public class HomeActivity extends AppCompatActivity {
// }
// ActivityManager mAm = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
// mAm.killBackgroundProcesses("com.android.documentsui");
BaseApplication.cleanJpushAlias();
BaseApplication.cleanJpushTag();
}
private void testRxhttp() {
@@ -17,6 +17,7 @@ import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.blankj.utilcode.util.NetworkUtils;
@@ -70,17 +71,17 @@ public class MainActivity extends BaseActivity implements MainContact.MainView,
@BindView(R.id.chkupd)
Button bt_checkupdate;
@BindView(R.id.checkupdate)
RelativeLayout checkupdate;
ConstraintLayout checkupdate;
@BindView(R.id.back)
ImageView back;
@BindView(R.id.locked)
ImageView iv_locked;
@BindView(R.id.layout_class)
RelativeLayout layout_class;
ConstraintLayout layout_class;
@BindView(R.id.layout_number)
RelativeLayout layout_number;
ConstraintLayout layout_number;
@BindView(R.id.layout_name)
RelativeLayout layout_name;
ConstraintLayout layout_name;
@BindView(R.id.tv_customversion)
TextView tv_customversion;
@@ -108,6 +109,8 @@ public class MainActivity extends BaseActivity implements MainContact.MainView,
ButterKnife.bind(this);
mPresenter = new MainPresenter(this);
mPresenter.attachView(this);
mPresenter.setProvider(this);
JGYUtils.startServices(MainActivity.this);
Logutils.e(TAG, "initView: " + "start request");
mPresenter.getFirstConnect();
getDevicesInfo();
@@ -170,9 +173,11 @@ public class MainActivity extends BaseActivity implements MainContact.MainView,
public void initData() {
JPushInterface.init(this);
registerMessageReceiver();
Logutils.e("getMacAddress", Utils.getAndroid10MAC(this));
Logutils.e("getMacAddress", Utils.getAndroid10MAC(this));
timeMillis = SystemClock.elapsedRealtime();
startService(new Intent(MainActivity.this, MainService.class));
mPresenter.getLockedState();
mPresenter.getStudesInfo();
}
@Override
@@ -452,14 +457,13 @@ public class MainActivity extends BaseActivity implements MainContact.MainView,
protected void onResume() {
super.onResume();
isForeground = true;
mPresenter.getStudesInfo();
}
@Override
protected void onDestroy() {
super.onDestroy();
mPresenter.detachView();
startService(new Intent(MainActivity.this, MainService.class));
JGYUtils.startServices(MainActivity.this);
}
@Override
@@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.SystemClock;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
@@ -43,6 +44,8 @@ import com.mjsheng.myappstore.utils.TimeUtils;
import com.mjsheng.myappstore.utils.ToastUtil;
import com.mjsheng.myappstore.utils.URLUtils;
import com.mjsheng.myappstore.utils.Utils;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;
import java.io.IOException;
import java.lang.reflect.Type;
@@ -76,6 +79,16 @@ public class MainPresenter implements MainContact.Presenter {
private final String DEFAULT_INFO = "暂无信息";
private final int OK = 200;
private LifecycleProvider<ActivityEvent> provider;
public void setProvider(LifecycleProvider<ActivityEvent> provider) {
this.provider = provider;
}
public LifecycleProvider<ActivityEvent> getProvider() {
return provider;
}
public MainPresenter(Context context) {
this.mContext = context;
Logutils.e(TAG, "MainPresenter: " + context.getClass());
@@ -119,6 +132,7 @@ public class MainPresenter implements MainContact.Presenter {
setState();
NetInterfaceManager.getInstance()
.getStudesInfoObservable()
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse<StudentsInfo>>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@@ -220,10 +234,17 @@ public class MainPresenter implements MainContact.Presenter {
}
}
private long lastgetLockedTime;
@Override
public void getLockedState() {
// if (System.currentTimeMillis() - lastgetLockedTime < 600 * 1000) {
// return;
// }
// lastgetLockedTime = System.currentTimeMillis();
NetInterfaceManager.getInstance()
.getDevicesLockedStateObservable()
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@@ -272,6 +293,7 @@ public class MainPresenter implements MainContact.Presenter {
Logutils.e(TAG + ":" + "getLockedState", "onComplete: ");
}
});
// lastgetLockedTime = System.currentTimeMillis();
}
/**
@@ -292,11 +314,24 @@ public class MainPresenter implements MainContact.Presenter {
}
private long lastSendMACTime;
@Override
public void sendMACAddress() {
if (System.currentTimeMillis() - lastSendMACTime < 60 * 60 * 1000) {
mView.sendMACFinished();
return;
}
lastSendMACTime = System.currentTimeMillis();
String macJson = (String) SPUtils.get(mContext, "macJson", "");
if (macJson.equals(JGYUtils.getInstance().getMacJson())) {
mView.sendMACFinished();
return;
}
NetInterfaceManager.getInstance()
.sendMACAddressObservable()
.observeOn(Schedulers.io())
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@@ -307,6 +342,7 @@ public class MainPresenter implements MainContact.Presenter {
public void onNext(@NonNull BaseResponse response) {
if (response.code == OK) {
Logutils.e(TAG + ":" + "sendMACAddress", response.msg);
SPUtils.put(mContext, "macJson", JGYUtils.getInstance().getMacJson());
} else {
Logutils.e(TAG + ":" + "sendMACAddress", response.toString());
}
@@ -321,6 +357,7 @@ public class MainPresenter implements MainContact.Presenter {
@Override
public void onComplete() {
Logutils.e(TAG + ":" + "sendMACAddress", "onComplete: ");
lastSendMACTime = System.currentTimeMillis();
mView.sendMACFinished();
}
});
@@ -359,6 +396,7 @@ public class MainPresenter implements MainContact.Presenter {
add)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<ResponseBody>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@@ -396,6 +434,7 @@ public class MainPresenter implements MainContact.Presenter {
}
NetInterfaceManager.getInstance()
.getSnTimeObservable()
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@@ -443,7 +482,9 @@ public class MainPresenter implements MainContact.Presenter {
@Override
public void getEBagCode() {
NetInterfaceManager.getInstance().getEBagCodeControl()
NetInterfaceManager.getInstance()
.getEBagCodeControl()
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(Disposable d) {
@@ -502,6 +543,7 @@ public class MainPresenter implements MainContact.Presenter {
public void setJpushTags() {
NetInterfaceManager.getInstance()
.getJpushTagsObservable()
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@@ -579,6 +621,7 @@ public class MainPresenter implements MainContact.Presenter {
JGYUtils.getInstance().checkAppPlatform())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@@ -620,6 +663,7 @@ public class MainPresenter implements MainContact.Presenter {
JGYUtils.getInstance().checkAppPlatform())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@@ -655,8 +699,8 @@ public class MainPresenter implements MainContact.Presenter {
@Override
public void buttonCheckUpdate(View view) {
// if ((SystemClock.elapsedRealtime() - buttonCheckUpdateTime) < 10000) {
// buttonCheckUpdateTime = SystemClock.elapsedRealtime();
// if ((System.currentTimeMillis() - buttonCheckUpdateTime) < 10000) {
// buttonCheckUpdateTime = System.currentTimeMillis();
// ToastUtil.show("正在检查更新");
// } else {
// ToastUtil.show("你已经过检查,请稍后再来");
@@ -671,6 +715,7 @@ public class MainPresenter implements MainContact.Presenter {
JGYUtils.getInstance().checkAppPlatform())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@@ -720,6 +765,7 @@ public class MainPresenter implements MainContact.Presenter {
public void checkTestUpdate() {
NetInterfaceManager.getInstance()
.getTestUpdateObservable()
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse<List<ForceDownloadData>>>() {
@Override
public void onSubscribe(Disposable d) {
@@ -764,6 +810,7 @@ public class MainPresenter implements MainContact.Presenter {
public void getAppLimit() {
NetInterfaceManager.getInstance()
.getAppLimitObservable()
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<ResponseBody>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@@ -878,6 +925,7 @@ public class MainPresenter implements MainContact.Presenter {
public void getForceDownload() {
NetInterfaceManager.getInstance()
.getForceDownloadObservable()
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<ForceDownloadBean>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@@ -939,59 +987,59 @@ public class MainPresenter implements MainContact.Presenter {
@Override
public void getBrowserList() {
// NetInterfaceManager.getInstance()
// .getBrowserListSettingObservable()
// .observeOn(Schedulers.io())
// .subscribe(new Observer<BaseResponse<BrowserData>>() {
// @Override
// public void onSubscribe(@NonNull Disposable d) {
// Logutils.e(TAG + ":" + "getBrowserList", "onSubscribe: ");
// }
//
// @Override
// public void onNext(@NonNull BaseResponse<BrowserData> browserDataBaseResponse) {
// Logutils.e(TAG + ":" + "getBrowserList", "onNext: ");
// if (browserDataBaseResponse.code == OK) {
// String white = browserDataBaseResponse.data.getWhite();
//
// if (!TextUtils.isEmpty(white)) {
// String homePage = Settings.System.getString(mContext.getContentResolver(), "homepagURL");
// if (!TextUtils.isEmpty(homePage) && !white.contains(homePage)) {
// white += "," + homePage;
// }
// boolean whiteList = Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", white);
// Logutils.e(TAG + ":" + "getBrowserList", "setBrowserList white: " + white + ":" + whiteList);
// mView.getBrowserListFinished(white);
// } else {
// Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", " ");
// mView.getBrowserListFinished("");
// }
// String black = browserDataBaseResponse.data.getBlack();
// if (!TextUtils.isEmpty(black)) {
// boolean blackList = Settings.System.putString(mContext.getContentResolver(), "qch_webblack_url", black);
// Logutils.e(TAG + ":" + "getBrowserList", "setBrowserList black: " + black + ":" + blackList);
// } else {
// Settings.System.putString(mContext.getContentResolver(), "qch_webblack_url", " ");
// }
// } else {
// mView.getBrowserListFinished("");
// }
// }
//
// @Override
// public void onError(@NonNull Throwable e) {
// Logutils.e(TAG + ":" + "getBrowserList", "onError: " + e.getMessage());
// String whiteURLList = Settings.System.getString(mContext.getContentResolver(), "DeselectBrowserArray");
// Logutils.e(TAG + ":" + "getBrowserList", "whiteURLList: " + whiteURLList);
// mView.getBrowserListFinished(whiteURLList);
// onComplete();
// }
//
// @Override
// public void onComplete() {
// Logutils.e(TAG + ":" + "getBrowserList", "onComplete: ");
// }
// });
//获取书签后会获取黑白名单
//// .getBrowserListSettingObservable()
//// .observeOn(Schedulers.io())
//// .subscribe(new Observer<BaseResponse<BrowserData>>() {
//// @Override
//// public void onSubscribe(@NonNull Disposable d) {
//// Logutils.e(TAG + ":" + "getBrowserList", "onSubscribe: ");
//// }
////
//// @Override
//// public void onNext(@NonNull BaseResponse<BrowserData> browserDataBaseResponse) {
//// Logutils.e(TAG + ":" + "getBrowserList", "onNext: ");
//// if (browserDataBaseResponse.code == OK) {
//// String white = browserDataBaseResponse.data.getWhite();
////
//// if (!TextUtils.isEmpty(white)) {
//// String homePage = Settings.System.getString(mContext.getContentResolver(), "homepagURL");
//// if (!TextUtils.isEmpty(homePage) && !white.contains(homePage)) {
//// white += "," + homePage;
//// }
//// boolean whiteList = Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", white);
//// Logutils.e(TAG + ":" + "getBrowserList", "setBrowserList white: " + white + ":" + whiteList);
//// mView.getBrowserListFinished(white);
//// } else {
//// Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", " ");
//// mView.getBrowserListFinished("");
//// }
//// String black = browserDataBaseResponse.data.getBlack();
//// if (!TextUtils.isEmpty(black)) {
//// boolean blackList = Settings.System.putString(mContext.getContentResolver(), "qch_webblack_url", black);
//// Logutils.e(TAG + ":" + "getBrowserList", "setBrowserList black: " + black + ":" + blackList);
//// } else {
//// Settings.System.putString(mContext.getContentResolver(), "qch_webblack_url", " ");
//// }
//// } else {
//// mView.getBrowserListFinished("");
//// }
//// }
////
//// @Override
//// public void onError(@NonNull Throwable e) {
//// Logutils.e(TAG + ":" + "getBrowserList", "onError: " + e.getMessage());
//// String whiteURLList = Settings.System.getString(mContext.getContentResolver(), "DeselectBrowserArray");
//// Logutils.e(TAG + ":" + "getBrowserList", "whiteURLList: " + whiteURLList);
//// mView.getBrowserListFinished(whiteURLList);
//// onComplete();
//// }
////
//// @Override
//// public void onComplete() {
//// Logutils.e(TAG + ":" + "getBrowserList", "onComplete: ");
//// }
//// });
// //获取书签后会获取黑白名单
Log.e(TAG, "getBrowserList: ");
mView.getBrowserListFinished("");
}
@@ -1000,6 +1048,7 @@ public class MainPresenter implements MainContact.Presenter {
NetInterfaceManager.getInstance()
.getBrowserListSettingObservable()
.observeOn(Schedulers.io())
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse<BrowserData>>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@@ -1061,6 +1110,7 @@ public class MainPresenter implements MainContact.Presenter {
NetInterfaceManager.getInstance()
.getBrowserListSettingObservable()
.observeOn(Schedulers.io())
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse<BrowserData>>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@@ -1223,14 +1273,25 @@ public class MainPresenter implements MainContact.Presenter {
@Override
public void onComplete() {
Logutils.e(TAG + ":" + "getBrowserBookmarks", "onComplete: ");
mView.getBrowserBookmarksFinished();
// String homepagURL = Settings.System.getString(mContext.getContentResolver(), "homepagURL");
// HashSet<String> hashSet = new HashSet<>(Arrays.asList(whitelist.split(",")));
// hashSet.add(homepagURL);
// String DeselectBrowserArray = String.join(",", hashSet);
// if (Utils.isEmpty(DeselectBrowserArray)) {
// Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", " ");
// } else {
// Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", DeselectBrowserArray);
// }
if (mView != null) {
mView.getBrowserBookmarksFinished();
}
}
});
}
@Override
public void getBrowserWhiteList() {
new URLUtils(mContext).setBrowserWhiteList();
// new URLUtils(mContext).setBrowserWhiteList();
new URLUtils(mContext).setBrowserBlackList();
// try {
@@ -1252,6 +1313,7 @@ public class MainPresenter implements MainContact.Presenter {
NetInterfaceManager.getInstance()
.getDesktopIconObservable()
.observeOn(Schedulers.io())
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@@ -1313,6 +1375,7 @@ public class MainPresenter implements MainContact.Presenter {
.getAppAutoStartUpdateAndNetObservable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<NetAndLaunchBean>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@@ -1348,6 +1411,7 @@ public class MainPresenter implements MainContact.Presenter {
NetInterfaceManager.getInstance()
.getAppIDControlObservable()
.observeOn(Schedulers.io())
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<ResponseBody>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@@ -1402,7 +1466,9 @@ public class MainPresenter implements MainContact.Presenter {
@Override
public void onComplete() {
Log.e(TAG, "setAppinsideWeb: " + "onComplete");
mView.setAppinsideWebFinished();
if (mView != null) {
mView.setAppinsideWebFinished();
}
}
});
}
@@ -1413,6 +1479,7 @@ public class MainPresenter implements MainContact.Presenter {
NetInterfaceManager.getInstance()
.getSystemSettingObservable()
.observeOn(Schedulers.io())
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<ResponseBody>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@@ -1469,6 +1536,7 @@ public class MainPresenter implements MainContact.Presenter {
public void getDefaultApp() {
NetInterfaceManager.getInstance()
.getDefaultAppApi()
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse<DefaultApp>>() {
@Override
public void onSubscribe(Disposable d) {
@@ -1482,6 +1550,9 @@ public class MainPresenter implements MainContact.Presenter {
if (code == OK) {
DefaultApp defaultApp = defaultAppBaseResponse.data;
JGYUtils.getInstance().setDefaultDesktop(defaultApp.getDefault_launcher());
if (defaultApp.getDefault_launcher() != null) {
SPUtils.put(mContext, "default_launcher", defaultApp.getDefault_launcher());
}
} else {
Log.e("getDefaultApp", "onNext: " + defaultAppBaseResponse.msg);
}
@@ -1509,6 +1580,7 @@ public class MainPresenter implements MainContact.Presenter {
.getROMApp(NetInterfaceManager.HTTP_KEY, customVersion)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(Disposable d) {
@@ -1545,7 +1617,9 @@ public class MainPresenter implements MainContact.Presenter {
@Override
public void getDeveloper() {
NetInterfaceManager.getInstance().getDeveloperControl()
NetInterfaceManager.getInstance()
.getDeveloperControl()
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(Disposable d) {
@@ -1592,6 +1666,7 @@ public class MainPresenter implements MainContact.Presenter {
}
NetInterfaceManager.getInstance()
.getLogoImgObservable()
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse<LogoImg>>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@@ -1638,7 +1713,9 @@ public class MainPresenter implements MainContact.Presenter {
mView.setTopAppFinished();
return;
}
NetInterfaceManager.getInstance().getTopAppControl()
NetInterfaceManager.getInstance()
.getTopAppControl()
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(Disposable d) {
@@ -1651,9 +1728,11 @@ public class MainPresenter implements MainContact.Presenter {
if (response.code == OK) {
JSONObject jsonObject = (JSONObject) JSON.toJSON(response.data);
String app_package = jsonObject.getString("app_package");
ForegroundAppUtil.setTopAppClass(mContext, app_package);
SPUtils.put(mContext, ForegroundAppUtil.TOPAPP_KEY, app_package);
ForegroundAppUtil.openTopApp(mContext);
} else {
ForegroundAppUtil.setTopAppClass(mContext, "");
SPUtils.put(mContext, ForegroundAppUtil.TOPAPP_KEY, "");
}
}
@@ -1673,8 +1752,16 @@ public class MainPresenter implements MainContact.Presenter {
});
}
//上次运行的时间
private long lastRunTime;
@Override
synchronized public void getScreenLockState() {
if (System.currentTimeMillis() - lastRunTime < 60 * 1000) {
Log.e(TAG, "getScreenLockState: " + lastRunTime);
return;
}
lastRunTime = System.currentTimeMillis();
int locked = Settings.System.getInt(mContext.getContentResolver(), "qch_unlock_ipad", 0);
if (JGYUtils.isOfficialVersion() || locked == 1) {
mView.setScreenLockStateFinished(false, "");
@@ -1682,6 +1769,7 @@ public class MainPresenter implements MainContact.Presenter {
}
NetInterfaceManager.getInstance()
.getScreenLockObservable()
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@@ -1706,11 +1794,15 @@ public class MainPresenter implements MainContact.Presenter {
@Override
public void onError(@NonNull Throwable e) {
Logutils.e(TAG + ":" + "getScreenLockState", "onError: " + e.getMessage());
boolean is_screen_lock = (boolean) SPUtils.get(mContext, "is_screen_lock", false);
String screen_tips = (String) SPUtils.get(mContext, "screen_tips", "");
mView.setScreenLockStateFinished(is_screen_lock, screen_tips);
onComplete();
}
@Override
public void onComplete() {
lastRunTime = System.currentTimeMillis();
Logutils.e(TAG + ":" + "getScreenLockState", "onComplete: ");
}
});
@@ -1725,6 +1817,7 @@ public class MainPresenter implements MainContact.Presenter {
}
NetInterfaceManager.getInstance()
.getDesktopObservable()
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<ResponseBody>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@@ -1742,10 +1835,18 @@ public class MainPresenter implements MainContact.Presenter {
JGYUtils.getInstance().installDesktop(data);
} else {
Logutils.e(TAG + ":" + "getDefaultDesktop", "onNext: " + "删除定制桌面");
ApkUtils.UninstallAPP(mContext, ApkUtils.desktopAPP.get(0));
ApkUtils.UninstallAPP(mContext, ApkUtils.desktopAPP.get(1));
String whiteList = Settings.System.getString(mContext.getContentResolver(), "only_jgy_shortcut_list");
if (!TextUtils.isEmpty(whiteList)) {
if (!whiteList.contains(ApkUtils.desktopAPP.get(0))) {
ApkUtils.UninstallAPP(mContext, ApkUtils.desktopAPP.get(0));
Log.e(TAG + ":" + "getDefaultDesktop", "skip: " + ApkUtils.desktopAPP.get(0));
}
if (!whiteList.contains(ApkUtils.desktopAPP.get(1))) {
ApkUtils.UninstallAPP(mContext, ApkUtils.desktopAPP.get(1));
Log.e(TAG + ":" + "getDefaultDesktop", "skip: " + ApkUtils.desktopAPP.get(1));
}
}
}
} catch (IOException e) {
e.printStackTrace();
Logutils.e(TAG + ":" + "getDefaultDesktop", "onNext: IOException: " + e.getMessage());
@@ -1761,7 +1862,7 @@ public class MainPresenter implements MainContact.Presenter {
@Override
public void onComplete() {
Logutils.e(TAG + ":" + "getDefaultDesktop", "onComplete: ");
HTTPInterface.getAllAppList();
HTTPInterface.getAllAppList(mContext);
mView.getDefaultDesktopFinished();
}
});
@@ -3,9 +3,10 @@ package com.mjsheng.myappstore.base;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public abstract class BaseActivity extends AppCompatActivity {
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;
public abstract class BaseActivity extends RxAppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -4,6 +4,7 @@ import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.Process;
import android.util.Log;
import androidx.multidex.MultiDexApplication;
@@ -34,6 +35,9 @@ import com.mjsheng.myappstore.utils.ToastUtil;
import com.mjsheng.myappstore.utils.Utils;
import com.mjsheng.myappstore.utils.XAPKUtils;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -47,6 +51,9 @@ import io.reactivex.ObservableOnSubscribe;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
/**
@@ -149,11 +156,6 @@ public class BaseApplication extends MultiDexApplication {
HTTPInterface.setJpushTags(context);
}
synchronized public static void clean() {
//alias的绑定的设备超过10个,但是alias应该是一个设备对应一个,在重置设备后jpush的regid会变动,所以需要清除
//https://docs.jiguang.cn/jpush/server/push/rest_api_v3_device/#_5
HTTPInterface.cleanJpushAlias(Utils.getSerial());
}
private static void initAliasObservable() {
Logutils.e(TAG, "initAliasObservable: ");
@@ -168,7 +170,7 @@ public class BaseApplication extends MultiDexApplication {
}
};
}
}).throttleLast(30, TimeUnit.SECONDS)
}).throttleLast(1, TimeUnit.HOURS)
.subscribe(new Observer<Integer>() {
@Override
public void onSubscribe(Disposable d) {
@@ -216,7 +218,7 @@ public class BaseApplication extends MultiDexApplication {
case 6017:
case 6027:
Logutils.e("jiguangInterface", s + "别名绑定的设备数超过限制");
clean();
cleanJpushAlias();
setJpushAlias();
break;
default:
@@ -237,6 +239,52 @@ public class BaseApplication extends MultiDexApplication {
});
}
synchronized public static void cleanJpushAlias() {
//alias的绑定的设备超过10个,但是alias应该是一个设备对应一个,在重置设备后jpush的regid会变动,所以需要清除
//https://docs.jiguang.cn/jpush/server/push/rest_api_v3_device/#_5
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(URLAddress.DELETE_JPUSH_ALIAS + Utils.getSerial())
.header("Authorization", JGYUtils.getAuthorization())
.delete()
.build();
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
Log.e("cleanJpushAlias", "onFailure: " + e.getMessage());
}
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
Log.e("cleanJpushAlias", "onResponse: " + response.toString());
Log.e(TAG, "onResponse: "+"清除Alias成功" );
}
});
}
synchronized public static void cleanJpushTag() {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(URLAddress.DELETE_JPUSH_TAG + Utils.getSerial())
.header("Authorization", JGYUtils.getAuthorization())
.delete()
.build();
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
Log.e("cleanJpushTag", "onFailure: " + e.getMessage());
}
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
Log.e("cleanJpushTag", "onResponse: " + response.toString());
Log.e(TAG, "onResponse: "+"清除Tag成功" );
}
});
}
private static void initTagObservable() {
Logutils.e(TAG, "initTagObservable: ");
Observable.create(new ObservableOnSubscribe<Integer>() {
@@ -250,7 +298,7 @@ public class BaseApplication extends MultiDexApplication {
}
};
}
}).throttleLast(30, TimeUnit.SECONDS)
}).throttleLast(1, TimeUnit.HOURS)
.subscribe(new Observer<Integer>() {
@Override
public void onSubscribe(Disposable d) {
@@ -293,6 +341,7 @@ public class BaseApplication extends MultiDexApplication {
break;
case 6018:
Logutils.e("jiguangInterface", s + "Tags 过多");
cleanJpushTag();
ToastUtil.show("设备标签数量超出限制,联系管理员修改\t" + "code:6018");
break;
case 6021:
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Environment;
import com.google.gson.JsonObject;
import com.mjsheng.myappstore.BuildConfig;
import com.mjsheng.myappstore.bean.Appground;
import com.mjsheng.myappstore.bean.BaseResponse;
@@ -50,6 +51,7 @@ import com.mjsheng.myappstore.network.api.newapi.SnTimeControl;
import com.mjsheng.myappstore.network.api.newapi.StudentsInfosApi;
import com.mjsheng.myappstore.network.api.newapi.TopAppControlApi;
import com.mjsheng.myappstore.network.api.newapi.UpdateDeviceInfoApi;
import com.mjsheng.myappstore.utils.SPUtils;
import com.mjsheng.myappstore.utils.Utils;
import java.io.File;
@@ -75,6 +77,7 @@ public class NetInterfaceManager {
private static NetInterfaceManager INSTANCE;
private Context mContext;
private static Retrofit mRetrofit;
private static Retrofit jiguangRetrofit;
public static final String ROOT_URL = BuildConfig.ROOT_URL;
public static final String WEBSOCKET_URL = BuildConfig.WebsocketURL;
@@ -90,6 +93,14 @@ public class NetInterfaceManager {
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
}
if (null == jiguangRetrofit) {
jiguangRetrofit = new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
}
}
public static void init(Context context) {
@@ -158,7 +169,7 @@ public class NetInterfaceManager {
* @return
*/
public Observable<BaseResponse> sendMACAddressObservable() {
return mRetrofit
return mRetrofit
.create(MACAddressApi.class)
.sendMACaddress(Utils.getSerial(),
Utils.getAndroid10MAC(mContext),
@@ -8,6 +8,7 @@ import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
@@ -16,11 +17,17 @@ import android.util.Log;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.arialyy.aria.core.Aria;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import com.mjsheng.myappstore.base.BaseApplication;
import com.mjsheng.myappstore.bean.AppListInfo;
import com.mjsheng.myappstore.bean.BrowserBookmarks;
import com.mjsheng.myappstore.bean.BrowserData;
import com.mjsheng.myappstore.bean.ForceDownloadBean;
import com.mjsheng.myappstore.bean.ForceDownloadData;
import com.mjsheng.myappstore.utils.CacheUtils;
import com.mjsheng.myappstore.utils.JGYUtils;
import com.mjsheng.myappstore.utils.Logutils;
@@ -42,8 +49,11 @@ import com.mjsheng.myappstore.utils.Logger;
import com.mjsheng.myappstore.utils.SPUtils;
import com.mjsheng.myappstore.utils.TimeUtils;
import com.mjsheng.myappstore.utils.Utils;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@@ -344,7 +354,7 @@ public class HTTPInterface {
final com.alibaba.fastjson.JSONObject object = new com.alibaba.fastjson.JSONObject();
object.put("app_name", app_name);
object.put("app_package", packageName);
object.put("MD5",app_md5);
object.put("MD5", app_md5);
PackageManager pm = context.getPackageManager();
PackageInfo packageInfo = null;
try {
@@ -393,28 +403,6 @@ public class HTTPInterface {
});
}
public static void cleanJpushAlias(String alias) {
OkGo.<String>post(URLAddress.DELETE_GEDEVICE_ALIAS)
.params("sn", alias)
.execute(new StringCallback() {
@Override
public void onSuccess(String s, Call call, Response response) {
String body = response.body().toString();
if ("200".equals(body)) {
Logutils.e("jiguangInterface", "alias清除成功");
} else {
Logutils.e("jiguangInterface", "alias清除失败");
}
}
@Override
public void onError(Call call, Response response, Exception e) {
super.onError(call, response, e);
Logutils.e("cleanJpushAlias", e.getMessage() + "???");
}
});
}
public interface GetAppinsideWebCallback {
void onComplete();
}
@@ -882,21 +870,6 @@ public class HTTPInterface {
// Logutils.e("getHomePageBookmarks", "onNext: homepagURL: homepagURL = " + homepagURL + "write: " + white);
// }
//主页
Intent homepag = new Intent("qch_app_brower_homepage");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
homepag.setPackage("com.android.settings")
.setPackage("com.android.browser");
}
if (!TextUtils.isEmpty(homepagURL)) {
String newHomePage = JGYUtils.getPrefixHttpsURL(homepagURL);
Logutils.e("getHomePageBookmarks", "onNext: newHomePage: " + newHomePage);
homepag.putExtra("homepage", newHomePage);
} else {
homepag.putExtra("homepage", "Invalid");
}
context.sendBroadcast(homepag);
//书签
String labelpage = browserBookmarksBaseResponse.data.getLabelpage();
Intent websiteBookMark = new Intent("qch_app_brower_website");
@@ -917,6 +890,25 @@ public class HTTPInterface {
websiteBookMark.putExtra("websiteBookMark", "Invalid");
}
context.sendBroadcast(websiteBookMark);
context.sendBroadcast(websiteBookMark);
context.sendBroadcast(websiteBookMark);
//主页
Intent homepag = new Intent("qch_app_brower_homepage");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
homepag.setPackage("com.android.settings")
.setPackage("com.android.browser");
}
if (!TextUtils.isEmpty(homepagURL)) {
// String newHomePage = JGYUtils.getPrefixHttpsURL(homepagURL);
Logutils.e("getHomePageBookmarks", "onNext: newHomePage: " + homepagURL);
homepag.putExtra("homepage", homepagURL);
} else {
homepag.putExtra("homepage", "Invalid");
}
context.sendBroadcast(homepag);
context.sendBroadcast(homepag);
context.sendBroadcast(homepag);
} else {
Intent intent1 = new Intent("qch_app_brower_homepage");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@@ -1159,9 +1151,11 @@ public class HTTPInterface {
JSONObject jsonObject = (JSONObject) JSON.toJSON(response.data);
String app_package = jsonObject.getString("app_package");
SPUtils.put(context, ForegroundAppUtil.TOPAPP_KEY, app_package);
ForegroundAppUtil.setTopAppClass(context, app_package);
ForegroundAppUtil.openTopApp(context);
} else {
SPUtils.put(context, ForegroundAppUtil.TOPAPP_KEY, "");
ForegroundAppUtil.setTopAppClass(context, "");
}
}
@@ -1200,11 +1194,8 @@ public class HTTPInterface {
boolean write = Settings.System.putString(context.getContentResolver(), "only_jgy_shortcut_list", data);
Logutils.e(TAG, "onNext: only_jgy_shortcut_list: " + write);
JGYUtils.getInstance().writeAppPackageList(context, data);
JGYUtils.getInstance().deleteOtherApp();
} else {
//为错误的时候不删除
// boolean write = Settings.System.putString(context.getContentResolver(), "only_jgy_shortcut_list", "");
// Settings.System.putString(context.getContentResolver(), "qch_app_forbid", " ");
// Logutils.e(TAG, "onNext: only_jgy_shortcut_list: " + write);
Logutils.e("getAppLimit", "onNext: " + bodyString);
}
} catch (IOException e) {
@@ -1222,13 +1213,13 @@ public class HTTPInterface {
@Override
public void onComplete() {
Logutils.e("getAppLimit", "onComplete: ");
getAllAppList();
getAllAppList(context);
}
});
}
public static void getAllAppList() {
public static void getAllAppList(Context context) {
NetInterfaceManager.getInstance().GetAllAppApi()
.getAllAppList(NetInterfaceManager.HTTP_KEY, Utils.getSerial())
.subscribeOn(Schedulers.io())
@@ -1241,7 +1232,7 @@ public class HTTPInterface {
@Override
public void onNext(BaseResponse<List<AppListInfo>> listBaseResponse) {
Logutils.e("getAllAppList", "onNext: " + listBaseResponse.toString());
Logutils.e("getAllAppList", "onNext: " + JSONObject.toJSONString(listBaseResponse));
int code = listBaseResponse.code;
if (code == 200) {
List<AppListInfo> appListInfos = listBaseResponse.data;
@@ -1255,15 +1246,65 @@ public class HTTPInterface {
@Override
public void onError(Throwable e) {
Logutils.e("getAllAppList", "onError: " + e.getMessage());
onComplete();
}
@Override
public void onComplete() {
Logutils.e("getAllAppList", "onComplete: ");
getForceDownload(context);
}
});
}
public static void getForceDownload(Context context) {
NetInterfaceManager.getInstance()
.getForceDownloadObservable()
.subscribe(new Observer<ForceDownloadBean>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
Logutils.e(TAG + ":" + "getForceDownload", "onSubscribe: ");
}
@Override
public void onNext(@NonNull ForceDownloadBean forceDownloadBean) {
Logutils.e(TAG + ":" + "getForceDownload", "onNext: ");
switch (forceDownloadBean.getCode()) {
case 200:
Logutils.e(TAG + ":" + "getForceDownload", "isDownloading=" + BaseApplication.getInstance().isDownloading());
BaseApplication.getInstance().checkIsDownloading();
if (!BaseApplication.getInstance().isDownloading()) {
Type type = new TypeToken<List<ForceDownloadData>>() {
}.getType();
Gson gson = new Gson();
List<ForceDownloadData> forceDownloadData = gson.fromJson(gson.toJson(forceDownloadBean.getData()), type);
JGYUtils.getInstance().forceDownload(forceDownloadData);
} else {
Aria.download(this).resumeAllTask();
}
break;
case -200:
boolean qch_force_app = Settings.System.putString(context.getContentResolver(), "qch_force_app", "invalid");
Logutils.e(TAG + ":" + "getForceDownload", "qch_force_app:" + qch_force_app);
break;
default:
Logutils.e(TAG + ":" + "getForceDownload", forceDownloadBean.getMsg());
break;
}
}
@Override
public void onError(@NonNull Throwable e) {
Logutils.e(TAG + ":" + "getForceDownload", "onError: " + e.getMessage());
onComplete();
}
@Override
public void onComplete() {
Logutils.e(TAG + ":" + "getForceDownload", "onComplete: ");
}
});
}
public static void getAppAutoStartUpdateAndNet(List<AppListInfo> appListInfos) {
NetInterfaceManager.getInstance()
@@ -2,6 +2,7 @@ package com.mjsheng.myappstore.network;
import com.mjsheng.myappstore.BuildConfig;
import com.mjsheng.myappstore.manager.NetInterfaceManager;
import com.mjsheng.myappstore.utils.Utils;
import rxhttp.wrapper.annotation.DefaultDomain;
@@ -72,4 +73,9 @@ public class URLAddress {
public final static String GET_EBAG_CODE = "And/getEbagCode";
//获取系统默认程序
public final static String GET_DEFAULT_APP = "app/getDefaultApp";
//删除alias
public static final String DELETE_JPUSH_ALIAS = "https://device.jpush.cn/v3/aliases/" ;
//删除tags
public static final String DELETE_JPUSH_TAG = "https://device.jpush.cn/v3/tags/" ;
}
@@ -3,16 +3,69 @@ package com.mjsheng.myappstore.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;
import android.util.Log;
import com.mjsheng.myappstore.service.MainService;
import com.mjsheng.myappstore.utils.BootManager;
import com.mjsheng.myappstore.utils.JGYUtils;
import com.mjsheng.myappstore.utils.Logutils;
import java.util.concurrent.TimeUnit;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
public class BootReceiver extends BroadcastReceiver {
private String TAG = BootReceiver.class.getSimpleName() + ":myappstore";
private static String TAG = BootReceiver.class.getSimpleName() + ":myappstore";
public static final String BOOT_COMPLETED = "com.jiaoguanyi.appstore.intent.action.BOOT_COMPLETED";
static {
getLockedState();
}
private static void getLockedState() {
Observable.create((ObservableOnSubscribe<Long>) emitter -> start = emitter::onNext)
.throttleLast(1, TimeUnit.HOURS)
.subscribe(new Observer<Long>() {
@Override
public void onSubscribe(Disposable d) {
Log.e("getLockedState", "onSubscribe: ");
}
@Override
public void onNext(Long aLong) {
Log.e("getLockedState", "onNext: ");
if (MainService.mPresenter != null) {
MainService.mPresenter.getLockedState();
Logutils.e("getLockedState", "mPresenter: " + "getLockedState");
} else {
Logutils.e("getLockedState", "mPresenter is NULL");
}
}
@Override
public void onError(Throwable e) {
Log.e("getLockedState", "onError: "+e.getMessage());
}
@Override
public void onComplete() {
Log.e("getLockedState", "onComplete: ");
}
});
}
private interface Start {
void onstar(long time);
}
private static Start start;
@Override
public void onReceive(Context context, Intent intent) {
Logutils.e(TAG, "action:" + intent.getAction());
@@ -24,12 +77,7 @@ public class BootReceiver extends BroadcastReceiver {
new BootManager(context).start();
break;
case BOOT_COMPLETED:
if (MainService.mPresenter != null) {
MainService.mPresenter.getLockedState();
Logutils.e(TAG, "mPresenter: " + "getLockedState");
} else {
Logutils.e(TAG, "mPresenter is NULL");
}
start.onstar(SystemClock.elapsedRealtime());
case Intent.ACTION_BATTERY_CHANGED:
case Intent.ACTION_BATTERY_LOW:
case Intent.ACTION_BATTERY_OKAY:
@@ -22,6 +22,7 @@ import com.alibaba.fastjson.JSONObject;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationListener;
import com.arialyy.aria.core.Aria;
import com.blankj.utilcode.util.PathUtils;
import com.mjsheng.myappstore.R;
import com.mjsheng.myappstore.utils.CacheUtils;
@@ -135,6 +136,9 @@ public class MyJPushReceiver extends BroadcastReceiver {
private final String EBAG_CODE = "35";
//更新白名单
private final String UPDATE_WHITELIST = "36";
//更换批次不恢复出厂
private final String UPDATE_BATCH = "37";
private Context mContext;
@@ -172,7 +176,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
//在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码,比如打开新的Activity, 打开一个网页等..
} else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
Logutils.e(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected);
Logutils.i(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected);
} else {
Logutils.e(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction());
}
@@ -286,8 +290,20 @@ public class MyJPushReceiver extends BroadcastReceiver {
Utils.ariaDownload(mContext, url, packageObj);
break;
case SET_HOMEPAG_TAG:
ToastUtil.betaShow("收到管控:浏览器主页书签设置");
setHomepagtag(extras);
Handler.getMain().postDelayed(new Runnable() {
@Override
public void run() {
try {
new CacheUtils().cleanApplicationUserData(mContext, "com.android.browser");
} catch (Exception e) {
e.printStackTrace();
Logutils.e(TAG, "setHomepagtag: " + e.getMessage());
}
setHomepagtag(extras);
ToastUtil.betaShow("收到管控:浏览器主页书签设置");
}
}, 2000);
break;
case APP_WEBSITE:
ToastUtil.betaShow("收到管控:APP内部网页管控");
@@ -414,7 +430,18 @@ public class MyJPushReceiver extends BroadcastReceiver {
ToastUtil.betaShow("收到管控:更新白名单");
HTTPInterface.getAppLimit(mContext);
break;
case UPDATE_BATCH:
ToastUtil.betaShow("收到管控:更换批次不恢复出厂设置");
Aria.download(this).removeAllTask(true);
if (MainService.mPresenter != null) {
MainService.mPresenter.getLockedState();
Logutils.e("getLockedState", "mPresenter: " + "getLockedState");
} else {
Logutils.e("getLockedState", "mPresenter is NULL");
}
break;
}
}
private void setLock_screen(int state, Context context, String name) {
@@ -845,12 +872,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
private void setHomepagtag(String s) {
//设置主页和标签
// HTTPInterface.setHomepagtag(mContext);//设置主页和标签
try {
new CacheUtils().cleanApplicationUserData(mContext, "com.android.browser");
} catch (Exception e) {
e.printStackTrace();
Logutils.e(TAG, "setHomepagtag: " + e.getMessage());
}
HTTPInterface.getHomePageBookmarks(mContext, null);
// if (TextUtils.isEmpty(s)) {
// Logutils.e(TAG, "setHomepagtag extras is null");
@@ -1033,8 +1055,15 @@ public class MyJPushReceiver extends BroadcastReceiver {
// if (TextUtils.isEmpty(packageName)) {
// return;
// }
SPUtils.put(context, ForegroundAppUtil.TOPAPP_KEY, packageName);
ForegroundAppUtil.openTopApp(context);
if (TextUtils.isEmpty(packageName)) {
SPUtils.put(context, ForegroundAppUtil.TOPAPP_KEY, "");
ForegroundAppUtil.setTopAppClass(context, "");
} else {
SPUtils.put(context, ForegroundAppUtil.TOPAPP_KEY, packageName);
ForegroundAppUtil.setTopAppClass(context, packageName);
ForegroundAppUtil.openTopApp(context);
}
}
private void setBootanimation(Context context, String extras) {
@@ -1057,8 +1086,11 @@ public class MyJPushReceiver extends BroadcastReceiver {
String default_launcher = jsonObject.getString("default_launcher");
if (TextUtils.isEmpty(default_launcher)) {
JGYUtils.getInstance().setDefaultDesktop("");
SPUtils.put(context, "default_launcher", "");
} else {
JGYUtils.getInstance().setDefaultDesktop(default_launcher);
SPUtils.put(context, "default_launcher", default_launcher);
}
}
}
@@ -15,6 +15,7 @@ import com.mjsheng.myappstore.utils.ApkUtils;
import com.mjsheng.myappstore.utils.CacheUtils;
import com.mjsheng.myappstore.utils.JGYUtils;
import com.mjsheng.myappstore.utils.Logutils;
import com.mjsheng.myappstore.utils.SPUtils;
import com.mjsheng.myappstore.utils.SaveListUtils;
import java.util.concurrent.TimeUnit;
@@ -124,6 +125,10 @@ public class NewAppReceiver extends BroadcastReceiver {
//HTTPInterface.getNetAndLaunchSetting(mContext);
HTTPInterface.getAppLimit(mContext);
// HTTPInterface.getAppinsideWeb(mContext, () -> Logutils.e(TAG, "onNext: setAPPinsideWebsite"));
String oldDesktop = (String) SPUtils.get(mContext, "default_launcher", "");
if (s.equals(oldDesktop)){
ApkUtils.openApp(mContext, s);
}
}
@Override
@@ -81,7 +81,7 @@ public class GuardService extends Service {
private ServiceConnection mServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
Logutils.e(TAG, "GuardService:建立链接");
Logutils.w(TAG, "GuardService:建立链接");
boolean isServiceRunning = ServiceAliveUtils.isServiceAlive(GuardService.this, StepService.class.getName());
if (!isServiceRunning) {
startService(new Intent(GuardService.this, StepService.class));
@@ -373,7 +373,7 @@ public class GuardService extends Service {
// 最大电量
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0);
int elec = (level * 100) / scale;
Logutils.e(TAG, "electricity:=" + elec + "%");
// Logutils.e(TAG, "electricity:=" + elec + "%");
if (elec == 50) {
start.onstar(SystemClock.elapsedRealtime());
}
@@ -41,6 +41,11 @@ import com.mjsheng.myappstore.utils.SaveListUtils;
import com.mjsheng.myappstore.utils.SysSettingUtils;
import com.mjsheng.myappstore.utils.TimeUtils;
import com.mjsheng.myappstore.utils.ToastUtil;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.LifecycleTransformer;
import com.trello.rxlifecycle2.RxLifecycle;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.trello.rxlifecycle2.android.RxLifecycleAndroid;
import java.util.Arrays;
import java.util.HashSet;
@@ -52,8 +57,9 @@ import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.subjects.BehaviorSubject;
public class MainService extends Service implements MainContact.MainView, NetworkUtils.OnNetworkStatusChangedListener {
public class MainService extends Service implements MainContact.MainView, NetworkUtils.OnNetworkStatusChangedListener, LifecycleProvider<ActivityEvent> {
@SuppressLint("StaticFieldLeak")
public static MainPresenter mPresenter;
private static final String TAG = MainService.class.getSimpleName();
@@ -71,13 +77,24 @@ public class MainService extends Service implements MainContact.MainView, Networ
runningTime = SystemClock.elapsedRealtime();
//直接获取数据
ToastUtil.betaShow("网络已连接");
mPresenter.getLockedState();
start.onstar(SystemClock.elapsedRealtime());
}
private final BehaviorSubject<ActivityEvent> lifecycleSubject = BehaviorSubject.create();
@Override
public Observable<ActivityEvent> lifecycle() {
return lifecycleSubject.hide();
}
@Override
public Resources getResources() {
//1920是设计稿的宽(单位p:x)
return AdaptScreenUtils.adaptWidth(super.getResources(), 1920);
public <T> LifecycleTransformer<T> bindUntilEvent(ActivityEvent event) {
return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
}
@Override
public <T> LifecycleTransformer<T> bindToLifecycle() {
return RxLifecycleAndroid.bindActivity(lifecycleSubject);
}
private interface Start {
@@ -129,8 +146,11 @@ public class MainService extends Service implements MainContact.MainView, Networ
@Override
public void onCreate() {
lifecycleSubject.onNext(ActivityEvent.CREATE);
mPresenter = new MainPresenter(this);
mPresenter.attachView(this);
mPresenter.setProvider(this);
lifecycleSubject.onNext(ActivityEvent.CREATE);
if ((int) SPUtils.get(this, "first_connect", 0) == 0) {
// TODO: 2021/5/26 待底层修改,临时解决办法
Logutils.e(TAG, "onCreate: " + "Disable All Settings");
@@ -159,6 +179,7 @@ public class MainService extends Service implements MainContact.MainView, Networ
super.onDestroy();
unRegisterReceivers();
NetworkUtils.unregisterNetworkStatusChangedListener(this);
lifecycleSubject.onNext(ActivityEvent.DESTROY);
mPresenter.detachView();
}
@@ -399,6 +420,7 @@ public class MainService extends Service implements MainContact.MainView, Networ
@SuppressLint("NewApi")
@Override
public void onReceive(Context context, Intent intent) {
Log.e(TAG, "onReceive: " + intent.getAction());
if (Intent.ACTION_DATE_CHANGED.equals(intent.getAction())) {
Logutils.e("TimeChangedReceiver", "onReceive:" + "data changed");
} else if (Intent.ACTION_TIME_CHANGED.equals(intent.getAction())) {
@@ -728,11 +750,15 @@ public class MainService extends Service implements MainContact.MainView, Networ
showFloatingWindow(tips);
}
screenlocked = true;
SPUtils.put(MainService.this, "is_screen_lock", true);
SPUtils.put(MainService.this, "screen_tips", tips);
} else {
if (!timelocked) {
hideFloatingWindow();
}
screenlocked = false;
SPUtils.put(MainService.this, "is_screen_lock", false);
SPUtils.put(MainService.this, "screen_tips", "");
}
}
}
@@ -8,16 +8,23 @@ package com.mjsheng.myappstore.service;
*/
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.os.PowerManager;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.Nullable;
import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.NetworkUtils;
import com.mjsheng.myappstore.KeepAliveConnection;
import com.mjsheng.myappstore.manager.NetInterfaceManager;
import com.mjsheng.myappstore.utils.Logutils;
@@ -34,12 +41,22 @@ import java.net.URI;
* @author LiGuangMin
* @time Created by 2018/8/17 11:26
*/
public class StepService extends Service {
public class StepService extends Service implements NetworkUtils.OnNetworkStatusChangedListener {
private final static String TAG = StepService.class.getSimpleName();
public JWebSocketClient client;
private JWebSocketClientBinder mBinder = new JWebSocketClientBinder();
@Override
public void onDisconnected() {
}
@Override
public void onConnected(NetworkUtils.NetworkType networkType) {
connect();
}
//用于Activity和service通讯
public class JWebSocketClientBinder extends Binder {
public StepService getService() {
@@ -50,7 +67,7 @@ public class StepService extends Service {
private ServiceConnection mServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
Logutils.e(TAG, "StepService:建立链接");
Logutils.w(TAG, "StepService:建立链接");
boolean isServiceRunning = ServiceAliveUtils.isServiceAlive(StepService.this, GuardService.class.getName());
if (!isServiceRunning) {
Intent i = new Intent(StepService.this, GuardService.class);
@@ -74,34 +91,78 @@ public class StepService extends Service {
};
}
@Override
public void onCreate() {
super.onCreate();
NetworkUtils.registerNetworkStatusChangedListener(this);
registerScreenLockReceiver();
//初始化websocket
initSocketClient();
mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// startForeground(1, new Notification());
// 绑定建立链接
// try {
// final String filePath = intent.getStringExtra("filePath");
// final String packageName = intent.getStringExtra("packageName");
// Logutils.e("fht", filePath);
// Logutils.e("fht", packageName);
// FileData fileData = new FileData(filePath, packageName);
// MyApplication.getInstance().addFileData(fileData);
//
// } catch (Exception e) {
// Logutils.e("fht", e.getMessage());
// }
//初始化websocket
Logutils.e(TAG, "onStartCommand: ");
// initSocketClient();
// mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测
Logutils.e("JWebSocketClientService", "onStartCommand: ");
bindService(new Intent(this, GuardService.class), mServiceConnection, Context.BIND_IMPORTANT);
return START_STICKY;
}
private ScreenLockReceiver screenLockReceiver;
private void registerScreenLockReceiver() {
if (null == screenLockReceiver) {
screenLockReceiver = new ScreenLockReceiver();
}
IntentFilter filter = new IntentFilter();
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_BOOT_COMPLETED);
filter.addAction(Intent.ACTION_USER_PRESENT);
filter.addAction(Intent.ACTION_SHUTDOWN);
filter.addAction(Intent.ACTION_FACTORY_RESET);
filter.addAction(Intent.ACTION_MASTER_CLEAR);
registerReceiver(screenLockReceiver, filter);
}
private class ScreenLockReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.e(TAG, "onReceive:" + action);
if (TextUtils.isEmpty(action)) {
Log.e(TAG, "onReceive: is NULL");
return;
}
switch (action) {
case Intent.ACTION_BOOT_COMPLETED:
case Intent.ACTION_USER_PRESENT:
case Intent.ACTION_SCREEN_ON:
sendMsg(1);
break;
case Intent.ACTION_SCREEN_OFF:
case Intent.ACTION_SHUTDOWN:
case Intent.ACTION_FACTORY_RESET:
case Intent.ACTION_MASTER_CLEAR:
sendMsg(2);
break;
default:
break;
}
}
}
@Override
public void onDestroy() {
super.onDestroy();
NetworkUtils.unregisterNetworkStatusChangedListener(this);
closeConnect();
if (screenLockReceiver != null) {
unregisterReceiver(screenLockReceiver);
}
}
/**
@@ -114,13 +175,14 @@ public class StepService extends Service {
client = new JWebSocketClient(uri) {
@Override
public void onMessage(String message) {
Logutils.i("JWebSocketClientService", "收到服务器发来的消息:" + message + "?");
Logutils.i("JWebSocketClientService", "收到服务器发来的消息:" + message);
}
@Override
public void onOpen(ServerHandshake handshakedata) {
super.onOpen(handshakedata);
Logutils.i("JWebSocketClientService", "websocket连接成功");
sendMsg(1);
}
@Override
@@ -129,17 +191,17 @@ public class StepService extends Service {
Logutils.i("JWebSocketClientService", "websocket连接关闭");
// client.close();
// initSocketClient();
// mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测
mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测
}
@Override
public void onError(Exception ex) {
super.onError(ex);
Logutils.i("JWebSocketClientService", "websocket连接错误");
Logutils.i("JWebSocketClientService", "websocket连接错误:" + ex.getMessage());
// client.close();
// initSocketClient();
// mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测
mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测
}
};
@@ -168,13 +230,32 @@ public class StepService extends Service {
/**
* 发送消息
*
* @param msg
*/
public void sendMsg(String msg) {
public void sendMsg() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("sn", Utils.getSerial());
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
if (!pm.isScreenOn()) {
jsonObject.put("online", 2);
//熄屏状态
} else {
jsonObject.put("online", 1);
}
if (null != client) {
Logutils.i("JWebSocketClientService", "发送的消息:" + msg);
client.send(msg);
Logutils.i("JWebSocketClientService", "发送的消息:" + jsonObject.toJSONString());
client.send(jsonObject.toJSONString());
}
}
public void sendMsg(int state) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("sn", Utils.getSerial());
jsonObject.put("online", state);
if (null != client) {
Logutils.i("JWebSocketClientService", "发送的消息:" + jsonObject.toJSONString());
client.send(jsonObject.toJSONString());
} else {
Logutils.i("JWebSocketClientService", "未连接");
}
}
@@ -194,7 +275,7 @@ public class StepService extends Service {
}
// -------------------------------------websocket心跳检测------------------------------------------------
private static final long HEART_BEAT_RATE = 50 * 1000;//每隔50秒进行一次对长连接的心跳检测
private static final long HEART_BEAT_RATE = 30 * 1000;//每隔50秒进行一次对长连接的心跳检测
private Handler mHandler = new Handler();
private Runnable heartBeatRunnable = new Runnable() {
@Override
@@ -203,10 +284,10 @@ public class StepService extends Service {
if (client != null) {
if (client.isOpen()) {
Logutils.i("JWebSocketClientService", "websocket已连接");
sendMsg(Utils.getSerial());
sendMsg();
} else if (client.isClosed()) {
Logutils.i("JWebSocketClientService", "websocket重连中");
// reconnectWs();
reconnectWs();
}
} else {
//如果client已为空,重新初始化连接
@@ -214,7 +295,7 @@ public class StepService extends Service {
initSocketClient();
}
//每隔一定的时间,对长连接进行一次心跳检测
// mHandler.postDelayed(this, HEART_BEAT_RATE);
mHandler.postDelayed(this, HEART_BEAT_RATE);
}
};
@@ -229,7 +310,7 @@ public class StepService extends Service {
try {
Logutils.i("JWebSocketClientService", "开启重连");
client.reconnectBlocking();
} catch (InterruptedException e) {
} catch (Exception e) {
e.printStackTrace();
}
}
@@ -1121,7 +1121,7 @@ public class ApkUtils {
installedListBuilder.append(",");
}
installedListBuilder.append(s);
Logutils.e("addShortcut", "packages: " + s);
Logutils.i("addShortcut", "packages: " + s);
}
String installedList = installedListBuilder.toString();
boolean qch_force_app = Settings.System.putString(context.getContentResolver(), "qch_launcher_icon_app", installedList);
@@ -8,6 +8,7 @@ import android.content.Intent;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import java.util.List;
@@ -18,6 +19,7 @@ public class ForegroundAppUtil {
private static final long START_TIME = END_TIME - TIME_INTERVAL;
public static final String TOPAPP_KEY = "TOP_ALWAYS_SHOW_APP_NAME";
private static String TAG = ForegroundAppUtil.class.getSimpleName();
public static String getForegroundPackageName(Context context) {
//系统应用可以直接获取
@@ -43,6 +45,26 @@ public class ForegroundAppUtil {
}
}
public static void setTopAppClass(Context context, String pkg) {
if (TextUtils.isEmpty(pkg)) {
boolean always_top_packagename = Settings.System.putString(context.getContentResolver(), "always_top_packagename", "Invalid");
boolean always_top_classname = Settings.System.putString(context.getContentResolver(), "always_top_classname", "Invalid");
Log.e(TAG, "setTopAppClass: always_top_packagename = " + always_top_packagename);
Log.e(TAG, "setTopAppClass: always_top_classname = " + always_top_classname);
} else {
String ClassName = JGYUtils.getInstance().getStartClassName(pkg);
setTopAppClass(context, pkg, ClassName);
}
}
public static void setTopAppClass(Context context, String pkg, String ClassName) {
boolean always_top_packagename = Settings.System.putString(context.getContentResolver(), "always_top_packagename", pkg);
boolean always_top_classname = Settings.System.putString(context.getContentResolver(), "always_top_classname", ClassName);
Log.e(TAG, "setTopAppClass: always_top_packagename = " + always_top_packagename);
Log.e(TAG, "setTopAppClass: always_top_classname = " + always_top_classname);
ApkUtils.openApp(context, pkg);
}
/**
* 获取栈顶的应用包名
@@ -81,10 +81,13 @@ import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import cn.jpush.android.api.JPushInterface;
import static android.app.ActivityManager.RECENT_IGNORE_UNAVAILABLE;
@@ -100,6 +103,9 @@ public class JGYUtils {
public static String ZhanruiTag = "展锐";
public static String Other = "其他";
static {
System.loadLibrary("jgy");
}
private JGYUtils(Context context) {
this.mContext = context;
@@ -119,6 +125,8 @@ public class JGYUtils {
return sInstance;
}
public static native String getAuthorization();
public static boolean isOfficialVersion() {
String channelValue = JGYUtils.getInstance().getStringMetaData();
return "official".equals(channelValue);
@@ -1754,19 +1762,28 @@ public class JGYUtils {
}
}
private String Launcher3 = "com.android.launcher3";
private String Launcher3Class = "com.android.launcher3.Launcher";
//设置默认桌面
public void setDefaultDesktop(String pkg) {
if (TextUtils.isEmpty(pkg)) {
setDefaultDesktop("", "");
openLauncher3();
} else {
String className = getStartClassName(pkg);
if (TextUtils.isEmpty(className)) {
setDefaultDesktop("", "");
openLauncher3();
} else {
setDefaultDesktop(pkg, className);
}
}
}
private void openLauncher3() {
setDefaultDesktop(Launcher3, Launcher3Class);
ApkUtils.openApp(mContext, Launcher3);
}
public String getStartClassName(String pkg) {
PackageInfo packageInfo = null;
try {
@@ -1803,11 +1820,29 @@ public class JGYUtils {
}
public void setDefaultDesktop(String pkg, String className) {
String oldDesktop = (String) SPUtils.get(mContext, "default_launcher", "");
if (Objects.equals(oldDesktop, pkg)) {
Log.e(TAG, "setDefaultDesktop: " + "数据一致");
return;
}
Intent intent = new Intent("setDefaultLauncher");
intent.putExtra("package", pkg);
intent.putExtra("className", className);
intent.setPackage("com.android.settings");
mContext.sendBroadcast(intent);
ApkUtils.openApp(mContext, pkg);
Log.e(TAG, "setDefaultDesktop: " + pkg + ":" + className);
}
public String getMacJson() {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("sn", Utils.getSerial());
jsonObject.addProperty("mac", Utils.getAndroid10MAC(mContext));
jsonObject.addProperty("jpush_id", JPushInterface.getRegistrationID(mContext));
jsonObject.addProperty("devices_version", Utils.getCustomVersion());
jsonObject.addProperty("appstore_version", BuildConfig.VERSION_NAME);
jsonObject.addProperty("store_version", Utils.getAPPVersionName(mContext));
jsonObject.addProperty("local_mac", Utils.getAndroid7MAC());
return jsonObject.toString();
}
}
@@ -16,7 +16,7 @@ public class ServiceAliveUtils {
isServiceRunning = true;
}
}
Logutils.e("ServiceAliveUtils", mContext.getClass().getName() + "isServiceAlice: " + isServiceRunning);
Logutils.i("ServiceAliveUtils", mContext.getClass().getName() + "isServiceAlice: " + isServiceRunning);
return isServiceRunning;
}
@@ -32,7 +32,7 @@ public class ServiceAliveUtils {
isServiceRunning = true;
}
}
Logutils.e("ServiceAliveUtils", serviceName + " :isServiceAlice: " + isServiceRunning);
Logutils.i("ServiceAliveUtils", serviceName + " :isServiceAlice: " + isServiceRunning);
return isServiceRunning;
}
}
@@ -135,7 +135,6 @@ public class SysSettingUtils {
}
private static void setPhoneList(Context context, JSONObject jsonObject) {
Logutils.e(TAG, "setPhoneList: " + jsonObject.toJSONString());
try {
//设置电话功能,电话白名单
//电话通话开关
@@ -471,8 +470,7 @@ public class SysSettingUtils {
/**
* @param context
* @param jsonObject
* tfmedia开关
* @param jsonObject tfmedia开关
*/
private static void setTF(Context context, JSONObject jsonObject) {
try {
@@ -590,6 +588,11 @@ public class SysSettingUtils {
ApkUtils.hideSystemSettingAPP(context, "com.android.documentsui");
}
Logutils.e(TAG, "qch_app_filemanager" + filemanager);
//浏览器
int browser = changeNum(jsonObject.getInteger("setting_browser"));
Settings.System.putInt(context.getContentResolver(), "qch_app_browser", browser);
Logutils.e(TAG, "qch_app_browser" + browser);
} catch (Exception e) {
Logutils.e(TAG, "setIcon: " + e.getMessage());
}
@@ -2,12 +2,18 @@ package com.mjsheng.myappstore.utils;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.Gravity;
import android.widget.Toast;
import com.blankj.utilcode.util.ColorUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.mjsheng.myappstore.BuildConfig;
import com.mjsheng.myappstore.R;
/**
@@ -15,12 +21,14 @@ import com.mjsheng.myappstore.BuildConfig;
*/
public class ToastUtil {
private static final String TAG = ToastUtil.class.getSimpleName();
@SuppressLint("StaticFieldLeak")
private static Context mContext;
private static Handler mainHandler = new Handler(Looper.getMainLooper());
private static Toast debugToast;
private static Toast toast;
@SuppressLint("ShowToast")
public static void init(Context context) {
mContext = context;
@@ -33,34 +41,25 @@ public class ToastUtil {
private static long time2 = 0L;
public static void show(final String msg) {
mainHandler.post(() -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
time2 = System.currentTimeMillis();
if ((time2 - time1) > 3500) {
showToast(mContext, msg, Toast.LENGTH_SHORT);
time1 = time2;
}
} else {
if (toast != null) {
toast.setText(msg);
toast.show();
}
}
});
ToastUtils.make()
// .setBgColor(ColorUtils.getColor(R.color.toast_color))
.setTextColor(Color.DKGRAY)
// .setGravity(Gravity.CENTER, 0, 0)
.setNotUseSystemToast()
.show(msg);
}
public static void betaShow(final String msg) {
if (JGYUtils.isBetaVersion() || BuildConfig.DEBUG) {
mainHandler.post(() -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
showToast(mContext, msg, Toast.LENGTH_SHORT);
} else {
if (debugToast != null) {
debugToast.setText(msg);
debugToast.show();
}
}
});
ToastUtils.make()
// .setBgColor(ColorUtils.getColor(R.color.toast_color))
.setTextColor(Color.RED)
// .setGravity(Gravity.CENTER, 0, 0)
.setNotUseSystemToast()
.setDurationIsLong(true)
.show(msg);
} else {
Log.e(TAG, "debugShow: " + msg);
}
}
@@ -11,6 +11,8 @@ import java.io.IOException;
import java.net.URI;
import java.util.Arrays;
import java.util.HashSet;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -27,20 +29,25 @@ import okhttp3.Request;
import okhttp3.Response;
public class URLUtils {
private static String TAG = URLUtils.class.getSimpleName();
private static final String TAG = URLUtils.class.getSimpleName();
private Context mContext;
private HashSet<String> baseURLList = new HashSet<>();
private HashSet<String> nohttpURLList = new HashSet<>();
private long time1;
private long time2;
public URLUtils(Context context) {
this.mContext = context;
}
public void setBrowserWhiteList() {
time1 = System.currentTimeMillis();
//会写入两次,第一次是不带前缀的,第二次会把实际的地址写入进去
String oldwhiteList = Settings.System.getString(mContext.getContentResolver(), "DeselectBrowserArray");
if (TextUtils.isEmpty(oldwhiteList)) {
Logutils.e(TAG, "getBrowserWhiteList: " + "oldwhiteList is empty");
Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray","Invalid");
Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", "Invalid");
} else {
Logutils.e(TAG, "getBrowserWhiteList: " + "oldwhiteList is : " + oldwhiteList);
HashSet<String> URLList = new HashSet<>(Arrays.asList(oldwhiteList.trim().split(",")));
@@ -66,8 +73,11 @@ public class URLUtils {
// }
// }else {
// }
nohttpURLList.add("m." + getDomain(url));
// nohttpURLList.add(getDomain(url));
if (!url.startsWith("http")) {
nohttpURLList.add(url);
String httpsUrl = "https://" + url;
String httpUrl = "http://" + url;
emitter.onNext(getOkHttpURL(httpsUrl));
@@ -77,14 +87,25 @@ public class URLUtils {
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(httpsUrl);
while (m.find()) {
Log.e(TAG, "matcher1: " + m.group());
baseURLList.add(m.group());
}
}else {
} else {
if (url.endsWith("/")) {
baseURLList.add(url.substring(0, url.length() - 1));
}
//临时
if (baseURLList.size() != 0) {
Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", String.join(",", baseURLList));
}
Log.e(TAG, "subscribe: baseURLList: " + baseURLList);
Log.e(TAG, "subscribe: DeselectBrowserArray: " + Settings.System.getString(mContext.getContentResolver(), "DeselectBrowserArray"));
String pattern = "[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\\.?";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(url);
if (m.find()) {
Log.e(TAG, "matcher: " + m.group());
nohttpURLList.add(m.group());
Log.e(TAG, "matcher2: " + m.group());
String httpsUrl = "https://" + m.group();
String httpUrl = "http://" + m.group();
emitter.onNext(getOkHttpURL(httpsUrl));
@@ -161,18 +182,14 @@ public class URLUtils {
@Override
public void onComplete() {
Logutils.e(TAG, "onComplete: " + baseURLList);
StringBuilder stringBuilder = new StringBuilder();
for (String s : baseURLList) {
if (stringBuilder.length() > 0) {
stringBuilder.append(",");
}
stringBuilder.append(s);
}
String DeselectBrowserArray = stringBuilder.toString();
Logutils.i(TAG, "onComplete: " + baseURLList);
baseURLList.addAll(nohttpURLList);
baseURLList.removeIf(TextUtils::isEmpty);
String DeselectBrowserArray = String.join(",", baseURLList);
Logutils.e(TAG, "onComplete: " + "white list: " + DeselectBrowserArray);
boolean write = Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", DeselectBrowserArray);
Logutils.e(TAG, "onComplete: " + "write :" + write);
Logutils.i(TAG, "onComplete: " + "write :" + write + " time = " + (System.currentTimeMillis() - time1));
}
});
}
@@ -184,7 +201,7 @@ public class URLUtils {
String qch_webblack_url = Settings.System.getString(mContext.getContentResolver(), "qch_webblack_url");
Logutils.e(TAG, "setBrowserBlackList: qch_webblack_url = " + qch_webblack_url);
if (TextUtils.isEmpty(qch_webblack_url)) {
Settings.System.putString(mContext.getContentResolver(), "qch_webblack_url","Invalid");
Settings.System.putString(mContext.getContentResolver(), "qch_webblack_url", "Invalid");
return;
}
HashSet<String> URLList = new HashSet<>(Arrays.asList(qch_webblack_url.trim().split(",")));
@@ -204,15 +221,9 @@ public class URLUtils {
blackList.add("https://" + url);
}
}
StringBuilder stringBuilder = new StringBuilder();
for (String url : blackList) {
if (stringBuilder.length() > 0) {
stringBuilder.append(",");
}
stringBuilder.append(url);
}
Logutils.e(TAG, "setBrowserBlackList: blackList: " + blackList);
boolean write = Settings.System.putString(mContext.getContentResolver(), "qch_webblack_url", stringBuilder.toString());
boolean write = Settings.System.putString(mContext.getContentResolver(), "qch_webblack_url", String.join(",", blackList));
Logutils.e(TAG, "setBrowserBlackList: write: " + write);
}
@@ -220,7 +231,12 @@ public class URLUtils {
if (!URL.startsWith("http")) {
return "";
}
OkHttpClient okHttpClient = new OkHttpClient();
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.connectTimeout(1, TimeUnit.SECONDS)
.writeTimeout(1, TimeUnit.SECONDS)
.readTimeout(1, TimeUnit.SECONDS)
.build();
final Request request = new Request.Builder()
.url(URL)
.removeHeader("User-Agent")
@@ -249,7 +265,7 @@ public class URLUtils {
}
} catch (IOException e) {
e.printStackTrace();
Logutils.e(TAG, "getOkHttpURL: " + e.getMessage() + " : " + URL);
Logutils.w(TAG, "getOkHttpURL: " + e.getMessage() + " : " + URL);
return "";
}
}
@@ -259,10 +275,31 @@ public class URLUtils {
//https://blog.csdn.net/liehuo123/article/details/81509486?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_baidulandingword-1&spm=1001.2101.3001.4242
//https://www.cnblogs.com/breakdown/archive/2012/09/17/2689101.html
/**
* 获取主机名
*
* @param url 网址
* @return
*/
//https://blog.csdn.net/smallnetvisitor/article/details/84516347
public String getDomain(String url) {
String regexStr = "(?<=//|)((\\w)+(\\.cn|\\.com.cn|\\.org.cn|\\.com|\\.net|\\.org|\\.cc|\\.biz|\\.uk|\\.info|\\.in|\\.eu))+";
Pattern p = Pattern.compile(regexStr);
Matcher m = p.matcher(url);
String domainVal = "";
if (m.find()) {
domainVal = m.group();
}
return domainVal;
}
/**
* Gets ip.
* 通过url获取到域名
*https://www.cnblogs.com/shizhijie/p/8277092.html
* https://www.cnblogs.com/shizhijie/p/8277092.html
*
* @param url the url
* @return the ip
*/