• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.mapclient;
18 
19 import android.util.Log;
20 
21 import java.io.IOException;
22 
23 import javax.obex.ClientSession;
24 import javax.obex.HeaderSet;
25 
26 final class RequestSetMessageStatus extends Request {
27     public enum StatusIndicator { READ, DELETED }
28     private static final String TAG = "RequestSetMessageStatus";
29     private static final String TYPE = "x-bt/messageStatus";
30     private static StatusIndicator mStatusInd;
31     private static byte mValue;
32 
RequestSetMessageStatus(String handle, StatusIndicator statusInd, byte value)33     public RequestSetMessageStatus(String handle, StatusIndicator statusInd, byte value) {
34         mHeaderSet.setHeader(HeaderSet.TYPE, TYPE);
35         mHeaderSet.setHeader(HeaderSet.NAME, handle);
36 
37         ObexAppParameters oap = new ObexAppParameters();
38         oap.add(OAP_TAGID_STATUS_INDICATOR,
39                 statusInd == StatusIndicator.READ ? STATUS_INDICATOR_READ
40                                                   : STATUS_INDICATOR_DELETED);
41         oap.add(OAP_TAGID_STATUS_VALUE, value == STATUS_YES ? STATUS_YES
42                                                             : STATUS_NO);
43         oap.addToHeaderSet(mHeaderSet);
44         mStatusInd = statusInd;
45         mValue = value;
46     }
47 
getStatusIndicator()48     public StatusIndicator getStatusIndicator() {
49         return mStatusInd;
50     }
51 
getValue()52     public byte getValue() {
53         return mValue;
54     }
55 
getHandle()56     public String getHandle() {
57         try {
58             return (String) mHeaderSet.getHeader(HeaderSet.NAME);
59         } catch (IOException e) {
60             Log.e(TAG, "Unexpected exception while reading handle!", e);
61             return null;
62         }
63     }
64 
65     @Override
execute(ClientSession session)66     public void execute(ClientSession session) throws IOException {
67         executePut(session, FILLER_BYTE);
68     }
69 }
70