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

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

Merge "Cosmetic ContentCapture fixes."

parents 43078a9d af1a0e75
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
 */
public abstract class ContentCaptureSession implements AutoCloseable {

    private static final String TAG = ContentCaptureSession.class.getSimpleName();

    /**
     * Used on {@link #notifyViewTextChanged(AutofillId, CharSequence, int)} to indicate that the
     *
@@ -86,9 +88,6 @@ public abstract class ContentCaptureSession implements AutoCloseable {

    private static final int INITIAL_CHILDREN_CAPACITY = 5;

    /** @hide */
    protected final String mTag = getClass().getSimpleName();

    private final CloseGuard mCloseGuard = CloseGuard.get();

    /**
@@ -141,7 +140,7 @@ public abstract class ContentCaptureSession implements AutoCloseable {
            @NonNull ContentCaptureContext context) {
        final ContentCaptureSession child = newChild(context);
        if (DEBUG) {
            Log.d(mTag, "createContentCaptureSession(" + context + ": parent=" + mId + ", child= "
            Log.d(TAG, "createContentCaptureSession(" + context + ": parent=" + mId + ", child="
                    + child.mId);
        }
        if (mChildren == null) {
@@ -165,7 +164,7 @@ public abstract class ContentCaptureSession implements AutoCloseable {
     */
    public final void destroy() {
        if (!mDestroyed.compareAndSet(false, true)) {
            Log.e(mTag, "destroy(): already destroyed");
            Log.e(TAG, "destroy(): already destroyed");
            return;
        }

@@ -174,19 +173,19 @@ public abstract class ContentCaptureSession implements AutoCloseable {
        //TODO(b/111276913): check state (for example, how to handle if it's waiting for remote
        // id) and send it to the cache of batched commands
        if (VERBOSE) {
            Log.v(mTag, "destroy(): state=" + getStateAsString(mState) + ", mId=" + mId);
            Log.v(TAG, "destroy(): state=" + getStateAsString(mState) + ", mId=" + mId);
        }

        // Finish children first
        if (mChildren != null) {
            final int numberChildren = mChildren.size();
            if (VERBOSE) Log.v(mTag, "Destroying " + numberChildren + " children first");
            if (VERBOSE) Log.v(TAG, "Destroying " + numberChildren + " children first");
            for (int i = 0; i < numberChildren; i++) {
                final ContentCaptureSession child = mChildren.get(i);
                try {
                    child.destroy();
                } catch (Exception e) {
                    Log.w(mTag, "exception destroying child session #" + i + ": " + e);
                    Log.w(TAG, "exception destroying child session #" + i + ": " + e);
                }
            }
        }
@@ -311,11 +310,12 @@ public abstract class ContentCaptureSession implements AutoCloseable {

    @CallSuper
    void dump(@NonNull String prefix, @NonNull PrintWriter pw) {
        pw.print(prefix); pw.print("id: "); pw.println(mId);
        pw.print(prefix); pw.print("destroyed: "); pw.println(mDestroyed.get());
        if (mChildren != null && !mChildren.isEmpty()) {
            final String prefix2 = prefix + "  ";
            final int numberChildren = mChildren.size();
            pw.print(prefix); pw.print("number children: "); pw.print(numberChildren);
            pw.print(prefix); pw.print("number children: "); pw.println(numberChildren);
            for (int i = 0; i < numberChildren; i++) {
                final ContentCaptureSession child = mChildren.get(i);
                pw.print(prefix); pw.print(i); pw.println(": "); child.dump(prefix2, pw);
+20 −26
Original line number Diff line number Diff line
@@ -63,6 +63,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
 */
public final class MainContentCaptureSession extends ContentCaptureSession {

    private static final String TAG = MainContentCaptureSession.class.getSimpleName();

    /**
     * Handler message used to flush the buffer.
     */
@@ -128,9 +130,6 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
    // Used just for debugging purposes (on dump)
    private long mNextFlush;

    // Lazily created on demand.
    private ContentCaptureSessionId mContentCaptureSessionId;

    /** @hide */
    protected MainContentCaptureSession(@NonNull Context context, @NonNull Handler handler,
            @Nullable IContentCaptureManager systemServerInterface,
@@ -157,7 +156,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
        if (!isContentCaptureEnabled()) return;

        if (VERBOSE) {
            Log.v(mTag, "start(): token=" + applicationToken + ", comp="
            Log.v(TAG, "start(): token=" + applicationToken + ", comp="
                    + ComponentName.flattenToShortString(activityComponent));
        }

@@ -179,7 +178,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
    private void handleStartSession(@NonNull IBinder token, @NonNull ComponentName componentName) {
        if (mState != STATE_UNKNOWN) {
            // TODO(b/111276913): revisit this scenario
            Log.w(mTag, "ignoring handleStartSession(" + token + ") while on state "
            Log.w(TAG, "ignoring handleStartSession(" + token + ") while on state "
                    + getStateAsString(mState));
            return;
        }
@@ -188,7 +187,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
        mComponentName = componentName;

        if (VERBOSE) {
            Log.v(mTag, "handleStartSession(): token=" + token + ", act="
            Log.v(TAG, "handleStartSession(): token=" + token + ", act="
                    + getActivityDebugName() + ", id=" + mId);
        }
        final int flags = 0; // TODO(b/111276913): get proper flags
@@ -202,7 +201,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
                            if (resultData != null) {
                                binder = resultData.getBinder(EXTRA_BINDER);
                                if (binder == null) {
                                    Log.wtf(mTag, "No " + EXTRA_BINDER + " extra result");
                                    Log.wtf(TAG, "No " + EXTRA_BINDER + " extra result");
                                    handleResetState();
                                    return;
                                }
@@ -211,7 +210,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
                        }
                    });
        } catch (RemoteException e) {
            Log.w(mTag, "Error starting session for " + componentName.flattenToShortString() + ": "
            Log.w(TAG, "Error starting session for " + componentName.flattenToShortString() + ": "
                    + e);
        }
    }
@@ -229,13 +228,13 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
        if (binder != null) {
            mDirectServiceInterface = IContentCaptureDirectManager.Stub.asInterface(binder);
            mDirectServiceVulture = () -> {
                Log.w(mTag, "Destroying session " + mId + " because service died");
                Log.w(TAG, "Destroying session " + mId + " because service died");
                destroy();
            };
            try {
                binder.linkToDeath(mDirectServiceVulture, 0);
            } catch (RemoteException e) {
                Log.w(mTag, "Failed to link to death on " + binder + ": " + e);
                Log.w(TAG, "Failed to link to death on " + binder + ": " + e);
            }
        }
        if (resultCode == STATE_DISABLED || resultCode == STATE_DISABLED_DUPLICATED_ID) {
@@ -245,7 +244,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
            mDisabled.set(false);
        }
        if (VERBOSE) {
            Log.v(mTag, "handleSessionStarted() result: code=" + resultCode + ", id=" + mId
            Log.v(TAG, "handleSessionStarted() result: code=" + resultCode + ", id=" + mId
                    + ", state=" + getStateAsString(mState) + ", disabled=" + mDisabled.get()
                    + ", binder=" + binder);
        }
@@ -254,7 +253,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
    private void handleSendEvent(@NonNull ContentCaptureEvent event, boolean forceFlush) {
        if (mEvents == null) {
            if (VERBOSE) {
                Log.v(mTag, "Creating buffer for " + MAX_BUFFER_SIZE + " events");
                Log.v(TAG, "Creating buffer for " + MAX_BUFFER_SIZE + " events");
            }
            mEvents = new ArrayList<>(MAX_BUFFER_SIZE);
        }
@@ -266,7 +265,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
            if (lastEvent.getType() == TYPE_VIEW_TEXT_CHANGED
                    && lastEvent.getId().equals(event.getId())) {
                if (VERBOSE) {
                    Log.v(mTag, "Buffering VIEW_TEXT_CHANGED event, updated text = "
                    Log.v(TAG, "Buffering VIEW_TEXT_CHANGED event, updated text = "
                            + event.getText());
                }
                lastEvent.setText(event.getText());
@@ -293,7 +292,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
            // not complete instead. Similarly, the manager service should return right away
            // when the user does not have a service set
            if (VERBOSE) {
                Log.v(mTag, "Closing session for " + getActivityDebugName()
                Log.v(TAG, "Closing session for " + getActivityDebugName()
                        + " after " + numberEvents + " delayed events and state "
                        + getStateAsString(mState));
            }
@@ -313,7 +312,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
        }
        mNextFlush = SystemClock.elapsedRealtime() + FLUSHING_FREQUENCY_MS;
        if (VERBOSE) {
            Log.v(mTag, "Scheduled to flush in " + FLUSHING_FREQUENCY_MS + "ms: " + mNextFlush);
            Log.v(TAG, "Scheduled to flush in " + FLUSHING_FREQUENCY_MS + "ms: " + mNextFlush);
        }
        mHandler.sendMessageDelayed(
                obtainMessage(MainContentCaptureSession::handleFlushIfNeeded, this)
@@ -322,7 +321,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession {

    private void handleFlushIfNeeded() {
        if (mEvents.isEmpty()) {
            if (VERBOSE) Log.v(mTag, "Nothing to flush");
            if (VERBOSE) Log.v(TAG, "Nothing to flush");
            return;
        }
        handleForceFlush();
@@ -332,7 +331,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
        if (mEvents == null) return;

        if (mDirectServiceInterface == null) {
            if (DEBUG) Log.d(mTag, "handleForceFlush(): hold your horses, client not ready yet!");
            if (DEBUG) Log.d(TAG, "handleForceFlush(): hold your horses, client not ready yet!");
            if (!mHandler.hasMessages(MSG_FLUSH)) {
                handleScheduleFlush(/* checkExisting= */ false);
            }
@@ -342,14 +341,14 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
        final int numberEvents = mEvents.size();
        try {
            if (DEBUG) {
                Log.d(mTag, "Flushing " + numberEvents + " event(s) for " + getActivityDebugName());
                Log.d(TAG, "Flushing " + numberEvents + " event(s) for " + getActivityDebugName());
            }
            mHandler.removeMessages(MSG_FLUSH);

            final ParceledListSlice<ContentCaptureEvent> events = handleClearEvents();
            mDirectServiceInterface.sendEvents(events);
        } catch (RemoteException e) {
            Log.w(mTag, "Error sending " + numberEvents + " for " + getActivityDebugName()
            Log.w(TAG, "Error sending " + numberEvents + " for " + getActivityDebugName()
                    + ": " + e);
        }
    }
@@ -370,7 +369,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession {

    private void handleDestroySession() {
        if (DEBUG) {
            Log.d(mTag, "Destroying session (ctx=" + mContext + ", id=" + mId + ") with "
            Log.d(TAG, "Destroying session (ctx=" + mContext + ", id=" + mId + ") with "
                    + (mEvents == null ? 0 : mEvents.size()) + " event(s) for "
                    + getActivityDebugName());
        }
@@ -378,7 +377,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
        try {
            mSystemServerInterface.finishSession(mContext.getUserId(), mId);
        } catch (RemoteException e) {
            Log.e(mTag, "Error destroying system-service session " + mId + " for "
            Log.e(TAG, "Error destroying system-service session " + mId + " for "
                    + getActivityDebugName() + ": " + e);
        }
    }
@@ -395,8 +394,6 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
        }

        // TODO(b/121033016): must reset children (which currently is owned by superclass)

        mContentCaptureSessionId = null;
        mApplicationToken = null;
        mComponentName = null;
        mEvents = null;
@@ -482,9 +479,6 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
        }
        pw.print(prefix); pw.print("mDisabled: "); pw.println(mDisabled.get());
        pw.print(prefix); pw.print("isEnabled(): "); pw.println(isContentCaptureEnabled());
        if (mContentCaptureSessionId != null) {
            pw.print(prefix); pw.print("public id: "); pw.println(mContentCaptureSessionId);
        }
        pw.print(prefix); pw.print("state: "); pw.print(mState); pw.print(" (");
        pw.print(getStateAsString(mState)); pw.println(")");
        if (mApplicationToken != null) {