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

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

Merge "ContentCaptureManager should be null when the feature is disabled."

parents 03f311cb d49d52c0
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -1129,8 +1129,12 @@ final class SystemServiceRegistry {
                    IBinder b = ServiceManager
                    IBinder b = ServiceManager
                            .getService(Context.CONTENT_CAPTURE_MANAGER_SERVICE);
                            .getService(Context.CONTENT_CAPTURE_MANAGER_SERVICE);
                    IContentCaptureManager service = IContentCaptureManager.Stub.asInterface(b);
                    IContentCaptureManager service = IContentCaptureManager.Stub.asInterface(b);
                    if (service != null) {
                        // When feature is disabled, we return a null manager to apps so the
                        // performance impact is practically zero
                        return new ContentCaptureManager(outerContext, service);
                        return new ContentCaptureManager(outerContext, service);
                    }
                    }
                }
                return null;
                return null;
            }});
            }});


+16 −28
Original line number Original line Diff line number Diff line
@@ -39,15 +39,8 @@ import com.android.internal.util.SyncResultReceiver;


import java.io.PrintWriter;
import java.io.PrintWriter;


/*
 * NOTE: all methods in this class should return right away, or do the real work in a handler
 * thread.
 *
 * Hence, the only field that must be thread-safe is mEnabled, which is called at the beginning
 * of every method.
 */
/**
/**
 * TODO(b/123577059): add javadocs / implement
 * TODO(b/123577059): add javadocs / mention it can be null
 */
 */
@SystemService(Context.CONTENT_CAPTURE_MANAGER_SERVICE)
@SystemService(Context.CONTENT_CAPTURE_MANAGER_SERVICE)
public final class ContentCaptureManager {
public final class ContentCaptureManager {
@@ -90,7 +83,7 @@ public final class ContentCaptureManager {
    @NonNull
    @NonNull
    private final Context mContext;
    private final Context mContext;


    @Nullable
    @NonNull
    private final IContentCaptureManager mService;
    private final IContentCaptureManager mService;


    // Flags used for starting session.
    // Flags used for starting session.
@@ -107,11 +100,11 @@ public final class ContentCaptureManager {


    /** @hide */
    /** @hide */
    public ContentCaptureManager(@NonNull Context context,
    public ContentCaptureManager(@NonNull Context context,
            @Nullable IContentCaptureManager service) {
            @NonNull IContentCaptureManager service) {
        mContext = Preconditions.checkNotNull(context, "context cannot be null");
        if (VERBOSE) Log.v(TAG, "Constructor for " + context.getPackageName());
        if (VERBOSE) Log.v(TAG, "Constructor for " + context.getPackageName());
        mContext = Preconditions.checkNotNull(context, "context cannot be null");
        mService = Preconditions.checkNotNull(service, "service cannot be null");


        mService = service;
        // TODO(b/119220549): we might not even need a handler, as the IPCs are oneway. But if we
        // TODO(b/119220549): we might not even need a handler, as the IPCs are oneway. But if we
        // do, then we should optimize it to run the tests after the Choreographer finishes the most
        // do, then we should optimize it to run the tests after the Choreographer finishes the most
        // important steps of the frame.
        // important steps of the frame.
@@ -199,8 +192,6 @@ public final class ContentCaptureManager {
     * </ul>
     * </ul>
     */
     */
    public boolean isContentCaptureEnabled() {
    public boolean isContentCaptureEnabled() {
        if (mService == null) return false;

        final MainContentCaptureSession mainSession;
        final MainContentCaptureSession mainSession;
        synchronized (mLock) {
        synchronized (mLock) {
            mainSession = mMainSession;
            mainSession = mMainSession;
@@ -242,8 +233,6 @@ public final class ContentCaptureManager {
    @SystemApi
    @SystemApi
    @TestApi
    @TestApi
    public boolean isContentCaptureFeatureEnabled() {
    public boolean isContentCaptureFeatureEnabled() {
        if (mService == null) return false;

        final SyncResultReceiver resultReceiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS);
        final SyncResultReceiver resultReceiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS);
        final int resultCode;
        final int resultCode;
        try {
        try {
@@ -314,22 +303,21 @@ public final class ContentCaptureManager {


    /** @hide */
    /** @hide */
    public void dump(String prefix, PrintWriter pw) {
    public void dump(String prefix, PrintWriter pw) {
        synchronized (mLock) {
        pw.print(prefix); pw.println("ContentCaptureManager");
        pw.print(prefix); pw.println("ContentCaptureManager");
            pw.print(prefix); pw.print("isContentCaptureEnabled(): ");
        final String prefix2 = prefix + "  ";
        synchronized (mLock) {
            pw.print(prefix2); pw.print("isContentCaptureEnabled(): ");
            pw.println(isContentCaptureEnabled());
            pw.println(isContentCaptureEnabled());
            pw.print(prefix); pw.print("Context: "); pw.println(mContext);
            pw.print(prefix2); pw.print("Context: "); pw.println(mContext);
            pw.print(prefix); pw.print("User: "); pw.println(mContext.getUserId());
            pw.print(prefix2); pw.print("User: "); pw.println(mContext.getUserId());
            if (mService != null) {
            pw.print(prefix2); pw.print("Service: "); pw.println(mService);
                pw.print(prefix); pw.print("Service: "); pw.println(mService);
            pw.print(prefix2); pw.print("Flags: "); pw.println(mFlags);
            }
            pw.print(prefix); pw.print("Flags: "); pw.println(mFlags);
            if (mMainSession != null) {
            if (mMainSession != null) {
                final String prefix2 = prefix + "  ";
                final String prefix3 = prefix2 + "  ";
                pw.print(prefix); pw.println("Main session:");
                pw.print(prefix2); pw.println("Main session:");
                mMainSession.dump(prefix2, pw);
                mMainSession.dump(prefix3, pw);
            } else {
            } else {
                pw.print(prefix); pw.println("No sessions");
                pw.print(prefix2); pw.println("No sessions");
            }
            }
        }
        }
    }
    }
+6 −13
Original line number Original line Diff line number Diff line
@@ -105,14 +105,14 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
     * Interface to the system_server binder object - it's only used to start the session (and
     * Interface to the system_server binder object - it's only used to start the session (and
     * notify when the session is finished).
     * notify when the session is finished).
     */
     */
    @Nullable // TODO(b/122959591): shoul never be null, we should make main session null instead
    @NonNull
    private final IContentCaptureManager mSystemServerInterface;
    private final IContentCaptureManager mSystemServerInterface;


    /**
    /**
     * Direct interface to the service binder object - it's used to send the events, including the
     * Direct interface to the service binder object - it's used to send the events, including the
     * last ones (when the session is finished)
     * last ones (when the session is finished)
     */
     */
    @Nullable
    @NonNull
    private IContentCaptureDirectManager mDirectServiceInterface;
    private IContentCaptureDirectManager mDirectServiceInterface;
    @Nullable
    @Nullable
    private DeathRecipient mDirectServiceVulture;
    private DeathRecipient mDirectServiceVulture;
@@ -140,7 +140,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
    /** @hide */
    /** @hide */
    protected MainContentCaptureSession(@NonNull Context context,
    protected MainContentCaptureSession(@NonNull Context context,
            @NonNull ContentCaptureManager manager, @NonNull Handler handler,
            @NonNull ContentCaptureManager manager, @NonNull Handler handler,
            @Nullable IContentCaptureManager systemServerInterface) {
            @NonNull IContentCaptureManager systemServerInterface) {
        mContext = context;
        mContext = context;
        mManager = manager;
        mManager = manager;
        mHandler = handler;
        mHandler = handler;
@@ -193,8 +193,6 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
        }
        }


        try {
        try {
            if (mSystemServerInterface == null) return;

            mSystemServerInterface.startSession(mApplicationToken, component, mId, flags,
            mSystemServerInterface.startSession(mApplicationToken, component, mId, flags,
                    new IResultReceiver.Stub() {
                    new IResultReceiver.Stub() {
                        @Override
                        @Override
@@ -507,8 +505,6 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
        }
        }


        try {
        try {
            if (mSystemServerInterface == null) return;

            mSystemServerInterface.finishSession(mId);
            mSystemServerInterface.finishSession(mId);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG, "Error destroying system-service session " + mId + " for "
            Log.e(TAG, "Error destroying system-service session " + mId + " for "
@@ -628,12 +624,11 @@ public final class MainContentCaptureSession extends ContentCaptureSession {


    @Override
    @Override
    void dump(@NonNull String prefix, @NonNull PrintWriter pw) {
    void dump(@NonNull String prefix, @NonNull PrintWriter pw) {
        super.dump(prefix, pw);

        pw.print(prefix); pw.print("mContext: "); pw.println(mContext);
        pw.print(prefix); pw.print("mContext: "); pw.println(mContext);
        pw.print(prefix); pw.print("user: "); pw.println(mContext.getUserId());
        pw.print(prefix); pw.print("user: "); pw.println(mContext.getUserId());
        if (mSystemServerInterface != null) {
        pw.print(prefix); pw.print("mSystemServerInterface: ");
        pw.print(prefix); pw.print("mSystemServerInterface: ");
            pw.println(mSystemServerInterface);
        }
        if (mDirectServiceInterface != null) {
        if (mDirectServiceInterface != null) {
            pw.print(prefix); pw.print("mDirectServiceInterface: ");
            pw.print(prefix); pw.print("mDirectServiceInterface: ");
            pw.println(mDirectServiceInterface);
            pw.println(mDirectServiceInterface);
@@ -667,8 +662,6 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
        }
        }
        pw.print(prefix); pw.println("flush history:");
        pw.print(prefix); pw.println("flush history:");
        mFlushHistory.reverseDump(/* fd= */ null, pw, /* args= */ null); pw.println();
        mFlushHistory.reverseDump(/* fd= */ null, pw, /* args= */ null); pw.println();

        super.dump(prefix, pw);
    }
    }


    /**
    /**