Commit ab318ef9 authored by dvdandroid's avatar dvdandroid

Updated UI

Added "Root" section
parent c86c2661
...@@ -9,7 +9,7 @@ android { ...@@ -9,7 +9,7 @@ android {
applicationId "com.topjohnwu.magisk" applicationId "com.topjohnwu.magisk"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 24 targetSdkVersion 24
versionCode 3 versionCode 4
versionName "2.0" versionName "2.0"
} }
buildTypes { buildTypes {
......
package com.topjohnwu.magisk;
import android.os.AsyncTask;
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.ImageView;
import android.widget.ProgressBar;
import android.widget.Switch;
import android.widget.TextView;
import com.topjohnwu.magisk.utils.Shell;
import java.io.File;
import java.util.List;
import butterknife.BindColor;
import butterknife.BindView;
import butterknife.ButterKnife;
public class RootFragment extends Fragment {
@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;
@BindColor(R.color.red500) int red500;
@BindColor(R.color.green500) int green500;
@BindColor(R.color.grey500) int grey500;
@BindColor(R.color.accent) int accent;
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.root_fragment, container, false);
ButterKnife.bind(this, view);
new updateUI().execute();
rootToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
Shell.su(b ? "setprop magisk.root 1" : "setprop magisk.root 0");
new updateUI().execute();
}
});
selinuxToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
Shell.su(b ? "setenforce 1" : "setenforce 0");
new updateUI().execute();
}
});
return view;
}
private class updateUI extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... voids) {
// Make sure static block invoked
Shell.rootAccess();
return null;
}
@Override
protected void onPostExecute(Void v) {
super.onPostExecute(v);
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<String> selinux = Shell.sh("getenforce");
if (selinux.isEmpty()) {
selinuxStatusContainer.setBackgroundColor(grey500);
selinuxStatusIcon.setImageResource(statusUnknown);
selinuxStatus.setText(R.string.selinux_error_info);
selinuxStatus.setTextColor(grey500);
selinuxToggle.setChecked(false);
} else if (selinux.get(0).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_info));
}
switch (Shell.rootStatus) {
case -1:
// Root Error
rootStatusContainer.setBackgroundColor(grey500);
rootStatusIcon.setImageResource(statusUnknown);
rootStatus.setTextColor(grey500);
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(green500);
rootStatusIcon.setImageResource(statusOK);
rootStatus.setTextColor(green500);
rootStatus.setText(R.string.root_none);
rootToggle.setChecked(false);
safetyNetStatusIcon.setImageResource(statusOK);
safetyNetStatus.setText(R.string.root_none_info);
break;
case 1:
// Proper root
if (new File("/system/xbin/su").exists()) {
// Mounted
rootStatusContainer.setBackgroundColor(accent);
rootStatusIcon.setImageResource(statusError);
rootStatus.setTextColor(accent);
rootStatus.setText(R.string.root_mounted);
rootToggle.setChecked(true);
safetyNetStatusIcon.setImageResource(statusError);
safetyNetStatus.setText(R.string.root_mounted_info);
break;
} else {
// Not Mounted
rootStatusContainer.setBackgroundColor(green500);
rootStatusIcon.setImageResource(statusOK);
rootStatus.setTextColor(green500);
rootStatus.setText(R.string.root_unmounted);
rootToggle.setChecked(false);
safetyNetStatusIcon.setImageResource(statusOK);
safetyNetStatus.setText(R.string.root_unmounted_info);
break;
}
case 2:
// Improper root
rootStatusContainer.setBackgroundColor(red500);
rootStatusIcon.setImageResource(statusError);
rootStatus.setTextColor(red500);
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;
}
}
}
}
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#fff"
android:pathData="M19,9h-4V3H9v6H5l7,7 7,-7zM5,18v2h14v-2H5z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#fff"
android:pathData="M1,21h22L12,2 1,21zM13,18h-2v-2h2v2zM13,14h-2v-4h2v4z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="#000"
android:pathData="M3,5A2,2 0 0,1 5,3H19A2,2 0 0,1 21,5V19A2,2 0 0,1 19,21H5C3.89,21 3,20.1 3,19V5M7,18H9L9.35,16H13.35L13,18H15L15.35,16H17.35L17.71,14H15.71L16.41,10H18.41L18.76,8H16.76L17.12,6H15.12L14.76,8H10.76L11.12,6H9.12L8.76,8H6.76L6.41,10H8.41L7.71,14H5.71L5.35,16H7.35L7,18M10.41,10H14.41L13.71,14H9.71L10.41,10Z"/>
</vector>
\ No newline at end of file
...@@ -4,58 +4,14 @@ ...@@ -4,58 +4,14 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:layout_marginTop="?attr/actionBarSize"> android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<android.support.v7.widget.CardView
android:id="@+id/rootSwitchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="2dp"
app:cardCornerRadius="0dp"
android:visibility="gone">
<Switch
android:id="@+id/root_toggle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:checked="true"
android:text="@string/root_toggle"
android:textSize="16sp"/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/selinuxSwitchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:elevation="2dp"
app:cardCornerRadius="0dp"
android:visibility="gone">
<Switch
android:id="@+id/selinux_toggle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:checked="true"
android:text="@string/selinux_toggle"
android:textSize="16sp"/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView <android.support.v7.widget.CardView
android:id="@+id/magiskStatusView" android:id="@+id/magiskStatusView"
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -64,8 +20,7 @@ ...@@ -64,8 +20,7 @@
android:layout_marginLeft="5dip" android:layout_marginLeft="5dip"
android:layout_marginRight="5dip" android:layout_marginRight="5dip"
android:layout_marginTop="6dp" android:layout_marginTop="6dp"
app:cardUseCompatPadding="true" app:cardUseCompatPadding="true">
android:visibility="gone">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -76,6 +31,7 @@ ...@@ -76,6 +31,7 @@
android:id="@+id/magisk_status_container" android:id="@+id/magisk_status_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="100dp" android:layout_height="100dp"
android:background="?android:attr/selectableItemBackground"
android:foregroundGravity="center" android:foregroundGravity="center"
android:orientation="vertical"> android:orientation="vertical">
...@@ -85,6 +41,12 @@ ...@@ -85,6 +41,12 @@
android:layout_height="84dp" android:layout_height="84dp"
android:layout_gravity="center"/> android:layout_gravity="center"/>
<ProgressBar
android:id="@+id/progressBarVersion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
</FrameLayout> </FrameLayout>
<TextView <TextView
...@@ -98,19 +60,17 @@ ...@@ -98,19 +60,17 @@
</LinearLayout> </LinearLayout>
</android.support.v7.widget.CardView> </android.support.v7.widget.CardView>
<android.support.v7.widget.CardView <android.support.v7.widget.CardView
android:id="@+id/rootStatusView" android:id="@+id/app_updateView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="4dp" android:layout_marginBottom="4dp"
android:layout_marginLeft="5dip" android:layout_marginLeft="5dip"
android:layout_marginRight="5dip" android:layout_marginRight="5dip"
android:layout_marginTop="6dp" android:layout_marginTop="6dp"
app:cardUseCompatPadding="true" app:cardUseCompatPadding="true">
android:visibility="gone">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -118,62 +78,33 @@ ...@@ -118,62 +78,33 @@
android:orientation="vertical"> android:orientation="vertical">
<FrameLayout <FrameLayout
android:id="@+id/root_status_container" android:id="@+id/app_check_updates_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="100dp" android:layout_height="100dp"
android:foregroundGravity="center" android:foregroundGravity="center"
android:orientation="vertical"> android:orientation="vertical">
<ImageView <ImageView
android:id="@+id/root_status_icon" android:id="@+id/app_check_updates_icon"
android:layout_width="84dp" android:layout_width="84dp"
android:layout_height="84dp" android:layout_height="84dp"
android:layout_gravity="center"/>
</FrameLayout>
<TextView
android:id="@+id/root_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:gravity="center" android:src="@drawable/ic_check_circle"/>
android:padding="6dp"
android:textStyle="bold"/>
</LinearLayout>
</android.support.v7.widget.CardView> <ProgressBar
android:id="@+id/app_check_updates_progress"
<android.support.v7.widget.CardView android:layout_width="wrap_content"
android:id="@+id/safetynetStatusView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginTop="6dp"
app:cardUseCompatPadding="true"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:layout_gravity="center"/>
android:padding="4dp">
<ImageView </FrameLayout>
android:id="@+id/safety_net_icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:tint="#757575"/>
<TextView <TextView
android:id="@+id/safety_net_status" android:id="@+id/app_check_updates_status"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:gravity="center"
android:padding="6dp" android:padding="6dp"
android:textStyle="bold"/> android:textStyle="bold"/>
...@@ -182,15 +113,14 @@ ...@@ -182,15 +113,14 @@
</android.support.v7.widget.CardView> </android.support.v7.widget.CardView>
<android.support.v7.widget.CardView <android.support.v7.widget.CardView
android:id="@+id/selinuxStatusView" android:id="@+id/magisk_updateView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="4dp" android:layout_marginBottom="4dp"
android:layout_marginLeft="5dip" android:layout_marginLeft="5dip"
android:layout_marginRight="5dip" android:layout_marginRight="5dip"
android:layout_marginTop="6dp" android:layout_marginTop="6dp"
app:cardUseCompatPadding="true" app:cardUseCompatPadding="true">
android:visibility="gone">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -198,22 +128,30 @@ ...@@ -198,22 +128,30 @@
android:orientation="vertical"> android:orientation="vertical">
<FrameLayout <FrameLayout
android:id="@+id/selinux_status_container" android:id="@+id/magisk_check_updates_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="100dp" android:layout_height="100dp"
android:background="?android:attr/selectableItemBackground"
android:foregroundGravity="center" android:foregroundGravity="center"
android:orientation="vertical"> android:orientation="vertical">
<ImageView <ImageView
android:id="@+id/selinux_status_icon" android:id="@+id/magisk_check_updates_icon"
android:layout_width="84dp" android:layout_width="84dp"
android:layout_height="84dp" android:layout_height="84dp"
android:layout_gravity="center"
android:src="@drawable/ic_check_circle"/>
<ProgressBar
android:id="@+id/magisk_check_updates_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/> android:layout_gravity="center"/>
</FrameLayout> </FrameLayout>
<TextView <TextView
android:id="@+id/selinux_status" android:id="@+id/magisk_check_updates_status"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
...@@ -224,7 +162,6 @@ ...@@ -224,7 +162,6 @@
</LinearLayout> </LinearLayout>
</android.support.v7.widget.CardView> </android.support.v7.widget.CardView>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginTop="?attr/actionBarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<android.support.v7.widget.CardView
android:id="@+id/rootSwitchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="2dp"
android:visibility="gone"
app:cardCornerRadius="0dp">
<Switch
android:id="@+id/root_toggle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:checked="true"
android:text="@string/root_toggle"
android:textSize="16sp"/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/selinuxSwitchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="2dp"
android:visibility="gone"
app:cardCornerRadius="0dp">
<Switch
android:id="@+id/selinux_toggle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:checked="true"
android:text="@string/selinux_toggle"
android:textSize="16sp"/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/rootStatusView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginTop="6dp"
android:visibility="gone"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:id="@+id/root_status_container"
android:layout_width="match_parent"
android:layout_height="100dp"
android:foregroundGravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/root_status_icon"
android:layout_width="84dp"
android:layout_height="84dp"
android:layout_gravity="center"/>
</FrameLayout>
<TextView
android:id="@+id/root_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:padding="6dp"
android:textStyle="bold"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/safetynetStatusView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginTop="6dp"
android:visibility="gone"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="4dp">
<ImageView
android:id="@+id/safety_net_icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:tint="#757575"/>
<TextView
android:id="@+id/safety_net_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="6dp"
android:textStyle="bold"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/selinuxStatusView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginTop="6dp"
android:visibility="gone"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:id="@+id/selinux_status_container"
android:layout_width="match_parent"
android:layout_height="100dp"
android:foregroundGravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/selinux_status_icon"
android:layout_width="84dp"
android:layout_height="84dp"
android:layout_gravity="center"/>
</FrameLayout>
<TextView
android:id="@+id/selinux_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:padding="6dp"
android:textStyle="bold"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
\ No newline at end of file
...@@ -10,6 +10,11 @@ ...@@ -10,6 +10,11 @@
android:icon="@drawable/magisk" android:icon="@drawable/magisk"
android:title="@string/magisk"/> android:title="@string/magisk"/>
<item
android:id="@+id/root"
android:icon="@drawable/root"
android:title="@string/root"/>
<item <item
android:id="@+id/modules" android:id="@+id/modules"
android:icon="@drawable/ic_extension" android:icon="@drawable/ic_extension"
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<color name="red500">#F44336</color> <color name="red500">#F44336</color>
<color name="green500">#4CAF50</color> <color name="green500">#4CAF50</color>
<color name="blue500">#2196F3</color>
<color name="grey500">#9E9E9E</color> <color name="grey500">#9E9E9E</color>
</resources> </resources>
...@@ -64,5 +64,10 @@ ...@@ -64,5 +64,10 @@
<string name="never_show_again">Don\'t show again</string> <string name="never_show_again">Don\'t show again</string>
<string name="error_download_file">Error downloading file</string> <string name="error_download_file">Error downloading file</string>
<string name="flash_recovery">File downloaded in Magisk directory, you can flash it in recovery</string> <string name="flash_recovery">File downloaded in Magisk directory, you can flash it in recovery</string>
<string name="root">Root</string>
<string name="app_update_available">An update for Magisk Manager is available!</string>
<string name="magisk_update_available">An update for Magisk is available!</string>
<string name="cannot_check_updates">Cannot check for updates</string>
<string name="up_to_date">You\'ve got the latest version available of %1$s</string>
</resources> </resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment