1 /*
2  * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PRIVACY_MANAGER_STUB_H
17 #define PRIVACY_MANAGER_STUB_H
18 
19 #include <map>
20 
21 #include "i_privacy_manager.h"
22 #include "iremote_stub.h"
23 #include "nocopyable.h"
24 
25 namespace OHOS {
26 namespace Security {
27 namespace AccessToken {
28 class PrivacyManagerStub : public IRemoteStub<IPrivacyManager> {
29 public:
30     PrivacyManagerStub();
31     virtual ~PrivacyManagerStub() = default;
32 
33     int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
34 
35 private:
36     void AddPermissionUsedRecordInner(MessageParcel& data, MessageParcel& reply);
37     void StartUsingPermissionInner(MessageParcel& data, MessageParcel& reply);
38     void StartUsingPermissionCallbackInner(MessageParcel& data, MessageParcel& reply);
39     void StopUsingPermissionInner(MessageParcel& data, MessageParcel& reply);
40     void RemovePermissionUsedRecordsInner(MessageParcel& data, MessageParcel& reply);
41     void GetPermissionUsedRecordsInner(MessageParcel& data, MessageParcel& reply);
42     void GetPermissionUsedRecordsAsyncInner(MessageParcel& data, MessageParcel& reply);
43     void RegisterPermActiveStatusCallbackInner(MessageParcel& data, MessageParcel& reply);
44     void UnRegisterPermActiveStatusCallbackInner(MessageParcel& data, MessageParcel& reply);
45     void IsAllowedUsingPermissionInner(MessageParcel& data, MessageParcel& reply);
46 #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE
47     void RegisterSecCompEnhanceInner(MessageParcel& data, MessageParcel& reply);
48     void UpdateSecCompEnhanceInner(MessageParcel& data, MessageParcel& reply);
49     void GetSecCompEnhanceInner(MessageParcel& data, MessageParcel& reply);
50     void GetSpecialSecCompEnhanceInner(MessageParcel& data, MessageParcel& reply);
51     bool IsSecCompServiceCalling();
52 #endif
53     void GetPermissionUsedTypeInfosInner(MessageParcel& data, MessageParcel& reply);
54     void SetMutePolicyInner(MessageParcel& data, MessageParcel& reply);
55     void SetHapWithFGReminderInner(MessageParcel& data, MessageParcel& reply);
56     bool IsAccessTokenCalling() const;
57     bool IsSystemAppCalling() const;
58     bool VerifyPermission(const std::string& permission) const;
59     static const int32_t ACCESSTOKEN_UID = 3020;
60 #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE
61     AccessTokenID secCompTokenId_ = 0;
62 #endif
63     void SetPrivacyFuncInMap();
64 
65     using RequestType = void (PrivacyManagerStub::*)(MessageParcel &data, MessageParcel &reply);
66     std::map<uint32_t, RequestType> requestMap_;
67 };
68 } // namespace AccessToken
69 } // namespace Security
70 } // namespace OHOS
71 #endif // PRIVACY_MANAGER_STUB_H
72