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

Commit d5a9e85c authored by Song Chun Fan's avatar Song Chun Fan
Browse files

[TextClassificationManagerService] hold PackageMonitor object

System server only holds a weak reference to PackageMonitor though PackageMonitorCallback. If there's nothing else holding on to PackageMonitor, it will get GC'd and following callbacks to it will be discarded.

BUG: 398759145  
TEST: manual
FLAG: EXEMPT bug fix
Change-Id: Id144aeac1d9f41ea6a4d9f36af769c0bdd783ebc
parent 6d5cc4fc
Loading
Loading
Loading
Loading
+31 −30
Original line number Diff line number Diff line
@@ -177,6 +177,7 @@ public final class TextClassificationManagerService extends ITextClassifierServi
    private final String mDefaultTextClassifierPackage;
    @Nullable
    private final String mSystemTextClassifierPackage;
    private final MyPackageMonitor mPackageMonitor;

    private TextClassificationManagerService(Context context) {
        mContext = Objects.requireNonNull(context);
@@ -187,15 +188,14 @@ public final class TextClassificationManagerService extends ITextClassifierServi
        mDefaultTextClassifierPackage = packageManager.getDefaultTextClassifierPackageName();
        mSystemTextClassifierPackage = packageManager.getSystemTextClassifierPackageName();
        mSessionCache = new SessionCache(mLock);
        mPackageMonitor = new MyPackageMonitor();
    }

    private void startListenSettings() {
        mSettingsListener.registerObserver();
    }

    void startTrackingPackageChanges() {
        final PackageMonitor monitor = new PackageMonitor() {

    private class MyPackageMonitor extends PackageMonitor {
        @Override
        public void onPackageAdded(String packageName, int uid) {
            notifyPackageInstallStatusChange(packageName, /* installed*/ true);
@@ -228,9 +228,10 @@ public final class TextClassificationManagerService extends ITextClassifierServi
                }
            }
        }
        };
    }

        monitor.register(mContext, null,  UserHandle.ALL, true);
    void startTrackingPackageChanges() {
       mPackageMonitor.register(mContext, null,  UserHandle.ALL, true);
    }

    @Override