mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-10-25 23:18:46 +00:00
More work on Quick Settings, refactoring
This commit is contained in:
@@ -22,6 +22,7 @@ import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.topjohnwu.magisk.services.MonitorService;
|
||||
import com.topjohnwu.magisk.utils.Shell;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import com.topjohnwu.magisk.module.RepoHelper;
|
||||
import com.topjohnwu.magisk.utils.LogFragment;
|
||||
import com.topjohnwu.magisk.services.MonitorService;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import butterknife.BindView;
|
||||
@@ -62,10 +64,8 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
Intent serviceIntent = new Intent(this, QuickSettingTileService.class);
|
||||
startService(serviceIntent);
|
||||
}
|
||||
Utils.SetupQuickSettingsTile(getApplicationContext());
|
||||
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
|
||||
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
package com.topjohnwu.magisk;
|
||||
package com.topjohnwu.magisk.receivers;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
public class AutoStart extends BroadcastReceiver {
|
||||
import com.topjohnwu.magisk.services.MonitorService;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
public class AutoStartReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.d("Magisk", "Received Boot call, attempting to start service");
|
||||
Intent myIntent = new Intent(context, MonitorService.class);
|
||||
context.startService(myIntent);
|
||||
Utils.SetupQuickSettingsTile(context);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.topjohnwu.magisk.receivers;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
/**
|
||||
* Receiver for click events on the custom M Quick Settings tile
|
||||
*/
|
||||
public final class PrivateBroadcastReceiver extends BroadcastReceiver {
|
||||
public static final String ACTION_AUTOROOT = "com.topjohnwu.magisk.CUSTOMTILE_ACTION_AUTOROOT";
|
||||
public static final String ACTION_DISABLEROOT = "com.topjohnwu.magisk.CUSTOMTILE_ACTION_DISABLEROOT";
|
||||
public static final String ACTION_ENABLEROOT = "com.topjohnwu.magisk.CUSTOMTILE_ACTION_ENABLEROOT";
|
||||
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
|
||||
if (ACTION_AUTOROOT.equals(action)) {
|
||||
Utils.toggleAutoRoot(true, context);
|
||||
}
|
||||
if (ACTION_ENABLEROOT.equals(action)) {
|
||||
Utils.toggleAutoRoot(false, context);
|
||||
Utils.toggleRoot(true);
|
||||
}
|
||||
if (ACTION_DISABLEROOT.equals(action)) {
|
||||
Utils.toggleRoot(false);
|
||||
}
|
||||
|
||||
Utils.SetupQuickSettingsTile(context);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.topjohnwu.magisk;
|
||||
package com.topjohnwu.magisk.services;
|
||||
|
||||
import android.accessibilityservice.AccessibilityService;
|
||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||
@@ -16,6 +16,8 @@ import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.WelcomeActivity;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import java.util.Set;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.topjohnwu.magisk;
|
||||
package com.topjohnwu.magisk.services;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.drawable.Icon;
|
||||
@@ -6,6 +6,7 @@ import android.service.quicksettings.Tile;
|
||||
import android.service.quicksettings.TileService;
|
||||
import android.util.Log;
|
||||
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.topjohnwu.magisk;
|
||||
package com.topjohnwu.magisk.utils;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
@@ -25,6 +25,7 @@ import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import java.io.File;
|
||||
@@ -14,6 +14,7 @@ import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.DocumentsContract;
|
||||
@@ -27,13 +28,16 @@ import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.kcoppock.broadcasttilesupport.BroadcastTileIntentBuilder;
|
||||
import com.topjohnwu.magisk.ModulesFragment;
|
||||
import com.topjohnwu.magisk.MonitorService;
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.ReposFragment;
|
||||
import com.topjohnwu.magisk.module.Module;
|
||||
import com.topjohnwu.magisk.module.Repo;
|
||||
import com.topjohnwu.magisk.module.RepoHelper;
|
||||
import com.topjohnwu.magisk.receivers.PrivateBroadcastReceiver;
|
||||
import com.topjohnwu.magisk.services.MonitorService;
|
||||
import com.topjohnwu.magisk.services.QuickSettingTileService;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -65,12 +69,12 @@ import javax.crypto.spec.DESKeySpec;
|
||||
public class Utils {
|
||||
|
||||
public static int magiskVersion, remoteMagiskVersion = -1, remoteAppVersion = -1;
|
||||
public static String magiskLink, magiskChangelog, appChangelog, appLink, phhLink, supersuLink;
|
||||
private static String magiskLink, magiskChangelog, appChangelog, appLink, phhLink, supersuLink;
|
||||
private static final String TAG = "Magisk";
|
||||
|
||||
public static final String MAGISK_PATH = "/magisk";
|
||||
public static final String MAGISK_CACHE_PATH = "/cache/magisk";
|
||||
public static final String UPDATE_JSON = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/updates/magisk_update.json";
|
||||
private static final String MAGISK_PATH = "/magisk";
|
||||
private static final String MAGISK_CACHE_PATH = "/cache/magisk";
|
||||
private static final String UPDATE_JSON = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/updates/magisk_update.json";
|
||||
|
||||
public static boolean fileExist(String path) {
|
||||
List<String> ret;
|
||||
@@ -190,6 +194,70 @@ public class Utils {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static void SetupQuickSettingsTile(Context mContext) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
Intent serviceIntent = new Intent(mContext, QuickSettingTileService.class);
|
||||
mContext.startService(serviceIntent);
|
||||
}
|
||||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
|
||||
String mLabelString;
|
||||
int mRootIcon = R.drawable.root;
|
||||
int mAutoRootIcon = R.drawable.ic_autoroot;
|
||||
int mRootsState = CheckRootsState(mContext);
|
||||
final Intent enableBroadcast = new Intent(PrivateBroadcastReceiver.ACTION_ENABLEROOT);
|
||||
final Intent disableBroadcast = new Intent(PrivateBroadcastReceiver.ACTION_DISABLEROOT);
|
||||
final Intent autoBroadcast = new Intent(PrivateBroadcastReceiver.ACTION_AUTOROOT);
|
||||
Intent intent;
|
||||
int mIcon;
|
||||
switch (mRootsState) {
|
||||
case 2:
|
||||
mLabelString = "Auto-root";
|
||||
mIcon = mAutoRootIcon;
|
||||
intent = autoBroadcast;
|
||||
break;
|
||||
case 1:
|
||||
mLabelString = "Root enabled";
|
||||
mIcon = mRootIcon;
|
||||
intent = enableBroadcast;
|
||||
break;
|
||||
case 0:
|
||||
mLabelString = "Root disabled";
|
||||
mIcon = mRootIcon;
|
||||
intent = disableBroadcast;
|
||||
break;
|
||||
default:
|
||||
mLabelString = "Root enabled";
|
||||
mIcon = mRootIcon;
|
||||
intent = enableBroadcast;
|
||||
break;
|
||||
}
|
||||
|
||||
Intent tileConfigurationIntent = new BroadcastTileIntentBuilder(mContext, "com.magisk.ROOT_TILE")
|
||||
.setLabel(mLabelString)
|
||||
.setIconResource(mIcon)
|
||||
.setOnClickBroadcast(intent)
|
||||
.build();
|
||||
mContext.sendBroadcast(tileConfigurationIntent);
|
||||
}
|
||||
}
|
||||
|
||||
// Gets an overall state for the quick settings tile
|
||||
// 0 for root disabled, 1 for root enabled (no auto), 2 for auto-root
|
||||
|
||||
public static int CheckRootsState(Context mContext) {
|
||||
if (autoRootEnabled(mContext)) {
|
||||
return 2;
|
||||
} else {
|
||||
if (rootStatus()) {
|
||||
return 1;
|
||||
|
||||
} else {
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// To check if service is enabled
|
||||
public static boolean hasServicePermission(Context mContext) {
|
||||
int accessibilityEnabled = 0;
|
||||
|
||||
Reference in New Issue
Block a user