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