• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.RoleApplicationItem;
30 import com.android.permissioncontroller.role.ui.TwoTargetPreference;
31 import com.android.role.controller.model.Role;
32 
33 import java.util.List;
34 import java.util.function.Predicate;
35 
36 /***
37  * Interface for UI behavior for roles
38  */
39 public interface RoleUiBehavior {
40 
41     /**
42      * Prepare a {@link RequestRoleItemView} for this role and an application.
43      *
44      * @param role the role to prepare the preference for
45      * @param itemView the {@link RequestRoleItemView} for the application
46      * @param applicationInfo the {@link ApplicationInfo} for the application
47      * @param user the user for this role
48      * @param context the {@code Context} to retrieve system services
49      */
prepareRequestRoleItemViewAsUser(@onNull Role role, @NonNull RequestRoleItemView itemView, @NonNull ApplicationInfo applicationInfo, @NonNull UserHandle user, @NonNull Context context)50     default void prepareRequestRoleItemViewAsUser(@NonNull Role role,
51             @NonNull RequestRoleItemView itemView, @NonNull ApplicationInfo applicationInfo,
52             @NonNull UserHandle user, @NonNull Context context) {}
53 
54     /**
55      * Get the {@link Intent} to manage this role, or {@code null} to use the default UI.
56      *
57      * @param role the role to get the intent for
58      * @param user the user to manage this role for
59      * @param context the {@code Context} to retrieve system services
60      *
61      * @return the {@link Intent} to manage this role, or {@code null} to use the default UI.
62      */
63     @Nullable
getManageIntentAsUser(@onNull Role role, @NonNull UserHandle user, @NonNull Context context)64     default Intent getManageIntentAsUser(@NonNull Role role, @NonNull UserHandle user,
65             @NonNull Context context) {
66         return null;
67     }
68 
69     /**
70      * Prepare a {@link Preference} for this role.
71      *
72      * @param role the role to prepare the preference for
73      * @param preference the {@link Preference} for this role
74      * @param applicationInfos a list {@link ApplicationInfo} for the current role holders
75      * @param user the user for this role
76      * @param context the {@code Context} to retrieve system services
77      */
preparePreferenceAsUser(@onNull Role role, @NonNull TwoTargetPreference preference, @NonNull List<ApplicationInfo> applicationInfos, @NonNull UserHandle user, @NonNull Context context)78     default void preparePreferenceAsUser(@NonNull Role role,
79             @NonNull TwoTargetPreference preference,
80             @NonNull List<ApplicationInfo> applicationInfos,
81             @NonNull UserHandle user, @NonNull Context context) {}
82 
83     /**
84      * Prepare a {@link Preference} for this role and an application.
85      *
86      * @param role the role to prepare the preference for
87      * @param preference the {@link Preference} for the application
88      * @param applicationInfo the {@link ApplicationInfo} for the application
89      * @param user the user for this role
90      * @param context the {@code Context} to retrieve system services
91      */
prepareApplicationPreferenceAsUser(@onNull Role role, @NonNull Preference preference, @NonNull ApplicationInfo applicationInfo, @NonNull UserHandle user, @NonNull Context context)92     default void prepareApplicationPreferenceAsUser(@NonNull Role role,
93             @NonNull Preference preference, @NonNull ApplicationInfo applicationInfo,
94             @NonNull UserHandle user, @NonNull Context context) {}
95 
96     /**
97      * Get the filter for recommended applications of this role.
98      *
99      * @param role the role to get the recommended application filter for
100      * @param context the {@code Context} to retrieve system services
101      *
102      * @return the filter for recommended applications
103      */
104     @NonNull
getRecommendedApplicationFilter( @onNull Role role, @NonNull Context context)105     default Predicate<RoleApplicationItem> getRecommendedApplicationFilter(
106             @NonNull Role role, @NonNull Context context) {
107         return applicationItem -> false;
108     }
109 
110     /**
111      * Get the confirmation message for adding an application as a holder of this role.
112      *
113      * @param role the role to get confirmation message for
114      * @param packageName the package name of the application to get confirmation message for
115      * @param context the {@code Context} to retrieve system services
116      *
117      * @return the confirmation message, or {@code null} if no confirmation is needed
118      */
119     @Nullable
getConfirmationMessage(@onNull Role role, @NonNull String packageName, @NonNull Context context)120     default CharSequence getConfirmationMessage(@NonNull Role role, @NonNull String packageName,
121             @NonNull Context context) {
122         return null;
123     }
124 }
125