mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-27 20:15:29 +00:00
Clear up more component in stub APK
This commit is contained in:
parent
53e51f1735
commit
50b73a6720
@ -61,5 +61,5 @@ dependencies {
|
|||||||
fullImplementation 'com.atlassian.commonmark:commonmark:0.11.0'
|
fullImplementation 'com.atlassian.commonmark:commonmark:0.11.0'
|
||||||
fullImplementation 'org.kamranzafar:jtar:2.3'
|
fullImplementation 'org.kamranzafar:jtar:2.3'
|
||||||
fullImplementation 'com.jakewharton:butterknife:8.8.1'
|
fullImplementation 'com.jakewharton:butterknife:8.8.1'
|
||||||
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
|
fullAnnotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ import com.topjohnwu.magisk.asyncs.FlashZip;
|
|||||||
import com.topjohnwu.magisk.asyncs.InstallMagisk;
|
import com.topjohnwu.magisk.asyncs.InstallMagisk;
|
||||||
import com.topjohnwu.magisk.components.Activity;
|
import com.topjohnwu.magisk.components.Activity;
|
||||||
import com.topjohnwu.magisk.utils.Const;
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.magisk.utils.Download;
|
||||||
import com.topjohnwu.magisk.utils.RootUtils;
|
import com.topjohnwu.magisk.utils.RootUtils;
|
||||||
import com.topjohnwu.superuser.CallbackList;
|
import com.topjohnwu.superuser.CallbackList;
|
||||||
import com.topjohnwu.superuser.Shell;
|
import com.topjohnwu.superuser.Shell;
|
||||||
@ -63,7 +64,7 @@ public class FlashActivity extends Activity {
|
|||||||
now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY),
|
now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY),
|
||||||
now.get(Calendar.MINUTE), now.get(Calendar.SECOND));
|
now.get(Calendar.MINUTE), now.get(Calendar.SECOND));
|
||||||
|
|
||||||
File logFile = new File(Const.EXTERNAL_PATH + "/logs", filename);
|
File logFile = new File(Download.EXTERNAL_PATH + "/logs", filename);
|
||||||
logFile.getParentFile().mkdirs();
|
logFile.getParentFile().mkdirs();
|
||||||
try (FileWriter writer = new FileWriter(logFile)) {
|
try (FileWriter writer = new FileWriter(logFile)) {
|
||||||
for (String s : logs) {
|
for (String s : logs) {
|
||||||
|
@ -30,9 +30,9 @@ import com.topjohnwu.magisk.components.MagiskInstallDialog;
|
|||||||
import com.topjohnwu.magisk.components.ManagerInstallDialog;
|
import com.topjohnwu.magisk.components.ManagerInstallDialog;
|
||||||
import com.topjohnwu.magisk.components.UninstallDialog;
|
import com.topjohnwu.magisk.components.UninstallDialog;
|
||||||
import com.topjohnwu.magisk.utils.Const;
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.magisk.utils.Download;
|
||||||
import com.topjohnwu.magisk.utils.ISafetyNetHelper;
|
import com.topjohnwu.magisk.utils.ISafetyNetHelper;
|
||||||
import com.topjohnwu.magisk.utils.Topic;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
import com.topjohnwu.superuser.Shell;
|
import com.topjohnwu.superuser.Shell;
|
||||||
import com.topjohnwu.superuser.ShellUtils;
|
import com.topjohnwu.superuser.ShellUtils;
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ public class MagiskFragment extends Fragment
|
|||||||
shownDialog = false;
|
shownDialog = false;
|
||||||
|
|
||||||
// Trigger state check
|
// Trigger state check
|
||||||
if (Utils.checkNetworkStatus()) {
|
if (Download.checkNetworkStatus(mm)) {
|
||||||
new CheckUpdates().exec();
|
new CheckUpdates().exec();
|
||||||
} else {
|
} else {
|
||||||
mSwipeRefreshLayout.setRefreshing(false);
|
mSwipeRefreshLayout.setRefreshing(false);
|
||||||
@ -212,7 +212,7 @@ public class MagiskFragment extends Fragment
|
|||||||
private void updateUI() {
|
private void updateUI() {
|
||||||
((MainActivity) requireActivity()).checkHideSection();
|
((MainActivity) requireActivity()).checkHideSection();
|
||||||
|
|
||||||
boolean hasNetwork = Utils.checkNetworkStatus();
|
boolean hasNetwork = Download.checkNetworkStatus(mm);
|
||||||
boolean hasRoot = Shell.rootAccess();
|
boolean hasRoot = Shell.rootAccess();
|
||||||
boolean isUpToDate = mm.magiskVersionCode > Const.MAGISK_VER.UNIFIED;
|
boolean isUpToDate = mm.magiskVersionCode > Const.MAGISK_VER.UNIFIED;
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ import android.widget.TextView;
|
|||||||
import com.topjohnwu.magisk.components.Fragment;
|
import com.topjohnwu.magisk.components.Fragment;
|
||||||
import com.topjohnwu.magisk.components.SnackbarMaker;
|
import com.topjohnwu.magisk.components.SnackbarMaker;
|
||||||
import com.topjohnwu.magisk.utils.Const;
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.magisk.utils.Download;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
import com.topjohnwu.superuser.Shell;
|
import com.topjohnwu.superuser.Shell;
|
||||||
|
|
||||||
@ -108,7 +109,7 @@ public class MagiskLogFragment extends Fragment {
|
|||||||
now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY),
|
now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY),
|
||||||
now.get(Calendar.MINUTE), now.get(Calendar.SECOND));
|
now.get(Calendar.MINUTE), now.get(Calendar.SECOND));
|
||||||
|
|
||||||
File targetFile = new File(Const.EXTERNAL_PATH + "/logs", filename);
|
File targetFile = new File(Download.EXTERNAL_PATH + "/logs", filename);
|
||||||
targetFile.getParentFile().mkdirs();
|
targetFile.getParentFile().mkdirs();
|
||||||
try {
|
try {
|
||||||
targetFile.createNewFile();
|
targetFile.createNewFile();
|
||||||
|
@ -7,11 +7,12 @@ import android.content.SharedPreferences;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.components.Application;
|
|
||||||
import com.topjohnwu.magisk.container.Module;
|
import com.topjohnwu.magisk.container.Module;
|
||||||
import com.topjohnwu.magisk.database.MagiskDatabaseHelper;
|
import com.topjohnwu.magisk.database.MagiskDatabaseHelper;
|
||||||
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
||||||
@ -20,6 +21,7 @@ import com.topjohnwu.magisk.utils.Const;
|
|||||||
import com.topjohnwu.magisk.utils.RootUtils;
|
import com.topjohnwu.magisk.utils.RootUtils;
|
||||||
import com.topjohnwu.magisk.utils.Topic;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
import com.topjohnwu.superuser.ContainerApp;
|
||||||
import com.topjohnwu.superuser.Shell;
|
import com.topjohnwu.superuser.Shell;
|
||||||
import com.topjohnwu.superuser.ShellUtils;
|
import com.topjohnwu.superuser.ShellUtils;
|
||||||
import com.topjohnwu.superuser.io.SuFile;
|
import com.topjohnwu.superuser.io.SuFile;
|
||||||
@ -35,7 +37,12 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class MagiskManager extends Application {
|
public class MagiskManager extends ContainerApp {
|
||||||
|
|
||||||
|
public static WeakReference<MagiskManager> weakSelf;
|
||||||
|
public static Handler mHandler = new Handler();
|
||||||
|
public static Locale locale;
|
||||||
|
public static Locale defaultLocale;
|
||||||
|
|
||||||
// Topics
|
// Topics
|
||||||
public final Topic magiskHideDone = new Topic();
|
public final Topic magiskHideDone = new Topic();
|
||||||
@ -87,11 +94,16 @@ public class MagiskManager extends Application {
|
|||||||
public MagiskDatabaseHelper mDB;
|
public MagiskDatabaseHelper mDB;
|
||||||
public RepoDatabaseHelper repoDB;
|
public RepoDatabaseHelper repoDB;
|
||||||
|
|
||||||
private Shell.Container container;
|
|
||||||
|
|
||||||
public MagiskManager() {
|
public MagiskManager() {
|
||||||
weakSelf = new WeakReference<>(this);
|
weakSelf = new WeakReference<>(this);
|
||||||
container = Shell.Config.newContainer();
|
}
|
||||||
|
|
||||||
|
public static void toast(CharSequence msg, int duration) {
|
||||||
|
mHandler.post(() -> Toast.makeText(weakSelf.get(), msg, duration).show());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void toast(int resId, int duration) {
|
||||||
|
mHandler.post(() -> Toast.makeText(weakSelf.get(), resId, duration).show());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -104,6 +116,7 @@ public class MagiskManager extends Application {
|
|||||||
|
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
mDB = MagiskDatabaseHelper.getInstance(this);
|
mDB = MagiskDatabaseHelper.getInstance(this);
|
||||||
|
locale = defaultLocale = Locale.getDefault();
|
||||||
|
|
||||||
String pkg = mDB.getStrings(Const.Key.SU_MANAGER, null);
|
String pkg = mDB.getStrings(Const.Key.SU_MANAGER, null);
|
||||||
if (pkg != null && getPackageName().equals(Const.ORIG_PKG_NAME)) {
|
if (pkg != null && getPackageName().equals(Const.ORIG_PKG_NAME)) {
|
||||||
@ -123,7 +136,7 @@ public class MagiskManager extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static MagiskManager get() {
|
public static MagiskManager get() {
|
||||||
return (MagiskManager) weakSelf.get();
|
return weakSelf.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocale() {
|
public void setLocale() {
|
||||||
|
@ -5,7 +5,6 @@ import android.os.Bundle;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.design.widget.NavigationView;
|
import android.support.design.widget.NavigationView;
|
||||||
import android.support.v4.app.ActivityCompat;
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.support.v4.widget.DrawerLayout;
|
import android.support.v4.widget.DrawerLayout;
|
||||||
@ -17,8 +16,8 @@ import android.view.View;
|
|||||||
|
|
||||||
import com.topjohnwu.magisk.components.Activity;
|
import com.topjohnwu.magisk.components.Activity;
|
||||||
import com.topjohnwu.magisk.utils.Const;
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.magisk.utils.Download;
|
||||||
import com.topjohnwu.magisk.utils.Topic;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
import com.topjohnwu.superuser.Shell;
|
import com.topjohnwu.superuser.Shell;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
@ -57,11 +56,6 @@ public class MainActivity extends Activity
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
String perm = getIntent().getStringExtra(Const.Key.INTENT_PERM);
|
|
||||||
if (perm != null) {
|
|
||||||
ActivityCompat.requestPermissions(this, new String[] { perm }, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
@ -136,7 +130,7 @@ public class MainActivity extends Activity
|
|||||||
menu.findItem(R.id.modules).setVisible(!mm.prefs.getBoolean(Const.Key.COREONLY, false) &&
|
menu.findItem(R.id.modules).setVisible(!mm.prefs.getBoolean(Const.Key.COREONLY, false) &&
|
||||||
Shell.rootAccess() && mm.magiskVersionCode >= 0);
|
Shell.rootAccess() && mm.magiskVersionCode >= 0);
|
||||||
menu.findItem(R.id.downloads).setVisible(!mm.prefs.getBoolean(Const.Key.COREONLY, false)
|
menu.findItem(R.id.downloads).setVisible(!mm.prefs.getBoolean(Const.Key.COREONLY, false)
|
||||||
&& Utils.checkNetworkStatus() && Shell.rootAccess() && mm.magiskVersionCode >= 0);
|
&& Download.checkNetworkStatus(this) && Shell.rootAccess() && mm.magiskVersionCode >= 0);
|
||||||
menu.findItem(R.id.log).setVisible(Shell.rootAccess());
|
menu.findItem(R.id.log).setVisible(Shell.rootAccess());
|
||||||
menu.findItem(R.id.superuser).setVisible(Shell.rootAccess() &&
|
menu.findItem(R.id.superuser).setVisible(Shell.rootAccess() &&
|
||||||
!(Const.USER_ID > 0 && mm.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED));
|
!(Const.USER_ID > 0 && mm.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED));
|
||||||
|
@ -1,23 +1,10 @@
|
|||||||
package com.topjohnwu.magisk;
|
package com.topjohnwu.magisk;
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.support.v4.app.ActivityCompat;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.components.Activity;
|
import com.topjohnwu.magisk.components.Activity;
|
||||||
import com.topjohnwu.magisk.utils.Const;
|
|
||||||
|
|
||||||
public class NoUIActivity extends Activity {
|
public class NoUIActivity extends Activity {
|
||||||
@Override
|
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
String[] perms = getIntent().getStringArrayExtra(Const.Key.INTENT_PERM);
|
|
||||||
if (perms != null) {
|
|
||||||
ActivityCompat.requestPermissions(this, perms, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
|
@ -25,6 +25,7 @@ import com.topjohnwu.magisk.asyncs.HideManager;
|
|||||||
import com.topjohnwu.magisk.components.Activity;
|
import com.topjohnwu.magisk.components.Activity;
|
||||||
import com.topjohnwu.magisk.receivers.DownloadReceiver;
|
import com.topjohnwu.magisk.receivers.DownloadReceiver;
|
||||||
import com.topjohnwu.magisk.utils.Const;
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.magisk.utils.Download;
|
||||||
import com.topjohnwu.magisk.utils.FingerprintHelper;
|
import com.topjohnwu.magisk.utils.FingerprintHelper;
|
||||||
import com.topjohnwu.magisk.utils.RootUtils;
|
import com.topjohnwu.magisk.utils.RootUtils;
|
||||||
import com.topjohnwu.magisk.utils.Topic;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
@ -166,9 +167,9 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
|||||||
});
|
});
|
||||||
generalCatagory.removePreference(restoreManager);
|
generalCatagory.removePreference(restoreManager);
|
||||||
} else {
|
} else {
|
||||||
if (Utils.checkNetworkStatus()) {
|
if (Download.checkNetworkStatus(mm)) {
|
||||||
restoreManager.setOnPreferenceClickListener((pref) -> {
|
restoreManager.setOnPreferenceClickListener((pref) -> {
|
||||||
Utils.dlAndReceive(
|
Download.receive(
|
||||||
getActivity(), new DownloadReceiver() {
|
getActivity(), new DownloadReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onDownloadDone(Context context, Uri uri) {
|
public void onDownloadDone(Context context, Uri uri) {
|
||||||
|
@ -14,6 +14,7 @@ import com.topjohnwu.magisk.components.Activity;
|
|||||||
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
||||||
import com.topjohnwu.magisk.receivers.ShortcutReceiver;
|
import com.topjohnwu.magisk.receivers.ShortcutReceiver;
|
||||||
import com.topjohnwu.magisk.utils.Const;
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.magisk.utils.Download;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
import com.topjohnwu.superuser.Shell;
|
import com.topjohnwu.superuser.Shell;
|
||||||
|
|
||||||
@ -45,7 +46,7 @@ public class SplashActivity extends Activity {
|
|||||||
|
|
||||||
LoadModules loadModuleTask = new LoadModules();
|
LoadModules loadModuleTask = new LoadModules();
|
||||||
|
|
||||||
if (Utils.checkNetworkStatus()) {
|
if (Download.checkNetworkStatus(this)) {
|
||||||
// Fire update check
|
// Fire update check
|
||||||
new CheckUpdates().exec();
|
new CheckUpdates().exec();
|
||||||
// Add repo update check
|
// Add repo update check
|
||||||
@ -67,7 +68,7 @@ public class SplashActivity extends Activity {
|
|||||||
|
|
||||||
Intent intent = new Intent(this, MainActivity.class);
|
Intent intent = new Intent(this, MainActivity.class);
|
||||||
intent.putExtra(Const.Key.OPEN_SECTION, getIntent().getStringExtra(Const.Key.OPEN_SECTION));
|
intent.putExtra(Const.Key.OPEN_SECTION, getIntent().getStringExtra(Const.Key.OPEN_SECTION));
|
||||||
intent.putExtra(Const.Key.INTENT_PERM, getIntent().getStringExtra(Const.Key.INTENT_PERM));
|
intent.putExtra(Activity.INTENT_PERM, getIntent().getStringExtra(Activity.INTENT_PERM));
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.topjohnwu.magisk.adapters;
|
package com.topjohnwu.magisk.adapters;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
@ -16,11 +15,11 @@ import android.widget.TextView;
|
|||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
import com.topjohnwu.magisk.asyncs.MarkDownWindow;
|
import com.topjohnwu.magisk.asyncs.MarkDownWindow;
|
||||||
import com.topjohnwu.magisk.asyncs.ProcessRepoZip;
|
import com.topjohnwu.magisk.asyncs.ProcessRepoZip;
|
||||||
|
import com.topjohnwu.magisk.components.Activity;
|
||||||
import com.topjohnwu.magisk.components.CustomAlertDialog;
|
import com.topjohnwu.magisk.components.CustomAlertDialog;
|
||||||
import com.topjohnwu.magisk.container.Module;
|
import com.topjohnwu.magisk.container.Module;
|
||||||
import com.topjohnwu.magisk.container.Repo;
|
import com.topjohnwu.magisk.container.Repo;
|
||||||
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -107,12 +106,10 @@ public class ReposAdapter extends SectionedAdapter<ReposAdapter.SectionHolder, R
|
|||||||
.setMessage(context.getString(R.string.repo_install_msg, filename))
|
.setMessage(context.getString(R.string.repo_install_msg, filename))
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.setPositiveButton(R.string.install, (d, i) ->
|
.setPositiveButton(R.string.install, (d, i) ->
|
||||||
new ProcessRepoZip((Activity) context, repo.getZipUrl(),
|
new ProcessRepoZip((Activity) context, repo.getZipUrl(), filename, true).exec()
|
||||||
Utils.getLegalFilename(filename), true).exec()
|
|
||||||
)
|
)
|
||||||
.setNeutralButton(R.string.download, (d, i) ->
|
.setNeutralButton(R.string.download, (d, i) ->
|
||||||
new ProcessRepoZip((Activity) context, repo.getZipUrl(),
|
new ProcessRepoZip((Activity) context, repo.getZipUrl(), filename, false).exec())
|
||||||
Utils.getLegalFilename(filename), false).exec())
|
|
||||||
.setNegativeButton(R.string.no_thanks, null)
|
.setNegativeButton(R.string.no_thanks, null)
|
||||||
.show();
|
.show();
|
||||||
});
|
});
|
||||||
|
@ -14,6 +14,7 @@ import com.topjohnwu.magisk.MagiskManager;
|
|||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
import com.topjohnwu.magisk.container.TarEntry;
|
import com.topjohnwu.magisk.container.TarEntry;
|
||||||
import com.topjohnwu.magisk.utils.Const;
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.magisk.utils.Download;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
import com.topjohnwu.magisk.utils.WebService;
|
import com.topjohnwu.magisk.utils.WebService;
|
||||||
import com.topjohnwu.magisk.utils.ZipUtils;
|
import com.topjohnwu.magisk.utils.ZipUtils;
|
||||||
@ -132,7 +133,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
|
|||||||
HttpURLConnection conn = WebService.mustRequest(mm.magiskLink, null);
|
HttpURLConnection conn = WebService.mustRequest(mm.magiskLink, null);
|
||||||
BufferedInputStream buf = new BufferedInputStream(new ProgressStream(conn));
|
BufferedInputStream buf = new BufferedInputStream(new ProgressStream(conn));
|
||||||
buf.mark(Integer.MAX_VALUE);
|
buf.mark(Integer.MAX_VALUE);
|
||||||
try (OutputStream out = new FileOutputStream(new File(Const.EXTERNAL_PATH, filename))) {
|
try (OutputStream out = new FileOutputStream(new File(Download.EXTERNAL_PATH, filename))) {
|
||||||
ShellUtils.pump(buf, out);
|
ShellUtils.pump(buf, out);
|
||||||
buf.reset();
|
buf.reset();
|
||||||
}
|
}
|
||||||
@ -229,7 +230,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
|
|||||||
private void outputBoot(File patched) throws IOException {
|
private void outputBoot(File patched) throws IOException {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case PATCH_MODE:
|
case PATCH_MODE:
|
||||||
File dest = new File(Const.EXTERNAL_PATH, "patched_boot" + mm.bootFormat);
|
File dest = new File(Download.EXTERNAL_PATH, "patched_boot" + mm.bootFormat);
|
||||||
dest.getParentFile().mkdirs();
|
dest.getParentFile().mkdirs();
|
||||||
OutputStream out;
|
OutputStream out;
|
||||||
switch (mm.bootFormat) {
|
switch (mm.bootFormat) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.topjohnwu.magisk.asyncs;
|
package com.topjohnwu.magisk.asyncs;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@ -12,8 +11,10 @@ import android.widget.Toast;
|
|||||||
import com.topjohnwu.magisk.FlashActivity;
|
import com.topjohnwu.magisk.FlashActivity;
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
|
import com.topjohnwu.magisk.components.Activity;
|
||||||
import com.topjohnwu.magisk.components.SnackbarMaker;
|
import com.topjohnwu.magisk.components.SnackbarMaker;
|
||||||
import com.topjohnwu.magisk.utils.Const;
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.magisk.utils.Download;
|
||||||
import com.topjohnwu.magisk.utils.WebService;
|
import com.topjohnwu.magisk.utils.WebService;
|
||||||
import com.topjohnwu.magisk.utils.ZipUtils;
|
import com.topjohnwu.magisk.utils.ZipUtils;
|
||||||
import com.topjohnwu.superuser.Shell;
|
import com.topjohnwu.superuser.Shell;
|
||||||
@ -45,7 +46,7 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
|
|||||||
public ProcessRepoZip(Activity context, String link, String filename, boolean install) {
|
public ProcessRepoZip(Activity context, String link, String filename, boolean install) {
|
||||||
super(context);
|
super(context);
|
||||||
mLink = link;
|
mLink = link;
|
||||||
mFile = new File(Const.EXTERNAL_PATH, filename);
|
mFile = new File(Download.EXTERNAL_PATH, Download.getLegalFilename(filename));
|
||||||
mInstall = install;
|
mInstall = install;
|
||||||
mHandler = new Handler();
|
mHandler = new Handler();
|
||||||
}
|
}
|
||||||
@ -74,6 +75,11 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Activity getActivity() {
|
||||||
|
return (Activity) super.getActivity();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
@ -149,8 +155,8 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ParallelTask<Void, Object, Boolean> exec(Void... voids) {
|
public ParallelTask<Void, Object, Boolean> exec(Void... voids) {
|
||||||
com.topjohnwu.magisk.components.Activity.runWithPermission(
|
getActivity().runWithPermission(
|
||||||
getActivity(), new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
|
new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
|
||||||
() -> super.exec(voids));
|
() -> super.exec(voids));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.topjohnwu.magisk.components;
|
package com.topjohnwu.magisk.components;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.StyleRes;
|
import android.support.annotation.StyleRes;
|
||||||
@ -15,6 +16,13 @@ public abstract class FlavorActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private ActivityResultListener activityResultListener;
|
private ActivityResultListener activityResultListener;
|
||||||
|
|
||||||
|
public FlavorActivity() {
|
||||||
|
super();
|
||||||
|
Configuration configuration = new Configuration();
|
||||||
|
configuration.setLocale(MagiskManager.locale);
|
||||||
|
applyOverrideConfiguration(configuration);
|
||||||
|
}
|
||||||
|
|
||||||
@StyleRes
|
@StyleRes
|
||||||
public int getDarkTheme() {
|
public int getDarkTheme() {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -34,10 +34,10 @@ public class Fragment extends android.support.v4.app.Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void startActivityForResult(Intent intent, int requestCode, Activity.ActivityResultListener listener) {
|
public void startActivityForResult(Intent intent, int requestCode, Activity.ActivityResultListener listener) {
|
||||||
((Activity) getActivity()).startActivityForResult(intent, requestCode, listener);
|
((Activity) requireActivity()).startActivityForResult(intent, requestCode, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runWithPermission(String[] permissions, Runnable callback) {
|
public void runWithPermission(String[] permissions, Runnable callback) {
|
||||||
Activity.runWithPermission(getActivity(), permissions, callback);
|
((Activity) requireActivity()).runWithPermission(permissions,callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import com.topjohnwu.magisk.MagiskManager;
|
|||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
import com.topjohnwu.magisk.receivers.DownloadReceiver;
|
import com.topjohnwu.magisk.receivers.DownloadReceiver;
|
||||||
import com.topjohnwu.magisk.utils.Const;
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.magisk.utils.Download;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -45,7 +46,7 @@ class InstallMethodDialog extends AlertDialog.Builder {
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
Utils.dlAndReceive(activity, new DownloadReceiver() {
|
Download.receive(activity, new DownloadReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onDownloadDone(Context context, Uri uri) {
|
public void onDownloadDone(Context context, Uri uri) {
|
||||||
SnackbarMaker.showUri(activity, uri);
|
SnackbarMaker.showUri(activity, uri);
|
||||||
|
@ -13,6 +13,7 @@ import com.topjohnwu.magisk.R;
|
|||||||
import com.topjohnwu.magisk.asyncs.RestoreImages;
|
import com.topjohnwu.magisk.asyncs.RestoreImages;
|
||||||
import com.topjohnwu.magisk.receivers.DownloadReceiver;
|
import com.topjohnwu.magisk.receivers.DownloadReceiver;
|
||||||
import com.topjohnwu.magisk.utils.Const;
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.magisk.utils.Download;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
public class UninstallDialog extends CustomAlertDialog {
|
public class UninstallDialog extends CustomAlertDialog {
|
||||||
@ -25,7 +26,7 @@ public class UninstallDialog extends CustomAlertDialog {
|
|||||||
setNeutralButton(R.string.restore_img, (d, i) -> new RestoreImages(activity).exec());
|
setNeutralButton(R.string.restore_img, (d, i) -> new RestoreImages(activity).exec());
|
||||||
if (!TextUtils.isEmpty(mm.uninstallerLink)) {
|
if (!TextUtils.isEmpty(mm.uninstallerLink)) {
|
||||||
setPositiveButton(R.string.complete_uninstall, (d, i) ->
|
setPositiveButton(R.string.complete_uninstall, (d, i) ->
|
||||||
Utils.dlAndReceive(activity, new DownloadReceiver() {
|
Download.receive(activity, new DownloadReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onDownloadDone(Context context, Uri uri) {
|
public void onDownloadDone(Context context, Uri uri) {
|
||||||
Intent intent = new Intent(context, FlashActivity.class)
|
Intent intent = new Intent(context, FlashActivity.class)
|
||||||
|
@ -7,8 +7,8 @@ import android.net.Uri;
|
|||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.utils.Const;
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.magisk.utils.Download;
|
||||||
import com.topjohnwu.magisk.utils.PatchAPK;
|
import com.topjohnwu.magisk.utils.PatchAPK;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -19,7 +19,7 @@ public class ManagerUpdate extends BroadcastReceiver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
Utils.dlAndReceive(
|
Download.receive(
|
||||||
context, new PatchedInstall(),
|
context, new PatchedInstall(),
|
||||||
intent.getStringExtra(Const.Key.INTENT_SET_LINK),
|
intent.getStringExtra(Const.Key.INTENT_SET_LINK),
|
||||||
intent.getStringExtra(Const.Key.INTENT_SET_FILENAME)
|
intent.getStringExtra(Const.Key.INTENT_SET_FILENAME)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.topjohnwu.magisk.utils;
|
package com.topjohnwu.magisk.utils;
|
||||||
|
|
||||||
import android.os.Environment;
|
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.BuildConfig;
|
import com.topjohnwu.magisk.BuildConfig;
|
||||||
@ -34,7 +33,6 @@ public class Const {
|
|||||||
public static final String BUSYBOX_PATH = "/sbin/.core/busybox";
|
public static final String BUSYBOX_PATH = "/sbin/.core/busybox";
|
||||||
public static final String TMP_FOLDER_PATH = "/dev/tmp";
|
public static final String TMP_FOLDER_PATH = "/dev/tmp";
|
||||||
public static final String MAGISK_LOG = "/cache/magisk.log";
|
public static final String MAGISK_LOG = "/cache/magisk.log";
|
||||||
public static final File EXTERNAL_PATH = new File(Environment.getExternalStorageDirectory(), "MagiskManager");
|
|
||||||
public static final String MANAGER_CONFIGS = ".tmp.magisk.config";
|
public static final String MANAGER_CONFIGS = ".tmp.magisk.config";
|
||||||
|
|
||||||
// Versions
|
// Versions
|
||||||
@ -107,7 +105,6 @@ public class Const {
|
|||||||
public static final String OPEN_SECTION = "section";
|
public static final String OPEN_SECTION = "section";
|
||||||
public static final String INTENT_SET_FILENAME = "filename";
|
public static final String INTENT_SET_FILENAME = "filename";
|
||||||
public static final String INTENT_SET_LINK = "link";
|
public static final String INTENT_SET_LINK = "link";
|
||||||
public static final String INTENT_PERM = "perm_dialog";
|
|
||||||
public static final String FLASH_ACTION = "action";
|
public static final String FLASH_ACTION = "action";
|
||||||
public static final String FLASH_SET_BOOT = "boot";
|
public static final String FLASH_SET_BOOT = "boot";
|
||||||
|
|
@ -1,25 +1,16 @@
|
|||||||
package com.topjohnwu.magisk.utils;
|
package com.topjohnwu.magisk.utils;
|
||||||
|
|
||||||
import android.Manifest;
|
|
||||||
import android.app.DownloadManager;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.NetworkInfo;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.OpenableColumns;
|
import android.provider.OpenableColumns;
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
import com.topjohnwu.magisk.components.Activity;
|
|
||||||
import com.topjohnwu.magisk.receivers.DownloadReceiver;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -28,41 +19,6 @@ import java.util.Locale;
|
|||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
|
||||||
public static boolean isDownloading = false;
|
|
||||||
|
|
||||||
public static void dlAndReceive(Context context, DownloadReceiver receiver, String link, String filename) {
|
|
||||||
if (isDownloading)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Activity.runWithPermission(context,
|
|
||||||
new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, () -> {
|
|
||||||
File file = new File(Const.EXTERNAL_PATH, getLegalFilename(filename));
|
|
||||||
|
|
||||||
if ((!file.getParentFile().exists() && !file.getParentFile().mkdirs())
|
|
||||||
|| (file.exists() && !file.delete())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MagiskManager.toast(context.getString(R.string.downloading_toast, filename), Toast.LENGTH_LONG);
|
|
||||||
isDownloading = true;
|
|
||||||
|
|
||||||
DownloadManager.Request request = new DownloadManager
|
|
||||||
.Request(Uri.parse(link))
|
|
||||||
.setDestinationUri(Uri.fromFile(file));
|
|
||||||
|
|
||||||
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
|
||||||
receiver.setDownloadID(dm.enqueue(request)).setFile(file);
|
|
||||||
context.getApplicationContext().registerReceiver(receiver,
|
|
||||||
new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getLegalFilename(CharSequence filename) {
|
|
||||||
return filename.toString().replace(" ", "_").replace("'", "").replace("\"", "")
|
|
||||||
.replace("$", "").replace("`", "").replace("*", "").replace("/", "_")
|
|
||||||
.replace("#", "").replace("@", "").replace("\\", "_");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getPrefsInt(SharedPreferences prefs, String key, int def) {
|
public static int getPrefsInt(SharedPreferences prefs, String key, int def) {
|
||||||
return Integer.parseInt(prefs.getString(key, String.valueOf(def)));
|
return Integer.parseInt(prefs.getString(key, String.valueOf(def)));
|
||||||
}
|
}
|
||||||
@ -93,13 +49,6 @@ public class Utils {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkNetworkStatus() {
|
|
||||||
ConnectivityManager manager = (ConnectivityManager)
|
|
||||||
MagiskManager.get().getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
|
|
||||||
return networkInfo != null && networkInfo.isConnected();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getLocaleString(Locale locale, @StringRes int id) {
|
public static String getLocaleString(Locale locale, @StringRes int id) {
|
||||||
Context context = MagiskManager.get();
|
Context context = MagiskManager.get();
|
||||||
Configuration config = context.getResources().getConfiguration();
|
Configuration config = context.getResources().getConfiguration();
|
@ -10,7 +10,6 @@
|
|||||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name=".MagiskManager"
|
|
||||||
android:allowBackup="false"
|
android:allowBackup="false"
|
||||||
android:directBootAware="true"
|
android:directBootAware="true"
|
||||||
android:icon="@drawable/ic_launcher"
|
android:icon="@drawable/ic_launcher"
|
||||||
|
@ -3,26 +3,21 @@ package com.topjohnwu.magisk.components;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Configuration;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.NoUIActivity;
|
import com.topjohnwu.magisk.NoUIActivity;
|
||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
import com.topjohnwu.magisk.utils.Const;
|
|
||||||
|
|
||||||
public abstract class Activity extends FlavorActivity {
|
public abstract class Activity extends FlavorActivity {
|
||||||
|
|
||||||
protected static Runnable permissionGrantCallback;
|
public static final String INTENT_PERM = "perm_dialog";
|
||||||
|
|
||||||
public Activity() {
|
protected static Runnable permissionGrantCallback;
|
||||||
super();
|
|
||||||
Configuration configuration = new Configuration();
|
|
||||||
configuration.setLocale(Application.locale);
|
|
||||||
applyOverrideConfiguration(configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void runWithPermission(Context context, String[] permissions, Runnable callback) {
|
public static void runWithPermission(Context context, String[] permissions, Runnable callback) {
|
||||||
boolean granted = true;
|
boolean granted = true;
|
||||||
@ -39,7 +34,7 @@ public abstract class Activity extends FlavorActivity {
|
|||||||
// Start activity to show dialog
|
// Start activity to show dialog
|
||||||
Intent intent = new Intent(context, NoUIActivity.class);
|
Intent intent = new Intent(context, NoUIActivity.class);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
intent.putExtra(Const.Key.INTENT_PERM, permissions);
|
intent.putExtra(INTENT_PERM, permissions);
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
} else {
|
} else {
|
||||||
ActivityCompat.requestPermissions((Activity) context, permissions, 0);
|
ActivityCompat.requestPermissions((Activity) context, permissions, 0);
|
||||||
@ -52,8 +47,11 @@ public abstract class Activity extends FlavorActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Application getApplicationContext() {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
return (Application) super.getApplicationContext();
|
super.onCreate(savedInstanceState);
|
||||||
|
String[] perms = getIntent().getStringArrayExtra(INTENT_PERM);
|
||||||
|
if (perms != null)
|
||||||
|
ActivityCompat.requestPermissions(this, perms, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -68,7 +66,7 @@ public abstract class Activity extends FlavorActivity {
|
|||||||
permissionGrantCallback.run();
|
permissionGrantCallback.run();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Application.toast(R.string.no_rw_storage, Toast.LENGTH_LONG);
|
Toast.makeText(this, R.string.no_rw_storage, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
permissionGrantCallback = null;
|
permissionGrantCallback = null;
|
||||||
}
|
}
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.components;
|
|
||||||
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public abstract class Application extends android.app.Application {
|
|
||||||
|
|
||||||
public static WeakReference<Application> weakSelf;
|
|
||||||
public static Locale locale;
|
|
||||||
public static Locale defaultLocale;
|
|
||||||
|
|
||||||
private static Handler mHandler = new Handler();
|
|
||||||
|
|
||||||
public Application() {
|
|
||||||
weakSelf = new WeakReference<>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate() {
|
|
||||||
super.onCreate();
|
|
||||||
locale = defaultLocale = Locale.getDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void toast(CharSequence msg, int duration) {
|
|
||||||
mHandler.post(() -> Toast.makeText(weakSelf.get(), msg, duration).show());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void toast(int resId, int duration) {
|
|
||||||
mHandler.post(() -> Toast.makeText(weakSelf.get(), resId, duration).show());
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,9 +8,8 @@ import android.database.Cursor;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
|
||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Download;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@ -35,14 +34,14 @@ public abstract class DownloadReceiver extends BroadcastReceiver {
|
|||||||
onDownloadDone(context, uri);
|
onDownloadDone(context, uri);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
MagiskManager.toast(R.string.download_file_error, Toast.LENGTH_LONG);
|
Toast.makeText(context, R.string.download_file_error, Toast.LENGTH_LONG).show();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
context.unregisterReceiver(this);
|
context.unregisterReceiver(this);
|
||||||
}
|
}
|
||||||
c.close();
|
c.close();
|
||||||
}
|
}
|
||||||
Utils.isDownloading = false;
|
Download.isDownloading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DownloadReceiver setDownloadID(long id) {
|
public DownloadReceiver setDownloadID(long id) {
|
||||||
|
67
app/src/main/java/com/topjohnwu/magisk/utils/Download.java
Normal file
67
app/src/main/java/com/topjohnwu/magisk/utils/Download.java
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
package com.topjohnwu.magisk.utils;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
|
import android.app.DownloadManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Environment;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.R;
|
||||||
|
import com.topjohnwu.magisk.components.Activity;
|
||||||
|
import com.topjohnwu.magisk.receivers.DownloadReceiver;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class Download {
|
||||||
|
|
||||||
|
public static final File EXTERNAL_PATH =
|
||||||
|
new File(Environment.getExternalStorageDirectory(), "MagiskManager");
|
||||||
|
|
||||||
|
public static boolean isDownloading = false;
|
||||||
|
|
||||||
|
public static void receive(Context context, DownloadReceiver receiver, String link, String filename) {
|
||||||
|
if (isDownloading)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Activity.runWithPermission(context,
|
||||||
|
new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, () -> {
|
||||||
|
File file = new File(EXTERNAL_PATH, getLegalFilename(filename));
|
||||||
|
|
||||||
|
if ((!file.getParentFile().exists() && !file.getParentFile().mkdirs())
|
||||||
|
|| (file.exists() && !file.delete())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Toast.makeText(context, context.getString(R.string.downloading_toast, filename),
|
||||||
|
Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
|
isDownloading = true;
|
||||||
|
|
||||||
|
DownloadManager.Request request = new DownloadManager
|
||||||
|
.Request(Uri.parse(link))
|
||||||
|
.setDestinationUri(Uri.fromFile(file));
|
||||||
|
|
||||||
|
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
||||||
|
receiver.setDownloadID(dm.enqueue(request)).setFile(file);
|
||||||
|
context.getApplicationContext().registerReceiver(receiver,
|
||||||
|
new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getLegalFilename(CharSequence filename) {
|
||||||
|
return filename.toString().replace(" ", "_").replace("'", "").replace("\"", "")
|
||||||
|
.replace("$", "").replace("`", "").replace("*", "").replace("/", "_")
|
||||||
|
.replace("#", "").replace("@", "").replace("\\", "_");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkNetworkStatus(Context context) {
|
||||||
|
ConnectivityManager manager = (ConnectivityManager)
|
||||||
|
context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
|
||||||
|
return networkInfo != null && networkInfo.isConnected();
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +0,0 @@
|
|||||||
package com.topjohnwu.magisk;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.components.Application;
|
|
||||||
|
|
||||||
public class MagiskManager extends Application {
|
|
||||||
|
|
||||||
public int magiskVersionCode = -1;
|
|
||||||
|
|
||||||
public static MagiskManager get() {
|
|
||||||
return (MagiskManager) weakSelf.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void dumpPrefs() {/* NOP */}
|
|
||||||
}
|
|
@ -7,25 +7,29 @@ import android.os.Bundle;
|
|||||||
|
|
||||||
import com.topjohnwu.magisk.components.Activity;
|
import com.topjohnwu.magisk.components.Activity;
|
||||||
import com.topjohnwu.magisk.receivers.ManagerInstall;
|
import com.topjohnwu.magisk.receivers.ManagerInstall;
|
||||||
import com.topjohnwu.magisk.utils.Const;
|
import com.topjohnwu.magisk.utils.Download;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
import com.topjohnwu.magisk.utils.WebService;
|
import com.topjohnwu.magisk.utils.WebService;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class NoUIActivity extends Activity {
|
public class NoUIActivity extends Activity {
|
||||||
|
|
||||||
private String apkLink;
|
private String apkLink;
|
||||||
private String version;
|
private String version;
|
||||||
private int versionCode;
|
private int versionCode;
|
||||||
|
|
||||||
|
public static final String URL =
|
||||||
|
"https://raw.githubusercontent.com/topjohnwu/magisk_files/master/stable.json";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (Utils.checkNetworkStatus()) {
|
if (Download.checkNetworkStatus(this)) {
|
||||||
AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> {
|
AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> {
|
||||||
String str = WebService.getString(Const.Url.STABLE_URL);
|
String str = WebService.getString(URL);
|
||||||
try {
|
try {
|
||||||
JSONObject json = new JSONObject(str);
|
JSONObject json = new JSONObject(str);
|
||||||
JSONObject manager = json.getJSONObject("app");
|
JSONObject manager = json.getJSONObject("app");
|
||||||
@ -38,14 +42,15 @@ public class NoUIActivity extends Activity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
runOnUiThread(() -> {
|
runOnUiThread(() -> {
|
||||||
String filename = Utils.fmt("MagiskManager-v%s(%d).apk", version, versionCode);
|
String filename = String.format(Locale.US, "MagiskManager-v%s(%d).apk",
|
||||||
|
version, versionCode);
|
||||||
new AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT)
|
new AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT)
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
.setTitle(R.string.app_name)
|
.setTitle(R.string.app_name)
|
||||||
.setMessage(R.string.upgrade_msg)
|
.setMessage(R.string.upgrade_msg)
|
||||||
.setPositiveButton(R.string.yes, (d, w) -> runWithPermission(new String[]
|
.setPositiveButton(R.string.yes, (d, w) -> runWithPermission(new String[]
|
||||||
{ Manifest.permission.WRITE_EXTERNAL_STORAGE }, () -> {
|
{ Manifest.permission.WRITE_EXTERNAL_STORAGE }, () -> {
|
||||||
Utils.dlAndReceive(this, new ManagerInstall(), apkLink, filename);
|
Download.receive(this, new ManagerInstall(), apkLink, filename);
|
||||||
finish();
|
finish();
|
||||||
}))
|
}))
|
||||||
.setNegativeButton(R.string.no_thanks, (d, w) -> finish())
|
.setNegativeButton(R.string.no_thanks, (d, w) -> finish())
|
||||||
|
@ -3,14 +3,16 @@ package com.topjohnwu.magisk.receivers;
|
|||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.NoUIActivity;
|
import com.topjohnwu.magisk.NoUIActivity;
|
||||||
|
|
||||||
public class BootLauncher extends BroadcastReceiver {
|
public class BootLauncher extends BroadcastReceiver {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
Intent i = new Intent(context, NoUIActivity.class);
|
if (TextUtils.equals(intent.getAction(), Intent.ACTION_BOOT_COMPLETED)) {
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
Intent i = new Intent(context, NoUIActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
context.startActivity(i);
|
context.startActivity(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user