update:2019.03.18

fix:增加桌面,应用市场,updatetools静默安装。增加亮屏后检测更新
add:
This commit is contained in:
2020-03-18 18:40:06 +08:00
parent e898f83670
commit f51ceac69d
8 changed files with 385 additions and 30 deletions

View File

@@ -11,12 +11,24 @@ public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.e("BootReceiver", intent.getAction());
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
Log.e("SNBootReceiver", intent.getAction());
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")
|| intent.getAction().equals("android.intent.action.BATTERY_CHANGED")
|| intent.getAction().equals("android.intent.action.BATTERY_LEVEL_CHANGED")
|| intent.getAction().equals("android.intent.action.BATTERY_LOW")
|| intent.getAction().equals("android.intent.action.BATTERY_OKAY")
|| intent.getAction().equals("android.intent.action.ACTION_POWER_CONNECTED")
|| intent.getAction().equals("android.intent.action.ACTION_POWER_DISCONNECTED")
|| intent.getAction().equals("android.intent.action.DATE_CHANGED")
|| intent.getAction().equals("android.intent.action.TIME_TICK")
|| intent.getAction().equals("android.intent.action.USER_PRESENT")
|| intent.getAction().equals("android.intent.action.ACTION_SCREEN_ON")
|| intent.getAction().equals("android.intent.action.ACTION_SCREEN_OFF")) {
// Intent i = new Intent(context, InitJpushServer.class);
// context.startService(i);
context.startService(new Intent(context, StepService.class));
context.startService(new Intent(context, GuardService.class));
context.startService(new Intent(context, MyDownloadService.class));
}
}

View File

@@ -36,24 +36,24 @@ public class MyDownloadService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
flags = START_STICKY;
return super.onStartCommand(intent, flags, startId);
}
synchronized private void CheckUpdate() {
HTTPInterface.checkUpdateByPackage(handler, this.getPackageName(), String.valueOf(BuildConfig.VERSION_CODE));
}
@Override
public void onCreate() {
super.onCreate();
startService(new Intent(this, StepService.class));
startService(new Intent(this, GuardService.class));
CheckUpdate();
CheckUpdateByPackageName("com.appstore.uiui", handler);
//静默升级应用市场
CheckUpdateByPackageName("com.android.uiuios", handler);
//静默升级桌面
CheckUpdateByPackageName("com.uiuios.updatetools", handler);
//静默升级更新工具
HTTPInterface.getAllAppPackageName(handler);
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onCreate() {
super.onCreate();
// new Thread(new Runnable() {
// @Override
@@ -72,8 +72,11 @@ public class MyDownloadService extends Service {
// }).start();
}
synchronized private void CheckUpdate() {
HTTPInterface.checkUpdateByself(handler, this.getPackageName(), String.valueOf(BuildConfig.VERSION_CODE));
}
synchronized private void CheckUpdateByPackageName(String packageName, Handler handlers) {
//检测设备信息的更新
PackageManager pm = getPackageManager();
PackageInfo packageInfo = null;
try {
@@ -124,14 +127,85 @@ public class MyDownloadService extends Service {
break;
case 202:
break;
case 300:
Bundle b = (Bundle) msg.obj;
update(b);
break;
}
}
};
private void getFile(final Bundle bundle) {
String url = bundle.getString("url");
final File path = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/");
path.mkdirs();
final File file = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/Update" + bundle.getString("versionCode") + ".apk");
final File file = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/" + url.substring(url.lastIndexOf("/") + 1));
if (file.exists() && file.isFile()) {
// AlertDialog.Builder builder = new AlertDialog.Builder(this)
// .setTitle("软件更新")
// .setIcon(R.mipmap.ic_launcher)
// .setCancelable(false)
// .setMessage("发现新版本,点击确定更新\n" + "更新内容:" + bundle.getString("content"))
// .setPositiveButton("确定", new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialogInterface, int i) {
ApkUtils.installApp(MyDownloadService.this, file.getAbsolutePath());
// dialogInterface.dismiss();
// }
// });
// AlertDialog ad = builder.create();
// ad.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
// ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失
// ad.show();
} else {
OkGo.<File>get(url)
.execute(new FileCallback("Sninfo/" + url.substring(url.lastIndexOf("/") + 1)) {
@Override
public void onSuccess(final Response<File> response) {
// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
// ApkUtils.installApkInSilence(response.body().getAbsolutePath(), Launcher.this.getPackageName());
// AlertDialog.Builder builder = new AlertDialog.Builder(MyDownloadService.this)
// .setTitle("软件更新")
// .setIcon(R.mipmap.ic_launcher)
// .setCancelable(false)
// .setMessage("发现新版本,点击确定更新\n" + "更新内容:" + bundle.getString("content"))
// .setPositiveButton("确定", new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialogInterface, int i) {
ApkUtils.installApp(MyDownloadService.this, response.body().getAbsolutePath());
// dialogInterface.dismiss();
// }
// });
// AlertDialog ad = builder.create();
// ad.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
// ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失
// ad.show();
Log.e("getFile", "download file successful,now installing");
}
@Override
public void onError(Response<File> response) {
super.onError(response);
Log.e("getFile", "File download Failure" + response.getException());
}
@Override
public void downloadProgress(Progress progress) {
super.downloadProgress(progress);
Log.e("getFile", "已下载:" + progress.currentSize + ",总大小:" + progress.totalSize + ",进度:" + progress.fraction + ",当前网速:" + progress.speed);
}
});
}
}
private void update(final Bundle bundle) {
String url = bundle.getString("url");
final File path = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/");
path.mkdirs();
final File file = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/" + url.substring(url.lastIndexOf("/") + 1));
if (file.exists() && file.isFile()) {
AlertDialog.Builder builder = new AlertDialog.Builder(this)
@@ -151,8 +225,8 @@ public class MyDownloadService extends Service {
ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失
ad.show();
} else {
OkGo.<File>get(bundle.getString("url"))
.execute(new FileCallback("Sninfo/Update" + bundle.getString("versionCode") + ".apk") {
OkGo.<File>get(url)
.execute(new FileCallback("Sninfo/" + url.substring(url.lastIndexOf("/") + 1)) {
@Override
public void onSuccess(final Response<File> response) {
// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");