Magisk Update checker use prefs listener
This commit is contained in:
parent
cb5187fd8d
commit
0acc5e33b3
@ -2,6 +2,7 @@ package com.topjohnwu.magisk;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
@ -11,6 +12,7 @@ import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import android.support.v4.content.FileProvider;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -21,6 +23,7 @@ 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.Utils;
|
||||
|
||||
import java.io.File;
|
||||
@ -30,6 +33,8 @@ import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class MagiskFragment extends Fragment {
|
||||
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
||||
|
||||
@BindView(R.id.magiskStatusView) View magiskStatusView;
|
||||
@BindView(R.id.magisk_status_container) View magiskStatusContainer;
|
||||
@BindView(R.id.magisk_status_icon) ImageView magiskStatusIcon;
|
||||
@ -54,6 +59,9 @@ public class MagiskFragment extends Fragment {
|
||||
int statusUnknown = R.drawable.ic_help;
|
||||
private AlertDialog.Builder builder;
|
||||
|
||||
private SharedPreferences prefs;
|
||||
private SharedPreferences.OnSharedPreferenceChangeListener listener;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
@ -86,7 +94,25 @@ public class MagiskFragment extends Fragment {
|
||||
magiskVersion.setTextColor(colorOK);
|
||||
}
|
||||
|
||||
new updateUI().executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
|
||||
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
||||
prefs.edit().putBoolean("update_check_done", false).apply();
|
||||
new Async.CheckUpdates(getActivity()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
});
|
||||
|
||||
if (prefs.getBoolean("update_check_done", false)) {
|
||||
updateUI();
|
||||
}
|
||||
|
||||
listener = (pref, s) -> {
|
||||
if (s.equals("update_check_done")) {
|
||||
if (pref.getBoolean(s, false)) {
|
||||
Logger.dev("MagiskFragment: UI refresh triggered");
|
||||
updateUI();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return v;
|
||||
}
|
||||
@ -94,102 +120,215 @@ public class MagiskFragment extends Fragment {
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
getActivity().setTitle("Magisk");
|
||||
getActivity().setTitle(R.string.magisk);
|
||||
prefs.registerOnSharedPreferenceChangeListener(listener);
|
||||
}
|
||||
|
||||
private class updateUI extends AsyncTask<Void, Void, Void> {
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
prefs.unregisterOnSharedPreferenceChangeListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
return null;
|
||||
|
||||
private void updateUI() {
|
||||
String theme = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("theme", "");
|
||||
if (theme.equals("Dark")) {
|
||||
builder = new AlertDialog.Builder(getActivity(),R.style.AlertDialog_dh);
|
||||
} else {
|
||||
builder = new AlertDialog.Builder(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void v) {
|
||||
super.onPostExecute(v);
|
||||
String theme = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("theme", "");
|
||||
if (theme.equals("Dark")) {
|
||||
builder = new AlertDialog.Builder(getActivity(),R.style.AlertDialog_dh);
|
||||
if (Utils.remoteMagiskVersion == -1) {
|
||||
appCheckUpdatesContainer.setBackgroundColor(colorWarn);
|
||||
magiskCheckUpdatesContainer.setBackgroundColor(colorWarn);
|
||||
|
||||
appCheckUpdatesIcon.setImageResource(R.drawable.ic_warning);
|
||||
magiskCheckUpdatesIcon.setImageResource(R.drawable.ic_warning);
|
||||
|
||||
appCheckUpdatesStatus.setText(R.string.cannot_check_updates);
|
||||
appCheckUpdatesStatus.setTextColor(colorWarn);
|
||||
magiskCheckUpdatesStatus.setText(R.string.cannot_check_updates);
|
||||
magiskCheckUpdatesStatus.setTextColor(colorWarn);
|
||||
} else {
|
||||
if (Utils.remoteMagiskVersion > Utils.magiskVersion) {
|
||||
magiskCheckUpdatesContainer.setBackgroundColor(colorNeutral);
|
||||
magiskCheckUpdatesIcon.setImageResource(R.drawable.ic_file_download);
|
||||
magiskCheckUpdatesStatus.setText(getString(R.string.magisk_update_available, String.valueOf(Utils.remoteMagiskVersion)));
|
||||
magiskCheckUpdatesStatus.setTextColor(colorNeutral);
|
||||
magiskUpdateView.setOnClickListener(view -> builder
|
||||
.setTitle(getString(R.string.update_title, getString(R.string.magisk)))
|
||||
.setMessage(getString(R.string.update_msg, getString(R.string.magisk), String.valueOf(Utils.remoteMagiskVersion), Utils.magiskChangelog))
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(R.string.download_install, (dialogInterface, i) -> Utils.downloadAndReceive(
|
||||
getActivity(),
|
||||
new DownloadReceiver() {
|
||||
@Override
|
||||
public void task(Uri uri) {
|
||||
new Async.FlashZIP(mContext, uri).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||
}
|
||||
},
|
||||
Utils.magiskLink,
|
||||
"Magisk-v" + String.valueOf(Utils.remoteMagiskVersion) + ".zip"))
|
||||
.setNegativeButton(R.string.no_thanks, null)
|
||||
.show());
|
||||
} else {
|
||||
builder = new AlertDialog.Builder(getActivity());
|
||||
magiskCheckUpdatesContainer.setBackgroundColor(colorOK);
|
||||
magiskCheckUpdatesIcon.setImageResource(R.drawable.ic_check_circle);
|
||||
magiskCheckUpdatesStatus.setText(getString(R.string.up_to_date, getString(R.string.magisk)));
|
||||
magiskCheckUpdatesStatus.setTextColor(colorOK);
|
||||
}
|
||||
|
||||
if (Utils.remoteMagiskVersion == -1) {
|
||||
appCheckUpdatesContainer.setBackgroundColor(colorWarn);
|
||||
magiskCheckUpdatesContainer.setBackgroundColor(colorWarn);
|
||||
|
||||
appCheckUpdatesIcon.setImageResource(R.drawable.ic_warning);
|
||||
magiskCheckUpdatesIcon.setImageResource(R.drawable.ic_warning);
|
||||
|
||||
appCheckUpdatesStatus.setText(R.string.cannot_check_updates);
|
||||
appCheckUpdatesStatus.setTextColor(colorWarn);
|
||||
magiskCheckUpdatesStatus.setText(R.string.cannot_check_updates);
|
||||
magiskCheckUpdatesStatus.setTextColor(colorWarn);
|
||||
if (Utils.remoteAppVersionCode > BuildConfig.VERSION_CODE) {
|
||||
appCheckUpdatesContainer.setBackgroundColor(colorNeutral);
|
||||
appCheckUpdatesIcon.setImageResource(R.drawable.ic_file_download);
|
||||
appCheckUpdatesStatus.setText(getString(R.string.app_update_available, Utils.remoteAppVersion));
|
||||
appCheckUpdatesStatus.setTextColor(colorNeutral);
|
||||
appUpdateView.setOnClickListener(view -> builder
|
||||
.setTitle(getString(R.string.update_title, getString(R.string.app_name)))
|
||||
.setMessage(getString(R.string.update_msg, getString(R.string.app_name), Utils.remoteAppVersion, Utils.appChangelog))
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(R.string.download_install, (dialogInterface, i) -> Utils.downloadAndReceive(getActivity(),
|
||||
new DownloadReceiver() {
|
||||
@Override
|
||||
public void task(Uri uri) {
|
||||
Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE);
|
||||
install.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
Uri content = FileProvider.getUriForFile(getActivity(), "com.topjohnwu.magisk.provider", new File(uri.getPath()));
|
||||
install.setData(content);
|
||||
mContext.startActivity(install);
|
||||
}
|
||||
},
|
||||
Utils.appLink,
|
||||
"MagiskManager-v" + Utils.remoteAppVersion + ".apk"))
|
||||
.setNegativeButton(R.string.no_thanks, null)
|
||||
.show()
|
||||
);
|
||||
} else {
|
||||
if (Utils.remoteMagiskVersion > Utils.magiskVersion) {
|
||||
magiskCheckUpdatesContainer.setBackgroundColor(colorNeutral);
|
||||
magiskCheckUpdatesIcon.setImageResource(R.drawable.ic_file_download);
|
||||
magiskCheckUpdatesStatus.setText(getString(R.string.magisk_update_available, String.valueOf(Utils.remoteMagiskVersion)));
|
||||
magiskCheckUpdatesStatus.setTextColor(colorNeutral);
|
||||
magiskUpdateView.setOnClickListener(view -> builder
|
||||
.setTitle(getString(R.string.update_title, getString(R.string.magisk)))
|
||||
.setMessage(getString(R.string.update_msg, getString(R.string.magisk), String.valueOf(Utils.remoteMagiskVersion), Utils.magiskChangelog))
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(R.string.download_install, (dialogInterface, i) -> Utils.downloadAndReceive(
|
||||
getActivity(),
|
||||
new DownloadReceiver() {
|
||||
@Override
|
||||
public void task(Uri uri) {
|
||||
new Async.FlashZIP(mContext, uri).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||
}
|
||||
},
|
||||
Utils.magiskLink,
|
||||
"Magisk-v" + String.valueOf(Utils.remoteMagiskVersion) + ".zip"))
|
||||
.setNegativeButton(R.string.no_thanks, null)
|
||||
.show());
|
||||
} else {
|
||||
magiskCheckUpdatesContainer.setBackgroundColor(colorOK);
|
||||
magiskCheckUpdatesIcon.setImageResource(R.drawable.ic_check_circle);
|
||||
magiskCheckUpdatesStatus.setText(getString(R.string.up_to_date, getString(R.string.magisk)));
|
||||
magiskCheckUpdatesStatus.setTextColor(colorOK);
|
||||
}
|
||||
appCheckUpdatesContainer.setBackgroundColor(colorOK);
|
||||
appCheckUpdatesIcon.setImageResource(R.drawable.ic_check_circle);
|
||||
appCheckUpdatesStatus.setText(getString(R.string.up_to_date, getString(R.string.app_name)));
|
||||
appCheckUpdatesStatus.setTextColor(colorOK);
|
||||
|
||||
if (Utils.remoteAppVersionCode > BuildConfig.VERSION_CODE) {
|
||||
appCheckUpdatesContainer.setBackgroundColor(colorNeutral);
|
||||
appCheckUpdatesIcon.setImageResource(R.drawable.ic_file_download);
|
||||
appCheckUpdatesStatus.setText(getString(R.string.app_update_available, Utils.remoteAppVersion));
|
||||
appCheckUpdatesStatus.setTextColor(colorNeutral);
|
||||
appUpdateView.setOnClickListener(view -> builder
|
||||
.setTitle(getString(R.string.update_title, getString(R.string.app_name)))
|
||||
.setMessage(getString(R.string.update_msg, getString(R.string.app_name), Utils.remoteAppVersion, Utils.appChangelog))
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(R.string.download_install, (dialogInterface, i) -> Utils.downloadAndReceive(getActivity(),
|
||||
new DownloadReceiver() {
|
||||
@Override
|
||||
public void task(Uri uri) {
|
||||
Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE);
|
||||
install.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
Uri content = FileProvider.getUriForFile(getActivity(), "com.topjohnwu.magisk.provider", new File(uri.getPath()));
|
||||
install.setData(content);
|
||||
mContext.startActivity(install);
|
||||
}
|
||||
},
|
||||
Utils.appLink,
|
||||
"MagiskManager-v" + Utils.remoteAppVersion + ".apk"))
|
||||
.setNegativeButton(R.string.no_thanks, null)
|
||||
.show()
|
||||
);
|
||||
} else {
|
||||
appCheckUpdatesContainer.setBackgroundColor(colorOK);
|
||||
appCheckUpdatesIcon.setImageResource(R.drawable.ic_check_circle);
|
||||
appCheckUpdatesStatus.setText(getString(R.string.up_to_date, getString(R.string.app_name)));
|
||||
appCheckUpdatesStatus.setTextColor(colorOK);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
appCheckUpdatesProgress.setVisibility(View.GONE);
|
||||
magiskCheckUpdatesProgress.setVisibility(View.GONE);
|
||||
appCheckUpdatesProgress.setVisibility(View.GONE);
|
||||
magiskCheckUpdatesProgress.setVisibility(View.GONE);
|
||||
|
||||
if (Utils.magiskVersion == -1) {
|
||||
builder
|
||||
.setTitle(R.string.no_magisk_title)
|
||||
.setMessage(R.string.no_magisk_msg)
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(R.string.download_install, (dialogInterface, i) -> Utils.downloadAndReceive(
|
||||
getActivity(),
|
||||
new DownloadReceiver() {
|
||||
@Override
|
||||
public void task(Uri uri) {
|
||||
new Async.FlashZIP(mContext, uri).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||
}
|
||||
},
|
||||
Utils.magiskLink,
|
||||
"Magisk-v" + String.valueOf(Utils.remoteMagiskVersion) + ".zip"))
|
||||
.setNegativeButton(R.string.no_thanks, null)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
// private class updateUI extends AsyncTask<Void, Void, Void> {
|
||||
//
|
||||
// @Override
|
||||
// protected Void doInBackground(Void... voids) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onPostExecute(Void v) {
|
||||
// super.onPostExecute(v);
|
||||
// String theme = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("theme", "");
|
||||
// if (theme.equals("Dark")) {
|
||||
// builder = new AlertDialog.Builder(getActivity(),R.style.AlertDialog_dh);
|
||||
// } else {
|
||||
// builder = new AlertDialog.Builder(getActivity());
|
||||
// }
|
||||
//
|
||||
// if (Utils.remoteMagiskVersion == -1) {
|
||||
// appCheckUpdatesContainer.setBackgroundColor(colorWarn);
|
||||
// magiskCheckUpdatesContainer.setBackgroundColor(colorWarn);
|
||||
//
|
||||
// appCheckUpdatesIcon.setImageResource(R.drawable.ic_warning);
|
||||
// magiskCheckUpdatesIcon.setImageResource(R.drawable.ic_warning);
|
||||
//
|
||||
// appCheckUpdatesStatus.setText(R.string.cannot_check_updates);
|
||||
// appCheckUpdatesStatus.setTextColor(colorWarn);
|
||||
// magiskCheckUpdatesStatus.setText(R.string.cannot_check_updates);
|
||||
// magiskCheckUpdatesStatus.setTextColor(colorWarn);
|
||||
// } else {
|
||||
// if (Utils.remoteMagiskVersion > Utils.magiskVersion) {
|
||||
// magiskCheckUpdatesContainer.setBackgroundColor(colorNeutral);
|
||||
// magiskCheckUpdatesIcon.setImageResource(R.drawable.ic_file_download);
|
||||
// magiskCheckUpdatesStatus.setText(getString(R.string.magisk_update_available, String.valueOf(Utils.remoteMagiskVersion)));
|
||||
// magiskCheckUpdatesStatus.setTextColor(colorNeutral);
|
||||
// magiskUpdateView.setOnClickListener(view -> builder
|
||||
// .setTitle(getString(R.string.update_title, getString(R.string.magisk)))
|
||||
// .setMessage(getString(R.string.update_msg, getString(R.string.magisk), String.valueOf(Utils.remoteMagiskVersion), Utils.magiskChangelog))
|
||||
// .setCancelable(true)
|
||||
// .setPositiveButton(R.string.download_install, (dialogInterface, i) -> Utils.downloadAndReceive(
|
||||
// getActivity(),
|
||||
// new DownloadReceiver() {
|
||||
// @Override
|
||||
// public void task(Uri uri) {
|
||||
// new Async.FlashZIP(mContext, uri).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||
// }
|
||||
// },
|
||||
// Utils.magiskLink,
|
||||
// "Magisk-v" + String.valueOf(Utils.remoteMagiskVersion) + ".zip"))
|
||||
// .setNegativeButton(R.string.no_thanks, null)
|
||||
// .show());
|
||||
// } else {
|
||||
// magiskCheckUpdatesContainer.setBackgroundColor(colorOK);
|
||||
// magiskCheckUpdatesIcon.setImageResource(R.drawable.ic_check_circle);
|
||||
// magiskCheckUpdatesStatus.setText(getString(R.string.up_to_date, getString(R.string.magisk)));
|
||||
// magiskCheckUpdatesStatus.setTextColor(colorOK);
|
||||
// }
|
||||
//
|
||||
// if (Utils.remoteAppVersionCode > BuildConfig.VERSION_CODE) {
|
||||
// appCheckUpdatesContainer.setBackgroundColor(colorNeutral);
|
||||
// appCheckUpdatesIcon.setImageResource(R.drawable.ic_file_download);
|
||||
// appCheckUpdatesStatus.setText(getString(R.string.app_update_available, Utils.remoteAppVersion));
|
||||
// appCheckUpdatesStatus.setTextColor(colorNeutral);
|
||||
// appUpdateView.setOnClickListener(view -> builder
|
||||
// .setTitle(getString(R.string.update_title, getString(R.string.app_name)))
|
||||
// .setMessage(getString(R.string.update_msg, getString(R.string.app_name), Utils.remoteAppVersion, Utils.appChangelog))
|
||||
// .setCancelable(true)
|
||||
// .setPositiveButton(R.string.download_install, (dialogInterface, i) -> Utils.downloadAndReceive(getActivity(),
|
||||
// new DownloadReceiver() {
|
||||
// @Override
|
||||
// public void task(Uri uri) {
|
||||
// Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE);
|
||||
// install.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
// Uri content = FileProvider.getUriForFile(getActivity(), "com.topjohnwu.magisk.provider", new File(uri.getPath()));
|
||||
// install.setData(content);
|
||||
// mContext.startActivity(install);
|
||||
// }
|
||||
// },
|
||||
// Utils.appLink,
|
||||
// "MagiskManager-v" + Utils.remoteAppVersion + ".apk"))
|
||||
// .setNegativeButton(R.string.no_thanks, null)
|
||||
// .show()
|
||||
// );
|
||||
// } else {
|
||||
// appCheckUpdatesContainer.setBackgroundColor(colorOK);
|
||||
// appCheckUpdatesIcon.setImageResource(R.drawable.ic_check_circle);
|
||||
// appCheckUpdatesStatus.setText(getString(R.string.up_to_date, getString(R.string.app_name)));
|
||||
// appCheckUpdatesStatus.setTextColor(colorOK);
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// appCheckUpdatesProgress.setVisibility(View.GONE);
|
||||
// magiskCheckUpdatesProgress.setVisibility(View.GONE);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
@ -68,12 +68,15 @@ public class SplashActivity extends AppCompatActivity {
|
||||
defaultPrefs.edit()
|
||||
.putBoolean("module_done", false)
|
||||
.putBoolean("repo_done", false)
|
||||
.putBoolean("update_check_done", false)
|
||||
.apply();
|
||||
new Async.CheckUpdates(this).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||
new Async.LoadModules(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new Async.LoadRepos(this).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||
|
||||
new Async.CheckUpdates(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new Async.constructEnv(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
new Async.LoadModules(this).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||
new Async.LoadRepos(this).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||
|
||||
// Start main activity
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
startActivity(intent);
|
||||
|
@ -8,7 +8,7 @@ import java.util.List;
|
||||
public abstract class BaseModule {
|
||||
|
||||
protected String mId, mName, mVersion, mAuthor, mDescription, mSupportUrl, mDonateUrl;
|
||||
protected boolean mIsCacheModule = false;
|
||||
protected boolean mIsCacheModule = false, mCanUpdate = false;
|
||||
protected int mVersionCode = 0;
|
||||
|
||||
protected void parseProps(List<String> props) { parseProps(props.toArray(new String[props.size()])); }
|
||||
@ -97,4 +97,12 @@ public abstract class BaseModule {
|
||||
public String getSupportUrl() {
|
||||
return mSupportUrl;
|
||||
}
|
||||
|
||||
public void setUpdate() {
|
||||
mCanUpdate = true;
|
||||
}
|
||||
|
||||
public boolean canUpdate() {
|
||||
return mCanUpdate;
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ public class Module extends BaseModule {
|
||||
|
||||
private String mRemoveFile;
|
||||
private String mDisableFile;
|
||||
private boolean mEnable, mRemove, mUpdateAvailable = false;
|
||||
private boolean mEnable, mRemove;
|
||||
|
||||
public Module(String path) {
|
||||
|
||||
@ -38,7 +38,7 @@ public class Module extends BaseModule {
|
||||
repo.setInstalled();
|
||||
if (repo.getVersionCode() > mVersionCode) {
|
||||
repo.setUpdate();
|
||||
mUpdateAvailable = true;
|
||||
mCanUpdate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -67,6 +67,4 @@ public class Module extends BaseModule {
|
||||
return mRemove;
|
||||
}
|
||||
|
||||
public boolean isUpdateAvailable() { return mUpdateAvailable; }
|
||||
|
||||
}
|
@ -18,7 +18,7 @@ import java.util.Date;
|
||||
public class Repo extends BaseModule {
|
||||
protected String repoName, mLogUrl, mManifestUrl, mZipUrl;
|
||||
protected Date mLastUpdate;
|
||||
protected boolean mIsInstalled = false, mCanUpdate = false;
|
||||
protected boolean mIsInstalled = false;
|
||||
|
||||
public Repo(Context context, String name, Date lastUpdate) {
|
||||
repoName = name;
|
||||
@ -42,10 +42,6 @@ public class Repo extends BaseModule {
|
||||
}
|
||||
}
|
||||
|
||||
public void setUpdate() {
|
||||
mCanUpdate = true;
|
||||
}
|
||||
|
||||
public void setInstalled() {
|
||||
mIsInstalled = true;
|
||||
}
|
||||
@ -67,6 +63,4 @@ public class Repo extends BaseModule {
|
||||
}
|
||||
|
||||
public boolean isInstalled() { return mIsInstalled; }
|
||||
public boolean canUpdate() { return mCanUpdate; }
|
||||
public boolean isCacheModule() { return mIsCacheModule; }
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public class Async {
|
||||
"for tool in $(" + toolPath + "/busybox --list); do",
|
||||
"ln -s " + busybox + " " + toolPath + "/$tool",
|
||||
"done",
|
||||
!Utils.commandExists("zip") ? "ln -s " + zip + " " + toolPath + "/zip" : ""
|
||||
"ln -s " + zip + " " + toolPath + "/zip"
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -101,24 +101,8 @@ public class Async {
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void v) {
|
||||
if (Shell.rootAccess() && Utils.magiskVersion == -1) {
|
||||
new AlertDialog.Builder(mContext)
|
||||
.setTitle(R.string.no_magisk_title)
|
||||
.setMessage(R.string.no_magisk_msg)
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(R.string.download_install, (dialogInterface, i) -> Utils.downloadAndReceive(
|
||||
mContext,
|
||||
new DownloadReceiver() {
|
||||
@Override
|
||||
public void task(Uri uri) {
|
||||
new Async.FlashZIP(mContext, uri).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||
}
|
||||
},
|
||||
Utils.magiskLink,
|
||||
"Magisk-v" + String.valueOf(Utils.remoteMagiskVersion) + ".zip"))
|
||||
.setNegativeButton(R.string.no_thanks, null)
|
||||
.show();
|
||||
}
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||
prefs.edit().putBoolean("update_check_done", true).apply();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,6 @@ import com.topjohnwu.magisk.ModulesFragment;
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.module.Module;
|
||||
import com.topjohnwu.magisk.module.Repo;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
import com.topjohnwu.magisk.utils.WebRequest;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@ -46,9 +44,7 @@ public class RepoHelper {
|
||||
}
|
||||
|
||||
// Making a request to url and getting response
|
||||
String token = context.getString(R.string.some_string);
|
||||
String url1 = context.getString(R.string.url_main);
|
||||
String jsonStr = WebRequest.makeWebServiceCall(url1 + Utils.procFile(token, context), WebRequest.GET);
|
||||
String jsonStr = WebRequest.makeWebServiceCall(context.getString(R.string.url_main) + Utils.getToken(), WebRequest.GET);
|
||||
if (jsonStr != null && !jsonStr.isEmpty()) {
|
||||
try {
|
||||
JSONArray jsonArray = new JSONArray(jsonStr);
|
||||
|
@ -164,9 +164,9 @@ public class Shell {
|
||||
STDOUT.join();
|
||||
process.destroy();
|
||||
} else {
|
||||
STDIN.write(("echo \' \'\n").getBytes("UTF-8"));
|
||||
STDIN.write(("echo\n").getBytes("UTF-8"));
|
||||
STDIN.flush();
|
||||
STDIN.write(("echo \'-done-\'\n").getBytes("UTF-8"));
|
||||
STDIN.write(("echo \'-root-done-\'\n").getBytes("UTF-8"));
|
||||
STDIN.flush();
|
||||
while (true) {
|
||||
try {
|
||||
@ -177,9 +177,11 @@ public class Shell {
|
||||
// Process still running, gobble output until done
|
||||
int end = res.size() - 1;
|
||||
if (end > 0) {
|
||||
if (res.get(end).equals("-done-")) {
|
||||
if (res.get(end).equals("-root-done-")) {
|
||||
res.remove(end);
|
||||
res.remove(end - 1);
|
||||
if (res.get(end -1).isEmpty()) {
|
||||
res.remove(end -1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -57,9 +57,12 @@ public class Utils {
|
||||
public static final String MAGISK_CACHE_PATH = "/cache/magisk";
|
||||
public static final String UPDATE_JSON = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/updates/magisk_update.json";
|
||||
|
||||
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).replaceAll("\\s", "").isEmpty()) {
|
||||
if (ret.get(0).isEmpty()) {
|
||||
magiskVersion = -1;
|
||||
} else {
|
||||
magiskVersion = Integer.parseInt(ret.get(0));
|
||||
@ -187,15 +190,14 @@ public class Utils {
|
||||
context.registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
|
||||
}
|
||||
|
||||
public static String procFile(String value, Context context) {
|
||||
public static String getToken() {
|
||||
|
||||
String cryptoPass = context.getResources().getString(R.string.pass);
|
||||
try {
|
||||
DESKeySpec keySpec = new DESKeySpec(cryptoPass.getBytes("UTF8"));
|
||||
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
|
||||
SecretKey key = keyFactory.generateSecret(keySpec);
|
||||
|
||||
byte[] encrypedPwdBytes = Base64.decode(value, Base64.DEFAULT);
|
||||
byte[] encrypedPwdBytes = Base64.decode(secret, Base64.DEFAULT);
|
||||
// cipher is not thread safe
|
||||
Cipher cipher = Cipher.getInstance("DES");
|
||||
cipher.init(Cipher.DECRYPT_MODE, key);
|
||||
@ -208,7 +210,7 @@ public class Utils {
|
||||
| InvalidKeySpecException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return value;
|
||||
return secret;
|
||||
}
|
||||
|
||||
public static void SetupQuickSettingsTile(Context mContext) {
|
||||
|
@ -1,166 +1,177 @@
|
||||
<?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.support.v4.widget.SwipeRefreshLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/swipeRefreshLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_marginTop="?attr/actionBarSize"
|
||||
android:orientation="vertical">
|
||||
|
||||
<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"
|
||||
xmlns:card_view="http://schemas.android.com/tools"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginTop="?attr/actionBarSize"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:card_view="http://schemas.android.com/tools"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginTop="?attr/actionBarSize"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:id="@+id/magiskStatusView"
|
||||
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"
|
||||
style="?attr/cardStyle"
|
||||
app:cardUseCompatPadding="true">
|
||||
|
||||
<LinearLayout
|
||||
<android.support.v7.widget.CardView
|
||||
android:id="@+id/magiskStatusView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
android:layout_marginBottom="4dp"
|
||||
android:layout_marginLeft="5dip"
|
||||
android:layout_marginRight="5dip"
|
||||
android:layout_marginTop="6dp"
|
||||
style="?attr/cardStyle"
|
||||
app:cardUseCompatPadding="true">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/magisk_status_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:foregroundGravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/magisk_status_icon"
|
||||
android:layout_width="84dp"
|
||||
android:layout_height="84dp"
|
||||
android:layout_gravity="center"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/magisk_version"
|
||||
<LinearLayout
|
||||
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/magisk_updateView"
|
||||
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"
|
||||
style="?attr/cardStyle"
|
||||
app:cardUseCompatPadding="true">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/magisk_check_updates_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:foregroundGravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/magisk_check_updates_icon"
|
||||
android:layout_width="84dp"
|
||||
android:layout_height="84dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/ic_check_circle"/>
|
||||
<FrameLayout
|
||||
android:id="@+id/magisk_status_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:foregroundGravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/magisk_check_updates_progress"
|
||||
android:layout_width="wrap_content"
|
||||
<ImageView
|
||||
android:id="@+id/magisk_status_icon"
|
||||
android:layout_width="84dp"
|
||||
android:layout_height="84dp"
|
||||
android:layout_gravity="center"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/magisk_version"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"/>
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:padding="6dp"
|
||||
android:textStyle="bold"/>
|
||||
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/magisk_check_updates_status"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:padding="6dp"
|
||||
android:textStyle="bold"/>
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:id="@+id/app_updateView"
|
||||
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"
|
||||
style="?attr/cardStyle"
|
||||
app:cardUseCompatPadding="true">
|
||||
|
||||
<LinearLayout
|
||||
<android.support.v7.widget.CardView
|
||||
android:id="@+id/magisk_updateView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
android:layout_marginBottom="4dp"
|
||||
android:layout_marginLeft="5dip"
|
||||
android:layout_marginRight="5dip"
|
||||
android:layout_marginTop="6dp"
|
||||
style="?attr/cardStyle"
|
||||
app:cardUseCompatPadding="true">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/app_check_updates_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:foregroundGravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/app_check_updates_icon"
|
||||
android:layout_width="84dp"
|
||||
android:layout_height="84dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/ic_check_circle"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/app_check_updates_progress"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/app_check_updates_status"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:padding="6dp"
|
||||
android:textStyle="bold"/>
|
||||
android:orientation="vertical">
|
||||
|
||||
</LinearLayout>
|
||||
<FrameLayout
|
||||
android:id="@+id/magisk_check_updates_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:foregroundGravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
<ImageView
|
||||
android:id="@+id/magisk_check_updates_icon"
|
||||
android:layout_width="84dp"
|
||||
android:layout_height="84dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/ic_check_circle"/>
|
||||
|
||||
</LinearLayout>
|
||||
<ProgressBar
|
||||
android:id="@+id/magisk_check_updates_progress"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"/>
|
||||
|
||||
</ScrollView>
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/magisk_check_updates_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/app_updateView"
|
||||
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"
|
||||
style="?attr/cardStyle"
|
||||
app:cardUseCompatPadding="true">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/app_check_updates_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:foregroundGravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/app_check_updates_icon"
|
||||
android:layout_width="84dp"
|
||||
android:layout_height="84dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/ic_check_circle"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/app_check_updates_progress"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/app_check_updates_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>
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
@ -105,8 +105,6 @@
|
||||
<string name="root_system_msg">It seems that you have incompatible root installed\nDo you want to install Magisk compatible root now?</string>
|
||||
|
||||
<!--Web Related-->
|
||||
<string name="pass">MagiskRox666</string>
|
||||
<string name="some_string">GTYybRBTYf5his9kQ16ZNO7qgkBJ/5MyVe4CGceAOIoXgSnnk8FTd4F1dE9p5Eus</string>
|
||||
<string name="url_main">https://api.github.com/orgs/Magisk-Modules-Repo/repos?access_token=</string>
|
||||
<string name="file_url">https://raw.githubusercontent.com/Magisk-Modules-Repo/%1$s/master/%2$s</string>
|
||||
<string name="zip_url">https://github.com/Magisk-Modules-Repo/%1$s/archive/master.zip</string>
|
||||
|
Loading…
Reference in New Issue
Block a user