diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 49f6562971268fd1858d69780d93a6b398b124d2..704b9391909bb3288b50de7e2a8bde60cdaee68e 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -167,6 +167,7 @@ dependencies { implementation(libs.circleindicator) implementation(libs.restriction.bypass) debugImplementation(libs.debug.db) + debugImplementation(libs.whatthestack) coreLibraryDesugaring(libs.tools.desugar) implementation(libs.androidx.profileinstaller) debugImplementation(libs.tools.leakcanary) 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 81acab13c9c9d9cce9e1fd6c49f066ee926855a3..f7171bb5e5ad21857403bdb970dfa124210f4917 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,7 +1,9 @@ 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; @@ -18,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; @@ -42,13 +44,12 @@ public class DatabaseManager { } public void removeLauncherItem(String itemId) { + Log.d(TAG, "[debug-db] removeLauncherItem: " + itemId); mAppExecutors.diskIO().execute(() -> LauncherDB.getDatabase(mContext).launcherDao().delete(itemId)); } 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) { @@ -102,6 +103,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/core/migrate/Migration.java b/app/src/main/java/foundation/e/blisslauncher/core/migrate/Migration.java index e2ef0253efb51dd3d36e16376aa3625ebb336a10..039eaf3ee1329a6de7f29092bd495011cb40a465 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; } 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 04069a7b8b6d108fb8f8879f29e455390c13ea48..d19b68eb71725b2b5f0c8a01c9eb6c096f603427 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; @@ -96,7 +97,7 @@ public class AppProvider { private boolean mStopped; private boolean isSdCardReady; - private AppsRepository appsRepository; + private final AppsRepository appsRepository; private AppProvider(Context context) { this.mContext = context; @@ -145,8 +146,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); @@ -155,23 +156,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 + "]"); } }); @@ -260,14 +261,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<>(); @@ -373,7 +379,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()); }); @@ -382,7 +388,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( @@ -439,6 +445,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(); @@ -466,7 +473,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()); }); @@ -480,7 +487,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 6225da2e85a36d3164be3dc9b3d61245384a12bf..03f2b4f121087d081784d1ed50b46a4976f4bc05 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); } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6143679edb7f791e0f826cc8aca487affbe323d6..e6436fa8b0f8bbe607260948ca3586f9e0b63ffb 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -71,6 +71,7 @@ timber = "com.jakewharton.timber:timber:4.7.1" restriction-bypass = "com.github.ChickenHook:RestrictionBypass:2.2" elib = "foundation.e:elib:0.0.1-alpha11" telemetry = "foundation.e.lib:telemetry:0.0.3-alpha" +whatthestack = "com.github.haroldadmin:WhatTheStack:1.0.0-alpha04" [plugins] android-application = { id = "com.android.application", version.ref = "agp" }