Add BootReceiver

This commit is contained in:
topjohnwu 2017-01-29 16:52:43 +08:00
parent 49e546919a
commit 13512b4146
4 changed files with 38 additions and 32 deletions

View File

@ -53,6 +53,12 @@
<receiver
android:name=".superuser.SuReceiver" />
<receiver android:name=".receivers.BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.topjohnwu.magisk.provider"

View File

@ -28,7 +28,6 @@ public class Global {
public static String bootBlock = null;
public static boolean isSuClient = false;
public static String suVersion = null;
public static int shellUid;
}
public static class Data {
public static ValueSortedMap<String, Repo> repoMap = new ValueSortedMap<>();
@ -60,12 +59,8 @@ public class Global {
Configs.isDarkTheme = prefs.getBoolean("dark_theme", false);
Configs.devLogging = prefs.getBoolean("developer_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();
initSuAccess();
initSuConfigs(context);
// Initialize prefs
prefs.edit()
@ -82,19 +77,26 @@ public class Global {
public static void initSuConfigs(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
List<String> ret = Shell.sh("getprop persist.sys.root_access");
if (Utils.isValidShellResponse(ret))
Configs.suAccessState = Integer.parseInt(ret.get(0));
else {
Shell.su("setprop persist.sys.root_access 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));
}
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))
Configs.suAccessState = Integer.parseInt(ret.get(0));
else {
Shell.su("setprop persist.sys.root_access 3");
Configs.suAccessState = 3;
}
}
}
static void updateMagiskInfo() {

View File

@ -156,7 +156,6 @@ public class MagiskLogFragment extends Fragment {
return "";
case 2:
case 3:
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
@ -221,17 +220,6 @@ public class MagiskLogFragment extends Fragment {
else
Toast.makeText(getActivity(), getString(R.string.logs_save_failed), Toast.LENGTH_LONG).show();
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 {
public void save() {
exec(2);
}
public void send() {
exec(3);
}
}
}

View File

@ -0,0 +1,14 @@
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();
}
}