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.ParcelFileDescriptor; 21 import android.view.contentcapture.ContentCaptureManager.DataShareError; 22 23 /** Adapter class used by apps to share data with the Content Capture service. */ 24 public interface DataShareWriteAdapter { 25 26 /** 27 * Method invoked when the data share session has been started and the app needs to start 28 * writing into the file used for sharing. 29 * 30 * <p>App needs to handle explicitly cases when the file descriptor is closed and handle 31 * gracefully if IOExceptions happen. 32 * 33 * @param destination file descriptor used to write data into. 34 */ onWrite(@onNull ParcelFileDescriptor destination)35 void onWrite(@NonNull ParcelFileDescriptor destination); 36 37 /** Data share sessions has been rejected by the Content Capture service. */ onRejected()38 void onRejected(); 39 40 /** 41 * Method invoked when an error occurred, for example sessions has not been started or 42 * terminated unsuccessfully. 43 * 44 * @param errorCode the error code corresponding to an ERROR_* value. 45 */ onError(@ataShareError int errorCode)46 default void onError(@DataShareError int errorCode) { 47 /* do nothing - stub */ 48 } 49 } 50