Various fixes

This commit is contained in:
topjohnwu 2016-10-01 05:21:24 +08:00
parent d788bd8323
commit f2611f64ac
8 changed files with 62 additions and 62 deletions

View File

@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.topjohnwu.magisk"

View File

@ -9,10 +9,10 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.graphics.drawable.animated.BuildConfig;
import android.support.v4.content.FileProvider;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -23,9 +23,11 @@ import android.widget.TextView;
import com.topjohnwu.magisk.receivers.DownloadReceiver;
import com.topjohnwu.magisk.utils.Async;
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;
@ -107,7 +109,7 @@ public class MagiskFragment extends Fragment {
appCheckUpdatesProgress.setVisibility(View.VISIBLE);
magiskCheckUpdatesProgress.setVisibility(View.VISIBLE);
new Async.CheckUpdates(getActivity()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new Async.CheckUpdates(prefs).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
});
if (prefs.getBoolean("update_check_done", false)) {
@ -147,6 +149,13 @@ public class MagiskFragment extends Fragment {
builder = new AlertDialog.Builder(getActivity());
}
List<String> ret = Shell.sh("getprop magisk.version");
if (ret.get(0).isEmpty()) {
magiskVersion = -1;
} else {
magiskVersion = Integer.parseInt(ret.get(0));
}
if (remoteMagiskVersion == -1) {
appCheckUpdatesContainer.setBackgroundColor(colorWarn);
magiskCheckUpdatesContainer.setBackgroundColor(colorWarn);
@ -204,13 +213,7 @@ public class MagiskFragment extends Fragment {
.show());
}
int appVersionCode = 0;
try {
appVersionCode = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0).versionCode;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (remoteAppVersionCode > appVersionCode) {
if (remoteAppVersionCode > BuildConfig.VERSION_CODE) {
appCheckUpdatesContainer.setBackgroundColor(colorInfo);
appCheckUpdatesIcon.setImageResource(R.drawable.ic_file_download);
appCheckUpdatesStatus.setText(getString(R.string.app_update_available, remoteAppVersion));
@ -258,7 +261,13 @@ public class MagiskFragment extends Fragment {
new DownloadReceiver() {
@Override
public void task(Uri uri) {
new Async.FlashZIP(mContext, uri).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
new Async.FlashZIP(mContext, uri) {
@Override
protected void done() {
Shell.su("setprop magisk.version " + String.valueOf(remoteMagiskVersion));
super.done();
}
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
},
magiskLink,

View File

@ -59,7 +59,7 @@ public class ModulesFragment extends Fragment {
mSwipeRefreshLayout.setOnRefreshListener(() -> {
recyclerView.setVisibility(View.GONE);
prefs.edit().putBoolean("module_done", false).apply();
new Async.LoadModules(getActivity()).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
new Async.LoadModules(prefs).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
});
if (prefs.getBoolean("module_done", false)) {

View File

@ -2,7 +2,6 @@ package com.topjohnwu.magisk;
import android.app.Fragment;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;

View File

@ -12,7 +12,6 @@ import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.WindowManager;
import android.widget.Toast;
import com.topjohnwu.magisk.utils.Async;
import com.topjohnwu.magisk.utils.Logger;

View File

@ -1,5 +1,6 @@
package com.topjohnwu.magisk;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
@ -12,38 +13,41 @@ import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.utils.Utils;
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences defaultPrefs = PreferenceManager.getDefaultSharedPreferences(getApplication());
if (defaultPrefs.getString("theme","").equals("Dark")) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplication());
if (prefs.getString("theme","").equals("Dark")) {
setTheme(R.style.AppTheme_dh);
}
Logger.devLog = defaultPrefs.getBoolean("developer_logging", false);
Logger.logShell = defaultPrefs.getBoolean("shell_logging", false);
Logger.devLog = prefs.getBoolean("developer_logging", false);
Logger.logShell = prefs.getBoolean("shell_logging", false);
// Initialize
Utils.init(this);
defaultPrefs.edit()
prefs.edit()
.putBoolean("module_done", false)
.putBoolean("repo_done", false)
.putBoolean("update_check_done", false)
.putBoolean("root", Utils.rootEnabled())
.apply();
new Async.CheckUpdates(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new Async.constructEnv(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new Async.CheckUpdates(prefs).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new Async.constructEnv(getApplicationInfo()).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
new Async.LoadModules(this).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
new Async.LoadRepos(this).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
new Async.LoadModules(prefs) {
@Override
protected void onPostExecute(Void v) {
super.onPostExecute(v);
new Async.LoadRepos(getApplicationContext()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
// Start main activity
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
}
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
// Start main activity
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}

View File

@ -3,6 +3,7 @@ package com.topjohnwu.magisk.utils;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
@ -34,20 +35,20 @@ public class Async {
public static class constructEnv extends AsyncTask<Void, Void, Void> {
Context mContext;
ApplicationInfo mInfo;
public constructEnv(Context context) {
mContext = context;
public constructEnv(ApplicationInfo info) {
mInfo = info;
}
@Override
protected Void doInBackground(Void... voids) {
String toolPath = mContext.getApplicationInfo().dataDir + "/tools";
String busybox = mContext.getApplicationInfo().dataDir + "/lib/libbusybox.so";
String zip = mContext.getApplicationInfo().dataDir + "/lib/libzip.so";
String toolPath = mInfo.dataDir + "/tools";
String busybox = mInfo.dataDir + "/lib/libbusybox.so";
String zip = mInfo.dataDir + "/lib/libzip.so";
if (Shell.rootAccess()) {
if (!Utils.itemExist(false, toolPath)) {
Shell.sh(
Shell.su(
"rm -rf " + toolPath,
"mkdir " + toolPath,
"chmod 755 " + toolPath,
@ -60,6 +61,7 @@ public class Async {
"ln -s " + zip + " zip"
);
}
Shell.su("PATH=" + toolPath + ":$PATH");
}
return null;
@ -68,10 +70,10 @@ public class Async {
public static class CheckUpdates extends AsyncTask<Void, Void, Void> {
private Context mContext;
private SharedPreferences mPrefs;
public CheckUpdates(Context context) {
mContext = context;
public CheckUpdates(SharedPreferences prefs) {
mPrefs = prefs;
}
@Override
@ -100,17 +102,16 @@ public class Async {
@Override
protected void onPostExecute(Void v) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
prefs.edit().putBoolean("update_check_done", true).apply();
mPrefs.edit().putBoolean("update_check_done", true).apply();
}
}
public static class LoadModules extends AsyncTask<Void, Void, Void> {
private Context mContext;
private SharedPreferences mPrefs;
public LoadModules(Context context) {
mContext = context;
public LoadModules(SharedPreferences prefs) {
mPrefs = prefs;
}
@Override
@ -121,8 +122,7 @@ public class Async {
@Override
protected void onPostExecute(Void v) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
prefs.edit().putBoolean("module_done", true).apply();
mPrefs.edit().putBoolean("module_done", true).apply();
}
}
@ -142,8 +142,8 @@ public class Async {
@Override
protected void onPostExecute(Void v) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
prefs.edit().putBoolean("repo_done", true).apply();
PreferenceManager.getDefaultSharedPreferences(mContext).edit()
.putBoolean("repo_done", true).apply();
}
}
@ -308,8 +308,8 @@ public class Async {
protected void done() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
prefs.edit().putBoolean("module_done", false).apply();
new LoadModules(mContext).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
prefs.edit().putBoolean("module_done", false).putBoolean("update_check_done", true).apply();
new LoadModules(prefs).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
AlertDialog.Builder builder;
String theme = PreferenceManager.getDefaultSharedPreferences(mContext).getString("theme", "");

View File

@ -39,17 +39,6 @@ public class Utils {
private static final String cryptoPass = "MagiskRox666";
private static final String secret = "GTYybRBTYf5his9kQ16ZNO7qgkBJ/5MyVe4CGceAOIoXgSnnk8FTd4F1dE9p5Eus";
public static void init(Context context) {
List<String> ret = Shell.sh("getprop magisk.version");
if (ret.get(0).isEmpty()) {
MagiskFragment.magiskVersion = -1;
} else {
MagiskFragment.magiskVersion = Integer.parseInt(ret.get(0));
}
String toolPath = context.getApplicationInfo().dataDir + "/tools";
Shell.su("PATH=" + toolPath + ":$PATH");
}
public static boolean itemExist(String path) {
return itemExist(true, path);
}