From 19fbdc6582376d3b274733cc98893dc09eee9ab9 Mon Sep 17 00:00:00 2001 From: Till Kottmann Date: Thu, 27 Sep 2018 20:41:19 +0200 Subject: [PATCH] CustomAppPredictor: Handle component name changes Actually check if the saved activity still exists and find a new launch intent for the packagename if it doesn't. If no launch intent is found the app was uninstalled so we can remove it completely. Signed-off-by: Till Kottmann --- .../apps/nexuslauncher/CustomAppPredictor.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/com/google/android/apps/nexuslauncher/CustomAppPredictor.java b/src/com/google/android/apps/nexuslauncher/CustomAppPredictor.java index a49d0f4ffd..6961243866 100644 --- a/src/com/google/android/apps/nexuslauncher/CustomAppPredictor.java +++ b/src/com/google/android/apps/nexuslauncher/CustomAppPredictor.java @@ -81,7 +81,7 @@ public CustomAppPredictor(Context context) { List> getPredictions() { List> list = new ArrayList<>(); if (isPredictorEnabled()) { - clearNonExistentPackages(); + clearNonExistingComponents(); List predictionList = new ArrayList<>(getStringSetCopy()); @@ -119,7 +119,7 @@ public void logAppLaunch(View v, Intent intent, UserHandle user) { if (isPredictorEnabled() && recursiveIsDrawer(v)) { ComponentName componentInfo = intent.getComponent(); if (componentInfo != null && mAppFilter.shouldShowApp(componentInfo, user)) { - clearNonExistentPackages(); + clearNonExistingComponents(); Set predictionSet = getStringSetCopy(); SharedPreferences.Editor edit = mPrefs.edit(); @@ -201,17 +201,26 @@ private ComponentKeyMapper getComponentFromString(String str) { return new ComponentKeyMapper<>(new ComponentKey(mContext, str)); } - private void clearNonExistentPackages() { + private void clearNonExistingComponents() { Set originalSet = mPrefs.getStringSet(PREDICTION_SET, EMPTY_SET); Set predictionSet = new HashSet<>(originalSet); SharedPreferences.Editor edit = mPrefs.edit(); for (String prediction : originalSet) { + ComponentName cn = new ComponentKey(mContext, prediction).componentName; try { - mPackageManager.getPackageInfo(new ComponentKey(mContext, prediction).componentName.getPackageName(), 0); + mPackageManager.getActivityInfo(cn, 0); } catch (PackageManager.NameNotFoundException e) { predictionSet.remove(prediction); edit.remove(PREDICTION_PREFIX + prediction); + Intent intent = mPackageManager.getLaunchIntentForPackage(cn.getPackageName()); + if (intent != null) { + ComponentName componentInfo = intent.getComponent(); + if (componentInfo != null) { + ComponentKey key = new ComponentKey(componentInfo, Process.myUserHandle()); + predictionSet.add(key.toString()); + } + } } }