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

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

Merge "New APIs for ContentCaptureService: onConnected() and onDisconnected()"

parents fee326de bb98ed65
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -5156,10 +5156,12 @@ package android.service.contentcapture {
    method public final java.util.Set<android.content.ComponentName> getContentCaptureDisabledActivities();
    method public final java.util.Set<java.lang.String> getContentCaptureDisabledPackages();
    method public void onActivitySnapshot(android.view.contentcapture.ContentCaptureSessionId, android.service.contentcapture.SnapshotData);
    method public void onConnected();
    method public void onContentCaptureEvent(android.view.contentcapture.ContentCaptureSessionId, android.view.contentcapture.ContentCaptureEvent);
    method public deprecated void onContentCaptureEventsRequest(android.view.contentcapture.ContentCaptureSessionId, android.service.contentcapture.ContentCaptureEventsRequest);
    method public void onCreateContentCaptureSession(android.view.contentcapture.ContentCaptureContext, android.view.contentcapture.ContentCaptureSessionId);
    method public void onDestroyContentCaptureSession(android.view.contentcapture.ContentCaptureSessionId);
    method public void onDisconnected();
    method public final void setActivityContentCaptureEnabled(android.content.ComponentName, boolean);
    method public final void setContentCaptureWhitelist(java.util.List<java.lang.String>, java.util.List<android.content.ComponentName>);
    method public final void setPackageContentCaptureEnabled(java.lang.String, boolean);
+33 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.service.autofill.AutofillService;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Slog;
@@ -81,6 +82,12 @@ public abstract class ContentCaptureService extends Service {
     */
    private final IContentCaptureService mServerInterface = new IContentCaptureService.Stub() {

        @Override
        public void onConnectedStateChanged(boolean state) {
            mHandler.sendMessage(obtainMessage(ContentCaptureService::handleOnConnectedStateChanged,
                    ContentCaptureService.this, state));
        }

        @Override
        public void onSessionStarted(ContentCaptureContext context, String sessionId, int uid,
                IResultReceiver clientReceiver) {
@@ -203,6 +210,15 @@ public abstract class ContentCaptureService extends Service {
        return null;
    }

    /**
     * Called when the Android system connects to service.
     *
     * <p>You should generally do initialization here rather than in {@link #onCreate}.
     */
    public void onConnected() {
        Slog.i(TAG, "bound to " + getClass().getName());
    }

    /**
     * Creates a new content capture session.
     *
@@ -257,6 +273,15 @@ public abstract class ContentCaptureService extends Service {
        if (VERBOSE) Log.v(TAG, "onDestroyContentCaptureSession(id=" + sessionId + ")");
    }

    /**
     * Called when the Android system disconnects from the service.
     *
     * <p> At this point this service may no longer be an active {@link AutofillService}.
     */
    public void onDisconnected() {
        Slog.i(TAG, "unbinding from " + getClass().getName());
    }

    @Override
    @CallSuper
    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
@@ -271,6 +296,14 @@ public abstract class ContentCaptureService extends Service {
        }
    }

    private void handleOnConnectedStateChanged(boolean state) {
        if (state) {
            onConnected();
        } else {
            onDisconnected();
        }
    }

    //TODO(b/111276913): consider caching the InteractionSessionId for the lifetime of the session,
    // so we don't need to create a temporary InteractionSessionId for each event.

+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import java.util.List;
 * @hide
 */
oneway interface IContentCaptureService {
    void onConnectedStateChanged(boolean state);
    void onSessionStarted(in ContentCaptureContext context, String sessionId, int uid,
                          in IResultReceiver clientReceiver);
    void onSessionFinished(String sessionId);
+22 −2
Original line number Diff line number Diff line
@@ -63,7 +63,8 @@ import java.lang.ref.WeakReference;
//TODO(b/117779333): improve javadoc above instead of using Autofill as an example
public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I>,
        I extends IInterface> implements DeathRecipient {
    private static final int MSG_UNBIND = 1;
    private static final int MSG_BIND = 1;
    private static final int MSG_UNBIND = 2;

    protected static final long PERMANENT_BOUND_TIMEOUT_MS = 0;

@@ -106,7 +107,7 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
        void onServiceDied(T service);
    }

    // NOTE: must be package-protected so this class is not extend outside
    // NOTE: must be package-protected so this class is not extended outside
    AbstractRemoteService(@NonNull Context context, @NonNull String serviceInterface,
            @NonNull ComponentName componentName, int userId, @NonNull VultureCallback<S> callback,
            boolean bindInstantServiceAllowed, boolean verbose) {
@@ -284,6 +285,25 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
        mHandler.removeMessages(MSG_UNBIND);
    }

    /**
     * Schedules a request to bind to the remote service.
     *
     * <p>Typically used on constructor for implementations that need a permanent connection to
     * the remote service.
     */
    protected void scheduleBind() {
        if (mHandler.hasMessages(MSG_BIND)) {
            if (mVerbose) Slog.v(mTag, "scheduleBind(): already scheduled");
            return;
        }
        mHandler.sendMessage(obtainMessage(AbstractRemoteService::handleEnsureBound, this)
                .setWhat(MSG_BIND));
    }

    /**
     * Schedules a request to automatically unbind from the service after the
     * {@link #getTimeoutIdleBindMillis() idle timeout} expires.
     */
    protected void scheduleUnbind() {
        final long unbindDelay = getTimeoutIdleBindMillis();

+1 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ final class RemoteFillService
        try {
            mService.onConnectedStateChanged(state);
        } catch (Exception e) {
            Slog.w(mTag, "Exception calling onConnectedStateChanged(): " + e);
            Slog.w(mTag, "Exception calling onConnectedStateChanged(" + state + "): " + e);
        }
    }

Loading