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 GetImageProperties request, allowing a user to retrieve information regarding
27  * the image formats, encodings, etc. available for an image.
28  */
29 public class RequestGetImageProperties extends BipRequest {
30     // Expected inputs
31     private String mImageHandle = null;
32 
33     // Expected return type
34     private static final String TYPE = "x-bt/img-properties";
35     private BipImageProperties mImageProperties = null;
36 
RequestGetImageProperties(String imageHandle)37     public RequestGetImageProperties(String imageHandle) {
38         mHeaderSet = new HeaderSet();
39         mResponseCode = -1;
40         mImageHandle = imageHandle;
41 
42         debug("GetImageProperties - handle: " + mImageHandle);
43 
44         mHeaderSet.setHeader(HeaderSet.TYPE, TYPE);
45         mHeaderSet.setHeader(HEADER_ID_IMG_HANDLE, mImageHandle);
46     }
47 
48     @Override
getType()49     public int getType() {
50         return TYPE_GET_IMAGE_PROPERTIES;
51     }
52 
53     @Override
execute(ClientSession session)54     public void execute(ClientSession session) throws IOException {
55         executeGet(session);
56     }
57 
58     @Override
readResponse(InputStream stream)59     protected void readResponse(InputStream stream) throws IOException {
60         try {
61             mImageProperties = new BipImageProperties(stream);
62             debug("Response GetImageProperties - handle: " + mImageHandle + ", properties: "
63                     + mImageProperties.toString());
64         } catch (ParseException e) {
65             error("Failed to parse incoming properties object");
66             mImageProperties = null;
67         }
68     }
69 
70     /**
71      * Get the image handle associated with this request
72      *
73      * @return image handle used with this request
74      */
getImageHandle()75     public String getImageHandle() {
76         return mImageHandle;
77     }
78 
79     /**
80      * Get the requested set of image properties sent from the remote device
81      *
82      * @return A BipImageProperties object
83      */
getImageProperties()84     public BipImageProperties getImageProperties() {
85         return mImageProperties;
86     }
87 }
88