mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-25 23:47:39 +00:00
Re-organize application startup
This commit is contained in:
parent
1b1394cf5d
commit
ea884e7fa1
@ -260,6 +260,7 @@ public class MagiskFragment extends Fragment
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
magiskManager.getMagiskInfo();
|
||||
updateUI();
|
||||
|
||||
magiskUpdateText.setText(R.string.checking_for_updates);
|
||||
@ -304,7 +305,6 @@ public class MagiskFragment extends Fragment
|
||||
|
||||
private void updateUI() {
|
||||
((MainActivity) getActivity()).checkHideSection();
|
||||
magiskManager.updateMagiskInfo();
|
||||
|
||||
final int ROOT = 0x1, NETWORK = 0x2, UPTODATE = 0x4;
|
||||
int status = 0;
|
||||
|
@ -117,6 +117,16 @@ public class MagiskManager extends Application {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
new File(getApplicationInfo().dataDir).mkdirs(); /* Create the app data directory */
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
suDB = new SuDatabaseHelper(this);
|
||||
repoDB = new RepoDatabaseHelper(this);
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
public void setLocale() {
|
||||
String localeTag = prefs.getString("locale", "");
|
||||
if (localeTag.isEmpty()) {
|
||||
@ -130,17 +140,31 @@ public class MagiskManager extends Application {
|
||||
res.updateConfiguration(config, res.getDisplayMetrics());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
new File(getApplicationInfo().dataDir).mkdirs(); /* Create the app data directory */
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
shell = Shell.getShell();
|
||||
suDB = new SuDatabaseHelper(this);
|
||||
repoDB = new RepoDatabaseHelper(this);
|
||||
private void loadConfig() {
|
||||
// Locale
|
||||
defaultLocale = Locale.getDefault();
|
||||
setLocale();
|
||||
new LoadLocale(this).exec();
|
||||
|
||||
isDarkTheme = prefs.getBoolean("dark_theme", false);
|
||||
if (BuildConfig.DEBUG) {
|
||||
devLogging = prefs.getBoolean("developer_logging", false);
|
||||
shellLogging = prefs.getBoolean("shell_logging", false);
|
||||
} else {
|
||||
devLogging = false;
|
||||
shellLogging = false;
|
||||
}
|
||||
|
||||
// su
|
||||
suRequestTimeout = Utils.getPrefsInt(prefs, "su_request_timeout", 10);
|
||||
suResponseType = Utils.getPrefsInt(prefs, "su_auto_response", 0);
|
||||
suNotificationType = Utils.getPrefsInt(prefs, "su_notification", 1);
|
||||
suReauth = prefs.getBoolean("su_reauth", false);
|
||||
suAccessState = suDB.getSettings(SuDatabaseHelper.ROOT_ACCESS, 3);
|
||||
multiuserMode = suDB.getSettings(SuDatabaseHelper.MULTIUSER_MODE, 0);
|
||||
suNamespaceMode = suDB.getSettings(SuDatabaseHelper.MNT_NS, 1);
|
||||
|
||||
updateNotification = prefs.getBoolean("notification", true);
|
||||
}
|
||||
|
||||
public void toast(String msg, int duration) {
|
||||
@ -152,18 +176,10 @@ public class MagiskManager extends Application {
|
||||
}
|
||||
|
||||
public void init() {
|
||||
isDarkTheme = prefs.getBoolean("dark_theme", false);
|
||||
if (BuildConfig.DEBUG) {
|
||||
devLogging = prefs.getBoolean("developer_logging", false);
|
||||
shellLogging = prefs.getBoolean("shell_logging", false);
|
||||
} else {
|
||||
devLogging = false;
|
||||
shellLogging = false;
|
||||
}
|
||||
initSU();
|
||||
updateMagiskInfo();
|
||||
getMagiskInfo();
|
||||
updateBlockInfo();
|
||||
// Initialize prefs
|
||||
|
||||
// Write back default values
|
||||
prefs.edit()
|
||||
.putBoolean("dark_theme", isDarkTheme)
|
||||
.putBoolean("magiskhide", magiskHide)
|
||||
@ -192,31 +208,14 @@ public class MagiskManager extends Application {
|
||||
|
||||
}
|
||||
|
||||
public void initSUConfig() {
|
||||
suRequestTimeout = Utils.getPrefsInt(prefs, "su_request_timeout", 10);
|
||||
suResponseType = Utils.getPrefsInt(prefs, "su_auto_response", 0);
|
||||
suNotificationType = Utils.getPrefsInt(prefs, "su_notification", 1);
|
||||
suReauth = prefs.getBoolean("su_reauth", false);
|
||||
}
|
||||
|
||||
public void initSU() {
|
||||
initSUConfig();
|
||||
|
||||
List<String> ret = shell.sh("su -v");
|
||||
public void getMagiskInfo() {
|
||||
Shell.getShell(this);
|
||||
List<String> ret;
|
||||
ret = shell.sh("su -v");
|
||||
if (Utils.isValidShellResponse(ret)) {
|
||||
suVersion = ret.get(0);
|
||||
isSuClient = suVersion.toUpperCase().contains("MAGISK");
|
||||
}
|
||||
if (isSuClient) {
|
||||
suAccessState = suDB.getSettings(SuDatabaseHelper.ROOT_ACCESS, 3);
|
||||
multiuserMode = suDB.getSettings(SuDatabaseHelper.MULTIUSER_MODE, 0);
|
||||
suNamespaceMode = suDB.getSettings(SuDatabaseHelper.MNT_NS, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateMagiskInfo() {
|
||||
updateNotification = prefs.getBoolean("notification", true);
|
||||
List<String> ret;
|
||||
ret = shell.sh("magisk -v");
|
||||
if (!Utils.isValidShellResponse(ret)) {
|
||||
ret = shell.sh("getprop magisk.version");
|
||||
@ -247,11 +246,11 @@ public class MagiskManager extends Application {
|
||||
}
|
||||
}
|
||||
|
||||
public void updateBlockInfo() {
|
||||
private void updateBlockInfo() {
|
||||
List<String> res = shell.su(
|
||||
"for BLOCK in boot_a BOOT_A kern-a KERN-A android_boot ANDROID_BOOT kernel KERNEL boot BOOT lnx LNX; do",
|
||||
"BOOTIMAGE=`ls /dev/block/by-name/$BLOCK || ls /dev/block/platform/*/by-name/$BLOCK || ls /dev/block/platform/*/*/by-name/$BLOCK` 2>/dev/null",
|
||||
"[ ! -z \"$BOOTIMAGE\" ] && break",
|
||||
"for BLOCK in boot_a kern-a android_boot kernel boot lnx; do",
|
||||
" BOOTIMAGE=`find /dev/block -iname $BLOCK | head -n 1` 2>/dev/null",
|
||||
" [ ! -z $BOOTIMAGE ] && break",
|
||||
"done",
|
||||
"[ ! -z \"$BOOTIMAGE\" -a -L \"$BOOTIMAGE\" ] && BOOTIMAGE=`readlink $BOOTIMAGE`",
|
||||
"echo \"$BOOTIMAGE\""
|
||||
|
@ -6,7 +6,6 @@ import android.content.Intent;
|
||||
import android.os.Build;
|
||||
|
||||
import com.topjohnwu.magisk.services.OnBootIntentService;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
public class BootReceiver extends BroadcastReceiver {
|
||||
|
||||
@ -21,7 +20,6 @@ public class BootReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
|
||||
Utils.getMagiskManager(context).initSU();
|
||||
// There is currently no need to start an IntentService onBoot
|
||||
// startIntentService(context);
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ public class PackageReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
MagiskManager magiskManager = Utils.getMagiskManager(context);
|
||||
magiskManager.initSUConfig();
|
||||
|
||||
String pkg = intent.getData().getEncodedSchemeSpecificPart();
|
||||
Policy policy = magiskManager.suDB.getPolicy(pkg);
|
||||
|
@ -10,7 +10,7 @@ public class UpdateCheckService extends JobService {
|
||||
|
||||
@Override
|
||||
public boolean onStartJob(JobParameters params) {
|
||||
Utils.getMagiskManager(this).updateMagiskInfo();
|
||||
Utils.getMagiskManager(this).getMagiskInfo();
|
||||
new CheckUpdates(this, true)
|
||||
.setCallBack(() -> jobFinished(params, false)).exec();
|
||||
return true;
|
||||
|
@ -17,7 +17,6 @@ public class RequestActivity extends Activity {
|
||||
return;
|
||||
}
|
||||
|
||||
getApplicationContext().initSUConfig();
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setClass(this, SuRequestActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
|
@ -27,7 +27,6 @@ public class SuReceiver extends BroadcastReceiver {
|
||||
Policy policy;
|
||||
|
||||
MagiskManager magiskManager = (MagiskManager) context.getApplicationContext();
|
||||
magiskManager.initSUConfig();
|
||||
|
||||
if (intent == null) return;
|
||||
|
||||
|
@ -91,7 +91,7 @@ public class Shell {
|
||||
|
||||
public static Shell getShell(Context context) {
|
||||
MagiskManager magiskManager = Utils.getMagiskManager(context);
|
||||
if (!magiskManager.shell.isValid) {
|
||||
if (magiskManager.shell == null || !magiskManager.shell.isValid) {
|
||||
// Get new shell if needed
|
||||
magiskManager.shell = getShell();
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ buildscript {
|
||||
maven { url "https://maven.google.com" }
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.0.0-alpha9'
|
||||
classpath 'com.android.tools.build:gradle:3.0.0-beta1'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
Loading…
x
Reference in New Issue
Block a user