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