Settings improvements

This commit is contained in:
topjohnwu 2018-02-20 00:39:17 +08:00
parent c1423ca9ad
commit 271cbddd5e
8 changed files with 41 additions and 28 deletions

View File

@ -8,7 +8,7 @@ android {
applicationId "com.topjohnwu.magisk" applicationId "com.topjohnwu.magisk"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 27 targetSdkVersion 27
versionCode 100 versionCode 103
versionName "5.6.0" versionName "5.6.0"
javaCompileOptions { javaCompileOptions {
annotationProcessorOptions { annotationProcessorOptions {

View File

@ -1,5 +1,8 @@
package com.topjohnwu.magisk; 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.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
@ -14,6 +17,7 @@ import android.widget.Toast;
import com.topjohnwu.magisk.container.Module; import com.topjohnwu.magisk.container.Module;
import com.topjohnwu.magisk.database.RepoDatabaseHelper; import com.topjohnwu.magisk.database.RepoDatabaseHelper;
import com.topjohnwu.magisk.database.SuDatabaseHelper; import com.topjohnwu.magisk.database.SuDatabaseHelper;
import com.topjohnwu.magisk.services.UpdateCheckService;
import com.topjohnwu.magisk.utils.Const; import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Topic; import com.topjohnwu.magisk.utils.Topic;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
@ -226,4 +230,23 @@ public class MagiskManager extends Shell.ContainerApp {
public void setPermissionGrantCallback(Runnable callback) { public void setPermissionGrantCallback(Runnable callback) {
permissionGrantCallback = 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);
}
}
} }

View File

@ -150,9 +150,10 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
reauth.setSummary(R.string.android_o_not_support); reauth.setSummary(R.string.android_o_not_support);
} }
// Remove fingerprint option if not possible // Disable fingerprint option if not possible
if (!FingerprintHelper.canUseFingerprint()) { if (!FingerprintHelper.canUseFingerprint()) {
suCategory.removePreference(fingerprint); fingerprint.setEnabled(false);
fingerprint.setSummary(R.string.disable_fingerprint);
} }
if (mm.magiskVersionCode >= 1440) { if (mm.magiskVersionCode >= 1440) {
@ -298,6 +299,9 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
case Const.Key.UPDATE_CHANNEL: case Const.Key.UPDATE_CHANNEL:
new CheckUpdates().exec(); new CheckUpdates().exec();
break; break;
case Const.Key.CHECK_UPDATES:
mm.setupUpdateCheck();
break;
} }
mm.loadConfig(); mm.loadConfig();
setSummary(); setSummary();

View File

@ -2,10 +2,6 @@ package com.topjohnwu.magisk;
import android.app.NotificationChannel; import android.app.NotificationChannel;
import android.app.NotificationManager; 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.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle; 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.ParallelTask;
import com.topjohnwu.magisk.asyncs.UpdateRepos; import com.topjohnwu.magisk.asyncs.UpdateRepos;
import com.topjohnwu.magisk.components.Activity; import com.topjohnwu.magisk.components.Activity;
import com.topjohnwu.magisk.services.UpdateCheckService;
import com.topjohnwu.magisk.utils.Const; import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.Shell;
@ -50,31 +45,18 @@ public class SplashActivity extends Activity {
LoadModules loadModuleTask = new LoadModules(); LoadModules loadModuleTask = new LoadModules();
if (Utils.checkNetworkStatus()) { if (Utils.checkNetworkStatus()) {
// Fire update check // Fire update check
new CheckUpdates().exec(); new CheckUpdates().exec();
// Add repo update check // Add repo update check
loadModuleTask.setCallBack(() -> new UpdateRepos(false).exec()); loadModuleTask.setCallBack(() -> new UpdateRepos(false).exec());
} }
// Magisk working as expected // Magisk working as expected
if (Shell.rootAccess() && mm.magiskVersionCode > 0) { if (Shell.rootAccess() && mm.magiskVersionCode > 0) {
// Update check service
// Add update checking service mm.setupUpdateCheck();
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);
}
// Fire asynctasks // Fire asynctasks
loadModuleTask.exec(); loadModuleTask.exec();
// Check dtbo status // Check dtbo status
Utils.patchDTBO(); Utils.patchDTBO();
} }

View File

@ -54,7 +54,7 @@ public class CheckUpdates extends ParallelTask<Void, Void, Void> {
@Override @Override
protected void onPostExecute(Void v) { protected void onPostExecute(Void v) {
MagiskManager mm = MagiskManager.get(); MagiskManager mm = MagiskManager.get();
if (showNotification && mm.prefs.getBoolean(Const.Key.UPDATE_NOTIFICATION, true)) { if (showNotification) {
if (BuildConfig.VERSION_CODE < mm.remoteManagerVersionCode) { if (BuildConfig.VERSION_CODE < mm.remoteManagerVersionCode) {
ShowUI.managerUpdateNotification(); ShowUI.managerUpdateNotification();
} else if (mm.magiskVersionCode < mm.remoteMagiskVersionCode) { } else if (mm.magiskVersionCode < mm.remoteMagiskVersionCode) {

View File

@ -120,7 +120,7 @@ public class Const {
public static final String FLASH_SET_BOOT = "boot"; public static final String FLASH_SET_BOOT = "boot";
// others // 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 UPDATE_CHANNEL = "update_channel";
public static final String CUSTOM_CHANNEL = "custom_channel"; public static final String CUSTOM_CHANNEL = "custom_channel";
public static final String BOOT_FORMAT = "boot_format"; public static final String BOOT_FORMAT = "boot_format";

View File

@ -140,6 +140,8 @@
<string name="language">Language</string> <string name="language">Language</string>
<string name="system_default">(System Default)</string> <string name="system_default">(System Default)</string>
<string name="settings_update">Update Settings</string> <string name="settings_update">Update Settings</string>
<string name="settings_check_update_title">Check Updates</string>
<string name="settings_check_update_summary">Check updates in the background periodically</string>
<string name="settings_update_channel_title">Update Channel</string> <string name="settings_update_channel_title">Update Channel</string>
<string name="settings_update_stable">Stable</string> <string name="settings_update_stable">Stable</string>
<string name="settings_update_beta">Beta</string> <string name="settings_update_beta">Beta</string>
@ -188,6 +190,7 @@
<string name="requester_summary">Root sessions will inherit its requester\'s namespace</string> <string name="requester_summary">Root sessions will inherit its requester\'s namespace</string>
<string name="isolate_summary">Each root session will have its own isolated namespace</string> <string name="isolate_summary">Each root session will have its own isolated namespace</string>
<string name="android_o_not_support">Does not support Android 8.0+</string> <string name="android_o_not_support">Does not support Android 8.0+</string>
<string name="disable_fingerprint">No fingerprints were set or no device support</string>
<!--Superuser--> <!--Superuser-->
<string name="su_request_title">Superuser Request</string> <string name="su_request_title">Superuser Request</string>

View File

@ -32,9 +32,10 @@
android:title="@string/settings_update"> android:title="@string/settings_update">
<SwitchPreference <SwitchPreference
android:key="notification" android:key="check_update"
android:title="@string/settings_notification_title" android:defaultValue="true"
android:summary="@string/settings_notification_summary" /> android:title="@string/settings_check_update_title"
android:summary="@string/settings_check_update_summary" />
<ListPreference <ListPreference
android:key="update_channel" android:key="update_channel"