New APIs for ContentCaptureService: onConnected() and onDisconnected()
Bug: 117944706 Test: atest CtsContentCaptureServiceTestCases:android.contentcaptureservice.cts.BlankActivityTest#testDisconnected Test: atest CtsContentCaptureServiceTestCases Change-Id: Iba3c1ae774221946a550fad95539d3a9771ae3d7
This commit is contained in:
committed by
Winson Chung
parent
50b33dce59
commit
bb98ed6521
@@ -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.
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user