1 /* 2 * Copyright (C) 2016 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.pbapclient; 18 19 import android.util.Log; 20 21 import com.android.bluetooth.pbapclient.utils.ObexAppParameters; 22 import com.android.bluetooth.pbapclient.BluetoothPbapVcardListing; 23 24 import java.io.IOException; 25 import java.io.InputStream; 26 import java.util.ArrayList; 27 28 import javax.obex.HeaderSet; 29 30 final class BluetoothPbapRequestPullVcardListing extends BluetoothPbapRequest { 31 32 private static final String TAG = "BluetoothPbapRequestPullVcardListing"; 33 34 private static final String TYPE = "x-bt/vcard-listing"; 35 36 private BluetoothPbapVcardListing mResponse = null; 37 38 private int mNewMissedCalls = -1; 39 BluetoothPbapRequestPullVcardListing(String folder, byte order, byte searchAttr, String searchVal, int maxListCount, int listStartOffset)40 public BluetoothPbapRequestPullVcardListing(String folder, byte order, byte searchAttr, 41 String searchVal, int maxListCount, int listStartOffset) { 42 43 if (maxListCount < 0 || maxListCount > 65535) { 44 throw new IllegalArgumentException("maxListCount should be [0..65535]"); 45 } 46 47 if (listStartOffset < 0 || listStartOffset > 65535) { 48 throw new IllegalArgumentException("listStartOffset should be [0..65535]"); 49 } 50 51 if (folder == null) { 52 folder = ""; 53 } 54 55 mHeaderSet.setHeader(HeaderSet.NAME, folder); 56 57 mHeaderSet.setHeader(HeaderSet.TYPE, TYPE); 58 59 ObexAppParameters oap = new ObexAppParameters(); 60 61 if (order >= 0) { 62 oap.add(OAP_TAGID_ORDER, order); 63 } 64 65 if (searchVal != null) { 66 oap.add(OAP_TAGID_SEARCH_ATTRIBUTE, searchAttr); 67 oap.add(OAP_TAGID_SEARCH_VALUE, searchVal); 68 } 69 70 /* 71 * maxListCount is a special case which is handled in 72 * BluetoothPbapRequestPullVcardListingSize 73 */ 74 if (maxListCount > 0) { 75 oap.add(OAP_TAGID_MAX_LIST_COUNT, (short) maxListCount); 76 } 77 78 if (listStartOffset > 0) { 79 oap.add(OAP_TAGID_LIST_START_OFFSET, (short) listStartOffset); 80 } 81 82 oap.addToHeaderSet(mHeaderSet); 83 } 84 85 @Override readResponse(InputStream stream)86 protected void readResponse(InputStream stream) throws IOException { 87 Log.v(TAG, "readResponse"); 88 89 mResponse = new BluetoothPbapVcardListing(stream); 90 } 91 92 @Override readResponseHeaders(HeaderSet headerset)93 protected void readResponseHeaders(HeaderSet headerset) { 94 Log.v(TAG, "readResponseHeaders"); 95 96 ObexAppParameters oap = ObexAppParameters.fromHeaderSet(headerset); 97 98 if (oap.exists(OAP_TAGID_NEW_MISSED_CALLS)) { 99 mNewMissedCalls = oap.getByte(OAP_TAGID_NEW_MISSED_CALLS); 100 } 101 } 102 getList()103 public ArrayList<BluetoothPbapCard> getList() { 104 return mResponse.getList(); 105 } 106 getNewMissedCalls()107 public int getNewMissedCalls() { 108 return mNewMissedCalls; 109 } 110 } 111