Magisk/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java

88 lines
2.9 KiB
Java
Raw Normal View History

package com.topjohnwu.magisk;
2017-11-06 04:47:24 +08:00
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Intent;
2017-11-06 04:47:24 +08:00
import android.os.Build;
import android.os.Bundle;
2017-11-06 04:47:24 +08:00
import com.topjohnwu.magisk.asyncs.CheckUpdates;
import com.topjohnwu.magisk.asyncs.LoadModules;
import com.topjohnwu.magisk.asyncs.ParallelTask;
import com.topjohnwu.magisk.asyncs.UpdateRepos;
2017-02-07 02:01:32 +08:00
import com.topjohnwu.magisk.components.Activity;
2018-04-08 01:05:01 +08:00
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
2018-04-07 00:45:10 +08:00
import com.topjohnwu.magisk.receivers.ShortcutReceiver;
2017-11-06 04:41:23 +08:00
import com.topjohnwu.magisk.utils.Const;
2018-07-30 20:37:00 +08:00
import com.topjohnwu.magisk.utils.Download;
2017-11-06 04:47:24 +08:00
import com.topjohnwu.magisk.utils.Utils;
2018-01-21 06:07:24 +08:00
import com.topjohnwu.superuser.Shell;
2017-11-06 04:47:24 +08:00
2017-08-30 02:28:24 +08:00
public class SplashActivity extends Activity {
2016-10-31 11:13:48 +08:00
@Override
protected void onCreate(Bundle savedInstanceState) {
2016-09-26 13:16:11 -05:00
super.onCreate(savedInstanceState);
2017-11-06 04:47:24 +08:00
MagiskManager mm = getMagiskManager();
2018-04-08 01:05:01 +08:00
mm.repoDB = new RepoDatabaseHelper(this);
2017-12-20 12:14:46 +08:00
mm.loadMagiskInfo();
mm.getDefaultInstallFlags();
2018-06-02 22:00:52 +08:00
mm.loadPrefs();
2017-12-20 12:14:46 +08:00
2017-11-06 04:47:24 +08:00
// Dynamic detect all locales
new LoadLocale().exec();
// Create notification channel on Android O
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(Const.ID.NOTIFICATION_CHANNEL,
getString(R.string.magisk_updates), NotificationManager.IMPORTANCE_DEFAULT);
getSystemService(NotificationManager.class).createNotificationChannel(channel);
}
2018-04-07 00:45:10 +08:00
// Setup shortcuts
sendBroadcast(new Intent(this, ShortcutReceiver.class));
2017-11-06 04:47:24 +08:00
LoadModules loadModuleTask = new LoadModules();
2018-07-30 20:37:00 +08:00
if (Download.checkNetworkStatus(this)) {
2017-11-06 04:47:24 +08:00
// Fire update check
new CheckUpdates().exec();
// Add repo update check
loadModuleTask.setCallBack(() -> new UpdateRepos(false).exec());
}
// Magisk working as expected
if (Shell.rootAccess() && mm.magiskVersionCode > 0) {
2018-02-20 00:39:17 +08:00
// Update check service
mm.setupUpdateCheck();
2017-11-06 04:47:24 +08:00
// Fire asynctasks
loadModuleTask.exec();
}
// Write back default values
2017-12-27 01:07:33 +08:00
mm.writeConfig();
2017-11-06 04:47:24 +08:00
mm.hasInit = true;
2017-07-20 02:54:34 +08:00
Intent intent = new Intent(this, MainActivity.class);
2017-11-06 05:36:20 +08:00
intent.putExtra(Const.Key.OPEN_SECTION, getIntent().getStringExtra(Const.Key.OPEN_SECTION));
2018-07-30 20:37:00 +08:00
intent.putExtra(Activity.INTENT_PERM, getIntent().getStringExtra(Activity.INTENT_PERM));
2017-05-23 16:51:23 +08:00
startActivity(intent);
finish();
}
2017-11-06 04:47:24 +08:00
static class LoadLocale extends ParallelTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... voids) {
MagiskManager.get().locales = Utils.getAvailableLocale();
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
MagiskManager.get().localeDone.publish();
}
}
}