Commit 13512b41 authored by topjohnwu's avatar topjohnwu

Add BootReceiver

parent 49e54691
...@@ -53,6 +53,12 @@ ...@@ -53,6 +53,12 @@
<receiver <receiver
android:name=".superuser.SuReceiver" /> android:name=".superuser.SuReceiver" />
<receiver android:name=".receivers.BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<provider <provider
android:name="android.support.v4.content.FileProvider" android:name="android.support.v4.content.FileProvider"
android:authorities="com.topjohnwu.magisk.provider" android:authorities="com.topjohnwu.magisk.provider"
......
...@@ -28,7 +28,6 @@ public class Global { ...@@ -28,7 +28,6 @@ public class Global {
public static String bootBlock = null; public static String bootBlock = null;
public static boolean isSuClient = false; public static boolean isSuClient = false;
public static String suVersion = null; public static String suVersion = null;
public static int shellUid;
} }
public static class Data { public static class Data {
public static ValueSortedMap<String, Repo> repoMap = new ValueSortedMap<>(); public static ValueSortedMap<String, Repo> repoMap = new ValueSortedMap<>();
...@@ -60,12 +59,8 @@ public class Global { ...@@ -60,12 +59,8 @@ public class Global {
Configs.isDarkTheme = prefs.getBoolean("dark_theme", false); Configs.isDarkTheme = prefs.getBoolean("dark_theme", false);
Configs.devLogging = prefs.getBoolean("developer_logging", false); Configs.devLogging = prefs.getBoolean("developer_logging", false);
Configs.shellLogging = prefs.getBoolean("shell_logging", false); Configs.shellLogging = prefs.getBoolean("shell_logging", false);
List<String> ret = Shell.sh("su -v");
if (Utils.isValidShellResponse(ret)) {
Info.suVersion = ret.get(0);
Info.isSuClient = Info.suVersion.toUpperCase().contains("MAGISK");
}
updateMagiskInfo(); updateMagiskInfo();
initSuAccess();
initSuConfigs(context); initSuConfigs(context);
// Initialize prefs // Initialize prefs
prefs.edit() prefs.edit()
...@@ -82,19 +77,26 @@ public class Global { ...@@ -82,19 +77,26 @@ public class Global {
public static void initSuConfigs(Context context) { public static void initSuConfigs(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
List<String> ret = Shell.sh("getprop persist.sys.root_access"); Configs.suRequestTimeout = Utils.getPrefsInt(prefs, "su_request_timeout", 10);
Configs.suResponseType = Utils.getPrefsInt(prefs, "su_auto_response", 0);
Configs.suNotificationType = Utils.getPrefsInt(prefs, "su_notification", 1);
}
public static void initSuAccess() {
List<String> ret = Shell.sh("su -v");
if (Utils.isValidShellResponse(ret)) {
Info.suVersion = ret.get(0);
Info.isSuClient = Info.suVersion.toUpperCase().contains("MAGISK");
}
if (Info.isSuClient) {
ret = Shell.sh("getprop persist.sys.root_access");
if (Utils.isValidShellResponse(ret)) if (Utils.isValidShellResponse(ret))
Configs.suAccessState = Integer.parseInt(ret.get(0)); Configs.suAccessState = Integer.parseInt(ret.get(0));
else { else {
Shell.su("setprop persist.sys.root_access 3"); Shell.su("setprop persist.sys.root_access 3");
Configs.suAccessState = 3; Configs.suAccessState = 3;
} }
Configs.suRequestTimeout = Utils.getPrefsInt(prefs, "su_request_timeout", 10); }
Configs.suResponseType = Utils.getPrefsInt(prefs, "su_auto_response", 0);
Configs.suNotificationType = Utils.getPrefsInt(prefs, "su_notification", 1);
ret = Shell.sh("id -u shell");
if (Utils.isValidShellResponse(ret))
Info.shellUid = Integer.parseInt(ret.get(0));
} }
static void updateMagiskInfo() { static void updateMagiskInfo() {
......
...@@ -156,7 +156,6 @@ public class MagiskLogFragment extends Fragment { ...@@ -156,7 +156,6 @@ public class MagiskLogFragment extends Fragment {
return ""; return "";
case 2: case 2:
case 3:
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0); requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
...@@ -221,17 +220,6 @@ public class MagiskLogFragment extends Fragment { ...@@ -221,17 +220,6 @@ public class MagiskLogFragment extends Fragment {
else else
Toast.makeText(getActivity(), getString(R.string.logs_save_failed), Toast.LENGTH_LONG).show(); Toast.makeText(getActivity(), getString(R.string.logs_save_failed), Toast.LENGTH_LONG).show();
break; break;
case 3:
bool = (boolean) o;
if (bool) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(targetFile));
sendIntent.setType("application/html");
startActivity(Intent.createChooser(sendIntent, getResources().getString(R.string.menuSend)));
} else {
Toast.makeText(getActivity(), getString(R.string.logs_save_failed), Toast.LENGTH_LONG).show();
}
} }
} }
...@@ -246,10 +234,6 @@ public class MagiskLogFragment extends Fragment { ...@@ -246,10 +234,6 @@ public class MagiskLogFragment extends Fragment {
public void save() { public void save() {
exec(2); exec(2);
} }
public void send() {
exec(3);
}
} }
} }
package com.topjohnwu.magisk.receivers;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.topjohnwu.magisk.Global;
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Global.initSuAccess();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment