• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 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_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 El5FilekeyManagerStub {
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,
50         std::vector<std::pair<int32_t, std::string>> &keyInfos) override;
51     int32_t ChangeUserAppkeysLoadInfo(int32_t userId, std::vector<std::pair<std::string, bool>> &loadInfos) override;
52     int32_t SetFilePathPolicy() override;
53     int32_t RegisterCallback(const sptr<El5FilekeyCallbackInterface> &callback) override;
54     int32_t GenerateGroupIDKey(uint32_t uid, const std::string &groupID, std::string &keyId) override;
55     int32_t DeleteGroupIDKey(uint32_t uid, const std::string &groupID) override;
56     int32_t QueryAppKeyState(DataLockType type) override;
57 
58     void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId);
59     int32_t SetPolicyScreenLocked();
60     int32_t HandleUserCommonEvent(const std::string &eventName, int32_t userId);
61     void PostDelayedUnloadTask(uint32_t delayedTime);
62     void CancelDelayedUnloadTask();
63     int Dump(int fd, const std::vector<std::u16string>& args) override;
64 private:
65     ServiceRunningState serviceRunningState_ = ServiceRunningState::STATE_NOT_START;
66 
67     bool IsSystemApp();
68     int32_t CheckReqLockPermission(DataLockType type, bool& isApp);
69     bool VerifyNativeCallingProcess(const std::string &validCaller, const AccessTokenID &callerTokenId);
70     bool VerifyHapCallingProcess(int32_t userId, const std::string &validCaller, const AccessTokenID &callerTokenId);
71 
72     El5FilekeyServiceExtInterface* service_ = nullptr;
73 #ifdef COMMON_EVENT_SERVICE_ENABLE
74     std::shared_ptr<El5FilekeyManagerSubscriber> subscriber_;
75 #endif
76 #ifdef EVENTHANDLER_ENABLE
77     std::shared_ptr<AppExecFwk::EventHandler> unloadHandler_;
78 #endif
79     void *handler_{nullptr};
80 
81     DISALLOW_COPY_AND_MOVE(El5FilekeyManagerService);
82 };
83 }  // namespace AccessToken
84 }  // namespace Security
85 }  // namespace OHOS
86 #endif  // EL5_FILEKEY_MANAGER_SERVICE_H
87