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

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

Merge "Auto-fill logging improvements:"

parents 13a80432 0ab53dcb
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.view.autofill;

import static android.view.autofill.Helper.DEBUG;
import static android.view.autofill.Helper.VERBOSE;

import android.content.Context;
import android.content.Intent;
@@ -255,7 +256,7 @@ public final class AutoFillManager {
    private void startSession(AutoFillId id, IBinder windowToken,
            Rect bounds, AutoFillValue value) {
        if (DEBUG) {
            Log.v(TAG, "startSession(): id=" + id + ", bounds=" + bounds + ", value=" + value);
            Log.d(TAG, "startSession(): id=" + id + ", bounds=" + bounds + ", value=" + value);
        }
        try {
            mService.startSession(mContext.getActivityToken(), windowToken,
@@ -272,7 +273,7 @@ public final class AutoFillManager {

    private void finishSession() {
        if (DEBUG) {
            Log.v(TAG, "finishSession()");
            Log.d(TAG, "finishSession()");
        }
        mHasSession = false;
        try {
@@ -284,9 +285,12 @@ public final class AutoFillManager {

    private void updateSession(AutoFillId id, Rect bounds, AutoFillValue value, int flags) {
        if (DEBUG) {
            Log.v(TAG, "updateSession(): id=" + id + ", bounds=" + bounds + ", value=" + value
            if (VERBOSE || (flags & FLAG_FOCUS_LOST) != 0) {
                Log.d(TAG, "updateSession(): id=" + id + ", bounds=" + bounds + ", value=" + value
                    + ", flags=" + flags);
            }
        }

        try {
            mService.updateSession(mContext.getActivityToken(), id, bounds, value, flags,
                    mContext.getUserId());
+7 −16
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.server.autofill;

import static android.Manifest.permission.MANAGE_AUTO_FILL;
import static android.content.Context.AUTO_FILL_MANAGER_SERVICE;
import static com.android.server.autofill.Helper.DEBUG;
import static com.android.server.autofill.Helper.VERBOSE;

import android.Manifest;
@@ -101,14 +100,16 @@ public final class AutoFillManagerService extends SystemService {
    private SparseArray<AutoFillManagerServiceImpl> mServicesCache = new SparseArray<>();

    // TODO(b/33197203): set a different max (or disable it) on low-memory devices.
    private final LocalLog mRequestsHistory = new LocalLog(100);
    private final LocalLog mRequestsHistory = new LocalLog(20);

    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(intent.getAction())) {
                final String reason = intent.getStringExtra("reason");
                if (DEBUG) Slog.d(TAG, "close system dialogs: " + reason);
                if (VERBOSE) {
                    Slog.v(TAG, "close system dialogs: " + reason);
                }
                mUi.hideAll();
            }
        }
@@ -247,7 +248,9 @@ public final class AutoFillManagerService extends SystemService {
    private IBinder getTopActivityForUser() {
        final List<IBinder> topActivities = LocalServices
                .getService(ActivityManagerInternal.class).getTopVisibleActivities();
        if (DEBUG) Slog.d(TAG, "Top activities (" + topActivities.size() + "): " + topActivities);
        if (VERBOSE) {
            Slog.v(TAG, "Top activities (" + topActivities.size() + "): " + topActivities);
        }
        if (topActivities.isEmpty()) {
            Slog.w(TAG, "Could not get top activity");
            return null;
@@ -276,11 +279,6 @@ public final class AutoFillManagerService extends SystemService {
                AutoFillId autoFillId, Rect bounds, AutoFillValue value, int userId) {
            // TODO(b/33197203): make sure it's called by resumed / focused activity

            if (VERBOSE) {
                Slog.v(TAG, "startSession: autoFillId=" + autoFillId + ", bounds=" + bounds
                        + ", value=" + value);
            }

            synchronized (mLock) {
                final AutoFillManagerServiceImpl service = getServiceForUserLocked(userId);
                service.startSessionLocked(activityToken, windowToken, appCallback,
@@ -291,11 +289,6 @@ public final class AutoFillManagerService extends SystemService {
        @Override
        public void updateSession(IBinder activityToken, AutoFillId id, Rect bounds,
                AutoFillValue value, int flags, int userId) {
            if (DEBUG) {
                Slog.d(TAG, "updateSession: flags=" + flags + ", autoFillId=" + id
                        + ", bounds=" + bounds + ", value=" + value);
            }

            synchronized (mLock) {
                final AutoFillManagerServiceImpl service = mServicesCache.get(
                        UserHandle.getCallingUserId());
@@ -307,8 +300,6 @@ public final class AutoFillManagerService extends SystemService {

        @Override
        public void finishSession(IBinder activityToken, int userId) {
            if (VERBOSE) Slog.v(TAG, "finishSession(): " + activityToken);

            synchronized (mLock) {
                final AutoFillManagerServiceImpl service = mServicesCache.get(
                        UserHandle.getCallingUserId());
+54 −36
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ final class AutoFillManagerServiceImpl {
                handleSessionSave((IBinder) msg.obj);
                break;
            default:
                Slog.d(TAG, "invalid msg: " + msg);
                Slog.w(TAG, "invalid msg on handler: " + msg);
        }
    };

@@ -128,17 +128,18 @@ final class AutoFillManagerServiceImpl {
    private final IResultReceiver mAssistReceiver = new IResultReceiver.Stub() {
        @Override
        public void send(int resultCode, Bundle resultData) throws RemoteException {
            if (DEBUG) Slog.d(TAG, "resultCode on mAssistReceiver: " + resultCode);
            if (VERBOSE) {
                Slog.v(TAG, "resultCode on mAssistReceiver: " + resultCode);
            }

            final AssistStructure structure = resultData.getParcelable(KEY_STRUCTURE);
            if (structure == null) {
                Slog.w(TAG, "no assist structure for id " + resultCode);
                Slog.wtf(TAG, "no assist structure for id " + resultCode);
                return;
            }

            final Bundle receiverExtras = resultData.getBundle(KEY_RECEIVER_EXTRAS);
            if (receiverExtras == null) {
                // Should not happen
                Slog.wtf(TAG, "No " + KEY_RECEIVER_EXTRAS + " on receiver");
                return;
            }
@@ -195,7 +196,7 @@ final class AutoFillManagerServiceImpl {
            final ApplicationInfo info = pm.getApplicationInfo(packageName, 0);
            return pm.getApplicationLabel(info);
        } catch (Exception e) {
            Slog.w(TAG, "Could not get label for " + packageName + ": " + e);
            Slog.e(TAG, "Could not get label for " + packageName + ": " + e);
            return packageName;
        }
    }
@@ -211,7 +212,7 @@ final class AutoFillManagerServiceImpl {
                serviceInfo = AppGlobals.getPackageManager().getServiceInfo(serviceComponent,
                        0, mUserId);
            } catch (RuntimeException | RemoteException e) {
                Slog.e(TAG, "Bad auto-fill service name " + componentName, e);
                Slog.e(TAG, "Bad auto-fill service name " + componentName + ": " + e);
                return;
            }
        }
@@ -235,7 +236,7 @@ final class AutoFillManagerServiceImpl {
                sendStateToClients();
            }
        } catch (PackageManager.NameNotFoundException e) {
            Slog.e(TAG, "Bad auto-fill service name " + componentName, e);
            Slog.e(TAG, "Bad auto-fill service name " + componentName + ": " + e);
        }
    }

@@ -279,9 +280,9 @@ final class AutoFillManagerServiceImpl {
            return;
        }

        final String historyItem = "s=" + new ComponentName(mInfo.getServiceInfo().packageName,
                mInfo.getServiceInfo().name) + " u=" + mUserId + " a=" + activityToken
                + " i=" + autoFillId + " b=" + bounds + " v=" + value;
        final String historyItem = "s=" + mInfo.getServiceInfo().packageName
                + " u=" + mUserId + " a=" + activityToken
                + " i=" + autoFillId + " b=" + bounds;
        mRequestsHistory.log(historyItem);

        // TODO(b/33197203): Handle partitioning
@@ -331,8 +332,6 @@ final class AutoFillManagerServiceImpl {
            try {
                if (!ActivityManager.getService().requestAutoFillData(mAssistReceiver,
                        receiverExtras, activityToken)) {
                    // TODO(b/33197203): might need a way to warn user (perhaps a new method on
                    // AutoFillService).
                    Slog.w(TAG, "failed to request auto-fill data for " + activityToken);
                }
            } finally {
@@ -349,7 +348,9 @@ final class AutoFillManagerServiceImpl {
        // TODO(b/33197203): add MetricsLogger call
        final Session session = mSessions.get(activityToken);
        if (session == null) {
            Slog.w(TAG, "updateSessionLocked(): session gone for " + activityToken);
            if (VERBOSE) {
                Slog.v(TAG, "updateSessionLocked(): session gone for " + activityToken);
            }
            return;
        }

@@ -369,7 +370,9 @@ final class AutoFillManagerServiceImpl {
    }

    void destroyLocked() {
        if (VERBOSE) Slog.v(TAG, "destroyLocked()");
        if (VERBOSE) {
            Slog.v(TAG, "destroyLocked()");
        }

        for (Session session : mSessions.values()) {
            session.destroyLocked();
@@ -380,7 +383,7 @@ final class AutoFillManagerServiceImpl {
    void dumpLocked(String prefix, PrintWriter pw) {
        final String prefix2 = prefix + "  ";

        pw.print(prefix); pw.println("Component:"); pw.println(mInfo != null
        pw.print(prefix); pw.print("Component:"); pw.println(mInfo != null
                ? mInfo.getServiceInfo().getComponentName() : null);

        if (VERBOSE) {
@@ -526,8 +529,6 @@ final class AutoFillManagerServiceImpl {

        @Override
        public String toString() {
            if (!DEBUG) return super.toString();

            return "ViewState: [id=" + mId + ", value=" + mAutoFillValue + ", bounds=" + mBounds
                    + ", updated = " + mValueUpdated + "]";
        }
@@ -602,7 +603,9 @@ final class AutoFillManagerServiceImpl {
            mClient = IAutoFillManagerClient.Stub.asInterface(client);
            try {
                client.linkToDeath(() -> {
                    if (DEBUG) Slog.d(TAG, "app binder died");
                    if (DEBUG) {
                        Slog.d(TAG, "app binder died");
                    }

                    removeSelf();
                }, 0);
@@ -705,20 +708,23 @@ final class AutoFillManagerServiceImpl {
         */
        public void showSaveLocked() {
            if (mStructure == null) {
                // Sanity check; should not happen...
                Slog.wtf(TAG, "showSaveLocked(): no mStructure");
                return;
            }
            if (mCurrentResponse == null) {
                // Happens when the activity / session was finished before the service replied.
                Slog.d(TAG, "showSaveLocked(): no mCurrentResponse yet");
                // Happens when the activity / session was finished before the service replied, or
                // when the service cannot auto-fill it (and returned a null response).
                if (DEBUG) {
                    Slog.d(TAG, "showSaveLocked(): no mCurrentResponse");
                }
                return;
            }
            final ArraySet<AutoFillId> savableIds = mCurrentResponse.getSavableIds();
            if (VERBOSE) Slog.v(TAG, "showSaveLocked(): savableIds=" + savableIds);
            if (DEBUG) {
                Slog.d(TAG, "showSaveLocked(): savableIds=" + savableIds);
            }

            if (savableIds.isEmpty()) {
                if (DEBUG) Slog.d(TAG, "showSaveLocked(): service doesn't want to save");
            if (savableIds == null || savableIds.isEmpty()) {
                return;
            }

@@ -742,21 +748,27 @@ final class AutoFillManagerServiceImpl {
            }

            // Nothing changed...
            if (DEBUG) Slog.d(TAG, "showSaveLocked(): with no changes, comes no responsibilities");
            if (DEBUG) {
                Slog.d(TAG, "showSaveLocked(): with no changes, comes no responsibilities");
            }
        }

        /**
         * Calls service when user requested save.
         */
        private void callSaveLocked() {
            if (DEBUG) Slog.d(TAG, "callSaveLocked(): mViewStates=" + mViewStates);
            if (DEBUG) {
                Slog.d(TAG, "callSaveLocked(): mViewStates=" + mViewStates);
            }

            final Bundle extras = this.mCurrentResponse.getExtras();

            for (Entry<AutoFillId, ViewState> entry : mViewStates.entrySet()) {
                final AutoFillValue value = entry.getValue().mAutoFillValue;
                if (value == null) {
                    if (VERBOSE) Slog.v(TAG, "callSaveLocked(): skipping " + entry.getKey());
                    if (VERBOSE) {
                        Slog.v(TAG, "callSaveLocked(): skipping " + entry.getKey());
                    }
                    continue;
                }
                final AutoFillId id = entry.getKey();
@@ -765,7 +777,9 @@ final class AutoFillManagerServiceImpl {
                    Slog.w(TAG, "callSaveLocked(): did not find node with id " + id);
                    continue;
                }
                if (DEBUG) Slog.d(TAG, "callSaveLocked(): updating " + id + " to " + value);
                if (VERBOSE) {
                    Slog.v(TAG, "callSaveLocked(): updating " + id + " to " + value);
                }

                node.updateAutoFillValue(value);
            }
@@ -781,11 +795,9 @@ final class AutoFillManagerServiceImpl {
        }

        void updateLocked(AutoFillId id, Rect bounds, AutoFillValue value, int flags) {
            if (DEBUG) Slog.d(TAG, "updateLocked(): id=" + id + ", flags=" + flags);

            if (mAutoFilledDataset != null && (flags & FLAG_VALUE_CHANGED) == 0) {
                // TODO(b/33197203): ignoring because we don't support partitions yet
                if (DEBUG) Slog.d(TAG, "updateLocked(): ignoring " + flags + " after auto-filled");
                Slog.d(TAG, "updateLocked(): ignoring " + flags + " after app was auto-filled");
                return;
            }

@@ -852,7 +864,7 @@ final class AutoFillManagerServiceImpl {
                return;
            }

            Slog.w(TAG, "unknown flags " + flags);
            Slog.w(TAG, "updateLocked(): unknown flags " + flags);
        }

        @Override
@@ -871,8 +883,10 @@ final class AutoFillManagerServiceImpl {
        }

        private void processResponseLocked(FillResponse response) {
            if (DEBUG) Slog.d(TAG, "processResponseLocked(authRequired="
                    + response.getAuthentication() + "):" + response);
            if (DEBUG) {
                Slog.d(TAG, "processResponseLocked(auth=" + response.getAuthentication()
                    + "):" + response);
            }

            // TODO(b/33197203): add MetricsLogger calls

@@ -956,7 +970,9 @@ final class AutoFillManagerServiceImpl {
        void autoFillApp(Dataset dataset) {
            synchronized (mLock) {
                try {
                    if (DEBUG) Slog.d(TAG, "autoFillApp(): the buck is on the app: " + dataset);
                    if (DEBUG) {
                        Slog.d(TAG, "autoFillApp(): the buck is on the app: " + dataset);
                    }
                    mClient.autoFill(dataset.getFieldIds(), dataset.getFieldValues());
                } catch (RemoteException e) {
                    Slog.w(TAG, "Error auto-filling activity: " + e);
@@ -1010,7 +1026,9 @@ final class AutoFillManagerServiceImpl {
        }

        private void removeSelf() {
            if (VERBOSE) Slog.v(TAG, "removeSelf()");
            if (VERBOSE) {
                Slog.v(TAG, "removeSelf()");
            }

            synchronized (mLock) {
                destroyLocked();