blob: f64ef87b3b41791b8577ae9971099451ba79c1d5 [file] [log] [blame]
Mike Lockwood24236072010-06-23 17:36:36 -04001/*
2 * Copyright (C) 2010 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
Mike Lockwoodc4308f02011-03-01 08:04:54 -080018package android.hardware.usb;
Mike Lockwood24236072010-06-23 17:36:36 -040019
Mike Lockwood3a68b832011-03-08 10:08:59 -050020import android.app.PendingIntent;
21import android.content.Context;
Mike Lockwoode7d511e2010-12-30 13:39:37 -050022import android.os.Bundle;
23import android.os.ParcelFileDescriptor;
24import android.os.RemoteException;
Mike Lockwood02e45692011-06-14 15:43:51 -040025import android.os.SystemProperties;
Mike Lockwoode7d511e2010-12-30 13:39:37 -050026import android.util.Log;
27
Mike Lockwoode7d511e2010-12-30 13:39:37 -050028import java.util.HashMap;
Mike Lockwood08bff3b2010-08-31 13:27:05 -040029
Mike Lockwood24236072010-06-23 17:36:36 -040030/**
Mike Lockwood11dd5ae2011-04-01 14:00:08 -040031 * This class allows you to access the state of USB and communicate with USB devices.
32 * Currently only host mode is supported in the public API.
Mike Lockwoode7d511e2010-12-30 13:39:37 -050033 *
34 * <p>You can obtain an instance of this class by calling
35 * {@link android.content.Context#getSystemService(java.lang.String) Context.getSystemService()}.
36 *
37 * {@samplecode
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080038 * UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);}
39 *
40 * <div class="special reference">
41 * <h3>Developer Guides</h3>
42 * <p>For more information about communicating with USB hardware, read the
43 * <a href="{@docRoot}guide/topics/usb/index.html">USB</a> developer guide.</p>
44 * </div>
Mike Lockwood24236072010-06-23 17:36:36 -040045 */
Mike Lockwood770126a2010-12-09 22:30:37 -080046public class UsbManager {
Mike Lockwoode7d511e2010-12-30 13:39:37 -050047 private static final String TAG = "UsbManager";
48
Mike Lockwood24236072010-06-23 17:36:36 -040049 /**
Mike Lockwoode7d511e2010-12-30 13:39:37 -050050 * Broadcast Action: A sticky broadcast for USB state change events when in device mode.
Mike Lockwood709981e2010-06-28 09:58:58 -040051 *
Mike Lockwoodb92df0f2010-12-10 16:19:32 -080052 * This is a sticky broadcast for clients that includes USB connected/disconnected state,
Mike Lockwood9182d3c2011-02-15 09:50:22 -050053 * <ul>
54 * <li> {@link #USB_CONNECTED} boolean indicating whether USB is connected or disconnected.
Mike Lockwood02e45692011-06-14 15:43:51 -040055 * <li> {@link #USB_CONFIGURED} boolean indicating whether USB is configured.
Mike Lockwood9eb014a2011-06-08 09:17:45 -070056 * currently zero if not configured, one for configured.
57 * <li> {@link #USB_FUNCTION_MASS_STORAGE} boolean extra indicating whether the
58 * mass storage function is enabled
59 * <li> {@link #USB_FUNCTION_ADB} boolean extra indicating whether the
60 * adb function is enabled
61 * <li> {@link #USB_FUNCTION_RNDIS} boolean extra indicating whether the
62 * RNDIS ethernet function is enabled
63 * <li> {@link #USB_FUNCTION_MTP} boolean extra indicating whether the
64 * MTP function is enabled
65 * <li> {@link #USB_FUNCTION_PTP} boolean extra indicating whether the
66 * PTP function is enabled
67 * <li> {@link #USB_FUNCTION_PTP} boolean extra indicating whether the
68 * accessory function is enabled
Mike Lockwood9d5a4be2012-04-06 09:41:32 -070069 * <li> {@link #USB_FUNCTION_AUDIO_SOURCE} boolean extra indicating whether the
70 * audio source function is enabled
Mike Lockwood9182d3c2011-02-15 09:50:22 -050071 * </ul>
Mike Lockwooda75075e12011-03-11 11:26:11 -050072 *
73 * {@hide}
Mike Lockwood709981e2010-06-28 09:58:58 -040074 */
75 public static final String ACTION_USB_STATE =
Mike Lockwoodc4308f02011-03-01 08:04:54 -080076 "android.hardware.usb.action.USB_STATE";
Mike Lockwood709981e2010-06-28 09:58:58 -040077
Mike Lockwoode7d511e2010-12-30 13:39:37 -050078 /**
79 * Broadcast Action: A broadcast for USB device attached event.
80 *
81 * This intent is sent when a USB device is attached to the USB bus when in host mode.
Mike Lockwood9182d3c2011-02-15 09:50:22 -050082 * <ul>
Mike Lockwoodc4308f02011-03-01 08:04:54 -080083 * <li> {@link #EXTRA_DEVICE} containing the {@link android.hardware.usb.UsbDevice}
Mike Lockwood9182d3c2011-02-15 09:50:22 -050084 * for the attached device
85 * </ul>
Mike Lockwoode7d511e2010-12-30 13:39:37 -050086 */
87 public static final String ACTION_USB_DEVICE_ATTACHED =
Mike Lockwoodc4308f02011-03-01 08:04:54 -080088 "android.hardware.usb.action.USB_DEVICE_ATTACHED";
Mike Lockwoode7d511e2010-12-30 13:39:37 -050089
90 /**
91 * Broadcast Action: A broadcast for USB device detached event.
92 *
93 * This intent is sent when a USB device is detached from the USB bus when in host mode.
Mike Lockwood9182d3c2011-02-15 09:50:22 -050094 * <ul>
Mike Lockwoodc4308f02011-03-01 08:04:54 -080095 * <li> {@link #EXTRA_DEVICE} containing the {@link android.hardware.usb.UsbDevice}
Mike Lockwood188d00b2011-02-23 13:14:33 -080096 * for the detached device
Mike Lockwood9182d3c2011-02-15 09:50:22 -050097 * </ul>
Mike Lockwoode7d511e2010-12-30 13:39:37 -050098 */
99 public static final String ACTION_USB_DEVICE_DETACHED =
Mike Lockwoodc4308f02011-03-01 08:04:54 -0800100 "android.hardware.usb.action.USB_DEVICE_DETACHED";
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500101
Mike Lockwood9182d3c2011-02-15 09:50:22 -0500102 /**
103 * Broadcast Action: A broadcast for USB accessory attached event.
104 *
105 * This intent is sent when a USB accessory is attached.
106 * <ul>
Mike Lockwoodc4308f02011-03-01 08:04:54 -0800107 * <li> {@link #EXTRA_ACCESSORY} containing the {@link android.hardware.usb.UsbAccessory}
Mike Lockwood9182d3c2011-02-15 09:50:22 -0500108 * for the attached accessory
109 * </ul>
110 */
111 public static final String ACTION_USB_ACCESSORY_ATTACHED =
Mike Lockwoodc4308f02011-03-01 08:04:54 -0800112 "android.hardware.usb.action.USB_ACCESSORY_ATTACHED";
Mike Lockwood9182d3c2011-02-15 09:50:22 -0500113
114 /**
115 * Broadcast Action: A broadcast for USB accessory detached event.
116 *
117 * This intent is sent when a USB accessory is detached.
118 * <ul>
Mike Lockwood980f0432011-03-09 15:49:13 -0500119 * <li> {@link #EXTRA_ACCESSORY} containing the {@link UsbAccessory}
Mike Lockwood9182d3c2011-02-15 09:50:22 -0500120 * for the attached accessory that was detached
121 * </ul>
122 */
123 public static final String ACTION_USB_ACCESSORY_DETACHED =
Mike Lockwoodc4308f02011-03-01 08:04:54 -0800124 "android.hardware.usb.action.USB_ACCESSORY_DETACHED";
Mike Lockwood9182d3c2011-02-15 09:50:22 -0500125
Mike Lockwood709981e2010-06-28 09:58:58 -0400126 /**
127 * Boolean extra indicating whether USB is connected or disconnected.
128 * Used in extras for the {@link #ACTION_USB_STATE} broadcast.
Mike Lockwooda75075e12011-03-11 11:26:11 -0500129 *
130 * {@hide}
Mike Lockwood709981e2010-06-28 09:58:58 -0400131 */
132 public static final String USB_CONNECTED = "connected";
Mike Lockwood24236072010-06-23 17:36:36 -0400133
134 /**
Mike Lockwood02e45692011-06-14 15:43:51 -0400135 * Boolean extra indicating whether USB is configured.
Mike Lockwoodb92df0f2010-12-10 16:19:32 -0800136 * Used in extras for the {@link #ACTION_USB_STATE} broadcast.
Mike Lockwooda75075e12011-03-11 11:26:11 -0500137 *
138 * {@hide}
Mike Lockwoodb92df0f2010-12-10 16:19:32 -0800139 */
Mike Lockwood02e45692011-06-14 15:43:51 -0400140 public static final String USB_CONFIGURED = "configured";
Mike Lockwoodb92df0f2010-12-10 16:19:32 -0800141
142 /**
Mike Lockwood24236072010-06-23 17:36:36 -0400143 * Name of the USB mass storage USB function.
Mike Lockwoodb92df0f2010-12-10 16:19:32 -0800144 * Used in extras for the {@link #ACTION_USB_STATE} broadcast
Mike Lockwooda75075e12011-03-11 11:26:11 -0500145 *
146 * {@hide}
Mike Lockwood24236072010-06-23 17:36:36 -0400147 */
148 public static final String USB_FUNCTION_MASS_STORAGE = "mass_storage";
149
150 /**
151 * Name of the adb USB function.
Mike Lockwoodb92df0f2010-12-10 16:19:32 -0800152 * Used in extras for the {@link #ACTION_USB_STATE} broadcast
Mike Lockwooda75075e12011-03-11 11:26:11 -0500153 *
154 * {@hide}
Mike Lockwood24236072010-06-23 17:36:36 -0400155 */
156 public static final String USB_FUNCTION_ADB = "adb";
157
158 /**
159 * Name of the RNDIS ethernet USB function.
Mike Lockwoodb92df0f2010-12-10 16:19:32 -0800160 * Used in extras for the {@link #ACTION_USB_STATE} broadcast
Mike Lockwooda75075e12011-03-11 11:26:11 -0500161 *
162 * {@hide}
Mike Lockwood24236072010-06-23 17:36:36 -0400163 */
164 public static final String USB_FUNCTION_RNDIS = "rndis";
165
166 /**
167 * Name of the MTP USB function.
Mike Lockwoodb92df0f2010-12-10 16:19:32 -0800168 * Used in extras for the {@link #ACTION_USB_STATE} broadcast
Mike Lockwooda75075e12011-03-11 11:26:11 -0500169 *
170 * {@hide}
Mike Lockwood24236072010-06-23 17:36:36 -0400171 */
172 public static final String USB_FUNCTION_MTP = "mtp";
173
174 /**
Mike Lockwood9eb014a2011-06-08 09:17:45 -0700175 * Name of the PTP USB function.
176 * Used in extras for the {@link #ACTION_USB_STATE} broadcast
177 *
178 * {@hide}
179 */
180 public static final String USB_FUNCTION_PTP = "ptp";
181
182 /**
Mike Lockwood9d5a4be2012-04-06 09:41:32 -0700183 * Name of the audio source USB function.
184 * Used in extras for the {@link #ACTION_USB_STATE} broadcast
185 *
186 * {@hide}
187 */
188 public static final String USB_FUNCTION_AUDIO_SOURCE = "audio_source";
189
190 /**
Mike Lockwood9182d3c2011-02-15 09:50:22 -0500191 * Name of the Accessory USB function.
Mike Lockwoodb92df0f2010-12-10 16:19:32 -0800192 * Used in extras for the {@link #ACTION_USB_STATE} broadcast
Mike Lockwooda75075e12011-03-11 11:26:11 -0500193 *
194 * {@hide}
Mike Lockwood24236072010-06-23 17:36:36 -0400195 */
Mike Lockwood9182d3c2011-02-15 09:50:22 -0500196 public static final String USB_FUNCTION_ACCESSORY = "accessory";
197
198 /**
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500199 * Name of extra for {@link #ACTION_USB_DEVICE_ATTACHED} and
Mike Lockwood02eb8742011-02-27 09:10:37 -0800200 * {@link #ACTION_USB_DEVICE_DETACHED} broadcasts
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500201 * containing the UsbDevice object for the device.
202 */
Mike Lockwood9182d3c2011-02-15 09:50:22 -0500203
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500204 public static final String EXTRA_DEVICE = "device";
205
Mike Lockwood9182d3c2011-02-15 09:50:22 -0500206 /**
Mike Lockwood02eb8742011-02-27 09:10:37 -0800207 * Name of extra for {@link #ACTION_USB_ACCESSORY_ATTACHED} and
208 * {@link #ACTION_USB_ACCESSORY_DETACHED} broadcasts
Mike Lockwood9182d3c2011-02-15 09:50:22 -0500209 * containing the UsbAccessory object for the accessory.
210 */
211 public static final String EXTRA_ACCESSORY = "accessory";
212
Mike Lockwood3a68b832011-03-08 10:08:59 -0500213 /**
214 * Name of extra added to the {@link android.app.PendingIntent}
Mike Lockwood980f0432011-03-09 15:49:13 -0500215 * passed into {@link #requestPermission(UsbDevice, PendingIntent)}
216 * or {@link #requestPermission(UsbAccessory, PendingIntent)}
Mike Lockwood3a68b832011-03-08 10:08:59 -0500217 * containing a boolean value indicating whether the user granted permission or not.
218 */
219 public static final String EXTRA_PERMISSION_GRANTED = "permission";
220
221 private final Context mContext;
222 private final IUsbManager mService;
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500223
224 /**
225 * {@hide}
226 */
Mike Lockwood3a68b832011-03-08 10:08:59 -0500227 public UsbManager(Context context, IUsbManager service) {
228 mContext = context;
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500229 mService = service;
230 }
231
232 /**
233 * Returns a HashMap containing all USB devices currently attached.
234 * USB device name is the key for the returned HashMap.
235 * The result will be empty if no devices are attached, or if
236 * USB host mode is inactive or unsupported.
237 *
238 * @return HashMap containing all connected USB devices.
239 */
240 public HashMap<String,UsbDevice> getDeviceList() {
241 Bundle bundle = new Bundle();
242 try {
243 mService.getDeviceList(bundle);
244 HashMap<String,UsbDevice> result = new HashMap<String,UsbDevice>();
245 for (String name : bundle.keySet()) {
246 result.put(name, (UsbDevice)bundle.get(name));
247 }
248 return result;
249 } catch (RemoteException e) {
250 Log.e(TAG, "RemoteException in getDeviceList", e);
251 return null;
252 }
253 }
254
255 /**
256 * Opens the device so it can be used to send and receive
Mike Lockwoodc4308f02011-03-01 08:04:54 -0800257 * data using {@link android.hardware.usb.UsbRequest}.
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500258 *
259 * @param device the device to open
mike wakerly1567a432012-07-17 19:58:19 -0700260 * @return a {@link UsbDeviceConnection}, or {@code null} if open failed
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500261 */
Mike Lockwoodacc29cc2011-03-11 08:18:08 -0500262 public UsbDeviceConnection openDevice(UsbDevice device) {
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500263 try {
Mike Lockwoodacc29cc2011-03-11 08:18:08 -0500264 String deviceName = device.getDeviceName();
265 ParcelFileDescriptor pfd = mService.openDevice(deviceName);
266 if (pfd != null) {
267 UsbDeviceConnection connection = new UsbDeviceConnection(device);
268 boolean result = connection.open(deviceName, pfd);
269 pfd.close();
270 if (result) {
271 return connection;
272 }
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500273 }
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500274 } catch (Exception e) {
275 Log.e(TAG, "exception in UsbManager.openDevice", e);
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500276 }
Mike Lockwoodacc29cc2011-03-11 08:18:08 -0500277 return null;
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500278 }
279
Mike Lockwood9182d3c2011-02-15 09:50:22 -0500280 /**
281 * Returns a list of currently attached USB accessories.
282 * (in the current implementation there can be at most one)
283 *
284 * @return list of USB accessories, or null if none are attached.
285 */
286 public UsbAccessory[] getAccessoryList() {
287 try {
288 UsbAccessory accessory = mService.getCurrentAccessory();
289 if (accessory == null) {
290 return null;
291 } else {
292 return new UsbAccessory[] { accessory };
293 }
294 } catch (RemoteException e) {
Mike Lockwood3a68b832011-03-08 10:08:59 -0500295 Log.e(TAG, "RemoteException in getAccessoryList", e);
Mike Lockwood9182d3c2011-02-15 09:50:22 -0500296 return null;
297 }
298 }
299
300 /**
301 * Opens a file descriptor for reading and writing data to the USB accessory.
302 *
303 * @param accessory the USB accessory to open
304 * @return file descriptor, or null if the accessor could not be opened.
305 */
306 public ParcelFileDescriptor openAccessory(UsbAccessory accessory) {
307 try {
Mike Lockwood02eb8742011-02-27 09:10:37 -0800308 return mService.openAccessory(accessory);
Mike Lockwood9182d3c2011-02-15 09:50:22 -0500309 } catch (RemoteException e) {
Mike Lockwood3a68b832011-03-08 10:08:59 -0500310 Log.e(TAG, "RemoteException in openAccessory", e);
Mike Lockwood9182d3c2011-02-15 09:50:22 -0500311 return null;
312 }
313 }
314
Mike Lockwood3a68b832011-03-08 10:08:59 -0500315 /**
316 * Returns true if the caller has permission to access the device.
Mike Lockwoodc6f23e82011-03-09 12:05:20 -0500317 * Permission might have been granted temporarily via
Mike Lockwood980f0432011-03-09 15:49:13 -0500318 * {@link #requestPermission(UsbDevice, PendingIntent)} or
Mike Lockwoodc6f23e82011-03-09 12:05:20 -0500319 * by the user choosing the caller as the default application for the device.
Mike Lockwood3a68b832011-03-08 10:08:59 -0500320 *
321 * @param device to check permissions for
322 * @return true if caller has permission
323 */
324 public boolean hasPermission(UsbDevice device) {
325 try {
326 return mService.hasDevicePermission(device);
327 } catch (RemoteException e) {
328 Log.e(TAG, "RemoteException in hasPermission", e);
329 return false;
330 }
331 }
332
333 /**
334 * Returns true if the caller has permission to access the accessory.
Mike Lockwoodc6f23e82011-03-09 12:05:20 -0500335 * Permission might have been granted temporarily via
Mike Lockwood980f0432011-03-09 15:49:13 -0500336 * {@link #requestPermission(UsbAccessory, PendingIntent)} or
Mike Lockwoodc6f23e82011-03-09 12:05:20 -0500337 * by the user choosing the caller as the default application for the accessory.
Mike Lockwood3a68b832011-03-08 10:08:59 -0500338 *
339 * @param accessory to check permissions for
340 * @return true if caller has permission
341 */
342 public boolean hasPermission(UsbAccessory accessory) {
343 try {
344 return mService.hasAccessoryPermission(accessory);
345 } catch (RemoteException e) {
346 Log.e(TAG, "RemoteException in hasPermission", e);
347 return false;
348 }
349 }
350
351 /**
Mike Lockwoodc6f23e82011-03-09 12:05:20 -0500352 * Requests temporary permission for the given package to access the device.
Mike Lockwood3a68b832011-03-08 10:08:59 -0500353 * This may result in a system dialog being displayed to the user
354 * if permission had not already been granted.
355 * Success or failure is returned via the {@link android.app.PendingIntent} pi.
Mike Lockwoodc6f23e82011-03-09 12:05:20 -0500356 * If successful, this grants the caller permission to access the device only
357 * until the device is disconnected.
358 *
Mike Lockwood3a68b832011-03-08 10:08:59 -0500359 * The following extras will be added to pi:
360 * <ul>
361 * <li> {@link #EXTRA_DEVICE} containing the device passed into this call
362 * <li> {@link #EXTRA_PERMISSION_GRANTED} containing boolean indicating whether
363 * permission was granted by the user
364 * </ul>
365 *
366 * @param device to request permissions for
367 * @param pi PendingIntent for returning result
368 */
369 public void requestPermission(UsbDevice device, PendingIntent pi) {
370 try {
371 mService.requestDevicePermission(device, mContext.getPackageName(), pi);
372 } catch (RemoteException e) {
373 Log.e(TAG, "RemoteException in requestPermission", e);
374 }
375 }
376
377 /**
Mike Lockwoodc6f23e82011-03-09 12:05:20 -0500378 * Requests temporary permission for the given package to access the accessory.
Mike Lockwood3a68b832011-03-08 10:08:59 -0500379 * This may result in a system dialog being displayed to the user
380 * if permission had not already been granted.
381 * Success or failure is returned via the {@link android.app.PendingIntent} pi.
Mike Lockwood62cfeeb2011-03-11 18:39:03 -0500382 * If successful, this grants the caller permission to access the accessory only
Mike Lockwoodc6f23e82011-03-09 12:05:20 -0500383 * until the device is disconnected.
384 *
Mike Lockwood3a68b832011-03-08 10:08:59 -0500385 * The following extras will be added to pi:
386 * <ul>
387 * <li> {@link #EXTRA_ACCESSORY} containing the accessory passed into this call
388 * <li> {@link #EXTRA_PERMISSION_GRANTED} containing boolean indicating whether
389 * permission was granted by the user
390 * </ul>
391 *
392 * @param accessory to request permissions for
393 * @param pi PendingIntent for returning result
394 */
395 public void requestPermission(UsbAccessory accessory, PendingIntent pi) {
396 try {
397 mService.requestAccessoryPermission(accessory, mContext.getPackageName(), pi);
398 } catch (RemoteException e) {
399 Log.e(TAG, "RemoteException in requestPermission", e);
400 }
401 }
402
Mike Lockwood02e45692011-06-14 15:43:51 -0400403 private static boolean propertyContainsFunction(String property, String function) {
404 String functions = SystemProperties.get(property, "");
405 int index = functions.indexOf(function);
406 if (index < 0) return false;
407 if (index > 0 && functions.charAt(index - 1) != ',') return false;
408 int charAfter = index + function.length();
409 if (charAfter < functions.length() && functions.charAt(charAfter) != ',') return false;
410 return true;
Mike Lockwood08bff3b2010-08-31 13:27:05 -0400411 }
412
413 /**
414 * Returns true if the specified USB function is currently enabled.
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500415 *
416 * @param function name of the USB function
417 * @return true if the USB function is enabled.
Mike Lockwooda75075e12011-03-11 11:26:11 -0500418 *
419 * {@hide}
Mike Lockwood08bff3b2010-08-31 13:27:05 -0400420 */
Mike Lockwood02e45692011-06-14 15:43:51 -0400421 public boolean isFunctionEnabled(String function) {
422 return propertyContainsFunction("sys.usb.config", function);
423 }
424
425 /**
Mike Lockwoode51099f2011-08-02 12:54:49 -0400426 * Returns the current default USB function.
427 *
428 * @return name of the default function.
429 *
430 * {@hide}
431 */
432 public String getDefaultFunction() {
433 String functions = SystemProperties.get("persist.sys.usb.config", "");
434 int commaIndex = functions.indexOf(',');
435 if (commaIndex > 0) {
436 return functions.substring(0, commaIndex);
437 } else {
438 return functions;
439 }
440 }
441
442 /**
Mike Lockwoodf59717d2011-06-22 15:19:33 -0400443 * Sets the current USB function.
Mike Lockwood875c24b2011-07-18 10:54:32 -0700444 * If function is null, then the current function is set to the default function.
Mike Lockwood02e45692011-06-14 15:43:51 -0400445 *
Mike Lockwood875c24b2011-07-18 10:54:32 -0700446 * @param function name of the USB function, or null to restore the default function
447 * @param makeDefault true if the function should be set as the new default function
Mike Lockwood02e45692011-06-14 15:43:51 -0400448 *
449 * {@hide}
450 */
Mike Lockwoodf59717d2011-06-22 15:19:33 -0400451 public void setCurrentFunction(String function, boolean makeDefault) {
Mike Lockwood08bff3b2010-08-31 13:27:05 -0400452 try {
Mike Lockwoodf59717d2011-06-22 15:19:33 -0400453 mService.setCurrentFunction(function, makeDefault);
Mike Lockwood02e45692011-06-14 15:43:51 -0400454 } catch (RemoteException e) {
Mike Lockwoodf59717d2011-06-22 15:19:33 -0400455 Log.e(TAG, "RemoteException in setCurrentFunction", e);
Mike Lockwood02e45692011-06-14 15:43:51 -0400456 }
457 }
458
459 /**
460 * Sets the file path for USB mass storage backing file.
461 *
462 * @param path backing file path
463 *
464 * {@hide}
465 */
466 public void setMassStorageBackingFile(String path) {
467 try {
468 mService.setMassStorageBackingFile(path);
469 } catch (RemoteException e) {
470 Log.e(TAG, "RemoteException in setDefaultFunction", e);
Mike Lockwood9182d3c2011-02-15 09:50:22 -0500471 }
472 }
Mike Lockwood24236072010-06-23 17:36:36 -0400473}