• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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 #pragma once
18 
19 #include <com/android/internal/app/IAppOpsCallback.h>
20 #include <com/android/internal/app/BnAppOpsCallback.h>
21 #include <binder/IInterface.h>
22 
23 #include <optional>
24 
25 #ifdef __ANDROID_VNDK__
26 #error "This header is not visible to vendors"
27 #endif
28 
29 namespace android {
30 
31 using IAppOpsCallback = ::com::android::internal::app::IAppOpsCallback;
32 
33 // ----------------------------------------------------------------------
34 
35 class IAppOpsService : public IInterface
36 {
37 public:
38     DECLARE_META_INTERFACE(AppOpsService)
39 
40     virtual int32_t checkOperation(int32_t code, int32_t uid, const String16& packageName) = 0;
41     virtual int32_t noteOperation(int32_t code, int32_t uid, const String16& packageName,
42             const std::optional<String16>& attributionTag, bool shouldCollectAsyncNotedOp,
43             const String16& message, bool shouldCollectMessage) = 0;
44     virtual int32_t startOperation(const sp<IBinder>& token, int32_t code, int32_t uid,
45             const String16& packageName, const std::optional<String16>& attributionTag,
46             bool startIfModeDefault, bool shouldCollectAsyncNotedOp, const String16& message,
47             bool shouldCollectMessage) = 0;
48     virtual void finishOperation(const sp<IBinder>& token, int32_t code, int32_t uid,
49             const String16& packageName, const std::optional<String16>& attributionTag) = 0;
50     virtual void startWatchingMode(int32_t op, const String16& packageName,
51             const sp<IAppOpsCallback>& callback) = 0;
52     virtual void stopWatchingMode(const sp<IAppOpsCallback>& callback) = 0;
53     virtual int32_t permissionToOpCode(const String16& permission) = 0;
54     virtual int32_t checkAudioOperation(int32_t code, int32_t usage,int32_t uid,
55             const String16& packageName) = 0;
56     virtual void setCameraAudioRestriction(int32_t mode) = 0;
57     virtual bool shouldCollectNotes(int32_t opCode) = 0;
58     virtual void startWatchingModeWithFlags(int32_t op, const String16& packageName,
59             int32_t flags, const sp<IAppOpsCallback>& callback) = 0;
60 
61     enum {
62         CHECK_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
63         NOTE_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+1,
64         START_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+2,
65         FINISH_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+3,
66         START_WATCHING_MODE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+4,
67         STOP_WATCHING_MODE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+5,
68         PERMISSION_TO_OP_CODE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+6,
69         CHECK_AUDIO_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+7,
70         SHOULD_COLLECT_NOTES_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+8,
71         SET_CAMERA_AUDIO_RESTRICTION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+9,
72         START_WATCHING_MODE_WITH_FLAGS_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+10,
73     };
74 
75     enum {
76         MODE_ALLOWED = 0,
77         MODE_IGNORED = 1,
78         MODE_ERRORED = 2
79     };
80 };
81 
82 // ----------------------------------------------------------------------
83 
84 class BnAppOpsService : public BnInterface<IAppOpsService>
85 {
86 public:
87     // NOLINTNEXTLINE(google-default-arguments)
88     virtual status_t    onTransact( uint32_t code,
89                                     const Parcel& data,
90                                     Parcel* reply,
91                                     uint32_t flags = 0);
92 };
93 
94 // ----------------------------------------------------------------------
95 
96 } // namespace android
97