mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-06-13 05:37:47 +02:00
WIP Sync
It might compile, is probably broken atm...
This commit is contained in:
@ -1,16 +1,19 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -22,6 +25,8 @@ import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.topjohnwu.magisk.receivers.Receiver;
|
||||
import com.topjohnwu.magisk.receivers.RootFragmentReceiver;
|
||||
import com.topjohnwu.magisk.services.MonitorService;
|
||||
import com.topjohnwu.magisk.utils.Shell;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
@ -33,7 +38,7 @@ import butterknife.BindColor;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class RootFragment extends Fragment {
|
||||
public class RootFragment extends Fragment implements Receiver{
|
||||
|
||||
public SharedPreferences prefs;
|
||||
@BindView(R.id.progressBar)
|
||||
@ -92,7 +97,6 @@ public class RootFragment extends Fragment {
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.root_fragment, container, false);
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
|
||||
if (prefs.contains("autoRootEnable")) {
|
||||
@ -112,7 +116,7 @@ public class RootFragment extends Fragment {
|
||||
|
||||
autoRootToggle.setOnClickListener(toggle -> {
|
||||
ToggleAutoRoot(autoRootToggle.isChecked());
|
||||
new Handler().postDelayed(() -> new updateUI().execute(), 1000);
|
||||
new updateUI().execute();
|
||||
|
||||
});
|
||||
|
||||
@ -121,9 +125,23 @@ public class RootFragment extends Fragment {
|
||||
new updateUI().execute();
|
||||
});
|
||||
|
||||
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mYourBroadcastReceiver,
|
||||
new IntentFilter("com.magisk.UPDATEUI"));
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private final BroadcastReceiver mYourBroadcastReceiver = new RootFragmentReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
Log.d("Magisk", "RootFragment: UpdateRF called and fired");
|
||||
new updateUI().execute();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
// Check which request we're responding to
|
||||
@ -139,6 +157,9 @@ public class RootFragment extends Fragment {
|
||||
|
||||
}
|
||||
|
||||
} else if (requestCode == 420) {
|
||||
Log.d("Magisk", "Got result code OK for UI update.");
|
||||
new updateUI().execute();
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,6 +195,11 @@ public class RootFragment extends Fragment {
|
||||
new updateUI().execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResult() {
|
||||
|
||||
}
|
||||
|
||||
public class updateUI extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
@Override
|
||||
@ -301,4 +327,5 @@ public class RootFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
||||
|
||||
|
||||
|
||||
private void navigate(final int itemId) {
|
||||
public void navigate(final int itemId) {
|
||||
Fragment navFragment = null;
|
||||
String tag = "";
|
||||
switch (itemId) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.topjohnwu.magisk.tile;
|
||||
package com.topjohnwu.magisk.receivers;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@ -19,15 +19,16 @@ public final class PrivateBroadcastReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
Log.d("Magisk","Broadcast Receiver, Made it this far!");
|
||||
Log.d("Magisk","Broadcast Receiver, Made it this far! We're trying to " + action);
|
||||
if (ACTION_AUTOROOT.equals(action)) {
|
||||
Utils.toggleAutoRoot(true, context);
|
||||
Utils.toggleAutoRoot(!Utils.autoRootEnabled(context),context);
|
||||
}
|
||||
if (ACTION_ENABLEROOT.equals(action)) {
|
||||
Utils.toggleAutoRoot(false, context);
|
||||
Utils.toggleRoot(true);
|
||||
}
|
||||
if (ACTION_DISABLEROOT.equals(action)) {
|
||||
Utils.toggleAutoRoot(false, context);
|
||||
Utils.toggleRoot(false);
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
package com.topjohnwu.magisk.receivers;
|
||||
|
||||
public interface Receiver {
|
||||
void onResult();
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.topjohnwu.magisk.receivers;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
public class RootFragmentReceiver extends BroadcastReceiver {
|
||||
|
||||
private Receiver mFragment;
|
||||
public RootFragmentReceiver(Receiver fragment) {
|
||||
mFragment = fragment;
|
||||
}
|
||||
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(420)) {
|
||||
mFragment.onResult();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package com.topjohnwu.magisk.tile;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.kcoppock.broadcasttilesupport.BroadcastTileIntentBuilder;
|
||||
import com.topjohnwu.magisk.R;
|
||||
|
||||
final public class CustomTileHelper {
|
||||
/**
|
||||
* This is the identifier of the custom Broadcast Tile. Whatever action you configured the tile
|
||||
* for must be used when configuring the tile. For Broadcast tiles, only alphanumeric characters
|
||||
* (and periods) are allowed. Keep in mind that this excludes underscores.
|
||||
*/
|
||||
private static final String BROADCAST_TILE_IDENTIFIER = "com.kcoppock.CUSTOMTILE";
|
||||
|
||||
/**
|
||||
* Keeps track of the last known state of the Quick Settings custom tile. There doesn't seem to
|
||||
* be a way to query the state of the tile.
|
||||
*/
|
||||
private static final String PREF_TILE_SHOWN = "com.kcoppock.CUSTOMTILE_SHOWN";
|
||||
|
||||
private final Context mContext;
|
||||
private final TilePreferenceHelper mTilePreferenceHelper;
|
||||
|
||||
CustomTileHelper(@NonNull Context context) {
|
||||
mContext = context.getApplicationContext();
|
||||
mTilePreferenceHelper = new TilePreferenceHelper(mContext);
|
||||
}
|
||||
|
||||
void showTile() {
|
||||
mTilePreferenceHelper.setBoolean(PREF_TILE_SHOWN, true);
|
||||
|
||||
// Set up an Intent that will be broadcast by the system, and received by the exported
|
||||
// PublicBroadcastReceiver.
|
||||
|
||||
|
||||
|
||||
|
||||
// Send the update event to the Broadcast Tile. Custom tiles are hidden by default until
|
||||
// enabled with this broadcast Intent.
|
||||
mContext.sendBroadcast(new BroadcastTileIntentBuilder(mContext, BROADCAST_TILE_IDENTIFIER)
|
||||
.setVisible(true)
|
||||
.build());
|
||||
}
|
||||
|
||||
void hideTile() {
|
||||
mTilePreferenceHelper.setBoolean(PREF_TILE_SHOWN, false);
|
||||
|
||||
mContext.sendBroadcast(new BroadcastTileIntentBuilder(mContext, BROADCAST_TILE_IDENTIFIER)
|
||||
.setVisible(false)
|
||||
.build());
|
||||
}
|
||||
|
||||
boolean isLastTileStateShown() {
|
||||
return mTilePreferenceHelper.getBoolean(PREF_TILE_SHOWN);
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.topjohnwu.magisk.tile;
|
||||
|
||||
import android.content.*;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* Exported receiver for the custom event on the custom Quick Settings tile
|
||||
*/
|
||||
public final class PublicBroadcastReceiver extends BroadcastReceiver {
|
||||
/**
|
||||
* The action broadcast from the Quick Settings tile when clicked
|
||||
*/
|
||||
public static final String ACTION_TOAST = "com.kcoppock.CUSTOMTILE_ACTION_TOAST";
|
||||
|
||||
/**
|
||||
* Constant for the String extra to be displayed in the Toast
|
||||
*/
|
||||
public static final String EXTRA_MESSAGE = "com.kcoppock.CUSTOMTILE_EXTRA_MESSAGE";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
|
||||
if (ACTION_TOAST.equals(action)) {
|
||||
final String message = intent.getStringExtra(EXTRA_MESSAGE);
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.topjohnwu.magisk.tile;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
/**
|
||||
* Helper class for tracking preference values to keep track of the state of the custom tile
|
||||
*/
|
||||
final public class TilePreferenceHelper {
|
||||
private static final String PREFS_NAME = "tile_prefs";
|
||||
|
||||
private final SharedPreferences mSharedPreferences;
|
||||
|
||||
TilePreferenceHelper(@NonNull Context context) {
|
||||
mSharedPreferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
void setBoolean(@NonNull String key, boolean value) {
|
||||
mSharedPreferences.edit().putBoolean(key, value).apply();
|
||||
}
|
||||
|
||||
boolean getBoolean(@NonNull String key) {
|
||||
return mSharedPreferences.getBoolean(key, false);
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
@ -32,13 +33,15 @@ import com.kcoppock.broadcasttilesupport.BroadcastTileIntentBuilder;
|
||||
import com.topjohnwu.magisk.ModulesFragment;
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.ReposFragment;
|
||||
import com.topjohnwu.magisk.RootFragment;
|
||||
import com.topjohnwu.magisk.module.Module;
|
||||
import com.topjohnwu.magisk.module.Repo;
|
||||
import com.topjohnwu.magisk.module.RepoHelper;
|
||||
import com.topjohnwu.magisk.tile.PrivateBroadcastReceiver;
|
||||
import com.topjohnwu.magisk.receivers.PrivateBroadcastReceiver;
|
||||
import com.topjohnwu.magisk.receivers.Receiver;
|
||||
import com.topjohnwu.magisk.receivers.RootFragmentReceiver;
|
||||
import com.topjohnwu.magisk.services.MonitorService;
|
||||
import com.topjohnwu.magisk.services.QuickSettingTileService;
|
||||
import com.topjohnwu.magisk.tile.CustomTileHelper;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@ -96,7 +99,9 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static boolean autoRootEnabled(Context context) {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("autoRootEnable", false);
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
Log.d("Magisk", "AutoRootEnableCheck is " + preferences.getBoolean("autoRootEnable", false));
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("autoRootEnable", false);
|
||||
|
||||
}
|
||||
|
||||
@ -119,22 +124,26 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static void toggleRoot(Boolean b) {
|
||||
if (b) {
|
||||
Shell.su("ln -s $(getprop magisk.supath) /magisk/.core/bin", "setprop magisk.root 1");
|
||||
} else {
|
||||
Shell.su("rm -rf /magisk/.core/bin", "setprop magisk.root 0");
|
||||
if (Utils.magiskVersion != -1) {
|
||||
if (b) {
|
||||
Shell.su("ln -s $(getprop magisk.supath) /magisk/.core/bin", "setprop magisk.root 1");
|
||||
} else {
|
||||
Shell.su("rm -rf /magisk/.core/bin", "setprop magisk.root 0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void toggleAutoRoot(Boolean b, Context context) {
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("autoRootEnable", b).apply();
|
||||
Intent myServiceIntent = new Intent(context, MonitorService.class);
|
||||
if (b) {
|
||||
context.startService(myServiceIntent);
|
||||
} else {
|
||||
context.stopService(myServiceIntent);
|
||||
if (Utils.magiskVersion != -1) {
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("autoRootEnable", b).apply();
|
||||
Intent myServiceIntent = new Intent(context, MonitorService.class);
|
||||
if (b) {
|
||||
context.startService(myServiceIntent);
|
||||
} else {
|
||||
context.stopService(myServiceIntent);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateRootFragmentUI(context);
|
||||
}
|
||||
|
||||
public static List<String> getModList(String path) {
|
||||
@ -196,22 +205,24 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static void SetupQuickSettingsTile(Context mContext) {
|
||||
Log.d("Magisk","Utils: SetupQuickSettings called");
|
||||
Log.d("Magisk", "Utils: SetupQuickSettings called");
|
||||
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) {
|
||||
Log.d("Magisk","Utils: Marshmallow build detected");
|
||||
Log.d("Magisk", "Utils: Marshmallow build detected");
|
||||
String mLabelString;
|
||||
int mRootIcon = R.drawable.root;
|
||||
int mAutoRootIcon = R.drawable.ic_autoroot;
|
||||
int mRootIcon = R.drawable.root_white;
|
||||
int mAutoRootIcon = R.drawable.ic_autoroot_white;
|
||||
int mRootDisabled = R.drawable.root_grey;
|
||||
int mRootsState = CheckRootsState(mContext);
|
||||
Log.d("Magisk","Utils: Root State returned as " + mRootsState);
|
||||
Log.d("Magisk", "Utils: Root State returned as " + mRootsState);
|
||||
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:
|
||||
@ -222,30 +233,41 @@ public class Utils {
|
||||
case 1:
|
||||
mLabelString = "Root enabled";
|
||||
mIcon = mRootIcon;
|
||||
intent = enableBroadcast;
|
||||
intent = disableBroadcast;
|
||||
break;
|
||||
case 0:
|
||||
mLabelString = "Root disabled";
|
||||
mIcon = mRootIcon;
|
||||
intent = disableBroadcast;
|
||||
mIcon = mRootDisabled;
|
||||
intent = enableBroadcast;
|
||||
break;
|
||||
default:
|
||||
mLabelString = "Root enabled";
|
||||
mIcon = mRootIcon;
|
||||
intent = enableBroadcast;
|
||||
mLabelString = "Root disabled";
|
||||
mIcon = mRootDisabled;
|
||||
intent = disableBroadcast;
|
||||
break;
|
||||
}
|
||||
|
||||
Intent tileConfigurationIntent = new BroadcastTileIntentBuilder(mContext, "ROOT")
|
||||
Intent tileConfigurationIntent = new BroadcastTileIntentBuilder(mContext, "Magisk")
|
||||
.setLabel(mLabelString)
|
||||
.setIconResource(mIcon)
|
||||
.setOnClickBroadcast(intent)
|
||||
.setOnLongClickBroadcast(autoBroadcast)
|
||||
.setVisible(true)
|
||||
.build();
|
||||
mContext.sendBroadcast(tileConfigurationIntent);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateRootFragmentUI(Context context) {
|
||||
|
||||
Log.d("Magisk", "Utils: UpdateRF called");
|
||||
Intent intent = new Intent(context, RootFragment.class);
|
||||
intent.setAction("com.magisk.UPDATEUI");
|
||||
context.sendBroadcast(intent);
|
||||
|
||||
}
|
||||
|
||||
// Gets an overall state for the quick settings tile
|
||||
// 0 for root disabled, 1 for root enabled (no auto), 2 for auto-root
|
||||
|
||||
@ -562,8 +584,6 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static boolean isMyServiceRunning(Class<?> serviceClass, Context context) {
|
||||
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
||||
|
Reference in New Issue
Block a user