summaryrefslogtreecommitdiff
path: root/services/contentcapture/java
diff options
context:
space:
mode:
authorFelipe Leme <felipeal@google.com>2019-03-25 16:36:09 -0700
committerFelipe Leme <felipeal@google.com>2019-03-28 18:48:31 -0700
commita8d33c24f8531b65020436c15d868d72677a5b97 (patch)
tree213c4a223e3e7e0afff33da07419af068afcb31e /services/contentcapture/java
parentae9f6953adeb8f69bc095df3b84c9937d331dd11 (diff)
Implemented ContentCaptureConditions APIs.
Test: atest ContentCaptureConditionTest \ CustomViewActivityTest#testContentCaptureConditions \ CustomViewActivityTest#testContentCaptureConditions_otherPackage Test: atest CtsContentCaptureServiceTestCases # sanity check (minus usual flakiness) Fixes: 129266058 Change-Id: I199c3ae99fa6b407da64562a71d8d7581ebf80e6
Diffstat (limited to 'services/contentcapture/java')
-rw-r--r--services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java23
-rw-r--r--services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java70
2 files changed, 93 insertions, 0 deletions
diff --git a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java
index c88d3ae4ea24..2894662becac 100644
--- a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java
+++ b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java
@@ -18,6 +18,7 @@ package com.android.server.contentcapture;
import static android.Manifest.permission.MANAGE_CONTENT_CAPTURE;
import static android.content.Context.CONTENT_CAPTURE_MANAGER_SERVICE;
+import static android.view.contentcapture.ContentCaptureHelper.toList;
import static android.view.contentcapture.ContentCaptureManager.RESULT_CODE_FALSE;
import static android.view.contentcapture.ContentCaptureManager.RESULT_CODE_OK;
import static android.view.contentcapture.ContentCaptureManager.RESULT_CODE_SECURITY_EXCEPTION;
@@ -56,6 +57,7 @@ import android.util.LocalLog;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
+import android.view.contentcapture.ContentCaptureCondition;
import android.view.contentcapture.ContentCaptureHelper;
import android.view.contentcapture.ContentCaptureManager;
import android.view.contentcapture.IContentCaptureManager;
@@ -568,6 +570,8 @@ public final class ContentCaptureManagerService extends
@Override
public void removeUserData(@NonNull UserDataRemovalRequest request) {
Preconditions.checkNotNull(request);
+ // TODO(b/122959591): check caller uid owns the package name
+
final int userId = UserHandle.getCallingUserId();
synchronized (mLock) {
final ContentCapturePerUserService service = getServiceForUserLocked(userId);
@@ -621,6 +625,25 @@ public final class ContentCaptureManagerService extends
}
@Override
+ public void getContentCaptureConditions(@NonNull String packageName,
+ @NonNull IResultReceiver result) {
+ // TODO(b/122959591): check caller uid owns the package name
+
+ final int userId = UserHandle.getCallingUserId();
+ final ArrayList<ContentCaptureCondition> conditions;
+ synchronized (mLock) {
+ final ContentCapturePerUserService service = getServiceForUserLocked(userId);
+ conditions = service == null ? null
+ : toList(service.getContentCaptureConditionsLocked(packageName));
+ }
+ try {
+ result.send(RESULT_CODE_OK, bundleFor(conditions));
+ } catch (RemoteException e) {
+ Slog.w(mTag, "Unable to send getServiceComponentName(): " + e);
+ }
+ }
+
+ @Override
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(getContext(), mTag, pw)) return;
diff --git a/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java b/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java
index 665d3dfc7bb7..564952697250 100644
--- a/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java
+++ b/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java
@@ -35,11 +35,13 @@ import android.app.ActivityManagerInternal;
import android.app.assist.AssistContent;
import android.app.assist.AssistStructure;
import android.content.ComponentName;
+import android.content.ContentCaptureOptions;
import android.content.pm.ActivityPresentationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ServiceInfo;
import android.os.Binder;
+import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.os.UserHandle;
@@ -50,8 +52,11 @@ import android.service.contentcapture.ContentCaptureService;
import android.service.contentcapture.ContentCaptureServiceInfo;
import android.service.contentcapture.IContentCaptureServiceCallback;
import android.service.contentcapture.SnapshotData;
+import android.util.ArrayMap;
+import android.util.ArraySet;
import android.util.Slog;
import android.util.SparseArray;
+import android.view.contentcapture.ContentCaptureCondition;
import android.view.contentcapture.UserDataRemovalRequest;
import com.android.internal.annotations.GuardedBy;
@@ -98,6 +103,13 @@ final class ContentCapturePerUserService
private final WhitelistHelper mWhitelistHelper = new WhitelistHelper();
/**
+ * List of conditions keyed by package.
+ */
+ @GuardedBy("mLock")
+ private final ArrayMap<String, ArraySet<ContentCaptureCondition>> mConditionsByPkg =
+ new ArrayMap<>();
+
+ /**
* When {@code true}, remote service died but service state is kept so it's restored after
* the system re-binds to it.
*/
@@ -449,6 +461,47 @@ final class ContentCapturePerUserService
}
@GuardedBy("mLock")
+ @Nullable
+ ContentCaptureOptions getOptionsForPackageLocked(@NonNull String packageName) {
+ if (!mWhitelistHelper.isWhitelisted(packageName)) {
+ if (packageName.equals(getServicePackageName())) {
+ if (mMaster.verbose) Slog.v(mTag, "getOptionsForPackage() lite for " + packageName);
+ return new ContentCaptureOptions(mMaster.mDevCfgLoggingLevel);
+ }
+ if (mMaster.verbose) {
+ Slog.v(mTag, "getOptionsForPackage(" + packageName + "): not whitelisted");
+ }
+ return null;
+ }
+
+ final ArraySet<ComponentName> whitelistedComponents = mWhitelistHelper
+ .getWhitelistedComponents(packageName);
+ if (Build.IS_USER && isTemporaryServiceSetLocked()) {
+ final String servicePackageName = getServicePackageName();
+ if (!packageName.equals(servicePackageName)) {
+ Slog.w(mTag, "Ignoring package " + packageName
+ + " while using temporary service " + servicePackageName);
+ return null;
+ }
+ }
+ final ContentCaptureOptions options = new ContentCaptureOptions(mMaster.mDevCfgLoggingLevel,
+ mMaster.mDevCfgMaxBufferSize, mMaster.mDevCfgIdleFlushingFrequencyMs,
+ mMaster.mDevCfgTextChangeFlushingFrequencyMs, mMaster.mDevCfgLogHistorySize,
+ whitelistedComponents);
+ if (mMaster.verbose) {
+ Slog.v(mTag, "getOptionsForPackage(" + packageName + "): " + options);
+ }
+ return options;
+ }
+
+ @GuardedBy("mLock")
+ @Nullable
+ ArraySet<ContentCaptureCondition> getContentCaptureConditionsLocked(
+ @NonNull String packageName) {
+ return mConditionsByPkg.get(packageName);
+ }
+
+ @GuardedBy("mLock")
void onActivityEventLocked(@NonNull ComponentName componentName, @ActivityEventType int type) {
if (mRemoteService == null) {
if (mMaster.debug) Slog.d(mTag, "onActivityEvent(): no remote service");
@@ -536,6 +589,23 @@ final class ContentCapturePerUserService
}
@Override
+ public void setContentCaptureConditions(String packageName,
+ List<ContentCaptureCondition> conditions) {
+ if (mMaster.verbose) {
+ Slog.v(TAG, "setContentCaptureConditions(" + packageName + "): "
+ + (conditions == null ? "null" : conditions.size() + " conditions"));
+ }
+ synchronized (mLock) {
+ if (conditions == null) {
+ mConditionsByPkg.remove(packageName);
+ } else {
+ mConditionsByPkg.put(packageName, new ArraySet<>(conditions));
+ }
+ }
+ // TODO(b/119613670): log metrics
+ }
+
+ @Override
public void disableSelf() {
if (mMaster.verbose) Slog.v(TAG, "disableSelf()");