• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.permission.ui;
18 
19 import static java.lang.annotation.RetentionPolicy.SOURCE;
20 
21 import android.graphics.drawable.Icon;
22 import android.os.Bundle;
23 import android.view.View;
24 import android.view.Window;
25 import android.view.WindowManager;
26 
27 import androidx.annotation.IntDef;
28 
29 import java.lang.annotation.Retention;
30 import java.util.List;
31 
32 /**
33  * Class for managing the presentation and user interaction of the "grant
34  * permissions" user interface.
35  */
36 public interface GrantPermissionsViewHandler {
37     @Retention(SOURCE)
38     @IntDef({CANCELED, GRANTED_ALWAYS, GRANTED_FOREGROUND_ONLY, DENIED, DENIED_DO_NOT_ASK_AGAIN,
39             GRANTED_ONE_TIME})
40     @interface Result {}
41     int LINKED_TO_SETTINGS = -2;
42     int CANCELED = -1;
43     int GRANTED_ALWAYS = 0;
44     int GRANTED_FOREGROUND_ONLY = 1;
45     int DENIED = 2;
46     int DENIED_DO_NOT_ASK_AGAIN = 3;
47     int GRANTED_ONE_TIME = 4;
48 
49     /**
50      * Listener interface for getting notified when the user responds to a
51      * permissions grant request.
52      */
53     interface ResultListener {
onPermissionGrantResult(String groupName, @Result int result)54         void onPermissionGrantResult(String groupName, @Result int result);
55 
onPermissionGrantResult(String groupName, List<String> affectedForegroundPermissions, @Result int result)56         void onPermissionGrantResult(String groupName, List<String> affectedForegroundPermissions,
57                 @Result int result);
58     }
59 
60     /**
61      * Creates and returns the view hierarchy that is managed by this view
62      * handler. This must be called before {@link #updateUi}.
63      */
createView()64     View createView();
65 
66     /**
67      * Updates the layout attributes of the current window. This is an optional
68      * operation; implementations only need to do work in this method if they
69      * need to alter the default styles provided by the activity's theme.
70      */
updateWindowAttributes(WindowManager.LayoutParams outLayoutParams)71     void updateWindowAttributes(WindowManager.LayoutParams outLayoutParams);
72 
73     /**
74      * Updates the view hierarchy to reflect the specified state.
75      * <p>
76      * Note that this must be called at least once before showing the UI to
77      * the user to properly initialize the UI.
78      *
79      * @param groupName the name of the permission group
80      * @param groupCount the total number of groups that are being requested
81      * @param groupIndex the index of the current group being requested
82      * @param icon the icon representation of the current group
83      * @param message the message to display the user
84      * @param detailMessage another message to display to the user. This clarifies "message" in more
85      *                      detail
86      * @param buttonVisibilities visibilities for each button
87      * @param locationVisibilities visibilities for location options
88      */
updateUi(String groupName, int groupCount, int groupIndex, Icon icon, CharSequence message, CharSequence detailMessage, boolean[] buttonVisibilities, boolean[] locationVisibilities)89     void updateUi(String groupName, int groupCount, int groupIndex, Icon icon,
90             CharSequence message, CharSequence detailMessage, boolean[] buttonVisibilities,
91             boolean[] locationVisibilities);
92 
93     /**
94      * Sets the result listener that will be notified when the user responds
95      * to a permissions grant request.
96      */
setResultListener(ResultListener listener)97     GrantPermissionsViewHandler setResultListener(ResultListener listener);
98 
99     /**
100      * Called by {@link GrantPermissionsActivity} to save the state of this
101      * view handler to the specified bundle.
102      */
saveInstanceState(Bundle outState)103     void saveInstanceState(Bundle outState);
104 
105     /**
106      * Called by {@link GrantPermissionsActivity} to load the state of this
107      * view handler from the specified bundle.
108      */
loadInstanceState(Bundle savedInstanceState)109     void loadInstanceState(Bundle savedInstanceState);
110 
111     /**
112      * Gives a chance for handling the back key.
113      */
onBackPressed()114     void onBackPressed();
115 
116     /**
117      * Called by {@link GrantPermissionsActivity} to allow the handler to update
118      * the ui when blur is enabled/disabled.
119      */
onBlurEnabledChanged(Window window, boolean enabled)120     default void onBlurEnabledChanged(Window window, boolean enabled) {}
121 }
122