diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 821d3f147282d..69eb4d4c4441c 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -1344,6 +1344,7 @@ package android.app.role { public abstract class RoleControllerService extends android.app.Service { ctor public RoleControllerService(); + method @NonNull public android.app.role.RolePrivileges getRolePrivileges(@NonNull String); method @WorkerThread public abstract boolean onAddRoleHolder(@NonNull String, @NonNull String, int); method @Nullable public final android.os.IBinder onBind(@Nullable android.content.Intent); method @WorkerThread public abstract boolean onClearRoleHolders(@NonNull String, int); @@ -1370,6 +1371,18 @@ package android.app.role { field public static final int MANAGE_HOLDERS_FLAG_DONT_KILL_APP = 1; // 0x1 } + public final class RolePrivileges implements android.os.Parcelable { + ctor public RolePrivileges(@NonNull java.util.List, @NonNull java.util.List, @NonNull java.util.List, @NonNull java.util.List); + method public int describeContents(); + method @NonNull public java.util.List getAppOpPermissions(); + method @NonNull public java.util.List getAppOps(); + method @NonNull public java.util.List getCapabilities(); + method @NonNull public java.util.List getPermissions(); + method public void writeToParcel(@NonNull android.os.Parcel, int); + field public static final String CAPABILITY_NOTIFICATION_LISTENER = "android.app.role.capability.NOTIFICATION_LISTENER"; + field @NonNull public static final android.os.Parcelable.Creator CREATOR; + } + } package android.app.time { diff --git a/core/java/android/app/role/IRoleController.aidl b/core/java/android/app/role/IRoleController.aidl index 8a43d7fa90364..fbf79a485dd5f 100644 --- a/core/java/android/app/role/IRoleController.aidl +++ b/core/java/android/app/role/IRoleController.aidl @@ -16,7 +16,9 @@ package android.app.role; +import android.app.role.RolePrivileges; import android.os.RemoteCallback; +import com.android.internal.infra.AndroidFuture; /** * @hide @@ -40,4 +42,6 @@ oneway interface IRoleController { in RemoteCallback callback); void isRoleVisible(in String roleName, in RemoteCallback callback); + + void getRolePrivileges(in String roleName, in AndroidFuture callback); } diff --git a/core/java/android/app/role/RoleControllerService.java b/core/java/android/app/role/RoleControllerService.java index d92c95691eea1..4c6aa8d2a4e08 100644 --- a/core/java/android/app/role/RoleControllerService.java +++ b/core/java/android/app/role/RoleControllerService.java @@ -16,6 +16,8 @@ package android.app.role; +import static java.util.Collections.emptyList; + import android.Manifest; import android.annotation.NonNull; import android.annotation.Nullable; @@ -32,6 +34,7 @@ import android.os.Process; import android.os.RemoteCallback; import android.os.UserHandle; +import com.android.internal.infra.AndroidFuture; import com.android.internal.util.Preconditions; import com.android.internal.util.function.pooled.PooledLambda; @@ -177,6 +180,20 @@ public abstract class RoleControllerService extends Service { boolean visible = onIsRoleVisible(roleName); callback.sendResult(visible ? Bundle.EMPTY : null); } + + @Override + public void getRolePrivileges(String roleName, AndroidFuture callback) { + enforceCallingPermission(Manifest.permission.MANAGE_ROLE_HOLDERS, null); + + Preconditions.checkStringNotEmpty(roleName, "roleName cannot be null or empty"); + Objects.requireNonNull(callback, "callback cannot be null"); + + try { + callback.complete(RoleControllerService.this.getRolePrivileges(roleName)); + } catch (Throwable t) { + callback.completeExceptionally(t); + } + } }; } @@ -302,4 +319,14 @@ public abstract class RoleControllerService extends Service { * @return whether the role should be visible to user */ public abstract boolean onIsRoleVisible(@NonNull String roleName); + + /** + * Queries the {@link RolePrivileges privileges} that the given role grants. + * + * @param roleName name of the role to quey for + * @return the {@link RolePrivileges} for the role + */ + public @NonNull RolePrivileges getRolePrivileges(@NonNull String roleName) { + return new RolePrivileges(emptyList(), emptyList(), emptyList(), emptyList()); + } } diff --git a/core/java/android/app/role/RolePrivileges.aidl b/core/java/android/app/role/RolePrivileges.aidl new file mode 100644 index 0000000000000..1561ad499d0a1 --- /dev/null +++ b/core/java/android/app/role/RolePrivileges.aidl @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package android.app.role; + +parcelable RolePrivileges; diff --git a/core/java/android/app/role/RolePrivileges.java b/core/java/android/app/role/RolePrivileges.java new file mode 100644 index 0000000000000..5fc0b0a086af3 --- /dev/null +++ b/core/java/android/app/role/RolePrivileges.java @@ -0,0 +1,221 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package android.app.role; + +import android.annotation.NonNull; +import android.annotation.SystemApi; +import android.os.Parcelable; + +import com.android.internal.util.DataClass; + +import java.util.List; + +/** + * Describes a set of privileges granted by a {@link RoleManager role} + * + * @hide + */ +@SystemApi +@DataClass +public final class RolePrivileges implements Parcelable { + + /** + * An identifier of a role holder app being granted the + * {@link android.service.notification.NotificationListenerService Notification Access} + * privilege. + */ + public static final String CAPABILITY_NOTIFICATION_LISTENER = + "android.app.role.capability.NOTIFICATION_LISTENER"; + + /** + * Permissions granted to the role holder(s). + */ + private @NonNull List mPermissions; + /** + * Appop permissions granted to the role holder(s). + */ + private @NonNull List mAppOpPermissions; + /** + * Appops granted to the role holder(s). + */ + private @NonNull List mAppOps; + /** + * Special access granted to the role holder(s). + * + * @see #CAPABILITY_NOTIFICATION_LISTENER + */ + private @NonNull List mCapabilities; + + + + // Code below generated by codegen v1.0.22. + // + // DO NOT MODIFY! + // CHECKSTYLE:OFF Generated code + // + // To regenerate run: + // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/role/RolePrivileges.java + // + // To exclude the generated code from IntelliJ auto-formatting enable (one-time): + // Settings > Editor > Code Style > Formatter Control + //@formatter:off + + + /** + * Creates a new RolePrivileges. + * + * @param permissions + * Permissions granted to the role holder(s). + * @param appOpPermissions + * Appop permissions granted to the role holder(s). + * @param appOps + * Appops granted to the role holder(s). + * @param capabilities + * Special access granted to the role holder(s). + */ + @DataClass.Generated.Member + public RolePrivileges( + @NonNull List permissions, + @NonNull List appOpPermissions, + @NonNull List appOps, + @NonNull List capabilities) { + this.mPermissions = permissions; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, mPermissions); + this.mAppOpPermissions = appOpPermissions; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, mAppOpPermissions); + this.mAppOps = appOps; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, mAppOps); + this.mCapabilities = capabilities; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, mCapabilities); + + // onConstructed(); // You can define this method to get a callback + } + + /** + * Permissions granted to the role holder(s). + */ + @DataClass.Generated.Member + public @NonNull List getPermissions() { + return mPermissions; + } + + /** + * Appop permissions granted to the role holder(s). + */ + @DataClass.Generated.Member + public @NonNull List getAppOpPermissions() { + return mAppOpPermissions; + } + + /** + * Appops granted to the role holder(s). + */ + @DataClass.Generated.Member + public @NonNull List getAppOps() { + return mAppOps; + } + + /** + * Special access granted to the role holder(s). + * + * @see #CAPABILITY_NOTIFICATION_LISTENER + */ + @DataClass.Generated.Member + public @NonNull List getCapabilities() { + return mCapabilities; + } + + @Override + @DataClass.Generated.Member + public void writeToParcel(@NonNull android.os.Parcel dest, int flags) { + // You can override field parcelling by defining methods like: + // void parcelFieldName(Parcel dest, int flags) { ... } + + dest.writeStringList(mPermissions); + dest.writeStringList(mAppOpPermissions); + dest.writeStringList(mAppOps); + dest.writeStringList(mCapabilities); + } + + @Override + @DataClass.Generated.Member + public int describeContents() { return 0; } + + /** @hide */ + @SuppressWarnings({"unchecked", "RedundantCast"}) + @DataClass.Generated.Member + /* package-private */ RolePrivileges(@NonNull android.os.Parcel in) { + // You can override field unparcelling by defining methods like: + // static FieldType unparcelFieldName(Parcel in) { ... } + + List permissions = new java.util.ArrayList<>(); + in.readStringList(permissions); + List appOpPermissions = new java.util.ArrayList<>(); + in.readStringList(appOpPermissions); + List appOps = new java.util.ArrayList<>(); + in.readStringList(appOps); + List capabilities = new java.util.ArrayList<>(); + in.readStringList(capabilities); + + this.mPermissions = permissions; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, mPermissions); + this.mAppOpPermissions = appOpPermissions; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, mAppOpPermissions); + this.mAppOps = appOps; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, mAppOps); + this.mCapabilities = capabilities; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, mCapabilities); + + // onConstructed(); // You can define this method to get a callback + } + + @DataClass.Generated.Member + public static final @NonNull Parcelable.Creator CREATOR + = new Parcelable.Creator() { + @Override + public RolePrivileges[] newArray(int size) { + return new RolePrivileges[size]; + } + + @Override + public RolePrivileges createFromParcel(@NonNull android.os.Parcel in) { + return new RolePrivileges(in); + } + }; + + @DataClass.Generated( + time = 1607546429137L, + codegenVersion = "1.0.22", + sourceFile = "frameworks/base/core/java/android/app/role/RolePrivileges.java", + inputSignatures = "public static final java.lang.String CAPABILITY_NOTIFICATION_LISTENER\nprivate @android.annotation.NonNull java.util.List mPermissions\nprivate @android.annotation.NonNull java.util.List mAppOpPermissions\nprivate @android.annotation.NonNull java.util.List mAppOps\nprivate @android.annotation.NonNull java.util.List mCapabilities\nclass RolePrivileges extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass") + @Deprecated + private void __metadata() {} + + + //@formatter:on + // End of generated code + +}