Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dd010427 authored by Eugene Susla's avatar Eugene Susla
Browse files

Add API to query role privileges

Bug: 165951651
Test: presubmit
Change-Id: Ib69fe274960681252ad17ba849f7de8fee8efc24
parent aeca9585
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -1341,6 +1341,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);
@@ -1367,6 +1368,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<java.lang.String>, @NonNull java.util.List<java.lang.String>, @NonNull java.util.List<java.lang.String>, @NonNull java.util.List<java.lang.String>);
    method public int describeContents();
    method @NonNull public java.util.List<java.lang.String> getAppOpPermissions();
    method @NonNull public java.util.List<java.lang.String> getAppOps();
    method @NonNull public java.util.List<java.lang.String> getCapabilities();
    method @NonNull public java.util.List<java.lang.String> 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<android.app.role.RolePrivileges> CREATOR;
  }
}
package android.app.time {
+4 −0
Original line number Diff line number Diff line
@@ -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<RolePrivileges> callback);
}
+27 −0
Original line number Diff line number Diff line
@@ -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<RolePrivileges> 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());
    }
}
+20 −0
Original line number Diff line number Diff line
/*
 * 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;
+221 −0
Original line number Diff line number Diff line
/*
 * 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<String> mPermissions;
    /**
     * Appop permissions granted to the role holder(s).
     */
    private @NonNull List<String> mAppOpPermissions;
    /**
     * Appops granted to the role holder(s).
     */
    private @NonNull List<String> mAppOps;
    /**
     * Special access granted to the role holder(s).
     *
     * @see #CAPABILITY_NOTIFICATION_LISTENER
     */
    private @NonNull List<String> 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<String> permissions,
            @NonNull List<String> appOpPermissions,
            @NonNull List<String> appOps,
            @NonNull List<String> 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<String> getPermissions() {
        return mPermissions;
    }

    /**
     * Appop permissions granted to the role holder(s).
     */
    @DataClass.Generated.Member
    public @NonNull List<String> getAppOpPermissions() {
        return mAppOpPermissions;
    }

    /**
     * Appops granted to the role holder(s).
     */
    @DataClass.Generated.Member
    public @NonNull List<String> getAppOps() {
        return mAppOps;
    }

    /**
     * Special access granted to the role holder(s).
     *
     * @see #CAPABILITY_NOTIFICATION_LISTENER
     */
    @DataClass.Generated.Member
    public @NonNull List<String> 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<String> permissions = new java.util.ArrayList<>();
        in.readStringList(permissions);
        List<String> appOpPermissions = new java.util.ArrayList<>();
        in.readStringList(appOpPermissions);
        List<String> appOps = new java.util.ArrayList<>();
        in.readStringList(appOps);
        List<String> 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<RolePrivileges> CREATOR
            = new Parcelable.Creator<RolePrivileges>() {
        @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<java.lang.String> mPermissions\nprivate @android.annotation.NonNull java.util.List<java.lang.String> mAppOpPermissions\nprivate @android.annotation.NonNull java.util.List<java.lang.String> mAppOps\nprivate @android.annotation.NonNull java.util.List<java.lang.String> 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

}