• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2025 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 EL5_FILEKEY_MANAGER_SERVICE_H
17 #define EL5_FILEKEY_MANAGER_SERVICE_H
18 
19 #include <singleton.h>
20 #include "nocopyable.h"
21 
22 #include "accesstoken_kit.h"
23 #ifdef COMMON_EVENT_SERVICE_ENABLE
24 #include "el5_filkey_manager_subscriber.h"
25 #endif
26 #include "el5_filekey_manager_interface_stub.h"
27 #include "el5_filekey_service_ext_interface.h"
28 #ifdef EVENTHANDLER_ENABLE
29 #include "event_handler.h"
30 #endif
31 
32 namespace OHOS {
33 namespace Security {
34 namespace AccessToken {
35 enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING };
36 
37 class El5FilekeyManagerService : public El5FilekeyManagerInterfaceStub {
38 public:
39     El5FilekeyManagerService();
40     virtual ~El5FilekeyManagerService();
41 
42     int32_t Init();
43     void UnInit();
44 
45     int32_t AcquireAccess(DataLockType type) override;
46     int32_t ReleaseAccess(DataLockType type) override;
47     int32_t GenerateAppKey(uint32_t uid, const std::string& bundleName, std::string& keyId) override;
48     int32_t DeleteAppKey(const std::string& bundleName, int32_t userId) override;
49     int32_t GetUserAppKey(int32_t userId, bool getAllFlag, std::vector<UserAppKeyInfo> &keyInfos) override;
50     int32_t ChangeUserAppkeysLoadInfo(int32_t userId, const std::vector<AppKeyLoadInfo> &loadInfos) override;
51     int32_t SetFilePathPolicy() override;
52     int32_t RegisterCallback(const sptr<El5FilekeyCallbackInterface> &callback) override;
53     int32_t GenerateGroupIDKey(uint32_t uid, const std::string &groupID, std::string &keyId) override;
54     int32_t DeleteGroupIDKey(uint32_t uid, const std::string &groupID) override;
55     int32_t QueryAppKeyState(DataLockType type) override;
56 
57     void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId);
58     int32_t SetPolicyScreenLocked();
59     int32_t HandleUserCommonEvent(const std::string &eventName, int32_t userId);
60     void PostDelayedUnloadTask(uint32_t delayedTime);
61     void CancelDelayedUnloadTask();
62     int Dump(int fd, const std::vector<std::u16string>& args) override;
63     int32_t CallbackEnter(uint32_t code) override;
64     int32_t CallbackExit(uint32_t code, int32_t result) override;
65 
66 private:
67     ServiceRunningState serviceRunningState_ = ServiceRunningState::STATE_NOT_START;
68 
69     bool IsSystemApp();
70     int32_t CheckReqLockPermission(DataLockType type, bool& isApp);
71     bool VerifyNativeCallingProcess(const std::string &validCaller, const AccessTokenID &callerTokenId);
72     bool VerifyHapCallingProcess(int32_t userId, const std::string &validCaller, const AccessTokenID &callerTokenId);
73 
74     El5FilekeyServiceExtInterface* service_ = nullptr;
75 #ifdef COMMON_EVENT_SERVICE_ENABLE
76     std::shared_ptr<El5FilekeyManagerSubscriber> subscriber_;
77 #endif
78 #ifdef EVENTHANDLER_ENABLE
79     std::shared_ptr<AppExecFwk::EventHandler> unloadHandler_;
80 #endif
81     void *handler_{ nullptr };
82 
83     DISALLOW_COPY_AND_MOVE(El5FilekeyManagerService);
84 };
85 }  // namespace AccessToken
86 }  // namespace Security
87 }  // namespace OHOS
88 #endif  // EL5_FILEKEY_MANAGER_SERVICE_H
89