• 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.TwoTargetPreference;
29 import com.android.role.controller.model.Role;
30 
31 /***
32  * Interface for UI behavior for roles
33  */
34 public interface RoleUiBehavior {
35 
36     /**
37      * Check whether this role should be visible to user.
38      *
39      * @param role the role to check for
40      * @param user the user to check for
41      * @param context the `Context` to retrieve system services
42      *
43      * @return whether this role should be visible to user
44      */
isVisibleAsUser(@onNull Role role, @NonNull UserHandle user, @NonNull Context context)45     default boolean isVisibleAsUser(@NonNull Role role, @NonNull UserHandle user,
46             @NonNull Context context) {
47         return true;
48     }
49 
50     /**
51      * Get the {@link Intent} to manage this role, or {@code null} to use the default UI.
52      *
53      * @param role the role to get the intent for
54      * @param user the user to manage this role for
55      * @param context the {@code Context} to retrieve system services
56      *
57      * @return the {@link Intent} to manage this role, or {@code null} to use the default UI.
58      */
59     @Nullable
getManageIntentAsUser(@onNull Role role, @NonNull UserHandle user, @NonNull Context context)60     default Intent getManageIntentAsUser(@NonNull Role role, @NonNull UserHandle user,
61             @NonNull Context context) {
62         return null;
63     }
64 
65     /**
66      * Prepare a {@link Preference} for this role.
67      *
68      * @param role the role to prepare the preference for
69      * @param preference the {@link Preference} for this role
70      * @param user the user for this role
71      * @param context the {@code Context} to retrieve system services
72      */
preparePreferenceAsUser(@onNull Role role, @NonNull TwoTargetPreference preference, @NonNull UserHandle user, @NonNull Context context)73     default void preparePreferenceAsUser(@NonNull Role role,
74             @NonNull TwoTargetPreference preference,
75             @NonNull UserHandle user,
76             @NonNull Context context) {}
77 
78     /**
79      * Check whether a qualifying application should be visible to user.
80      *
81      * @param applicationInfo the {@link ApplicationInfo} for the application
82      * @param user the user for the application
83      * @param context the {@code Context} to retrieve system services
84      *
85      * @return whether the qualifying application should be visible to user
86      */
isApplicationVisibleAsUser(@onNull Role role, @NonNull ApplicationInfo applicationInfo, @NonNull UserHandle user, @NonNull Context context)87     default boolean isApplicationVisibleAsUser(@NonNull Role role,
88             @NonNull ApplicationInfo applicationInfo, @NonNull UserHandle user,
89             @NonNull Context context) {
90         return true;
91     }
92 
93     /**
94      * Prepare a {@link Preference} for this role.
95      *
96      * @param role the role to prepare the preference for
97      * @param preference the {@link Preference} for this role
98      * @param user the user for this role
99      * @param context the {@code Context} to retrieve system services
100      */
prepareApplicationPreferenceAsUser(@onNull Role role, @NonNull Preference preference, @NonNull ApplicationInfo applicationInfo, @NonNull UserHandle user, @NonNull Context context)101     default void prepareApplicationPreferenceAsUser(@NonNull Role role,
102             @NonNull Preference preference, @NonNull ApplicationInfo applicationInfo,
103             @NonNull UserHandle user, @NonNull Context context) {}
104 
105     /**
106      * Get the confirmation message for adding an application as a holder of this role.
107      *
108      * @param role the role to get confirmation message for
109      * @param packageName the package name of the application to get confirmation message for
110      * @param context the {@code Context} to retrieve system services
111      *
112      * @return the confirmation message, or {@code null} if no confirmation is needed
113      */
114     @Nullable
getConfirmationMessage(@onNull Role role, @NonNull String packageName, @NonNull Context context)115     default CharSequence getConfirmationMessage(@NonNull Role role, @NonNull String packageName,
116             @NonNull Context context) {
117         return null;
118     }
119 }
120