From 271cbddd5e21e3dfa7d7d8b4def0966fc5ead8c6 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 20 Feb 2018 00:39:17 +0800 Subject: [PATCH] Settings improvements --- build.gradle | 2 +- .../com/topjohnwu/magisk/MagiskManager.java | 23 +++++++++++++++++++ .../topjohnwu/magisk/SettingsActivity.java | 8 +++++-- .../com/topjohnwu/magisk/SplashActivity.java | 22 ++---------------- .../topjohnwu/magisk/asyncs/CheckUpdates.java | 2 +- .../com/topjohnwu/magisk/utils/Const.java | 2 +- src/main/res/values/strings.xml | 3 +++ src/main/res/xml/app_settings.xml | 7 +++--- 8 files changed, 41 insertions(+), 28 deletions(-) diff --git a/build.gradle b/build.gradle index fb37ad9c5..540e8f61e 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ android { applicationId "com.topjohnwu.magisk" minSdkVersion 21 targetSdkVersion 27 - versionCode 100 + versionCode 103 versionName "5.6.0" javaCompileOptions { annotationProcessorOptions { diff --git a/src/main/java/com/topjohnwu/magisk/MagiskManager.java b/src/main/java/com/topjohnwu/magisk/MagiskManager.java index b59818a9e..e84a7c6df 100644 --- a/src/main/java/com/topjohnwu/magisk/MagiskManager.java +++ b/src/main/java/com/topjohnwu/magisk/MagiskManager.java @@ -1,5 +1,8 @@ package com.topjohnwu.magisk; +import android.app.job.JobInfo; +import android.app.job.JobScheduler; +import android.content.ComponentName; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; @@ -14,6 +17,7 @@ import android.widget.Toast; import com.topjohnwu.magisk.container.Module; import com.topjohnwu.magisk.database.RepoDatabaseHelper; import com.topjohnwu.magisk.database.SuDatabaseHelper; +import com.topjohnwu.magisk.services.UpdateCheckService; import com.topjohnwu.magisk.utils.Const; import com.topjohnwu.magisk.utils.Topic; import com.topjohnwu.magisk.utils.Utils; @@ -226,4 +230,23 @@ public class MagiskManager extends Shell.ContainerApp { public void setPermissionGrantCallback(Runnable callback) { permissionGrantCallback = callback; } + + public void setupUpdateCheck() { + JobScheduler scheduler = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE); + + if (prefs.getBoolean(Const.Key.CHECK_UPDATES, true)) { + if (scheduler.getAllPendingJobs().isEmpty() || + Const.UPDATE_SERVICE_VER > prefs.getInt(Const.Key.UPDATE_SERVICE_VER, -1)) { + ComponentName service = new ComponentName(this, UpdateCheckService.class); + JobInfo info = new JobInfo.Builder(Const.ID.UPDATE_SERVICE_ID, service) + .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) + .setPersisted(true) + .setPeriodic(8 * 60 * 60 * 1000) + .build(); + scheduler.schedule(info); + } + } else { + scheduler.cancel(Const.UPDATE_SERVICE_VER); + } + } } diff --git a/src/main/java/com/topjohnwu/magisk/SettingsActivity.java b/src/main/java/com/topjohnwu/magisk/SettingsActivity.java index 42c3d5a58..45ed7fd51 100644 --- a/src/main/java/com/topjohnwu/magisk/SettingsActivity.java +++ b/src/main/java/com/topjohnwu/magisk/SettingsActivity.java @@ -150,9 +150,10 @@ public class SettingsActivity extends Activity implements Topic.Subscriber { reauth.setSummary(R.string.android_o_not_support); } - // Remove fingerprint option if not possible + // Disable fingerprint option if not possible if (!FingerprintHelper.canUseFingerprint()) { - suCategory.removePreference(fingerprint); + fingerprint.setEnabled(false); + fingerprint.setSummary(R.string.disable_fingerprint); } if (mm.magiskVersionCode >= 1440) { @@ -298,6 +299,9 @@ public class SettingsActivity extends Activity implements Topic.Subscriber { case Const.Key.UPDATE_CHANNEL: new CheckUpdates().exec(); break; + case Const.Key.CHECK_UPDATES: + mm.setupUpdateCheck(); + break; } mm.loadConfig(); setSummary(); diff --git a/src/main/java/com/topjohnwu/magisk/SplashActivity.java b/src/main/java/com/topjohnwu/magisk/SplashActivity.java index 4981ea297..50c45f2b0 100644 --- a/src/main/java/com/topjohnwu/magisk/SplashActivity.java +++ b/src/main/java/com/topjohnwu/magisk/SplashActivity.java @@ -2,10 +2,6 @@ package com.topjohnwu.magisk; import android.app.NotificationChannel; import android.app.NotificationManager; -import android.app.job.JobInfo; -import android.app.job.JobScheduler; -import android.content.ComponentName; -import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Bundle; @@ -15,7 +11,6 @@ import com.topjohnwu.magisk.asyncs.LoadModules; import com.topjohnwu.magisk.asyncs.ParallelTask; import com.topjohnwu.magisk.asyncs.UpdateRepos; import com.topjohnwu.magisk.components.Activity; -import com.topjohnwu.magisk.services.UpdateCheckService; import com.topjohnwu.magisk.utils.Const; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.superuser.Shell; @@ -50,31 +45,18 @@ public class SplashActivity extends Activity { LoadModules loadModuleTask = new LoadModules(); if (Utils.checkNetworkStatus()) { - // Fire update check new CheckUpdates().exec(); - // Add repo update check loadModuleTask.setCallBack(() -> new UpdateRepos(false).exec()); } // Magisk working as expected if (Shell.rootAccess() && mm.magiskVersionCode > 0) { - - // Add update checking service - if (Const.UPDATE_SERVICE_VER > mm.prefs.getInt(Const.Key.UPDATE_SERVICE_VER, -1)) { - ComponentName service = new ComponentName(this, UpdateCheckService.class); - JobInfo info = new JobInfo.Builder(Const.ID.UPDATE_SERVICE_ID, service) - .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) - .setPersisted(true) - .setPeriodic(8 * 60 * 60 * 1000) - .build(); - ((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(info); - } - + // Update check service + mm.setupUpdateCheck(); // Fire asynctasks loadModuleTask.exec(); - // Check dtbo status Utils.patchDTBO(); } diff --git a/src/main/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java b/src/main/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java index 575f26aa4..3652742c3 100644 --- a/src/main/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java +++ b/src/main/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java @@ -54,7 +54,7 @@ public class CheckUpdates extends ParallelTask { @Override protected void onPostExecute(Void v) { MagiskManager mm = MagiskManager.get(); - if (showNotification && mm.prefs.getBoolean(Const.Key.UPDATE_NOTIFICATION, true)) { + if (showNotification) { if (BuildConfig.VERSION_CODE < mm.remoteManagerVersionCode) { ShowUI.managerUpdateNotification(); } else if (mm.magiskVersionCode < mm.remoteMagiskVersionCode) { diff --git a/src/main/java/com/topjohnwu/magisk/utils/Const.java b/src/main/java/com/topjohnwu/magisk/utils/Const.java index 42eb6c4f8..4643f864e 100644 --- a/src/main/java/com/topjohnwu/magisk/utils/Const.java +++ b/src/main/java/com/topjohnwu/magisk/utils/Const.java @@ -120,7 +120,7 @@ public class Const { public static final String FLASH_SET_BOOT = "boot"; // others - public static final String UPDATE_NOTIFICATION = "notification"; + public static final String CHECK_UPDATES = "check_update"; public static final String UPDATE_CHANNEL = "update_channel"; public static final String CUSTOM_CHANNEL = "custom_channel"; public static final String BOOT_FORMAT = "boot_format"; diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index a2f969de0..fa8504dde 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -140,6 +140,8 @@ Language (System Default) Update Settings + Check Updates + Check updates in the background periodically Update Channel Stable Beta @@ -188,6 +190,7 @@ Root sessions will inherit its requester\'s namespace Each root session will have its own isolated namespace Does not support Android 8.0+ + No fingerprints were set or no device support Superuser Request diff --git a/src/main/res/xml/app_settings.xml b/src/main/res/xml/app_settings.xml index 677828165..663c6aec8 100644 --- a/src/main/res/xml/app_settings.xml +++ b/src/main/res/xml/app_settings.xml @@ -32,9 +32,10 @@ android:title="@string/settings_update"> + android:key="check_update" + android:defaultValue="true" + android:title="@string/settings_check_update_title" + android:summary="@string/settings_check_update_summary" />