Reduce boilerplate

This commit is contained in:
topjohnwu 2017-08-28 00:27:10 +08:00
parent 1ce1a94a35
commit a78950e822
6 changed files with 23 additions and 14 deletions

View File

@ -35,7 +35,7 @@ public class FlashActivity extends Activity {
@OnClick(R.id.reboot)
public void reboot() {
Shell.getShell(this).su_raw("reboot");
getShell().su_raw("reboot");
}
@Override

View File

@ -145,7 +145,7 @@ public class MagiskFragment extends Fragment
@Override
public void onDownloadDone(Uri uri) {
if (Shell.rootAccess()) {
Shell.getShell(getActivity()).su_raw(
getShell().su_raw(
"rm -f /dev/.magisk",
"echo \"BOOTIMAGE=" + boot + "\" >> /dev/.magisk",
"echo \"KEEPFORCEENCRYPT=" + String.valueOf(enc) + "\" >> /dev/.magisk",
@ -209,7 +209,7 @@ public class MagiskFragment extends Fragment
@Override
public void onFinish() {
progress.setMessage(getString(R.string.reboot_countdown, 0));
Shell.getShell(getActivity()).su_raw(
getShell().su_raw(
"mv -f " + uninstaller + " /cache/" + UNINSTALLER,
"mv -f " + utils + " /data/magisk/" + UTIL_FUNCTIONS,
"reboot"

View File

@ -130,16 +130,15 @@ public class MagiskLogFragment extends Fragment {
@SuppressLint("DefaultLocale")
@Override
protected Object doInBackground(Object... params) {
MagiskManager magiskManager = MagiskLogFragment.this.getApplication();
mode = (int) params[0];
switch (mode) {
case 0:
StringBuildingList logList = new StringBuildingList();
Shell.getShell(magiskManager).su(logList, "cat " + MAGISK_LOG);
getShell().su(logList, "cat " + MAGISK_LOG);
return logList.toString();
case 1:
Shell.getShell(magiskManager).su_raw("echo > " + MAGISK_LOG);
getShell().su_raw("echo > " + MAGISK_LOG);
SnackbarMaker.make(txtLog, R.string.logs_cleared, Snackbar.LENGTH_SHORT).show();
return "";
@ -160,7 +159,7 @@ public class MagiskLogFragment extends Fragment {
try (FileWriter out = new FileWriter(targetFile)) {
FileWritingList fileWritingList = new FileWritingList(out);
Shell.getShell(magiskManager).su(fileWritingList, "cat " + MAGISK_LOG);
getShell().su(fileWritingList, "cat " + MAGISK_LOG);
} catch (IOException e) {
e.printStackTrace();
return false;

View File

@ -69,7 +69,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
return new Topic[] { getApplicationContext().reloadActivity };
}
public static class SettingsFragment extends PreferenceFragment
public class SettingsFragment extends PreferenceFragment
implements SharedPreferences.OnSharedPreferenceChangeListener,
Topic.Subscriber {
@ -197,28 +197,28 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
case "disable":
enabled = prefs.getBoolean("disable", false);
if (enabled) {
Utils.createFile(Shell.getShell(magiskManager), MagiskManager.MAGISK_DISABLE_FILE);
Utils.createFile(getShell(), MagiskManager.MAGISK_DISABLE_FILE);
} else {
Utils.removeItem(Shell.getShell(magiskManager), MagiskManager.MAGISK_DISABLE_FILE);
Utils.removeItem(getShell(), MagiskManager.MAGISK_DISABLE_FILE);
}
Toast.makeText(getActivity(), R.string.settings_reboot_toast, Toast.LENGTH_LONG).show();
break;
case "magiskhide":
enabled = prefs.getBoolean("magiskhide", false);
if (enabled) {
Utils.enableMagiskHide(Shell.getShell(magiskManager));
Utils.enableMagiskHide(getShell());
} else {
Utils.disableMagiskHide(Shell.getShell(magiskManager));
Utils.disableMagiskHide(getShell());
}
break;
case "hosts":
enabled = prefs.getBoolean("hosts", false);
if (enabled) {
Shell.getShell(magiskManager).su_raw(
getShell().su_raw(
"cp -af /system/etc/hosts /magisk/.core/hosts",
"mount -o bind /magisk/.core/hosts /system/etc/hosts");
} else {
Shell.getShell(magiskManager).su_raw(
getShell().su_raw(
"umount -l /system/etc/hosts",
"rm -f /magisk/.core/hosts");
}

View File

@ -8,6 +8,7 @@ import android.view.WindowManager;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Topic;
public class Activity extends AppCompatActivity {
@ -40,6 +41,10 @@ public class Activity extends AppCompatActivity {
return (MagiskManager) super.getApplicationContext();
}
public Shell getShell() {
return Shell.getShell(this);
}
protected void setFloating() {
boolean isTablet = getResources().getBoolean(R.bool.isTablet);
if (isTablet) {

View File

@ -1,6 +1,7 @@
package com.topjohnwu.magisk.components;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Topic;
import com.topjohnwu.magisk.utils.Utils;
@ -10,6 +11,10 @@ public class Fragment extends android.support.v4.app.Fragment {
return Utils.getMagiskManager(getActivity());
}
public Shell getShell() {
return Shell.getShell(getActivity());
}
@Override
public void onResume() {
super.onResume();