• 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.permission.ui.v34
18 
19 import android.os.Build
20 import android.os.Bundle
21 import android.view.View
22 import android.view.Window
23 import androidx.annotation.IntDef
24 import androidx.annotation.RequiresApi
25 
26 /**
27  * Class for managing the presentation and user interaction of the "permission rationale" user
28  * interface.
29  */
30 @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
31 interface PermissionRationaleViewHandler {
32     @Retention(AnnotationRetention.SOURCE)
33     @IntDef(Result.CANCELLED)
34     annotation class Result {
35         companion object {
36             const val CANCELLED = -1
37         }
38     }
39 
40     /**
41      * Listener interface for getting notified when the user responds to a permission rationale
42      * user action.
43      */
44     interface ResultListener {
onPermissionRationaleResultnull45         fun onPermissionRationaleResult(groupName: String?, @Result result: Int)
46     }
47 
48     /**
49      * Creates and returns the view hierarchy that is managed by this view handler. This must be
50      * called before [.updateUi].
51      */
52     fun createView(): View
53 
54     /**
55      * Updates the view hierarchy to reflect the specified state.
56      *
57      * Note that this must be called at least once before showing the UI to the user to properly
58      * initialize the UI.
59      *
60      * @param groupName the name of the permission group
61      * @param title the title for the dialog
62      * @param dataSharingSourceMessage the data sharing source data usage comes from message to
63      * display the user
64      * @param purposeTitle the data usage purposes title to display the user
65      * @param purposeMessage the data usage purposes message to display the user
66      * @param learnMoreMessage the more info about safety labels message to display the user
67      * @param settingsMessage the settings link message to display the user
68      */
69     fun updateUi(
70         groupName: String,
71         title: CharSequence,
72         dataSharingSourceMessage: CharSequence,
73         purposeTitle: CharSequence,
74         purposeMessage: CharSequence,
75         learnMoreMessage: CharSequence,
76         settingsMessage: CharSequence
77     )
78 
79     /**
80      * Called by [PermissionRationaleActivity] to save the state of this view handler to the
81      * specified bundle.
82      */
83     fun saveInstanceState(outState: Bundle)
84 
85     /**
86      * Called by [PermissionRationaleActivity] to load the state of this view handler from the
87      * specified bundle.
88      */
89     fun loadInstanceState(savedInstanceState: Bundle)
90 
91     /** Gives a chance for handling the back key. */
92     fun onBackPressed()
93 
94     /**
95      * Handles cancel event for the permission rationale dialog.
96      */
97     fun onCancelled() {}
98 
99     /**
100      * Called by [PermissionRationaleActivity] to allow the handler to update the ui when blur is
101      * enabled/disabled.
102      */
onBlurEnabledChangednull103     fun onBlurEnabledChanged(window: Window?, enabled: Boolean) {}
104 }
105