diff --git a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java index 98acc843e..c1a5e9e9b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java @@ -129,11 +129,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On tag = "magisk"; navFragment = new MagiskFragment(); break; - case R.id.root: - setTitle(R.string.root); - tag = "root"; - navFragment = new RootFragment(); - break; case R.id.modules: setTitle(R.string.modules); tag = "modules"; diff --git a/app/src/main/java/com/topjohnwu/magisk/RootFragment.java b/app/src/main/java/com/topjohnwu/magisk/RootFragment.java deleted file mode 100644 index a2f4b9447..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/RootFragment.java +++ /dev/null @@ -1,221 +0,0 @@ -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.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CompoundButton; -import android.widget.ImageView; -import android.widget.ProgressBar; -import android.widget.Switch; -import android.widget.TextView; - -import com.topjohnwu.magisk.utils.Logger; -import com.topjohnwu.magisk.utils.Shell; -import com.topjohnwu.magisk.utils.Utils; - -import java.io.File; -import java.util.List; - -import butterknife.BindColor; -import butterknife.BindView; -import butterknife.ButterKnife; - -public class RootFragment extends Fragment { - - public SharedPreferences prefs; - - @BindView(R.id.progressBar) ProgressBar progressBar; - @BindView(R.id.rootSwitchView) View rootToggleView; - @BindView(R.id.selinuxSwitchView) View selinuxToggleView; - @BindView(R.id.rootStatusView) View rootStatusView; - @BindView(R.id.safetynetStatusView) View safetynetStatusView; - @BindView(R.id.selinuxStatusView) View selinuxStatusView; - @BindView(R.id.root_toggle) Switch rootToggle; - @BindView(R.id.selinux_toggle) Switch selinuxToggle; - @BindView(R.id.root_status_container) View rootStatusContainer; - @BindView(R.id.root_status_icon) ImageView rootStatusIcon; - @BindView(R.id.root_status) TextView rootStatus; - @BindView(R.id.selinux_status_container) View selinuxStatusContainer; - @BindView(R.id.selinux_status_icon) ImageView selinuxStatusIcon; - @BindView(R.id.selinux_status) TextView selinuxStatus; - @BindView(R.id.safety_net_status) TextView safetyNetStatus; - @BindView(R.id.safety_net_icon) ImageView safetyNetStatusIcon; - - int statusOK = R.drawable.ic_check_circle; - int statusError = R.drawable.ic_error; - int statusUnknown = R.drawable.ic_help; - - @BindColor(R.color.green500) int colorOK; - @BindColor(R.color.yellow500) int colorWarn; - @BindColor(R.color.grey500) int colorNeutral; - @BindColor(R.color.red500) int colorFail; - - private SharedPreferences.OnSharedPreferenceChangeListener listener; - - @Nullable - @Override - 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(getActivity()); - - updateUI(); - - rootToggle.setOnClickListener(toggle -> { - new AsyncTask() { - @Override - protected Void doInBackground(Boolean... bools) { - Utils.toggleRoot(bools[0], getActivity()); - return null; - } - }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, ((CompoundButton) toggle).isChecked()); - - }); - - selinuxToggle.setOnClickListener(toggle -> { - - new AsyncTask() { - @Override - protected Void doInBackground(Boolean... bools) { - Shell.su(bools[0] ? "setenforce 1" : "setenforce 0"); - return null; - } - @Override - protected void onPostExecute(Void v) { - super.onPostExecute(v); - updateUI(); - } - }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, ((CompoundButton) toggle).isChecked()); - }); - - return view; - } - - @Override - public void onResume() { - super.onResume(); - listener = (pref, key) -> { - if ((key.contains("autoRootEnable")) || (key.equals("root"))) { - Logger.dev("RootFragmnet, keychange detected for " + key); - updateUI(); - } - - }; - prefs.registerOnSharedPreferenceChangeListener(listener); - updateUI(); - } - - @Override - public void onDestroy() { - super.onDestroy(); - prefs.unregisterOnSharedPreferenceChangeListener(listener); - } - - private void updateUI() { - progressBar.setVisibility(View.GONE); - rootStatusView.setVisibility(View.VISIBLE); - safetynetStatusView.setVisibility(View.VISIBLE); - selinuxStatusView.setVisibility(View.VISIBLE); - - if (Shell.rootAccess()) { - rootToggleView.setVisibility(View.VISIBLE); - selinuxToggleView.setVisibility(View.VISIBLE); - } - - List selinux = Shell.sh("getenforce"); - - if (selinux.isEmpty()) { - selinuxStatusContainer.setBackgroundColor(colorNeutral); - selinuxStatusIcon.setImageResource(statusUnknown); - - selinuxStatus.setText(R.string.selinux_error_info); - selinuxStatus.setTextColor(colorNeutral); - selinuxToggle.setChecked(false); - } else if (selinux.get(0).equals("Enforcing")) { - selinuxStatusContainer.setBackgroundColor(colorOK); - selinuxStatusIcon.setImageResource(statusOK); - - selinuxStatus.setText(R.string.selinux_enforcing_info); - selinuxStatus.setTextColor(colorOK); - selinuxToggle.setChecked(true); - } else { - selinuxStatusContainer.setBackgroundColor(colorFail); - selinuxStatusIcon.setImageResource(statusError); - - selinuxStatus.setText(R.string.selinux_permissive_info); - selinuxStatus.setTextColor(colorFail); - selinuxToggle.setChecked(false); - } - - if (new File("/system/framework/twframework.jar").exists()) { - selinuxStatus.append("\n" + getString(R.string.selinux_samsung_info)); - } - - switch (Shell.rootStatus) { - case -1: - // Root Error - rootStatusContainer.setBackgroundColor(colorFail); - rootStatusIcon.setImageResource(statusUnknown); - rootStatus.setTextColor(colorNeutral); - rootStatus.setText(R.string.root_error); - rootToggle.setChecked(false); - safetyNetStatusIcon.setImageResource(statusUnknown); - safetyNetStatus.setText(R.string.root_error_info); - break; - case 0: - // Not rooted - rootStatusContainer.setBackgroundColor(colorOK); - rootStatusIcon.setImageResource(statusOK); - rootStatus.setTextColor(colorOK); - rootStatus.setText(R.string.root_none); - rootToggle.setChecked(false); - safetyNetStatusIcon.setImageResource(statusOK); - safetyNetStatus.setText(R.string.root_none_info); - break; - case 1: - // Proper root - rootToggle.setEnabled(true); - if (Utils.rootEnabled()) { - // Mounted - rootStatusContainer.setBackgroundColor(colorWarn); - rootStatusIcon.setImageResource(statusError); - rootStatus.setTextColor(colorWarn); - rootStatus.setText(R.string.root_enabled); - rootToggle.setChecked(true); - safetyNetStatusIcon.setImageResource(statusError); - safetyNetStatus.setText(R.string.root_enabled_info); - break; - } else { - // Disabled - rootStatusContainer.setBackgroundColor(colorOK); - rootStatusIcon.setImageResource(statusOK); - rootStatus.setTextColor(colorOK); - rootStatus.setText(R.string.root_disabled); - rootToggle.setChecked(false); - safetyNetStatusIcon.setImageResource(statusOK); - safetyNetStatus.setText(R.string.root_disabled_info); - break; - } - case 2: - // Improper root - rootStatusContainer.setBackgroundColor(colorFail); - rootStatusIcon.setImageResource(statusError); - rootStatus.setTextColor(colorFail); - rootStatus.setText(R.string.root_system); - rootToggle.setChecked(true); - safetyNetStatusIcon.setImageResource(statusError); - safetyNetStatus.setText(R.string.root_system_info); - rootToggleView.setVisibility(View.GONE); - selinuxToggleView.setVisibility(View.GONE); - break; - } - } - -} diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java b/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java index e625da01f..d36c82543 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java @@ -12,7 +12,7 @@ import java.util.List; public class Shell { - // -1 = problematic/unknown issue; 0 = not rooted; 1 = properly rooted; 2 = improperly rooted; + // -1 = problematic/unknown issue; 0 = not rooted; 1 = properly rooted public static int rootStatus; private static Process rootShell; @@ -27,18 +27,12 @@ public class Shell { private static void init() { try { - rootShell = Runtime.getRuntime().exec(sh("getprop magisk.supath").get(0) + "/su"); + rootShell = Runtime.getRuntime().exec("su"); rootStatus = 1; - } catch (IOException e) { - try { - // Improper root - rootShell = Runtime.getRuntime().exec("su"); - rootStatus = 2; - } catch (IOException err) { - // No root - rootStatus = 0; - return; - } + } catch (IOException err) { + // No root + rootStatus = 0; + return; } rootSTDIN = new DataOutputStream(rootShell.getOutputStream()); diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java index fb37bce69..f374a9865 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -73,17 +73,6 @@ public class Utils { return Shell.rootAccess() && Boolean.parseBoolean(Shell.su(command).get(0)); } - public static void toggleRoot(Boolean b, Context context) { - if (MagiskFragment.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"); - } - PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("root", b).apply(); - } - } - static List getModList(String path) { List ret; String command = "find " + path + " -type d -maxdepth 1 ! -name \"*.core\" ! -name \"*lost+found\" ! -name \"*magisk\""; diff --git a/app/src/main/res/drawable/ic_error.xml b/app/src/main/res/drawable/ic_error.xml deleted file mode 100644 index a5884273f..000000000 --- a/app/src/main/res/drawable/ic_error.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/root.xml b/app/src/main/res/drawable/root.xml deleted file mode 100644 index bca20e4d8..000000000 --- a/app/src/main/res/drawable/root.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - \ No newline at end of file diff --git a/app/src/main/res/layout/root_fragment.xml b/app/src/main/res/layout/root_fragment.xml deleted file mode 100644 index 8d3ad22cf..000000000 --- a/app/src/main/res/layout/root_fragment.xml +++ /dev/null @@ -1,189 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/menu/drawer.xml b/app/src/main/res/menu/drawer.xml index 65910a30b..d3817b115 100644 --- a/app/src/main/res/menu/drawer.xml +++ b/app/src/main/res/menu/drawer.xml @@ -24,10 +24,6 @@ android:id="@+id/log" android:icon="@drawable/ic_bug_report" android:title="@string/log"/> - Open navigation drawer Close navigation drawer - Root Modules Downloads Log @@ -22,24 +21,6 @@ Latest version of %1$s installed - Root Toggle - SELinux Toggle - - Root Error - Safety Net Status Unknown - Not Rooted - Safety Net (Android Pay) should work - Root enabled - Root enabled. Safety Net (Android Pay) will NOT work - Root disabled - Safety Net (Android Pay) should work, but no root temporarily\nYou might need to manually add a card in Android Pay app to refresh the root status of AP - Magisk Incompatible Root Detected - Root improperly installed. Safety Net (Android Pay) will NOT work, and impossible to toggle. - - SELinux Status Unknown - SELinux is enforced - SELinux is permissive\nOnly turn off SELinux if necessary! - Samsung need custom kernel for switching SELinux status! (No info provided)