• 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 SERVICES_SAMGR_NATIVE_INCLUDE_SYSTEM_ABILITY_MANAGER_UTIL_H
17 #define SERVICES_SAMGR_NATIVE_INCLUDE_SYSTEM_ABILITY_MANAGER_UTIL_H
18 
19 #include <string>
20 #include <list>
21 
22 #include "config_policy_utils.h"
23 #include "directory_ex.h"
24 #include "sa_profiles.h"
25 #include "system_ability_on_demand_event.h"
26 #include "ffrt_handler.h"
27 
28 namespace OHOS {
29 class SamgrUtil {
30 public:
31     ~SamgrUtil();
32     static bool IsNameInValid(const std::u16string& name);
33     static void ParseRemoteSaName(const std::u16string& name, std::string& deviceId, std::u16string& saName);
34     static bool CheckDistributedPermission();
35     static bool IsSameEvent(const OnDemandEvent& event, std::list<OnDemandEvent>& enableOnceList);
36     static std::string EventToStr(const OnDemandEvent& event);
37     static std::string TransformDeviceId(const std::string& deviceId, int32_t type, bool isPrivate);
38     static bool CheckCallerProcess(const CommonSaProfile& saProfile);
39     static bool CheckCallerProcess(const std::string& callProcess);
40     static bool CheckAllowUpdate(OnDemandPolicyType type, const CommonSaProfile& saProfile);
41     static void ConvertToOnDemandEvent(const SystemAbilityOnDemandEvent& from, OnDemandEvent& to);
42     static void ConvertToSystemAbilityOnDemandEvent(const OnDemandEvent& from, SystemAbilityOnDemandEvent& to);
43     static uint64_t GenerateFreKey(int32_t uid, int32_t saId);
44     static std::list<int32_t> GetCacheCommonEventSa(const OnDemandEvent& event,
45         const std::list<SaControlInfo>& saControlList);
46     static void SetModuleUpdateParam(const std::string& key, const std::string& value);
47     static void SendUpdateSaState(int32_t systemAbilityId, const std::string& updateSaState);
48     static void InvalidateSACache();
49     static void FilterCommonSaProfile(const SaProfile& oldProfile, CommonSaProfile& newProfile);
50     static bool CheckPengLai();
51 #ifdef SUPPORT_PENGLAI_MODE
52     static bool CheckPengLaiPermission(int32_t systemAbilityId);
53 #endif
54     static void GetFilesByPriority(const std::string& path, std::vector<std::string>& files);
55     static void GetFilesFromPath(const std::string& path, std::map<std::string, std::string>& fileNamesMap);
56 private:
57 #ifdef SUPPORT_PENGLAI_MODE
58     static void* InitPenglaiFunc();
59     static void* penglaiFunc_;
60 #endif
61     static std::shared_ptr<FFRTHandler> setParmHandler_;
62 };
63 } // namespace OHOS
64 
65 #endif // !defined(SERVICES_SAMGR_NATIVE_INCLUDE_SYSTEM_ABILITY_MANAGER_UTIL_H)
66