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 android.permission; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.UserIdInt; 22 import android.os.UserHandle; 23 24 import com.android.internal.util.function.TriFunction; 25 26 import java.util.function.BiFunction; 27 28 /** 29 * Internal interfaces to be used by other components within the system server. 30 * 31 * <p>Only for use within the system server. 32 * 33 * @hide 34 */ 35 public abstract class PermissionManagerInternal { 36 37 /** 38 * Listener for package permission state (permissions or flags) changes. 39 */ 40 public interface OnRuntimePermissionStateChangedListener { 41 42 /** 43 * Called when the runtime permission state (permissions or flags) changed. 44 * 45 * @param packageName The package for which the change happened. 46 * @param userId the user id for which the change happened. 47 */ 48 @Nullable onRuntimePermissionStateChanged(@onNull String packageName, @UserIdInt int userId)49 void onRuntimePermissionStateChanged(@NonNull String packageName, 50 @UserIdInt int userId); 51 } 52 53 /** Interface to override permission checks via composition */ 54 public interface CheckPermissionDelegate { 55 /** 56 * Checks whether the given package has been granted the specified permission. 57 * 58 * @return If the package has the permission, PERMISSION_GRANTED is 59 * returned. If it does not have the permission, PERMISSION_DENIED 60 * is returned. 61 * 62 * @see android.content.pm.PackageManager#checkPermission(String, String) 63 */ checkPermission(String permName, String pkgName, int userId, TriFunction<String, String, Integer, Integer> superImpl)64 int checkPermission(String permName, String pkgName, int userId, 65 TriFunction<String, String, Integer, Integer> superImpl); 66 67 /** 68 /** 69 * Checks whether the given uid has been granted the specified permission. 70 * 71 * @return If the package has the permission, PERMISSION_GRANTED is 72 * returned. If it does not have the permission, PERMISSION_DENIED 73 * is returned. 74 * 75 */ checkUidPermission(String permName, int uid, BiFunction<String, Integer, Integer> superImpl)76 int checkUidPermission(String permName, int uid, 77 BiFunction<String, Integer, Integer> superImpl); 78 } 79 80 /** 81 * Get the state of the runtime permissions as xml file. 82 * 83 * @param user The user the data should be extracted for 84 * 85 * @return The state as a xml file 86 */ backupRuntimePermissions(@onNull UserHandle user)87 public abstract @Nullable byte[] backupRuntimePermissions(@NonNull UserHandle user); 88 89 /** 90 * Restore a permission state previously backed up via {@link #backupRuntimePermissions}. 91 * 92 * <p>If not all state can be restored, the un-restoreable state will be delayed and can be 93 * re-tried via {@link #restoreDelayedRuntimePermissions}. 94 * 95 * @param backup The state as an xml file 96 * @param user The user the data should be restored for 97 */ restoreRuntimePermissions(@onNull byte[] backup, @NonNull UserHandle user)98 public abstract void restoreRuntimePermissions(@NonNull byte[] backup, 99 @NonNull UserHandle user); 100 101 /** 102 * Try to apply permission backup of a package that was previously not applied. 103 * 104 * @param packageName The package that is newly installed 105 * @param user The user the package is installed for 106 * 107 * @see #restoreRuntimePermissions 108 */ restoreDelayedRuntimePermissions(@onNull String packageName, @NonNull UserHandle user)109 public abstract void restoreDelayedRuntimePermissions(@NonNull String packageName, 110 @NonNull UserHandle user); 111 112 /** 113 * Adds a listener for runtime permission state (permissions or flags) changes. 114 * 115 * @param listener The listener. 116 */ addOnRuntimePermissionStateChangedListener( @onNull OnRuntimePermissionStateChangedListener listener)117 public abstract void addOnRuntimePermissionStateChangedListener( 118 @NonNull OnRuntimePermissionStateChangedListener listener); 119 120 /** 121 * Removes a listener for runtime permission state (permissions or flags) changes. 122 * 123 * @param listener The listener. 124 */ removeOnRuntimePermissionStateChangedListener( @onNull OnRuntimePermissionStateChangedListener listener)125 public abstract void removeOnRuntimePermissionStateChangedListener( 126 @NonNull OnRuntimePermissionStateChangedListener listener); 127 } 128