summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Guojing Yuan <guojing@google.com> 2023-11-29 19:44:55 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-11-29 19:44:55 +0000
commit05a2e36544fa7ec516d6329a4e68b0b387d62ee0 (patch)
tree3e729f69b9d2ff23cc3846730af14a3dcbf24377
parent6d596d2be4fb039a83fb3c45ac54418913a17508 (diff)
parent8b5928ed91dcc7e71e8ed37a3599b48a667d14ad (diff)
Merge "[Perm Sync] Add an API for the companion app to get the perm sync consent" into main
-rw-r--r--core/api/current.txt1
-rw-r--r--core/java/android/companion/CompanionDeviceManager.java30
-rw-r--r--core/java/android/companion/ICompanionDeviceManager.aidl2
-rw-r--r--core/java/android/companion/flags.aconfig7
-rw-r--r--services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java7
-rw-r--r--services/companion/java/com/android/server/companion/datatransfer/SystemDataTransferProcessor.java17
6 files changed, 63 insertions, 1 deletions
diff --git a/core/api/current.txt b/core/api/current.txt
index 5b339fa9494d..e11f8ce940c4 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -9676,6 +9676,7 @@ package android.companion {
method @Deprecated @NonNull public java.util.List<java.lang.String> getAssociations();
method @NonNull public java.util.List<android.companion.AssociationInfo> getMyAssociations();
method @Deprecated public boolean hasNotificationAccess(android.content.ComponentName);
+ method @FlaggedApi("android.companion.perm_sync_user_consent") public boolean isPermissionTransferUserConsented(int);
method public void requestNotificationAccess(android.content.ComponentName);
method @FlaggedApi("android.companion.association_tag") public void setAssociationTag(int, @NonNull String);
method @RequiresPermission(android.Manifest.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE) public void startObservingDevicePresence(@NonNull String) throws android.companion.DeviceNotAssociatedException;
diff --git a/core/java/android/companion/CompanionDeviceManager.java b/core/java/android/companion/CompanionDeviceManager.java
index e0ce917fa3b3..e4a03c596254 100644
--- a/core/java/android/companion/CompanionDeviceManager.java
+++ b/core/java/android/companion/CompanionDeviceManager.java
@@ -1358,6 +1358,36 @@ public final class CompanionDeviceManager {
}
/**
+ * Return the current state of consent for permission transfer for the association.
+ * True if the user has allowed permission transfer for the association, false otherwise.
+ *
+ * <p>
+ * Note: The initial user consent is collected via
+ * {@link #buildPermissionTransferUserConsentIntent(int) a permission transfer user consent dialog}.
+ * After the user has made their initial selection, they can toggle the permission transfer
+ * feature in the settings.
+ * This method always returns the state of the toggle setting.
+ * </p>
+ *
+ * @param associationId The unique {@link AssociationInfo#getId ID} assigned to the association
+ * of the companion device recorded by CompanionDeviceManager
+ * @return True if the user has consented to the permission transfer, or false otherwise.
+ * @throws DeviceNotAssociatedException Exception if the companion device is not associated with
+ * the user or the calling app.
+ */
+ @UserHandleAware
+ @FlaggedApi(Flags.FLAG_PERM_SYNC_USER_CONSENT)
+ public boolean isPermissionTransferUserConsented(int associationId) {
+ try {
+ return mService.isPermissionTransferUserConsented(mContext.getOpPackageName(),
+ mContext.getUserId(), associationId);
+ } catch (RemoteException e) {
+ ExceptionUtils.propagateIfInstanceOf(e.getCause(), DeviceNotAssociatedException.class);
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
* Start system data transfer which has been previously approved by the user.
*
* <p>Before calling this method, the app needs to make sure there's a communication channel
diff --git a/core/java/android/companion/ICompanionDeviceManager.aidl b/core/java/android/companion/ICompanionDeviceManager.aidl
index c5a19888205c..22689f3b85c7 100644
--- a/core/java/android/companion/ICompanionDeviceManager.aidl
+++ b/core/java/android/companion/ICompanionDeviceManager.aidl
@@ -97,6 +97,8 @@ interface ICompanionDeviceManager {
PendingIntent buildPermissionTransferUserConsentIntent(String callingPackage, int userId,
int associationId);
+ boolean isPermissionTransferUserConsented(String callingPackage, int userId, int associationId);
+
void startSystemDataTransfer(String packageName, int userId, int associationId,
in ISystemDataTransferCallback callback);
diff --git a/core/java/android/companion/flags.aconfig b/core/java/android/companion/flags.aconfig
index 6e33dff3a379..9e410b86b6bd 100644
--- a/core/java/android/companion/flags.aconfig
+++ b/core/java/android/companion/flags.aconfig
@@ -27,3 +27,10 @@ flag {
description: "Enable device presence APIs"
bug: "283000075"
}
+
+flag {
+ name: "perm_sync_user_consent"
+ namespace: "companion"
+ description: "Expose perm sync user consent API"
+ bug: "309528663"
+} \ No newline at end of file
diff --git a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java
index 71a1f012e5cb..cce596b7f088 100644
--- a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java
+++ b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java
@@ -833,6 +833,13 @@ public class CompanionDeviceManagerService extends SystemService {
}
@Override
+ public boolean isPermissionTransferUserConsented(String packageName, int userId,
+ int associationId) {
+ return mSystemDataTransferProcessor.isPermissionTransferUserConsented(packageName,
+ userId, associationId);
+ }
+
+ @Override
public void startSystemDataTransfer(String packageName, int userId, int associationId,
ISystemDataTransferCallback callback) {
mSystemDataTransferProcessor.startSystemDataTransfer(packageName, userId,
diff --git a/services/companion/java/com/android/server/companion/datatransfer/SystemDataTransferProcessor.java b/services/companion/java/com/android/server/companion/datatransfer/SystemDataTransferProcessor.java
index e5c847acad6e..bd646fa6bfbc 100644
--- a/services/companion/java/com/android/server/companion/datatransfer/SystemDataTransferProcessor.java
+++ b/services/companion/java/com/android/server/companion/datatransfer/SystemDataTransferProcessor.java
@@ -120,7 +120,8 @@ public class SystemDataTransferProcessor {
* Resolve the requested association, throwing if the caller doesn't have
* adequate permissions.
*/
- private @NonNull AssociationInfo resolveAssociation(String packageName, int userId,
+ @NonNull
+ private AssociationInfo resolveAssociation(String packageName, int userId,
int associationId) {
AssociationInfo association = mAssociationStore.getAssociationById(associationId);
association = PermissionsUtils.sanitizeWithCallerChecks(mContext, association);
@@ -133,6 +134,20 @@ public class SystemDataTransferProcessor {
}
/**
+ * Return whether the user has consented to the permission transfer for the association.
+ */
+ public boolean isPermissionTransferUserConsented(String packageName, @UserIdInt int userId,
+ int associationId) {
+ resolveAssociation(packageName, userId, associationId);
+
+ PermissionSyncRequest request = getPermissionSyncRequest(associationId);
+ if (request == null) {
+ return false;
+ }
+ return request.isUserConsented();
+ }
+
+ /**
* Build a PendingIntent of permission sync user consent dialog
*/
public PendingIntent buildPermissionTransferUserConsentIntent(String packageName,