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