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