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

Commit c84542c9 authored by Hongming Jin's avatar Hongming Jin Committed by Android (Google) Code Review
Browse files

Merge "Unbind autofill service when the service package is updated." into pi-dev

parents 2d664339 3d848139
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.
     */
     */