update:2020.06.12
fix:更换图标 add:增加连接上wifi之后启动管控功能
This commit is contained in:
@@ -6,9 +6,16 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.multidex.MultiDexApplication;
|
||||
import android.text.TextUtils;
|
||||
@@ -33,12 +40,12 @@ import com.mjsheng.myappstore.jpush.TagAliasOperatorHelper;
|
||||
import com.mjsheng.myappstore.network.HTTPInterface;
|
||||
import com.mjsheng.myappstore.server.GuardService;
|
||||
import com.mjsheng.myappstore.server.InitJpushServer;
|
||||
import com.mjsheng.myappstore.server.StepService;
|
||||
import com.mjsheng.myappstore.utils.Configure;
|
||||
import com.mjsheng.myappstore.utils.MySQLData;
|
||||
import com.mjsheng.myappstore.utils.ToastUtil;
|
||||
import com.mjsheng.myappstore.utils.Utils;
|
||||
import com.mjsheng.myappstore.utils.update.ToastTool;
|
||||
import com.tianma.netdetector.lib.NetStateChangeReceiver;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
@@ -48,7 +55,6 @@ import org.lzh.framework.updatepluginlib.model.CheckEntity;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
@@ -137,7 +143,6 @@ public class MyApplication extends MultiDexApplication {
|
||||
Aria.get(this).getDownloadConfig().setMaxTaskNum(1);
|
||||
Aria.get(this).getDownloadConfig().setConvertSpeed(true);
|
||||
|
||||
NetStateChangeReceiver.registerReceiver(this);
|
||||
|
||||
ToastUtil.init(this);
|
||||
if (!BuildConfig.DEBUG) {
|
||||
@@ -147,6 +152,27 @@ public class MyApplication extends MultiDexApplication {
|
||||
//8.0之后需要在
|
||||
registerTimeReceiver();
|
||||
}
|
||||
ignoreBatteryOptimization(this);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 忽略电池优化
|
||||
*/
|
||||
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 receiver receiver;
|
||||
@@ -181,6 +207,7 @@ public class MyApplication extends MultiDexApplication {
|
||||
//可能会多次触发,1分钟之内不执行
|
||||
//application中启动服务,startcommand执行会两次
|
||||
startService(new Intent(context, InitJpushServer.class));
|
||||
startService(new Intent(context, StepService.class));
|
||||
startService(new Intent(context, GuardService.class));
|
||||
time1 = time2;
|
||||
Log.e("fht", "onReceive");
|
||||
@@ -192,6 +219,8 @@ public class MyApplication extends MultiDexApplication {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void onTagOperatorResult(JPushMessage jPushMessage) {
|
||||
if (jPushMessage == null) {
|
||||
return;
|
||||
@@ -570,7 +599,7 @@ public class MyApplication extends MultiDexApplication {
|
||||
result = result + "," + store;
|
||||
}
|
||||
Settings.System.putString(context.getContentResolver(), "qch_app_forbid", result);
|
||||
Log.e("mjsheng", "qch_app_forbid :"+result);
|
||||
Log.e("mjsheng", "qch_app_forbid :" + result);
|
||||
} else {
|
||||
Log.e("mjsheng", "writeAppPackageList is null:");
|
||||
Settings.System.putString(context.getContentResolver(), "qch_app_forbid", appstore + "," + store);
|
||||
@@ -623,12 +652,6 @@ public class MyApplication extends MultiDexApplication {
|
||||
//
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onTerminate() {
|
||||
super.onTerminate();
|
||||
// 取消BroadcastReceiver注册
|
||||
NetStateChangeReceiver.unregisterReceiver(this);
|
||||
}
|
||||
|
||||
// static List<FileData> fileList = new ArrayList<>();
|
||||
//
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mjsheng.myappstore.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
@@ -11,6 +12,7 @@ import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@@ -18,12 +20,17 @@ import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.PersistableBundle;
|
||||
import android.os.PowerManager;
|
||||
import android.os.SystemClock;
|
||||
import android.provider.Settings;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.Layout;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
@@ -54,6 +61,7 @@ import com.mjsheng.myappstore.bean.JsonCallback;
|
||||
import com.mjsheng.myappstore.bean.LzyResponse;
|
||||
import com.mjsheng.myappstore.bean.NetAndLaunchBean;
|
||||
import com.mjsheng.myappstore.bean.NetAndLaunchData;
|
||||
import com.mjsheng.myappstore.bean.StudentsInfo;
|
||||
import com.mjsheng.myappstore.bean.UploadAppInfo;
|
||||
import com.mjsheng.myappstore.bean.UserInfo;
|
||||
import com.mjsheng.myappstore.comm.CommonDatas;
|
||||
@@ -83,8 +91,6 @@ import com.mjsheng.myappstore.utils.update.NotificationDownloadCreator;
|
||||
import com.mjsheng.myappstore.utils.update.OkhttpCheckWorker;
|
||||
import com.mjsheng.myappstore.utils.update.ToastCallback;
|
||||
import com.mjsheng.myappstore.utils.update.ToastTool;
|
||||
import com.tianma.netdetector.lib.NetStateChangeObserver;
|
||||
import com.tianma.netdetector.lib.NetworkType;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.lzh.framework.updatepluginlib.UpdateBuilder;
|
||||
@@ -122,7 +128,7 @@ import static com.mjsheng.myappstore.jpush.TagAliasOperatorHelper.ACTION_SET;
|
||||
import static com.mjsheng.myappstore.jpush.TagAliasOperatorHelper.TagAliasBean;
|
||||
import static com.mjsheng.myappstore.jpush.TagAliasOperatorHelper.sequence;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements NetStateChangeObserver {
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private ToastCallback callback;
|
||||
private long mPreClickTime;
|
||||
@@ -132,8 +138,10 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
private DownloadManager downloadManager;
|
||||
private ImageView imageView;
|
||||
private TextView tv_devsn, tv_devmac, tv_version;
|
||||
private TextView tv_class, tv_number, tv_name;
|
||||
private int DeviceInfo;
|
||||
|
||||
private RelativeLayout checkupdate;
|
||||
private ImageView back;
|
||||
//jiguang
|
||||
public static boolean isForeground = false;
|
||||
//for receive customer msg from jpush server
|
||||
@@ -287,6 +295,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||
// }
|
||||
requestPermission();
|
||||
acquireWakeLock();
|
||||
registerMessageReceiver(); // used for receive msg
|
||||
// HTTPInterface.checkDevicesInfo(handler);
|
||||
startService(new Intent(MainActivity.this, MyDownloadService.class));
|
||||
@@ -353,15 +362,49 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
checkupdate = findViewById(R.id.checkupdate);
|
||||
checkupdate.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
continuousClick(COUNTS, DURATION);
|
||||
}
|
||||
});
|
||||
imageView = findViewById(R.id.imageView);
|
||||
tv_devsn = findViewById(R.id.tv_devsn);
|
||||
tv_devsn.setText("设备SN\t\t" + Utils.getSerial());
|
||||
tv_devsn.setText(Utils.getSerial());
|
||||
tv_devmac = findViewById(R.id.tv_devmac);
|
||||
tv_devmac.setText("MAC地址\t\t" + com.blankj.utilcode.util.DeviceUtils.getMacAddress());
|
||||
tv_devmac.setText(com.blankj.utilcode.util.DeviceUtils.getMacAddress());
|
||||
tv_version = findViewById(R.id.version);
|
||||
tv_version.setText("版本:" + BuildConfig.VERSION_NAME);
|
||||
tv_version.setText(BuildConfig.VERSION_NAME);
|
||||
tv_class = findViewById(R.id.tv_class);
|
||||
tv_number = findViewById(R.id.tv_number);
|
||||
tv_name = findViewById(R.id.tv_name);
|
||||
back = findViewById(R.id.back);
|
||||
back.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
lazyExit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
final static int COUNTS = 5;// 点击次数
|
||||
final static long DURATION = 1000;// 规定有效时间
|
||||
long[] mHits = new long[COUNTS];
|
||||
|
||||
private void continuousClick(int count, long time) {
|
||||
//每次点击时,数组向前移动一位
|
||||
System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
|
||||
//为数组最后一位赋值
|
||||
mHits[mHits.length - 1] = SystemClock.uptimeMillis();
|
||||
if (mHits[0] >= (SystemClock.uptimeMillis() - DURATION)) {
|
||||
mHits = new long[COUNTS];//重新初始化数组
|
||||
ToastUtil.show("正在检查更新");
|
||||
HTTPInterface.checkUpdate(mHandler, BuildConfig.APPLICATION_ID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void initData() {
|
||||
Log.e("mjhsneg", "gagagag--------------------------" + Utils.getSerial());
|
||||
getLockedState();
|
||||
@@ -389,8 +432,8 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
}
|
||||
|
||||
private void setImageAndText(ImageView imageView, String text) {
|
||||
Bitmap bitmap = Utils.createQRImage(Utils.getSn(), 250, 250);
|
||||
imageView.setImageBitmap(bitmap);
|
||||
// Bitmap bitmap = Utils.createQRImage(Utils.getSn(), 250, 250);
|
||||
// imageView.setImageBitmap(bitmap);
|
||||
}
|
||||
|
||||
|
||||
@@ -465,6 +508,37 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
}
|
||||
|
||||
|
||||
private PowerManager.WakeLock wakeLock = null;
|
||||
private static final String mWakeLockName = "BackupService";
|
||||
|
||||
/**
|
||||
* 获取电源锁,保持该服务在屏幕熄灭时仍然获取CPU时,保持运行
|
||||
*/
|
||||
private synchronized void acquireWakeLock() {
|
||||
if (null == wakeLock) {
|
||||
PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
|
||||
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
|
||||
| PowerManager.ON_AFTER_RELEASE, mWakeLockName);
|
||||
if (null != wakeLock) {
|
||||
Log.e("fht", "acquireWakeLock!");
|
||||
wakeLock.acquire();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 释放设备电源锁
|
||||
*/
|
||||
private synchronized void releaseWakeLock() {
|
||||
if (null != wakeLock) {
|
||||
Log.e("fht", "releaseWakeLock!");
|
||||
wakeLock.release();
|
||||
wakeLock = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean locked = false;
|
||||
|
||||
public void getLockedState() {
|
||||
@@ -562,6 +636,33 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
break;
|
||||
case -200:
|
||||
Log.e("fht", "no update");
|
||||
break;
|
||||
case 2:
|
||||
StudentsInfo info = com.alibaba.fastjson.JSONObject.parseObject(String.valueOf(msg.obj), StudentsInfo.class);
|
||||
if (null != info) {
|
||||
if (info.getBatch().equals("")) {
|
||||
tv_class.setText("暂无信息");
|
||||
} else {
|
||||
tv_class.setText(info.getBatch());
|
||||
}
|
||||
if (info.getSno().equals("")) {
|
||||
tv_number.setText("暂无信息");
|
||||
} else {
|
||||
tv_number.setText(info.getSno());
|
||||
}
|
||||
if (info.getRealname().equals("")) {
|
||||
tv_name.setText("暂无信息");
|
||||
} else {
|
||||
tv_name.setText(info.getRealname());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case -2:
|
||||
tv_class.setText("暂无信息");
|
||||
tv_number.setText("暂无信息");
|
||||
tv_name.setText("暂无信息");
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -589,7 +690,8 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
.setExtendField(object.toJSONString())
|
||||
.create(); //启动下载}
|
||||
} else {
|
||||
Log.e("fht", "无需更新");
|
||||
// ToastUtil.show("已是最新版本");
|
||||
Log.e("fht", "已是最新版本");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -628,7 +730,37 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
loadHeadImg(Configure.HTTP_TAG_HOME_PAGE_URL);
|
||||
getLockedState();
|
||||
// MyApplication.getInstance().getWhitePackageList();
|
||||
getInfo(mHandler);
|
||||
}
|
||||
|
||||
private void getInfo(final Handler handler) {
|
||||
OkGo.post(Configure.GET_STUDENTS_INFO)
|
||||
.params("sn", Utils.getSerial())
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(String s, Call call, Response response) {
|
||||
try {
|
||||
LzyResponse<StudentsInfo> lzyResponse = (LzyResponse<StudentsInfo>) JSON.parseObject(s, LzyResponse.class);
|
||||
Message message = new Message();
|
||||
if (lzyResponse.code == 200) {
|
||||
message.what = 2;
|
||||
message.obj = lzyResponse.data;
|
||||
handler.sendMessage(message);
|
||||
} else {
|
||||
handler.sendEmptyMessage(-2);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("fht", "getInfo:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Call call, Response response, Exception e) {
|
||||
super.onError(call, response, e);
|
||||
Log.e("onError", "error");
|
||||
}
|
||||
|
||||
});// 请求方式和请求url
|
||||
}
|
||||
|
||||
private void loadHeadImg(String URL) {
|
||||
@@ -1579,18 +1711,4 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onNetDisconnected() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNetConnected(NetworkType networkType) {
|
||||
initJpush();
|
||||
Aria.download(this).resumeAllTask();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONException;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.lzy.okgo.callback.StringCallback;
|
||||
import com.mjsheng.myappstore.MyApplication;
|
||||
@@ -562,6 +563,7 @@ public class HTTPInterface {
|
||||
int code = jsonObject.getInteger("code");
|
||||
String msg = jsonObject.getString("msg");
|
||||
String data = jsonObject.getString("data");
|
||||
Log.e("setHideDesktopIcon", data);
|
||||
ApkUtils.showAllAPP(context);
|
||||
if (code == 200) {
|
||||
if (data != null && !"".equals(data)) {
|
||||
@@ -584,7 +586,7 @@ public class HTTPInterface {
|
||||
});
|
||||
}
|
||||
|
||||
synchronized public static void getNetAndLaunchSetting(final Context context) {
|
||||
synchronized public static void getNetAndLaunchSetting(final Context context) {
|
||||
OkGo.post(Configure.NET_AND_LAUNCH_API)
|
||||
.params("key", Configure.HTTP_KEY)
|
||||
.params("sn", Utils.getSerial())
|
||||
@@ -593,7 +595,12 @@ public class HTTPInterface {
|
||||
public void onSuccess(String s, Call call, Response response) {
|
||||
NetAndLaunchBean netAndLaunchBeanList = JSON.parseObject(s, NetAndLaunchBean.class);
|
||||
LogUtils.e(s);
|
||||
setNetAndlaunch(netAndLaunchBeanList, context);
|
||||
switch (netAndLaunchBeanList.getCode()) {
|
||||
case 200:
|
||||
setNetAndlaunch(netAndLaunchBeanList, context);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,6 +35,8 @@ public class BootReceiver extends BroadcastReceiver {
|
||||
startService(context);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void startService(Context context) {
|
||||
|
||||
@@ -444,13 +444,16 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<ResponseBody>() {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable param1Throwable) {
|
||||
Log.e("mjsheng", "DeselectIDApi=onError:");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(ResponseBody param1ResponseBody) {
|
||||
try {
|
||||
String str1;
|
||||
|
||||
@@ -8,12 +8,18 @@ package com.mjsheng.myappstore.server;
|
||||
*/
|
||||
|
||||
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.net.ConnectivityManager;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.IBinder;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.format.Formatter;
|
||||
import android.util.Log;
|
||||
@@ -25,16 +31,12 @@ import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.task.DownloadTask;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
import com.mjsheng.myappstore.KeepAliveConnection;
|
||||
import com.mjsheng.myappstore.MyApplication;
|
||||
import com.mjsheng.myappstore.utils.ApkUtils;
|
||||
import com.mjsheng.myappstore.utils.ServiceAliveUtils;
|
||||
import com.mjsheng.myappstore.utils.ToastUtil;
|
||||
import com.tianma.netdetector.lib.NetStateChangeObserver;
|
||||
import com.tianma.netdetector.lib.NetworkType;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -44,7 +46,7 @@ import java.util.List;
|
||||
* @author LiGuangMin
|
||||
* @time Created by 2018/8/17 11:27
|
||||
*/
|
||||
public class GuardService extends Service implements NetStateChangeObserver {
|
||||
public class GuardService extends Service {
|
||||
private final static String TAG = GuardService.class.getSimpleName();
|
||||
private ServiceConnection mServiceConnection = new ServiceConnection() {
|
||||
@Override
|
||||
@@ -69,8 +71,10 @@ public class GuardService extends Service implements NetStateChangeObserver {
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
registerNetworkReceiver();
|
||||
return new KeepAliveConnection.Stub() {
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,16 +84,115 @@ public class GuardService extends Service implements NetStateChangeObserver {
|
||||
Aria.init(this);
|
||||
Aria.get(this).getDownloadConfig().setMaxTaskNum(1);
|
||||
|
||||
|
||||
Aria.download(this).register();
|
||||
|
||||
|
||||
// startForeground(1, new Notification());
|
||||
// 绑定建立链接
|
||||
bindService(new Intent(this, StepService.class), mServiceConnection, Context.BIND_IMPORTANT);
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (null != mNetworkChangedRecceiver) {
|
||||
unregisterReceiver(mNetworkChangedRecceiver);
|
||||
}
|
||||
}
|
||||
|
||||
private NetworkChangedRecceiver mNetworkChangedRecceiver;
|
||||
|
||||
public void registerNetworkReceiver() {
|
||||
mNetworkChangedRecceiver = new NetworkChangedRecceiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||
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(mNetworkChangedRecceiver, filter);
|
||||
}
|
||||
|
||||
Long time1 = 0L;
|
||||
Long time2 = 0L;
|
||||
|
||||
public class NetworkChangedRecceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
|
||||
//获得ConnectivityManager对象
|
||||
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
//获取ConnectivityManager对象对应的NetworkInfo对象
|
||||
//获取WIFI连接的信息
|
||||
NetworkInfo wifiNetworkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
//获取移动数据连接的信息
|
||||
NetworkInfo dataNetworkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
|
||||
if (wifiNetworkInfo.isConnected() && dataNetworkInfo.isConnected()) {
|
||||
Log.e("fht", "WIFI已连接,移动数据已连接");
|
||||
} else if (wifiNetworkInfo.isConnected() && !dataNetworkInfo.isConnected()) {
|
||||
Log.e("fht", "WIFI已连接,移动数据已断开");
|
||||
} else if (!wifiNetworkInfo.isConnected() && dataNetworkInfo.isConnected()) {
|
||||
Log.e("fht", "WIFI已连接,移动数据已连接");
|
||||
} else {
|
||||
Log.e("fht", "WIFI已连接,移动数据已断开");
|
||||
}
|
||||
//API大于23时使用下面的方式进行网络监听
|
||||
} else {
|
||||
//获得ConnectivityManager对象
|
||||
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
//获取所有网络连接的信息
|
||||
Network[] networks = connMgr.getAllNetworks();
|
||||
//用于存放网络连接信息
|
||||
StringBuilder sb = new StringBuilder();
|
||||
//通过循环将网络信息逐个取出来
|
||||
for (int i = 0; i < networks.length; i++) {
|
||||
//获取ConnectivityManager对象对应的NetworkInfo对象
|
||||
NetworkInfo networkInfo = connMgr.getNetworkInfo(networks[i]);
|
||||
if (null != networkInfo) {
|
||||
sb.append(networkInfo.getTypeName() + " connect is " + networkInfo.isConnected());
|
||||
}
|
||||
}
|
||||
Log.e("fht", sb.toString());
|
||||
}
|
||||
if (intent.getAction().equals(WifiManager.RSSI_CHANGED_ACTION)) {
|
||||
Log.e("fht", "wifi信号强度变化");
|
||||
}
|
||||
//wifi连接上与否
|
||||
if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
|
||||
|
||||
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
|
||||
if (info.getState().equals(NetworkInfo.State.DISCONNECTED)) {
|
||||
Log.e("fht", "wifi断开");
|
||||
} else if (info.getState().equals(NetworkInfo.State.CONNECTED)) {
|
||||
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
||||
//获取当前wifi名称
|
||||
Log.e("fht", "连接到网络 " + wifiInfo.getSSID());
|
||||
time2 = System.currentTimeMillis();
|
||||
if ((time2 - time1) > 60 * 1000) {
|
||||
//可能会多次触发,1分钟之内不执行
|
||||
//application中启动服务,startcommand执行会两次
|
||||
startService(new Intent(context, InitJpushServer.class));
|
||||
Aria.download(this).resumeAllTask();
|
||||
time1 = time2;
|
||||
Log.e("fht", "onReceive");
|
||||
}
|
||||
}
|
||||
}
|
||||
//wifi打开与否
|
||||
if (intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
|
||||
int wifistate = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_DISABLED);
|
||||
if (wifistate == WifiManager.WIFI_STATE_DISABLED) {
|
||||
Log.e("fht", "系统关闭wifi");
|
||||
} else if (wifistate == WifiManager.WIFI_STATE_ENABLED) {
|
||||
Log.e("fht", "系统开启wifi");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//在这里处理任务执行中的状态,如进度进度条的刷新
|
||||
@Download.onTaskRunning
|
||||
@@ -147,15 +250,6 @@ public class GuardService extends Service implements NetStateChangeObserver {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNetDisconnected() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNetConnected(NetworkType networkType) {
|
||||
Aria.download(this).resumeAllTask();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -573,6 +573,7 @@ public class InitJpushServer extends Service {
|
||||
}
|
||||
|
||||
Utils.writeDisableUpdateList(this, upgrade_not.split(","), upgrade_ok.split(","));
|
||||
LogUtils.e("UpdateList:upgrade_not:" + upgrade_not + "-----------upgrade_ok:" + upgrade_ok);
|
||||
|
||||
LogUtils.e("launch:" + launch + "-----------net_ok:" + net_ok + "-----------net_not:" + net_not);
|
||||
boolean qch_app_power_on = Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_power_on", launch);
|
||||
|
||||
@@ -204,4 +204,6 @@ public class Configure {
|
||||
//获取隐藏桌面图标
|
||||
public final static String NET_AND_LAUNCH_API = HTTP_TAG_HEAD_NEW + "automatic/get";
|
||||
//获取应用升级自启
|
||||
public static final String GET_STUDENTS_INFO = HTTP_TAG_HEAD_NEW + "Sn/getStudent";
|
||||
|
||||
}
|
||||
|
||||
@@ -919,8 +919,14 @@ public class Utils {
|
||||
|
||||
static synchronized public boolean writeDisableUpdateList(Context context, String[] banList, String[] notList) {
|
||||
String now = Settings.System.getString(context.getContentResolver(), "qch_app_forbid");
|
||||
String[] nowList = now.split(",");
|
||||
List<String> allList = new ArrayList<>(Arrays.asList(nowList));//已经写入的列表
|
||||
String[] nowList;
|
||||
List<String> allList;
|
||||
if (now == null || now.equalsIgnoreCase("")) {
|
||||
allList = new ArrayList<>();
|
||||
} else {
|
||||
nowList = now.split(",");
|
||||
allList = new ArrayList<>(Arrays.asList(nowList));//已经写入的列表
|
||||
}
|
||||
boolean writeSucceed = false;
|
||||
if (banList != null && banList.length > 0) {
|
||||
for (String s : banList) {
|
||||
@@ -944,7 +950,7 @@ public class Utils {
|
||||
list = list.substring(0, list.length() - 1);
|
||||
Log.e("fht", list);
|
||||
writeSucceed = Settings.System.putString(context.getContentResolver(), "qch_app_forbid", list);
|
||||
Log.e("fht","qch_app_forbid:"+list);
|
||||
Log.e("fht", "qch_app_forbid:" + list);
|
||||
} else {
|
||||
writeSucceed = Settings.System.putString(context.getContentResolver(), "qch_app_forbid", "Invalid");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user