1 /* 2 * Copyright (C) 2014 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 java.io.IOException; 20 import java.io.InputStream; 21 import java.util.ArrayList; 22 23 import javax.obex.ClientSession; 24 import javax.obex.HeaderSet; 25 /* Get a listing of subdirectories. */ 26 final class RequestGetFolderListing extends Request { 27 28 private static final String TYPE = "x-obex/folder-listing"; 29 30 private FolderListing mResponse = null; 31 32 public RequestGetFolderListing(int maxListCount, int listStartOffset) { 33 34 if (maxListCount < 0 || maxListCount > 65535) { 35 throw new IllegalArgumentException("maxListCount should be [0..65535]"); 36 } 37 38 if (listStartOffset < 0 || listStartOffset > 65535) { 39 throw new IllegalArgumentException("listStartOffset should be [0..65535]"); 40 } 41 42 mHeaderSet.setHeader(HeaderSet.TYPE, TYPE); 43 44 ObexAppParameters oap = new ObexAppParameters(); 45 // Allow GetFolderListing for maxListCount value 0 also. 46 if (maxListCount >= 0) { 47 oap.add(OAP_TAGID_MAX_LIST_COUNT, (short) maxListCount); 48 } 49 50 if (listStartOffset > 0) { 51 oap.add(OAP_TAGID_START_OFFSET, (short) listStartOffset); 52 } 53 54 oap.addToHeaderSet(mHeaderSet); 55 } 56 57 @Override 58 protected void readResponse(InputStream stream) { 59 mResponse = new FolderListing(stream); 60 } 61 62 public ArrayList<String> getList() { 63 if (mResponse == null) { 64 return null; 65 } 66 67 return mResponse.getList(); 68 } 69 70 @Override 71 public void execute(ClientSession session) throws IOException { 72 executeGet(session); 73 } 74 } 75