Loading services/autofill/java/com/android/server/autofill/AutofillManagerService.java +5 −6 Original line number Original line Diff line number Diff line Loading @@ -84,7 +84,6 @@ import com.android.internal.util.Preconditions; import com.android.internal.util.SyncResultReceiver; import com.android.internal.util.SyncResultReceiver; import com.android.server.FgThread; import com.android.server.FgThread; import com.android.server.LocalServices; import com.android.server.LocalServices; import com.android.server.SystemService.TargetUser; import com.android.server.autofill.ui.AutoFillUI; import com.android.server.autofill.ui.AutoFillUI; import com.android.server.infra.AbstractMasterSystemService; import com.android.server.infra.AbstractMasterSystemService; import com.android.server.infra.FrameworkResourcesServiceNameResolver; import com.android.server.infra.FrameworkResourcesServiceNameResolver; Loading Loading @@ -170,7 +169,7 @@ public final class AutofillManagerService // beneath it is brought back to top. Ideally, we should just hide the UI and // beneath it is brought back to top. Ideally, we should just hide the UI and // bring it back when the activity resumes. // bring it back when the activity resumes. synchronized (mLock) { synchronized (mLock) { visitServicesLocked((s) -> s.destroyFinishedSessionsLocked()); visitServicesLocked((s) -> s.forceRemoveFinishedSessionsLocked()); } } mUi.hideAll(null); mUi.hideAll(null); } } Loading Loading @@ -386,18 +385,18 @@ public final class AutofillManagerService } } // Called by Shell command. // Called by Shell command. void destroySessions(@UserIdInt int userId, IResultReceiver receiver) { void removeAllSessions(@UserIdInt int userId, IResultReceiver receiver) { Slog.i(TAG, "destroySessions() for userId " + userId); Slog.i(TAG, "removeAllSessions() for userId " + userId); enforceCallingPermissionForManagement(); enforceCallingPermissionForManagement(); synchronized (mLock) { synchronized (mLock) { if (userId != UserHandle.USER_ALL) { if (userId != UserHandle.USER_ALL) { AutofillManagerServiceImpl service = peekServiceForUserLocked(userId); AutofillManagerServiceImpl service = peekServiceForUserLocked(userId); if (service != null) { if (service != null) { service.destroySessionsLocked(); service.forceRemoveAllSessionsLocked(); } } } else { } else { visitServicesLocked((s) -> s.destroySessionsLocked()); visitServicesLocked((s) -> s.forceRemoveAllSessionsLocked()); } } } } Loading services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java +23 −17 Original line number Original line Diff line number Diff line Loading @@ -215,14 +215,14 @@ final class AutofillManagerServiceImpl @GuardedBy("mLock") @GuardedBy("mLock") @Override // from PerUserSystemService @Override // from PerUserSystemService protected boolean updateLocked(boolean disabled) { protected boolean updateLocked(boolean disabled) { destroySessionsLocked(); forceRemoveAllSessionsLocked(); final boolean enabledChanged = super.updateLocked(disabled); final boolean enabledChanged = super.updateLocked(disabled); if (enabledChanged) { if (enabledChanged) { if (!isEnabledLocked()) { if (!isEnabledLocked()) { final int sessionCount = mSessions.size(); final int sessionCount = mSessions.size(); for (int i = sessionCount - 1; i >= 0; i--) { for (int i = sessionCount - 1; i >= 0; i--) { final Session session = mSessions.valueAt(i); final Session session = mSessions.valueAt(i); session.removeSelfLocked(); session.removeFromServiceLocked(); } } } } sendStateToClients(/* resetClient= */ false); sendStateToClients(/* resetClient= */ false); Loading Loading @@ -442,7 +442,7 @@ final class AutofillManagerServiceImpl if (sVerbose) Slog.v(TAG, "finishSessionLocked(): session finished on save? " + finished); if (sVerbose) Slog.v(TAG, "finishSessionLocked(): session finished on save? " + finished); if (finished) { if (finished) { session.removeSelfLocked(); session.removeFromServiceLocked(); } } } } Loading @@ -457,7 +457,7 @@ final class AutofillManagerServiceImpl Slog.w(TAG, "cancelSessionLocked(): no session for " + sessionId + "(" + uid + ")"); Slog.w(TAG, "cancelSessionLocked(): no session for " + sessionId + "(" + uid + ")"); return; return; } } session.removeSelfLocked(); session.removeFromServiceLocked(); } } @GuardedBy("mLock") @GuardedBy("mLock") Loading @@ -483,7 +483,7 @@ final class AutofillManagerServiceImpl componentName.getPackageName()); componentName.getPackageName()); Settings.Secure.putStringForUser(getContext().getContentResolver(), Settings.Secure.putStringForUser(getContext().getContentResolver(), Settings.Secure.AUTOFILL_SERVICE, null, mUserId); Settings.Secure.AUTOFILL_SERVICE, null, mUserId); destroySessionsLocked(); forceRemoveAllSessionsLocked(); } else { } else { Slog.w(TAG, "disableOwnedServices(): ignored because current service (" Slog.w(TAG, "disableOwnedServices(): ignored because current service (" + serviceInfo + ") does not match Settings (" + autoFillService + ")"); + serviceInfo + ") does not match Settings (" + autoFillService + ")"); Loading Loading @@ -1107,35 +1107,41 @@ final class AutofillManagerServiceImpl } } @GuardedBy("mLock") @GuardedBy("mLock") void destroySessionsLocked() { void forceRemoveAllSessionsLocked() { if (mSessions.size() == 0) { final int sessionCount = mSessions.size(); if (sessionCount == 0) { mUi.destroyAll(null, null, false); mUi.destroyAll(null, null, false); return; return; } } while (mSessions.size() > 0) { mSessions.valueAt(0).forceRemoveSelfLocked(); for (int i = sessionCount - 1; i >= 0; i--) { mSessions.valueAt(i).forceRemoveFromServiceLocked(); } } } } @GuardedBy("mLock") @GuardedBy("mLock") void destroySessionsForAugmentedAutofillOnlyLocked() { void forceRemoveForAugmentedOnlySessionsLocked() { final int sessionCount = mSessions.size(); final int sessionCount = mSessions.size(); for (int i = sessionCount - 1; i >= 0; i--) { for (int i = sessionCount - 1; i >= 0; i--) { mSessions.valueAt(i).forceRemoveSelfIfForAugmentedAutofillOnlyLocked(); mSessions.valueAt(i).forceRemoveFromServiceIfForAugmentedOnlyLocked(); } } } } /** * This method is called exclusively in response to {@code Intent.ACTION_CLOSE_SYSTEM_DIALOGS}. * The method removes all sessions that are finished but showing SaveUI due to how SaveUI is * managed (see b/64940307). Otherwise it will remove any augmented autofill generated windows. */ // TODO(b/64940307): remove this method if SaveUI is refactored to be attached on activities // TODO(b/64940307): remove this method if SaveUI is refactored to be attached on activities @GuardedBy("mLock") @GuardedBy("mLock") void destroyFinishedSessionsLocked() { void forceRemoveFinishedSessionsLocked() { final int sessionCount = mSessions.size(); final int sessionCount = mSessions.size(); for (int i = sessionCount - 1; i >= 0; i--) { for (int i = sessionCount - 1; i >= 0; i--) { final Session session = mSessions.valueAt(i); final Session session = mSessions.valueAt(i); if (session.isSavingLocked()) { if (session.isSavingLocked()) { if (sDebug) Slog.d(TAG, "destroyFinishedSessionsLocked(): " + session.id); if (sDebug) Slog.d(TAG, "destroyFinishedSessionsLocked(): " + session.id); session.forceRemoveSelfLocked(); session.forceRemoveFromServiceLocked(); } } else { else { session.destroyAugmentedAutofillWindowsLocked(); session.destroyAugmentedAutofillWindowsLocked(); } } } } Loading Loading @@ -1261,7 +1267,7 @@ final class AutofillManagerServiceImpl Slog.v(TAG, "updateRemoteAugmentedAutofillService(): " Slog.v(TAG, "updateRemoteAugmentedAutofillService(): " + "destroying old remote service"); + "destroying old remote service"); } } destroySessionsForAugmentedAutofillOnlyLocked(); forceRemoveForAugmentedOnlySessionsLocked(); mRemoteAugmentedAutofillService.unbind(); mRemoteAugmentedAutofillService.unbind(); mRemoteAugmentedAutofillService = null; mRemoteAugmentedAutofillService = null; mRemoteAugmentedAutofillServiceInfo = null; mRemoteAugmentedAutofillServiceInfo = null; Loading Loading @@ -1663,7 +1669,7 @@ final class AutofillManagerServiceImpl Slog.i(TAG, "Prune session " + sessionToRemove.id + " (" Slog.i(TAG, "Prune session " + sessionToRemove.id + " (" + sessionToRemove.getActivityTokenLocked() + ")"); + sessionToRemove.getActivityTokenLocked() + ")"); } } sessionToRemove.removeSelfLocked(); sessionToRemove.removeFromServiceLocked(); } } } } } } Loading services/autofill/java/com/android/server/autofill/AutofillManagerServiceShellCommand.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -355,7 +355,7 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand { latch.countDown(); latch.countDown(); } } }; }; return requestSessionCommon(pw, latch, () -> mService.destroySessions(userId, receiver)); return requestSessionCommon(pw, latch, () -> mService.removeAllSessions(userId, receiver)); } } private int requestList(PrintWriter pw) { private int requestList(PrintWriter pw) { Loading services/autofill/java/com/android/server/autofill/Session.java +50 −50 Original line number Original line Diff line number Diff line Loading @@ -227,8 +227,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState private boolean mHasCallback; private boolean mHasCallback; /** /** * Extras sent by service on {@code onFillRequest()} calls; the first non-null extra is saved * Extras sent by service on {@code onFillRequest()} calls; the most recent non-null extra is * and used on subsequent {@code onFillRequest()} and {@code onSaveRequest()} calls. * saved and used on subsequent {@code onFillRequest()} and {@code onSaveRequest()} calls. */ */ @GuardedBy("mLock") @GuardedBy("mLock") private Bundle mClientState; private Bundle mClientState; Loading Loading @@ -1086,7 +1086,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState if (showMessage) { if (showMessage) { getUiForShowing().showError(message, this); getUiForShowing().showError(message, this); } } removeSelf(); removeFromService(); } } // FillServiceCallbacks // FillServiceCallbacks Loading @@ -1111,7 +1111,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } } // Nothing left to do... // Nothing left to do... removeSelf(); removeFromService(); } } // FillServiceCallbacks // FillServiceCallbacks Loading Loading @@ -1147,7 +1147,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState if (showMessage) { if (showMessage) { getUiForShowing().showError(message, this); getUiForShowing().showError(message, this); } } removeSelf(); removeFromService(); } } /** /** Loading Loading @@ -1179,7 +1179,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState @Override @Override public void onServiceDied(@NonNull RemoteFillService service) { public void onServiceDied(@NonNull RemoteFillService service) { Slog.w(TAG, "removing session because service died"); Slog.w(TAG, "removing session because service died"); forceRemoveSelfLocked(); forceRemoveFromServiceLocked(); } } // AutoFillUiCallback // AutoFillUiCallback Loading @@ -1199,7 +1199,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } } fillInIntent = createAuthFillInIntentLocked(requestId, extras); fillInIntent = createAuthFillInIntentLocked(requestId, extras); if (fillInIntent == null) { if (fillInIntent == null) { forceRemoveSelfLocked(); forceRemoveFromServiceLocked(); return; return; } } } } Loading Loading @@ -1255,7 +1255,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } } } } mHandler.sendMessage(obtainMessage( mHandler.sendMessage(obtainMessage( Session::removeSelf, this)); Session::removeFromService, this)); } } // AutoFillUiCallback // AutoFillUiCallback Loading Loading @@ -1327,7 +1327,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState @Override @Override public void cancelSession() { public void cancelSession() { synchronized (mLock) { synchronized (mLock) { removeSelfLocked(); removeFromServiceLocked(); } } } } Loading @@ -1347,7 +1347,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState return; return; } } if (intent == null) { if (intent == null) { removeSelfLocked(); removeFromServiceLocked(); } } } } mHandler.sendMessage(obtainMessage( mHandler.sendMessage(obtainMessage( Loading Loading @@ -1401,13 +1401,13 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState // Typically happens when app explicitly called cancel() while the service was showing // Typically happens when app explicitly called cancel() while the service was showing // the auth UI. // the auth UI. Slog.w(TAG, "setAuthenticationResultLocked(" + authenticationId + "): no responses"); Slog.w(TAG, "setAuthenticationResultLocked(" + authenticationId + "): no responses"); removeSelf(); removeFromService(); return; return; } } final FillResponse authenticatedResponse = mResponses.get(requestId); final FillResponse authenticatedResponse = mResponses.get(requestId); if (authenticatedResponse == null || data == null) { if (authenticatedResponse == null || data == null) { Slog.w(TAG, "no authenticated response"); Slog.w(TAG, "no authenticated response"); removeSelf(); removeFromService(); return; return; } } Loading @@ -1418,7 +1418,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState final Dataset dataset = authenticatedResponse.getDatasets().get(datasetIdx); final Dataset dataset = authenticatedResponse.getDatasets().get(datasetIdx); if (dataset == null) { if (dataset == null) { Slog.w(TAG, "no dataset with index " + datasetIdx + " on fill response"); Slog.w(TAG, "no dataset with index " + datasetIdx + " on fill response"); removeSelf(); removeFromService(); return; return; } } } } Loading Loading @@ -1504,7 +1504,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState Slog.d(TAG, "Rejecting empty/invalid auth result"); Slog.d(TAG, "Rejecting empty/invalid auth result"); } } mService.resetLastAugmentedAutofillResponse(); mService.resetLastAugmentedAutofillResponse(); removeSelfLocked(); removeFromServiceLocked(); return; return; } } Loading Loading @@ -2715,7 +2715,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState return; return; } } if (sDebug) Slog.d(TAG, "Finishing session because URL bar changed"); if (sDebug) Slog.d(TAG, "Finishing session because URL bar changed"); forceRemoveSelfLocked(AutofillManager.STATE_UNKNOWN_COMPAT_MODE); forceRemoveFromServiceLocked(AutofillManager.STATE_UNKNOWN_COMPAT_MODE); return; return; } } if (!Objects.equals(value, viewState.getCurrentValue())) { if (!Objects.equals(value, viewState.getCurrentValue())) { Loading Loading @@ -3226,7 +3226,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } } // Nothing to be done, but need to notify client. // Nothing to be done, but need to notify client. notifyUnavailableToClient(AutofillManager.STATE_FINISHED, autofillableIds); notifyUnavailableToClient(AutofillManager.STATE_FINISHED, autofillableIds); removeSelf(); removeFromService(); } else { } else { if ((flags & FLAG_PASSWORD_INPUT_TYPE) != 0) { if ((flags & FLAG_PASSWORD_INPUT_TYPE) != 0) { if (sVerbose) { if (sVerbose) { Loading Loading @@ -3392,20 +3392,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState return mAugmentedAutofillDestroyer; return mAugmentedAutofillDestroyer; } } @GuardedBy("mLock") private void logAugmentedAutofillRequestLocked(int mode, ComponentName augmentedRemoteServiceName, AutofillId focusedId, boolean isWhitelisted, Boolean isInline) { final String historyItem = "aug:id=" + id + " u=" + uid + " m=" + mode + " a=" + ComponentName.flattenToShortString(mComponentName) + " f=" + focusedId + " s=" + augmentedRemoteServiceName + " w=" + isWhitelisted + " i=" + isInline; mService.getMaster().logRequestLocked(historyItem); } @GuardedBy("mLock") @GuardedBy("mLock") private void cancelAugmentedAutofillLocked() { private void cancelAugmentedAutofillLocked() { final RemoteAugmentedAutofillService remoteService = mService final RemoteAugmentedAutofillService remoteService = mService Loading Loading @@ -3574,7 +3560,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState setViewStatesLocked(null, dataset, ViewState.STATE_WAITING_DATASET_AUTH, false); setViewStatesLocked(null, dataset, ViewState.STATE_WAITING_DATASET_AUTH, false); final Intent fillInIntent = createAuthFillInIntentLocked(requestId, mClientState); final Intent fillInIntent = createAuthFillInIntentLocked(requestId, mClientState); if (fillInIntent == null) { if (fillInIntent == null) { forceRemoveSelfLocked(); forceRemoveFromServiceLocked(); return; return; } } final int authenticationId = AutofillManager.makeAuthenticationId(requestId, final int authenticationId = AutofillManager.makeAuthenticationId(requestId, Loading Loading @@ -3923,12 +3909,12 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } } /** /** * Cleans up this session. * Destroy this session and perform any clean up work. * * * <p>Typically called in 2 scenarios: * <p>Typically called in 2 scenarios: * * * <ul> * <ul> * <li>When the session naturally finishes (i.e., from {@link #removeSelfLocked()}. * <li>When the session naturally finishes (i.e., from {@link #removeFromServiceLocked()}. * <li>When the service hosting the session is finished (for example, because the user * <li>When the service hosting the session is finished (for example, because the user * disabled it). * disabled it). * </ul> * </ul> Loading Loading @@ -3990,32 +3976,32 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } } /** /** * Cleans up this session and remove it from the service always, even if it does have a pending * Destroy this session and remove it from the service always, even if it does have a pending * Save UI. * Save UI. */ */ @GuardedBy("mLock") @GuardedBy("mLock") void forceRemoveSelfLocked() { void forceRemoveFromServiceLocked() { forceRemoveSelfLocked(AutofillManager.STATE_UNKNOWN); forceRemoveFromServiceLocked(AutofillManager.STATE_UNKNOWN); } } @GuardedBy("mLock") @GuardedBy("mLock") void forceRemoveSelfIfForAugmentedAutofillOnlyLocked() { void forceRemoveFromServiceIfForAugmentedOnlyLocked() { if (sVerbose) { if (sVerbose) { Slog.v(TAG, "forceRemoveSelfIfForAugmentedAutofillOnly(" + this.id + "): " Slog.v(TAG, "forceRemoveFromServiceIfForAugmentedOnlyLocked(" + this.id + "): " + mForAugmentedAutofillOnly); + mForAugmentedAutofillOnly); } } if (!mForAugmentedAutofillOnly) return; if (!mForAugmentedAutofillOnly) return; forceRemoveSelfLocked(); forceRemoveFromServiceLocked(); } } @GuardedBy("mLock") @GuardedBy("mLock") void forceRemoveSelfLocked(int clientState) { void forceRemoveFromServiceLocked(int clientState) { if (sVerbose) Slog.v(TAG, "forceRemoveSelfLocked(): " + mPendingSaveUi); if (sVerbose) Slog.v(TAG, "forceRemoveFromServiceLocked(): " + mPendingSaveUi); final boolean isPendingSaveUi = isSaveUiPendingLocked(); final boolean isPendingSaveUi = isSaveUiPendingLocked(); mPendingSaveUi = null; mPendingSaveUi = null; removeSelfLocked(); removeFromServiceLocked(); mUi.destroyAll(mPendingSaveUi, this, false); mUi.destroyAll(mPendingSaveUi, this, false); if (!isPendingSaveUi) { if (!isPendingSaveUi) { try { try { Loading @@ -4036,28 +4022,28 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } } /** /** * Thread-safe version of {@link #removeSelfLocked()}. * Thread-safe version of {@link #removeFromServiceLocked()}. */ */ private void removeSelf() { private void removeFromService() { synchronized (mLock) { synchronized (mLock) { removeSelfLocked(); removeFromServiceLocked(); } } } } /** /** * Cleans up this session and remove it from the service, but but only if it does not have a * Destroy this session and remove it from the service, but but only if it does not have a * pending Save UI. * pending Save UI. */ */ @GuardedBy("mLock") @GuardedBy("mLock") void removeSelfLocked() { void removeFromServiceLocked() { if (sVerbose) Slog.v(TAG, "removeSelfLocked(" + this.id + "): " + mPendingSaveUi); if (sVerbose) Slog.v(TAG, "removeFromServiceLocked(" + this.id + "): " + mPendingSaveUi); if (mDestroyed) { if (mDestroyed) { Slog.w(TAG, "Call to Session#removeSelfLocked() rejected - session: " Slog.w(TAG, "Call to Session#removeFromServiceLocked() rejected - session: " + id + " destroyed"); + id + " destroyed"); return; return; } } if (isSaveUiPendingLocked()) { if (isSaveUiPendingLocked()) { Slog.i(TAG, "removeSelfLocked() ignored, waiting for pending save ui"); Slog.i(TAG, "removeFromServiceLocked() ignored, waiting for pending save ui"); return; return; } } Loading Loading @@ -4139,6 +4125,20 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState requestLog.addTaggedData(tag, value); requestLog.addTaggedData(tag, value); } } @GuardedBy("mLock") private void logAugmentedAutofillRequestLocked(int mode, ComponentName augmentedRemoteServiceName, AutofillId focusedId, boolean isWhitelisted, Boolean isInline) { final String historyItem = "aug:id=" + id + " u=" + uid + " m=" + mode + " a=" + ComponentName.flattenToShortString(mComponentName) + " f=" + focusedId + " s=" + augmentedRemoteServiceName + " w=" + isWhitelisted + " i=" + isInline; mService.getMaster().logRequestLocked(historyItem); } private void wtf(@Nullable Exception e, String fmt, Object...args) { private void wtf(@Nullable Exception e, String fmt, Object...args) { final String message = String.format(fmt, args); final String message = String.format(fmt, args); synchronized (mLock) { synchronized (mLock) { Loading Loading
services/autofill/java/com/android/server/autofill/AutofillManagerService.java +5 −6 Original line number Original line Diff line number Diff line Loading @@ -84,7 +84,6 @@ import com.android.internal.util.Preconditions; import com.android.internal.util.SyncResultReceiver; import com.android.internal.util.SyncResultReceiver; import com.android.server.FgThread; import com.android.server.FgThread; import com.android.server.LocalServices; import com.android.server.LocalServices; import com.android.server.SystemService.TargetUser; import com.android.server.autofill.ui.AutoFillUI; import com.android.server.autofill.ui.AutoFillUI; import com.android.server.infra.AbstractMasterSystemService; import com.android.server.infra.AbstractMasterSystemService; import com.android.server.infra.FrameworkResourcesServiceNameResolver; import com.android.server.infra.FrameworkResourcesServiceNameResolver; Loading Loading @@ -170,7 +169,7 @@ public final class AutofillManagerService // beneath it is brought back to top. Ideally, we should just hide the UI and // beneath it is brought back to top. Ideally, we should just hide the UI and // bring it back when the activity resumes. // bring it back when the activity resumes. synchronized (mLock) { synchronized (mLock) { visitServicesLocked((s) -> s.destroyFinishedSessionsLocked()); visitServicesLocked((s) -> s.forceRemoveFinishedSessionsLocked()); } } mUi.hideAll(null); mUi.hideAll(null); } } Loading Loading @@ -386,18 +385,18 @@ public final class AutofillManagerService } } // Called by Shell command. // Called by Shell command. void destroySessions(@UserIdInt int userId, IResultReceiver receiver) { void removeAllSessions(@UserIdInt int userId, IResultReceiver receiver) { Slog.i(TAG, "destroySessions() for userId " + userId); Slog.i(TAG, "removeAllSessions() for userId " + userId); enforceCallingPermissionForManagement(); enforceCallingPermissionForManagement(); synchronized (mLock) { synchronized (mLock) { if (userId != UserHandle.USER_ALL) { if (userId != UserHandle.USER_ALL) { AutofillManagerServiceImpl service = peekServiceForUserLocked(userId); AutofillManagerServiceImpl service = peekServiceForUserLocked(userId); if (service != null) { if (service != null) { service.destroySessionsLocked(); service.forceRemoveAllSessionsLocked(); } } } else { } else { visitServicesLocked((s) -> s.destroySessionsLocked()); visitServicesLocked((s) -> s.forceRemoveAllSessionsLocked()); } } } } Loading
services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java +23 −17 Original line number Original line Diff line number Diff line Loading @@ -215,14 +215,14 @@ final class AutofillManagerServiceImpl @GuardedBy("mLock") @GuardedBy("mLock") @Override // from PerUserSystemService @Override // from PerUserSystemService protected boolean updateLocked(boolean disabled) { protected boolean updateLocked(boolean disabled) { destroySessionsLocked(); forceRemoveAllSessionsLocked(); final boolean enabledChanged = super.updateLocked(disabled); final boolean enabledChanged = super.updateLocked(disabled); if (enabledChanged) { if (enabledChanged) { if (!isEnabledLocked()) { if (!isEnabledLocked()) { final int sessionCount = mSessions.size(); final int sessionCount = mSessions.size(); for (int i = sessionCount - 1; i >= 0; i--) { for (int i = sessionCount - 1; i >= 0; i--) { final Session session = mSessions.valueAt(i); final Session session = mSessions.valueAt(i); session.removeSelfLocked(); session.removeFromServiceLocked(); } } } } sendStateToClients(/* resetClient= */ false); sendStateToClients(/* resetClient= */ false); Loading Loading @@ -442,7 +442,7 @@ final class AutofillManagerServiceImpl if (sVerbose) Slog.v(TAG, "finishSessionLocked(): session finished on save? " + finished); if (sVerbose) Slog.v(TAG, "finishSessionLocked(): session finished on save? " + finished); if (finished) { if (finished) { session.removeSelfLocked(); session.removeFromServiceLocked(); } } } } Loading @@ -457,7 +457,7 @@ final class AutofillManagerServiceImpl Slog.w(TAG, "cancelSessionLocked(): no session for " + sessionId + "(" + uid + ")"); Slog.w(TAG, "cancelSessionLocked(): no session for " + sessionId + "(" + uid + ")"); return; return; } } session.removeSelfLocked(); session.removeFromServiceLocked(); } } @GuardedBy("mLock") @GuardedBy("mLock") Loading @@ -483,7 +483,7 @@ final class AutofillManagerServiceImpl componentName.getPackageName()); componentName.getPackageName()); Settings.Secure.putStringForUser(getContext().getContentResolver(), Settings.Secure.putStringForUser(getContext().getContentResolver(), Settings.Secure.AUTOFILL_SERVICE, null, mUserId); Settings.Secure.AUTOFILL_SERVICE, null, mUserId); destroySessionsLocked(); forceRemoveAllSessionsLocked(); } else { } else { Slog.w(TAG, "disableOwnedServices(): ignored because current service (" Slog.w(TAG, "disableOwnedServices(): ignored because current service (" + serviceInfo + ") does not match Settings (" + autoFillService + ")"); + serviceInfo + ") does not match Settings (" + autoFillService + ")"); Loading Loading @@ -1107,35 +1107,41 @@ final class AutofillManagerServiceImpl } } @GuardedBy("mLock") @GuardedBy("mLock") void destroySessionsLocked() { void forceRemoveAllSessionsLocked() { if (mSessions.size() == 0) { final int sessionCount = mSessions.size(); if (sessionCount == 0) { mUi.destroyAll(null, null, false); mUi.destroyAll(null, null, false); return; return; } } while (mSessions.size() > 0) { mSessions.valueAt(0).forceRemoveSelfLocked(); for (int i = sessionCount - 1; i >= 0; i--) { mSessions.valueAt(i).forceRemoveFromServiceLocked(); } } } } @GuardedBy("mLock") @GuardedBy("mLock") void destroySessionsForAugmentedAutofillOnlyLocked() { void forceRemoveForAugmentedOnlySessionsLocked() { final int sessionCount = mSessions.size(); final int sessionCount = mSessions.size(); for (int i = sessionCount - 1; i >= 0; i--) { for (int i = sessionCount - 1; i >= 0; i--) { mSessions.valueAt(i).forceRemoveSelfIfForAugmentedAutofillOnlyLocked(); mSessions.valueAt(i).forceRemoveFromServiceIfForAugmentedOnlyLocked(); } } } } /** * This method is called exclusively in response to {@code Intent.ACTION_CLOSE_SYSTEM_DIALOGS}. * The method removes all sessions that are finished but showing SaveUI due to how SaveUI is * managed (see b/64940307). Otherwise it will remove any augmented autofill generated windows. */ // TODO(b/64940307): remove this method if SaveUI is refactored to be attached on activities // TODO(b/64940307): remove this method if SaveUI is refactored to be attached on activities @GuardedBy("mLock") @GuardedBy("mLock") void destroyFinishedSessionsLocked() { void forceRemoveFinishedSessionsLocked() { final int sessionCount = mSessions.size(); final int sessionCount = mSessions.size(); for (int i = sessionCount - 1; i >= 0; i--) { for (int i = sessionCount - 1; i >= 0; i--) { final Session session = mSessions.valueAt(i); final Session session = mSessions.valueAt(i); if (session.isSavingLocked()) { if (session.isSavingLocked()) { if (sDebug) Slog.d(TAG, "destroyFinishedSessionsLocked(): " + session.id); if (sDebug) Slog.d(TAG, "destroyFinishedSessionsLocked(): " + session.id); session.forceRemoveSelfLocked(); session.forceRemoveFromServiceLocked(); } } else { else { session.destroyAugmentedAutofillWindowsLocked(); session.destroyAugmentedAutofillWindowsLocked(); } } } } Loading Loading @@ -1261,7 +1267,7 @@ final class AutofillManagerServiceImpl Slog.v(TAG, "updateRemoteAugmentedAutofillService(): " Slog.v(TAG, "updateRemoteAugmentedAutofillService(): " + "destroying old remote service"); + "destroying old remote service"); } } destroySessionsForAugmentedAutofillOnlyLocked(); forceRemoveForAugmentedOnlySessionsLocked(); mRemoteAugmentedAutofillService.unbind(); mRemoteAugmentedAutofillService.unbind(); mRemoteAugmentedAutofillService = null; mRemoteAugmentedAutofillService = null; mRemoteAugmentedAutofillServiceInfo = null; mRemoteAugmentedAutofillServiceInfo = null; Loading Loading @@ -1663,7 +1669,7 @@ final class AutofillManagerServiceImpl Slog.i(TAG, "Prune session " + sessionToRemove.id + " (" Slog.i(TAG, "Prune session " + sessionToRemove.id + " (" + sessionToRemove.getActivityTokenLocked() + ")"); + sessionToRemove.getActivityTokenLocked() + ")"); } } sessionToRemove.removeSelfLocked(); sessionToRemove.removeFromServiceLocked(); } } } } } } Loading
services/autofill/java/com/android/server/autofill/AutofillManagerServiceShellCommand.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -355,7 +355,7 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand { latch.countDown(); latch.countDown(); } } }; }; return requestSessionCommon(pw, latch, () -> mService.destroySessions(userId, receiver)); return requestSessionCommon(pw, latch, () -> mService.removeAllSessions(userId, receiver)); } } private int requestList(PrintWriter pw) { private int requestList(PrintWriter pw) { Loading
services/autofill/java/com/android/server/autofill/Session.java +50 −50 Original line number Original line Diff line number Diff line Loading @@ -227,8 +227,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState private boolean mHasCallback; private boolean mHasCallback; /** /** * Extras sent by service on {@code onFillRequest()} calls; the first non-null extra is saved * Extras sent by service on {@code onFillRequest()} calls; the most recent non-null extra is * and used on subsequent {@code onFillRequest()} and {@code onSaveRequest()} calls. * saved and used on subsequent {@code onFillRequest()} and {@code onSaveRequest()} calls. */ */ @GuardedBy("mLock") @GuardedBy("mLock") private Bundle mClientState; private Bundle mClientState; Loading Loading @@ -1086,7 +1086,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState if (showMessage) { if (showMessage) { getUiForShowing().showError(message, this); getUiForShowing().showError(message, this); } } removeSelf(); removeFromService(); } } // FillServiceCallbacks // FillServiceCallbacks Loading @@ -1111,7 +1111,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } } // Nothing left to do... // Nothing left to do... removeSelf(); removeFromService(); } } // FillServiceCallbacks // FillServiceCallbacks Loading Loading @@ -1147,7 +1147,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState if (showMessage) { if (showMessage) { getUiForShowing().showError(message, this); getUiForShowing().showError(message, this); } } removeSelf(); removeFromService(); } } /** /** Loading Loading @@ -1179,7 +1179,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState @Override @Override public void onServiceDied(@NonNull RemoteFillService service) { public void onServiceDied(@NonNull RemoteFillService service) { Slog.w(TAG, "removing session because service died"); Slog.w(TAG, "removing session because service died"); forceRemoveSelfLocked(); forceRemoveFromServiceLocked(); } } // AutoFillUiCallback // AutoFillUiCallback Loading @@ -1199,7 +1199,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } } fillInIntent = createAuthFillInIntentLocked(requestId, extras); fillInIntent = createAuthFillInIntentLocked(requestId, extras); if (fillInIntent == null) { if (fillInIntent == null) { forceRemoveSelfLocked(); forceRemoveFromServiceLocked(); return; return; } } } } Loading Loading @@ -1255,7 +1255,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } } } } mHandler.sendMessage(obtainMessage( mHandler.sendMessage(obtainMessage( Session::removeSelf, this)); Session::removeFromService, this)); } } // AutoFillUiCallback // AutoFillUiCallback Loading Loading @@ -1327,7 +1327,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState @Override @Override public void cancelSession() { public void cancelSession() { synchronized (mLock) { synchronized (mLock) { removeSelfLocked(); removeFromServiceLocked(); } } } } Loading @@ -1347,7 +1347,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState return; return; } } if (intent == null) { if (intent == null) { removeSelfLocked(); removeFromServiceLocked(); } } } } mHandler.sendMessage(obtainMessage( mHandler.sendMessage(obtainMessage( Loading Loading @@ -1401,13 +1401,13 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState // Typically happens when app explicitly called cancel() while the service was showing // Typically happens when app explicitly called cancel() while the service was showing // the auth UI. // the auth UI. Slog.w(TAG, "setAuthenticationResultLocked(" + authenticationId + "): no responses"); Slog.w(TAG, "setAuthenticationResultLocked(" + authenticationId + "): no responses"); removeSelf(); removeFromService(); return; return; } } final FillResponse authenticatedResponse = mResponses.get(requestId); final FillResponse authenticatedResponse = mResponses.get(requestId); if (authenticatedResponse == null || data == null) { if (authenticatedResponse == null || data == null) { Slog.w(TAG, "no authenticated response"); Slog.w(TAG, "no authenticated response"); removeSelf(); removeFromService(); return; return; } } Loading @@ -1418,7 +1418,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState final Dataset dataset = authenticatedResponse.getDatasets().get(datasetIdx); final Dataset dataset = authenticatedResponse.getDatasets().get(datasetIdx); if (dataset == null) { if (dataset == null) { Slog.w(TAG, "no dataset with index " + datasetIdx + " on fill response"); Slog.w(TAG, "no dataset with index " + datasetIdx + " on fill response"); removeSelf(); removeFromService(); return; return; } } } } Loading Loading @@ -1504,7 +1504,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState Slog.d(TAG, "Rejecting empty/invalid auth result"); Slog.d(TAG, "Rejecting empty/invalid auth result"); } } mService.resetLastAugmentedAutofillResponse(); mService.resetLastAugmentedAutofillResponse(); removeSelfLocked(); removeFromServiceLocked(); return; return; } } Loading Loading @@ -2715,7 +2715,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState return; return; } } if (sDebug) Slog.d(TAG, "Finishing session because URL bar changed"); if (sDebug) Slog.d(TAG, "Finishing session because URL bar changed"); forceRemoveSelfLocked(AutofillManager.STATE_UNKNOWN_COMPAT_MODE); forceRemoveFromServiceLocked(AutofillManager.STATE_UNKNOWN_COMPAT_MODE); return; return; } } if (!Objects.equals(value, viewState.getCurrentValue())) { if (!Objects.equals(value, viewState.getCurrentValue())) { Loading Loading @@ -3226,7 +3226,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } } // Nothing to be done, but need to notify client. // Nothing to be done, but need to notify client. notifyUnavailableToClient(AutofillManager.STATE_FINISHED, autofillableIds); notifyUnavailableToClient(AutofillManager.STATE_FINISHED, autofillableIds); removeSelf(); removeFromService(); } else { } else { if ((flags & FLAG_PASSWORD_INPUT_TYPE) != 0) { if ((flags & FLAG_PASSWORD_INPUT_TYPE) != 0) { if (sVerbose) { if (sVerbose) { Loading Loading @@ -3392,20 +3392,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState return mAugmentedAutofillDestroyer; return mAugmentedAutofillDestroyer; } } @GuardedBy("mLock") private void logAugmentedAutofillRequestLocked(int mode, ComponentName augmentedRemoteServiceName, AutofillId focusedId, boolean isWhitelisted, Boolean isInline) { final String historyItem = "aug:id=" + id + " u=" + uid + " m=" + mode + " a=" + ComponentName.flattenToShortString(mComponentName) + " f=" + focusedId + " s=" + augmentedRemoteServiceName + " w=" + isWhitelisted + " i=" + isInline; mService.getMaster().logRequestLocked(historyItem); } @GuardedBy("mLock") @GuardedBy("mLock") private void cancelAugmentedAutofillLocked() { private void cancelAugmentedAutofillLocked() { final RemoteAugmentedAutofillService remoteService = mService final RemoteAugmentedAutofillService remoteService = mService Loading Loading @@ -3574,7 +3560,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState setViewStatesLocked(null, dataset, ViewState.STATE_WAITING_DATASET_AUTH, false); setViewStatesLocked(null, dataset, ViewState.STATE_WAITING_DATASET_AUTH, false); final Intent fillInIntent = createAuthFillInIntentLocked(requestId, mClientState); final Intent fillInIntent = createAuthFillInIntentLocked(requestId, mClientState); if (fillInIntent == null) { if (fillInIntent == null) { forceRemoveSelfLocked(); forceRemoveFromServiceLocked(); return; return; } } final int authenticationId = AutofillManager.makeAuthenticationId(requestId, final int authenticationId = AutofillManager.makeAuthenticationId(requestId, Loading Loading @@ -3923,12 +3909,12 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } } /** /** * Cleans up this session. * Destroy this session and perform any clean up work. * * * <p>Typically called in 2 scenarios: * <p>Typically called in 2 scenarios: * * * <ul> * <ul> * <li>When the session naturally finishes (i.e., from {@link #removeSelfLocked()}. * <li>When the session naturally finishes (i.e., from {@link #removeFromServiceLocked()}. * <li>When the service hosting the session is finished (for example, because the user * <li>When the service hosting the session is finished (for example, because the user * disabled it). * disabled it). * </ul> * </ul> Loading Loading @@ -3990,32 +3976,32 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } } /** /** * Cleans up this session and remove it from the service always, even if it does have a pending * Destroy this session and remove it from the service always, even if it does have a pending * Save UI. * Save UI. */ */ @GuardedBy("mLock") @GuardedBy("mLock") void forceRemoveSelfLocked() { void forceRemoveFromServiceLocked() { forceRemoveSelfLocked(AutofillManager.STATE_UNKNOWN); forceRemoveFromServiceLocked(AutofillManager.STATE_UNKNOWN); } } @GuardedBy("mLock") @GuardedBy("mLock") void forceRemoveSelfIfForAugmentedAutofillOnlyLocked() { void forceRemoveFromServiceIfForAugmentedOnlyLocked() { if (sVerbose) { if (sVerbose) { Slog.v(TAG, "forceRemoveSelfIfForAugmentedAutofillOnly(" + this.id + "): " Slog.v(TAG, "forceRemoveFromServiceIfForAugmentedOnlyLocked(" + this.id + "): " + mForAugmentedAutofillOnly); + mForAugmentedAutofillOnly); } } if (!mForAugmentedAutofillOnly) return; if (!mForAugmentedAutofillOnly) return; forceRemoveSelfLocked(); forceRemoveFromServiceLocked(); } } @GuardedBy("mLock") @GuardedBy("mLock") void forceRemoveSelfLocked(int clientState) { void forceRemoveFromServiceLocked(int clientState) { if (sVerbose) Slog.v(TAG, "forceRemoveSelfLocked(): " + mPendingSaveUi); if (sVerbose) Slog.v(TAG, "forceRemoveFromServiceLocked(): " + mPendingSaveUi); final boolean isPendingSaveUi = isSaveUiPendingLocked(); final boolean isPendingSaveUi = isSaveUiPendingLocked(); mPendingSaveUi = null; mPendingSaveUi = null; removeSelfLocked(); removeFromServiceLocked(); mUi.destroyAll(mPendingSaveUi, this, false); mUi.destroyAll(mPendingSaveUi, this, false); if (!isPendingSaveUi) { if (!isPendingSaveUi) { try { try { Loading @@ -4036,28 +4022,28 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } } /** /** * Thread-safe version of {@link #removeSelfLocked()}. * Thread-safe version of {@link #removeFromServiceLocked()}. */ */ private void removeSelf() { private void removeFromService() { synchronized (mLock) { synchronized (mLock) { removeSelfLocked(); removeFromServiceLocked(); } } } } /** /** * Cleans up this session and remove it from the service, but but only if it does not have a * Destroy this session and remove it from the service, but but only if it does not have a * pending Save UI. * pending Save UI. */ */ @GuardedBy("mLock") @GuardedBy("mLock") void removeSelfLocked() { void removeFromServiceLocked() { if (sVerbose) Slog.v(TAG, "removeSelfLocked(" + this.id + "): " + mPendingSaveUi); if (sVerbose) Slog.v(TAG, "removeFromServiceLocked(" + this.id + "): " + mPendingSaveUi); if (mDestroyed) { if (mDestroyed) { Slog.w(TAG, "Call to Session#removeSelfLocked() rejected - session: " Slog.w(TAG, "Call to Session#removeFromServiceLocked() rejected - session: " + id + " destroyed"); + id + " destroyed"); return; return; } } if (isSaveUiPendingLocked()) { if (isSaveUiPendingLocked()) { Slog.i(TAG, "removeSelfLocked() ignored, waiting for pending save ui"); Slog.i(TAG, "removeFromServiceLocked() ignored, waiting for pending save ui"); return; return; } } Loading Loading @@ -4139,6 +4125,20 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState requestLog.addTaggedData(tag, value); requestLog.addTaggedData(tag, value); } } @GuardedBy("mLock") private void logAugmentedAutofillRequestLocked(int mode, ComponentName augmentedRemoteServiceName, AutofillId focusedId, boolean isWhitelisted, Boolean isInline) { final String historyItem = "aug:id=" + id + " u=" + uid + " m=" + mode + " a=" + ComponentName.flattenToShortString(mComponentName) + " f=" + focusedId + " s=" + augmentedRemoteServiceName + " w=" + isWhitelisted + " i=" + isInline; mService.getMaster().logRequestLocked(historyItem); } private void wtf(@Nullable Exception e, String fmt, Object...args) { private void wtf(@Nullable Exception e, String fmt, Object...args) { final String message = String.format(fmt, args); final String message = String.format(fmt, args); synchronized (mLock) { synchronized (mLock) { Loading