Reduce boilerplate
This commit is contained in:
parent
1ce1a94a35
commit
a78950e822
@ -35,7 +35,7 @@ public class FlashActivity extends Activity {
|
|||||||
|
|
||||||
@OnClick(R.id.reboot)
|
@OnClick(R.id.reboot)
|
||||||
public void reboot() {
|
public void reboot() {
|
||||||
Shell.getShell(this).su_raw("reboot");
|
getShell().su_raw("reboot");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -145,7 +145,7 @@ public class MagiskFragment extends Fragment
|
|||||||
@Override
|
@Override
|
||||||
public void onDownloadDone(Uri uri) {
|
public void onDownloadDone(Uri uri) {
|
||||||
if (Shell.rootAccess()) {
|
if (Shell.rootAccess()) {
|
||||||
Shell.getShell(getActivity()).su_raw(
|
getShell().su_raw(
|
||||||
"rm -f /dev/.magisk",
|
"rm -f /dev/.magisk",
|
||||||
"echo \"BOOTIMAGE=" + boot + "\" >> /dev/.magisk",
|
"echo \"BOOTIMAGE=" + boot + "\" >> /dev/.magisk",
|
||||||
"echo \"KEEPFORCEENCRYPT=" + String.valueOf(enc) + "\" >> /dev/.magisk",
|
"echo \"KEEPFORCEENCRYPT=" + String.valueOf(enc) + "\" >> /dev/.magisk",
|
||||||
@ -209,7 +209,7 @@ public class MagiskFragment extends Fragment
|
|||||||
@Override
|
@Override
|
||||||
public void onFinish() {
|
public void onFinish() {
|
||||||
progress.setMessage(getString(R.string.reboot_countdown, 0));
|
progress.setMessage(getString(R.string.reboot_countdown, 0));
|
||||||
Shell.getShell(getActivity()).su_raw(
|
getShell().su_raw(
|
||||||
"mv -f " + uninstaller + " /cache/" + UNINSTALLER,
|
"mv -f " + uninstaller + " /cache/" + UNINSTALLER,
|
||||||
"mv -f " + utils + " /data/magisk/" + UTIL_FUNCTIONS,
|
"mv -f " + utils + " /data/magisk/" + UTIL_FUNCTIONS,
|
||||||
"reboot"
|
"reboot"
|
||||||
|
@ -130,16 +130,15 @@ public class MagiskLogFragment extends Fragment {
|
|||||||
@SuppressLint("DefaultLocale")
|
@SuppressLint("DefaultLocale")
|
||||||
@Override
|
@Override
|
||||||
protected Object doInBackground(Object... params) {
|
protected Object doInBackground(Object... params) {
|
||||||
MagiskManager magiskManager = MagiskLogFragment.this.getApplication();
|
|
||||||
mode = (int) params[0];
|
mode = (int) params[0];
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 0:
|
case 0:
|
||||||
StringBuildingList logList = new StringBuildingList();
|
StringBuildingList logList = new StringBuildingList();
|
||||||
Shell.getShell(magiskManager).su(logList, "cat " + MAGISK_LOG);
|
getShell().su(logList, "cat " + MAGISK_LOG);
|
||||||
return logList.toString();
|
return logList.toString();
|
||||||
|
|
||||||
case 1:
|
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();
|
SnackbarMaker.make(txtLog, R.string.logs_cleared, Snackbar.LENGTH_SHORT).show();
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
@ -160,7 +159,7 @@ public class MagiskLogFragment extends Fragment {
|
|||||||
|
|
||||||
try (FileWriter out = new FileWriter(targetFile)) {
|
try (FileWriter out = new FileWriter(targetFile)) {
|
||||||
FileWritingList fileWritingList = new FileWritingList(out);
|
FileWritingList fileWritingList = new FileWritingList(out);
|
||||||
Shell.getShell(magiskManager).su(fileWritingList, "cat " + MAGISK_LOG);
|
getShell().su(fileWritingList, "cat " + MAGISK_LOG);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
|
@ -69,7 +69,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
|||||||
return new Topic[] { getApplicationContext().reloadActivity };
|
return new Topic[] { getApplicationContext().reloadActivity };
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SettingsFragment extends PreferenceFragment
|
public class SettingsFragment extends PreferenceFragment
|
||||||
implements SharedPreferences.OnSharedPreferenceChangeListener,
|
implements SharedPreferences.OnSharedPreferenceChangeListener,
|
||||||
Topic.Subscriber {
|
Topic.Subscriber {
|
||||||
|
|
||||||
@ -197,28 +197,28 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
|||||||
case "disable":
|
case "disable":
|
||||||
enabled = prefs.getBoolean("disable", false);
|
enabled = prefs.getBoolean("disable", false);
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
Utils.createFile(Shell.getShell(magiskManager), MagiskManager.MAGISK_DISABLE_FILE);
|
Utils.createFile(getShell(), MagiskManager.MAGISK_DISABLE_FILE);
|
||||||
} else {
|
} 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();
|
Toast.makeText(getActivity(), R.string.settings_reboot_toast, Toast.LENGTH_LONG).show();
|
||||||
break;
|
break;
|
||||||
case "magiskhide":
|
case "magiskhide":
|
||||||
enabled = prefs.getBoolean("magiskhide", false);
|
enabled = prefs.getBoolean("magiskhide", false);
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
Utils.enableMagiskHide(Shell.getShell(magiskManager));
|
Utils.enableMagiskHide(getShell());
|
||||||
} else {
|
} else {
|
||||||
Utils.disableMagiskHide(Shell.getShell(magiskManager));
|
Utils.disableMagiskHide(getShell());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "hosts":
|
case "hosts":
|
||||||
enabled = prefs.getBoolean("hosts", false);
|
enabled = prefs.getBoolean("hosts", false);
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
Shell.getShell(magiskManager).su_raw(
|
getShell().su_raw(
|
||||||
"cp -af /system/etc/hosts /magisk/.core/hosts",
|
"cp -af /system/etc/hosts /magisk/.core/hosts",
|
||||||
"mount -o bind /magisk/.core/hosts /system/etc/hosts");
|
"mount -o bind /magisk/.core/hosts /system/etc/hosts");
|
||||||
} else {
|
} else {
|
||||||
Shell.getShell(magiskManager).su_raw(
|
getShell().su_raw(
|
||||||
"umount -l /system/etc/hosts",
|
"umount -l /system/etc/hosts",
|
||||||
"rm -f /magisk/.core/hosts");
|
"rm -f /magisk/.core/hosts");
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import android.view.WindowManager;
|
|||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
import com.topjohnwu.magisk.utils.Topic;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
|
|
||||||
public class Activity extends AppCompatActivity {
|
public class Activity extends AppCompatActivity {
|
||||||
@ -40,6 +41,10 @@ public class Activity extends AppCompatActivity {
|
|||||||
return (MagiskManager) super.getApplicationContext();
|
return (MagiskManager) super.getApplicationContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Shell getShell() {
|
||||||
|
return Shell.getShell(this);
|
||||||
|
}
|
||||||
|
|
||||||
protected void setFloating() {
|
protected void setFloating() {
|
||||||
boolean isTablet = getResources().getBoolean(R.bool.isTablet);
|
boolean isTablet = getResources().getBoolean(R.bool.isTablet);
|
||||||
if (isTablet) {
|
if (isTablet) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.topjohnwu.magisk.components;
|
package com.topjohnwu.magisk.components;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
import com.topjohnwu.magisk.utils.Topic;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
@ -10,6 +11,10 @@ public class Fragment extends android.support.v4.app.Fragment {
|
|||||||
return Utils.getMagiskManager(getActivity());
|
return Utils.getMagiskManager(getActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Shell getShell() {
|
||||||
|
return Shell.getShell(getActivity());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
Loading…
Reference in New Issue
Block a user