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
|
@Override
|
||||||
public void onRefresh() {
|
public void onRefresh() {
|
||||||
|
magiskManager.getMagiskInfo();
|
||||||
updateUI();
|
updateUI();
|
||||||
|
|
||||||
magiskUpdateText.setText(R.string.checking_for_updates);
|
magiskUpdateText.setText(R.string.checking_for_updates);
|
||||||
@ -304,7 +305,6 @@ public class MagiskFragment extends Fragment
|
|||||||
|
|
||||||
private void updateUI() {
|
private void updateUI() {
|
||||||
((MainActivity) getActivity()).checkHideSection();
|
((MainActivity) getActivity()).checkHideSection();
|
||||||
magiskManager.updateMagiskInfo();
|
|
||||||
|
|
||||||
final int ROOT = 0x1, NETWORK = 0x2, UPTODATE = 0x4;
|
final int ROOT = 0x1, NETWORK = 0x2, UPTODATE = 0x4;
|
||||||
int status = 0;
|
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() {
|
public void setLocale() {
|
||||||
String localeTag = prefs.getString("locale", "");
|
String localeTag = prefs.getString("locale", "");
|
||||||
if (localeTag.isEmpty()) {
|
if (localeTag.isEmpty()) {
|
||||||
@ -130,17 +140,31 @@ public class MagiskManager extends Application {
|
|||||||
res.updateConfiguration(config, res.getDisplayMetrics());
|
res.updateConfiguration(config, res.getDisplayMetrics());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void loadConfig() {
|
||||||
public void onCreate() {
|
// Locale
|
||||||
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);
|
|
||||||
defaultLocale = Locale.getDefault();
|
defaultLocale = Locale.getDefault();
|
||||||
setLocale();
|
setLocale();
|
||||||
new LoadLocale(this).exec();
|
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) {
|
public void toast(String msg, int duration) {
|
||||||
@ -152,18 +176,10 @@ public class MagiskManager extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
isDarkTheme = prefs.getBoolean("dark_theme", false);
|
getMagiskInfo();
|
||||||
if (BuildConfig.DEBUG) {
|
|
||||||
devLogging = prefs.getBoolean("developer_logging", false);
|
|
||||||
shellLogging = prefs.getBoolean("shell_logging", false);
|
|
||||||
} else {
|
|
||||||
devLogging = false;
|
|
||||||
shellLogging = false;
|
|
||||||
}
|
|
||||||
initSU();
|
|
||||||
updateMagiskInfo();
|
|
||||||
updateBlockInfo();
|
updateBlockInfo();
|
||||||
// Initialize prefs
|
|
||||||
|
// Write back default values
|
||||||
prefs.edit()
|
prefs.edit()
|
||||||
.putBoolean("dark_theme", isDarkTheme)
|
.putBoolean("dark_theme", isDarkTheme)
|
||||||
.putBoolean("magiskhide", magiskHide)
|
.putBoolean("magiskhide", magiskHide)
|
||||||
@ -192,31 +208,14 @@ public class MagiskManager extends Application {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initSUConfig() {
|
public void getMagiskInfo() {
|
||||||
suRequestTimeout = Utils.getPrefsInt(prefs, "su_request_timeout", 10);
|
Shell.getShell(this);
|
||||||
suResponseType = Utils.getPrefsInt(prefs, "su_auto_response", 0);
|
List<String> ret;
|
||||||
suNotificationType = Utils.getPrefsInt(prefs, "su_notification", 1);
|
ret = shell.sh("su -v");
|
||||||
suReauth = prefs.getBoolean("su_reauth", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initSU() {
|
|
||||||
initSUConfig();
|
|
||||||
|
|
||||||
List<String> ret = shell.sh("su -v");
|
|
||||||
if (Utils.isValidShellResponse(ret)) {
|
if (Utils.isValidShellResponse(ret)) {
|
||||||
suVersion = ret.get(0);
|
suVersion = ret.get(0);
|
||||||
isSuClient = suVersion.toUpperCase().contains("MAGISK");
|
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");
|
ret = shell.sh("magisk -v");
|
||||||
if (!Utils.isValidShellResponse(ret)) {
|
if (!Utils.isValidShellResponse(ret)) {
|
||||||
ret = shell.sh("getprop magisk.version");
|
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(
|
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",
|
"for BLOCK in boot_a kern-a android_boot kernel boot 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",
|
" BOOTIMAGE=`find /dev/block -iname $BLOCK | head -n 1` 2>/dev/null",
|
||||||
"[ ! -z \"$BOOTIMAGE\" ] && break",
|
" [ ! -z $BOOTIMAGE ] && break",
|
||||||
"done",
|
"done",
|
||||||
"[ ! -z \"$BOOTIMAGE\" -a -L \"$BOOTIMAGE\" ] && BOOTIMAGE=`readlink $BOOTIMAGE`",
|
"[ ! -z \"$BOOTIMAGE\" -a -L \"$BOOTIMAGE\" ] && BOOTIMAGE=`readlink $BOOTIMAGE`",
|
||||||
"echo \"$BOOTIMAGE\""
|
"echo \"$BOOTIMAGE\""
|
||||||
|
@ -6,7 +6,6 @@ import android.content.Intent;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.services.OnBootIntentService;
|
import com.topjohnwu.magisk.services.OnBootIntentService;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
|
|
||||||
public class BootReceiver extends BroadcastReceiver {
|
public class BootReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
@ -21,7 +20,6 @@ public class BootReceiver extends BroadcastReceiver {
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
|
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
|
||||||
Utils.getMagiskManager(context).initSU();
|
|
||||||
// There is currently no need to start an IntentService onBoot
|
// There is currently no need to start an IntentService onBoot
|
||||||
// startIntentService(context);
|
// startIntentService(context);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ public class PackageReceiver extends BroadcastReceiver {
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
MagiskManager magiskManager = Utils.getMagiskManager(context);
|
MagiskManager magiskManager = Utils.getMagiskManager(context);
|
||||||
magiskManager.initSUConfig();
|
|
||||||
|
|
||||||
String pkg = intent.getData().getEncodedSchemeSpecificPart();
|
String pkg = intent.getData().getEncodedSchemeSpecificPart();
|
||||||
Policy policy = magiskManager.suDB.getPolicy(pkg);
|
Policy policy = magiskManager.suDB.getPolicy(pkg);
|
||||||
|
@ -10,7 +10,7 @@ public class UpdateCheckService extends JobService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onStartJob(JobParameters params) {
|
public boolean onStartJob(JobParameters params) {
|
||||||
Utils.getMagiskManager(this).updateMagiskInfo();
|
Utils.getMagiskManager(this).getMagiskInfo();
|
||||||
new CheckUpdates(this, true)
|
new CheckUpdates(this, true)
|
||||||
.setCallBack(() -> jobFinished(params, false)).exec();
|
.setCallBack(() -> jobFinished(params, false)).exec();
|
||||||
return true;
|
return true;
|
||||||
|
@ -17,7 +17,6 @@ public class RequestActivity extends Activity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
getApplicationContext().initSUConfig();
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setClass(this, SuRequestActivity.class);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setClass(this, SuRequestActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
finish();
|
finish();
|
||||||
|
@ -27,7 +27,6 @@ public class SuReceiver extends BroadcastReceiver {
|
|||||||
Policy policy;
|
Policy policy;
|
||||||
|
|
||||||
MagiskManager magiskManager = (MagiskManager) context.getApplicationContext();
|
MagiskManager magiskManager = (MagiskManager) context.getApplicationContext();
|
||||||
magiskManager.initSUConfig();
|
|
||||||
|
|
||||||
if (intent == null) return;
|
if (intent == null) return;
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ public class Shell {
|
|||||||
|
|
||||||
public static Shell getShell(Context context) {
|
public static Shell getShell(Context context) {
|
||||||
MagiskManager magiskManager = Utils.getMagiskManager(context);
|
MagiskManager magiskManager = Utils.getMagiskManager(context);
|
||||||
if (!magiskManager.shell.isValid) {
|
if (magiskManager.shell == null || !magiskManager.shell.isValid) {
|
||||||
// Get new shell if needed
|
// Get new shell if needed
|
||||||
magiskManager.shell = getShell();
|
magiskManager.shell = getShell();
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ buildscript {
|
|||||||
maven { url "https://maven.google.com" }
|
maven { url "https://maven.google.com" }
|
||||||
}
|
}
|
||||||
dependencies {
|
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
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
Loading…
x
Reference in New Issue
Block a user