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 OHOS_FILEMGMT_BACKUP_APP_GALLERY_DISPOSE_PROXY_H
17 #define OHOS_FILEMGMT_BACKUP_APP_GALLERY_DISPOSE_PROXY_H
18 
19 #include <condition_variable>
20 #include <mutex>
21 
22 #include <iremote_stub.h>
23 
24 #include "i_appgallery_service.h"
25 
26 namespace OHOS::FileManagement::Backup {
27 enum class DisposeErr {
28     OK = 0,
29     CONN_FAIL = 1,
30     IPC_FAIL = 2,
31     REQUEST_FAIL = 3,
32 };
33 
34 class AppGalleryDisposeProxy : public IRemoteStub<IAppGalleryService> {
35 public:
36     DISALLOW_COPY_AND_MOVE(AppGalleryDisposeProxy);
37     AppGalleryDisposeProxy();
38     ~AppGalleryDisposeProxy();
39 
40     static sptr<AppGalleryDisposeProxy> GetInstance();
41 
42     DisposeErr StartBackup(const std::string &bundleName);
43     DisposeErr EndBackup(const std::string &bundleName);
44     DisposeErr StartRestore(const std::string &bundleName);
45     DisposeErr EndRestore(const std::string &bundleName);
46 
47     static std::condition_variable conditionVal_;
48     static std::string abilityName;
49     static std::string pkgName;
50     static std::mutex appRemoteObjLock_;
51     static std::mutex connectMutex;
52     static sptr<IRemoteObject> appRemoteObj_;
53 
54 private:
55     DisposeErr DoDispose(const std::string &bundleName, DisposeOperation disposeOperation);
56 
57 private:
58     static std::mutex instanceLock_;
59     static std::mutex conditionMutex_;
60     static sptr<AppGalleryDisposeProxy> appGalleryDisposeProxyInstance_;
61 };
62 } // namespace OHOS::FileManagement::Backup
63 
64 #endif // OHOS_FILEMGMT_BACKUP_APP_GALLERY_DISPOSE_PROXY_H