Remove unnecessary root calls

This commit is contained in:
topjohnwu 2016-08-23 03:50:46 +08:00
parent 7eadc74f6c
commit 36c575023e
5 changed files with 44 additions and 13 deletions

View File

@ -12,13 +12,13 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity android:name=".ui.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<!--<activity android:name=".ui.MainActivity">-->
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.MAIN"/>-->
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!--<category android:name="android.intent.category.LAUNCHER"/>-->
<!--</intent-filter>-->
<!--</activity>-->
<activity
android:name=".WelcomeActivity"
android:configChanges="orientation|screenSize">

View File

@ -19,6 +19,7 @@ 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 butterknife.BindView;
import butterknife.ButterKnife;
@ -44,6 +45,9 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
Utils.initialize.execute();
setSupportActionBar(toolbar);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {

View File

@ -35,6 +35,7 @@ import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.Calendar;
import java.util.concurrent.ExecutionException;
import butterknife.BindView;
import butterknife.ButterKnife;
@ -226,13 +227,18 @@ public class LogFragment extends Fragment {
@Override
protected void onPreExecute() {
Utils.su("chmod 755 /cache");
Utils.su("chmod 644 /cache/magisk.log");
txtLog.setText("");
}
@Override
protected String doInBackground(File... log) {
// Ensure initialize is done
try {
Utils.initialize.get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
Thread.currentThread().setPriority(Thread.NORM_PRIORITY + 2);
StringBuilder llog = new StringBuilder(15 * 10 * 1024);

View File

@ -21,6 +21,7 @@ import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import butterknife.BindView;
import butterknife.ButterKnife;
@ -81,6 +82,13 @@ public class ModulesFragment extends Fragment {
@Override
protected Boolean doInBackground(Void... voids) {
// Ensure initialize is done
try {
Utils.initialize.get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
File[] magisk = new File(MAGISK_PATH).listFiles(new FileFilter() {
@Override
public boolean accept(File file) {
@ -88,8 +96,6 @@ public class ModulesFragment extends Fragment {
}
});
Utils.su("chmod 755 /cache");
File[] magiskCache = new File(MAGISK_CACHE_PATH).listFiles(new FileFilter() {
@Override
public boolean accept(File file) {

View File

@ -1,5 +1,7 @@
package com.topjohnwu.magisk.ui.utils;
import android.os.AsyncTask;
import java.util.List;
import eu.chainfire.libsuperuser.Shell;
@ -7,7 +9,22 @@ import eu.chainfire.libsuperuser.Shell;
public class Utils {
public static final String suPath = sh("getprop magisk.supath");
public static final boolean rootAccess = isRoot();
public static boolean rootAccess = false;
public static Init initialize = new Init();
public static class Init extends AsyncTask<Void, Integer, Void> {
@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<String> result = Shell.SH.run(commands);
@ -28,8 +45,6 @@ public class Utils {
builder.append(s);
}
Shell.SU.available();
return builder.toString();
}