1 /*
2  * Copyright (c) 2023 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_USER_LOCKED_EVENT_SUBSCRIBER_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_USER_LOCKED_EVENT_SUBSCRIBER_H
18 
19 #include <mutex>
20 
21 #include "bundle_info.h"
22 #include "common_event_data.h"
23 #include "common_event_subscriber.h"
24 #include "ipc/create_dir_param.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
28 class UserUnlockedEventSubscriber final : public EventFwk::CommonEventSubscriber {
29 public:
30     explicit UserUnlockedEventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo);
31     virtual ~UserUnlockedEventSubscriber();
32     void OnReceiveEvent(const EventFwk::CommonEventData &data) override;
33 
34 private:
35     std::mutex mutex_;
36     int32_t userId_ = 0;
37 };
38 
39 class UpdateAppDataMgr {
40 public:
41     static void UpdateAppDataDirSelinuxLabel(int32_t userId);
42     static void ProcessUpdateAppDataDir(
43         int32_t userId, const std::vector<BundleInfo> &bundleInfos, const std::string &elDir);
44     static void ProcessUpdateAppLogDir(const std::vector<BundleInfo> &bundleInfos, int32_t userId);
45     static void ProcessFileManagerDir(const std::vector<BundleInfo> &bundleInfos, int32_t userId);
46     static void ProcessExtensionDir(const BundleInfo &bundleInfo, std::vector<std::string> &dirs);
47     static void ProcessNewBackupDir(const std::vector<BundleInfo> &bundleInfos, int32_t userId);
48     static void DeleteUninstallTmpDirs(const int32_t userId);
49 private:
50     static void CheckPathAttribute(const std::string &path, const BundleInfo &bundleInfo, bool &isExist);
51     static void CreateNewBackupDir(const BundleInfo &bundleInfo, int32_t userId);
52     static bool CreateBundleDataDir(const BundleInfo &bundleInfo, int32_t userId, const std::string &elDir);
53     static bool CreateBundleLogDir(const BundleInfo &bundleInfo, int32_t userId);
54     static bool CreateBundleCloudDir(const BundleInfo &bundleInfo, int32_t userId);
55     static void CreateDataGroupDir(const BundleInfo &bundleInfo, int32_t userId);
56     static bool CreateEl5Dir(const CreateDirParam &createDirParam);
57     static std::vector<std::string> GetBundleDataDirs(const int32_t userId);
58 };
59 }  // namespace AppExecFwk
60 }  // namespace OHOS
61 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_USER_LOCKED_EVENT_SUBSCRIBER_H
62