version:
update:极光推送优化 fix: add:
This commit is contained in:
@@ -41,8 +41,11 @@ import io.reactivex.annotations.NonNull;
|
|||||||
import io.reactivex.disposables.Disposable;
|
import io.reactivex.disposables.Disposable;
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
import rx.android.schedulers.AndroidSchedulers;
|
import rx.android.schedulers.AndroidSchedulers;
|
||||||
|
import rx.functions.Action1;
|
||||||
|
|
||||||
public class MainActivity extends BaseActivity implements MainContact.MainView {
|
public class MainActivity extends BaseActivity implements MainContact.MainView {
|
||||||
|
private static final String TAG = MainActivity.class.getSimpleName();
|
||||||
|
|
||||||
@BindView(R.id.imageView)
|
@BindView(R.id.imageView)
|
||||||
ImageView imageView;
|
ImageView imageView;
|
||||||
@BindView(R.id.tv_devsn)
|
@BindView(R.id.tv_devsn)
|
||||||
@@ -76,11 +79,11 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
|||||||
@BindView(R.id.tv_customversion)
|
@BindView(R.id.tv_customversion)
|
||||||
TextView tv_customversion;
|
TextView tv_customversion;
|
||||||
|
|
||||||
private static final String TAG = MainActivity.class.getSimpleName();
|
|
||||||
private MainPresenter mPresenter;
|
private MainPresenter mPresenter;
|
||||||
|
|
||||||
private boolean netWorkIsRunning = false;
|
private boolean netWorkIsRunning = false;
|
||||||
private boolean updateApp = false;
|
private boolean updateApp = false;
|
||||||
|
|
||||||
//jiguang
|
//jiguang
|
||||||
public static boolean isForeground = false;
|
public static boolean isForeground = false;
|
||||||
//for receive customer msg from jpush server
|
//for receive customer msg from jpush server
|
||||||
@@ -133,6 +136,7 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
|||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//执行所有接口耗时
|
||||||
long timeMillis;
|
long timeMillis;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -384,12 +384,7 @@ public class MainPresenter implements MainContact.Presenter {
|
|||||||
@Override
|
@Override
|
||||||
public void setJpushAlias() {
|
public void setJpushAlias() {
|
||||||
JPushInterface.init(mContext);
|
JPushInterface.init(mContext);
|
||||||
TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean();
|
SetAlias();
|
||||||
tagAliasBean.action = ACTION_SET;
|
|
||||||
sequence++;
|
|
||||||
tagAliasBean.alias = Utils.getSerial();
|
|
||||||
tagAliasBean.isAliasAction = true;
|
|
||||||
TagAliasOperatorHelper.getInstance().handleAction(mContext, sequence, tagAliasBean);
|
|
||||||
String rid = JPushInterface.getRegistrationID(mContext);
|
String rid = JPushInterface.getRegistrationID(mContext);
|
||||||
if (!TextUtils.isEmpty(rid)) {
|
if (!TextUtils.isEmpty(rid)) {
|
||||||
Log.e("setJpushAlias", "RegId:" + rid);
|
Log.e("setJpushAlias", "RegId:" + rid);
|
||||||
@@ -398,6 +393,15 @@ public class MainPresenter implements MainContact.Presenter {
|
|||||||
mView.setAliasFinished();
|
mView.setAliasFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetAlias(){
|
||||||
|
TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean();
|
||||||
|
tagAliasBean.action = ACTION_SET;
|
||||||
|
sequence++;
|
||||||
|
tagAliasBean.alias = Utils.getSerial();
|
||||||
|
tagAliasBean.isAliasAction = true;
|
||||||
|
TagAliasOperatorHelper.getInstance().handleAction(mContext, sequence, tagAliasBean);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setJpushTags() {
|
public void setJpushTags() {
|
||||||
NetInterfaceManager.getInstance()
|
NetInterfaceManager.getInstance()
|
||||||
@@ -414,14 +418,7 @@ public class MainPresenter implements MainContact.Presenter {
|
|||||||
JsonObject jsonObject = JsonParser.parseString(new Gson().toJson(response.data)).getAsJsonObject();
|
JsonObject jsonObject = JsonParser.parseString(new Gson().toJson(response.data)).getAsJsonObject();
|
||||||
String batch = jsonObject.get("batch").getAsString();
|
String batch = jsonObject.get("batch").getAsString();
|
||||||
if (!TextUtils.isEmpty(batch)) {
|
if (!TextUtils.isEmpty(batch)) {
|
||||||
Set set = new HashSet();
|
setTag(batch);
|
||||||
set.add(batch);
|
|
||||||
TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean();
|
|
||||||
tagAliasBean.action = ACTION_SET;
|
|
||||||
sequence++;
|
|
||||||
tagAliasBean.tags = set;
|
|
||||||
tagAliasBean.isAliasAction = false;
|
|
||||||
TagAliasOperatorHelper.getInstance().handleAction(mContext, sequence, tagAliasBean);
|
|
||||||
} else {
|
} else {
|
||||||
Log.e("setJpushTags", "onNext: " + "batch empty");
|
Log.e("setJpushTags", "onNext: " + "batch empty");
|
||||||
}
|
}
|
||||||
@@ -444,6 +441,17 @@ public class MainPresenter implements MainContact.Presenter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setTag(String batch){
|
||||||
|
Set set = new HashSet();
|
||||||
|
set.add(batch);
|
||||||
|
TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean();
|
||||||
|
tagAliasBean.action = ACTION_SET;
|
||||||
|
sequence++;
|
||||||
|
tagAliasBean.tags = set;
|
||||||
|
tagAliasBean.isAliasAction = false;
|
||||||
|
TagAliasOperatorHelper.getInstance().handleAction(mContext, sequence, tagAliasBean);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void checkStoreUpdate() {
|
public void checkStoreUpdate() {
|
||||||
checkUpdateStore();
|
checkUpdateStore();
|
||||||
|
|||||||
@@ -1,20 +1,9 @@
|
|||||||
package com.mjsheng.myappstore.base;
|
package com.mjsheng.myappstore.base;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
import android.os.BatteryManager;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.PowerManager;
|
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.multidex.MultiDexApplication;
|
import androidx.multidex.MultiDexApplication;
|
||||||
@@ -22,7 +11,6 @@ import androidx.multidex.MultiDexApplication;
|
|||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.amap.api.location.AMapLocationClient;
|
|
||||||
import com.arialyy.aria.core.Aria;
|
import com.arialyy.aria.core.Aria;
|
||||||
import com.arialyy.aria.core.download.DownloadEntity;
|
import com.arialyy.aria.core.download.DownloadEntity;
|
||||||
import com.lzy.okgo.OkGo;
|
import com.lzy.okgo.OkGo;
|
||||||
@@ -37,23 +25,14 @@ import com.mjsheng.myappstore.manager.FileManager;
|
|||||||
import com.mjsheng.myappstore.manager.NetInterfaceManager;
|
import com.mjsheng.myappstore.manager.NetInterfaceManager;
|
||||||
import com.mjsheng.myappstore.network.HTTPInterface;
|
import com.mjsheng.myappstore.network.HTTPInterface;
|
||||||
import com.mjsheng.myappstore.network.URLAddress;
|
import com.mjsheng.myappstore.network.URLAddress;
|
||||||
import com.mjsheng.myappstore.network.api.newapi.GetLockStateApi;
|
|
||||||
import com.mjsheng.myappstore.receiver.BootReceiver;
|
|
||||||
import com.mjsheng.myappstore.receiver.NewAppReceiver;
|
|
||||||
import com.mjsheng.myappstore.server.GuardService;
|
|
||||||
import com.mjsheng.myappstore.server.MainService;
|
|
||||||
import com.mjsheng.myappstore.server.StepService;
|
|
||||||
import com.mjsheng.myappstore.statistics.AppInformation;
|
import com.mjsheng.myappstore.statistics.AppInformation;
|
||||||
import com.mjsheng.myappstore.statistics.StatisticsInfo;
|
import com.mjsheng.myappstore.statistics.StatisticsInfo;
|
||||||
import com.mjsheng.myappstore.utils.JGYUtils;
|
import com.mjsheng.myappstore.utils.JGYUtils;
|
||||||
import com.mjsheng.myappstore.utils.NetworkUtils;
|
|
||||||
import com.mjsheng.myappstore.utils.SystemUtils;
|
import com.mjsheng.myappstore.utils.SystemUtils;
|
||||||
import com.mjsheng.myappstore.utils.ToastUtil;
|
import com.mjsheng.myappstore.utils.ToastUtil;
|
||||||
import com.mjsheng.myappstore.utils.Utils;
|
import com.mjsheng.myappstore.utils.Utils;
|
||||||
import com.mjsheng.myappstore.utils.XAPKUtils;
|
import com.mjsheng.myappstore.utils.XAPKUtils;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -61,15 +40,13 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
import cn.jpush.android.api.JPushInterface;
|
import cn.jpush.android.api.JPushInterface;
|
||||||
import cn.jpush.android.api.JPushMessage;
|
import cn.jpush.android.api.JPushMessage;
|
||||||
|
import io.reactivex.Observable;
|
||||||
|
import io.reactivex.ObservableEmitter;
|
||||||
|
import io.reactivex.ObservableOnSubscribe;
|
||||||
import io.reactivex.Observer;
|
import io.reactivex.Observer;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
||||||
import io.reactivex.disposables.Disposable;
|
import io.reactivex.disposables.Disposable;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
|
||||||
import okhttp3.Call;
|
import okhttp3.Call;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.ResponseBody;
|
|
||||||
import rx.Observable;
|
|
||||||
import rx.functions.Action1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Administrator on 2016/2/17 0017.
|
* Created by Administrator on 2016/2/17 0017.
|
||||||
@@ -77,12 +54,10 @@ import rx.functions.Action1;
|
|||||||
|
|
||||||
//public class MyApplication extends MultiDexApplication implements Thread.UncaughtExceptionHandler {
|
//public class MyApplication extends MultiDexApplication implements Thread.UncaughtExceptionHandler {
|
||||||
public class BaseApplication extends MultiDexApplication {
|
public class BaseApplication extends MultiDexApplication {
|
||||||
private final String TAG = BaseApplication.class.getSimpleName();
|
private static final String TAG = BaseApplication.class.getSimpleName();
|
||||||
|
|
||||||
public static Context context;
|
public static Context context;
|
||||||
private static BaseApplication instance;
|
private static BaseApplication instance;
|
||||||
private Handler mHandler = new Handler();
|
|
||||||
|
|
||||||
|
|
||||||
public static Context getAppContext() {
|
public static Context getAppContext() {
|
||||||
return context;
|
return context;
|
||||||
@@ -100,6 +75,7 @@ public class BaseApplication extends MultiDexApplication {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
context = getApplicationContext();
|
||||||
if (SystemUtils.isMainProcessName(this, Process.myPid())) {
|
if (SystemUtils.isMainProcessName(this, Process.myPid())) {
|
||||||
//非主进程不初始化
|
//非主进程不初始化
|
||||||
init();
|
init();
|
||||||
@@ -111,17 +87,10 @@ public class BaseApplication extends MultiDexApplication {
|
|||||||
JGYUtils.init(this);
|
JGYUtils.init(this);
|
||||||
XAPKUtils.init(this);
|
XAPKUtils.init(this);
|
||||||
FileManager.init(this);
|
FileManager.init(this);
|
||||||
JGYUtils.getInstance().hookWebView();
|
AmapManager.init(this);
|
||||||
Configuration config = getResources().getConfiguration();
|
ToastUtil.init(this);
|
||||||
|
|
||||||
// int smallestScreenWidthDp = config.smallestScreenWidthDp;
|
JGYUtils.getInstance().hookWebView();
|
||||||
// Log.e("mjsheng", "smallestScreenWidthDp=" + smallestScreenWidthDp);
|
|
||||||
// CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
|
|
||||||
// .setDefaultFontPath("fonts/1234.ttf")
|
|
||||||
// .setDefaultFontPath("fonts/Roboto-RobotoRegular.ttf")
|
|
||||||
// .setFontAttrId(R.attr.fontPath)
|
|
||||||
// .build()
|
|
||||||
// );
|
|
||||||
|
|
||||||
// 设置开启日志,发布时请关闭日志
|
// 设置开启日志,发布时请关闭日志
|
||||||
JPushInterface.setDebugMode(true);
|
JPushInterface.setDebugMode(true);
|
||||||
@@ -130,273 +99,128 @@ public class BaseApplication extends MultiDexApplication {
|
|||||||
//JPushInterface.init(this);
|
//JPushInterface.init(this);
|
||||||
//解锁设备不需要初始化
|
//解锁设备不需要初始化
|
||||||
|
|
||||||
context = getApplicationContext();
|
|
||||||
|
|
||||||
initOKHttp();
|
initOKHttp();
|
||||||
|
|
||||||
Aria.init(this);
|
Aria.init(this);
|
||||||
Aria.get(this).getDownloadConfig().setMaxTaskNum(1);
|
Aria.get(this).getDownloadConfig().setMaxTaskNum(1);
|
||||||
Aria.get(this).getDownloadConfig().setConvertSpeed(true);
|
Aria.get(this).getDownloadConfig().setConvertSpeed(true);
|
||||||
|
|
||||||
ToastUtil.init(this);
|
|
||||||
if (!BuildConfig.DEBUG) {
|
if (!BuildConfig.DEBUG) {
|
||||||
catchException();
|
catchException();
|
||||||
}
|
}
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
// Configuration config = getResources().getConfiguration();
|
||||||
// 8.0之后需要在
|
// int smallestScreenWidthDp = config.smallestScreenWidthDp;
|
||||||
registmNewAppReceiver();
|
// Log.e("mjsheng", "smallestScreenWidthDp=" + smallestScreenWidthDp);
|
||||||
|
// CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
|
||||||
startService(new Intent(this, MainService.class));
|
// .setDefaultFontPath("fonts/1234.ttf")
|
||||||
startService(new Intent(this, StepService.class));
|
// .setDefaultFontPath("fonts/Roboto-RobotoRegular.ttf")
|
||||||
startService(new Intent(this, GuardService.class));
|
// .setFontAttrId(R.attr.fontPath)
|
||||||
}
|
// .build()
|
||||||
registerTimeReceiver();
|
// );
|
||||||
registerBatteryReceiver();
|
initAliasObservable();
|
||||||
registerNetworkReceiver();
|
initTagObservable();
|
||||||
//忽略电池优化
|
|
||||||
// ignoreBatteryOptimization(this);
|
|
||||||
AmapManager.init(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onAliasOperatorResult(JPushMessage jPushMessage) {
|
||||||
/**
|
if (jPushMessage == null) {
|
||||||
* 忽略电池优化
|
|
||||||
*/
|
|
||||||
private void ignoreBatteryOptimization(Context context) {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
||||||
|
|
||||||
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
|
||||||
|
|
||||||
boolean hasIgnored = powerManager.isIgnoringBatteryOptimizations(context.getPackageName());
|
|
||||||
// 判断当前APP是否有加入电池优化的白名单,如果没有,弹出加入电池优化的白名单的设置对话框。
|
|
||||||
if (!hasIgnored) {
|
|
||||||
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
|
||||||
intent.setData(Uri.parse("package:" + context.getPackageName()));
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private NewAppReceiver mNewAppReceiver;
|
|
||||||
|
|
||||||
private void registmNewAppReceiver() {
|
|
||||||
mNewAppReceiver = new NewAppReceiver();
|
|
||||||
IntentFilter filter = new IntentFilter();
|
|
||||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
|
||||||
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
|
|
||||||
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
|
|
||||||
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
|
|
||||||
filter.addDataScheme("package");
|
|
||||||
registerReceiver(mNewAppReceiver, filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ScreenReceiver screenReceiver;
|
|
||||||
|
|
||||||
//监听时间和日期变化
|
|
||||||
public void registerTimeReceiver() {
|
|
||||||
screenReceiver = new ScreenReceiver();
|
|
||||||
IntentFilter filter = new IntentFilter();
|
|
||||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
|
||||||
filter.addAction(Intent.ACTION_USER_PRESENT);
|
|
||||||
filter.addAction(Intent.ACTION_SCREEN_ON);
|
|
||||||
filter.addAction(Intent.ACTION_SCREEN_OFF);
|
|
||||||
filter.addAction(Intent.ACTION_USER_UNLOCKED);
|
|
||||||
filter.addAction("android.intent.action.FACTORY_RESET");
|
|
||||||
filter.addAction("android.intent.action.MASTER_CLEAR");
|
|
||||||
registerReceiver(screenReceiver, filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Long time1 = 0L;
|
|
||||||
Long time2 = 0L;
|
|
||||||
|
|
||||||
Long time3 = 0L;
|
|
||||||
Long time4 = 0L;
|
|
||||||
|
|
||||||
public class ScreenReceiver extends BroadcastReceiver {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(final Context context, Intent intent) {
|
|
||||||
String action = intent.getAction();
|
|
||||||
Log.e(TAG, "action:" + action);
|
|
||||||
if (action.equals(Intent.ACTION_SCREEN_ON)) {
|
|
||||||
long time = System.currentTimeMillis();
|
|
||||||
AMapLocationClient aMapLocationClient = AmapManager.getInstance().getLocationClient();
|
|
||||||
aMapLocationClient.stopLocation();
|
|
||||||
aMapLocationClient.startLocation();
|
|
||||||
getLockState("2", String.valueOf(time));
|
|
||||||
} else if (action.equals(Intent.ACTION_USER_PRESENT)) {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
/*在8.0以上 除了开机广播其他广播基本上没有用
|
|
||||||
*当静默安装升级时,app不会被唤醒,只有通过显示广播唤醒
|
|
||||||
* */
|
|
||||||
mHandler.postDelayed(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Intent intent1 = new Intent(BootReceiver.BOOT_COMPLETED);
|
|
||||||
intent1.setComponent(new ComponentName("com.jiaoguanyi.store", "com.mjsheng.myappstore.receiver.BootReceiver"));
|
|
||||||
// 携带数据
|
|
||||||
// intent1.putExtra("test", "我是来测 A 应用的Android 8.0 系统静态广播的测试数据");
|
|
||||||
// 启动发送广播
|
|
||||||
sendBroadcast(intent1);
|
|
||||||
|
|
||||||
time2 = System.currentTimeMillis();
|
|
||||||
if ((time2 - time1) > 60 * 1000) {
|
|
||||||
//可能会多次触发,1分钟之内不执行
|
|
||||||
//application中启动服务,startcommand执行会两次
|
|
||||||
startService(new Intent(context, MainService.class));
|
|
||||||
startService(new Intent(context, StepService.class));
|
|
||||||
startService(new Intent(context, GuardService.class));
|
|
||||||
time1 = time2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 5000);
|
|
||||||
|
|
||||||
}
|
|
||||||
} else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
|
|
||||||
mHandler.postDelayed(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
long time = System.currentTimeMillis();
|
|
||||||
getLockState("1", String.valueOf(time));
|
|
||||||
if (time3 - System.currentTimeMillis() >= 10000) {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
Intent intent1 = new Intent(BootReceiver.BOOT_COMPLETED);
|
|
||||||
intent1.setComponent(new ComponentName("com.jiaoguanyi.store", "com.mjsheng.myappstore.receiver.BootReceiver"));
|
|
||||||
sendBroadcast(intent1);
|
|
||||||
deleteScreenshots();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
time3 = System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
}, 10000);
|
|
||||||
} else if (action.equals("android.intent.action.FACTORY_RESET")
|
|
||||||
|| action.equals("android.intent.action.MASTER_CLEAR")
|
|
||||||
//MASTER_CLEAR 7.0可以监听
|
|
||||||
|| action.equals("android.intent.action.MASTER_CLEAR_NOTIFICATION")
|
|
||||||
|| action.equals("android.intent.action.FORCE_FACTORY_RESET")
|
|
||||||
) {
|
|
||||||
Log.e("ScreenReceiver", "MASTER_CLEAR");
|
|
||||||
android.os.Process.killProcess(android.os.Process.myPid());
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerBatteryReceiver() {
|
|
||||||
if (null == batteryReceiver) {
|
|
||||||
batteryReceiver = new BatteryReceiver();
|
|
||||||
}
|
|
||||||
IntentFilter filter = new IntentFilter();
|
|
||||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
|
||||||
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
|
||||||
filter.addAction(Intent.ACTION_BATTERY_LOW);
|
|
||||||
filter.addAction(Intent.ACTION_BATTERY_OKAY);
|
|
||||||
filter.addAction(Intent.ACTION_POWER_CONNECTED);
|
|
||||||
filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
|
|
||||||
registerReceiver(batteryReceiver, filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
BatteryReceiver batteryReceiver;
|
|
||||||
|
|
||||||
private class BatteryReceiver extends BroadcastReceiver {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
String action = intent.getAction();
|
|
||||||
if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
|
|
||||||
// 当前电量
|
|
||||||
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
|
|
||||||
// 最大电量
|
|
||||||
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0);
|
|
||||||
int elec = (level * 100) / scale;
|
|
||||||
Log.e(TAG, "electricity:=" + elec + "%");
|
|
||||||
if (elec == 50) {
|
|
||||||
startService(new Intent(getBaseContext(), MainService.class));
|
|
||||||
}
|
|
||||||
} else if (Intent.ACTION_POWER_CONNECTED.equals(action)
|
|
||||||
|| Intent.ACTION_POWER_DISCONNECTED.equals(action)
|
|
||||||
|| Intent.ACTION_BATTERY_LOW.equals(action)
|
|
||||||
|| Intent.ACTION_BATTERY_OKAY.equals(action)
|
|
||||||
) {
|
|
||||||
Log.e(TAG, action);
|
|
||||||
startService(new Intent(getBaseContext(), MainService.class));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerNetworkReceiver() {
|
|
||||||
if (null == netReceiver) {
|
|
||||||
netReceiver = new NetworkStateReceiver();
|
|
||||||
}
|
|
||||||
IntentFilter filter = new IntentFilter();
|
|
||||||
filter.addAction("android.net.ethernet.ETHERNET_STATE_CHANGED");
|
|
||||||
filter.addAction("android.net.ethernet.STATE_CHANGE");
|
|
||||||
filter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
|
|
||||||
filter.addAction("android.net.wifi.WIFI_STATE_CHANGED");
|
|
||||||
filter.addAction("android.net.wifi.STATE_CHANGE");
|
|
||||||
filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
|
||||||
registerReceiver(netReceiver, filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
private NetworkStateReceiver netReceiver;
|
|
||||||
|
|
||||||
|
|
||||||
public class NetworkStateReceiver extends BroadcastReceiver {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
if (intent == null || intent.getAction() == null) {
|
|
||||||
Log.e(TAG, "NetworkStateReceiver: 异常");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (NetworkUtils.isConnected(getBaseContext())) {
|
int errorCode = jPushMessage.getErrorCode();
|
||||||
Log.e(TAG, "NetworkStateReceiver: 网络连接成功");
|
onAliasResult.onResult(errorCode);
|
||||||
startService(new Intent(getBaseContext(), MainService.class));
|
|
||||||
} else {
|
|
||||||
Log.e(TAG, "NetworkStateReceiver: 网络连接失败");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteScreenshots() {
|
public static void setJpushAlias() {
|
||||||
Log.e("File", "deleteScreenshots");
|
Log.e("jiguangInterface", "30s后重新设置alias");
|
||||||
String path = getExternalFilesDir("db").getAbsolutePath();
|
JPushInterface.setAlias(context, TagAliasOperatorHelper.sequence++, Utils.getSerial());
|
||||||
File file = new File(path);
|
|
||||||
File[] files = file.listFiles();
|
|
||||||
for (File f : files) {
|
|
||||||
if (f.isFile()) {
|
|
||||||
Log.e("File", f.getAbsolutePath());
|
|
||||||
f.delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getLockState(String status, String time) {
|
public void onTagOperatorResult(JPushMessage jPushMessage) {
|
||||||
if (JGYUtils.isOfficialVersion()) {
|
if (jPushMessage == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GetLockStateApi getLockState = NetInterfaceManager.getLockState();
|
int errorCode = jPushMessage.getErrorCode();
|
||||||
getLockState.getLockState(Utils.getSerial(), status, time)
|
onTagResult.onResult(errorCode);
|
||||||
.subscribeOn(Schedulers.io())
|
}
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe(new Observer<ResponseBody>() {
|
public static void setJpushTags() {
|
||||||
|
Log.e(TAG, "30s后重新设置tags");
|
||||||
|
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() {
|
||||||
|
Log.e(TAG, "initAliasObservable: " );
|
||||||
|
Observable.create(new ObservableOnSubscribe<Integer>() {
|
||||||
|
@Override
|
||||||
|
public void subscribe(ObservableEmitter<Integer> emitter) throws Exception {
|
||||||
|
onAliasResult = new OnAliasResult() {
|
||||||
|
@Override
|
||||||
|
public void onResult(int code) {
|
||||||
|
Log.e("initAliasObservable", "onResult: " + code);
|
||||||
|
emitter.onNext(code);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}).throttleLast(30, TimeUnit.SECONDS)
|
||||||
|
.subscribe(new Observer<Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSubscribe(Disposable d) {
|
public void onSubscribe(Disposable d) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNext(ResponseBody responseBody) {
|
public void onNext(Integer integer) {
|
||||||
try {
|
Log.e("initAliasObservable", "onNext: " + integer);
|
||||||
com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(responseBody.string());
|
String s = "alias:\t";
|
||||||
int code = jsonObject.getInteger("code");
|
switch (integer) {
|
||||||
|
case 0:
|
||||||
} catch (IOException e) {
|
Log.e("jiguangInterface", s + "Alias绑定成功");
|
||||||
e.printStackTrace();
|
break;
|
||||||
|
case 6001:
|
||||||
|
Log.e("jiguangInterface", s + "无效的设置");
|
||||||
|
break;
|
||||||
|
case 6011:
|
||||||
|
Log.e("jiguangInterface", s + "短时间内操作过于频繁");
|
||||||
|
break;
|
||||||
|
case 6013:
|
||||||
|
Log.e("jiguangInterface", s + "用户设备时间轴异常");
|
||||||
|
ToastUtil.show("用户设备时间轴异常,修改后重新登陆\t" + s + "code:6013");
|
||||||
|
break;
|
||||||
|
case 6022:
|
||||||
|
Log.e("jiguangInterface", s + "alias 操作正在进行中");
|
||||||
|
break;
|
||||||
|
//需要重新设置
|
||||||
|
case 6002:
|
||||||
|
Log.e("jiguangInterface", s + "设置超时,请重试");
|
||||||
|
setJpushAlias();
|
||||||
|
break;
|
||||||
|
case 6014:
|
||||||
|
Log.e("jiguangInterface", s + "服务器繁忙,建议重试");
|
||||||
|
setJpushAlias();
|
||||||
|
break;
|
||||||
|
case 6020:
|
||||||
|
Log.e("jiguangInterface", s + "建议过一段时间再设置");
|
||||||
|
setJpushAlias();
|
||||||
|
break;
|
||||||
|
case 6024:
|
||||||
|
Log.e("jiguangInterface", s + "服务器内部错误");
|
||||||
|
setJpushAlias();
|
||||||
|
break;
|
||||||
|
case 6017:
|
||||||
|
case 6027:
|
||||||
|
Log.e("jiguangInterface", s + "别名绑定的设备数超过限制");
|
||||||
|
clean();
|
||||||
|
setJpushAlias();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -411,14 +235,31 @@ public class BaseApplication extends MultiDexApplication {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void initTagObservable() {
|
||||||
public void onTagOperatorResult(JPushMessage jPushMessage) {
|
Log.e(TAG, "initTagObservable: " );
|
||||||
if (jPushMessage == null) {
|
Observable.create(new ObservableOnSubscribe<Integer>() {
|
||||||
return;
|
@Override
|
||||||
|
public void subscribe(ObservableEmitter<Integer> emitter) {
|
||||||
|
onTagResult = new OnTagResult() {
|
||||||
|
@Override
|
||||||
|
public void onResult(int code) {
|
||||||
|
Log.e("initTagObservable", "onResult: " + code);
|
||||||
|
emitter.onNext(code);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}).throttleLast(30, TimeUnit.SECONDS)
|
||||||
|
.subscribe(new Observer<Integer>() {
|
||||||
|
@Override
|
||||||
|
public void onSubscribe(Disposable d) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNext(Integer integer) {
|
||||||
|
Log.e("initTagObservable", "onNext: " + integer);
|
||||||
String s = "tags:\t";
|
String s = "tags:\t";
|
||||||
int errorCode = jPushMessage.getErrorCode();
|
switch (integer) {
|
||||||
switch (errorCode) {
|
|
||||||
case 0:
|
case 0:
|
||||||
Log.e("jiguangInterface", s + "Tag绑定成功");
|
Log.e("jiguangInterface", s + "Tag绑定成功");
|
||||||
break;
|
break;
|
||||||
@@ -455,7 +296,6 @@ public class BaseApplication extends MultiDexApplication {
|
|||||||
case 6021:
|
case 6021:
|
||||||
Log.e("jiguangInterface", s + "tags 操作正在进行中");
|
Log.e("jiguangInterface", s + "tags 操作正在进行中");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//需要重新设置
|
//需要重新设置
|
||||||
case 6002:
|
case 6002:
|
||||||
Log.e("jiguangInterface", s + "设置超时,请重试");
|
Log.e("jiguangInterface", s + "设置超时,请重试");
|
||||||
@@ -473,91 +313,61 @@ public class BaseApplication extends MultiDexApplication {
|
|||||||
Log.e("jiguangInterface", s + "服务器内部错误");
|
Log.e("jiguangInterface", s + "服务器内部错误");
|
||||||
setJpushTags();
|
setJpushTags();
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setJpushTags() {
|
|
||||||
Log.e("jiguangInterface", "10s后重新设置tags");
|
|
||||||
Observable.timer(10000, TimeUnit.MILLISECONDS)
|
|
||||||
.observeOn(rx.android.schedulers.AndroidSchedulers.mainThread())
|
|
||||||
.subscribe(new Action1<Long>() {
|
|
||||||
@Override
|
@Override
|
||||||
public void call(Long aLong) {
|
public void onError(Throwable e) {
|
||||||
HTTPInterface.setJpushTags(context);
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete() {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static OnAliasResult onAliasResult;
|
||||||
|
|
||||||
public void onAliasOperatorResult(JPushMessage jPushMessage) {
|
interface OnAliasResult {
|
||||||
if (jPushMessage == null) {
|
void onResult(int code);
|
||||||
return;
|
|
||||||
}
|
|
||||||
String s = "alias:\t";
|
|
||||||
int errorCode = jPushMessage.getErrorCode();
|
|
||||||
switch (errorCode) {
|
|
||||||
case 0:
|
|
||||||
Log.e("jiguangInterface", s + "Alias绑定成功");
|
|
||||||
break;
|
|
||||||
case 6001:
|
|
||||||
Log.e("jiguangInterface", s + "无效的设置");
|
|
||||||
break;
|
|
||||||
case 6011:
|
|
||||||
Log.e("jiguangInterface", s + "短时间内操作过于频繁");
|
|
||||||
break;
|
|
||||||
case 6013:
|
|
||||||
Log.e("jiguangInterface", s + "用户设备时间轴异常");
|
|
||||||
ToastUtil.show("用户设备时间轴异常,修改后重新登陆\t" + s + "code:6013");
|
|
||||||
break;
|
|
||||||
case 6022:
|
|
||||||
Log.e("jiguangInterface", s + "alias 操作正在进行中");
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
//需要重新设置
|
|
||||||
case 6002:
|
|
||||||
Log.e("jiguangInterface", s + "设置超时,请重试");
|
|
||||||
setJpushAlias();
|
|
||||||
break;
|
|
||||||
case 6014:
|
|
||||||
Log.e("jiguangInterface", s + "服务器繁忙,建议重试");
|
|
||||||
setJpushAlias();
|
|
||||||
break;
|
|
||||||
case 6020:
|
|
||||||
Log.e("jiguangInterface", s + "建议过一段时间再设置");
|
|
||||||
setJpushAlias();
|
|
||||||
break;
|
|
||||||
case 6024:
|
|
||||||
Log.e("jiguangInterface", s + "服务器内部错误");
|
|
||||||
setJpushAlias();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 6017:
|
|
||||||
case 6027:
|
|
||||||
Log.e("jiguangInterface", s + "别名绑定的设备数超过限制");
|
|
||||||
clean();
|
|
||||||
setJpushAlias();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized public static void setJpushAlias() {
|
private static OnTagResult onTagResult;
|
||||||
Log.e("jiguangInterface", "10s后重新设置alias");
|
|
||||||
Observable.timer(10000, TimeUnit.MILLISECONDS)
|
interface OnTagResult {
|
||||||
.observeOn(rx.android.schedulers.AndroidSchedulers.mainThread())
|
void onResult(int code);
|
||||||
.subscribe(new Action1<Long>() {
|
}
|
||||||
|
|
||||||
|
private void catchException() {
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler(
|
||||||
|
new Thread.UncaughtExceptionHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void call(Long aLong) {
|
public void uncaughtException(Thread t, Throwable e) {
|
||||||
JPushInterface.setAlias(context, TagAliasOperatorHelper.sequence++, Utils.getSerial());
|
Log.e("捕获异常子线程:", Thread.currentThread().getName() +
|
||||||
|
"在:" + e.getStackTrace()[0].getClassName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
//下面是新增方法!
|
||||||
|
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
Looper.loop(); //会先执行这个方法,然后在执行下面的异常捕获方法!
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("捕获异常主线程:", Thread.currentThread().getName() + "在:" + e.getStackTrace()[0].getClassName());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clean() {
|
|
||||||
//alias的绑定的设备超过10个,但是alias应该是一个设备对应一个,在重置设备后jpush的regid会变动,所以需要清除
|
|
||||||
//https://docs.jiguang.cn/jpush/server/push/rest_api_v3_device/#_5
|
|
||||||
HTTPInterface.cleanJpushAlias(Utils.getSerial());
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean finished = false;
|
private boolean finished = false;
|
||||||
|
|
||||||
@@ -717,34 +527,6 @@ public class BaseApplication extends MultiDexApplication {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void catchException() {
|
|
||||||
Thread.setDefaultUncaughtExceptionHandler(
|
|
||||||
new Thread.UncaughtExceptionHandler() {
|
|
||||||
@Override
|
|
||||||
public void uncaughtException(Thread t, Throwable e) {
|
|
||||||
Log.e("捕获异常子线程:", Thread.currentThread().getName() +
|
|
||||||
"在:" + e.getStackTrace()[0].getClassName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
//下面是新增方法!
|
|
||||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
Looper.loop(); //会先执行这个方法,然后在执行下面的异常捕获方法!
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e("捕获异常主线程:", Thread.currentThread().getName() + "在:" + e.getStackTrace()[0].getClassName());
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
// public void uncaughtException(Thread thread, Throwable ex) {
|
// public void uncaughtException(Thread thread, Throwable ex) {
|
||||||
//// Log.e(TAG, ex.getMessage(), new Exception(ex));
|
//// Log.e(TAG, ex.getMessage(), new Exception(ex));
|
||||||
@@ -764,7 +546,6 @@ public class BaseApplication extends MultiDexApplication {
|
|||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
// static List<FileData> fileList = new ArrayList<>();
|
// static List<FileData> fileList = new ArrayList<>();
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -294,7 +294,7 @@ public class TagAliasOperatorHelper {
|
|||||||
setActionCache.remove(sequence);
|
setActionCache.remove(sequence);
|
||||||
String logs = getActionStr(tagAliasBean.action)+" alias success";
|
String logs = getActionStr(tagAliasBean.action)+" alias success";
|
||||||
Logger.i(TAG,logs);
|
Logger.i(TAG,logs);
|
||||||
Log.e("fht","JPush绑定成功");
|
Log.e("fht","Alias绑定成功");
|
||||||
ExampleUtil.showToast(logs, context);
|
ExampleUtil.showToast(logs, context);
|
||||||
}else{
|
}else{
|
||||||
String logs = "Failed to " + getActionStr(tagAliasBean.action)+" alias, errorCode:" + jPushMessage.getErrorCode();
|
String logs = "Failed to " + getActionStr(tagAliasBean.action)+" alias, errorCode:" + jPushMessage.getErrorCode();
|
||||||
|
|||||||
@@ -13,51 +13,50 @@ import com.mjsheng.myappstore.server.MainService;
|
|||||||
import com.mjsheng.myappstore.server.StepService;
|
import com.mjsheng.myappstore.server.StepService;
|
||||||
|
|
||||||
public class BootReceiver extends BroadcastReceiver {
|
public class BootReceiver extends BroadcastReceiver {
|
||||||
private String TAG = BootReceiver.class.getSimpleName() + "myapp";
|
private String TAG = BootReceiver.class.getSimpleName() + ":myappstore";
|
||||||
public static final String BOOT_COMPLETED = "com.jiaoguanyi.appstore.intent.action.BOOT_COMPLETED";
|
public static final String BOOT_COMPLETED = "com.jiaoguanyi.appstore.intent.action.BOOT_COMPLETED";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
Log.e(TAG, "action:" + intent.getAction());
|
Log.e(TAG, "action:" + intent.getAction());
|
||||||
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
|
switch (intent.getAction()) {
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
case Intent.ACTION_BOOT_COMPLETED:
|
||||||
String packageList = Settings.System.getString(context.getContentResolver(), "qch_launcher_icon_app");
|
String packageList = Settings.System.getString(context.getContentResolver(), "qch_launcher_icon_app");
|
||||||
if (TextUtils.isEmpty(packageList)) {
|
if (TextUtils.isEmpty(packageList)) {
|
||||||
Settings.System.putString(context.getContentResolver(), "qch_launcher_icon_app", "");
|
Settings.System.putString(context.getContentResolver(), "qch_launcher_icon_app", "");
|
||||||
}
|
}
|
||||||
HTTPInterface.updateDeviceInfo(context);
|
HTTPInterface.updateDeviceInfo(context);
|
||||||
startService(context);
|
startService(context);
|
||||||
} else if (
|
break;
|
||||||
intent.getAction().equals(BOOT_COMPLETED)
|
case BOOT_COMPLETED:
|
||||||
|| intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)
|
case Intent.ACTION_BATTERY_CHANGED:
|
||||||
|| intent.getAction().equals(Intent.ACTION_BATTERY_LOW)
|
case Intent.ACTION_BATTERY_LOW:
|
||||||
|| intent.getAction().equals(Intent.ACTION_BATTERY_OKAY)
|
case Intent.ACTION_BATTERY_OKAY:
|
||||||
|| intent.getAction().equals(Intent.ACTION_POWER_CONNECTED)
|
case Intent.ACTION_POWER_CONNECTED:
|
||||||
|| intent.getAction().equals(Intent.ACTION_POWER_DISCONNECTED)
|
case Intent.ACTION_POWER_DISCONNECTED:
|
||||||
|| intent.getAction().equals(Intent.ACTION_DATE_CHANGED)
|
case Intent.ACTION_DATE_CHANGED:
|
||||||
|| intent.getAction().equals(Intent.ACTION_TIME_TICK)
|
case Intent.ACTION_TIME_TICK:
|
||||||
|| intent.getAction().equals(Intent.ACTION_USER_PRESENT)
|
case Intent.ACTION_USER_PRESENT:
|
||||||
|| intent.getAction().equals(Intent.ACTION_SCREEN_OFF)
|
case Intent.ACTION_SCREEN_OFF:
|
||||||
|| intent.getAction().equals(Intent.ACTION_SCREEN_ON)
|
case Intent.ACTION_SCREEN_ON:
|
||||||
//测试
|
// case "android.hardware.usb.action.USB_ACCESSORY_ATTACHED":
|
||||||
// || intent.getAction().equals("android.hardware.usb.action.USB_ACCESSORY_ATTACHED")
|
// case "android.hardware.usb.action.USB_ACCESSORY_DETACHED":
|
||||||
// || intent.getAction().equals("android.hardware.usb.action.USB_ACCESSORY_DETACHED")
|
// case "android.hardware.usb.action.USB_DEVICE_ATTACHED":
|
||||||
// || intent.getAction().equals("android.hardware.usb.action.USB_DEVICE_ATTACHED")
|
// case "android.hardware.usb.action.USB_DEVICE_DETACHED":
|
||||||
// || intent.getAction().equals("android.hardware.usb.action.USB_DEVICE_DETACHED")
|
// case "android.intent.action.MEDIA_MOUNTED":
|
||||||
// || intent.getAction().equals("android.intent.action.MEDIA_MOUNTED")
|
// case "android.intent.action.MEDIA_CHECKING":
|
||||||
// || intent.getAction().equals("android.intent.action.MEDIA_CHECKING")
|
// case "android.intent.action.MEDIA_UNMOUNTED":
|
||||||
// || intent.getAction().equals("android.intent.action.MEDIA_UNMOUNTED")
|
// case "android.intent.action.MEDIA_EJECT":
|
||||||
// || intent.getAction().equals("android.intent.action.MEDIA_EJECT")
|
// case "android.intent.action.MEDIA_UNMOUNTABLE":
|
||||||
// || intent.getAction().equals("android.intent.action.MEDIA_UNMOUNTABLE")
|
// case "android.intent.action.MEDIA_REMOVED":
|
||||||
// || intent.getAction().equals("android.intent.action.MEDIA_REMOVED")
|
// case "android.intent.action.MEDIA_BAD_REMOVAL":
|
||||||
// || intent.getAction().equals("android.intent.action.MEDIA_BAD_REMOVAL")
|
|
||||||
|
|
||||||
) {
|
|
||||||
//除了USER_PRESENT应该都收不到
|
//除了USER_PRESENT应该都收不到
|
||||||
// Log.e("fht", "BootReceiver MSG:" + intent.getAction());
|
// Log.e("fht", "BootReceiver MSG:" + intent.getAction());
|
||||||
startService(context);
|
startService(context);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startService(Context context) {
|
private void startService(Context context) {
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ import android.net.Network;
|
|||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.wifi.WifiInfo;
|
import android.net.wifi.WifiInfo;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.os.BatteryManager;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.text.format.Formatter;
|
import android.text.format.Formatter;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -27,11 +29,17 @@ import androidx.annotation.Nullable;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.amap.api.location.AMapLocationClient;
|
||||||
import com.arialyy.annotations.Download;
|
import com.arialyy.annotations.Download;
|
||||||
import com.arialyy.aria.core.Aria;
|
import com.arialyy.aria.core.Aria;
|
||||||
import com.arialyy.aria.core.download.DownloadEntity;
|
import com.arialyy.aria.core.download.DownloadEntity;
|
||||||
import com.arialyy.aria.core.task.DownloadTask;
|
import com.arialyy.aria.core.task.DownloadTask;
|
||||||
|
import com.mjsheng.myappstore.manager.AmapManager;
|
||||||
|
import com.mjsheng.myappstore.network.api.newapi.GetLockStateApi;
|
||||||
|
import com.mjsheng.myappstore.receiver.BootReceiver;
|
||||||
|
import com.mjsheng.myappstore.receiver.NewAppReceiver;
|
||||||
import com.mjsheng.myappstore.utils.JGYUtils;
|
import com.mjsheng.myappstore.utils.JGYUtils;
|
||||||
|
import com.mjsheng.myappstore.utils.NetworkUtils;
|
||||||
import com.mjsheng.myappstore.utils.XAPKUtils;
|
import com.mjsheng.myappstore.utils.XAPKUtils;
|
||||||
import com.lzy.okgo.OkGo;
|
import com.lzy.okgo.OkGo;
|
||||||
import com.lzy.okgo.callback.StringCallback;
|
import com.lzy.okgo.callback.StringCallback;
|
||||||
@@ -51,8 +59,13 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import io.reactivex.Observer;
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
import io.reactivex.disposables.Disposable;
|
||||||
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import okhttp3.Call;
|
import okhttp3.Call;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
import okhttp3.ResponseBody;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,6 +76,7 @@ import okhttp3.Response;
|
|||||||
*/
|
*/
|
||||||
public class GuardService extends Service {
|
public class GuardService extends Service {
|
||||||
private final static String TAG = GuardService.class.getSimpleName();
|
private final static String TAG = GuardService.class.getSimpleName();
|
||||||
|
|
||||||
private ServiceConnection mServiceConnection = new ServiceConnection() {
|
private ServiceConnection mServiceConnection = new ServiceConnection() {
|
||||||
@Override
|
@Override
|
||||||
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
||||||
@@ -86,15 +100,10 @@ public class GuardService extends Service {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
registerNetworkReceiver();
|
|
||||||
return new KeepAliveConnection.Stub() {
|
return new KeepAliveConnection.Stub() {
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Process exec;
|
|
||||||
private LogThread logThread;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
// try {
|
// try {
|
||||||
@@ -107,9 +116,23 @@ public class GuardService extends Service {
|
|||||||
//// e.printStackTrace();
|
//// e.printStackTrace();
|
||||||
// Log.e("第一个是Logcat", e.getMessage());
|
// Log.e("第一个是Logcat", e.getMessage());
|
||||||
// }
|
// }
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
// 8.0之后需要在
|
||||||
|
registmNewAppReceiver();
|
||||||
|
startService(new Intent(this, MainService.class));
|
||||||
|
startService(new Intent(this, StepService.class));
|
||||||
|
startService(new Intent(this, GuardService.class));
|
||||||
|
}
|
||||||
|
registerTimeReceiver();
|
||||||
|
registerBatteryReceiver();
|
||||||
|
registerNetworkReceiver();
|
||||||
|
registerNetworkConnectedReceiver();
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Process exec;
|
||||||
|
private LogThread logThread;
|
||||||
|
|
||||||
//第一个是Logcat ,也就是我们想要获取的log日志
|
//第一个是Logcat ,也就是我们想要获取的log日志
|
||||||
//第二个是 -s 也就是表示过滤的意思
|
//第二个是 -s 也就是表示过滤的意思
|
||||||
//第三个就是 我们要过滤的类型 W表示warm ,我们也可以换成 D :debug, I:info,E:error等等
|
//第三个就是 我们要过滤的类型 W表示warm ,我们也可以换成 D :debug, I:info,E:error等等
|
||||||
@@ -150,7 +173,6 @@ public class GuardService extends Service {
|
|||||||
try {
|
try {
|
||||||
os.close();
|
os.close();
|
||||||
os = null;
|
os = null;
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
@@ -161,10 +183,9 @@ public class GuardService extends Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
|
Log.e(TAG, "onStartCommand: ");
|
||||||
Aria.init(this);
|
Aria.init(this);
|
||||||
Aria.get(this).getDownloadConfig().setMaxTaskNum(1);
|
|
||||||
Aria.download(this).register();
|
Aria.download(this).register();
|
||||||
// startForeground(1, new Notification());
|
|
||||||
// 绑定建立链接
|
// 绑定建立链接
|
||||||
bindService(new Intent(this, StepService.class), mServiceConnection, Context.BIND_IMPORTANT);
|
bindService(new Intent(this, StepService.class), mServiceConnection, Context.BIND_IMPORTANT);
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
@@ -176,6 +197,18 @@ public class GuardService extends Service {
|
|||||||
if (null != mNetworkChangedRecceiver) {
|
if (null != mNetworkChangedRecceiver) {
|
||||||
unregisterReceiver(mNetworkChangedRecceiver);
|
unregisterReceiver(mNetworkChangedRecceiver);
|
||||||
}
|
}
|
||||||
|
if (null != mNewAppReceiver) {
|
||||||
|
unregisterReceiver(mNewAppReceiver);
|
||||||
|
}
|
||||||
|
if (null != screenReceiver) {
|
||||||
|
unregisterReceiver(screenReceiver);
|
||||||
|
}
|
||||||
|
if (null != batteryReceiver) {
|
||||||
|
unregisterReceiver(batteryReceiver);
|
||||||
|
}
|
||||||
|
if (null != netReceiver) {
|
||||||
|
unregisterReceiver(netReceiver);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private NetworkChangedRecceiver mNetworkChangedRecceiver;
|
private NetworkChangedRecceiver mNetworkChangedRecceiver;
|
||||||
@@ -262,6 +295,205 @@ public class GuardService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private NewAppReceiver mNewAppReceiver;
|
||||||
|
|
||||||
|
private void registmNewAppReceiver() {
|
||||||
|
mNewAppReceiver = new NewAppReceiver();
|
||||||
|
IntentFilter filter = new IntentFilter();
|
||||||
|
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||||
|
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
|
||||||
|
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
|
||||||
|
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
|
||||||
|
filter.addDataScheme("package");
|
||||||
|
registerReceiver(mNewAppReceiver, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ScreenReceiver screenReceiver;
|
||||||
|
|
||||||
|
//监听时间和日期变化
|
||||||
|
public void registerTimeReceiver() {
|
||||||
|
screenReceiver = new ScreenReceiver();
|
||||||
|
IntentFilter filter = new IntentFilter();
|
||||||
|
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||||
|
filter.addAction(Intent.ACTION_USER_PRESENT);
|
||||||
|
filter.addAction(Intent.ACTION_SCREEN_ON);
|
||||||
|
filter.addAction(Intent.ACTION_SCREEN_OFF);
|
||||||
|
filter.addAction(Intent.ACTION_USER_UNLOCKED);
|
||||||
|
filter.addAction("android.intent.action.FACTORY_RESET");
|
||||||
|
filter.addAction("android.intent.action.MASTER_CLEAR");
|
||||||
|
registerReceiver(screenReceiver, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ScreenReceiver extends BroadcastReceiver {
|
||||||
|
@Override
|
||||||
|
public void onReceive(final Context context, Intent intent) {
|
||||||
|
String action = intent.getAction();
|
||||||
|
Log.e(TAG, "action:" + action);
|
||||||
|
switch (action) {
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
case Intent.ACTION_USER_PRESENT:
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
/*在8.0以上 除了开机广播其他广播基本上没有用
|
||||||
|
*当静默安装升级时,app不会被唤醒,只有通过显示广播唤醒
|
||||||
|
* */
|
||||||
|
Intent intent1 = new Intent(BootReceiver.BOOT_COMPLETED);
|
||||||
|
intent1.setComponent(new ComponentName("com.jiaoguanyi.store", "com.mjsheng.myappstore.receiver.BootReceiver"));
|
||||||
|
// 携带数据
|
||||||
|
//intent1.putExtra("test", "我是来测 A 应用的Android 8.0 系统静态广播的测试数据");
|
||||||
|
// 启动发送广播
|
||||||
|
sendBroadcast(intent1);
|
||||||
|
startService(new Intent(context, MainService.class));
|
||||||
|
startService(new Intent(context, StepService.class));
|
||||||
|
startService(new Intent(context, GuardService.class));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Intent.ACTION_SCREEN_ON: {
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
|
AMapLocationClient aMapLocationClient = AmapManager.getInstance().getLocationClient();
|
||||||
|
aMapLocationClient.stopLocation();
|
||||||
|
aMapLocationClient.startLocation();
|
||||||
|
getLockState("2", String.valueOf(time));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Intent.ACTION_SCREEN_OFF: {
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
|
getLockState("1", String.valueOf(time));
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
Intent intent1 = new Intent(BootReceiver.BOOT_COMPLETED);
|
||||||
|
intent1.setComponent(new ComponentName("com.jiaoguanyi.store", "com.mjsheng.myappstore.receiver.BootReceiver"));
|
||||||
|
sendBroadcast(intent1);
|
||||||
|
JGYUtils.getInstance().deleteScreenshots();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "android.intent.action.FACTORY_RESET":
|
||||||
|
case "android.intent.action.MASTER_CLEAR":
|
||||||
|
case "android.intent.action.MASTER_CLEAR_NOTIFICATION":
|
||||||
|
case "android.intent.action.FORCE_FACTORY_RESET":
|
||||||
|
Log.e("ScreenReceiver", "MASTER_CLEAR");
|
||||||
|
android.os.Process.killProcess(android.os.Process.myPid());
|
||||||
|
System.exit(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getLockState(String status, String time) {
|
||||||
|
if (JGYUtils.isOfficialVersion()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
GetLockStateApi getLockState = NetInterfaceManager.getLockState();
|
||||||
|
getLockState.getLockState(Utils.getSerial(), status, time)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(new Observer<ResponseBody>() {
|
||||||
|
@Override
|
||||||
|
public void onSubscribe(Disposable d) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNext(ResponseBody responseBody) {
|
||||||
|
try {
|
||||||
|
com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(responseBody.string());
|
||||||
|
int code = jsonObject.getInteger("code");
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete() {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void registerBatteryReceiver() {
|
||||||
|
if (null == batteryReceiver) {
|
||||||
|
batteryReceiver = new BatteryReceiver();
|
||||||
|
}
|
||||||
|
IntentFilter filter = new IntentFilter();
|
||||||
|
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||||
|
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
||||||
|
filter.addAction(Intent.ACTION_BATTERY_LOW);
|
||||||
|
filter.addAction(Intent.ACTION_BATTERY_OKAY);
|
||||||
|
filter.addAction(Intent.ACTION_POWER_CONNECTED);
|
||||||
|
filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
|
||||||
|
registerReceiver(batteryReceiver, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
BatteryReceiver batteryReceiver;
|
||||||
|
|
||||||
|
private class BatteryReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
String action = intent.getAction();
|
||||||
|
if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
|
||||||
|
// 当前电量
|
||||||
|
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
|
||||||
|
// 最大电量
|
||||||
|
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0);
|
||||||
|
int elec = (level * 100) / scale;
|
||||||
|
Log.e(TAG, "electricity:=" + elec + "%");
|
||||||
|
if (elec == 50) {
|
||||||
|
startService(new Intent(getBaseContext(), MainService.class));
|
||||||
|
}
|
||||||
|
} else if (Intent.ACTION_POWER_CONNECTED.equals(action)
|
||||||
|
|| Intent.ACTION_POWER_DISCONNECTED.equals(action)
|
||||||
|
|| Intent.ACTION_BATTERY_LOW.equals(action)
|
||||||
|
|| Intent.ACTION_BATTERY_OKAY.equals(action)
|
||||||
|
) {
|
||||||
|
Log.e(TAG, action);
|
||||||
|
startService(new Intent(getBaseContext(), MainService.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerNetworkConnectedReceiver() {
|
||||||
|
if (null == netReceiver) {
|
||||||
|
netReceiver = new NetworkStateReceiver();
|
||||||
|
}
|
||||||
|
IntentFilter filter = new IntentFilter();
|
||||||
|
filter.addAction("android.net.ethernet.ETHERNET_STATE_CHANGED");
|
||||||
|
filter.addAction("android.net.ethernet.STATE_CHANGE");
|
||||||
|
filter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
|
||||||
|
filter.addAction("android.net.wifi.WIFI_STATE_CHANGED");
|
||||||
|
filter.addAction("android.net.wifi.STATE_CHANGE");
|
||||||
|
filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||||
|
registerReceiver(netReceiver, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
private NetworkStateReceiver netReceiver;
|
||||||
|
|
||||||
|
|
||||||
|
public class NetworkStateReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (intent == null || intent.getAction() == null) {
|
||||||
|
Log.e(TAG, "NetworkStateReceiver: 异常");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NetworkUtils.isConnected(getBaseContext())) {
|
||||||
|
Log.e(TAG, "NetworkStateReceiver: 网络连接成功");
|
||||||
|
startService(new Intent(getBaseContext(), MainService.class));
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "NetworkStateReceiver: 网络连接失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//在这里处理任务执行中的状态,如进度进度条的刷新
|
//在这里处理任务执行中的状态,如进度进度条的刷新
|
||||||
@Download.onTaskRunning
|
@Download.onTaskRunning
|
||||||
protected void running(DownloadTask task) {
|
protected void running(DownloadTask task) {
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ public class MainService extends Service implements MainContact.MainView {
|
|||||||
|
|
||||||
private Start start;
|
private Start start;
|
||||||
|
|
||||||
|
|
||||||
private ObservableOnSubscribe<Long> subscribe = new ObservableOnSubscribe<Long>() {
|
private ObservableOnSubscribe<Long> subscribe = new ObservableOnSubscribe<Long>() {
|
||||||
@Override
|
@Override
|
||||||
public void subscribe(ObservableEmitter<Long> emitter) throws Exception {
|
public void subscribe(ObservableEmitter<Long> emitter) throws Exception {
|
||||||
@@ -67,7 +66,7 @@ public class MainService extends Service implements MainContact.MainView {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private Observer<Long> TimeObserver = new Observer<Long>() {
|
private Observer<Long> timeObserver = new Observer<Long>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSubscribe(Disposable d) {
|
public void onSubscribe(Disposable d) {
|
||||||
|
|
||||||
@@ -92,7 +91,6 @@ public class MainService extends Service implements MainContact.MainView {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
public MainService() {
|
public MainService() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -111,7 +109,7 @@ public class MainService extends Service implements MainContact.MainView {
|
|||||||
addShortcut();
|
addShortcut();
|
||||||
Observable.create(subscribe)
|
Observable.create(subscribe)
|
||||||
.throttleLast(60, TimeUnit.SECONDS)
|
.throttleLast(60, TimeUnit.SECONDS)
|
||||||
.subscribe(TimeObserver);
|
.subscribe(timeObserver);
|
||||||
// cleanLauncherCache();
|
// cleanLauncherCache();
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
}
|
}
|
||||||
@@ -123,11 +121,11 @@ public class MainService extends Service implements MainContact.MainView {
|
|||||||
mPresenter.detachView();
|
mPresenter.detachView();
|
||||||
}
|
}
|
||||||
|
|
||||||
long runningTime;
|
|
||||||
//执行所有请求的时间
|
//执行所有请求的时间
|
||||||
|
long runningTime;
|
||||||
|
|
||||||
long startCommandTime = 0;
|
|
||||||
//MainService上次执行时间
|
//MainService上次执行时间
|
||||||
|
long startCommandTime = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
@@ -146,7 +144,7 @@ public class MainService extends Service implements MainContact.MainView {
|
|||||||
// Log.e(TAG, "onStartCommand: " + (SystemClock.elapsedRealtime() - startCommandTime));
|
// Log.e(TAG, "onStartCommand: " + (SystemClock.elapsedRealtime() - startCommandTime));
|
||||||
// }
|
// }
|
||||||
start.onstar(SystemClock.elapsedRealtime());
|
start.onstar(SystemClock.elapsedRealtime());
|
||||||
Log.e("TimeObserver", "onStartCommand: " + (SystemClock.elapsedRealtime() - startCommandTime) + "ms");
|
Log.e("timeObserver", "onStartCommand: " + (SystemClock.elapsedRealtime() - startCommandTime) + "ms");
|
||||||
}
|
}
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
}
|
}
|
||||||
@@ -272,7 +270,7 @@ public class MainService extends Service implements MainContact.MainView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//锁屏管控广播
|
||||||
public class LockScreenReceiver extends BroadcastReceiver {
|
public class LockScreenReceiver extends BroadcastReceiver {
|
||||||
public static final String action_lock = "LockScreenReceiver_lockscreen";
|
public static final String action_lock = "LockScreenReceiver_lockscreen";
|
||||||
public static final String action_unlock = "LockScreenReceiver_unlockscreen";
|
public static final String action_unlock = "LockScreenReceiver_unlockscreen";
|
||||||
@@ -280,6 +278,7 @@ public class MainService extends Service implements MainContact.MainView {
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
|
Log.e("LockScreenReceiver", "onReceive: " + action);
|
||||||
if (TextUtils.isEmpty(action)) {
|
if (TextUtils.isEmpty(action)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ import java.net.URI;
|
|||||||
* @time Created by 2018/8/17 11:26
|
* @time Created by 2018/8/17 11:26
|
||||||
*/
|
*/
|
||||||
public class StepService extends Service {
|
public class StepService extends Service {
|
||||||
|
private final static String TAG = StepService.class.getSimpleName();
|
||||||
|
|
||||||
public JWebSocketClient client;
|
public JWebSocketClient client;
|
||||||
private JWebSocketClientBinder mBinder = new JWebSocketClientBinder();
|
private JWebSocketClientBinder mBinder = new JWebSocketClientBinder();
|
||||||
|
|
||||||
@@ -45,7 +47,6 @@ public class StepService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String TAG = StepService.class.getSimpleName();
|
|
||||||
private ServiceConnection mServiceConnection = new ServiceConnection() {
|
private ServiceConnection mServiceConnection = new ServiceConnection() {
|
||||||
@Override
|
@Override
|
||||||
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
||||||
@@ -75,8 +76,6 @@ public class StepService extends Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
// Utils.KillOTA(StepService.this);
|
|
||||||
// Utils.openOTA(StepService.this);
|
|
||||||
// startForeground(1, new Notification());
|
// startForeground(1, new Notification());
|
||||||
// 绑定建立链接
|
// 绑定建立链接
|
||||||
// try {
|
// try {
|
||||||
@@ -90,6 +89,7 @@ public class StepService extends Service {
|
|||||||
// } catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
// Log.e("fht", e.getMessage());
|
// Log.e("fht", e.getMessage());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
//初始化websocket
|
//初始化websocket
|
||||||
Log.e(TAG, "onStartCommand: ");
|
Log.e(TAG, "onStartCommand: ");
|
||||||
initSocketClient();
|
initSocketClient();
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.mjsheng.myappstore.utils;
|
package com.mjsheng.myappstore.utils;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.ActivityManager;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.ContextWrapper;
|
import android.content.ContextWrapper;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -8,6 +10,7 @@ import android.content.IntentFilter;
|
|||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
@@ -43,8 +46,11 @@ import java.util.Arrays;
|
|||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class JGYUtils {
|
public class JGYUtils {
|
||||||
private static final String TAG = JGYUtils.class.getSimpleName();
|
private static final String TAG = JGYUtils.class.getSimpleName();
|
||||||
|
|
||||||
private static JGYUtils sInstance;
|
private static JGYUtils sInstance;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
public static final String ROOT_URL = BuildConfig.ROOT_URL;
|
public static final String ROOT_URL = BuildConfig.ROOT_URL;
|
||||||
@@ -586,11 +592,11 @@ public class JGYUtils {
|
|||||||
int versionCode = jsonObject.get("app_version_code").getAsInt();
|
int versionCode = jsonObject.get("app_version_code").getAsInt();
|
||||||
String packageName = jsonObject.get("app_package").getAsString();
|
String packageName = jsonObject.get("app_package").getAsString();
|
||||||
String app_name = jsonObject.get("app_name").getAsString();
|
String app_name = jsonObject.get("app_name").getAsString();
|
||||||
String app_id = jsonObject.get("app_id").getAsString();
|
// String app_id = jsonObject.get("app_id").getAsString();
|
||||||
JSONObject object = new JSONObject();
|
JSONObject object = new JSONObject();
|
||||||
object.put("app_name", app_name);
|
object.put("app_name", app_name);
|
||||||
object.put("app_package", packageName);
|
object.put("app_package", packageName);
|
||||||
object.put("app_id", app_id);
|
// object.put("app_id", app_id);
|
||||||
PackageManager pm = mContext.getPackageManager();
|
PackageManager pm = mContext.getPackageManager();
|
||||||
PackageInfo packageInfo = null;
|
PackageInfo packageInfo = null;
|
||||||
try {
|
try {
|
||||||
@@ -839,4 +845,50 @@ public class JGYUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteScreenshots() {
|
||||||
|
Log.e("File", "deleteScreenshots");
|
||||||
|
String path = mContext.getExternalFilesDir("db").getAbsolutePath();
|
||||||
|
File file = new File(path);
|
||||||
|
File[] files = file.listFiles();
|
||||||
|
for (File f : files) {
|
||||||
|
if (f.isFile()) {
|
||||||
|
Log.e("File", f.getAbsolutePath());
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 忽略电池优化
|
||||||
|
*/
|
||||||
|
private void ignoreBatteryOptimization(Context context) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
|
||||||
|
PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
|
||||||
|
|
||||||
|
boolean hasIgnored = powerManager.isIgnoringBatteryOptimizations(context.getPackageName());
|
||||||
|
// 判断当前APP是否有加入电池优化的白名单,如果没有,弹出加入电池优化的白名单的设置对话框。
|
||||||
|
if (!hasIgnored) {
|
||||||
|
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
||||||
|
intent.setData(Uri.parse("package:" + context.getPackageName()));
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
mContext.startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void KillOTA() {
|
||||||
|
ActivityManager manager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
|
manager.killBackgroundProcesses("com.adups.fota");
|
||||||
|
CmdUtil.execute("am force-stop " + "com.adups.fota");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void openOTA() {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||||
|
/**知道要跳转应用的包命与目标Activity*/
|
||||||
|
ComponentName componentName = new ComponentName("com.adups.fota", "com.adups.fota.GoogleOtaClient");
|
||||||
|
intent.setComponent(componentName);
|
||||||
|
mContext.startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1155,21 +1155,6 @@ public class Utils {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void KillOTA(Context context) {
|
|
||||||
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
|
||||||
manager.killBackgroundProcesses("com.adups.fota");
|
|
||||||
CmdUtil.execute("am force-stop " + "com.adups.fota");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void openOTA(Context context) {
|
|
||||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
|
||||||
/**知道要跳转应用的包命与目标Activity*/
|
|
||||||
ComponentName componentName = new ComponentName("com.adups.fota", "com.adups.fota.GoogleOtaClient");
|
|
||||||
intent.setComponent(componentName);
|
|
||||||
context.startActivity(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getAndroiodScreenProperty(Context context) {
|
public static String getAndroiodScreenProperty(Context context) {
|
||||||
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||||
DisplayMetrics dm = new DisplayMetrics();
|
DisplayMetrics dm = new DisplayMetrics();
|
||||||
|
|||||||
Reference in New Issue
Block a user