Code clean-up

This commit is contained in:
d8ahazard 2016-09-24 10:07:30 -05:00
parent b1ef9361f3
commit 16c804106a
12 changed files with 41 additions and 216 deletions

View File

@ -77,6 +77,7 @@ public class AutoRootFragment extends ListFragment {
Set<String> set = new HashSet<>();
set.add("com.google.android.apps.walletnfcrel");
set.add("com.google.android.gms");
set.add("com.google.commerce.tapandpay");
editor.putStringSet("auto_blacklist", set);
editor.apply();
}

View File

@ -21,7 +21,6 @@ import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import com.topjohnwu.magisk.receivers.Receiver;
import com.topjohnwu.magisk.services.MonitorService;
import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.utils.PrefHelper;
@ -35,7 +34,7 @@ import butterknife.BindColor;
import butterknife.BindView;
import butterknife.ButterKnife;
public class RootFragment extends Fragment implements Receiver {
public class RootFragment extends Fragment {
public SharedPreferences prefs;
@BindView(R.id.progressBar)
@ -108,10 +107,7 @@ public class RootFragment extends Fragment implements Receiver {
autoRootToggle.setChecked(autoRootStatus);
new updateUI().execute();
rootToggle.setOnClickListener(toggle -> {
Utils.toggleRoot(((CompoundButton) toggle).isChecked(), getActivity());
});
rootToggle.setOnClickListener(toggle -> Utils.toggleRoot(((CompoundButton) toggle).isChecked(), getActivity()));
autoRootToggle.setOnClickListener(toggle -> {
if (!Utils.hasServicePermission(getActivity())) {
@ -128,7 +124,6 @@ public class RootFragment extends Fragment implements Receiver {
listener = (prefs1, key) -> {
if ((key.contains("autoRootEnable")) | (key.equals("root"))) {
Logger.dh("RootFragmnet, keychange detected for " + key);
new updateUI().execute();
@ -186,8 +181,6 @@ public class RootFragment extends Fragment implements Receiver {
rootToggle.setEnabled(true);
}
}
@Override
@ -197,11 +190,6 @@ public class RootFragment extends Fragment implements Receiver {
new updateUI().execute();
}
@Override
public void onResult() {
}
public class updateUI extends AsyncTask<Void, Void, Void> {
@Override
@ -219,10 +207,8 @@ public class RootFragment extends Fragment implements Receiver {
@Override
protected void onPostExecute(Void v) {
super.onPostExecute(v);
autoRootToggle.setChecked(autoRootStatus);
progressBar.setVisibility(View.GONE);
rootStatusView.setVisibility(View.VISIBLE);
safetynetStatusView.setVisibility(View.VISIBLE);
selinuxStatusView.setVisibility(View.VISIBLE);

View File

@ -2,10 +2,8 @@ package com.topjohnwu.magisk;
import android.Manifest;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Build;
@ -24,7 +22,6 @@ import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import com.topjohnwu.magisk.module.RepoHelper;
import com.topjohnwu.magisk.services.MonitorService;
import com.topjohnwu.magisk.utils.Async;
import com.topjohnwu.magisk.utils.Logger;
@ -39,7 +36,6 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
private final Handler mDrawerHandler = new Handler();
private String currentTitle;
private String tag;
@BindView(R.id.toolbar)
Toolbar toolbar;
@ -57,10 +53,8 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
setContentView(R.layout.activity_welcome);
ButterKnife.bind(this);
// Startups
PreferenceManager.setDefaultValues(this, R.xml.defaultpref, false);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (Utils.autoToggleEnabled(getApplicationContext())) {
if (!Utils.isMyServiceRunning(MonitorService.class, getApplicationContext())) {
Intent myIntent = new Intent(getApplication(), MonitorService.class);
@ -76,72 +70,52 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
this.getFragmentManager().addOnBackStackChangedListener(
() -> {
FragmentManager fragmentManager = getFragmentManager();
Fragment hm=getFragmentManager().findFragmentByTag("root");
if(hm!=null)
{
if(hm.isVisible())
{
Fragment hm = getFragmentManager().findFragmentByTag("root");
if (hm != null) {
if (hm.isVisible()) {
navigationView.setCheckedItem(R.id.root);
}
}
hm=getFragmentManager().findFragmentByTag("autoroot");
if(hm!=null)
{
if(hm.isVisible())
{
hm = getFragmentManager().findFragmentByTag("autoroot");
if (hm != null) {
if (hm.isVisible()) {
navigationView.setCheckedItem(R.id.autoroot);
}
}
hm=getFragmentManager().findFragmentByTag("magisk");
if(hm!=null)
{
if(hm.isVisible())
{
hm = getFragmentManager().findFragmentByTag("magisk");
if (hm != null) {
if (hm.isVisible()) {
navigationView.setCheckedItem(R.id.magisk);
}
}
hm=getFragmentManager().findFragmentByTag("modules");
if(hm!=null)
{
if(hm.isVisible())
{
hm = getFragmentManager().findFragmentByTag("modules");
if (hm != null) {
if (hm.isVisible()) {
navigationView.setCheckedItem(R.id.modules);
}
}
hm=getFragmentManager().findFragmentByTag("downloads");
if(hm!=null)
{
if(hm.isVisible())
{
hm = getFragmentManager().findFragmentByTag("downloads");
if (hm != null) {
if (hm.isVisible()) {
navigationView.setCheckedItem(R.id.downloads);
}
}
hm=getFragmentManager().findFragmentByTag("log");
if(hm!=null)
{
if(hm.isVisible())
{
hm = getFragmentManager().findFragmentByTag("log");
if (hm != null) {
if (hm.isVisible()) {
navigationView.setCheckedItem(R.id.log);
}
}
hm=getFragmentManager().findFragmentByTag("settings");
if(hm!=null)
{
if(hm.isVisible())
{
hm = getFragmentManager().findFragmentByTag("settings");
if (hm != null) {
if (hm.isVisible()) {
navigationView.setCheckedItem(R.id.settings);
}
}
});
Utils.init(this);
new Async.CheckUpdates(this).execute();
RepoHelper.TaskDelegate delegate = result -> {
//Do a thing here when we get a result we want
};
new Async.LoadModules(this).execute();
new Async.LoadRepos(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@ -178,7 +152,6 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
}
}
@Override
protected void onDestroy() {
super.onDestroy();
@ -195,22 +168,18 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
@Override
public void onBackPressed() {
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
int backStackEntryCount = getFragmentManager().getBackStackEntryCount();
Logger.dh("Welcomeactivity: Entrycount is " + backStackEntryCount);
if(backStackEntryCount>=2) {
if (backStackEntryCount >= 2) {
super.onBackPressed();
} else {
finish();
}
}
}
@Override
@ -231,7 +200,7 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
public void navigate(final int itemId) {
Fragment navFragment = null;
tag = "";
String tag = "";
switch (itemId) {
case R.id.magisk:
setTitle(R.string.magisk);
@ -275,7 +244,6 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
if (navFragment != null) {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
try {

View File

@ -20,6 +20,7 @@ public class AutoStartReceiver extends BroadcastReceiver {
}
if (PrefHelper.CheckBool("enable_quicktile",context)) {
Utils.SetupQuickSettingsTile(context);
}

View File

@ -1,5 +0,0 @@
package com.topjohnwu.magisk.receivers;
public interface Receiver {
void onResult();
}

View File

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

View File

@ -1,25 +0,0 @@
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.TileServiceCompat;
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,TileServiceCompat.class));
}
}
}

View File

@ -7,7 +7,6 @@ import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Build;
@ -25,7 +24,6 @@ import com.topjohnwu.magisk.utils.Utils;
import java.util.Set;
public class MonitorService extends AccessibilityService {
private static final String TAG = "MonitorService";
private Boolean disableroot;
@Override
@ -64,22 +62,18 @@ public class MonitorService extends AccessibilityService {
event.getPackageName().toString(),
event.getClassName().toString()
);
Logger.dh("MonitorService: CurrentActivity: " + event.getPackageName());
ActivityInfo activityInfo = tryGetActivity(componentName);
boolean isActivity = activityInfo != null;
if (isActivity) {
Logger.dh("MonitorService: CurrentActivity: " + componentName.getPackageName());
String mPackage = componentName.getPackageName();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
if (Utils.autoToggleEnabled(getApplicationContext())) {
Set<String> setBlackList = prefs.getStringSet("auto_blacklist", null);
String mPackage = componentName.getPackageName();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
if (Utils.autoToggleEnabled(getApplicationContext())) {
Set<String> setBlackList = prefs.getStringSet("auto_blacklist", null);
if (setBlackList != null) {
disableroot = setBlackList.contains(mPackage);
ForceRoot(!disableroot);
String appFriendly = getAppName(mPackage);
ShowNotification(disableroot, appFriendly);
}
if (setBlackList != null) {
disableroot = setBlackList.contains(mPackage);
ForceRoot(!disableroot);
String appFriendly = getAppName(mPackage);
ShowNotification(disableroot, appFriendly);
}
}
}
@ -98,36 +92,20 @@ public class MonitorService extends AccessibilityService {
}
}
private ActivityInfo tryGetActivity(ComponentName componentName) {
try {
return getPackageManager().getActivityInfo(componentName, 0);
} catch (PackageManager.NameNotFoundException e) {
return null;
}
}
private void ForceRoot(Boolean rootToggle) {
String rootString = rootToggle ? "on" : "off";
if (Utils.rootEnabled() != rootToggle) {
Logger.dh("MonitorService: toggling root " + rootString);
Utils.toggleRoot(rootToggle,getApplicationContext());
Utils.toggleRoot(rootToggle, getApplicationContext());
if (Utils.rootEnabled() != rootToggle) {
Utils.toggleRoot(rootToggle,getApplicationContext());
Utils.toggleRoot(rootToggle, getApplicationContext());
Logger.dh("MonitorService: FORCING to " + rootString);
}
}
}
private void ForceEnableRoot() {
Log.d("Magisk", "MonitorService: ForceEnable called.");
Utils.toggleRoot(true,getApplicationContext());
if (!Utils.rootEnabled()) {
Utils.toggleRoot(true,getApplicationContext());
}
}
private void ShowNotification(boolean rootAction, String packageName) {
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder;

View File

@ -5,7 +5,6 @@ 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 com.kcoppock.broadcasttilesupport.BroadcastTileIntentBuilder;

View File

@ -1,58 +0,0 @@
package com.topjohnwu.magisk.utils;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.LinearLayout;
public class AnimationHelper {
public static void expand(final View v) {
v.measure(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
final int targetHeight = v.getMeasuredHeight();
v.getLayoutParams().height = 0;
v.setVisibility(View.VISIBLE);
Animation a = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
v.getLayoutParams().height = interpolatedTime == 1
? LinearLayout.LayoutParams.WRAP_CONTENT
: (int) (targetHeight * interpolatedTime);
v.requestLayout();
}
@Override
public boolean willChangeBounds() {
return true;
}
};
// 1dp/ms
a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density));
v.startAnimation(a);
}
public static void collapse(final View v) {
final int initialHeight = v.getMeasuredHeight();
Animation a = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
if (interpolatedTime == 1) {
v.setVisibility(View.GONE);
} else {
v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
v.requestLayout();
}
}
@Override
public boolean willChangeBounds() {
return true;
}
};
// 1dp/ms
a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
v.startAnimation(a);
}
}

View File

@ -1,7 +1,5 @@
package com.topjohnwu.magisk.utils;
import android.app.Application;
import android.content.Context;
import android.preference.PreferenceManager;
@ -17,7 +15,7 @@ public class PrefHelper {
public static void SetBool(String key, Boolean value, Context context) {
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(key, value).commit();
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(key, value).apply();
}

View File

@ -293,6 +293,7 @@ public class Utils {
.setVisible(true)
.build();
mContext.sendBroadcast(tileConfigurationIntent);
mContext.startService(new Intent(mContext, TileServiceCompat.class));
}
}