Dianne Hackborn | d525441 | 2018-05-11 18:02:58 -0700 | [diff] [blame] | 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 | |
Philip P. Moltmann | 724150d | 2019-03-11 17:01:05 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Dianne Hackborn | d525441 | 2018-05-11 18:02:58 -0700 | [diff] [blame] | 20 | import android.util.SparseIntArray; |
| 21 | |
Svet Ganov | d873ae6 | 2018-06-25 16:39:23 -0700 | [diff] [blame] | 22 | import com.android.internal.util.function.QuadFunction; |
| 23 | import com.android.internal.util.function.TriFunction; |
| 24 | |
Dianne Hackborn | d525441 | 2018-05-11 18:02:58 -0700 | [diff] [blame] | 25 | /** |
| 26 | * App ops service local interface. |
| 27 | * |
| 28 | * @hide Only for use within the system server. |
| 29 | */ |
| 30 | public abstract class AppOpsManagerInternal { |
Svet Ganov | d873ae6 | 2018-06-25 16:39:23 -0700 | [diff] [blame] | 31 | /** Interface to override app ops checks via composition */ |
| 32 | public interface CheckOpsDelegate { |
| 33 | /** |
| 34 | * Allows overriding check operation behavior. |
| 35 | * |
| 36 | * @param code The op code to check. |
| 37 | * @param uid The UID for which to check. |
| 38 | * @param packageName The package for which to check. |
| 39 | * @param superImpl The super implementation. |
Svet Ganov | 9d528a1 | 2018-12-19 17:23:11 -0800 | [diff] [blame] | 40 | * @param raw Whether to check the raw op i.e. not interpret the mode based on UID state. |
Svet Ganov | d873ae6 | 2018-06-25 16:39:23 -0700 | [diff] [blame] | 41 | * @return The app op check result. |
| 42 | */ |
Svet Ganov | 9d528a1 | 2018-12-19 17:23:11 -0800 | [diff] [blame] | 43 | int checkOperation(int code, int uid, String packageName, boolean raw, |
| 44 | QuadFunction<Integer, Integer, String, Boolean, Integer> superImpl); |
Svet Ganov | d873ae6 | 2018-06-25 16:39:23 -0700 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * Allows overriding check audio operation behavior. |
| 48 | * |
| 49 | * @param code The op code to check. |
| 50 | * @param usage The audio op usage. |
| 51 | * @param uid The UID for which to check. |
| 52 | * @param packageName The package for which to check. |
| 53 | * @param superImpl The super implementation. |
| 54 | * @return The app op check result. |
| 55 | */ |
| 56 | int checkAudioOperation(int code, int usage, int uid, String packageName, |
| 57 | QuadFunction<Integer, Integer, Integer, String, Integer> superImpl); |
| 58 | |
| 59 | /** |
| 60 | * Allows overriding note operation behavior. |
| 61 | * |
| 62 | * @param code The op code to note. |
| 63 | * @param uid The UID for which to note. |
| 64 | * @param packageName The package for which to note. |
| 65 | * @param superImpl The super implementation. |
| 66 | * @return The app op note result. |
| 67 | */ |
| 68 | int noteOperation(int code, int uid, String packageName, |
| 69 | TriFunction<Integer, Integer, String, Integer> superImpl); |
| 70 | } |
| 71 | |
Dianne Hackborn | d525441 | 2018-05-11 18:02:58 -0700 | [diff] [blame] | 72 | /** |
| 73 | * Set the currently configured device and profile owners. Specifies the package uid (value) |
| 74 | * that has been configured for each user (key) that has one. These will be allowed privileged |
| 75 | * access to app ops for their user. |
| 76 | */ |
| 77 | public abstract void setDeviceAndProfileOwners(SparseIntArray owners); |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * Sets the app-ops mode for a certain app-op and uid. |
| 81 | * |
Philip P. Moltmann | dde0785 | 2019-01-25 16:42:36 -0800 | [diff] [blame] | 82 | * <p>Similar as {@link AppOpsManager#setUidMode} but does not require the package manager to be |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 83 | * working. Hence this can be used very early during boot. |
| 84 | * |
| 85 | * <p>Only for internal callers. Does <u>not</u> verify that package name belongs to uid. |
| 86 | * |
| 87 | * @param code The op code to set. |
| 88 | * @param uid The UID for which to set. |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 89 | * @param mode The new mode to set. |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 90 | */ |
Philip P. Moltmann | 159d98b | 2018-12-20 08:30:53 -0800 | [diff] [blame] | 91 | public abstract void setUidMode(int code, int uid, int mode); |
Philip P. Moltmann | dde0785 | 2019-01-25 16:42:36 -0800 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * Set all {@link #setMode (package) modes} for this uid to the default value. |
| 95 | * |
| 96 | * @param code The app-op |
| 97 | * @param uid The uid |
| 98 | */ |
| 99 | public abstract void setAllPkgModesToDefault(int code, int uid); |
Philip P. Moltmann | 724150d | 2019-03-11 17:01:05 -0700 | [diff] [blame] | 100 | |
| 101 | /** |
| 102 | * Get the (raw) mode of an app-op. |
| 103 | * |
| 104 | * <p>Does <u>not</u> verify that package belongs to uid. The caller needs to do that. |
| 105 | * |
| 106 | * @param code The code of the op |
| 107 | * @param uid The uid of the package the op belongs to |
| 108 | * @param packageName The package the op belongs to |
| 109 | * |
| 110 | * @return The mode of the op |
| 111 | */ |
| 112 | public abstract @AppOpsManager.Mode int checkOperationUnchecked(int code, int uid, |
| 113 | @NonNull String packageName); |
Dianne Hackborn | d525441 | 2018-05-11 18:02:58 -0700 | [diff] [blame] | 114 | } |