Sergey Volnov | 6e04901 | 2020-01-10 18:10:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.view.contentcapture; |
| 18 | |
| 19 | import android.annotation.NonNull; |
| 20 | import android.os.CancellationSignal; |
| 21 | import android.os.ParcelFileDescriptor; |
| 22 | |
| 23 | /** Adapter class used by apps to share data with the Content Capture service. */ |
| 24 | public interface DataShareWriteAdapter { |
| 25 | |
| 26 | /** Request has been rejected, because a concurrent data share sessions is in progress. */ |
| 27 | int ERROR_CONCURRENT_REQUEST = 1; |
| 28 | |
| 29 | /** Data share session timed out. */ |
| 30 | int ERROR_UNKNOWN = 2; |
| 31 | |
| 32 | /** |
| 33 | * Method invoked when the data share session has been started and the app needs to start |
| 34 | * writing into the file used for sharing. |
| 35 | * |
| 36 | * <p>App needs to handle explicitly cases when the file descriptor is closed and handle |
| 37 | * gracefully if IOExceptions happen. |
| 38 | * |
| 39 | * @param destination file descriptor used to write data into |
| 40 | * @param cancellationSignal cancellation signal that the app can use to subscribe to cancel |
| 41 | * operations. |
| 42 | */ |
| 43 | void onWrite(@NonNull ParcelFileDescriptor destination, |
| 44 | @NonNull CancellationSignal cancellationSignal); |
| 45 | |
| 46 | /** Data share sessions has been rejected by the Content Capture service. */ |
| 47 | void onRejected(); |
| 48 | |
| 49 | /** |
| 50 | * Method invoked when an error occurred, for example sessions has not been started or |
| 51 | * terminated unsuccessfully. |
| 52 | * |
| 53 | * @param errorCode the error code corresponding to an ERROR_* value. |
| 54 | */ |
| 55 | default void onError(int errorCode) { |
| 56 | /* do nothing - stub */ |
| 57 | } |
| 58 | } |