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

77 lines
2.6 KiB
Java
Raw Normal View History

package com.topjohnwu.magisk;
import android.content.Intent;
2018-10-28 00:54:56 -04:00
import android.content.pm.PackageManager;
import android.os.Bundle;
2018-10-28 00:54:56 -04:00
import android.text.TextUtils;
2019-01-21 15:49:03 -05:00
import com.topjohnwu.core.Config;
import com.topjohnwu.core.Const;
import com.topjohnwu.core.tasks.CheckUpdates;
import com.topjohnwu.core.tasks.UpdateRepos;
import com.topjohnwu.core.utils.LocaleManager;
import com.topjohnwu.core.utils.Utils;
2018-08-01 17:57:11 +08:00
import com.topjohnwu.magisk.components.BaseActivity;
2018-12-03 01:44:13 -05:00
import com.topjohnwu.magisk.components.Notifications;
2018-09-16 00:08:13 -04:00
import com.topjohnwu.magisk.receivers.ShortcutReceiver;
import com.topjohnwu.magisk.utils.AppUtils;
2018-12-27 14:35:55 +08:00
import com.topjohnwu.net.Networking;
2018-01-21 06:07:24 +08:00
import com.topjohnwu.superuser.Shell;
2017-11-06 04:47:24 +08:00
2018-08-01 17:57:11 +08:00
public class SplashActivity extends BaseActivity {
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);
2018-12-13 05:53:39 -05:00
// Dynamic detect all locales
LocaleManager.loadAvailableLocales(R.string.app_changelog);
2019-01-21 15:49:03 -05:00
String pkg = Config.get(Config.Key.SU_MANAGER);
2018-12-02 15:28:18 -05:00
if (pkg != null && getPackageName().equals(BuildConfig.APPLICATION_ID)) {
2019-01-21 15:49:03 -05:00
Config.remove(Config.Key.SU_MANAGER);
2018-10-28 00:54:56 -04:00
Shell.su("pm uninstall " + pkg).exec();
}
if (TextUtils.equals(pkg, getPackageName())) {
try {
// We are the manager, remove com.topjohnwu.magisk as it could be malware
2018-12-02 15:28:18 -05:00
getPackageManager().getApplicationInfo(BuildConfig.APPLICATION_ID, 0);
Shell.su("pm uninstall " + BuildConfig.APPLICATION_ID).submit();
2018-10-28 00:54:56 -04:00
} catch (PackageManager.NameNotFoundException ignored) {}
}
2018-08-02 00:41:10 +08:00
// Magisk working as expected
2019-01-21 15:49:03 -05:00
if (Shell.rootAccess() && Config.magiskVersionCode > 0) {
2018-08-02 00:41:10 +08:00
// Load modules
Utils.loadModules();
}
2017-11-06 04:47:24 +08:00
2019-01-21 15:49:03 -05:00
// Set default configs
Config.initialize();
2017-12-20 12:14:46 +08:00
2017-11-06 04:47:24 +08:00
// Create notification channel on Android O
2018-12-02 15:15:42 -05:00
Notifications.setup(this);
2017-11-06 04:47:24 +08:00
2018-12-27 22:07:47 +08:00
// Schedule periodic update checks
AppUtils.scheduleUpdateCheck();
2018-04-07 00:45:10 +08:00
// Setup shortcuts
sendBroadcast(new Intent(this, ClassMap.get(ShortcutReceiver.class)));
2018-04-07 00:45:10 +08:00
2018-12-27 14:35:55 +08:00
if (Networking.checkNetworkStatus(this)) {
2017-11-06 04:47:24 +08:00
// Fire update check
2018-08-02 00:41:10 +08:00
CheckUpdates.check();
// Repo update check
new UpdateRepos().exec();
2017-11-06 04:47:24 +08:00
}
app.init = true;
2017-07-20 02:54:34 +08:00
Intent intent = new Intent(this, ClassMap.get(MainActivity.class));
2017-11-06 05:36:20 +08:00
intent.putExtra(Const.Key.OPEN_SECTION, getIntent().getStringExtra(Const.Key.OPEN_SECTION));
2018-08-01 17:57:11 +08:00
intent.putExtra(BaseActivity.INTENT_PERM, getIntent().getStringExtra(BaseActivity.INTENT_PERM));
2017-05-23 16:51:23 +08:00
startActivity(intent);
finish();
}
}