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

Commit 23c75ffd authored by Felipe Leme's avatar Felipe Leme
Browse files

New Autofill API:AutofillManager.getAutofillServiceComponentName()

Also minor fixes on isFieldClassificationEnabled() to make sure it's ignored
when not called by the service app and its calls are properly synchronized.

Test: atest CtsAutoFillServiceTestCases:LoginActivityTest#testGetAutofillServiceComponentName

Fixes: 70678279

Change-Id: I58ccb313d22c30af907f3da62f727f067240fa66
parent dfee3c8f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -48633,6 +48633,7 @@ package android.view.autofill {
    method public void cancel();
    method public void commit();
    method public void disableAutofillServices();
    method public android.content.ComponentName getAutofillServiceComponentName();
    method public android.service.autofill.UserData getUserData();
    method public boolean hasEnabledAutofillServices();
    method public boolean isAutofillSupported();
+15 −0
Original line number Diff line number Diff line
@@ -1008,6 +1008,21 @@ public final class AutofillManager {
        }
    }

    /**
     * Returns the component name of the {@link AutofillService} that is enabled for the current
     * user.
     */
    @Nullable
    public ComponentName getAutofillServiceComponentName() {
        if (mService == null) return null;

        try {
            return mService.getAutofillServiceComponentName();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Gets the user data used for
     * <a href="AutofillService.html#FieldClassification">field classification</a>.
+1 −0
Original line number Diff line number Diff line
@@ -57,4 +57,5 @@ interface IAutoFillManager {
    UserData getUserData();
    void setUserData(in UserData userData);
    boolean isFieldClassificationEnabled();
    ComponentName getAutofillServiceComponentName();
}
+26 −16
Original line number Diff line number Diff line
@@ -568,13 +568,12 @@ public final class AutofillManagerService extends SystemService {

        @Override
        public FillEventHistory getFillEventHistory() throws RemoteException {
            UserHandle user = getCallingUserHandle();
            int uid = getCallingUid();
            final int userId = UserHandle.getCallingUserId();

            synchronized (mLock) {
                AutofillManagerServiceImpl service = peekServiceForUserLocked(user.getIdentifier());
                final AutofillManagerServiceImpl service = peekServiceForUserLocked(userId);
                if (service != null) {
                    return service.getFillEventHistory(uid);
                    return service.getFillEventHistory(getCallingUid());
                }
            }

@@ -583,13 +582,12 @@ public final class AutofillManagerService extends SystemService {

        @Override
        public UserData getUserData() throws RemoteException {
            UserHandle user = getCallingUserHandle();
            int uid = getCallingUid();
            final int userId = UserHandle.getCallingUserId();

            synchronized (mLock) {
                AutofillManagerServiceImpl service = peekServiceForUserLocked(user.getIdentifier());
                final AutofillManagerServiceImpl service = peekServiceForUserLocked(userId);
                if (service != null) {
                    return service.getUserData(uid);
                    return service.getUserData(getCallingUid());
                }
            }

@@ -598,32 +596,44 @@ public final class AutofillManagerService extends SystemService {

        @Override
        public void setUserData(UserData userData) throws RemoteException {
            UserHandle user = getCallingUserHandle();
            int uid = getCallingUid();
            final int userId = UserHandle.getCallingUserId();

            synchronized (mLock) {
                AutofillManagerServiceImpl service = peekServiceForUserLocked(user.getIdentifier());
                final AutofillManagerServiceImpl service = peekServiceForUserLocked(userId);
                if (service != null) {
                    service.setUserData(uid, userData);
                    service.setUserData(getCallingUid(), userData);
                }
            }
        }

        @Override
        public boolean isFieldClassificationEnabled() throws RemoteException {
            UserHandle user = getCallingUserHandle();
            int uid = getCallingUid();
            final int userId = UserHandle.getCallingUserId();

            synchronized (mLock) {
                AutofillManagerServiceImpl service = peekServiceForUserLocked(user.getIdentifier());
                final AutofillManagerServiceImpl service = peekServiceForUserLocked(userId);
                if (service != null) {
                    return service.isFieldClassificationEnabled();
                    return service.isFieldClassificationEnabled(getCallingUid());
                }
            }

            return false;
        }

        @Override
        public ComponentName getAutofillServiceComponentName() throws RemoteException {
            final int userId = UserHandle.getCallingUserId();

            synchronized (mLock) {
                final AutofillManagerServiceImpl service = peekServiceForUserLocked(userId);
                if (service != null) {
                    return service.getServiceComponentName();
                }
            }

            return null;
        }

        @Override
        public boolean restoreSession(int sessionId, IBinder activityToken, IBinder appCallback)
                throws RemoteException {
+13 −2
Original line number Diff line number Diff line
@@ -835,7 +835,7 @@ final class AutofillManagerServiceImpl {
            pw.println(mContext.getString(R.string.config_defaultAutofillService));
        pw.print(prefix); pw.print("Disabled: "); pw.println(mDisabled);
        pw.print(prefix); pw.print("Field classification enabled: ");
            pw.println(isFieldClassificationEnabled());
            pw.println(isFieldClassificationEnabledLocked());
        pw.print(prefix); pw.print("Setup complete: "); pw.println(mSetupComplete);
        pw.print(prefix); pw.print("Last prune: "); pw.println(mLastPrune);

@@ -1095,7 +1095,18 @@ final class AutofillManagerServiceImpl {
        return false;
    }

    boolean isFieldClassificationEnabled() {
    // Called by AutofillManager, checks UID.
    boolean isFieldClassificationEnabled(int uid) {
        synchronized (mLock) {
            if (!isCalledByServiceLocked("isFieldClassificationEnabled", uid)) {
                return false;
            }
            return isFieldClassificationEnabledLocked();
        }
    }

    // Called by internally, no need to check UID.
    boolean isFieldClassificationEnabledLocked() {
        return Settings.Secure.getIntForUser(
                mContext.getContentResolver(),
                Settings.Secure.AUTOFILL_FEATURE_FIELD_CLASSIFICATION, 0,
Loading