From 56f10e238b88195bf7ee27b82c9bd9dd5d8cbd57 Mon Sep 17 00:00:00 2001 From: dvdandroid Date: Tue, 23 Aug 2016 11:39:18 +0200 Subject: [PATCH] UI improvements --- .../com/topjohnwu/magisk/MagiskFragment.java | 181 +++++++++++++++ .../com/topjohnwu/magisk/RootFragment.java | 105 --------- .../com/topjohnwu/magisk/WelcomeActivity.java | 56 ++--- .../topjohnwu/magisk/rv/ModulesAdapter.java | 2 +- app/src/main/res/drawable/ic_check_circle.xml | 9 + app/src/main/res/drawable/ic_error.xml | 9 + app/src/main/res/drawable/ic_help.xml | 9 + app/src/main/res/drawable/magisk.xml | 10 + app/src/main/res/layout/magisk_fragment.xml | 214 ++++++++++++++++++ app/src/main/res/menu/drawer.xml | 5 + app/src/main/res/values/colors.xml | 3 + app/src/main/res/values/strings.xml | 11 +- 12 files changed, 476 insertions(+), 138 deletions(-) create mode 100644 app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java create mode 100644 app/src/main/res/drawable/ic_check_circle.xml create mode 100644 app/src/main/res/drawable/ic_error.xml create mode 100644 app/src/main/res/drawable/ic_help.xml create mode 100644 app/src/main/res/drawable/magisk.xml create mode 100644 app/src/main/res/layout/magisk_fragment.xml diff --git a/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java b/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java new file mode 100644 index 000000000..f091a90ef --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java @@ -0,0 +1,181 @@ +package com.topjohnwu.magisk; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CompoundButton; +import android.widget.ImageView; +import android.widget.Switch; +import android.widget.TextView; + +import com.topjohnwu.magisk.utils.Utils; + +import java.io.File; + +import butterknife.BindColor; +import butterknife.BindView; +import butterknife.ButterKnife; + +public class MagiskFragment extends Fragment { + + @BindView(R.id.rootSwitchView) View rootToggleView; + @BindView(R.id.root_toggle) Switch rootToggle; + + @BindView(R.id.selinuxSwitchView) View selinuxToggleView; + @BindView(R.id.selinux_toggle) Switch selinuxToggle; + + @BindView(R.id.magisk_status_container) View magiskStatusContainer; + @BindView(R.id.magisk_status_icon) ImageView magiskStatusIcon; + @BindView(R.id.magisk_version) TextView magiskVersion; + + @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; + + @BindColor(R.color.red500) int red500; + @BindColor(R.color.green500) int green500; + @BindColor(R.color.grey500) int grey500; + + int statusOK = R.drawable.ic_check_circle; + int statusError = R.drawable.ic_error; + int statusUnknown = R.drawable.ic_help; + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.magisk_fragment, container, false); + ButterKnife.bind(this, view); + + updateStatus(); + + rootToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean b) { + Utils.su(b ? "setprop magisk.root 1" : "setprop magisk.root 0"); + updateStatus(); + } + }); + + selinuxToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean b) { + Utils.su(b ? "setenforce 1" : "setenforce 0"); + updateStatus(); + } + }); + + new android.os.Handler().postDelayed(new Runnable() { + @Override + public void run() { + updateStatus(); // update status again + } + }, 1000); + + + return view; + } + + private void updateStatus() { + String selinux = Utils.sh("getenforce"); + String version = Utils.sh("getprop magisk.version"); + + if (TextUtils.isEmpty(version)) { + magiskStatusContainer.setBackgroundColor(grey500); + magiskStatusIcon.setImageResource(statusUnknown); + + magiskVersion.setTextColor(grey500); + magiskVersion.setText("?"); + } else { + magiskStatusContainer.setBackgroundColor(green500); + magiskStatusIcon.setImageResource(statusOK); + + magiskVersion.setTextColor(green500); + magiskVersion.setText(getString(R.string.magisk_version, version)); + } + + if (selinux.equals("Enforcing")) { + selinuxStatusContainer.setBackgroundColor(green500); + selinuxStatusIcon.setImageResource(statusOK); + + selinuxStatus.setText(R.string.selinux_enforcing_info); + selinuxStatus.setTextColor(green500); + selinuxToggle.setChecked(true); + } else { + selinuxStatusContainer.setBackgroundColor(red500); + selinuxStatusIcon.setImageResource(statusError); + + selinuxStatus.setText(R.string.selinux_permissive_info); + selinuxStatus.setTextColor(red500); + selinuxToggle.setChecked(false); + } + + if (new File("/system/framework/twframework.jar").exists()) { + selinuxToggleView.setVisibility(View.GONE); + selinuxStatus.append("\n" + getString(R.string.selinux_samsung)); + } + + if (new File("/system/xbin/su").exists()) { + rootStatusContainer.setBackgroundColor(red500); + rootStatusIcon.setImageResource(statusError); + + rootStatus.setTextColor(red500); + rootToggle.setChecked(true); + + safetyNetStatusIcon.setImageResource(statusError); + + if (!Utils.rootAccess) { + rootStatusContainer.setBackgroundColor(red500); + rootStatusIcon.setImageResource(statusError); + rootStatus.setTextColor(red500); + rootStatus.setText(R.string.root_system); + + rootToggleView.setVisibility(View.GONE); + selinuxToggleView.setVisibility(View.GONE); + + safetyNetStatus.setText(R.string.root_system_info); + } else { + rootStatusContainer.setBackgroundColor(green500); + rootStatusIcon.setImageResource(statusOK); + rootStatus.setTextColor(green500); + rootStatus.setText(R.string.root_mounted); + + safetyNetStatus.setText(R.string.root_mounted_info); + } + } else { + rootStatusContainer.setBackgroundColor(green500); + rootStatusIcon.setImageResource(red500); + + rootStatus.setTextColor(green500); + rootToggle.setChecked(false); + + safetyNetStatusIcon.setImageResource(statusOK); + + if (!Utils.rootAccess) { + rootStatusContainer.setBackgroundColor(red500); + rootStatusIcon.setImageResource(statusError); + rootStatus.setTextColor(red500); + rootStatus.setText(R.string.root_none); + + rootToggleView.setVisibility(View.GONE); + selinuxToggleView.setVisibility(View.GONE); + + safetyNetStatusIcon.setImageResource(statusError); + safetyNetStatus.setText(R.string.root_none_info); + } else { + rootStatus.setText(R.string.root_unmounted); + safetyNetStatus.setText(R.string.root_unmounted_info); + } + } + } +} diff --git a/app/src/main/java/com/topjohnwu/magisk/RootFragment.java b/app/src/main/java/com/topjohnwu/magisk/RootFragment.java index 28779f8ad..7f31b265c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/RootFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/RootFragment.java @@ -1,112 +1,7 @@ package com.topjohnwu.magisk; -import android.graphics.Color; -import android.os.Bundle; -import android.support.annotation.Nullable; import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CompoundButton; -import android.widget.Switch; -import android.widget.TextView; - -import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.utils.Utils; - -import java.io.File; public class RootFragment extends Fragment { - private Switch rootToggle, selinuxToggle; - private TextView magiskVersion, rootStatus, selinuxStatus, safetyNet, permissive; - - @Nullable - @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.root_fragment, container, false); - - magiskVersion = (TextView) view.findViewById(R.id.magisk_version); - rootToggle = (Switch) view.findViewById(R.id.root_toggle); - selinuxToggle = (Switch) view.findViewById(R.id.selinux_toggle); - rootStatus = (TextView) view.findViewById(R.id.root_status); - selinuxStatus = (TextView) view.findViewById(R.id.selinux_status); - safetyNet = (TextView) view.findViewById(R.id.safety_net); - permissive = (TextView) view.findViewById(R.id.permissive); - - updateStatus(); - - rootToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - Utils.su(b ? "setprop magisk.root 1" : "setprop magisk.root 0"); - updateStatus(); - } - }); - - selinuxToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - Utils.su(b ? "setenforce 1" : "setenforce 0"); - updateStatus(); - } - }); - - return view; - } - - private void updateStatus() { - String selinux = Utils.sh("getenforce"); - String version = Utils.sh("getprop magisk.version"); - - magiskVersion.setText(getString(R.string.magisk_version, version)); - selinuxStatus.setText(selinux); - - if (selinux.equals("Enforcing")) { - selinuxStatus.setTextColor(Color.GREEN); - selinuxToggle.setChecked(true); - permissive.setText(R.string.selinux_enforcing_info); - permissive.setTextColor(Color.GREEN); - } else { - selinuxStatus.setTextColor(Color.RED); - selinuxToggle.setChecked(false); - permissive.setText(R.string.selinux_permissive_info); - permissive.setTextColor(Color.RED); - } - - if (new File("/system/framework/twframework.jar").exists()) { - selinuxToggle.setEnabled(false); - permissive.setText(R.string.selinux_samsung); - } - - if (new File("/system/xbin/su").exists()) { - rootStatus.setTextColor(Color.RED); - safetyNet.setTextColor(Color.RED); - rootToggle.setChecked(true); - - if (!Utils.rootAccess) { - rootStatus.setText(R.string.root_system); - safetyNet.setText(R.string.root_system_info); - rootToggle.setEnabled(false); - selinuxToggle.setEnabled(false); - } else { - rootStatus.setText(R.string.root_mounted); - safetyNet.setText(R.string.root_mounted_info); - } - } else { - rootStatus.setTextColor(Color.GREEN); - safetyNet.setTextColor(Color.GREEN); - rootToggle.setChecked(false); - - if (!Utils.rootAccess) { - rootStatus.setText(R.string.root_none); - safetyNet.setText(R.string.root_none_info); - rootToggle.setEnabled(false); - selinuxToggle.setEnabled(false); - } else { - rootStatus.setText(R.string.root_unmounted); - safetyNet.setText(R.string.root_unmounted_info); - } - } - } } diff --git a/app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java b/app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java index e39170b3e..f03cdb88c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java @@ -26,39 +26,15 @@ import butterknife.ButterKnife; public class WelcomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { private static final String SELECTED_ITEM_ID = "SELECTED_ITEM_ID"; - private final Handler mDrawerHandler = new Handler(); public static Init initialize; public static View view; - + private final Handler mDrawerHandler = new Handler(); @BindView(R.id.toolbar) Toolbar toolbar; @BindView(R.id.drawer_layout) DrawerLayout drawer; @BindView(R.id.nav_view) NavigationView navigationView; @IdRes - private int mSelectedId = R.id.modules;// for now - - public static class Init extends AsyncTask { - - @Override - protected Void doInBackground(Void... voids) { - // Check root access - Utils.checkRoot(); - // Permission for java code to read /cache files - if (Utils.rootAccess) { - Utils.su("chmod 755 /cache", "chmod 644 /cache/magisk.log"); - } - return null; - } - - @Override - protected void onPostExecute(Void v) { - super.onPostExecute(v); - - if (!Utils.rootAccess) { - Snackbar.make(view, R.string.no_root_access, Snackbar.LENGTH_LONG).show(); - } - } - } + private int mSelectedId = R.id.magisk; @Override protected void onCreate(final Bundle savedInstanceState) { @@ -73,7 +49,6 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView initialize.execute(); - setSupportActionBar(toolbar); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) { @@ -143,6 +118,10 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView private void navigate(final int itemId) { Fragment navFragment = null; switch (itemId) { + case R.id.magisk: + setTitle(R.string.magisk); + navFragment = new MagiskFragment(); + break; case R.id.root: setTitle(R.string.root); navFragment = new RootFragment(); @@ -168,4 +147,27 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView } } } + + public static class Init extends AsyncTask { + + @Override + protected Void doInBackground(Void... voids) { + // Check root access + Utils.checkRoot(); + // Permission for java code to read /cache files + if (Utils.rootAccess) { + Utils.su("chmod 755 /cache", "chmod 644 /cache/magisk.log"); + } + return null; + } + + @Override + protected void onPostExecute(Void v) { + super.onPostExecute(v); + + if (!Utils.rootAccess) { + Snackbar.make(view, R.string.no_root_access, Snackbar.LENGTH_LONG).show(); + } + } + } } diff --git a/app/src/main/java/com/topjohnwu/magisk/rv/ModulesAdapter.java b/app/src/main/java/com/topjohnwu/magisk/rv/ModulesAdapter.java index 191c909b4..fd6a99d11 100644 --- a/app/src/main/java/com/topjohnwu/magisk/rv/ModulesAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/rv/ModulesAdapter.java @@ -66,7 +66,7 @@ public class ModulesAdapter extends RecyclerView.Adapter + + diff --git a/app/src/main/res/drawable/ic_error.xml b/app/src/main/res/drawable/ic_error.xml new file mode 100644 index 000000000..a5884273f --- /dev/null +++ b/app/src/main/res/drawable/ic_error.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_help.xml b/app/src/main/res/drawable/ic_help.xml new file mode 100644 index 000000000..98d384f8b --- /dev/null +++ b/app/src/main/res/drawable/ic_help.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/magisk.xml b/app/src/main/res/drawable/magisk.xml new file mode 100644 index 000000000..f4e874645 --- /dev/null +++ b/app/src/main/res/drawable/magisk.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/magisk_fragment.xml b/app/src/main/res/layout/magisk_fragment.xml new file mode 100644 index 000000000..cb4795fad --- /dev/null +++ b/app/src/main/res/layout/magisk_fragment.xml @@ -0,0 +1,214 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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 dd1f2bf55..5924d7d33 100644 --- a/app/src/main/res/menu/drawer.xml +++ b/app/src/main/res/menu/drawer.xml @@ -3,6 +3,11 @@ + + #757575 #FFFFFF #BDBDBD + #F44336 + #4CAF50 + #9E9E9E diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1a0ae0106..9fa9e4313 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,17 +1,17 @@ Magisk Manager - Mounted + Root mounted Root mounted and enabled. Safety Net (Android Pay) will NOT work - Not Mounted + Root not mounted Safety Net (Android Pay) should work, but no root temporarily SELinux is enforced - Only turn off SELinux if necessary! + SELinux is permissive\nOnly turn off SELinux if necessary! (unavailable) Boot Version: Root Status: - Selinux Status: + SeLinux is %s Root Toggle - Selinux Toggle + SeLinux Toggle Improperly Installed Root improperly installed. Safety Net (Android Pay) will NOT work, and impossible to toggle Not Rooted @@ -42,5 +42,6 @@ Could not write log to SD card: This feature will not work without permission to write external storage. Module will be enabled at next reboot + Magisk