1 /* 2 * Copyright (C) 2022 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.permissioncontroller.role.ui.behavior; 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.permissioncontroller.role.ui.RequestRoleItemView; 29 import com.android.permissioncontroller.role.ui.TwoTargetPreference; 30 import com.android.role.controller.model.Role; 31 32 import java.util.List; 33 34 /*** 35 * Interface for UI behavior for roles 36 */ 37 public interface RoleUiBehavior { 38 39 /** 40 * Prepare a {@link RequestRoleItemView} for this role and an application. 41 * 42 * @param role the role to prepare the preference for 43 * @param itemView the {@link RequestRoleItemView} for the application 44 * @param applicationInfo the {@link ApplicationInfo} for the application 45 * @param user the user for this role 46 * @param context the {@code Context} to retrieve system services 47 */ prepareRequestRoleItemViewAsUser(@onNull Role role, @NonNull RequestRoleItemView itemView, @NonNull ApplicationInfo applicationInfo, @NonNull UserHandle user, @NonNull Context context)48 default void prepareRequestRoleItemViewAsUser(@NonNull Role role, 49 @NonNull RequestRoleItemView itemView, @NonNull ApplicationInfo applicationInfo, 50 @NonNull UserHandle user, @NonNull Context context) {} 51 52 /** 53 * Get the {@link Intent} to manage this role, or {@code null} to use the default UI. 54 * 55 * @param role the role to get the intent for 56 * @param user the user to manage this role for 57 * @param context the {@code Context} to retrieve system services 58 * 59 * @return the {@link Intent} to manage this role, or {@code null} to use the default UI. 60 */ 61 @Nullable getManageIntentAsUser(@onNull Role role, @NonNull UserHandle user, @NonNull Context context)62 default Intent getManageIntentAsUser(@NonNull Role role, @NonNull UserHandle user, 63 @NonNull Context context) { 64 return null; 65 } 66 67 /** 68 * Prepare a {@link Preference} for this role. 69 * 70 * @param role the role to prepare the preference for 71 * @param preference the {@link Preference} for this role 72 * @param applicationInfos a list {@link ApplicationInfo} for the current role holders 73 * @param user the user for this role 74 * @param context the {@code Context} to retrieve system services 75 */ preparePreferenceAsUser(@onNull Role role, @NonNull TwoTargetPreference preference, @NonNull List<ApplicationInfo> applicationInfos, @NonNull UserHandle user, @NonNull Context context)76 default void preparePreferenceAsUser(@NonNull Role role, 77 @NonNull TwoTargetPreference preference, 78 @NonNull List<ApplicationInfo> applicationInfos, 79 @NonNull UserHandle user, @NonNull Context context) {} 80 81 /** 82 * Prepare a {@link Preference} for this role and an application. 83 * 84 * @param role the role to prepare the preference for 85 * @param preference the {@link Preference} for the application 86 * @param applicationInfo the {@link ApplicationInfo} for the application 87 * @param user the user for this role 88 * @param context the {@code Context} to retrieve system services 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 * Get the confirmation message for adding an application as a holder of this role. 96 * 97 * @param role the role to get confirmation message for 98 * @param packageName the package name of the application to get confirmation message for 99 * @param context the {@code Context} to retrieve system services 100 * 101 * @return the confirmation message, or {@code null} if no confirmation is needed 102 */ 103 @Nullable getConfirmationMessage(@onNull Role role, @NonNull String packageName, @NonNull Context context)104 default CharSequence getConfirmationMessage(@NonNull Role role, @NonNull String packageName, 105 @NonNull Context context) { 106 return null; 107 } 108 } 109