diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 007ea3fdc..e5e871072 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,13 +12,6 @@ android:supportsRtl="true" android:theme="@style/AppTheme" tools:ignore="AllowBackup,GoogleAppIndexingWarning"> - - - - - - - diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/BaseModuleFragment.java b/app/src/main/java/com/topjohnwu/magisk/BaseModuleFragment.java similarity index 96% rename from app/src/main/java/com/topjohnwu/magisk/ui/BaseModuleFragment.java rename to app/src/main/java/com/topjohnwu/magisk/BaseModuleFragment.java index e7465c2a6..4a418b89e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/BaseModuleFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/BaseModuleFragment.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.ui; +package com.topjohnwu.magisk; import android.os.Bundle; import android.support.annotation.Nullable; @@ -11,7 +11,7 @@ import android.view.ViewGroup; import android.widget.CheckBox; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.model.Module; +import com.topjohnwu.magisk.module.Module; import com.topjohnwu.magisk.rv.ItemClickListener; import com.topjohnwu.magisk.rv.ModulesAdapter; diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/LogFragment.java b/app/src/main/java/com/topjohnwu/magisk/LogFragment.java similarity index 98% rename from app/src/main/java/com/topjohnwu/magisk/ui/LogFragment.java rename to app/src/main/java/com/topjohnwu/magisk/LogFragment.java index a5235d785..581db13b3 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/LogFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/LogFragment.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.ui; +package com.topjohnwu.magisk; import android.Manifest; import android.annotation.SuppressLint; @@ -26,7 +26,7 @@ import android.widget.TextView; import android.widget.Toast; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.ui.utils.Utils; +import com.topjohnwu.magisk.WelcomeActivity; import java.io.BufferedReader; import java.io.File; @@ -234,7 +234,7 @@ public class LogFragment extends Fragment { protected String doInBackground(File... log) { // Ensure initialize is done try { - Utils.initialize.get(); + WelcomeActivity.initialize.get(); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/ModulesFragment.java b/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java similarity index 85% rename from app/src/main/java/com/topjohnwu/magisk/ui/ModulesFragment.java rename to app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java index 4dee33a3b..67e5018dd 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/ModulesFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.ui; +package com.topjohnwu.magisk; import android.os.AsyncTask; import android.os.Bundle; @@ -13,9 +13,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ProgressBar; -import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.model.Module; -import com.topjohnwu.magisk.ui.utils.Utils; +import com.topjohnwu.magisk.module.Module; import java.io.File; import java.io.FileFilter; @@ -31,7 +29,7 @@ public class ModulesFragment extends Fragment { private static final String MAGISK_PATH = "/magisk"; private static final String MAGISK_CACHE_PATH = "/cache/magisk"; - private static List listModulesNoCache = new ArrayList<>(); + private static List listModules = new ArrayList<>(); private static List listModulesCache = new ArrayList<>(); @BindView(R.id.progressBar) ProgressBar progressBar; @@ -42,8 +40,8 @@ public class ModulesFragment extends Fragment { public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + listModules.clear(); listModulesCache.clear(); - listModulesNoCache.clear(); } @Nullable @@ -60,11 +58,11 @@ public class ModulesFragment extends Fragment { return view; } - public static class NoCacheModuleFragment extends BaseModuleFragment { + public static class NormalModuleFragment extends BaseModuleFragment { @Override protected List listModules() { - return listModulesNoCache; + return listModules; } } @@ -78,13 +76,13 @@ public class ModulesFragment extends Fragment { } - private class CheckFolders extends AsyncTask { + private class CheckFolders extends AsyncTask { @Override - protected Boolean doInBackground(Void... voids) { + protected Void doInBackground(Void... voids) { // Ensure initialize is done try { - Utils.initialize.get(); + WelcomeActivity.initialize.get(); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } @@ -109,7 +107,7 @@ public class ModulesFragment extends Fragment { if (m.isValid()) { try { m.parse(); - listModulesNoCache.add(m); + listModules.add(m); } catch (Exception ignored) { } } @@ -129,12 +127,12 @@ public class ModulesFragment extends Fragment { } } - return true; + return null; } @Override - protected void onPostExecute(Boolean result) { - super.onPostExecute(result); + protected void onPostExecute(Void v) { + super.onPostExecute(v); progressBar.setVisibility(View.GONE); } @@ -143,7 +141,7 @@ public class ModulesFragment extends Fragment { private class TabsAdapter extends FragmentPagerAdapter { String[] tabTitles = new String[]{ - "_no_cache", "_cache" + "Modules", "Cache Modules" // TODO stringify }; @@ -164,7 +162,7 @@ public class ModulesFragment extends Fragment { @Override public Fragment getItem(int position) { if (position == 0) { - return new NoCacheModuleFragment(); + return new NormalModuleFragment(); } else { return new CacheModuleFragment(); } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.java b/app/src/main/java/com/topjohnwu/magisk/RootFragment.java similarity index 67% rename from app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.java rename to app/src/main/java/com/topjohnwu/magisk/RootFragment.java index 364027bb7..28779f8ad 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/RootFragment.java @@ -1,44 +1,45 @@ -package com.topjohnwu.magisk.ui; +package com.topjohnwu.magisk; -import android.app.Activity; 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; -import static com.topjohnwu.magisk.ui.utils.Utils.su; - -public class MainActivity extends Activity { +public class RootFragment extends Fragment { private Switch rootToggle, selinuxToggle; private TextView magiskVersion, rootStatus, selinuxStatus, safetyNet, permissive; - private String suPath; + @Nullable @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.root_fragment, container, false); - magiskVersion = (TextView) findViewById(R.id.magisk_version); - rootToggle = (Switch) findViewById(R.id.root_toggle); - selinuxToggle = (Switch) findViewById(R.id.selinux_toggle); - rootStatus = (TextView) findViewById(R.id.root_status); - selinuxStatus = (TextView) findViewById(R.id.selinux_status); - safetyNet = (TextView) findViewById(R.id.safety_net); - permissive = (TextView) findViewById(R.id.permissive); + 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); - suPath = su("getprop magisk.supath"); updateStatus(); rootToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - su(b ? "setprop magisk.root 1" : "setprop magisk.root 0"); + Utils.su(b ? "setprop magisk.root 1" : "setprop magisk.root 0"); updateStatus(); } }); @@ -46,18 +47,19 @@ public class MainActivity extends Activity { selinuxToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - su(b ? "setenforce 1" : "setenforce 0"); + Utils.su(b ? "setenforce 1" : "setenforce 0"); updateStatus(); } }); - //findViewById(R.id.modules).setOnClickListener(view -> startActivity(new Intent(this, ModulesActivity.class))); + return view; } private void updateStatus() { - String selinux = su("getenforce"); + String selinux = Utils.sh("getenforce"); + String version = Utils.sh("getprop magisk.version"); - magiskVersion.setText(getString(R.string.magisk_version, su("getprop magisk.version"))); + magiskVersion.setText(getString(R.string.magisk_version, version)); selinuxStatus.setText(selinux); if (selinux.equals("Enforcing")) { @@ -82,7 +84,7 @@ public class MainActivity extends Activity { safetyNet.setTextColor(Color.RED); rootToggle.setChecked(true); - if (!new File(suPath + "/su").exists()) { + if (!Utils.rootAccess) { rootStatus.setText(R.string.root_system); safetyNet.setText(R.string.root_system_info); rootToggle.setEnabled(false); @@ -96,7 +98,7 @@ public class MainActivity extends Activity { safetyNet.setTextColor(Color.GREEN); rootToggle.setChecked(false); - if (!new File(suPath + "/su").exists()) { + if (!Utils.rootAccess) { rootStatus.setText(R.string.root_none); safetyNet.setText(R.string.root_none_info); rootToggle.setEnabled(false); @@ -107,5 +109,4 @@ public class MainActivity extends Activity { } } } - } diff --git a/app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java b/app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java index 141f2329a..01a86f12a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java @@ -1,11 +1,13 @@ package com.topjohnwu.magisk; +import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.annotation.IdRes; import android.support.annotation.NonNull; import android.support.design.widget.NavigationView; +import android.support.design.widget.Snackbar; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; import android.support.v4.view.GravityCompat; @@ -16,10 +18,7 @@ import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; -import com.topjohnwu.magisk.ui.LogFragment; -import com.topjohnwu.magisk.ui.ModulesFragment; -import com.topjohnwu.magisk.ui.RootFragment; -import com.topjohnwu.magisk.ui.utils.Utils; +import com.topjohnwu.magisk.utils.Utils; import butterknife.BindView; import butterknife.ButterKnife; @@ -28,6 +27,8 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView private static final String SELECTED_ITEM_ID = "SELECTED_ITEM_ID"; private final Handler mDrawerHandler = new Handler(); + public static Init initialize = new Init(); + public static View view; @BindView(R.id.toolbar) Toolbar toolbar; @BindView(R.id.drawer_layout) DrawerLayout drawer; @@ -36,16 +37,40 @@ public class WelcomeActivity extends AppCompatActivity implements 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(); + } + } + } + @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_welcome); + view = findViewById(R.id.toolbar); ButterKnife.bind(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); } - Utils.initialize.execute(); + initialize.execute(); setSupportActionBar(toolbar); diff --git a/app/src/main/java/com/topjohnwu/magisk/model/Module.java b/app/src/main/java/com/topjohnwu/magisk/module/Module.java similarity index 96% rename from app/src/main/java/com/topjohnwu/magisk/model/Module.java rename to app/src/main/java/com/topjohnwu/magisk/module/Module.java index 38b425375..4c6dbec4e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/Module.java +++ b/app/src/main/java/com/topjohnwu/magisk/module/Module.java @@ -1,6 +1,6 @@ -package com.topjohnwu.magisk.model; +package com.topjohnwu.magisk.module; -import com.topjohnwu.magisk.ui.utils.Utils; +import com.topjohnwu.magisk.utils.Utils; import java.io.BufferedReader; import java.io.File; 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 78da35655..191c909b4 100644 --- a/app/src/main/java/com/topjohnwu/magisk/rv/ModulesAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/rv/ModulesAdapter.java @@ -10,7 +10,8 @@ import android.widget.ImageView; import android.widget.TextView; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.model.Module; +import com.topjohnwu.magisk.module.Module; +import com.topjohnwu.magisk.utils.Utils; import java.util.List; @@ -92,6 +93,10 @@ public class ModulesAdapter extends RecyclerView.Adapter { - - @Override - protected Void doInBackground(Void... voids) { - // Check root access - rootAccess = isRoot(); - // Permission for java code to read /cache files - if (rootAccess) { - su("chmod 755 /cache", "chmod 644 /cache/magisk.log"); - } - return null; - } - } public static String sh(String... commands) { List result = Shell.SH.run(commands); @@ -48,30 +30,27 @@ public class Utils { return builder.toString(); } - public static boolean isRoot() { + public static void checkRoot() { String [] availableTestCommands = new String[] {"echo -BOC-", "id"}; List ret = Shell.run(Utils.suPath + "/su", availableTestCommands, null, false); if (ret == null) - return false; + return; // Taken from libsuperuser // this is only one of many ways this can be done - boolean echo_seen = false; for (String line : ret) { if (line.contains("uid=")) { // id command is working, let's see if we are actually root - return line.contains("uid=0"); + rootAccess = line.contains("uid=0"); } else if (line.contains("-BOC-")) { // if we end up here, at least the su command starts some kind // of shell, let's hope it has root privileges - no way to know without // additional native binaries - echo_seen = true; + rootAccess = true; } } - - return echo_seen; } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/root_fragment.xml similarity index 92% rename from app/src/main/res/layout/activity_main.xml rename to app/src/main/res/layout/root_fragment.xml index 5ef991c60..b9ef7dca2 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/root_fragment.xml @@ -3,8 +3,8 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:focusableInTouchMode="true" - tools:context=".ui.MainActivity"> + android:layout_marginTop="?attr/actionBarSize" + android:focusableInTouchMode="true"> -