summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorFelipe Leme <felipeal@google.com>2019-01-25 17:29:29 -0800
committerFelipe Leme <felipeal@google.com>2019-01-28 16:20:39 -0800
commitbb0c2a2a330c9903fbb3badc55d9a8ded3bc3299 (patch)
tree8ea7d3f0399c8c889facc47ca2546d7245330a1f /core
parent91ddecac0a320b56a2ad633ae62cca5411012c0e (diff)
Added new APIs to let ContentCaptureService enable / disable the feature.
Bug: 123286662 Test: atest ChildlessActivityTest#testSetContentCaptureFeatureEnabled_disabledByApi \ ChildlessActivityTest#testSetContentCaptureFeatureEnabled_disabledThenReEnabledByApi Test: atest CtsContentCaptureServiceTestCases # for sanity check Change-Id: Ideefb4c8e122e5f3f55dd7de8085212b2d8ce073
Diffstat (limited to 'core')
-rw-r--r--core/java/android/view/contentcapture/ContentCaptureManager.java60
-rw-r--r--core/java/android/view/contentcapture/IContentCaptureManager.aidl5
2 files changed, 63 insertions, 2 deletions
diff --git a/core/java/android/view/contentcapture/ContentCaptureManager.java b/core/java/android/view/contentcapture/ContentCaptureManager.java
index 07dedd65cf38..fde0cedf7db7 100644
--- a/core/java/android/view/contentcapture/ContentCaptureManager.java
+++ b/core/java/android/view/contentcapture/ContentCaptureManager.java
@@ -15,6 +15,7 @@
*/
package android.view.contentcapture;
+import static android.view.contentcapture.ContentCaptureHelper.DEBUG;
import static android.view.contentcapture.ContentCaptureHelper.VERBOSE;
import android.annotation.NonNull;
@@ -52,6 +53,13 @@ public final class ContentCaptureManager {
private static final String TAG = ContentCaptureManager.class.getSimpleName();
+ /** @hide */
+ public static final int RESULT_CODE_TRUE = 1;
+ /** @hide */
+ public static final int RESULT_CODE_FALSE = 2;
+ /** @hide */
+ public static final int RESULT_CODE_NOT_SERVICE = -1;
+
/**
* Timeout for calls to system_server.
*/
@@ -184,6 +192,10 @@ public final class ContentCaptureManager {
* it on {@link android.app.Activity#onCreate(android.os.Bundle, android.os.PersistableBundle)}.
*/
public void setContentCaptureEnabled(boolean enabled) {
+ if (DEBUG) {
+ Log.d(TAG, "setContentCaptureEnabled(): setting to " + enabled + " for " + mContext);
+ }
+
synchronized (mLock) {
mFlags |= enabled ? 0 : ContentCaptureContext.FLAG_DISABLED_BY_APP;
}
@@ -195,6 +207,9 @@ public final class ContentCaptureManager {
* <p>This method is typically used by the Content Capture Service settings page, so it can
* provide a toggle to enable / disable it.
*
+ * @throws SecurityException if caller is not the app that owns the Content Capture service
+ * associated with the user.
+ *
* @hide
*/
@SystemApi
@@ -202,13 +217,54 @@ public final class ContentCaptureManager {
if (mService == null) return false;
final SyncResultReceiver resultReceiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS);
+ final int resultCode;
try {
mService.isContentCaptureFeatureEnabled(resultReceiver);
- return resultReceiver.getIntResult() == 1;
+ resultCode = resultReceiver.getIntResult();
} catch (RemoteException e) {
- // Unable to retrieve component name in a reasonable amount of time.
throw e.rethrowFromSystemServer();
}
+ switch (resultCode) {
+ case RESULT_CODE_TRUE:
+ return true;
+ case RESULT_CODE_FALSE:
+ return false;
+ case RESULT_CODE_NOT_SERVICE:
+ throw new SecurityException("caller is not user's ContentCapture service");
+ default:
+ throw new IllegalStateException("received invalid result: " + resultCode);
+ }
+ }
+
+ /**
+ * Sets whether Content Capture is enabled for the given user.
+ *
+ * @throws SecurityException if caller is not the app that owns the Content Capture service
+ * associated with the user.
+ *
+ * @hide
+ */
+ @SystemApi
+ public void setContentCaptureFeatureEnabled(boolean enabled) {
+ if (DEBUG) Log.d(TAG, "setContentCaptureFeatureEnabled(): setting to " + enabled);
+
+ final SyncResultReceiver resultReceiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS);
+ final int resultCode;
+ try {
+ mService.setContentCaptureFeatureEnabled(enabled, resultReceiver);
+ resultCode = resultReceiver.getIntResult();
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ switch (resultCode) {
+ case RESULT_CODE_TRUE:
+ // Our work is done here, in our void existance...
+ return;
+ case RESULT_CODE_NOT_SERVICE:
+ throw new SecurityException("caller is not user's ContentCapture service");
+ default:
+ throw new IllegalStateException("received invalid result: " + resultCode);
+ }
}
/**
diff --git a/core/java/android/view/contentcapture/IContentCaptureManager.aidl b/core/java/android/view/contentcapture/IContentCaptureManager.aidl
index e3b0372a8cc7..26cf34c1b88e 100644
--- a/core/java/android/view/contentcapture/IContentCaptureManager.aidl
+++ b/core/java/android/view/contentcapture/IContentCaptureManager.aidl
@@ -67,4 +67,9 @@ oneway interface IContentCaptureManager {
* Returns whether the content capture feature is enabled for the calling user.
*/
void isContentCaptureFeatureEnabled(in IResultReceiver result);
+
+ /**
+ * Sets whether the content capture feature is enabled for the given user.
+ */
+ void setContentCaptureFeatureEnabled(boolean enabled, in IResultReceiver result);
}