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

Commit 4f87698d authored by Felipe Leme's avatar Felipe Leme Committed by android-build-merger
Browse files

Start a new session on manual request after session is "gone".

am: 7f33cd35

Change-Id: I1f93cea2d1699e8d388da4136c379aec4462e270
parents 122b3ce4 7f33cd35
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -862,10 +862,10 @@ public class AssistStructure implements Parcelable {
                out.writeInt(mAutofillType);
                out.writeStringArray(mAutofillHints);
                final AutofillValue sanitizedValue;
                if (mAutofillOverlay != null && mAutofillOverlay.value != null) {
                    sanitizedValue = mAutofillOverlay.value;
                } else if (writeSensitive) {
                if (writeSensitive) {
                    sanitizedValue = mAutofillValue;
                } else if (mAutofillOverlay != null && mAutofillOverlay.value != null) {
                    sanitizedValue = mAutofillOverlay.value;
                } else {
                    sanitizedValue = null;
                }
+19 −2
Original line number Diff line number Diff line
@@ -804,9 +804,26 @@ public final class AutofillManager {
                    + ", value=" + value + ", action=" + action + ", flags=" + flags);
        }

        boolean restartIfNecessary = (flags & FLAG_MANUAL_REQUEST) != 0;

        try {
            if (restartIfNecessary) {
                final int newId = mService.updateOrRestartSession(mContext.getActivityToken(),
                        mServiceClient.asBinder(), id, bounds, value, mContext.getUserId(),
                        mCallback != null, flags, mContext.getOpPackageName(), mSessionId, action);
                if (newId != mSessionId) {
                    if (sDebug) Log.d(TAG, "Session restarted: " + mSessionId + "=>" + newId);
                    mSessionId = newId;
                    final AutofillClient client = getClientLocked();
                    if (client != null) {
                        client.autofillCallbackResetableStateAvailable();
                    }
                }
            } else {
                mService.updateSession(mSessionId, id, bounds, value, action, flags,
                        mContext.getUserId());
            }

        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+3 −0
Original line number Diff line number Diff line
@@ -39,6 +39,9 @@ interface IAutoFillManager {
    boolean restoreSession(int sessionId, in IBinder activityToken, in IBinder appCallback);
    void updateSession(int sessionId, in AutofillId id, in Rect bounds,
            in AutofillValue value, int action, int flags, int userId);
    int updateOrRestartSession(IBinder activityToken, in IBinder appCallback,
            in AutofillId autoFillId, in Rect bounds, in AutofillValue value, int userId,
            boolean hasCallback, int flags, String packageName, int sessionId, int action);
    void finishSession(int sessionId, int userId);
    void cancelSession(int sessionId, int userId);
    void setAuthenticationResult(in Bundle data, int sessionId, int authenticationId, int userId);
+24 −4
Original line number Diff line number Diff line
@@ -172,7 +172,6 @@ public final class AutofillManagerService extends SystemService {
        startTrackingPackageChanges();
    }


    private void startTrackingPackageChanges() {
        PackageMonitor monitor = new PackageMonitor() {
            @Override
@@ -559,15 +558,36 @@ public final class AutofillManagerService extends SystemService {
        }

        @Override
        public void updateSession(int sessionId, AutofillId id, Rect bounds,
        public void updateSession(int sessionId, AutofillId autoFillId, Rect bounds,
                AutofillValue value, int action, int flags, int userId) {
            synchronized (mLock) {
                final AutofillManagerServiceImpl service = peekServiceForUserLocked(userId);
                if (service != null) {
                    service.updateSessionLocked(sessionId, getCallingUid(), id, bounds, value,
                            action, flags);
                    service.updateSessionLocked(sessionId, getCallingUid(), autoFillId, bounds,
                            value, action, flags);
                }
            }
        }

        @Override
        public int updateOrRestartSession(IBinder activityToken, IBinder appCallback,
                AutofillId autoFillId, Rect bounds, AutofillValue value, int userId,
                boolean hasCallback, int flags, String packageName, int sessionId, int action) {
            boolean restart = false;
            synchronized (mLock) {
                final AutofillManagerServiceImpl service = peekServiceForUserLocked(userId);
                if (service != null) {
                    restart = service.updateSessionLocked(sessionId, getCallingUid(), autoFillId,
                            bounds, value, action, flags);
                }
            }
            if (restart) {
                return startSession(activityToken, appCallback, autoFillId, bounds, value, userId,
                        hasCallback, flags, packageName);
            }

            // Nothing changed...
            return sessionId;
        }

        @Override
+18 −7
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.autofill;

import static android.service.autofill.FillRequest.FLAG_MANUAL_REQUEST;
import static android.view.autofill.AutofillManager.ACTION_START_SESSION;
import static android.view.autofill.AutofillManager.NO_SESSION;

@@ -275,7 +276,7 @@ final class AutofillManagerServiceImpl {
        pruneAbandonedSessionsLocked();

        final Session newSession = createSessionByTokenLocked(activityToken, uid, appCallbackToken,
                hasCallback, flags, packageName);
                hasCallback, packageName);
        if (newSession == null) {
            return NO_SESSION;
        }
@@ -359,8 +360,7 @@ final class AutofillManagerServiceImpl {
    }

    private Session createSessionByTokenLocked(@NonNull IBinder activityToken, int uid,
            @NonNull IBinder appCallbackToken, boolean hasCallback, int flags,
            @NonNull String packageName) {
            @NonNull IBinder appCallbackToken, boolean hasCallback, @NonNull String packageName) {
        // use random ids so that one app cannot know that another app creates sessions
        int sessionId;
        int tries = 0;
@@ -402,18 +402,29 @@ final class AutofillManagerServiceImpl {
        }
    }

    void updateSessionLocked(int sessionId, int uid, AutofillId autofillId, Rect virtualBounds,
    /**
     * Updates a session and returns whether it should be restarted.
     */
    boolean updateSessionLocked(int sessionId, int uid, AutofillId autofillId, Rect virtualBounds,
            AutofillValue value, int action, int flags) {
        final Session session = mSessions.get(sessionId);
        if (session == null || session.uid != uid) {
            if ((flags & FLAG_MANUAL_REQUEST) != 0) {
                if (sDebug) {
                    Slog.d(TAG, "restarting session " + sessionId + " due to manual request on "
                            + autofillId);
                }
                return true;
            }
            if (sVerbose) {
                Slog.v(TAG, "updateSessionLocked(): session gone for " + sessionId + "(" + uid
                        + ")");
                Slog.v(TAG, "updateSessionLocked(): session gone for " + sessionId
                        + "(" + uid + ")");
            }
            return;
            return false;
        }

        session.updateLocked(autofillId, virtualBounds, value, action, flags);
        return false;
    }

    void removeSessionLocked(int sessionId) {