From a2b91174c09c2e0bc6ca731ef1730448f6f0a720 Mon Sep 17 00:00:00 2001 From: Yash-Garg Date: Mon, 3 Oct 2022 18:57:19 +0530 Subject: [PATCH 1/3] chore: add some db logging to apps loading w/ @suphon --- .../core/database/DatabaseManager.java | 7 +++++++ .../features/launcher/AppProvider.java | 16 +++++++++++----- .../launcher/tasks/LoadDatabaseTask.java | 3 +++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/foundation/e/blisslauncher/core/database/DatabaseManager.java b/app/src/main/java/foundation/e/blisslauncher/core/database/DatabaseManager.java index 81acab13c9..101c69b21b 100644 --- a/app/src/main/java/foundation/e/blisslauncher/core/database/DatabaseManager.java +++ b/app/src/main/java/foundation/e/blisslauncher/core/database/DatabaseManager.java @@ -1,6 +1,7 @@ package foundation.e.blisslauncher.core.database; import android.content.Context; +import android.util.Log; import android.widget.GridLayout; import foundation.e.blisslauncher.core.customviews.BlissFrameLayout; import foundation.e.blisslauncher.core.database.daos.WidgetDao; @@ -42,6 +43,7 @@ public class DatabaseManager { } public void removeLauncherItem(String itemId) { + Log.d(TAG, "[debug-db] removeLauncherItem: " + itemId); mAppExecutors.diskIO().execute(() -> LauncherDB.getDatabase(mContext).launcherDao().delete(itemId)); } @@ -102,6 +104,11 @@ public class DatabaseManager { } } } + List ids = new ArrayList<>(); + for (LauncherItem item : items) { + ids.add(item.id); + } + Log.d(TAG, "[debug-db] saveLauncherItems: " + ids); LauncherDB.getDatabase(mContext).launcherDao().insertAll(items); } diff --git a/app/src/main/java/foundation/e/blisslauncher/features/launcher/AppProvider.java b/app/src/main/java/foundation/e/blisslauncher/features/launcher/AppProvider.java index ff011c80a8..ae6a081caa 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/launcher/AppProvider.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/launcher/AppProvider.java @@ -258,14 +258,19 @@ public class AppProvider { if (mDatabaseItems == null || mDatabaseItems.size() <= 0) { mLauncherItems = prepareDefaultLauncherItems(); } else { - mLauncherItems = prepareLauncherItems(); + try { + mLauncherItems = prepareLauncherItems(); + } catch (Exception e) { + Log.e(TAG, "[debug-db] prepareLauncherItems failed", e); + throw e; + } } mAppsRepository.updateAppsRelay(mLauncherItems); } } private List prepareLauncherItems() { - Log.d(TAG, "prepareLauncherItems() called"); + Log.d(TAG, "[debug-db] prepareLauncherItems() called"); /** Indices of folder in {@link #mLauncherItems}. */ LongSparseArray foldersIndex = new LongSparseArray<>(); @@ -371,7 +376,7 @@ public class AppProvider { applicationItems.removeAll(mDatabaseItems); List mutableList = new ArrayList<>(applicationItems); - Collections.sort(mutableList, (app1, app2) -> { + mutableList.sort((app1, app2) -> { Collator collator = Collator.getInstance(); return collator.compare(app1.title.toString(), app2.title.toString()); }); @@ -437,6 +442,7 @@ public class AppProvider { } private List prepareDefaultLauncherItems() { + Log.d(TAG, "[debug-db] prepareDefaultLauncherItems() called"); List mLauncherItems = new ArrayList<>(); List pinnedItems = new ArrayList<>(); PackageManager pm = mContext.getPackageManager(); @@ -464,7 +470,7 @@ public class AppProvider { } } - Collections.sort(mLauncherItems, (app1, app2) -> { + mLauncherItems.sort((app1, app2) -> { Collator collator = Collator.getInstance(); return collator.compare(app1.title.toString(), app2.title.toString()); }); @@ -478,7 +484,7 @@ public class AppProvider { } public void clear() { - this.sInstance = null; + sInstance = null; mLauncherItems = new ArrayList<>(); mAppsRepository.updateAppsRelay(Collections.emptyList()); } diff --git a/app/src/main/java/foundation/e/blisslauncher/features/launcher/tasks/LoadDatabaseTask.java b/app/src/main/java/foundation/e/blisslauncher/features/launcher/tasks/LoadDatabaseTask.java index 6225da2e85..03f2b4f121 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/launcher/tasks/LoadDatabaseTask.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/launcher/tasks/LoadDatabaseTask.java @@ -1,6 +1,8 @@ package foundation.e.blisslauncher.features.launcher.tasks; import android.os.AsyncTask; +import android.util.Log; + import foundation.e.blisslauncher.core.database.LauncherDB; import foundation.e.blisslauncher.core.database.model.LauncherItem; import foundation.e.blisslauncher.core.migrate.Migration; @@ -28,6 +30,7 @@ public class LoadDatabaseTask extends AsyncTask> @Override protected void onPostExecute(List launcherItems) { super.onPostExecute(launcherItems); + Log.d("LoadDatabaseTask", "[debug-db] load db done, got " + launcherItems.size() + " items"); if (mAppProvider != null) { mAppProvider.loadDatabaseOver(launcherItems); } -- GitLab From 9cb86aec2f6badeb980b5b86233c1c4efaa6a0f0 Mon Sep 17 00:00:00 2001 From: Yash-Garg Date: Mon, 3 Oct 2022 19:30:26 +0530 Subject: [PATCH 2/3] add some logs to migration --- .../java/foundation/e/blisslauncher/core/migrate/Migration.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/foundation/e/blisslauncher/core/migrate/Migration.java b/app/src/main/java/foundation/e/blisslauncher/core/migrate/Migration.java index e2ef0253ef..039eaf3ee1 100644 --- a/app/src/main/java/foundation/e/blisslauncher/core/migrate/Migration.java +++ b/app/src/main/java/foundation/e/blisslauncher/core/migrate/Migration.java @@ -24,6 +24,7 @@ public class Migration { } public static void migrateSafely(Context context) { + Log.d(TAG, "[debug-db] started migrateSafely task"); if (instance == null) { synchronized (Migration.class) { if (instance == null) { @@ -78,6 +79,7 @@ public class Migration { is.close(); json = new String(buffer, "UTF-8"); } catch (IOException ex) { + Log.d(TAG, "[debug-db] failed to read JSON from Asset: " + ex); ex.printStackTrace(); return null; } -- GitLab From e7cc8bd8643574d52d91789ac2f806f5827fcf91 Mon Sep 17 00:00:00 2001 From: Yash Garg Date: Fri, 14 Oct 2022 16:08:44 +0530 Subject: [PATCH 3/3] chore: use whatthestack for debug builds, also some misc. code improvements --- app/build.gradle.kts | 1 + .../core/database/DatabaseManager.java | 9 ++++---- .../features/launcher/AppProvider.java | 21 ++++++++++--------- gradle/libs.versions.toml | 1 + 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4cd51a270f..4cbc20613f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -176,6 +176,7 @@ dependencies { implementation(libs.circleindicator) implementation(libs.restriction.bypass) debugImplementation(libs.debug.db) + debugImplementation(libs.whatthestack) coreLibraryDesugaring(libs.tools.desugar) // Testing dependencies diff --git a/app/src/main/java/foundation/e/blisslauncher/core/database/DatabaseManager.java b/app/src/main/java/foundation/e/blisslauncher/core/database/DatabaseManager.java index 101c69b21b..f7171bb5e5 100644 --- a/app/src/main/java/foundation/e/blisslauncher/core/database/DatabaseManager.java +++ b/app/src/main/java/foundation/e/blisslauncher/core/database/DatabaseManager.java @@ -3,6 +3,7 @@ package foundation.e.blisslauncher.core.database; import android.content.Context; import android.util.Log; import android.widget.GridLayout; + import foundation.e.blisslauncher.core.customviews.BlissFrameLayout; import foundation.e.blisslauncher.core.database.daos.WidgetDao; import foundation.e.blisslauncher.core.database.model.FolderItem; @@ -19,12 +20,12 @@ import java.util.Set; public class DatabaseManager { - private AppExecutors mAppExecutors; + private final AppExecutors mAppExecutors; private static final String TAG = "DatabaseManager"; private static volatile DatabaseManager INSTANCE; - private Context mContext; + private final Context mContext; private DatabaseManager(Context context) { this.mContext = context; @@ -48,9 +49,7 @@ public class DatabaseManager { } public void saveLayouts(List pages, GridLayout dock) { - List tempPages = pages; - GridLayout tempDock = dock; - mAppExecutors.diskIO().execute(() -> saveLauncherItems(tempPages, tempDock)); + mAppExecutors.diskIO().execute(() -> saveLauncherItems(pages, dock)); } private void saveLauncherItems(final List pages, final GridLayout dock) { diff --git a/app/src/main/java/foundation/e/blisslauncher/features/launcher/AppProvider.java b/app/src/main/java/foundation/e/blisslauncher/features/launcher/AppProvider.java index ae6a081caa..93361cb84d 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/launcher/AppProvider.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/launcher/AppProvider.java @@ -39,6 +39,7 @@ import foundation.e.blisslauncher.features.shortcuts.DeepShortcutManager; import foundation.e.blisslauncher.features.shortcuts.ShortcutInfoCompat; import java.text.Collator; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -94,7 +95,7 @@ public class AppProvider { private boolean mStopped; private boolean isSdCardReady; - private AppsRepository appsRepository; + private final AppsRepository appsRepository; private AppProvider(Context context) { this.mContext = context; @@ -143,8 +144,8 @@ public class AppProvider { @Override public void onPackagesAvailable(String[] packageNames, android.os.UserHandle user, boolean replacing) { - Log.d(TAG, "onPackagesAvailable() called with: packageNames = [" + packageNames + "], user = [" + user - + "], replacing = [" + replacing + "]"); + Log.d(TAG, "onPackagesAvailable() called with: packageNames = [" + Arrays.toString(packageNames) + + "], user = [" + user + "], replacing = [" + replacing + "]"); for (String packageName : packageNames) { PackageAddedRemovedHandler.handleEvent(mContext, "android.intent.action.MEDIA_MOUNTED", packageName, new UserHandle(manager.getSerialNumberForUser(user), user), false); @@ -153,23 +154,23 @@ public class AppProvider { @Override public void onPackagesUnavailable(String[] packageNames, android.os.UserHandle user, boolean replacing) { - Log.d(TAG, "onPackagesUnavailable() called with: packageNames = [" + packageNames + "], user = [" + user - + "], replacing = [" + replacing + "]"); + Log.d(TAG, "onPackagesUnavailable() called with: packageNames = [" + Arrays.toString(packageNames) + + "], user = [" + user + "], replacing = [" + replacing + "]"); PackageAddedRemovedHandler.handleEvent(mContext, "android.intent.action.MEDIA_UNMOUNTED", null, new UserHandle(manager.getSerialNumberForUser(user), user), false); } @Override public void onPackagesSuspended(String[] packageNames, android.os.UserHandle user) { - Log.d(TAG, "onPackagesSuspended() called with: packageNames = [" + packageNames + "], user = [" + user - + "]"); + Log.d(TAG, "onPackagesSuspended() called with: packageNames = [" + Arrays.toString(packageNames) + + "], user = [" + user + "]"); } @Override public void onPackagesUnsuspended(String[] packageNames, android.os.UserHandle user) { super.onPackagesUnsuspended(packageNames, user); - Log.d(TAG, "onPackagesUnsuspended() called with: packageNames = [" + packageNames + "], user = [" + user - + "]"); + Log.d(TAG, "onPackagesUnsuspended() called with: packageNames = [" + Arrays.toString(packageNames) + + "], user = [" + user + "]"); } }); @@ -385,7 +386,7 @@ public class AppProvider { } private boolean isAppOnSdcard(String packageName, UserHandle userHandle) { - ApplicationInfo info = null; + ApplicationInfo info; try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { info = ((LauncherApps) mContext.getSystemService(Context.LAUNCHER_APPS_SERVICE)).getApplicationInfo( diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a523f7a174..2ef50450ac 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -62,6 +62,7 @@ tools-desugar = "com.android.tools:desugar_jdk_libs:1.1.5" timber = "com.jakewharton.timber:timber:4.7.1" restriction-bypass = "com.github.ChickenHook:RestrictionBypass:2.2" elib = "foundation.e:elib:0.0.1-alpha11" +whatthestack = "com.github.haroldadmin:WhatTheStack:1.0.0-alpha04" [plugins] android-application = { id = "com.android.application", version.ref = "agp" } -- GitLab