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

Commit 78e74aec authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Restricts ContentCapture and AugmentedAutofill when using temporary services."

parents 721df801 6430cbc8
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.graphics.Rect;
import android.metrics.LogMaker;
import android.os.AsyncTask;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@@ -1212,6 +1213,18 @@ final class AutofillManagerServiceImpl

    @GuardedBy("mLock")
    boolean isWhitelistedForAugmentedAutofillLocked(@NonNull ComponentName componentName) {
        if (Build.IS_USER && mMaster.mAugmentedAutofillResolver.isTemporary(mUserId)) {
            final String serviceName = mMaster.mAugmentedAutofillResolver.getServiceName(mUserId);
            final ComponentName component = ComponentName.unflattenFromString(serviceName);
            final String servicePackage = component == null ? null : component.getPackageName();
            final String packageName = componentName.getPackageName();
            if (!packageName.equals(servicePackage)) {
                Slog.w(TAG, "Ignoring package " + packageName + " for augmented autofill while "
                        + "using temporary service " + servicePackage);
                return false;
            }
        }

        return mAugmentedWhitelistHelper.isWhitelisted(componentName);
    }

+18 −16
Original line number Diff line number Diff line
@@ -2659,17 +2659,16 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        mAugmentedAutofillDestroyer = triggerAugmentedAutofillLocked();
        if (mAugmentedAutofillDestroyer == null) {
            if (sVerbose) {
                Slog.v(TAG, "canceling session " + id + " when server returned null and there is no"
                        + " AugmentedAutofill for user. AutofillableIds: " + autofillableIds);
                Slog.v(TAG, "canceling session " + id + " when service returned null and it cannot "
                        + "be augmented. AutofillableIds: " + autofillableIds);
            }
            // Nothing to be done, but need to notify client.
            notifyUnavailableToClient(AutofillManager.STATE_FINISHED, autofillableIds);
            removeSelf();
        } else {
            if (sVerbose) {
                Slog.v(TAG, "keeping session " + id + " when server returned null but "
                        + "there is an AugmentedAutofill for user. AutofillableIds: "
                        + autofillableIds);
                Slog.v(TAG, "keeping session " + id + " when service returned null but "
                        + "it can be augmented. AutofillableIds: " + autofillableIds);
            }
            mAugmentedAutofillableIds = autofillableIds;
        }
@@ -2687,7 +2686,10 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        // Check if Smart Suggestions is supported...
        final @SmartSuggestionMode int supportedModes = mService
                .getSupportedSmartSuggestionModesLocked();
        if (supportedModes == 0) return null;
        if (supportedModes == 0) {
            if (sVerbose) Slog.v(TAG, "triggerAugmentedAutofillLocked(): no supported modes");
            return null;
        }

        // ...then if the service is set for the user

@@ -2712,14 +2714,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
            return null;
        }

        if (sVerbose) {
            Slog.v(TAG, "calling Augmented Autofill Service ("
                    + remoteService.getComponentName().toShortString() + ") on view "
                    + mCurrentViewId + " using suggestion mode "
                    + getSmartSuggestionModeToString(mode)
                    + " when server returned null for session " + this.id);
        }

        final boolean isWhitelisted = mService
                .isWhitelistedForAugmentedAutofillLocked(mComponentName);

@@ -2733,12 +2727,20 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState

        if (!isWhitelisted) {
            if (sVerbose) {
                Slog.v(TAG, mComponentName.toShortString() + " is not whitelisted for "
                        + "augmented autofill");
                Slog.v(TAG, "triggerAugmentedAutofillLocked(): "
                        + ComponentName.flattenToShortString(mComponentName) + " not whitelisted ");
            }
            return null;
        }

        if (sVerbose) {
            Slog.v(TAG, "calling Augmented Autofill Service ("
                    + ComponentName.flattenToShortString(remoteService.getComponentName())
                    + ") on view " + mCurrentViewId + " using suggestion mode "
                    + getSmartSuggestionModeToString(mode)
                    + " when server returned null for session " + this.id);
        }

        final ViewState viewState = mViewStates.get(mCurrentViewId);
        viewState.setState(ViewState.STATE_TRIGGERED_AUGMENTED_AUTOFILL);
        final AutofillValue currentValue = viewState.getCurrentValue();
+10 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ServiceInfo;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.os.UserHandle;
@@ -455,6 +456,7 @@ final class ContentCapturePerUserService
    }

    @GuardedBy("mLock")
    @Nullable
    ContentCaptureOptions getOptionsForPackageLocked(@NonNull String packageName) {
        if (!mWhitelistHelper.isWhitelisted(packageName)) {
            if (mMaster.verbose) {
@@ -465,6 +467,14 @@ final class ContentCapturePerUserService

        final ArraySet<ComponentName> whitelistedComponents = mWhitelistHelper
                .getWhitelistedComponents(packageName);
        if (Build.IS_USER && isTemporaryServiceSetLocked()) {
            final String servicePackageName = getServicePackageName();
            if (!packageName.equals(servicePackageName)) {
                Slog.w(mTag, "Ignoring package " + packageName
                        + " while using temporary service " + servicePackageName);
                return null;
            }
        }
        ContentCaptureOptions options = new ContentCaptureOptions(mMaster.mDevCfgLoggingLevel,
                mMaster.mDevCfgMaxBufferSize, mMaster.mDevCfgIdleFlushingFrequencyMs,
                mMaster.mDevCfgTextChangeFlushingFrequencyMs, mMaster.mDevCfgLogHistorySize,