Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/com/google/android/apps/nexuslauncher/CustomAppPredictor.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public CustomAppPredictor(Context context) {
List<ComponentKeyMapper<AppInfo>> getPredictions() {
List<ComponentKeyMapper<AppInfo>> list = new ArrayList<>();
if (isPredictorEnabled()) {
clearNonExistentPackages();
clearNonExistingComponents();

List<String> predictionList = new ArrayList<>(getStringSetCopy());

Expand Down Expand Up @@ -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<String> predictionSet = getStringSetCopy();
SharedPreferences.Editor edit = mPrefs.edit();
Expand Down Expand Up @@ -201,17 +201,26 @@ private ComponentKeyMapper<AppInfo> getComponentFromString(String str) {
return new ComponentKeyMapper<>(new ComponentKey(mContext, str));
}

private void clearNonExistentPackages() {
private void clearNonExistingComponents() {
Set<String> originalSet = mPrefs.getStringSet(PREDICTION_SET, EMPTY_SET);
Set<String> 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());
}
}
}
}

Expand Down