mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-30 21:45: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;
|
final String finalBootImage = bootImage;
|
||||||
String filename = "Magisk-v" + magiskManager.remoteMagiskVersionString + ".zip";
|
String filename = "Magisk-v" + magiskManager.remoteMagiskVersionString + ".zip";
|
||||||
new AlertDialogBuilder(getActivity())
|
new AlertDialogBuilder(getActivity())
|
||||||
@ -129,9 +130,7 @@ public class MagiskFragment extends Fragment
|
|||||||
.setMessage(getString(R.string.repo_install_msg, filename))
|
.setMessage(getString(R.string.repo_install_msg, filename))
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.setPositiveButton(Shell.rootAccess() ? R.string.install : R.string.download,
|
.setPositiveButton(Shell.rootAccess() ? R.string.install : R.string.download,
|
||||||
(d, i) -> {
|
(d, i) ->
|
||||||
((NotificationManager) getActivity()
|
|
||||||
.getSystemService(Context.NOTIFICATION_SERVICE)).cancelAll();
|
|
||||||
Utils.dlAndReceive(
|
Utils.dlAndReceive(
|
||||||
getActivity(),
|
getActivity(),
|
||||||
new DownloadReceiver() {
|
new DownloadReceiver() {
|
||||||
@ -155,8 +154,7 @@ public class MagiskFragment extends Fragment
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
magiskManager.magiskLink,
|
magiskManager.magiskLink,
|
||||||
Utils.getLegalFilename(filename));
|
Utils.getLegalFilename(filename))
|
||||||
}
|
|
||||||
)
|
)
|
||||||
.setNeutralButton(R.string.release_notes, (d, i) -> {
|
.setNeutralButton(R.string.release_notes, (d, i) -> {
|
||||||
if (magiskManager.releaseNoteLink != null) {
|
if (magiskManager.releaseNoteLink != null) {
|
||||||
@ -226,20 +224,16 @@ public class MagiskFragment extends Fragment
|
|||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
View v = inflater.inflate(R.layout.fragment_magisk, container, false);
|
View v = inflater.inflate(R.layout.fragment_magisk, container, false);
|
||||||
unbinder = ButterKnife.bind(this, v);
|
unbinder = ButterKnife.bind(this, v);
|
||||||
|
getActivity().setTitle(R.string.magisk);
|
||||||
|
|
||||||
magiskManager = getApplication();
|
magiskManager = getApplication();
|
||||||
|
|
||||||
expandableContainer.expandLayout = expandLayout;
|
expandableContainer.expandLayout = expandLayout;
|
||||||
setupExpandable();
|
setupExpandable();
|
||||||
|
|
||||||
mSwipeRefreshLayout.setOnRefreshListener(this);
|
mSwipeRefreshLayout.setOnRefreshListener(this);
|
||||||
|
|
||||||
updateUI();
|
updateUI();
|
||||||
|
|
||||||
if (getArguments() != null && getArguments().getBoolean(SHOW_DIALOG))
|
|
||||||
install();
|
|
||||||
|
|
||||||
getActivity().setTitle(R.string.magisk);
|
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,9 @@ package com.topjohnwu.magisk;
|
|||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
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.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
@ -14,10 +17,13 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import com.topjohnwu.magisk.asyncs.CheckUpdates;
|
import com.topjohnwu.magisk.asyncs.CheckUpdates;
|
||||||
import com.topjohnwu.magisk.asyncs.DownloadBusybox;
|
import com.topjohnwu.magisk.asyncs.DownloadBusybox;
|
||||||
|
import com.topjohnwu.magisk.asyncs.LoadModules;
|
||||||
import com.topjohnwu.magisk.asyncs.ParallelTask;
|
import com.topjohnwu.magisk.asyncs.ParallelTask;
|
||||||
|
import com.topjohnwu.magisk.asyncs.UpdateRepos;
|
||||||
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
||||||
import com.topjohnwu.magisk.database.SuDatabaseHelper;
|
import com.topjohnwu.magisk.database.SuDatabaseHelper;
|
||||||
import com.topjohnwu.magisk.module.Module;
|
import com.topjohnwu.magisk.module.Module;
|
||||||
|
import com.topjohnwu.magisk.services.UpdateCheckService;
|
||||||
import com.topjohnwu.magisk.superuser.SuReceiver;
|
import com.topjohnwu.magisk.superuser.SuReceiver;
|
||||||
import com.topjohnwu.magisk.superuser.SuRequestActivity;
|
import com.topjohnwu.magisk.superuser.SuRequestActivity;
|
||||||
import com.topjohnwu.magisk.utils.SafetyNetHelper;
|
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 DISABLE_INDICATION_PROP = "ro.magisk.disable";
|
||||||
public static final String NOTIFICATION_CHANNEL = "magisk_update_notice";
|
public static final String NOTIFICATION_CHANNEL = "magisk_update_notice";
|
||||||
public static final String BUSYBOX_VERSION = "1.27.1";
|
public static final String BUSYBOX_VERSION = "1.27.1";
|
||||||
|
public static final int UPDATE_SERVICE_ID = 1;
|
||||||
|
|
||||||
// Topics
|
// Topics
|
||||||
public final Topic magiskHideDone = new Topic();
|
public final Topic magiskHideDone = new Topic();
|
||||||
@ -100,6 +107,7 @@ public class MagiskManager extends Application {
|
|||||||
public Shell shell;
|
public Shell shell;
|
||||||
|
|
||||||
private static Handler mHandler = new Handler();
|
private static Handler mHandler = new Handler();
|
||||||
|
private boolean startup = false;
|
||||||
|
|
||||||
private static class LoadLocale extends ParallelTask<Void, Void, Void> {
|
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());
|
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 LoadLocale(this).exec();
|
||||||
new DownloadBusybox(this).exec();
|
new DownloadBusybox(this).exec();
|
||||||
getMagiskInfo();
|
getMagiskInfo();
|
||||||
@ -212,10 +225,24 @@ public class MagiskManager extends Application {
|
|||||||
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(channel);
|
((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() {
|
public void getMagiskInfo() {
|
||||||
Shell.getShell(this);
|
|
||||||
List<String> ret;
|
List<String> ret;
|
||||||
ret = shell.sh("su -v");
|
ret = shell.sh("su -v");
|
||||||
if (Utils.isValidShellResponse(ret)) {
|
if (Utils.isValidShellResponse(ret)) {
|
||||||
|
@ -38,6 +38,7 @@ public class MainActivity extends Activity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(final Bundle savedInstanceState) {
|
protected void onCreate(final Bundle savedInstanceState) {
|
||||||
|
getApplicationContext().startup();
|
||||||
|
|
||||||
prefs = getApplicationContext().prefs;
|
prefs = getApplicationContext().prefs;
|
||||||
|
|
||||||
@ -131,9 +132,6 @@ public class MainActivity extends Activity
|
|||||||
case "magisk":
|
case "magisk":
|
||||||
itemId = R.id.magisk;
|
itemId = R.id.magisk;
|
||||||
break;
|
break;
|
||||||
case "install":
|
|
||||||
itemId = -1;
|
|
||||||
break;
|
|
||||||
case "superuser":
|
case "superuser":
|
||||||
itemId = R.id.superuser;
|
itemId = R.id.superuser;
|
||||||
break;
|
break;
|
||||||
@ -165,13 +163,6 @@ public class MainActivity extends Activity
|
|||||||
mDrawerItem = itemId;
|
mDrawerItem = itemId;
|
||||||
navigationView.setCheckedItem(itemId);
|
navigationView.setCheckedItem(itemId);
|
||||||
switch (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:
|
case R.id.magisk:
|
||||||
displayFragment(new MagiskFragment(), "magisk", true);
|
displayFragment(new MagiskFragment(), "magisk", true);
|
||||||
break;
|
break;
|
||||||
|
@ -1,54 +1,17 @@
|
|||||||
package com.topjohnwu.magisk;
|
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.content.Intent;
|
||||||
import android.os.Bundle;
|
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.components.Activity;
|
||||||
import com.topjohnwu.magisk.services.UpdateCheckService;
|
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
|
|
||||||
public class SplashActivity extends Activity{
|
public class SplashActivity extends Activity {
|
||||||
|
|
||||||
private static final int UPDATE_SERVICE_ID = 1;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
MagiskManager magiskManager = getApplicationContext();
|
getApplicationContext().startup();
|
||||||
|
|
||||||
// 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();
|
|
||||||
|
|
||||||
Intent intent = new Intent(this, MainActivity.class);
|
Intent intent = new Intent(this, MainActivity.class);
|
||||||
String section = getIntent().getStringExtra(MagiskManager.INTENT_SECTION);
|
String section = getIntent().getStringExtra(MagiskManager.INTENT_SECTION);
|
||||||
|
@ -201,9 +201,7 @@ public class Utils {
|
|||||||
.setVibrate(new long[]{0, 100, 100, 100})
|
.setVibrate(new long[]{0, 100, 100, 100})
|
||||||
.setAutoCancel(true);
|
.setAutoCancel(true);
|
||||||
Intent intent = new Intent(magiskManager, SplashActivity.class);
|
Intent intent = new Intent(magiskManager, SplashActivity.class);
|
||||||
intent.putExtra(MagiskManager.INTENT_SECTION, "install");
|
intent.putExtra(MagiskManager.INTENT_SECTION, "magisk");
|
||||||
intent.putExtra(MagiskManager.INTENT_VERSION, magiskManager.remoteMagiskVersionString);
|
|
||||||
intent.putExtra(MagiskManager.INTENT_LINK, magiskManager.magiskLink);
|
|
||||||
TaskStackBuilder stackBuilder = TaskStackBuilder.create(magiskManager);
|
TaskStackBuilder stackBuilder = TaskStackBuilder.create(magiskManager);
|
||||||
stackBuilder.addParentStack(SplashActivity.class);
|
stackBuilder.addParentStack(SplashActivity.class);
|
||||||
stackBuilder.addNextIntent(intent);
|
stackBuilder.addNextIntent(intent);
|
||||||
|
Loading…
Reference in New Issue
Block a user