mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-28 04:25:27 +00:00
Simplify app startup
This commit is contained in:
parent
cc81cd446b
commit
dbe6e5b3d7
@ -122,6 +122,7 @@ public class MagiskFragment extends Fragment
|
||||
}
|
||||
}
|
||||
}
|
||||
((NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE)).cancelAll();
|
||||
final String finalBootImage = bootImage;
|
||||
String filename = "Magisk-v" + magiskManager.remoteMagiskVersionString + ".zip";
|
||||
new AlertDialogBuilder(getActivity())
|
||||
@ -129,9 +130,7 @@ public class MagiskFragment extends Fragment
|
||||
.setMessage(getString(R.string.repo_install_msg, filename))
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(Shell.rootAccess() ? R.string.install : R.string.download,
|
||||
(d, i) -> {
|
||||
((NotificationManager) getActivity()
|
||||
.getSystemService(Context.NOTIFICATION_SERVICE)).cancelAll();
|
||||
(d, i) ->
|
||||
Utils.dlAndReceive(
|
||||
getActivity(),
|
||||
new DownloadReceiver() {
|
||||
@ -155,8 +154,7 @@ public class MagiskFragment extends Fragment
|
||||
}
|
||||
},
|
||||
magiskManager.magiskLink,
|
||||
Utils.getLegalFilename(filename));
|
||||
}
|
||||
Utils.getLegalFilename(filename))
|
||||
)
|
||||
.setNeutralButton(R.string.release_notes, (d, i) -> {
|
||||
if (magiskManager.releaseNoteLink != null) {
|
||||
@ -226,20 +224,16 @@ public class MagiskFragment extends Fragment
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View v = inflater.inflate(R.layout.fragment_magisk, container, false);
|
||||
unbinder = ButterKnife.bind(this, v);
|
||||
getActivity().setTitle(R.string.magisk);
|
||||
|
||||
magiskManager = getApplication();
|
||||
|
||||
expandableContainer.expandLayout = expandLayout;
|
||||
setupExpandable();
|
||||
|
||||
mSwipeRefreshLayout.setOnRefreshListener(this);
|
||||
|
||||
updateUI();
|
||||
|
||||
if (getArguments() != null && getArguments().getBoolean(SHOW_DIALOG))
|
||||
install();
|
||||
|
||||
getActivity().setTitle(R.string.magisk);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,9 @@ package com.topjohnwu.magisk;
|
||||
import android.app.Application;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.job.JobInfo;
|
||||
import android.app.job.JobScheduler;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
@ -14,10 +17,13 @@ import android.widget.Toast;
|
||||
|
||||
import com.topjohnwu.magisk.asyncs.CheckUpdates;
|
||||
import com.topjohnwu.magisk.asyncs.DownloadBusybox;
|
||||
import com.topjohnwu.magisk.asyncs.LoadModules;
|
||||
import com.topjohnwu.magisk.asyncs.ParallelTask;
|
||||
import com.topjohnwu.magisk.asyncs.UpdateRepos;
|
||||
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
||||
import com.topjohnwu.magisk.database.SuDatabaseHelper;
|
||||
import com.topjohnwu.magisk.module.Module;
|
||||
import com.topjohnwu.magisk.services.UpdateCheckService;
|
||||
import com.topjohnwu.magisk.superuser.SuReceiver;
|
||||
import com.topjohnwu.magisk.superuser.SuRequestActivity;
|
||||
import com.topjohnwu.magisk.utils.SafetyNetHelper;
|
||||
@ -42,6 +48,7 @@ public class MagiskManager extends Application {
|
||||
public static final String DISABLE_INDICATION_PROP = "ro.magisk.disable";
|
||||
public static final String NOTIFICATION_CHANNEL = "magisk_update_notice";
|
||||
public static final String BUSYBOX_VERSION = "1.27.1";
|
||||
public static final int UPDATE_SERVICE_ID = 1;
|
||||
|
||||
// Topics
|
||||
public final Topic magiskHideDone = new Topic();
|
||||
@ -100,6 +107,7 @@ public class MagiskManager extends Application {
|
||||
public Shell shell;
|
||||
|
||||
private static Handler mHandler = new Handler();
|
||||
private boolean startup = false;
|
||||
|
||||
private static class LoadLocale extends ParallelTask<Void, Void, Void> {
|
||||
|
||||
@ -177,7 +185,12 @@ public class MagiskManager extends Application {
|
||||
mHandler.post(() -> Toast.makeText(this, resId, duration).show());
|
||||
}
|
||||
|
||||
public void init() {
|
||||
public void startup() {
|
||||
if (startup)
|
||||
return;
|
||||
startup = true;
|
||||
|
||||
shell = Shell.getShell();
|
||||
new LoadLocale(this).exec();
|
||||
new DownloadBusybox(this).exec();
|
||||
getMagiskInfo();
|
||||
@ -212,10 +225,24 @@ public class MagiskManager extends Application {
|
||||
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(channel);
|
||||
}
|
||||
|
||||
LoadModules loadModuleTask = new LoadModules(this);
|
||||
// Start update check job
|
||||
if (Utils.checkNetworkStatus(this)) {
|
||||
ComponentName service = new ComponentName(this, UpdateCheckService.class);
|
||||
JobInfo jobInfo = new JobInfo.Builder(UPDATE_SERVICE_ID, service)
|
||||
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
|
||||
.setPersisted(true)
|
||||
.setPeriodic(8 * 60 * 60 * 1000)
|
||||
.build();
|
||||
((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo);
|
||||
loadModuleTask.setCallBack(() -> new UpdateRepos(this).exec());
|
||||
}
|
||||
// Fire asynctasks
|
||||
loadModuleTask.exec();
|
||||
|
||||
}
|
||||
|
||||
public void getMagiskInfo() {
|
||||
Shell.getShell(this);
|
||||
List<String> ret;
|
||||
ret = shell.sh("su -v");
|
||||
if (Utils.isValidShellResponse(ret)) {
|
||||
|
@ -38,6 +38,7 @@ public class MainActivity extends Activity
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
getApplicationContext().startup();
|
||||
|
||||
prefs = getApplicationContext().prefs;
|
||||
|
||||
@ -131,9 +132,6 @@ public class MainActivity extends Activity
|
||||
case "magisk":
|
||||
itemId = R.id.magisk;
|
||||
break;
|
||||
case "install":
|
||||
itemId = -1;
|
||||
break;
|
||||
case "superuser":
|
||||
itemId = R.id.superuser;
|
||||
break;
|
||||
@ -165,13 +163,6 @@ public class MainActivity extends Activity
|
||||
mDrawerItem = itemId;
|
||||
navigationView.setCheckedItem(itemId);
|
||||
switch (itemId) {
|
||||
case -1:
|
||||
Bundle args = new Bundle();
|
||||
args.putBoolean(MagiskFragment.SHOW_DIALOG, true);
|
||||
Fragment frag = new MagiskFragment();
|
||||
frag.setArguments(args);
|
||||
displayFragment(frag, "magisk", true);
|
||||
break;
|
||||
case R.id.magisk:
|
||||
displayFragment(new MagiskFragment(), "magisk", true);
|
||||
break;
|
||||
|
@ -1,54 +1,17 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import android.app.job.JobInfo;
|
||||
import android.app.job.JobScheduler;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.topjohnwu.magisk.asyncs.LoadModules;
|
||||
import com.topjohnwu.magisk.asyncs.UpdateRepos;
|
||||
import com.topjohnwu.magisk.components.Activity;
|
||||
import com.topjohnwu.magisk.services.UpdateCheckService;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
public class SplashActivity extends Activity{
|
||||
|
||||
private static final int UPDATE_SERVICE_ID = 1;
|
||||
public class SplashActivity extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
MagiskManager magiskManager = getApplicationContext();
|
||||
|
||||
// Init the info and configs and root sh
|
||||
magiskManager.init();
|
||||
|
||||
// Get possible additional info from intent
|
||||
magiskManager.remoteMagiskVersionString = getIntent().getStringExtra(MagiskManager.INTENT_VERSION);
|
||||
magiskManager.magiskLink = getIntent().getStringExtra(MagiskManager.INTENT_LINK);
|
||||
|
||||
LoadModules loadModuleTask = new LoadModules(this);
|
||||
|
||||
if (Utils.checkNetworkStatus(this)) {
|
||||
// Initialize the update check service, notify every 8 hours
|
||||
if (!TextUtils.equals("install", getIntent().getStringExtra(MagiskManager.INTENT_SECTION))) {
|
||||
ComponentName service = new ComponentName(this, UpdateCheckService.class);
|
||||
JobInfo jobInfo = new JobInfo.Builder(UPDATE_SERVICE_ID, service)
|
||||
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
|
||||
.setPersisted(true)
|
||||
.setPeriodic(8 * 60 * 60 * 1000)
|
||||
.build();
|
||||
((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo);
|
||||
}
|
||||
loadModuleTask.setCallBack(() -> new UpdateRepos(getApplication()).exec());
|
||||
}
|
||||
|
||||
loadModuleTask.exec();
|
||||
getApplicationContext().startup();
|
||||
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
String section = getIntent().getStringExtra(MagiskManager.INTENT_SECTION);
|
||||
|
@ -201,9 +201,7 @@ public class Utils {
|
||||
.setVibrate(new long[]{0, 100, 100, 100})
|
||||
.setAutoCancel(true);
|
||||
Intent intent = new Intent(magiskManager, SplashActivity.class);
|
||||
intent.putExtra(MagiskManager.INTENT_SECTION, "install");
|
||||
intent.putExtra(MagiskManager.INTENT_VERSION, magiskManager.remoteMagiskVersionString);
|
||||
intent.putExtra(MagiskManager.INTENT_LINK, magiskManager.magiskLink);
|
||||
intent.putExtra(MagiskManager.INTENT_SECTION, "magisk");
|
||||
TaskStackBuilder stackBuilder = TaskStackBuilder.create(magiskManager);
|
||||
stackBuilder.addParentStack(SplashActivity.class);
|
||||
stackBuilder.addNextIntent(intent);
|
||||
|
Loading…
Reference in New Issue
Block a user