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

Commit 2a44159e authored by Felipe Leme's avatar Felipe Leme
Browse files

Minor Autofill improvements:

- Removed unused getServiceName() code.
- Removed redundant if (disabled) check.
- Added sanity check for getServiceLabel() / getServiceIcon().

Bug: 117779333
Test: atest CtsAutoFillServiceTestCases

Change-Id: I4c7a394725bcd3f448c200576bb2ca012d4f5f18
parent b49d8ec1
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -181,10 +181,8 @@ public final class AutofillManagerService extends SystemService {
        for (int i = 0; i < users.size(); i++) {
            final int userId = users.get(i).id;
            final boolean disabled = umi.getUserRestriction(userId, UserManager.DISALLOW_AUTOFILL);
            if (disabled) {
            if (disabled) {
                Slog.i(TAG, "Disabling Autofill for user " + userId);
                }
                mDisabledUsers.put(userId, disabled);
            }
        }
+18 −24
Original line number Diff line number Diff line
@@ -185,23 +185,6 @@ final class AutofillManagerServiceImpl {
        updateLocked(disabled);
    }

    @Nullable
    CharSequence getServiceName() {
        final String packageName = getServicePackageName();
        if (packageName == null) {
            return null;
        }

        try {
            final PackageManager pm = mContext.getPackageManager();
            final ApplicationInfo info = pm.getApplicationInfo(packageName, 0);
            return pm.getApplicationLabel(info);
        } catch (Exception e) {
            Slog.e(TAG, "Could not get label for " + packageName + ": " + e);
            return packageName;
        }
    }

    @GuardedBy("mLock")
    private int getServiceUidLocked() {
        if (mInfo == null) {
@@ -226,6 +209,7 @@ final class AutofillManagerServiceImpl {
        return null;
    }

    @Nullable
    ComponentName getServiceComponentName() {
        synchronized (mLock) {
            if (mInfo == null) {
@@ -706,17 +690,27 @@ final class AutofillManagerServiceImpl {
        }
    }

    @NonNull
    CharSequence getServiceLabel() {
        final CharSequence label = mInfo.getServiceInfo().loadSafeLabel(
    /**
     * Gets the user-visibile name of the service this service binds to, or {@code null} if the
     * service is disabled.
     */
    @Nullable
    @GuardedBy("mLock")
    public CharSequence getServiceLabelLocked() {
        return mInfo == null ? null : mInfo.getServiceInfo().loadSafeLabel(
                mContext.getPackageManager(), 0 /* do not ellipsize */,
                PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE | PackageItemInfo.SAFE_LABEL_FLAG_TRIM);
        return label;
    }

    /**
     * Gets the icon of the service this service binds to, or {@code null} if the service is
     * disabled.
     */
    @NonNull
    Drawable getServiceIcon() {
        return mInfo.getServiceInfo().loadIcon(mContext.getPackageManager());
    @Nullable
    @GuardedBy("mLock")
    Drawable getServiceIconLocked() {
        return mInfo == null ? null : mInfo.getServiceInfo().loadIcon(mContext.getPackageManager());
    }

    /**
@@ -959,7 +953,7 @@ final class AutofillManagerServiceImpl {
        } else {
            pw.println();
            mInfo.dump(prefix2, pw);
            pw.print(prefix); pw.print("Service Label: "); pw.println(getServiceLabel());
            pw.print(prefix); pw.print("Service Label: "); pw.println(getServiceLabelLocked());
            pw.print(prefix); pw.print("Target SDK: "); pw.println(getTargedSdkLocked());
        }
        pw.print(prefix); pw.print("Component from settings: ");
+24 −8
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import android.content.Intent;
import android.content.IntentSender;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.metrics.LogMaker;
import android.os.Binder;
import android.os.Build;
@@ -1749,7 +1750,18 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState

                final IAutoFillManagerClient client = getClient();
                mPendingSaveUi = new PendingUi(mActivityToken, id, client);
                getUiForShowing().showSaveUi(mService.getServiceLabel(), mService.getServiceIcon(),

                final CharSequence serviceLabel;
                final Drawable serviceIcon;
                synchronized (mLock) {
                    serviceLabel = mService.getServiceLabelLocked();
                    serviceIcon = mService.getServiceIconLocked();
                }
                if (serviceLabel == null || serviceIcon == null) {
                    wtf(null, "showSaveLocked(): no service label or icon");
                    return true;
                }
                getUiForShowing().showSaveUi(serviceLabel, serviceIcon,
                        mService.getServicePackageName(), saveInfo, this,
                        mComponentName, this, mPendingSaveUi, isUpdate, mCompatMode);
                if (client != null) {
@@ -2318,9 +2330,19 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
            filterText = value.getTextValue().toString();
        }

        final CharSequence serviceLabel;
        final Drawable serviceIcon;
        synchronized (mLock) {
            serviceLabel = mService.getServiceLabelLocked();
            serviceIcon = mService.getServiceIconLocked();
        }
        if (serviceLabel == null || serviceIcon == null) {
            wtf(null, "onFillReady(): no service label or icon");
            return;
        }
        getUiForShowing().showFillUi(filledId, response, filterText,
                mService.getServicePackageName(), mComponentName,
                mService.getServiceLabel(), mService.getServiceIcon(), this, id, mCompatMode);
                serviceLabel, serviceIcon, this, id, mCompatMode);

        synchronized (mLock) {
            if (mUiShownTime == 0) {
@@ -2655,12 +2677,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        }
    }

    CharSequence getServiceName() {
        synchronized (mLock) {
            return mService.getServiceName();
        }
    }

    // TODO: this should never be null, but we got at least one occurrence, probably due to a race.
    @GuardedBy("mLock")
    @Nullable
+0 −4
Original line number Diff line number Diff line
@@ -141,10 +141,6 @@ final class ViewState {
        mResponse = response;
    }

    CharSequence getServiceName() {
        return mSession.getServiceName();
    }

    int getState() {
        return mState;
    }