Updated splash screen with new arch

This commit is contained in:
Viktor De Pasquale 2019-04-22 16:00:48 +02:00
parent 7cc8c014eb
commit 11d716a3c8
7 changed files with 107 additions and 113 deletions

View File

@ -19,6 +19,7 @@ import com.topjohnwu.magisk.utils.LocaleManager
import com.topjohnwu.magisk.utils.RootUtils
import com.topjohnwu.net.Networking
import com.topjohnwu.superuser.Shell
import org.koin.android.ext.android.inject
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin
import timber.log.Timber
@ -29,8 +30,8 @@ open class App : Application(), Application.ActivityLifecycleCallbacks {
// Global resources
val prefs: SharedPreferences get() = PreferenceManager.getDefaultSharedPreferences(deContext)
val DB: MagiskDB by lazy { MagiskDB(deContext) }
@JvmField
var repoDB: RepoDatabaseHelper? = null
@Deprecated("Use dependency injection")
val repoDB: RepoDatabaseHelper by inject()
@Volatile
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
@SuppressLint("StaticFieldLeak")
@Deprecated("Use dependency injection")
@JvmStatic
lateinit var self: App
//fixme this should be at least weak reference, me no likey
@SuppressLint("StaticFieldLeak")
@Deprecated("Use dependency injection")
@JvmStatic
lateinit var deContext: Context
@ -116,6 +119,7 @@ open class App : Application(), Application.ActivityLifecycleCallbacks {
}
//fixme me no likey
@Deprecated("")
@JvmStatic
fun foreground(): Activity? {
return self.foreground

View File

@ -1,10 +1,11 @@
package com.topjohnwu.magisk.di
import com.topjohnwu.magisk.App
import com.topjohnwu.magisk.data.database.RepoDatabaseHelper
import org.koin.dsl.module
val databaseModule = module {
single { get<App>().DB }
single { get<App>().repoDB }
single { RepoDatabaseHelper(get()) }
}

View File

@ -13,8 +13,6 @@ import android.widget.ImageView;
import android.widget.SearchView;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import com.topjohnwu.magisk.App;
import com.topjohnwu.magisk.ClassMap;
import com.topjohnwu.magisk.R;
@ -33,6 +31,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import java9.util.stream.StreamSupport;
@ -51,7 +50,7 @@ public class ReposAdapter
private SearchView mSearch;
public ReposAdapter() {
repoDB = App.self.repoDB;
repoDB = App.self.getRepoDB();
moduleMap = Collections.emptyMap();
fullList = Collections.emptyList();
repoPairs = new ArrayList<>();

View File

@ -34,7 +34,7 @@ import java.util.concurrent.Future;
public class UpdateRepos {
private static final DateFormat DATE_FORMAT;
private App app = App.self;
private final App app = App.self;
private Set<String> cached;
private Queue<Pair<String, Date>> moduleQueue;
@ -116,17 +116,17 @@ public class UpdateRepos {
Pair<String, Date> pair = moduleQueue.poll();
if (pair == null)
return;
Repo repo = app.repoDB.getRepo(pair.first);
Repo repo = app.getRepoDB().getRepo(pair.first);
try {
if (repo == null)
repo = new Repo(pair.first);
else
cached.remove(pair.first);
repo.update(pair.second);
app.repoDB.addRepo(repo);
app.getRepoDB().addRepo(repo);
} catch (Repo.IllegalRepoException e) {
Logger.debug(e.getMessage());
app.repoDB.removeRepo(pair.first);
app.getRepoDB().removeRepo(pair.first);
}
}
});
@ -134,7 +134,7 @@ public class UpdateRepos {
}
private void fullReload() {
Cursor c = app.repoDB.getRawCursor();
Cursor c = app.getRepoDB().getRawCursor();
runTasks(() -> {
while (true) {
Repo repo;
@ -145,10 +145,10 @@ public class UpdateRepos {
}
try {
repo.update();
app.repoDB.addRepo(repo);
app.getRepoDB().addRepo(repo);
} catch (Repo.IllegalRepoException e) {
Logger.debug(e.getMessage());
app.repoDB.removeRepo(repo);
app.getRepoDB().removeRepo(repo);
}
}
});
@ -157,12 +157,12 @@ public class UpdateRepos {
public void exec(boolean force) {
Event.reset(Event.REPO_LOAD_DONE);
App.THREAD_POOL.execute(() -> {
cached = Collections.synchronizedSet(app.repoDB.getRepoIDSet());
cached = Collections.synchronizedSet(app.getRepoDB().getRepoIDSet());
moduleQueue = new ConcurrentLinkedQueue<>();
if (loadPages()) {
// The leftover cached means they are removed from online repo
app.repoDB.removeRepo(cached);
app.getRepoDB().removeRepo(cached);
} else if (force) {
fullReload();
}

View File

@ -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();
}
}

View 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
}
}

View File

@ -74,7 +74,7 @@ public class SettingsFragment extends BasePreferenceFragment {
});
findPreference("clear").setOnPreferenceClickListener(pref -> {
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);
return true;
});