1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.role.controller.model; 18 19 import android.content.Context; 20 import android.content.pm.ApplicationInfo; 21 import android.os.UserHandle; 22 23 import androidx.annotation.NonNull; 24 import androidx.annotation.Nullable; 25 26 import java.util.Collections; 27 import java.util.List; 28 29 /** 30 * Interface for behavior of a role. 31 */ 32 public interface RoleBehavior { 33 34 /** 35 * @see Role#onRoleAddedAsUser(UserHandle, Context) 36 */ onRoleAddedAsUser(@onNull Role role, @NonNull UserHandle user, @NonNull Context context)37 default void onRoleAddedAsUser(@NonNull Role role, @NonNull UserHandle user, 38 @NonNull Context context) {} 39 40 /** 41 * @see Role#isAvailableAsUser(UserHandle, Context) 42 */ isAvailableAsUser(@onNull Role role, @NonNull UserHandle user, @NonNull Context context)43 default boolean isAvailableAsUser(@NonNull Role role, @NonNull UserHandle user, 44 @NonNull Context context) { 45 return true; 46 } 47 48 /** 49 * @see Role#getDefaultHolders(Context) 50 */ 51 @Nullable getDefaultHoldersAsUser(@onNull Role role, @NonNull UserHandle user, @NonNull Context context)52 default List<String> getDefaultHoldersAsUser(@NonNull Role role, @NonNull UserHandle user, 53 @NonNull Context context) { 54 return null; 55 } 56 57 /** 58 * @see Role#getFallbackHolder(Context) 59 */ 60 @Nullable getFallbackHolderAsUser(@onNull Role role, @NonNull UserHandle user, @NonNull Context context)61 default String getFallbackHolderAsUser(@NonNull Role role, @NonNull UserHandle user, 62 @NonNull Context context) { 63 return null; 64 } 65 66 /** 67 * @see Role#shouldAllowBypassingQualification(Context) 68 */ 69 @Nullable shouldAllowBypassingQualification(@onNull Role role, @NonNull Context context)70 default Boolean shouldAllowBypassingQualification(@NonNull Role role, 71 @NonNull Context context) { 72 return null; 73 } 74 75 /** 76 * @see Role#isPackageQualified(String, Context) 77 */ 78 @Nullable isPackageQualifiedAsUser(@onNull Role role, @NonNull String packageName, @NonNull UserHandle user, @NonNull Context context)79 default Boolean isPackageQualifiedAsUser(@NonNull Role role, @NonNull String packageName, 80 @NonNull UserHandle user, @NonNull Context context) { 81 return null; 82 } 83 84 /** 85 * @see Role#getQualifyingPackagesAsUser(UserHandle, Context) 86 */ 87 @Nullable getQualifyingPackagesAsUser(@onNull Role role, @NonNull UserHandle user, @NonNull Context context)88 default List<String> getQualifyingPackagesAsUser(@NonNull Role role, @NonNull UserHandle user, 89 @NonNull Context context) { 90 return null; 91 } 92 93 /** 94 * @see Role#grantAsUser(String, boolean, boolean, UserHandle, Context) 95 */ grantAsUser(@onNull Role role, @NonNull String packageName, @NonNull UserHandle user, @NonNull Context context)96 default void grantAsUser(@NonNull Role role, @NonNull String packageName, 97 @NonNull UserHandle user, @NonNull Context context) {} 98 99 /** 100 * @see Role#revokeAsUser(String, boolean, boolean, UserHandle, Context) 101 */ revokeAsUser(@onNull Role role, @NonNull String packageName, @NonNull UserHandle user, @NonNull Context context)102 default void revokeAsUser(@NonNull Role role, @NonNull String packageName, 103 @NonNull UserHandle user, @NonNull Context context) {} 104 105 /** 106 * @see Role#onHolderSelectedAsUser(String, UserHandle, Context) 107 */ onHolderSelectedAsUser(@onNull Role role, @NonNull String packageName, @NonNull UserHandle user, @NonNull Context context)108 default void onHolderSelectedAsUser(@NonNull Role role, @NonNull String packageName, 109 @NonNull UserHandle user, @NonNull Context context) {} 110 111 /** 112 * @see Role#onHolderChangedAsUser(String, UserHandle, Context) 113 */ onHolderChangedAsUser(@onNull Role role, @NonNull UserHandle user, @NonNull Context context)114 default void onHolderChangedAsUser(@NonNull Role role, @NonNull UserHandle user, 115 @NonNull Context context) {} 116 117 /** 118 * Check whether this role should be visible to user. 119 * 120 * @param role the role to check for 121 * @param user the user to check for 122 * @param context the `Context` to retrieve system services 123 * 124 * @return whether this role should be visible to user 125 */ isVisibleAsUser(@onNull Role role, @NonNull UserHandle user, @NonNull Context context)126 default boolean isVisibleAsUser(@NonNull Role role, @NonNull UserHandle user, 127 @NonNull Context context) { 128 return true; 129 } 130 131 /** 132 * Check whether a qualifying application should be visible to user. 133 * 134 * @param role the role to check for 135 * @param applicationInfo the {@link ApplicationInfo} for the application 136 * @param user the user for the application 137 * @param context the {@code Context} to retrieve system services 138 * 139 * @return whether the qualifying application should be visible to user 140 */ isApplicationVisibleAsUser(@onNull Role role, @NonNull ApplicationInfo applicationInfo, @NonNull UserHandle user, @NonNull Context context)141 default boolean isApplicationVisibleAsUser(@NonNull Role role, 142 @NonNull ApplicationInfo applicationInfo, @NonNull UserHandle user, 143 @NonNull Context context) { 144 return true; 145 } 146 } 147