• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 MIGRATION_MANAGER_ADAPTER_IMPL_H
17 #define MIGRATION_MANAGER_ADAPTER_IMPL_H
18 
19 #include <map>
20 #include <mutex>
21 
22 #include "ability_connect_callback_interface.h"
23 #include "ability_connect_callback_stub.h"
24 #include "migration_manager_adapter.h"
25 
26 namespace OHOS::NWeb {
27 
28 class MigrationManagerAdapterImpl : public MigrationManagerAdapter {
29 public:
30     MigrationManagerAdapterImpl() = default;
31     ~MigrationManagerAdapterImpl() override = default;
32     uint32_t RegisterMigrationListener(std::shared_ptr<MigrationListenerAdapter> listener) override;
33     void SetMigrationParam(
34         const std::string& bundleName, const std::string& abilityName, const std::string& token) override;
35     bool SendMigrationRequest(std::shared_ptr<std::string> jsonData) override;
36 
37     class MigrationListenerAdapterImpl : public OHOS::AAFwk::AbilityConnectionStub {
38     public:
MigrationListenerAdapterImpl(std::shared_ptr<MigrationListenerAdapter> listener)39         MigrationListenerAdapterImpl(std::shared_ptr<MigrationListenerAdapter> listener) : listener_(listener) {}
40         virtual ~MigrationListenerAdapterImpl() = default;
41         void OnAbilityConnectDone(
42             const AppExecFwk::ElementName& element, const sptr<IRemoteObject>& remoteObject, int resultCode) override;
43         void OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, int resultCode) override;
44         void OnMigrationReply(int32_t errorCode, int32_t succussCount, const std::vector<int32_t>& errorIndex,
45             const std::vector<int32_t>& codeList);
46         void SetJsonData(const std::string& jsonData);
47         void SetInterfaceToken(const std::string& token);
48         friend class MigrationManagerAdapterImpl;
49 
50     private:
51         std::shared_ptr<MigrationListenerAdapter> listener_;
52         std::string jsonData_;
53         std::string token_;
54         std::mutex mutex_;
55     };
56 
57 private:
58     static std::atomic<bool> isConnectSystemUI_;
59     sptr<MigrationListenerAdapterImpl> callback_;
60     std::string jsonUrl_;
61     std::string abilityName_;
62     std::string bundleName_;
63 };
64 } // namespace OHOS::NWeb
65 
66 #endif