summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorFelipe Leme <felipeal@google.com>2018-12-21 09:29:27 -0800
committerWinson Chung <winsonc@google.com>2018-12-21 15:11:49 -0800
commitbb98ed65218d7bf4c8622a48cedaefff2b90b2b8 (patch)
tree0d6f0a983449a52d21e1a685429009e04c67deb1 /core/java/android
parent50b33dce5986ff588bc064f9d2616746366b7cb5 (diff)
New APIs for ContentCaptureService: onConnected() and onDisconnected()
Bug: 117944706 Test: atest CtsContentCaptureServiceTestCases:android.contentcaptureservice.cts.BlankActivityTest#testDisconnected Test: atest CtsContentCaptureServiceTestCases Change-Id: Iba3c1ae774221946a550fad95539d3a9771ae3d7
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/service/contentcapture/ContentCaptureService.java33
-rw-r--r--core/java/android/service/contentcapture/IContentCaptureService.aidl1
2 files changed, 34 insertions, 0 deletions
diff --git a/core/java/android/service/contentcapture/ContentCaptureService.java b/core/java/android/service/contentcapture/ContentCaptureService.java
index 64f235546201..c9d46dd701b5 100644
--- a/core/java/android/service/contentcapture/ContentCaptureService.java
+++ b/core/java/android/service/contentcapture/ContentCaptureService.java
@@ -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;
@@ -82,6 +83,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) {
mHandler.sendMessage(obtainMessage(ContentCaptureService::handleOnCreateSession,
@@ -204,6 +211,15 @@ public abstract class ContentCaptureService extends Service {
}
/**
+ * 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.
*
* @param context content capture context
@@ -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.
diff --git a/core/java/android/service/contentcapture/IContentCaptureService.aidl b/core/java/android/service/contentcapture/IContentCaptureService.aidl
index 20e8e99d4ce1..1b4cccf630a0 100644
--- a/core/java/android/service/contentcapture/IContentCaptureService.aidl
+++ b/core/java/android/service/contentcapture/IContentCaptureService.aidl
@@ -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);