1 /* 2 * Copyright (C) 2023 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.model.grantPermissions 18 19 import android.os.Build.VERSION_CODES.TIRAMISU 20 import com.android.permissioncontroller.permission.model.livedatatypes.LightAppPermGroup 21 import com.android.permissioncontroller.permission.ui.model.DenyButton 22 import com.android.permissioncontroller.permission.ui.model.Prompt 23 24 /** 25 * The Notification permission behavior is similar to basic, except: 26 * 27 * It can be triggered by the system. If it's system triggered we only show it until the user makes 28 * one decision. We don't make the user show it twice. 29 * 30 * It can't be explicitly requested from apps that don't yet target android T. If they try, we 31 * remove it entirely from the request, do not return a result, and take no action on it. 32 */ 33 object NotificationGrantBehavior : GrantBehavior() { getPromptnull34 override fun getPrompt( 35 group: LightAppPermGroup, 36 requestedPerms: Set<String>, 37 isSystemTriggeredPrompt: Boolean 38 ): Prompt { 39 val isPreT = group.packageInfo.targetSdkVersion < TIRAMISU 40 if (!isSystemTriggeredPrompt && isPreT) { 41 // Apps targeting below T cannot manually request Notifications 42 return Prompt.NO_UI_FILTER_THIS_GROUP 43 } else if (isPreT && group.isUserSet) { 44 // If the user has seen the system-triggered prompt once, don't show it again 45 return Prompt.NO_UI_FILTER_THIS_GROUP 46 } 47 return BasicGrantBehavior.getPrompt(group, requestedPerms, isSystemTriggeredPrompt) 48 } 49 getDenyButtonnull50 override fun getDenyButton( 51 group: LightAppPermGroup, 52 requestedPerms: Set<String>, 53 prompt: Prompt 54 ): DenyButton { 55 return BasicGrantBehavior.getDenyButton(group, requestedPerms, prompt) 56 } 57 } 58