mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-24 10:35:26 +00:00
Updated splash screen with new arch
This commit is contained in:
parent
7cc8c014eb
commit
11d716a3c8
@ -19,6 +19,7 @@ import com.topjohnwu.magisk.utils.LocaleManager
|
|||||||
import com.topjohnwu.magisk.utils.RootUtils
|
import com.topjohnwu.magisk.utils.RootUtils
|
||||||
import com.topjohnwu.net.Networking
|
import com.topjohnwu.net.Networking
|
||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
|
import org.koin.android.ext.android.inject
|
||||||
import org.koin.android.ext.koin.androidContext
|
import org.koin.android.ext.koin.androidContext
|
||||||
import org.koin.core.context.startKoin
|
import org.koin.core.context.startKoin
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
@ -29,8 +30,8 @@ open class App : Application(), Application.ActivityLifecycleCallbacks {
|
|||||||
// Global resources
|
// Global resources
|
||||||
val prefs: SharedPreferences get() = PreferenceManager.getDefaultSharedPreferences(deContext)
|
val prefs: SharedPreferences get() = PreferenceManager.getDefaultSharedPreferences(deContext)
|
||||||
val DB: MagiskDB by lazy { MagiskDB(deContext) }
|
val DB: MagiskDB by lazy { MagiskDB(deContext) }
|
||||||
@JvmField
|
@Deprecated("Use dependency injection")
|
||||||
var repoDB: RepoDatabaseHelper? = null
|
val repoDB: RepoDatabaseHelper by inject()
|
||||||
@Volatile
|
@Volatile
|
||||||
private var foreground: Activity? = null
|
private var foreground: Activity? = null
|
||||||
|
|
||||||
@ -94,11 +95,13 @@ open class App : Application(), Application.ActivityLifecycleCallbacks {
|
|||||||
|
|
||||||
//fixme this should be at least weak reference, me no likey
|
//fixme this should be at least weak reference, me no likey
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
|
@Deprecated("Use dependency injection")
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
lateinit var self: App
|
lateinit var self: App
|
||||||
|
|
||||||
//fixme this should be at least weak reference, me no likey
|
//fixme this should be at least weak reference, me no likey
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
|
@Deprecated("Use dependency injection")
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
lateinit var deContext: Context
|
lateinit var deContext: Context
|
||||||
|
|
||||||
@ -116,6 +119,7 @@ open class App : Application(), Application.ActivityLifecycleCallbacks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//fixme me no likey
|
//fixme me no likey
|
||||||
|
@Deprecated("")
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun foreground(): Activity? {
|
fun foreground(): Activity? {
|
||||||
return self.foreground
|
return self.foreground
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package com.topjohnwu.magisk.di
|
package com.topjohnwu.magisk.di
|
||||||
|
|
||||||
import com.topjohnwu.magisk.App
|
import com.topjohnwu.magisk.App
|
||||||
|
import com.topjohnwu.magisk.data.database.RepoDatabaseHelper
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
|
||||||
val databaseModule = module {
|
val databaseModule = module {
|
||||||
single { get<App>().DB }
|
single { get<App>().DB }
|
||||||
single { get<App>().repoDB }
|
single { RepoDatabaseHelper(get()) }
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,6 @@ import android.widget.ImageView;
|
|||||||
import android.widget.SearchView;
|
import android.widget.SearchView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.App;
|
import com.topjohnwu.magisk.App;
|
||||||
import com.topjohnwu.magisk.ClassMap;
|
import com.topjohnwu.magisk.ClassMap;
|
||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
@ -33,6 +31,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import java9.util.stream.StreamSupport;
|
import java9.util.stream.StreamSupport;
|
||||||
|
|
||||||
@ -51,7 +50,7 @@ public class ReposAdapter
|
|||||||
private SearchView mSearch;
|
private SearchView mSearch;
|
||||||
|
|
||||||
public ReposAdapter() {
|
public ReposAdapter() {
|
||||||
repoDB = App.self.repoDB;
|
repoDB = App.self.getRepoDB();
|
||||||
moduleMap = Collections.emptyMap();
|
moduleMap = Collections.emptyMap();
|
||||||
fullList = Collections.emptyList();
|
fullList = Collections.emptyList();
|
||||||
repoPairs = new ArrayList<>();
|
repoPairs = new ArrayList<>();
|
||||||
|
@ -34,7 +34,7 @@ import java.util.concurrent.Future;
|
|||||||
public class UpdateRepos {
|
public class UpdateRepos {
|
||||||
private static final DateFormat DATE_FORMAT;
|
private static final DateFormat DATE_FORMAT;
|
||||||
|
|
||||||
private App app = App.self;
|
private final App app = App.self;
|
||||||
private Set<String> cached;
|
private Set<String> cached;
|
||||||
private Queue<Pair<String, Date>> moduleQueue;
|
private Queue<Pair<String, Date>> moduleQueue;
|
||||||
|
|
||||||
@ -116,17 +116,17 @@ public class UpdateRepos {
|
|||||||
Pair<String, Date> pair = moduleQueue.poll();
|
Pair<String, Date> pair = moduleQueue.poll();
|
||||||
if (pair == null)
|
if (pair == null)
|
||||||
return;
|
return;
|
||||||
Repo repo = app.repoDB.getRepo(pair.first);
|
Repo repo = app.getRepoDB().getRepo(pair.first);
|
||||||
try {
|
try {
|
||||||
if (repo == null)
|
if (repo == null)
|
||||||
repo = new Repo(pair.first);
|
repo = new Repo(pair.first);
|
||||||
else
|
else
|
||||||
cached.remove(pair.first);
|
cached.remove(pair.first);
|
||||||
repo.update(pair.second);
|
repo.update(pair.second);
|
||||||
app.repoDB.addRepo(repo);
|
app.getRepoDB().addRepo(repo);
|
||||||
} catch (Repo.IllegalRepoException e) {
|
} catch (Repo.IllegalRepoException e) {
|
||||||
Logger.debug(e.getMessage());
|
Logger.debug(e.getMessage());
|
||||||
app.repoDB.removeRepo(pair.first);
|
app.getRepoDB().removeRepo(pair.first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -134,7 +134,7 @@ public class UpdateRepos {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void fullReload() {
|
private void fullReload() {
|
||||||
Cursor c = app.repoDB.getRawCursor();
|
Cursor c = app.getRepoDB().getRawCursor();
|
||||||
runTasks(() -> {
|
runTasks(() -> {
|
||||||
while (true) {
|
while (true) {
|
||||||
Repo repo;
|
Repo repo;
|
||||||
@ -145,10 +145,10 @@ public class UpdateRepos {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
repo.update();
|
repo.update();
|
||||||
app.repoDB.addRepo(repo);
|
app.getRepoDB().addRepo(repo);
|
||||||
} catch (Repo.IllegalRepoException e) {
|
} catch (Repo.IllegalRepoException e) {
|
||||||
Logger.debug(e.getMessage());
|
Logger.debug(e.getMessage());
|
||||||
app.repoDB.removeRepo(repo);
|
app.getRepoDB().removeRepo(repo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -157,12 +157,12 @@ public class UpdateRepos {
|
|||||||
public void exec(boolean force) {
|
public void exec(boolean force) {
|
||||||
Event.reset(Event.REPO_LOAD_DONE);
|
Event.reset(Event.REPO_LOAD_DONE);
|
||||||
App.THREAD_POOL.execute(() -> {
|
App.THREAD_POOL.execute(() -> {
|
||||||
cached = Collections.synchronizedSet(app.repoDB.getRepoIDSet());
|
cached = Collections.synchronizedSet(app.getRepoDB().getRepoIDSet());
|
||||||
moduleQueue = new ConcurrentLinkedQueue<>();
|
moduleQueue = new ConcurrentLinkedQueue<>();
|
||||||
|
|
||||||
if (loadPages()) {
|
if (loadPages()) {
|
||||||
// The leftover cached means they are removed from online repo
|
// The leftover cached means they are removed from online repo
|
||||||
app.repoDB.removeRepo(cached);
|
app.getRepoDB().removeRepo(cached);
|
||||||
} else if (force) {
|
} else if (force) {
|
||||||
fullReload();
|
fullReload();
|
||||||
}
|
}
|
||||||
|
@ -1,97 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.ui;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.BuildConfig;
|
|
||||||
import com.topjohnwu.magisk.ClassMap;
|
|
||||||
import com.topjohnwu.magisk.Config;
|
|
||||||
import com.topjohnwu.magisk.Const;
|
|
||||||
import com.topjohnwu.magisk.R;
|
|
||||||
import com.topjohnwu.magisk.data.database.RepoDatabaseHelper;
|
|
||||||
import com.topjohnwu.magisk.tasks.CheckUpdates;
|
|
||||||
import com.topjohnwu.magisk.tasks.UpdateRepos;
|
|
||||||
import com.topjohnwu.magisk.ui.base.BaseActivity;
|
|
||||||
import com.topjohnwu.magisk.utils.LocaleManager;
|
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
import com.topjohnwu.magisk.view.Notifications;
|
|
||||||
import com.topjohnwu.magisk.view.Shortcuts;
|
|
||||||
import com.topjohnwu.net.Networking;
|
|
||||||
import com.topjohnwu.superuser.Shell;
|
|
||||||
|
|
||||||
public class SplashActivity extends BaseActivity {
|
|
||||||
|
|
||||||
public static boolean DONE = false;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
Shell.getShell(shell -> {
|
|
||||||
if (Config.magiskVersionCode > 0 &&
|
|
||||||
Config.magiskVersionCode < Const.MAGISK_VER.MIN_SUPPORT) {
|
|
||||||
new AlertDialog.Builder(this)
|
|
||||||
.setTitle(R.string.unsupport_magisk_title)
|
|
||||||
.setMessage(R.string.unsupport_magisk_message)
|
|
||||||
.setNegativeButton(R.string.ok, null)
|
|
||||||
.setOnDismissListener(dialog -> finish())
|
|
||||||
.show();
|
|
||||||
} else {
|
|
||||||
initAndStart();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initAndStart() {
|
|
||||||
String pkg = Config.get(Config.Key.SU_MANAGER);
|
|
||||||
if (pkg != null && getPackageName().equals(BuildConfig.APPLICATION_ID)) {
|
|
||||||
Config.remove(Config.Key.SU_MANAGER);
|
|
||||||
Shell.su("pm uninstall " + pkg).submit();
|
|
||||||
}
|
|
||||||
if (TextUtils.equals(pkg, getPackageName())) {
|
|
||||||
try {
|
|
||||||
// We are the manager, remove com.topjohnwu.magisk as it could be malware
|
|
||||||
getPackageManager().getApplicationInfo(BuildConfig.APPLICATION_ID, 0);
|
|
||||||
Shell.su("pm uninstall " + BuildConfig.APPLICATION_ID).submit();
|
|
||||||
} catch (PackageManager.NameNotFoundException ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dynamic detect all locales
|
|
||||||
LocaleManager.loadAvailableLocales(R.string.app_changelog);
|
|
||||||
|
|
||||||
// Set default configs
|
|
||||||
Config.initialize();
|
|
||||||
|
|
||||||
// Create notification channel on Android O
|
|
||||||
Notifications.setup(this);
|
|
||||||
|
|
||||||
// Schedule periodic update checks
|
|
||||||
Utils.scheduleUpdateCheck();
|
|
||||||
CheckUpdates.check();
|
|
||||||
|
|
||||||
// Setup shortcuts
|
|
||||||
Shortcuts.setup(this);
|
|
||||||
|
|
||||||
// Create repo database
|
|
||||||
app.repoDB = new RepoDatabaseHelper(this);
|
|
||||||
|
|
||||||
// Magisk working as expected
|
|
||||||
if (Shell.rootAccess() && Config.magiskVersionCode > 0) {
|
|
||||||
// Load modules
|
|
||||||
Utils.loadModules(false);
|
|
||||||
// Load repos
|
|
||||||
if (Networking.checkNetworkStatus(this))
|
|
||||||
new UpdateRepos().exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
Intent intent = new Intent(this, ClassMap.get(MainActivity.class));
|
|
||||||
intent.putExtra(Const.Key.OPEN_SECTION, getIntent().getStringExtra(Const.Key.OPEN_SECTION));
|
|
||||||
DONE = true;
|
|
||||||
startActivity(intent);
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
|
87
app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt
Normal file
87
app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
package com.topjohnwu.magisk.ui
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.text.TextUtils
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import com.topjohnwu.magisk.*
|
||||||
|
import com.topjohnwu.magisk.tasks.CheckUpdates
|
||||||
|
import com.topjohnwu.magisk.tasks.UpdateRepos
|
||||||
|
import com.topjohnwu.magisk.utils.LocaleManager
|
||||||
|
import com.topjohnwu.magisk.utils.Utils
|
||||||
|
import com.topjohnwu.magisk.view.Notifications
|
||||||
|
import com.topjohnwu.magisk.view.Shortcuts
|
||||||
|
import com.topjohnwu.net.Networking
|
||||||
|
import com.topjohnwu.superuser.Shell
|
||||||
|
|
||||||
|
open class SplashActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
Shell.getShell {
|
||||||
|
if (Config.magiskVersionCode > 0 && Config.magiskVersionCode < Const.MAGISK_VER.MIN_SUPPORT) {
|
||||||
|
AlertDialog.Builder(this)
|
||||||
|
.setTitle(R.string.unsupport_magisk_title)
|
||||||
|
.setMessage(R.string.unsupport_magisk_message)
|
||||||
|
.setNegativeButton(R.string.ok, null)
|
||||||
|
.setOnDismissListener { finish() }
|
||||||
|
.show()
|
||||||
|
} else {
|
||||||
|
initAndStart()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initAndStart() {
|
||||||
|
val pkg = Config.get<String>(Config.Key.SU_MANAGER)
|
||||||
|
if (pkg != null && packageName == BuildConfig.APPLICATION_ID) {
|
||||||
|
Config.remove(Config.Key.SU_MANAGER)
|
||||||
|
Shell.su("pm uninstall $pkg").submit()
|
||||||
|
}
|
||||||
|
if (TextUtils.equals(pkg, packageName)) {
|
||||||
|
runCatching {
|
||||||
|
// We are the manager, remove com.topjohnwu.magisk as it could be malware
|
||||||
|
packageManager.getApplicationInfo(BuildConfig.APPLICATION_ID, 0)
|
||||||
|
Shell.su("pm uninstall " + BuildConfig.APPLICATION_ID).submit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dynamic detect all locales
|
||||||
|
LocaleManager.loadAvailableLocales(R.string.app_changelog)
|
||||||
|
|
||||||
|
// Set default configs
|
||||||
|
Config.initialize()
|
||||||
|
|
||||||
|
// Create notification channel on Android O
|
||||||
|
Notifications.setup(this)
|
||||||
|
|
||||||
|
// Schedule periodic update checks
|
||||||
|
Utils.scheduleUpdateCheck()
|
||||||
|
CheckUpdates.check()
|
||||||
|
|
||||||
|
// Setup shortcuts
|
||||||
|
Shortcuts.setup(this)
|
||||||
|
|
||||||
|
// Magisk working as expected
|
||||||
|
if (Shell.rootAccess() && Config.magiskVersionCode > 0) {
|
||||||
|
// Load modules
|
||||||
|
Utils.loadModules(false)
|
||||||
|
// Load repos
|
||||||
|
if (Networking.checkNetworkStatus(this))
|
||||||
|
UpdateRepos().exec()
|
||||||
|
}
|
||||||
|
|
||||||
|
val intent = Intent(this, ClassMap.get<Any>(MainActivity::class.java))
|
||||||
|
intent.putExtra(Const.Key.OPEN_SECTION, getIntent().getStringExtra(Const.Key.OPEN_SECTION))
|
||||||
|
DONE = true
|
||||||
|
startActivity(intent)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
var DONE = false
|
||||||
|
}
|
||||||
|
}
|
@ -74,7 +74,7 @@ public class SettingsFragment extends BasePreferenceFragment {
|
|||||||
});
|
});
|
||||||
findPreference("clear").setOnPreferenceClickListener(pref -> {
|
findPreference("clear").setOnPreferenceClickListener(pref -> {
|
||||||
app.getPrefs().edit().remove(Config.Key.ETAG_KEY).apply();
|
app.getPrefs().edit().remove(Config.Key.ETAG_KEY).apply();
|
||||||
app.repoDB.clearRepo();
|
app.getRepoDB().clearRepo();
|
||||||
Utils.toast(R.string.repo_cache_cleared, Toast.LENGTH_SHORT);
|
Utils.toast(R.string.repo_cache_cleared, Toast.LENGTH_SHORT);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user