Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4dd6ab3c authored by Samuel Fufa's avatar Samuel Fufa
Browse files

Deference mAppPredictor on destroy

+ Also remove PredictionModel.mCachedComponentKeys

Bug: 156747920
Bug: 156041043
Test: Manual

Change-Id: I56dac1c6ac0a1bb93363342006232fc1ba42a3b4
parent e241f6c2
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -274,6 +274,7 @@ public class HotseatPredictionController implements DragController.DragListener,
        }
        }
        if (mAppPredictor != null) {
        if (mAppPredictor != null) {
            mAppPredictor.destroy();
            mAppPredictor.destroy();
            mAppPredictor = null;
        }
        }
        WeakReference<HotseatPredictionController> controllerRef = new WeakReference<>(this);
        WeakReference<HotseatPredictionController> controllerRef = new WeakReference<>(this);


+8 −11
Original line number Original line Diff line number Diff line
@@ -43,7 +43,6 @@ public class PredictionModel implements ResourceBasedOverride {
    private static final int MAX_CACHE_ITEMS = 5;
    private static final int MAX_CACHE_ITEMS = 5;


    protected Context mContext;
    protected Context mContext;
    private ArrayList<ComponentKey> mCachedComponentKeys;
    private SharedPreferences mDevicePrefs;
    private SharedPreferences mDevicePrefs;
    private UserCache mUserCache;
    private UserCache mUserCache;


@@ -78,7 +77,6 @@ public class PredictionModel implements ResourceBasedOverride {
                builder.append("\n");
                builder.append("\n");
            }
            }
            mDevicePrefs.edit().putString(CACHED_ITEMS_KEY, builder.toString()).apply();
            mDevicePrefs.edit().putString(CACHED_ITEMS_KEY, builder.toString()).apply();
            mCachedComponentKeys = null;
        });
        });
    }
    }


@@ -89,17 +87,16 @@ public class PredictionModel implements ResourceBasedOverride {
    @WorkerThread
    @WorkerThread
    public List<ComponentKey> getPredictionComponentKeys() {
    public List<ComponentKey> getPredictionComponentKeys() {
        Preconditions.assertWorkerThread();
        Preconditions.assertWorkerThread();
        if (mCachedComponentKeys == null) {
        ArrayList<ComponentKey> items = new ArrayList<>();
            mCachedComponentKeys = new ArrayList<>();
        String cachedBlob = mDevicePrefs.getString(CACHED_ITEMS_KEY, "");
        String cachedBlob = mDevicePrefs.getString(CACHED_ITEMS_KEY, "");
        for (String line : cachedBlob.split("\n")) {
        for (String line : cachedBlob.split("\n")) {
            ComponentKey key = getComponentKeyFromSerializedString(line);
            ComponentKey key = getComponentKeyFromSerializedString(line);
            if (key != null) {
            if (key != null) {
                    mCachedComponentKeys.add(key);
                items.add(key);
                }
            }
            }

        }
        }
        return mCachedComponentKeys;
        return items;
    }
    }


    private String serializeComponentKeyToString(ComponentKey componentKey) {
    private String serializeComponentKeyToString(ComponentKey componentKey) {