• 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.packageinstaller.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.WindowManager;
25 
26 import androidx.annotation.IntDef;
27 
28 import java.lang.annotation.Retention;
29 
30 /**
31  * Class for managing the presentation and user interaction of the "grant
32  * permissions" user interface.
33  */
34 public interface GrantPermissionsViewHandler {
35     @Retention(SOURCE)
36     @IntDef({GRANTED_ALWAYS, GRANTED_FOREGROUND_ONLY, DENIED, DENIED_DO_NOT_ASK_AGAIN})
37     @interface Result {}
38     int GRANTED_ALWAYS = 0;
39     int GRANTED_FOREGROUND_ONLY = 1;
40     int DENIED = 2;
41     int DENIED_DO_NOT_ASK_AGAIN = 3;
42 
43     /**
44      * Listener interface for getting notified when the user responds to a
45      * permissions grant request.
46      */
47     interface ResultListener {
onPermissionGrantResult(String groupName, @Result int result)48         void onPermissionGrantResult(String groupName, @Result int result);
49     }
50 
51     /**
52      * Creates and returns the view hierarchy that is managed by this view
53      * handler. This must be called before {@link #updateUi}.
54      */
createView()55     View createView();
56 
57     /**
58      * Updates the layout attributes of the current window. This is an optional
59      * operation; implementations only need to do work in this method if they
60      * need to alter the default styles provided by the activity's theme.
61      */
updateWindowAttributes(WindowManager.LayoutParams outLayoutParams)62     void updateWindowAttributes(WindowManager.LayoutParams outLayoutParams);
63 
64     /**
65      * Updates the view hierarchy to reflect the specified state.
66      * <p>
67      * Note that this must be called at least once before showing the UI to
68      * the user to properly initialize the UI.
69      *
70      * @param groupName the name of the permission group
71      * @param groupCount the total number of groups that are being requested
72      * @param groupIndex the index of the current group being requested
73      * @param icon the icon representation of the current group
74      * @param message the message to display the user
75      * @param detailMessage another message to display to the user. This clarifies "message" in more
76      *                      detail
77      * @param buttonLabels labels for each button. Use null to make the button gone
78      */
updateUi(String groupName, int groupCount, int groupIndex, Icon icon, CharSequence message, CharSequence detailMessage, CharSequence[] buttonLabels)79     void updateUi(String groupName, int groupCount, int groupIndex, Icon icon,
80             CharSequence message, CharSequence detailMessage, CharSequence[] buttonLabels);
81 
82     /**
83      * Sets the result listener that will be notified when the user responds
84      * to a permissions grant request.
85      */
setResultListener(ResultListener listener)86     GrantPermissionsViewHandler setResultListener(ResultListener listener);
87 
88     /**
89      * Called by {@link GrantPermissionsActivity} to save the state of this
90      * view handler to the specified bundle.
91      */
saveInstanceState(Bundle outState)92     void saveInstanceState(Bundle outState);
93 
94     /**
95      * Called by {@link GrantPermissionsActivity} to load the state of this
96      * view handler from the specified bundle.
97      */
loadInstanceState(Bundle savedInstanceState)98     void loadInstanceState(Bundle savedInstanceState);
99 
100     /**
101      * Gives a chance for handling the back key.
102      */
onBackPressed()103     void onBackPressed();
104 }
105