1 /* 2 * Copyright (C) 2018 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.app; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.app.AppOpsManager.AttributionFlags; 22 import android.content.AttributionSource; 23 import android.os.IBinder; 24 import android.os.UserHandle; 25 import android.util.SparseArray; 26 import android.util.SparseIntArray; 27 28 import com.android.internal.app.IAppOpsCallback; 29 import com.android.internal.util.function.HeptFunction; 30 import com.android.internal.util.function.HexFunction; 31 import com.android.internal.util.function.QuadFunction; 32 import com.android.internal.util.function.QuintConsumer; 33 import com.android.internal.util.function.QuintFunction; 34 import com.android.internal.util.function.UndecFunction; 35 36 /** 37 * App ops service local interface. 38 * 39 * @hide Only for use within the system server. 40 */ 41 public abstract class AppOpsManagerInternal { 42 /** Interface to override app ops checks via composition */ 43 public interface CheckOpsDelegate { 44 /** 45 * Allows overriding check operation behavior. 46 * 47 * @param code The op code to check. 48 * @param uid The UID for which to check. 49 * @param packageName The package for which to check. 50 * @param attributionTag The attribution tag for which to check. 51 * @param raw Whether to check the raw op i.e. not interpret the mode based on UID state. 52 * @param superImpl The super implementation. 53 * @return The app op check result. 54 */ checkOperation(int code, int uid, String packageName, @Nullable String attributionTag, boolean raw, QuintFunction<Integer, Integer, String, String, Boolean, Integer> superImpl)55 int checkOperation(int code, int uid, String packageName, @Nullable String attributionTag, 56 boolean raw, QuintFunction<Integer, Integer, String, String, Boolean, Integer> 57 superImpl); 58 59 /** 60 * Allows overriding check audio operation behavior. 61 * 62 * @param code The op code to check. 63 * @param usage The audio op usage. 64 * @param uid The UID for which to check. 65 * @param packageName The package for which to check. 66 * @param superImpl The super implementation. 67 * @return The app op check result. 68 */ checkAudioOperation(int code, int usage, int uid, String packageName, QuadFunction<Integer, Integer, Integer, String, Integer> superImpl)69 int checkAudioOperation(int code, int usage, int uid, String packageName, 70 QuadFunction<Integer, Integer, Integer, String, Integer> superImpl); 71 72 /** 73 * Allows overriding note operation behavior. 74 * 75 * @param code The op code to note. 76 * @param uid The UID for which to note. 77 * @param packageName The package for which to note. {@code null} for system package. 78 * @param featureId Id of the feature in the package 79 * @param shouldCollectAsyncNotedOp If an {@link AsyncNotedAppOp} should be collected 80 * @param message The message in the async noted op 81 * @param superImpl The super implementation. 82 * @return The app op note result. 83 */ noteOperation(int code, int uid, @Nullable String packageName, @Nullable String featureId, boolean shouldCollectAsyncNotedOp, @Nullable String message, boolean shouldCollectMessage, @NonNull HeptFunction<Integer, Integer, String, String, Boolean, String, Boolean, SyncNotedAppOp> superImpl)84 SyncNotedAppOp noteOperation(int code, int uid, @Nullable String packageName, 85 @Nullable String featureId, boolean shouldCollectAsyncNotedOp, 86 @Nullable String message, boolean shouldCollectMessage, 87 @NonNull HeptFunction<Integer, Integer, String, String, Boolean, String, Boolean, 88 SyncNotedAppOp> superImpl); 89 90 /** 91 * Allows overriding note proxy operation behavior. 92 * 93 * @param code The op code to note. 94 * @param attributionSource The permission identity of the caller. 95 * @param shouldCollectAsyncNotedOp If an {@link AsyncNotedAppOp} should be collected 96 * @param message The message in the async noted op 97 * @param shouldCollectMessage whether to collect messages 98 * @param skipProxyOperation Whether to skip the proxy portion of the operation 99 * @param superImpl The super implementation. 100 * @return The app op note result. 101 */ noteProxyOperation(int code, @NonNull AttributionSource attributionSource, boolean shouldCollectAsyncNotedOp, @Nullable String message, boolean shouldCollectMessage, boolean skipProxyOperation, @NonNull HexFunction<Integer, AttributionSource, Boolean, String, Boolean, Boolean, SyncNotedAppOp> superImpl)102 SyncNotedAppOp noteProxyOperation(int code, @NonNull AttributionSource attributionSource, 103 boolean shouldCollectAsyncNotedOp, @Nullable String message, 104 boolean shouldCollectMessage, boolean skipProxyOperation, 105 @NonNull HexFunction<Integer, AttributionSource, Boolean, String, Boolean, 106 Boolean, SyncNotedAppOp> superImpl); 107 108 /** 109 * Allows overriding start operation behavior. 110 * 111 * @param token The client state. 112 * @param code The op code to start. 113 * @param uid The UID for which to note. 114 * @param packageName The package for which to note. {@code null} for system package. 115 * @param attributionTag the attribution tag. 116 * @param startIfModeDefault Whether to start the op of the mode is default. 117 * @param shouldCollectAsyncNotedOp If an {@link AsyncNotedAppOp} should be collected 118 * @param message The message in the async noted op 119 * @param shouldCollectMessage whether to collect messages 120 * @param attributionFlags the attribution flags for this operation. 121 * @param attributionChainId the unique id of the attribution chain this op is a part of. 122 * @param superImpl The super implementation. 123 * @return The app op note result. 124 */ startOperation(IBinder token, int code, int uid, @Nullable String packageName, @Nullable String attributionTag, boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp, @Nullable String message, boolean shouldCollectMessage, @AttributionFlags int attributionFlags, int attributionChainId, @NonNull UndecFunction<IBinder, Integer, Integer, String, String, Boolean, Boolean, String, Boolean, Integer, Integer, SyncNotedAppOp> superImpl)125 SyncNotedAppOp startOperation(IBinder token, int code, int uid, 126 @Nullable String packageName, @Nullable String attributionTag, 127 boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp, 128 @Nullable String message, boolean shouldCollectMessage, 129 @AttributionFlags int attributionFlags, int attributionChainId, 130 @NonNull UndecFunction<IBinder, Integer, Integer, String, String, Boolean, 131 Boolean, String, Boolean, Integer, Integer, SyncNotedAppOp> superImpl); 132 133 /** 134 * Allows overriding start proxy operation behavior. 135 * 136 * @param clientId The client calling start, represented by an IBinder 137 * @param code The op code to start. 138 * @param attributionSource The permission identity of the caller. 139 * @param startIfModeDefault Whether to start the op of the mode is default. 140 * @param shouldCollectAsyncNotedOp If an {@link AsyncNotedAppOp} should be collected 141 * @param message The message in the async noted op 142 * @param shouldCollectMessage whether to collect messages 143 * @param skipProxyOperation Whether to skip the proxy portion of the operation 144 * @param proxyAttributionFlags The attribution flags for the proxy. 145 * @param proxiedAttributionFlags The attribution flags for the proxied. 146 * @oaram attributionChainId The id of the attribution chain this operation is a part of. 147 * @param superImpl The super implementation. 148 * @return The app op note result. 149 */ startProxyOperation(@onNull IBinder clientId, int code, @NonNull AttributionSource attributionSource, boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage, boolean skipProxyOperation, @AttributionFlags int proxyAttributionFlags, @AttributionFlags int proxiedAttributionFlags, int attributionChainId, @NonNull UndecFunction<IBinder, Integer, AttributionSource, Boolean, Boolean, String, Boolean, Boolean, Integer, Integer, Integer, SyncNotedAppOp> superImpl)150 SyncNotedAppOp startProxyOperation(@NonNull IBinder clientId, int code, 151 @NonNull AttributionSource attributionSource, boolean startIfModeDefault, 152 boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage, 153 boolean skipProxyOperation, @AttributionFlags int proxyAttributionFlags, 154 @AttributionFlags int proxiedAttributionFlags, int attributionChainId, 155 @NonNull UndecFunction<IBinder, Integer, AttributionSource, Boolean, 156 Boolean, String, Boolean, Boolean, Integer, Integer, Integer, 157 SyncNotedAppOp> superImpl); 158 159 /** 160 * Allows overriding finish op. 161 * 162 * @param clientId The client state. 163 * @param code The op code to finish. 164 * @param uid The UID for which the op was noted. 165 * @param packageName The package for which it was noted. {@code null} for system package. 166 * @param attributionTag the attribution tag. 167 */ finishOperation(IBinder clientId, int code, int uid, String packageName, String attributionTag, @NonNull QuintConsumer<IBinder, Integer, Integer, String, String> superImpl)168 default void finishOperation(IBinder clientId, int code, int uid, String packageName, 169 String attributionTag, 170 @NonNull QuintConsumer<IBinder, Integer, Integer, String, String> superImpl) { 171 superImpl.accept(clientId, code, uid, packageName, attributionTag); 172 } 173 174 /** 175 * Allows overriding finish proxy op. 176 * 177 * @param code The op code to finish. 178 * @param attributionSource The permission identity of the caller. 179 * @param skipProxyOperation Whether to skip the proxy in the proxy/proxied operation 180 * @param clientId The client calling finishProxyOperation 181 * @param superImpl The "standard" implementation to potentially call 182 */ finishProxyOperation(@onNull IBinder clientId, int code, @NonNull AttributionSource attributionSource, boolean skipProxyOperation, @NonNull QuadFunction<IBinder, Integer, AttributionSource, Boolean, Void> superImpl)183 void finishProxyOperation(@NonNull IBinder clientId, int code, 184 @NonNull AttributionSource attributionSource, 185 boolean skipProxyOperation, 186 @NonNull QuadFunction<IBinder, Integer, AttributionSource, Boolean, 187 Void> superImpl); 188 } 189 190 /** 191 * Set the currently configured device and profile owners. Specifies the package uid (value) 192 * that has been configured for each user (key) that has one. These will be allowed privileged 193 * access to app ops for their user. 194 */ setDeviceAndProfileOwners(SparseIntArray owners)195 public abstract void setDeviceAndProfileOwners(SparseIntArray owners); 196 197 /** 198 * Update if the list of AppWidget becomes visible/invisible. 199 * @param uidPackageNames uid to packageName map. 200 * @param visible true for visible, false for invisible. 201 */ updateAppWidgetVisibility(SparseArray<String> uidPackageNames, boolean visible)202 public abstract void updateAppWidgetVisibility(SparseArray<String> uidPackageNames, 203 boolean visible); 204 205 /** 206 * Like {@link AppOpsManager#setUidMode}, but allows ignoring our own callback and not updating 207 * the REVOKED_COMPAT flag. 208 */ setUidModeFromPermissionPolicy(int code, int uid, int mode, @Nullable IAppOpsCallback callback)209 public abstract void setUidModeFromPermissionPolicy(int code, int uid, int mode, 210 @Nullable IAppOpsCallback callback); 211 212 /** 213 * Like {@link AppOpsManager#setMode}, but allows ignoring our own callback and not updating the 214 * REVOKED_COMPAT flag. 215 */ setModeFromPermissionPolicy(int code, int uid, @NonNull String packageName, int mode, @Nullable IAppOpsCallback callback)216 public abstract void setModeFromPermissionPolicy(int code, int uid, @NonNull String packageName, 217 int mode, @Nullable IAppOpsCallback callback); 218 219 220 /** 221 * Sets a global restriction on an op code. 222 */ setGlobalRestriction(int code, boolean restricted, IBinder token)223 public abstract void setGlobalRestriction(int code, boolean restricted, IBinder token); 224 225 /** 226 * Gets the number of tokens restricting the given appop for a user, package, and 227 * attributionTag. 228 */ getOpRestrictionCount(int code, UserHandle user, String pkg, String attributionTag)229 public abstract int getOpRestrictionCount(int code, UserHandle user, String pkg, 230 String attributionTag); 231 } 232