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_INNER_FEATURE_H
17 #define OHOS_BUNDLE_INNER_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 struct SvcIdentityInfo {
33     char *path;
34     char *bundleName;
35     SvcIdentity *svc;
36     int32_t installLocation;
37     bool keepData;
38 };
39 
40 class BundleInnerFeature : private Feature {
41 public:
GetInstance()42     static BundleInnerFeature *GetInstance()
43     {
44         static BundleInnerFeature instance;
45         return &instance;
46     }
47     ~BundleInnerFeature();
48     static int32 Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, IpcIo *reply);
49 
50 private:
51     BundleInnerFeature();
52     static const char *GetFeatureName(Feature *feature);
53     static void OnFeatureInitialize(Feature *feature, Service *parent, Identity identity);
54     static void OnFeatureStop(Feature *feature, Identity identity);
55     static BOOL OnFeatureMessage(Feature *feature, Request *request);
56 
57     static uint8_t InstallInnerBundle(const uint8_t funcId, IpcIo *req, IpcIo *reply);
58     static uint8_t GetSvcIdentityInfo(
59     OHOS::SvcIdentityInfo *info, const SvcIdentity *svc, const char *reqPath, IpcIo *req);
60     static uint8_t UninstallInnerBundle(const uint8_t funcId, IpcIo *req, IpcIo *reply);
61 #ifdef OHOS_DEBUG
62     static uint8_t SetExternalInstallMode(const uint8_t funcId, IpcIo *req, IpcIo *reply);
63     static uint8_t SetInnerDebugMode(const uint8_t funcId, IpcIo *req, IpcIo *reply);
64     static uint8_t SetInnerSignMode(const uint8_t funcId, IpcIo *req, IpcIo *reply);
65 #endif
66 
67     Identity identity_;
68     static BundleInvokeType BundleMsInvokeFuc[BMS_CMD_END - BMS_INNER_BEGIN];
69 
70     DISALLOW_COPY_AND_MOVE(BundleInnerFeature);
71 };
72 
73 typedef struct {
74     INHERIT_IUNKNOWNENTRY(BmsInnerServerProxy);
75     BundleInnerFeature *bundleInnerFeature;
76 } BmsInnerImpl;
77 
78 IUnknown *GetBmsInnerFeatureApi(Feature *feature);
79 } // namespace OHOS
80 #endif // OHOS_BUNDLE_INNER_FEATURE_H
81