| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 1 | /* |
| 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 | package com.android.server; |
| 18 | |
| 19 | import android.content.ContentResolver; |
| 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
| Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 22 | import android.hardware.IUsbManager; |
| 23 | import android.hardware.UsbConstants; |
| 24 | import android.hardware.UsbDevice; |
| 25 | import android.hardware.UsbEndpoint; |
| 26 | import android.hardware.UsbInterface; |
| Mike Lockwood | 770126a | 2010-12-09 22:30:37 -0800 | [diff] [blame] | 27 | import android.hardware.UsbManager; |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 28 | import android.net.Uri; |
| Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 29 | import android.os.Bundle; |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 30 | import android.os.Handler; |
| 31 | import android.os.Message; |
| Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 32 | import android.os.Parcelable; |
| 33 | import android.os.ParcelFileDescriptor; |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 34 | import android.os.UEventObserver; |
| 35 | import android.provider.Settings; |
| 36 | import android.util.Log; |
| 37 | import android.util.Slog; |
| 38 | |
| 39 | import java.io.File; |
| 40 | import java.io.FileNotFoundException; |
| 41 | import java.io.FileReader; |
| 42 | import java.util.ArrayList; |
| Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 43 | import java.util.HashMap; |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 44 | |
| 45 | /** |
| Mike Lockwood | 770126a | 2010-12-09 22:30:37 -0800 | [diff] [blame] | 46 | * <p>UsbService monitors for changes to USB state. |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 47 | */ |
| Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 48 | class UsbService extends IUsbManager.Stub { |
| Mike Lockwood | 770126a | 2010-12-09 22:30:37 -0800 | [diff] [blame] | 49 | private static final String TAG = UsbService.class.getSimpleName(); |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 50 | private static final boolean LOG = false; |
| 51 | |
| Mike Lockwood | b92df0f | 2010-12-10 16:19:32 -0800 | [diff] [blame] | 52 | private static final String USB_CONNECTED_MATCH = |
| 53 | "DEVPATH=/devices/virtual/switch/usb_connected"; |
| 54 | private static final String USB_CONFIGURATION_MATCH = |
| 55 | "DEVPATH=/devices/virtual/switch/usb_configuration"; |
| 56 | private static final String USB_FUNCTIONS_MATCH = |
| 57 | "DEVPATH=/devices/virtual/usb_composite/"; |
| 58 | private static final String USB_CONNECTED_PATH = |
| 59 | "/sys/class/switch/usb_connected/state"; |
| 60 | private static final String USB_CONFIGURATION_PATH = |
| 61 | "/sys/class/switch/usb_configuration/state"; |
| 62 | private static final String USB_COMPOSITE_CLASS_PATH = |
| 63 | "/sys/class/usb_composite"; |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 64 | |
| 65 | private static final int MSG_UPDATE = 0; |
| 66 | |
| Mike Lockwood | b92df0f | 2010-12-10 16:19:32 -0800 | [diff] [blame] | 67 | // Delay for debouncing USB disconnects. |
| 68 | // We often get rapid connect/disconnect events when enabling USB functions, |
| 69 | // which need debouncing. |
| 70 | private static final int UPDATE_DELAY = 1000; |
| 71 | |
| 72 | // current connected and configuration state |
| 73 | private int mConnected; |
| 74 | private int mConfiguration; |
| 75 | |
| 76 | // last broadcasted connected and configuration state |
| 77 | private int mLastConnected = -1; |
| 78 | private int mLastConfiguration = -1; |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 79 | |
| Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 80 | // lists of enabled and disabled USB functions (for USB device mode) |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 81 | private final ArrayList<String> mEnabledFunctions = new ArrayList<String>(); |
| 82 | private final ArrayList<String> mDisabledFunctions = new ArrayList<String>(); |
| 83 | |
| Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 84 | private final HashMap<String,UsbDevice> mDevices = new HashMap<String,UsbDevice>(); |
| 85 | |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 86 | private boolean mSystemReady; |
| 87 | |
| 88 | private final Context mContext; |
| 89 | |
| Mike Lockwood | 770126a | 2010-12-09 22:30:37 -0800 | [diff] [blame] | 90 | private final UEventObserver mUEventObserver = new UEventObserver() { |
| 91 | @Override |
| 92 | public void onUEvent(UEventObserver.UEvent event) { |
| 93 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
| 94 | Slog.v(TAG, "USB UEVENT: " + event.toString()); |
| 95 | } |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 96 | |
| Mike Lockwood | 770126a | 2010-12-09 22:30:37 -0800 | [diff] [blame] | 97 | synchronized (this) { |
| Mike Lockwood | b92df0f | 2010-12-10 16:19:32 -0800 | [diff] [blame] | 98 | String name = event.get("SWITCH_NAME"); |
| 99 | String state = event.get("SWITCH_STATE"); |
| 100 | if (name != null && state != null) { |
| Mike Lockwood | 770126a | 2010-12-09 22:30:37 -0800 | [diff] [blame] | 101 | try { |
| Mike Lockwood | b92df0f | 2010-12-10 16:19:32 -0800 | [diff] [blame] | 102 | int intState = Integer.parseInt(state); |
| 103 | if ("usb_connected".equals(name)) { |
| 104 | mConnected = intState; |
| Mike Lockwood | 770126a | 2010-12-09 22:30:37 -0800 | [diff] [blame] | 105 | // trigger an Intent broadcast |
| 106 | if (mSystemReady) { |
| Mike Lockwood | b92df0f | 2010-12-10 16:19:32 -0800 | [diff] [blame] | 107 | // debounce disconnects |
| 108 | update(mConnected == 0); |
| 109 | } |
| 110 | } else if ("usb_configuration".equals(name)) { |
| 111 | mConfiguration = intState; |
| 112 | // trigger an Intent broadcast |
| 113 | if (mSystemReady) { |
| 114 | update(mConnected == 0); |
| Mike Lockwood | 770126a | 2010-12-09 22:30:37 -0800 | [diff] [blame] | 115 | } |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 116 | } |
| Mike Lockwood | 770126a | 2010-12-09 22:30:37 -0800 | [diff] [blame] | 117 | } catch (NumberFormatException e) { |
| 118 | Slog.e(TAG, "Could not parse switch state from event " + event); |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 119 | } |
| Mike Lockwood | 770126a | 2010-12-09 22:30:37 -0800 | [diff] [blame] | 120 | } else { |
| 121 | String function = event.get("FUNCTION"); |
| 122 | String enabledStr = event.get("ENABLED"); |
| 123 | if (function != null && enabledStr != null) { |
| 124 | // Note: we do not broadcast a change when a function is enabled or disabled. |
| 125 | // We just record the state change for the next broadcast. |
| 126 | boolean enabled = "1".equals(enabledStr); |
| 127 | if (enabled) { |
| 128 | if (!mEnabledFunctions.contains(function)) { |
| 129 | mEnabledFunctions.add(function); |
| 130 | } |
| 131 | mDisabledFunctions.remove(function); |
| 132 | } else { |
| 133 | if (!mDisabledFunctions.contains(function)) { |
| 134 | mDisabledFunctions.add(function); |
| 135 | } |
| 136 | mEnabledFunctions.remove(function); |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 137 | } |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | } |
| 141 | } |
| Mike Lockwood | 770126a | 2010-12-09 22:30:37 -0800 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | public UsbService(Context context) { |
| 145 | mContext = context; |
| 146 | init(); // set initial status |
| 147 | |
| David 'Digit' Turner | 49db853 | 2011-01-17 00:19:37 +0100 | [diff] [blame] | 148 | if (mConfiguration >= 0) { |
| 149 | mUEventObserver.startObserving(USB_CONNECTED_MATCH); |
| 150 | mUEventObserver.startObserving(USB_CONFIGURATION_MATCH); |
| 151 | mUEventObserver.startObserving(USB_FUNCTIONS_MATCH); |
| 152 | } |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 153 | } |
| Mike Lockwood | 770126a | 2010-12-09 22:30:37 -0800 | [diff] [blame] | 154 | |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 155 | private final void init() { |
| 156 | char[] buffer = new char[1024]; |
| 157 | |
| David 'Digit' Turner | 49db853 | 2011-01-17 00:19:37 +0100 | [diff] [blame] | 158 | mConfiguration = -1; |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 159 | try { |
| Mike Lockwood | b92df0f | 2010-12-10 16:19:32 -0800 | [diff] [blame] | 160 | FileReader file = new FileReader(USB_CONNECTED_PATH); |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 161 | int len = file.read(buffer, 0, 1024); |
| Brian Carlstrom | fd9ddd1 | 2010-11-04 11:24:58 -0700 | [diff] [blame] | 162 | file.close(); |
| Mike Lockwood | b92df0f | 2010-12-10 16:19:32 -0800 | [diff] [blame] | 163 | mConnected = Integer.valueOf((new String(buffer, 0, len)).trim()); |
| 164 | |
| 165 | file = new FileReader(USB_CONFIGURATION_PATH); |
| 166 | len = file.read(buffer, 0, 1024); |
| 167 | file.close(); |
| 168 | mConfiguration = Integer.valueOf((new String(buffer, 0, len)).trim()); |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 169 | |
| 170 | } catch (FileNotFoundException e) { |
| David 'Digit' Turner | 49db853 | 2011-01-17 00:19:37 +0100 | [diff] [blame] | 171 | Slog.i(TAG, "This kernel does not have USB configuration switch support"); |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 172 | } catch (Exception e) { |
| 173 | Slog.e(TAG, "" , e); |
| 174 | } |
| David 'Digit' Turner | 49db853 | 2011-01-17 00:19:37 +0100 | [diff] [blame] | 175 | if (mConfiguration < 0) |
| 176 | return; |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 177 | |
| 178 | try { |
| 179 | File[] files = new File(USB_COMPOSITE_CLASS_PATH).listFiles(); |
| 180 | for (int i = 0; i < files.length; i++) { |
| 181 | File file = new File(files[i], "enable"); |
| 182 | FileReader reader = new FileReader(file); |
| 183 | int len = reader.read(buffer, 0, 1024); |
| Brian Carlstrom | fd9ddd1 | 2010-11-04 11:24:58 -0700 | [diff] [blame] | 184 | reader.close(); |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 185 | int value = Integer.valueOf((new String(buffer, 0, len)).trim()); |
| 186 | String functionName = files[i].getName(); |
| 187 | if (value == 1) { |
| 188 | mEnabledFunctions.add(functionName); |
| 189 | } else { |
| 190 | mDisabledFunctions.add(functionName); |
| 191 | } |
| 192 | } |
| 193 | } catch (FileNotFoundException e) { |
| 194 | Slog.w(TAG, "This kernel does not have USB composite class support"); |
| 195 | } catch (Exception e) { |
| 196 | Slog.e(TAG, "" , e); |
| 197 | } |
| 198 | } |
| 199 | |
| Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 200 | // called from JNI in monitorUsbHostBus() |
| 201 | private void usbDeviceAdded(String deviceName, int vendorID, int productID, |
| 202 | int deviceClass, int deviceSubclass, int deviceProtocol, |
| 203 | /* array of quintuples containing id, class, subclass, protocol |
| 204 | and number of endpoints for each interface */ |
| 205 | int[] interfaceValues, |
| 206 | /* array of quadruples containing address, attributes, max packet size |
| 207 | and interval for each endpoint */ |
| 208 | int[] endpointValues) { |
| 209 | |
| 210 | // ignore hubs |
| 211 | if (deviceClass == UsbConstants.USB_CLASS_HUB) { |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | synchronized (mDevices) { |
| 216 | if (mDevices.get(deviceName) != null) { |
| 217 | Log.w(TAG, "device already on mDevices list: " + deviceName); |
| 218 | return; |
| 219 | } |
| 220 | |
| 221 | int numInterfaces = interfaceValues.length / 5; |
| 222 | Parcelable[] interfaces = new UsbInterface[numInterfaces]; |
| 223 | try { |
| 224 | // repackage interfaceValues as an array of UsbInterface |
| 225 | int intf, endp, ival = 0, eval = 0; |
| 226 | boolean hasGoodInterface = false; |
| 227 | for (intf = 0; intf < numInterfaces; intf++) { |
| 228 | int interfaceId = interfaceValues[ival++]; |
| 229 | int interfaceClass = interfaceValues[ival++]; |
| 230 | int interfaceSubclass = interfaceValues[ival++]; |
| 231 | int interfaceProtocol = interfaceValues[ival++]; |
| 232 | int numEndpoints = interfaceValues[ival++]; |
| 233 | |
| 234 | Parcelable[] endpoints = new UsbEndpoint[numEndpoints]; |
| 235 | for (endp = 0; endp < numEndpoints; endp++) { |
| 236 | int address = endpointValues[eval++]; |
| 237 | int attributes = endpointValues[eval++]; |
| 238 | int maxPacketSize = endpointValues[eval++]; |
| 239 | int interval = endpointValues[eval++]; |
| 240 | endpoints[endp] = new UsbEndpoint(address, attributes, |
| 241 | maxPacketSize, interval); |
| 242 | } |
| 243 | |
| 244 | if (interfaceClass != UsbConstants.USB_CLASS_HUB) { |
| 245 | hasGoodInterface = true; |
| 246 | } |
| 247 | interfaces[intf] = new UsbInterface(interfaceId, interfaceClass, |
| 248 | interfaceSubclass, interfaceProtocol, endpoints); |
| 249 | } |
| 250 | |
| 251 | if (!hasGoodInterface) { |
| 252 | return; |
| 253 | } |
| 254 | } catch (Exception e) { |
| 255 | // beware of index out of bound exceptions, which might happen if |
| 256 | // a device does not set bNumEndpoints correctly |
| 257 | Log.e(TAG, "error parsing USB descriptors", e); |
| 258 | return; |
| 259 | } |
| 260 | |
| 261 | UsbDevice device = new UsbDevice(deviceName, vendorID, productID, |
| 262 | deviceClass, deviceSubclass, deviceProtocol, interfaces); |
| 263 | mDevices.put(deviceName, device); |
| 264 | |
| 265 | Intent intent = new Intent(UsbManager.ACTION_USB_DEVICE_ATTACHED); |
| 266 | intent.putExtra(UsbManager.EXTRA_DEVICE_NAME, deviceName); |
| 267 | intent.putExtra(UsbManager.EXTRA_VENDOR_ID, vendorID); |
| 268 | intent.putExtra(UsbManager.EXTRA_PRODUCT_ID, productID); |
| 269 | intent.putExtra(UsbManager.EXTRA_DEVICE_CLASS, deviceClass); |
| 270 | intent.putExtra(UsbManager.EXTRA_DEVICE_SUBCLASS, deviceSubclass); |
| 271 | intent.putExtra(UsbManager.EXTRA_DEVICE_PROTOCOL, deviceProtocol); |
| 272 | intent.putExtra(UsbManager.EXTRA_DEVICE, device); |
| 273 | Log.d(TAG, "usbDeviceAdded, sending " + intent); |
| 274 | mContext.sendBroadcast(intent); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | // called from JNI in monitorUsbHostBus() |
| 279 | private void usbDeviceRemoved(String deviceName) { |
| 280 | synchronized (mDevices) { |
| 281 | UsbDevice device = mDevices.remove(deviceName); |
| 282 | if (device != null) { |
| 283 | Intent intent = new Intent(UsbManager.ACTION_USB_DEVICE_DETACHED); |
| 284 | intent.putExtra(UsbManager.EXTRA_DEVICE_NAME, deviceName); |
| 285 | Log.d(TAG, "usbDeviceRemoved, sending " + intent); |
| 286 | mContext.sendBroadcast(intent); |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
| Mike Lockwood | da39f0e | 2010-07-27 18:44:30 -0400 | [diff] [blame] | 291 | private void initHostSupport() { |
| Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 292 | // Create a thread to call into native code to wait for USB host events. |
| 293 | // This thread will call us back on usbDeviceAdded and usbDeviceRemoved. |
| 294 | Runnable runnable = new Runnable() { |
| 295 | public void run() { |
| 296 | monitorUsbHostBus(); |
| 297 | } |
| 298 | }; |
| 299 | new Thread(null, runnable, "UsbService host thread").start(); |
| Mike Lockwood | da39f0e | 2010-07-27 18:44:30 -0400 | [diff] [blame] | 300 | } |
| 301 | |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 302 | void systemReady() { |
| 303 | synchronized (this) { |
| Mike Lockwood | da39f0e | 2010-07-27 18:44:30 -0400 | [diff] [blame] | 304 | if (mContext.getResources().getBoolean( |
| 305 | com.android.internal.R.bool.config_hasUsbHostSupport)) { |
| 306 | // start monitoring for connected USB devices |
| 307 | initHostSupport(); |
| 308 | } |
| 309 | |
| Mike Lockwood | b92df0f | 2010-12-10 16:19:32 -0800 | [diff] [blame] | 310 | update(false); |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 311 | mSystemReady = true; |
| 312 | } |
| 313 | } |
| 314 | |
| Mike Lockwood | b92df0f | 2010-12-10 16:19:32 -0800 | [diff] [blame] | 315 | private final void update(boolean delayed) { |
| 316 | mHandler.removeMessages(MSG_UPDATE); |
| 317 | mHandler.sendEmptyMessageDelayed(MSG_UPDATE, delayed ? UPDATE_DELAY : 0); |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 318 | } |
| 319 | |
| Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 320 | /* Returns a list of all currently attached USB devices */ |
| 321 | public void getDeviceList(Bundle devices) { |
| 322 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_USB, null); |
| 323 | synchronized (mDevices) { |
| 324 | for (String name : mDevices.keySet()) { |
| 325 | devices.putParcelable(name, mDevices.get(name)); |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | public ParcelFileDescriptor openDevice(String deviceName) { |
| 331 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_USB, null); |
| 332 | return nativeOpenDevice(deviceName); |
| 333 | } |
| 334 | |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 335 | private final Handler mHandler = new Handler() { |
| Mike Lockwood | 709981e | 2010-06-28 09:58:58 -0400 | [diff] [blame] | 336 | private void addEnabledFunctions(Intent intent) { |
| 337 | // include state of all USB functions in our extras |
| 338 | for (int i = 0; i < mEnabledFunctions.size(); i++) { |
| Mike Lockwood | 770126a | 2010-12-09 22:30:37 -0800 | [diff] [blame] | 339 | intent.putExtra(mEnabledFunctions.get(i), UsbManager.USB_FUNCTION_ENABLED); |
| Mike Lockwood | 709981e | 2010-06-28 09:58:58 -0400 | [diff] [blame] | 340 | } |
| 341 | for (int i = 0; i < mDisabledFunctions.size(); i++) { |
| Mike Lockwood | 770126a | 2010-12-09 22:30:37 -0800 | [diff] [blame] | 342 | intent.putExtra(mDisabledFunctions.get(i), UsbManager.USB_FUNCTION_DISABLED); |
| Mike Lockwood | 709981e | 2010-06-28 09:58:58 -0400 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 346 | @Override |
| 347 | public void handleMessage(Message msg) { |
| 348 | switch (msg.what) { |
| 349 | case MSG_UPDATE: |
| 350 | synchronized (this) { |
| Mike Lockwood | b92df0f | 2010-12-10 16:19:32 -0800 | [diff] [blame] | 351 | if (mConnected != mLastConnected || mConfiguration != mLastConfiguration) { |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 352 | |
| Mike Lockwood | b92df0f | 2010-12-10 16:19:32 -0800 | [diff] [blame] | 353 | final ContentResolver cr = mContext.getContentResolver(); |
| 354 | if (Settings.Secure.getInt(cr, |
| 355 | Settings.Secure.DEVICE_PROVISIONED, 0) == 0) { |
| 356 | Slog.i(TAG, "Device not provisioned, skipping USB broadcast"); |
| 357 | return; |
| 358 | } |
| 359 | |
| 360 | mLastConnected = mConnected; |
| 361 | mLastConfiguration = mConfiguration; |
| 362 | |
| 363 | // send a sticky broadcast containing current USB state |
| 364 | Intent intent = new Intent(UsbManager.ACTION_USB_STATE); |
| 365 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
| 366 | intent.putExtra(UsbManager.USB_CONNECTED, mConnected != 0); |
| 367 | intent.putExtra(UsbManager.USB_CONFIGURATION, mConfiguration); |
| Mike Lockwood | 709981e | 2010-06-28 09:58:58 -0400 | [diff] [blame] | 368 | addEnabledFunctions(intent); |
| Mike Lockwood | b92df0f | 2010-12-10 16:19:32 -0800 | [diff] [blame] | 369 | mContext.sendStickyBroadcast(intent); |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 370 | } |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 371 | } |
| 372 | break; |
| 373 | } |
| 374 | } |
| 375 | }; |
| Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 376 | |
| 377 | private native void monitorUsbHostBus(); |
| 378 | private native ParcelFileDescriptor nativeOpenDevice(String deviceName); |
| Mike Lockwood | 2423607 | 2010-06-23 17:36:36 -0400 | [diff] [blame] | 379 | } |