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

Commit 3d848139 authored by Hongming Jin's avatar Hongming Jin
Browse files

Unbind autofill service when the service package is updated.

Test: atest FieldsClassificationTest
adb shell cmd autofill get fc_score half kale
m -j50 ExtServices && adb install -r
${OUT}/system/priv-app/ExtServices/ExtServices.apk
adb shell cmd autofill get fc_score half kale

Bug: 77596771
Change-Id: I29f6f5593dbe0155437d01ef73d07a354abe687d
parent 8785209f
Loading
Loading
Loading
Loading
+12 −0
Original line number Original line Diff line number Diff line
@@ -219,6 +219,8 @@ public final class AutofillManagerService extends SystemService {
                    final String activePackageName = getActiveAutofillServicePackageName();
                    final String activePackageName = getActiveAutofillServicePackageName();
                    if (packageName.equals(activePackageName)) {
                    if (packageName.equals(activePackageName)) {
                        removeCachedServiceLocked(getChangingUserId());
                        removeCachedServiceLocked(getChangingUserId());
                    } else {
                        handlePackageUpdateLocked(packageName);
                    }
                    }
                }
                }
            }
            }
@@ -250,6 +252,8 @@ public final class AutofillManagerService extends SystemService {
                                return true;
                                return true;
                            }
                            }
                            removeCachedServiceLocked(getChangingUserId());
                            removeCachedServiceLocked(getChangingUserId());
                        } else {
                          handlePackageUpdateLocked(pkg);
                        }
                        }
                    }
                    }
                }
                }
@@ -274,6 +278,14 @@ public final class AutofillManagerService extends SystemService {
                }
                }
                return serviceComponent.getPackageName();
                return serviceComponent.getPackageName();
            }
            }

            @GuardedBy("mLock")
            private void handlePackageUpdateLocked(String packageName) {
                final int size = mServicesCache.size();
                for (int i = 0; i < size; i++) {
                    mServicesCache.valueAt(i).handlePackageUpdateLocked(packageName);
                }
            }
        };
        };


        // package changes
        // package changes
+16 −0
Original line number Original line Diff line number Diff line
@@ -625,10 +625,26 @@ final class AutofillManagerServiceImpl {
        }
        }
    }
    }


    @GuardedBy("mLock")
    void handlePackageUpdateLocked(String packageName) {
        final ServiceInfo serviceInfo = mFieldClassificationStrategy.getServiceInfo();
        if (serviceInfo != null && serviceInfo.packageName.equals(packageName)) {
            resetExtServiceLocked();
        }
    }

    @GuardedBy("mLock")
    void resetExtServiceLocked() {
        if (sVerbose) Slog.v(TAG, "reset autofill service.");
        mFieldClassificationStrategy.reset();
    }

    @GuardedBy("mLock")
    @GuardedBy("mLock")
    void destroyLocked() {
    void destroyLocked() {
        if (sVerbose) Slog.v(TAG, "destroyLocked()");
        if (sVerbose) Slog.v(TAG, "destroyLocked()");


        resetExtServiceLocked();

        final int numSessions = mSessions.size();
        final int numSessions = mSessions.size();
        final ArraySet<RemoteFillService> remoteFillServices = new ArraySet<>(numSessions);
        final ArraySet<RemoteFillService> remoteFillServices = new ArraySet<>(numSessions);
        for (int i = 0; i < numSessions; i++) {
        for (int i = 0; i < numSessions; i++) {
+13 −1
Original line number Original line Diff line number Diff line
@@ -83,7 +83,7 @@ final class FieldClassificationStrategy {
    }
    }


    @Nullable
    @Nullable
    private ServiceInfo getServiceInfo() {
    ServiceInfo getServiceInfo() {
        final String packageName =
        final String packageName =
                mContext.getPackageManager().getServicesSystemSharedLibraryPackageName();
                mContext.getPackageManager().getServicesSystemSharedLibraryPackageName();
        if (packageName == null) {
        if (packageName == null) {
@@ -119,6 +119,18 @@ final class FieldClassificationStrategy {
        return name;
        return name;
    }
    }


    void reset() {
        synchronized (mLock) {
            if (mServiceConnection != null) {
                if (sDebug) Slog.d(TAG, "reset(): unbinding service.");
                mContext.unbindService(mServiceConnection);
                mServiceConnection = null;
            } else {
                if (sDebug) Slog.d(TAG, "reset(): service is not bound. Do nothing.");
            }
        }
    }

    /**
    /**
     * Run a command, starting the service connection if necessary.
     * Run a command, starting the service connection if necessary.
     */
     */