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 java.io.IOException; 22 23 import javax.obex.ClientSession; 24 import javax.obex.HeaderSet; 25 import javax.obex.ResponseCodes; 26 27 final class BluetoothPbapRequestSetPath extends BluetoothPbapRequest { 28 29 private final static String TAG = "BluetoothPbapRequestSetPath"; 30 31 private enum SetPathDir { 32 ROOT, UP, DOWN 33 }; 34 35 private SetPathDir mDir; 36 BluetoothPbapRequestSetPath(String name)37 public BluetoothPbapRequestSetPath(String name) { 38 mDir = SetPathDir.DOWN; 39 mHeaderSet.setHeader(HeaderSet.NAME, name); 40 } 41 BluetoothPbapRequestSetPath(boolean goUp)42 public BluetoothPbapRequestSetPath(boolean goUp) { 43 mHeaderSet.setEmptyNameHeader(); 44 if (goUp) { 45 mDir = SetPathDir.UP; 46 } else { 47 mDir = SetPathDir.ROOT; 48 } 49 } 50 51 @Override execute(ClientSession session)52 public void execute(ClientSession session) { 53 Log.v(TAG, "execute"); 54 55 HeaderSet hs = null; 56 57 try { 58 switch (mDir) { 59 case ROOT: 60 case DOWN: 61 hs = session.setPath(mHeaderSet, false, false); 62 break; 63 case UP: 64 hs = session.setPath(mHeaderSet, true, false); 65 break; 66 } 67 68 mResponseCode = hs.getResponseCode(); 69 } catch (IOException e) { 70 mResponseCode = ResponseCodes.OBEX_HTTP_INTERNAL_ERROR; 71 } 72 } 73 } 74