• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #ifndef FOUNDATION_APPEXECFWK_OHOS_CONTINUATION_REGISTER_MANAGER_INTERFACE_H
16 #define FOUNDATION_APPEXECFWK_OHOS_CONTINUATION_REGISTER_MANAGER_INTERFACE_H
17 #include <string>
18 #include <memory>
19 #include "extra_params.h"
20 
21 namespace OHOS {
22 namespace AppExecFwk {
23 
24 class IContinuationDeviceCallback;
25 class RequestCallback;
26 class IContinuationRegisterManager {
27 public:
28     IContinuationRegisterManager() = default;
29     virtual ~IContinuationRegisterManager() = default;
30     /**
31      * @brief Registers an ability to be migrated with the Device+ control center and obtains the registration token
32      * assigned to the ability.
33      *
34      * <p>You can use {@link IContinuationDeviceCallback} to listen for the device connection state changes after the
35      * user selects a device for ability migration and implement your own processing logic. When the device is
36      * connected, {@link IContinuationDeviceCallback#onDeviceConnectDone} is called to initiate the ability migration
37      * process; when the device is disconnected, {@link IContinuationDeviceCallback#onDeviceDisconnectDone} is called
38      * to perform related operations, for example, notify the user of the disconnection. In addition, you can obtain
39      * the registration token via {@link RequestCallback#onResult}.
40      * <p>To use this method, you must dynamically request the {@code ohos.permission.DISTRIBUTED_DATASYNC} permission
41      * from the user. The {@code ohos.permission.DISTRIBUTED_DATASYNC} permission is of the {@code user_grant} level.
42      *
43      * @param bundleName Indicates the bundle name of the application whose ability is to be migrated.
44      * @param parameter Indicates the {@link ExtraParams} object containing the extra parameters used to filter
45      * the list of available devices. This parameter can be null.
46      * @param deviceCallback Indicates the callback to be invoked when the connection state of the selected device
47      * changes.
48      * @param requestCallback Indicates the callback to be invoked when the Device+ service is connected.
49      * @return none
50      */
51     virtual void Register(const std::string &bundleName, const ExtraParams &parameter,
52         const std::shared_ptr<IContinuationDeviceCallback> &deviceCallback,
53         const std::shared_ptr<RequestCallback> &requestCallback) = 0;
54 
55     /**
56      * @brief Unregisters a specified ability from the Device+ control center based on the token obtained during ability
57      * registration.
58      *
59      * @param token Indicates the registration token of the ability.
60      * @param requestCallback Indicates the callback to be invoked when the Device+ service is connected.
61      * This parameter can be null.
62      * @return none
63      */
64     virtual void Unregister(int token, const std::shared_ptr<RequestCallback> &requestCallback) = 0;
65 
66     /**
67      * @brief Updates the connection state of the device where the specified ability is successfully migrated.
68      *
69      * <p>After the migration is successful, you can call this method in the UI thread to update the connection state
70      * of the migrated ability and the device connection state on the screen showing available devices.
71      *
72      * @param token Indicates the registration token of the ability.
73      * @param deviceId Indicates the ID of the device whose connection state is to be updated.
74      * @param status Indicates the connection state to update, which can be {@link DeviceConnectState#FAILURE},
75      * {@link DeviceConnectState#IDLE}, {@link DeviceConnectState#CONNECTING}, {@link DeviceConnectState#CONNECTED},
76      * or {@link DeviceConnectState#DIS_CONNECTING}.
77      * @param requestCallback Indicates the callback to be invoked when the Device+ service is connected.
78      * This parameter can be null.
79      * @return none
80      */
81     virtual void UpdateConnectStatus(int token, const std::string &deviceId, int status,
82         const std::shared_ptr<RequestCallback> &requestCallback) = 0;
83 
84     /**
85      * @brief Shows the list of devices that can be selected for ability migration on the distributed network.
86      *
87      * @param token Indicates the registration token of the ability.
88      * @param parameter Indicates the {@link ExtraParams} object containing the extra parameters used to filter
89      * the list of available devices. This parameter can be null.
90      * @param requestCallback Indicates the callback to be invoked when the Device+ service is connected.
91      * This parameter can be null.
92      * @return none
93      */
94     virtual void ShowDeviceList(
95         int token, const ExtraParams &parameter, const std::shared_ptr<RequestCallback> &requestCallback) = 0;
96 
97     /**
98      * @brief Disconnects from the Device+ control center.
99      *
100      * <p>This method can be called when you want to stop migrating an ability.
101      *
102      * @param none
103      * @return none
104      */
105     virtual void Disconnect() = 0;
106 };
107 }  // namespace AppExecFwk
108 }  // namespace OHOS
109 #endif  // FOUNDATION_APPEXECFWK_OHOS_CONTINUATION_REGISTER_MANAGER_INTERFACE_H