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.packageinstaller.role.model; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.content.pm.ApplicationInfo; 22 import android.os.UserHandle; 23 24 import androidx.annotation.NonNull; 25 import androidx.annotation.Nullable; 26 import androidx.preference.Preference; 27 28 import com.android.packageinstaller.role.ui.TwoTargetPreference; 29 30 import java.util.Collections; 31 import java.util.List; 32 33 /** 34 * Interface for behavior of a role. 35 */ 36 public interface RoleBehavior { 37 38 /** 39 * @see Role#isAvailableAsUser(UserHandle, Context) 40 */ isAvailableAsUser(@onNull Role role, @NonNull UserHandle user, @NonNull Context context)41 default boolean isAvailableAsUser(@NonNull Role role, @NonNull UserHandle user, 42 @NonNull Context context) { 43 return true; 44 } 45 46 /** 47 * @see Role#getDefaultHolders(Context) 48 */ 49 @NonNull getDefaultHolders(@onNull Role role, @NonNull Context context)50 default List<String> getDefaultHolders(@NonNull Role role, @NonNull Context context) { 51 return Collections.emptyList(); 52 } 53 54 /** 55 * @see Role#getFallbackHolder(Context) 56 */ 57 @Nullable getFallbackHolder(@onNull Role role, @NonNull Context context)58 default String getFallbackHolder(@NonNull Role role, @NonNull Context context) { 59 return null; 60 } 61 62 /** 63 * @see Role#isVisibleAsUser(UserHandle, Context) 64 */ isVisibleAsUser(@onNull Role role, @NonNull UserHandle user, @NonNull Context context)65 default boolean isVisibleAsUser(@NonNull Role role, @NonNull UserHandle user, 66 @NonNull Context context) { 67 return true; 68 } 69 70 /** 71 * @see Role#getManageIntentAsUser(UserHandle, Context) 72 */ 73 @Nullable getManageIntentAsUser(@onNull Role role, @NonNull UserHandle user, @NonNull Context context)74 default Intent getManageIntentAsUser(@NonNull Role role, @NonNull UserHandle user, 75 @NonNull Context context) { 76 return null; 77 } 78 79 /** 80 * @see Role#preparePreferenceAsUser(TwoTargetPreference, UserHandle, Context) 81 */ preparePreferenceAsUser(@onNull Role role, @NonNull TwoTargetPreference preference, @NonNull UserHandle user, @NonNull Context context)82 default void preparePreferenceAsUser(@NonNull Role role, 83 @NonNull TwoTargetPreference preference, @NonNull UserHandle user, 84 @NonNull Context context) {} 85 86 /** 87 * @see Role#prepareApplicationPreferenceAsUser(Preference, ApplicationInfo, UserHandle, 88 * Context) 89 */ prepareApplicationPreferenceAsUser(@onNull Role role, @NonNull Preference preference, @NonNull ApplicationInfo applicationInfo, @NonNull UserHandle user, @NonNull Context context)90 default void prepareApplicationPreferenceAsUser(@NonNull Role role, 91 @NonNull Preference preference, @NonNull ApplicationInfo applicationInfo, 92 @NonNull UserHandle user, @NonNull Context context) {} 93 94 /** 95 * @see Role#getConfirmationMessage(String, Context) 96 */ 97 @Nullable getConfirmationMessage(@onNull Role role, @NonNull String packageName, @NonNull Context context)98 default CharSequence getConfirmationMessage(@NonNull Role role, @NonNull String packageName, 99 @NonNull Context context) { 100 return null; 101 } 102 103 /** 104 * @see Role#getQualifyingPackagesAsUser(UserHandle, Context) 105 */ 106 @Nullable getQualifyingPackagesAsUser(@onNull Role role, @NonNull UserHandle user, @NonNull Context context)107 default List<String> getQualifyingPackagesAsUser(@NonNull Role role, @NonNull UserHandle user, 108 @NonNull Context context) { 109 return null; 110 } 111 112 /** 113 * @see Role#isPackageQualified(String, Context) 114 */ 115 @Nullable isPackageQualified(@onNull Role role, @NonNull String packageName, @NonNull Context context)116 default Boolean isPackageQualified(@NonNull Role role, @NonNull String packageName, 117 @NonNull Context context) { 118 return null; 119 } 120 121 /** 122 * @see Role#grant(String, boolean, boolean, boolean, Context) 123 */ grant(@onNull Role role, @NonNull String packageName, @NonNull Context context)124 default void grant(@NonNull Role role, @NonNull String packageName, @NonNull Context context) {} 125 126 /** 127 * @see Role#revoke(String, boolean, boolean, Context) 128 */ revoke(@onNull Role role, @NonNull String packageName, @NonNull Context context)129 default void revoke(@NonNull Role role, @NonNull String packageName, 130 @NonNull Context context) {} 131 132 /** 133 * @see Role#onHolderSelectedAsUser(String, UserHandle, Context) 134 */ onHolderSelectedAsUser(@onNull Role role, @NonNull String packageName, @NonNull UserHandle user, @NonNull Context context)135 default void onHolderSelectedAsUser(@NonNull Role role, @NonNull String packageName, 136 @NonNull UserHandle user, @NonNull Context context) {} 137 138 /** 139 * @see Role#onHolderChangedAsUser(String, UserHandle, Context) 140 */ onHolderChangedAsUser(@onNull Role role, @NonNull UserHandle user, @NonNull Context context)141 default void onHolderChangedAsUser(@NonNull Role role, @NonNull UserHandle user, 142 @NonNull Context context) {} 143 } 144