mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-06-13 05:37:47 +02:00
Whoop whoop
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import android.app.ListFragment;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
@ -8,7 +9,7 @@ import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.ListFragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -41,7 +42,7 @@ public class AutoRootFragment extends ListFragment {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
listView = getListView();
|
||||
packageManager = getActivity().getPackageManager();
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
if (!prefs.contains("auto_blacklist")) {
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
Set<String> set = new HashSet<>();
|
||||
|
@ -6,13 +6,14 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@ -132,7 +133,9 @@ public class LogFragment extends Fragment {
|
||||
@SuppressLint("DefaultLocale")
|
||||
private File save() {
|
||||
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import android.support.v4.content.FileProvider;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -1,12 +1,13 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -5,7 +5,7 @@ import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.app.Fragment;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
@ -12,7 +12,7 @@ import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.app.Fragment;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
@ -97,7 +97,7 @@ public class RootFragment extends Fragment implements Receiver{
|
||||
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());
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
|
||||
if (prefs.contains("autoRootEnable")) {
|
||||
autoRootStatus = prefs.getBoolean("autoRootEnable", false);
|
||||
@ -125,22 +125,22 @@ public class RootFragment extends Fragment implements Receiver{
|
||||
new updateUI().execute();
|
||||
});
|
||||
|
||||
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mYourBroadcastReceiver,
|
||||
new IntentFilter("com.magisk.UPDATEUI"));
|
||||
// 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();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
// private final BroadcastReceiver mYourBroadcastReceiver = new RootFragmentReceiver(Re) {
|
||||
// @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) {
|
||||
|
95
app/src/main/java/com/topjohnwu/magisk/SettingsFragment.java
Normal file
95
app/src/main/java/com/topjohnwu/magisk/SettingsFragment.java
Normal file
@ -0,0 +1,95 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
|
||||
public class SettingsFragment extends PreferenceFragment {
|
||||
private CheckBoxPreference quickTilePreference;
|
||||
private CheckBoxPreference devLogPreference;
|
||||
private CheckBoxPreference keepRootOffPreference;
|
||||
private CheckBoxPreference hideRootNotificationPreference;
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
// TODO Auto-generated method stub
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Load the preferences from an XML resource
|
||||
addPreferencesFromResource(R.xml.uisettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
ButterKnife.bind(this, view);
|
||||
quickTilePreference = (CheckBoxPreference) findPreference("enable_quicktile");
|
||||
devLogPreference = (CheckBoxPreference) findPreference("developer_logging");
|
||||
keepRootOffPreference = (CheckBoxPreference) findPreference("keep_root_off");
|
||||
hideRootNotificationPreference = (CheckBoxPreference) findPreference("hide_root_notification");
|
||||
|
||||
if (Utils.magiskVersion == -1) {
|
||||
quickTilePreference.setEnabled(false);
|
||||
keepRootOffPreference.setEnabled(false);
|
||||
hideRootNotificationPreference.setEnabled(false);
|
||||
} else {
|
||||
quickTilePreference.setEnabled(true);
|
||||
keepRootOffPreference.setEnabled(true);
|
||||
hideRootNotificationPreference.setEnabled(true);
|
||||
}
|
||||
|
||||
Preference.OnPreferenceClickListener preferenceClickListener = preference -> {
|
||||
if (preference == quickTilePreference) {
|
||||
boolean isChecked = quickTilePreference.isChecked();
|
||||
if (isChecked) {
|
||||
Utils.installTile(getActivity());
|
||||
} else {
|
||||
Utils.uninstallTile(getActivity());
|
||||
}
|
||||
|
||||
}
|
||||
if (preference == devLogPreference) {
|
||||
boolean isChecked = devLogPreference.isChecked();
|
||||
|
||||
}
|
||||
if (preference == keepRootOffPreference) {
|
||||
boolean isChecked = devLogPreference.isChecked();
|
||||
|
||||
}
|
||||
if (preference == hideRootNotificationPreference) {
|
||||
boolean isChecked = devLogPreference.isChecked();
|
||||
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
quickTilePreference.setOnPreferenceClickListener(preferenceClickListener);
|
||||
// calculate margins
|
||||
int horizontalMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
|
||||
int verticalMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
|
||||
TypedValue tv = new TypedValue();
|
||||
int actionBarHeight = 130;
|
||||
if (getActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
|
||||
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
|
||||
}
|
||||
|
||||
view.setPadding(horizontalMargin, actionBarHeight, horizontalMargin, verticalMargin);
|
||||
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Fragment;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
@ -12,9 +13,9 @@ import android.preference.PreferenceManager;
|
||||
import android.support.annotation.IdRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.NavigationView;
|
||||
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
@ -175,14 +176,19 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
||||
tag = "log";
|
||||
navFragment = new LogFragment();
|
||||
break;
|
||||
case R.id.settings:
|
||||
setTitle(R.string.settings);
|
||||
tag = "settings";
|
||||
navFragment = new SettingsFragment();
|
||||
break;
|
||||
case R.id.app_about:
|
||||
startActivity(new Intent(this, AboutActivity.class));
|
||||
return;
|
||||
}
|
||||
|
||||
if (navFragment != null) {
|
||||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
||||
transaction.setCustomAnimations(R.anim.fade_in, R.anim.fade_out);
|
||||
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
||||
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
|
||||
try {
|
||||
toolbar.setElevation(navFragment instanceof ModulesFragment ? 0 : 10);
|
||||
|
||||
|
@ -6,6 +6,7 @@ import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import com.topjohnwu.magisk.services.MonitorService;
|
||||
import com.topjohnwu.magisk.utils.PrefHelper;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
public class AutoStartReceiver extends BroadcastReceiver {
|
||||
@ -14,7 +15,13 @@ public class AutoStartReceiver extends BroadcastReceiver {
|
||||
Log.d("Magisk", "Received Boot call, attempting to start service");
|
||||
Intent myIntent = new Intent(context, MonitorService.class);
|
||||
context.startService(myIntent);
|
||||
Utils.SetupQuickSettingsTile(context);
|
||||
if (PrefHelper.CheckBool("keep_root_off")) {
|
||||
Utils.toggleRoot(false);
|
||||
}
|
||||
if (PrefHelper.CheckBool("enable_quicktile")) {
|
||||
Utils.SetupQuickSettingsTile(context);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.topjohnwu.magisk.receivers;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import com.topjohnwu.magisk.services.TileService;
|
||||
|
||||
public class TileReceiver extends BroadcastReceiver {
|
||||
private static final String TAG = "MainReceiver";
|
||||
public TileReceiver() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.d(TAG,"RECEIVED");
|
||||
String action = intent.getAction();
|
||||
|
||||
if (action.equals(Intent.ACTION_BOOT_COMPLETED) || action.equals(Intent.ACTION_USER_PRESENT) || action.equals(Intent.ACTION_SCREEN_ON)) {
|
||||
context.startService(new Intent(context,TileService.class));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ import android.view.accessibility.AccessibilityEvent;
|
||||
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.WelcomeActivity;
|
||||
import com.topjohnwu.magisk.utils.PrefHelper;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import java.util.Set;
|
||||
@ -125,32 +126,33 @@ public class MonitorService extends AccessibilityService {
|
||||
private void ShowNotification(boolean rootAction, String packageName) {
|
||||
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
NotificationCompat.Builder mBuilder;
|
||||
if (!PrefHelper.CheckBool("hide_root_notification")) {
|
||||
if (rootAction) {
|
||||
|
||||
if (rootAction) {
|
||||
|
||||
Intent intent = new Intent(getApplication(), WelcomeActivity.class);
|
||||
intent.putExtra("relaunch", "relaunch");
|
||||
String rootMessage;
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(
|
||||
getApplicationContext(),
|
||||
0,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
if (packageName.equals("")) {
|
||||
rootMessage = "Root has been disabled";
|
||||
Intent intent = new Intent(getApplication(), WelcomeActivity.class);
|
||||
intent.putExtra("relaunch", "relaunch");
|
||||
String rootMessage;
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(
|
||||
getApplicationContext(),
|
||||
0,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
if (packageName.equals("")) {
|
||||
rootMessage = "Root has been disabled";
|
||||
} else {
|
||||
rootMessage = "Root has been disabled for " + packageName;
|
||||
}
|
||||
mBuilder =
|
||||
new NotificationCompat.Builder(getApplicationContext())
|
||||
.setSmallIcon(disableroot ? R.drawable.ic_stat_notification_autoroot_off : R.drawable.ic_stat_notification_autoroot_on)
|
||||
.setContentIntent(pendingIntent)
|
||||
.setContentTitle("Auto-root status changed")
|
||||
.setContentText(rootMessage);
|
||||
int mNotificationId = 1;
|
||||
mNotifyMgr.notify(mNotificationId, mBuilder.build());
|
||||
} else {
|
||||
rootMessage = "Root has been disabled for " + packageName;
|
||||
mNotifyMgr.cancelAll();
|
||||
}
|
||||
mBuilder =
|
||||
new NotificationCompat.Builder(getApplicationContext())
|
||||
.setSmallIcon(disableroot ? R.drawable.ic_stat_notification_autoroot_off : R.drawable.ic_stat_notification_autoroot_on)
|
||||
.setContentIntent(pendingIntent)
|
||||
.setContentTitle("Auto-root status changed")
|
||||
.setContentText(rootMessage);
|
||||
int mNotificationId = 1;
|
||||
mNotifyMgr.notify(mNotificationId, mBuilder.build());
|
||||
} else {
|
||||
mNotifyMgr.cancelAll();
|
||||
}
|
||||
|
||||
}
|
||||
|
139
app/src/main/java/com/topjohnwu/magisk/services/TileService.java
Normal file
139
app/src/main/java/com/topjohnwu/magisk/services/TileService.java
Normal file
@ -0,0 +1,139 @@
|
||||
package com.topjohnwu.magisk.services;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.IBinder;
|
||||
import android.service.quicksettings.Tile;
|
||||
|
||||
import com.kcoppock.broadcasttilesupport.BroadcastTileIntentBuilder;
|
||||
import com.topjohnwu.magisk.utils.Shell;
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TileService extends Service {
|
||||
private static BroadcastReceiver clickTileReceiver;
|
||||
|
||||
private static boolean running = false;
|
||||
private static boolean root, autoRoot;
|
||||
|
||||
public static final String TILE_ID = "com.shovelgrill.magiskmmtile.TILE";
|
||||
public static final String ACTION_TILE_CLICK = "com.shovelgrill.magiskmmtile.ACTION_TILE_CLICK";
|
||||
public static final String EXTRA_CLICK_TYPE = "com.shovelgrill.magiskmmtile.EXTRA_CLICK_TYPE";
|
||||
public static final int CLICK_TYPE_UNKNOWN = -1;
|
||||
public static final int CLICK_TYPE_SIMPLE = 0;
|
||||
public static final int CLICK_TYPE_LONG = 1;
|
||||
|
||||
public TileService() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
running = true;
|
||||
root = true;
|
||||
registerClickTileReceiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
root = Utils.rootEnabled();
|
||||
autoRoot = Utils.autoRootEnabled(getApplicationContext());
|
||||
updateTile();
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void registerClickTileReceiver() {
|
||||
clickTileReceiver = new BroadcastReceiver() {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
int clickType = intent.getIntExtra(EXTRA_CLICK_TYPE, CLICK_TYPE_UNKNOWN);
|
||||
switch (clickType) {
|
||||
case CLICK_TYPE_SIMPLE:
|
||||
onSimpleClick();
|
||||
break;
|
||||
case CLICK_TYPE_LONG:
|
||||
onLongClick();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
registerReceiver(clickTileReceiver, new IntentFilter(ACTION_TILE_CLICK));
|
||||
}
|
||||
|
||||
|
||||
private void onSimpleClick() {
|
||||
Utils.toggleRoot(!root);
|
||||
}
|
||||
|
||||
private void onLongClick() {
|
||||
Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
|
||||
sendBroadcast(it);
|
||||
openApp(this,"com.topjohnwu.magisk");
|
||||
}
|
||||
|
||||
public static boolean openApp(Context context, String packageName) {
|
||||
PackageManager manager = context.getPackageManager();
|
||||
Intent i = manager.getLaunchIntentForPackage(packageName);
|
||||
if (i == null) {
|
||||
return false;
|
||||
//throw new PackageManager.NameNotFoundException();
|
||||
}
|
||||
i.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
context.startActivity(i);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateTile() {
|
||||
BroadcastTileIntentBuilder broadcastTileIntentBuilder = new BroadcastTileIntentBuilder(this, TILE_ID);
|
||||
if (autoRoot) {
|
||||
broadcastTileIntentBuilder.setLabel("Auto-root");
|
||||
broadcastTileIntentBuilder.setIconResource(R.drawable.ic_autoroot_white);
|
||||
|
||||
} else {
|
||||
if (root) {
|
||||
broadcastTileIntentBuilder.setLabel("Root enabled");
|
||||
broadcastTileIntentBuilder.setIconResource(R.drawable.root_white);
|
||||
|
||||
} else {
|
||||
broadcastTileIntentBuilder.setLabel("Root disabled");
|
||||
broadcastTileIntentBuilder.setIconResource(R.drawable.root_grey);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Intent simpleClick = new Intent(ACTION_TILE_CLICK);
|
||||
simpleClick.putExtra(EXTRA_CLICK_TYPE, CLICK_TYPE_SIMPLE);
|
||||
Intent longClick = new Intent(ACTION_TILE_CLICK);
|
||||
longClick.putExtra(EXTRA_CLICK_TYPE, CLICK_TYPE_LONG);
|
||||
|
||||
broadcastTileIntentBuilder.setVisible(true);
|
||||
broadcastTileIntentBuilder.setOnClickBroadcast(simpleClick);
|
||||
broadcastTileIntentBuilder.setOnLongClickBroadcast(longClick);
|
||||
this.sendBroadcast(broadcastTileIntentBuilder.build());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
unregisterReceiver(clickTileReceiver);
|
||||
running = false;
|
||||
}
|
||||
|
||||
}
|
20
app/src/main/java/com/topjohnwu/magisk/utils/Logger.java
Normal file
20
app/src/main/java/com/topjohnwu/magisk/utils/Logger.java
Normal file
@ -0,0 +1,20 @@
|
||||
package com.topjohnwu.magisk.utils;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
|
||||
public class Logger {
|
||||
|
||||
private static final String LOG_TAG = "Magisk";
|
||||
|
||||
public static void dh(String msg, Object... args) {
|
||||
if (PrefHelper.CheckBool("developer_logging")) {
|
||||
if (args.length == 1 && args[0] instanceof Throwable) {
|
||||
Log.d(LOG_TAG, msg, (Throwable) args[0]);
|
||||
} else {
|
||||
Log.d(LOG_TAG, String.format(msg, args));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
28
app/src/main/java/com/topjohnwu/magisk/utils/PrefHelper.java
Normal file
28
app/src/main/java/com/topjohnwu/magisk/utils/PrefHelper.java
Normal file
@ -0,0 +1,28 @@
|
||||
package com.topjohnwu.magisk.utils;
|
||||
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
public class PrefHelper {
|
||||
public PrefHelper() {
|
||||
|
||||
}
|
||||
|
||||
public static boolean CheckBool(String key) {
|
||||
Context context = null;
|
||||
try {
|
||||
context = getApplicationUsingReflection();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(key, false);
|
||||
}
|
||||
|
||||
private static Application getApplicationUsingReflection() throws Exception {
|
||||
return (Application) Class.forName("android.app.AppGlobals")
|
||||
.getMethod("getInitialApplication").invoke(null, (Object[]) null);
|
||||
}
|
||||
|
||||
}
|
@ -31,13 +31,16 @@ import com.topjohnwu.magisk.module.BaseModule;
|
||||
import com.topjohnwu.magisk.receivers.PrivateBroadcastReceiver;
|
||||
import com.topjohnwu.magisk.services.MonitorService;
|
||||
import com.topjohnwu.magisk.services.QuickSettingTileService;
|
||||
import com.topjohnwu.magisk.services.TileService;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
@ -68,6 +71,12 @@ public class Utils {
|
||||
if (!Shell.rootAccess()) {
|
||||
Snackbar.make(((Activity) context).findViewById(android.R.id.content), R.string.no_root_access, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
if (PrefHelper.CheckBool("keep_root_off")) {
|
||||
Utils.toggleRoot(false);
|
||||
}
|
||||
if (PrefHelper.CheckBool("enable_quicktile")) {
|
||||
Utils.SetupQuickSettingsTile(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean fileExist(String path) {
|
||||
@ -201,19 +210,19 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static void SetupQuickSettingsTile(Context mContext) {
|
||||
Log.d("Magisk", "Utils: SetupQuickSettings called");
|
||||
Logger.dh("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");
|
||||
Logger.dh("Utils: Marshmallow build detected");
|
||||
String mLabelString;
|
||||
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);
|
||||
Logger.dh("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);
|
||||
@ -255,9 +264,67 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void installTile(Context context) {
|
||||
|
||||
String qsTileId = "intent(" + TileService.TILE_ID + ")";
|
||||
List<String> lines = Shell.su("settings get secure sysui_qs_tiles");
|
||||
if (lines != null && lines.size() == 1) {
|
||||
List<String> tiles = new LinkedList<String>(Arrays.asList(lines.get(0).split(",")));
|
||||
if (tiles.size() > 1) {
|
||||
for (String tile : tiles) {
|
||||
if (tile.equals(qsTileId)) {
|
||||
Toast.makeText(context, "Tile already installed", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
String newTiles = TextUtils.join(",", tiles);
|
||||
Shell.su("settings put secure sysui_qs_tiles \"" + newTiles + "\"");
|
||||
Toast.makeText(context, "Tile installed", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
Toast.makeText(context, "Tile installation error", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
|
||||
public static void uninstallTile(Context context) {
|
||||
|
||||
String qsTileId = "intent(" + TileService.TILE_ID + ")";
|
||||
List<String> lines = Shell.su("settings get secure sysui_qs_tiles");
|
||||
if (lines != null && lines.size() == 1) {
|
||||
List<String> tiles = new LinkedList<String>(Arrays.asList(lines.get(0).split(",")));
|
||||
if (tiles.size() > 1) {
|
||||
boolean isPresent = false;
|
||||
for (int i = 0; i < tiles.size(); i++) {
|
||||
if (tiles.get(i).equals(qsTileId)) {
|
||||
isPresent = true;
|
||||
tiles.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isPresent) {
|
||||
String newTiles = TextUtils.join(",", tiles);
|
||||
Shell.su("settings put secure sysui_qs_tiles \"" + newTiles + "\"");
|
||||
Toast.makeText(context, "Tile uninstalled", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
Toast.makeText(context, "Tile already uninstalled", Toast.LENGTH_SHORT).show();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Toast.makeText(context, "Tile uninstallation error", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
|
||||
private void refreshService(Context context) {
|
||||
context.startService(new Intent(context, TileService.class));
|
||||
}
|
||||
|
||||
|
||||
public static void UpdateRootFragmentUI(Context context) {
|
||||
|
||||
Log.d("Magisk", "Utils: UpdateRF called");
|
||||
Logger.dh("Magisk", "Utils: UpdateRF called");
|
||||
Intent intent = new Intent(context, RootFragment.class);
|
||||
intent.setAction("com.magisk.UPDATEUI");
|
||||
context.sendBroadcast(intent);
|
||||
|
Reference in New Issue
Block a user