1 /* 2 * Copyright (C) 2019 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 com.android.bluetooth.avrcpcontroller; 18 19 import java.io.IOException; 20 import java.io.InputStream; 21 22 import javax.obex.ClientSession; 23 import javax.obex.HeaderSet; 24 25 /** 26 * This implements a GetImage request, allowing a user to retrieve an image from the remote device 27 * with a specified format, encoding, etc. 28 */ 29 public class RequestGetImage extends BipRequest { 30 // Expected inputs 31 private final String mImageHandle; 32 private final BipImageDescriptor mImageDescriptor; 33 34 // Expected return type 35 private static final String TYPE = "x-bt/img-img"; 36 private BipImage mImage = null; 37 RequestGetImage(String imageHandle, BipImageDescriptor descriptor)38 public RequestGetImage(String imageHandle, BipImageDescriptor descriptor) { 39 mHeaderSet = new HeaderSet(); 40 mResponseCode = -1; 41 42 mImageHandle = imageHandle; 43 mImageDescriptor = descriptor; 44 45 debug("GetImage - handle: " + mImageHandle + ", descriptor: " + mImageDescriptor); 46 47 mHeaderSet.setHeader(HeaderSet.TYPE, TYPE); 48 mHeaderSet.setHeader(HEADER_ID_IMG_HANDLE, mImageHandle); 49 if (mImageDescriptor != null) { 50 mHeaderSet.setHeader(HEADER_ID_IMG_DESCRIPTOR, mImageDescriptor.serialize()); 51 } else { 52 mHeaderSet.setHeader(HEADER_ID_IMG_DESCRIPTOR, null); 53 } 54 } 55 56 @Override getType()57 public int getType() { 58 return TYPE_GET_IMAGE; 59 } 60 61 @Override execute(ClientSession session)62 public void execute(ClientSession session) throws IOException { 63 executeGet(session); 64 } 65 66 @Override readResponse(InputStream stream)67 protected void readResponse(InputStream stream) throws IOException { 68 mImage = new BipImage(mImageHandle, stream); 69 debug("Response GetImage - handle:" + mImageHandle + ", image: " + mImage); 70 } 71 72 /** 73 * Get the image handle associated with this request 74 * 75 * @return image handle used with this request 76 */ getImageHandle()77 public String getImageHandle() { 78 return mImageHandle; 79 } 80 81 /** 82 * Get the downloaded image sent from the remote device 83 * 84 * @return A BipImage object containing the downloaded image Bitmap 85 */ getImage()86 public BipImage getImage() { 87 return mImage; 88 } 89 } 90