1 /* 2 * Copyright (C) 2019 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.server.policy; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.UserIdInt; 22 import android.app.TaskInfo; 23 import android.content.Intent; 24 25 /** 26 * Internal calls into {@link PermissionPolicyService}. 27 */ 28 public abstract class PermissionPolicyInternal { 29 30 /** 31 * Callback for initializing the permission policy service. 32 */ 33 public interface OnInitializedCallback { 34 35 /** 36 * Called when initialized for the given user. 37 * 38 * @param userId The initialized user. 39 */ onInitialized(@serIdInt int userId)40 void onInitialized(@UserIdInt int userId); 41 } 42 43 /** 44 * Check whether an activity should be started. 45 * 46 * @param intent the {@link Intent} for the activity start 47 * @param callingUid the calling uid starting the activity 48 * @param callingPackage the calling package starting the activity 49 * 50 * @return whether the activity should be started 51 */ checkStartActivity(@onNull Intent intent, int callingUid, @Nullable String callingPackage)52 public abstract boolean checkStartActivity(@NonNull Intent intent, int callingUid, 53 @Nullable String callingPackage); 54 55 /** 56 * Check whether a notification permission prompt should be shown for the given package. A 57 * prompt should be shown if the app targets S-, is currently running in a visible, focused 58 * task, has the REVIEW_REQUIRED flag set on its implicit notification permission, and has 59 * created at least one notification channel (even if it has since been deleted). 60 * 61 * @param packageName The package whose permission is being checked 62 * @param userId The user for whom the package is being started 63 * @param taskId The task the notification prompt should be attached to 64 */ showNotificationPromptIfNeeded(@onNull String packageName, int userId, int taskId)65 public abstract void showNotificationPromptIfNeeded(@NonNull String packageName, int userId, 66 int taskId); 67 68 /** 69 * Determine if a particular task is in the proper state to show a system-triggered permission 70 * prompt. A prompt can be shown if the task is focused, visible, and running and 71 * 1. The intent is a launcher intent (action is ACTION_MAIN, category is LAUNCHER), or 72 * 2. The activity belongs to the same package as the one which launched the task originally, 73 * and the task was started with a launcher intent 74 * 75 * @param taskInfo The task to be checked 76 * @param currPkg The package of the current top visible activity 77 * @param callingPkg The package that started the top visible activity 78 * @param intent The intent of the current top visible activity 79 * @param activityName The name of the current top visible activity 80 */ shouldShowNotificationDialogForTask(@ullable TaskInfo taskInfo, @Nullable String currPkg, @Nullable String callingPkg, @Nullable Intent intent, @NonNull String activityName)81 public abstract boolean shouldShowNotificationDialogForTask(@Nullable TaskInfo taskInfo, 82 @Nullable String currPkg, @Nullable String callingPkg, @Nullable Intent intent, 83 @NonNull String activityName); 84 85 /** 86 * @return true if an intent will resolve to a permission request dialog activity 87 */ isIntentToPermissionDialog(@onNull Intent intent)88 public abstract boolean isIntentToPermissionDialog(@NonNull Intent intent); 89 90 /** 91 * @return Whether the policy is initialized for a user. 92 */ isInitialized(@serIdInt int userId)93 public abstract boolean isInitialized(@UserIdInt int userId); 94 95 /** 96 * Set a callback for users being initialized. If the user is already 97 * initialized the callback will not be invoked. 98 * 99 * @param callback The callback to register. 100 */ setOnInitializedCallback(@onNull OnInitializedCallback callback)101 public abstract void setOnInitializedCallback(@NonNull OnInitializedCallback callback); 102 } 103