1 /*
2  * Copyright (c) 2020 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 OHOS_BUNDLE_MANAGER_SERVICE_H
17 #define OHOS_BUNDLE_MANAGER_SERVICE_H
18 
19 #include <map>
20 #include <vector>
21 
22 #include "ability_service_interface.h"
23 #include "adapter.h"
24 #include "bundle_installer.h"
25 #include "bundle_info.h"
26 #include "bundle_map.h"
27 #include "cJSON.h"
28 #include "message.h"
29 #include "nocopyable.h"
30 #include "stdint.h"
31 
32 namespace OHOS {
33 class ManagerService {
34 public:
GetInstance()35     static ManagerService &GetInstance()
36     {
37         static ManagerService instance;
38         return instance;
39     }
40     void ServiceMsgProcess(Request *request);
41     BundleInfo *QueryBundleInfo(const char *bundleName);
42     void RemoveBundleInfo(const char *bundleName);
43     void AddBundleInfo(BundleInfo *info);
44     bool UpdateBundleInfo(BundleInfo *info);
45     uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo& bundleInfo);
46     uint8_t GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, int32_t *len);
47     uint32_t GetBundleSize(const char *bundleName);
48     std::vector<SvcIdentity> GetServiceId() const;
49     int32_t GenerateUid(const char *bundleName, int8_t bundleStyle);
50     void RecycleUid(const char *bundleName);
51     static bool GetAmsInterface(AmsInnerInterface **amsInterface);
52     std::string GetCodeDirPath() const;
53     std::string GetDataDirPath() const;
54     uint8_t SetExternalInstallMode(bool enable);
55     bool IsExternalInstallMode() const;
56     uint8_t SetDebugMode(bool enable);
57     bool IsDebugMode() const;
58     bool HasSystemCapability(const char *bundleName);
59     uint8_t GetSystemAvailableCapabilities(char syscap[][MAX_SYSCAP_NAME_LEN], int32_t *len);
60 #ifdef OHOS_DEBUG
61     uint8_t SetSignMode(bool enable);
62     bool IsSignMode() const;
63 #endif
64 private:
65     ManagerService();
66     ~ManagerService();
67 
68     void ScanPackages();
69     void ScanSharedLibPath();
70     void ScanAppDir(const char *appDir, const cJSON *uninstallRecord, uint8_t scanFlag);
71     void InstallAllSystemBundle(int32_t scanFlag);
72     void InstallSystemBundle(const char *fileDir, const char *fileName);
73     void ReloadBundleInfo(const char *codePath, const char *appId, const char *bundleName, bool isSystemApp);
74     void ReloadEntireBundleInfo(const char *appPath, const char *bundleName, int32_t versionCode, uint8_t scanFlag);
75     bool CheckSystemBundleIsValid(const char *appPath, char **bundleName, int32_t &versionCode);
76     bool CheckThirdSystemBundleHasUninstalled(const char *bundleName, const cJSON *object);
77     void InstallThirdBundle(const char *path, const SvcIdentity &svc, int32_t installLocation);
78     void AddCallbackServiceId(const SvcIdentity &svc);
79     void RemoveCallbackServiceId(const SvcIdentity &svc);
80     void RestoreUidAndGidMap();
81     bool RecycleInnerUid(const std::string &bundleName, std::map<int, std::string> &innerMap);
82 
83     std::map<int, std::string> sysUidMap_;
84     std::map<int, std::string> sysVendorUidMap_;
85     std::map<int, std::string> appUidMap_;
86     BundleInstaller *installer_;
87     BundleMap *bundleMap_;
88     std::vector<SvcIdentity> svcIdentity_;
89     bool IsExternalInstallMode_ { false };
90     bool isDebugMode_ { false };
91 #ifdef OHOS_DEBUG
92     bool isSignMode_ { true };
93 #endif
94 
95     DISALLOW_COPY_AND_MOVE(ManagerService);
96 };
97 }
98 #endif // OHOS_BUNDLE_MANAGER_SERVICE_H
99