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_MS_FEATURE_H
17 #define OHOS_BUNDLE_MS_FEATURE_H
18 
19 #include "ability_info.h"
20 #include "bundle_inner_interface.h"
21 #include "bundle_manager.h"
22 #include "feature.h"
23 #include "iproxy_server.h"
24 #include "iunknown.h"
25 #include "nocopyable.h"
26 #include "ohos_types.h"
27 #include "want.h"
28 
29 namespace OHOS {
30 typedef uint8_t (*BundleInvokeType)(const uint8_t funcId, IpcIo *req, IpcIo *reply);
31 
32 class BundleMsFeature : private Feature {
33 public:
GetInstance()34     static BundleMsFeature *GetInstance()
35     {
36         static BundleMsFeature instance;
37         return &instance;
38     }
39     ~BundleMsFeature();
40     static int32 Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, IpcIo *reply);
41     static uint8_t QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo);
42     static uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo *bundleInfo);
43     static uint8_t GetBundleInfos(int flags, BundleInfo **bundleInfos, int32_t *len);
44     static uint8_t QueryKeepAliveBundleInfos(BundleInfo **bundleInfos, int32_t *len);
45     static uint8_t GetBundleInfosByMetaData(const char *metaDataKey, BundleInfo **bundleInfos, int32_t *len);
46     static uint8_t GetBundleNameForUid(int32_t uid, char **bundleName);
47     static uint32_t GetBundleSize(const char *bundleName);
48 
49 private:
50     BundleMsFeature();
51     static const char *GetFeatureName(Feature *feature);
52     static void OnFeatureInitialize(Feature *feature, Service *parent, Identity identity);
53     static void OnFeatureStop(Feature *feature, Identity identity);
54     static BOOL OnFeatureMessage(Feature *feature, Request *request);
55 
56     bool BundleServiceTaskInit();
57     static uint8_t HandleGetBundleInfos(const uint8_t funcId, IpcIo *req, IpcIo *reply);
58     static uint8_t QueryInnerAbilityInfo(const uint8_t funcId, IpcIo *req, IpcIo *reply);
59     static uint8_t GetInnerBundleInfo(const uint8_t funcId, IpcIo *req, IpcIo *reply);
60     static uint8_t GetInnerBundleNameForUid(const uint8_t funcId, IpcIo *req, IpcIo *reply);
61     static uint8_t ChangeInnerCallbackServiceId(const uint8_t funcId, IpcIo *req, IpcIo *reply);
62     static uint8_t HasSystemCapability(const uint8_t funcId, IpcIo *req, IpcIo *reply);
63     static uint8_t GetSystemAvailableCapabilities(const uint8_t funcId, IpcIo *req, IpcIo *reply);
64     static uint8_t GetInnerBundleSize(const uint8_t funcId, IpcIo *req, IpcIo *reply);
65     static uint8_t HandleGetBundleInfosByIndex(const uint8_t funcId, IpcIo *req, IpcIo *reply);
66     static uint8_t HandleGetBundleInfosLength(const uint8_t funcId, IpcIo *req, IpcIo *reply);
67     static BundleInfo *GetInnerBundleInfos(IpcIo *req, IpcIo *reply, int32_t *length);
68 
69     Identity identity_;
70     static BundleInvokeType BundleMsInvokeFuc[BMS_INNER_BEGIN];
71 
72     DISALLOW_COPY_AND_MOVE(BundleMsFeature);
73 };
74 
75 typedef struct {
76     INHERIT_IUNKNOWNENTRY(BmsServerProxy);
77     BundleMsFeature *bundleMsFeature;
78 } BmsImpl;
79 
80 IUnknown *GetBmsFeatureApi(Feature *feature);
81 } // namespace OHOS
82 #endif // OHOS_BUNDLE_MS_FEATURE_H
83