• 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 FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_COMMON_BUNDLE_APP_SPAWN_CLIENT_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_COMMON_BUNDLE_APP_SPAWN_CLIENT_H
18 
19 #include <mutex>
20 #include <string>
21 
22 #include "appexecfwk_errors.h"
23 #include "appspawn.h"
24 #include "nocopyable.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
28 enum class SpawnConnectionState { STATE_NOT_CONNECT, STATE_CONNECTED, STATE_CONNECT_FAILED };
29 struct AppSpawnRemoveSandboxDirMsg {
30     std::string bundleName;
31     int32_t uid = 0;
32     int32_t code = 0;
33     int32_t bundleIndex = 0;
34     AppFlagsIndex flags = AppFlagsIndex::APP_FLAGS_COLD_BOOT;
35 };
36 
37 class BundleAppSpawnClient {
38 public:
39     static BundleAppSpawnClient& GetInstance();
40     int32_t RemoveSandboxDir(const AppSpawnRemoveSandboxDirMsg &removeSandboxDirMsg);
41 private:
42     DISALLOW_COPY_AND_MOVE(BundleAppSpawnClient);
43     BundleAppSpawnClient();
44     ~BundleAppSpawnClient();
45     void CloseConnection();
46     int32_t OpenConnection();
47     int32_t AppspawnCreateDefaultMsg(const AppSpawnRemoveSandboxDirMsg &removeSandboxDirMsg,
48         AppSpawnReqMsgHandle reqHandle);
49     bool VerifyMsg(const AppSpawnRemoveSandboxDirMsg &removeSandboxDirMsg);
50 private:
51     std::string serviceName_;
52     AppSpawnClientHandle handle_;
53     SpawnConnectionState state_;
54     std::mutex mutex_;
55 };
56 }  // namespace AppExecFwk
57 }  // namespace OHOS
58 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_COMMON_BUNDLE_APP_SPAWN_CLIENT_H