Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 an |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.usb; |
| 18 | |
Mike Lockwood | 541c994 | 2011-06-12 19:35:45 -0400 | [diff] [blame] | 19 | import android.app.Notification; |
| 20 | import android.app.NotificationManager; |
Jeff Sharkey | fc3f24b | 2012-10-01 21:45:52 -0700 | [diff] [blame] | 21 | import android.app.PendingIntent; |
Mike Lockwood | d462ecf | 2011-07-21 13:55:16 -0700 | [diff] [blame] | 22 | import android.content.BroadcastReceiver; |
Mike Lockwood | 541c994 | 2011-06-12 19:35:45 -0400 | [diff] [blame] | 23 | import android.content.ComponentName; |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 24 | import android.content.ContentResolver; |
| 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
| 27 | import android.content.IntentFilter; |
| 28 | import android.content.pm.PackageManager; |
Mike Lockwood | 541c994 | 2011-06-12 19:35:45 -0400 | [diff] [blame] | 29 | import android.content.res.Resources; |
| 30 | import android.database.ContentObserver; |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 31 | import android.hardware.usb.UsbAccessory; |
| 32 | import android.hardware.usb.UsbManager; |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 33 | import android.os.FileUtils; |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 34 | import android.os.Handler; |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 35 | import android.os.Looper; |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 36 | import android.os.Message; |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 37 | import android.os.ParcelFileDescriptor; |
RoboErik | dab2072 | 2012-03-07 17:53:36 -0800 | [diff] [blame] | 38 | import android.os.SystemClock; |
Mike Lockwood | 541c994 | 2011-06-12 19:35:45 -0400 | [diff] [blame] | 39 | import android.os.SystemProperties; |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 40 | import android.os.UEventObserver; |
Jeff Sharkey | fc3f24b | 2012-10-01 21:45:52 -0700 | [diff] [blame] | 41 | import android.os.UserHandle; |
| 42 | import android.os.storage.StorageManager; |
| 43 | import android.os.storage.StorageVolume; |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 44 | import android.provider.Settings; |
Kazuhiro Ondo | afd8f18 | 2012-02-06 17:35:50 -0600 | [diff] [blame] | 45 | import android.util.Pair; |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 46 | import android.util.Slog; |
| 47 | |
Jeff Sharkey | 8b2c3a14 | 2012-11-12 11:45:05 -0800 | [diff] [blame] | 48 | import com.android.internal.annotations.GuardedBy; |
Dianne Hackborn | 8d044e8 | 2013-04-30 17:24:15 -0700 | [diff] [blame] | 49 | import com.android.server.FgThread; |
Jeff Sharkey | 8b2c3a14 | 2012-11-12 11:45:05 -0800 | [diff] [blame] | 50 | |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 51 | import java.io.File; |
| 52 | import java.io.FileDescriptor; |
| 53 | import java.io.FileNotFoundException; |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 54 | import java.io.IOException; |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 55 | import java.io.PrintWriter; |
Jeff Sharkey | fc3f24b | 2012-10-01 21:45:52 -0700 | [diff] [blame] | 56 | import java.util.HashMap; |
Kazuhiro Ondo | afd8f18 | 2012-02-06 17:35:50 -0600 | [diff] [blame] | 57 | import java.util.LinkedList; |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 58 | import java.util.List; |
Jeff Sharkey | fea17de | 2013-06-11 14:13:09 -0700 | [diff] [blame] | 59 | import java.util.Locale; |
Kazuhiro Ondo | afd8f18 | 2012-02-06 17:35:50 -0600 | [diff] [blame] | 60 | import java.util.Map; |
Mike Lockwood | 9d5a4be | 2012-04-06 09:41:32 -0700 | [diff] [blame] | 61 | import java.util.Scanner; |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * UsbDeviceManager manages USB state in device mode. |
| 65 | */ |
| 66 | public class UsbDeviceManager { |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 67 | |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 68 | private static final String TAG = UsbDeviceManager.class.getSimpleName(); |
Mike Lockwood | fdc0c29 | 2011-07-01 11:17:43 -0400 | [diff] [blame] | 69 | private static final boolean DEBUG = false; |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 70 | |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 71 | private static final String USB_STATE_MATCH = |
| 72 | "DEVPATH=/devices/virtual/android_usb/android0"; |
| 73 | private static final String ACCESSORY_START_MATCH = |
| 74 | "DEVPATH=/devices/virtual/misc/usb_accessory"; |
| 75 | private static final String FUNCTIONS_PATH = |
| 76 | "/sys/class/android_usb/android0/functions"; |
| 77 | private static final String STATE_PATH = |
| 78 | "/sys/class/android_usb/android0/state"; |
| 79 | private static final String MASS_STORAGE_FILE_PATH = |
Mike Lockwood | 629b149 | 2011-07-06 12:47:21 -0400 | [diff] [blame] | 80 | "/sys/class/android_usb/android0/f_mass_storage/lun/file"; |
| 81 | private static final String RNDIS_ETH_ADDR_PATH = |
| 82 | "/sys/class/android_usb/android0/f_rndis/ethaddr"; |
Mike Lockwood | 9d5a4be | 2012-04-06 09:41:32 -0700 | [diff] [blame] | 83 | private static final String AUDIO_SOURCE_PCM_PATH = |
| 84 | "/sys/class/android_usb/android0/f_audio_source/pcm"; |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 85 | |
| 86 | private static final int MSG_UPDATE_STATE = 0; |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 87 | private static final int MSG_ENABLE_ADB = 1; |
Mike Lockwood | 166b05e | 2012-04-24 10:45:18 -0700 | [diff] [blame] | 88 | private static final int MSG_SET_CURRENT_FUNCTIONS = 2; |
Mike Lockwood | f59717d | 2011-06-22 15:19:33 -0400 | [diff] [blame] | 89 | private static final int MSG_SYSTEM_READY = 3; |
Mike Lockwood | d462ecf | 2011-07-21 13:55:16 -0700 | [diff] [blame] | 90 | private static final int MSG_BOOT_COMPLETED = 4; |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 91 | private static final int MSG_USER_SWITCHED = 5; |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 92 | |
Mike Lockwood | 166b05e | 2012-04-24 10:45:18 -0700 | [diff] [blame] | 93 | private static final int AUDIO_MODE_NONE = 0; |
| 94 | private static final int AUDIO_MODE_SOURCE = 1; |
| 95 | |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 96 | // Delay for debouncing USB disconnects. |
| 97 | // We often get rapid connect/disconnect events when enabling USB functions, |
| 98 | // which need debouncing. |
| 99 | private static final int UPDATE_DELAY = 1000; |
| 100 | |
Kazuhiro Ondo | afd8f18 | 2012-02-06 17:35:50 -0600 | [diff] [blame] | 101 | private static final String BOOT_MODE_PROPERTY = "ro.bootmode"; |
| 102 | |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 103 | private UsbHandler mHandler; |
Mike Lockwood | d462ecf | 2011-07-21 13:55:16 -0700 | [diff] [blame] | 104 | private boolean mBootCompleted; |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 105 | |
Jeff Sharkey | fc3f24b | 2012-10-01 21:45:52 -0700 | [diff] [blame] | 106 | private final Object mLock = new Object(); |
| 107 | |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 108 | private final Context mContext; |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 109 | private final ContentResolver mContentResolver; |
Jeff Sharkey | 8b2c3a14 | 2012-11-12 11:45:05 -0800 | [diff] [blame] | 110 | @GuardedBy("mLock") |
Jeff Sharkey | fc3f24b | 2012-10-01 21:45:52 -0700 | [diff] [blame] | 111 | private UsbSettingsManager mCurrentSettings; |
Mike Lockwood | 541c994 | 2011-06-12 19:35:45 -0400 | [diff] [blame] | 112 | private NotificationManager mNotificationManager; |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 113 | private final boolean mHasUsbAccessory; |
Mike Lockwood | 5787a2d | 2011-06-17 12:21:39 -0400 | [diff] [blame] | 114 | private boolean mUseUsbNotification; |
Mike Lockwood | 541c994 | 2011-06-12 19:35:45 -0400 | [diff] [blame] | 115 | private boolean mAdbEnabled; |
Mike Lockwood | 9d5a4be | 2012-04-06 09:41:32 -0700 | [diff] [blame] | 116 | private boolean mAudioSourceEnabled; |
Kazuhiro Ondo | afd8f18 | 2012-02-06 17:35:50 -0600 | [diff] [blame] | 117 | private Map<String, List<Pair<String, String>>> mOemModeMap; |
Mike Lockwood | 166b05e | 2012-04-24 10:45:18 -0700 | [diff] [blame] | 118 | private String[] mAccessoryStrings; |
Benoit Goby | 4e68bd4 | 2012-04-25 18:06:00 -0700 | [diff] [blame] | 119 | private UsbDebuggingManager mDebuggingManager; |
Mike Lockwood | 541c994 | 2011-06-12 19:35:45 -0400 | [diff] [blame] | 120 | |
| 121 | private class AdbSettingsObserver extends ContentObserver { |
| 122 | public AdbSettingsObserver() { |
| 123 | super(null); |
| 124 | } |
| 125 | @Override |
| 126 | public void onChange(boolean selfChange) { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 127 | boolean enable = (Settings.Global.getInt(mContentResolver, |
| 128 | Settings.Global.ADB_ENABLED, 0) > 0); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 129 | mHandler.sendMessage(MSG_ENABLE_ADB, enable); |
Mike Lockwood | 541c994 | 2011-06-12 19:35:45 -0400 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 133 | /* |
| 134 | * Listens for uevent messages from the kernel to monitor the USB state |
| 135 | */ |
| 136 | private final UEventObserver mUEventObserver = new UEventObserver() { |
| 137 | @Override |
| 138 | public void onUEvent(UEventObserver.UEvent event) { |
Mike Lockwood | fdc0c29 | 2011-07-01 11:17:43 -0400 | [diff] [blame] | 139 | if (DEBUG) Slog.v(TAG, "USB UEVENT: " + event.toString()); |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 140 | |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 141 | String state = event.get("USB_STATE"); |
| 142 | String accessory = event.get("ACCESSORY"); |
| 143 | if (state != null) { |
| 144 | mHandler.updateState(state); |
| 145 | } else if ("START".equals(accessory)) { |
Mike Lockwood | fdc0c29 | 2011-07-01 11:17:43 -0400 | [diff] [blame] | 146 | if (DEBUG) Slog.d(TAG, "got accessory start"); |
Mike Lockwood | 166b05e | 2012-04-24 10:45:18 -0700 | [diff] [blame] | 147 | startAccessoryMode(); |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | }; |
| 151 | |
Jeff Sharkey | fc3f24b | 2012-10-01 21:45:52 -0700 | [diff] [blame] | 152 | public UsbDeviceManager(Context context) { |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 153 | mContext = context; |
Mike Lockwood | 541c994 | 2011-06-12 19:35:45 -0400 | [diff] [blame] | 154 | mContentResolver = context.getContentResolver(); |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 155 | PackageManager pm = mContext.getPackageManager(); |
| 156 | mHasUsbAccessory = pm.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY); |
Mike Lockwood | 629b149 | 2011-07-06 12:47:21 -0400 | [diff] [blame] | 157 | initRndisAddress(); |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 158 | |
Kazuhiro Ondo | afd8f18 | 2012-02-06 17:35:50 -0600 | [diff] [blame] | 159 | readOemUsbOverrideConfig(); |
| 160 | |
Dianne Hackborn | 8d044e8 | 2013-04-30 17:24:15 -0700 | [diff] [blame] | 161 | mHandler = new UsbHandler(FgThread.get().getLooper()); |
Mike Lockwood | d462ecf | 2011-07-21 13:55:16 -0700 | [diff] [blame] | 162 | |
| 163 | if (nativeIsStartRequested()) { |
| 164 | if (DEBUG) Slog.d(TAG, "accessory attached at boot"); |
Mike Lockwood | 166b05e | 2012-04-24 10:45:18 -0700 | [diff] [blame] | 165 | startAccessoryMode(); |
Mike Lockwood | d462ecf | 2011-07-21 13:55:16 -0700 | [diff] [blame] | 166 | } |
Benoit Goby | 4e68bd4 | 2012-04-25 18:06:00 -0700 | [diff] [blame] | 167 | |
Benoit Goby | 78a9687 | 2013-01-25 16:58:13 -0800 | [diff] [blame] | 168 | boolean secureAdbEnabled = SystemProperties.getBoolean("ro.adb.secure", false); |
| 169 | boolean dataEncrypted = "1".equals(SystemProperties.get("vold.decrypt")); |
| 170 | if (secureAdbEnabled && !dataEncrypted) { |
Benoit Goby | 4e68bd4 | 2012-04-25 18:06:00 -0700 | [diff] [blame] | 171 | mDebuggingManager = new UsbDebuggingManager(context); |
| 172 | } |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 173 | } |
| 174 | |
Jeff Sharkey | fc3f24b | 2012-10-01 21:45:52 -0700 | [diff] [blame] | 175 | public void setCurrentSettings(UsbSettingsManager settings) { |
| 176 | synchronized (mLock) { |
| 177 | mCurrentSettings = settings; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | private UsbSettingsManager getCurrentSettings() { |
| 182 | synchronized (mLock) { |
| 183 | return mCurrentSettings; |
| 184 | } |
| 185 | } |
| 186 | |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 187 | public void systemReady() { |
Mike Lockwood | d462ecf | 2011-07-21 13:55:16 -0700 | [diff] [blame] | 188 | if (DEBUG) Slog.d(TAG, "systemReady"); |
Mike Lockwood | 541c994 | 2011-06-12 19:35:45 -0400 | [diff] [blame] | 189 | |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 190 | mNotificationManager = (NotificationManager) |
| 191 | mContext.getSystemService(Context.NOTIFICATION_SERVICE); |
| 192 | |
Mike Lockwood | 5787a2d | 2011-06-17 12:21:39 -0400 | [diff] [blame] | 193 | // We do not show the USB notification if the primary volume supports mass storage. |
| 194 | // The legacy mass storage UI will be used instead. |
| 195 | boolean massStorageSupported = false; |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 196 | final StorageManager storageManager = StorageManager.from(mContext); |
| 197 | final StorageVolume primary = storageManager.getPrimaryVolume(); |
| 198 | massStorageSupported = primary != null && primary.allowMassStorage(); |
Mike Lockwood | 5787a2d | 2011-06-17 12:21:39 -0400 | [diff] [blame] | 199 | mUseUsbNotification = !massStorageSupported; |
| 200 | |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 201 | // make sure the ADB_ENABLED setting value matches the current state |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 202 | Settings.Global.putInt(mContentResolver, Settings.Global.ADB_ENABLED, mAdbEnabled ? 1 : 0); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 203 | |
| 204 | mHandler.sendEmptyMessage(MSG_SYSTEM_READY); |
| 205 | } |
| 206 | |
Mike Lockwood | 166b05e | 2012-04-24 10:45:18 -0700 | [diff] [blame] | 207 | private void startAccessoryMode() { |
| 208 | mAccessoryStrings = nativeGetAccessoryStrings(); |
| 209 | boolean enableAudio = (nativeGetAudioMode() == AUDIO_MODE_SOURCE); |
| 210 | // don't start accessory mode if our mandatory strings have not been set |
| 211 | boolean enableAccessory = (mAccessoryStrings != null && |
| 212 | mAccessoryStrings[UsbAccessory.MANUFACTURER_STRING] != null && |
| 213 | mAccessoryStrings[UsbAccessory.MODEL_STRING] != null); |
| 214 | String functions = null; |
| 215 | |
| 216 | if (enableAccessory && enableAudio) { |
| 217 | functions = UsbManager.USB_FUNCTION_ACCESSORY + "," |
| 218 | + UsbManager.USB_FUNCTION_AUDIO_SOURCE; |
| 219 | } else if (enableAccessory) { |
| 220 | functions = UsbManager.USB_FUNCTION_ACCESSORY; |
| 221 | } else if (enableAudio) { |
| 222 | functions = UsbManager.USB_FUNCTION_AUDIO_SOURCE; |
| 223 | } |
| 224 | |
| 225 | if (functions != null) { |
| 226 | setCurrentFunctions(functions, false); |
| 227 | } |
| 228 | } |
| 229 | |
Mike Lockwood | 629b149 | 2011-07-06 12:47:21 -0400 | [diff] [blame] | 230 | private static void initRndisAddress() { |
| 231 | // configure RNDIS ethernet address based on our serial number using the same algorithm |
| 232 | // we had been previously using in kernel board files |
| 233 | final int ETH_ALEN = 6; |
| 234 | int address[] = new int[ETH_ALEN]; |
| 235 | // first byte is 0x02 to signify a locally administered address |
| 236 | address[0] = 0x02; |
| 237 | |
| 238 | String serial = SystemProperties.get("ro.serialno", "1234567890ABCDEF"); |
| 239 | int serialLength = serial.length(); |
| 240 | // XOR the USB serial across the remaining 5 bytes |
| 241 | for (int i = 0; i < serialLength; i++) { |
| 242 | address[i % (ETH_ALEN - 1) + 1] ^= (int)serial.charAt(i); |
| 243 | } |
Jeff Sharkey | fea17de | 2013-06-11 14:13:09 -0700 | [diff] [blame] | 244 | String addrString = String.format(Locale.US, "%02X:%02X:%02X:%02X:%02X:%02X", |
Mike Lockwood | 629b149 | 2011-07-06 12:47:21 -0400 | [diff] [blame] | 245 | address[0], address[1], address[2], address[3], address[4], address[5]); |
| 246 | try { |
| 247 | FileUtils.stringToFile(RNDIS_ETH_ADDR_PATH, addrString); |
| 248 | } catch (IOException e) { |
| 249 | Slog.e(TAG, "failed to write to " + RNDIS_ETH_ADDR_PATH); |
| 250 | } |
| 251 | } |
| 252 | |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 253 | private static String addFunction(String functions, String function) { |
RoboErik | dab2072 | 2012-03-07 17:53:36 -0800 | [diff] [blame] | 254 | if ("none".equals(functions)) { |
| 255 | return function; |
| 256 | } |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 257 | if (!containsFunction(functions, function)) { |
| 258 | if (functions.length() > 0) { |
| 259 | functions += ","; |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 260 | } |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 261 | functions += function; |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 262 | } |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 263 | return functions; |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 264 | } |
| 265 | |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 266 | private static String removeFunction(String functions, String function) { |
| 267 | String[] split = functions.split(","); |
| 268 | for (int i = 0; i < split.length; i++) { |
| 269 | if (function.equals(split[i])) { |
| 270 | split[i] = null; |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 271 | } |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 272 | } |
RoboErik | dab2072 | 2012-03-07 17:53:36 -0800 | [diff] [blame] | 273 | if (split.length == 1 && split[0] == null) { |
| 274 | return "none"; |
| 275 | } |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 276 | StringBuilder builder = new StringBuilder(); |
| 277 | for (int i = 0; i < split.length; i++) { |
| 278 | String s = split[i]; |
| 279 | if (s != null) { |
| 280 | if (builder.length() > 0) { |
| 281 | builder.append(","); |
| 282 | } |
| 283 | builder.append(s); |
| 284 | } |
| 285 | } |
| 286 | return builder.toString(); |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 287 | } |
| 288 | |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 289 | private static boolean containsFunction(String functions, String function) { |
| 290 | int index = functions.indexOf(function); |
| 291 | if (index < 0) return false; |
| 292 | if (index > 0 && functions.charAt(index - 1) != ',') return false; |
| 293 | int charAfter = index + function.length(); |
| 294 | if (charAfter < functions.length() && functions.charAt(charAfter) != ',') return false; |
| 295 | return true; |
| 296 | } |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 297 | |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 298 | private final class UsbHandler extends Handler { |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 299 | |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 300 | // current USB state |
| 301 | private boolean mConnected; |
| 302 | private boolean mConfigured; |
| 303 | private String mCurrentFunctions; |
| 304 | private String mDefaultFunctions; |
| 305 | private UsbAccessory mCurrentAccessory; |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 306 | private int mUsbNotificationId; |
| 307 | private boolean mAdbNotificationShown; |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 308 | private int mCurrentUser = UserHandle.USER_NULL; |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 309 | |
Mike Lockwood | d462ecf | 2011-07-21 13:55:16 -0700 | [diff] [blame] | 310 | private final BroadcastReceiver mBootCompletedReceiver = new BroadcastReceiver() { |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 311 | @Override |
Mike Lockwood | d462ecf | 2011-07-21 13:55:16 -0700 | [diff] [blame] | 312 | public void onReceive(Context context, Intent intent) { |
| 313 | if (DEBUG) Slog.d(TAG, "boot completed"); |
| 314 | mHandler.sendEmptyMessage(MSG_BOOT_COMPLETED); |
| 315 | } |
| 316 | }; |
| 317 | |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 318 | private final BroadcastReceiver mUserSwitchedReceiver = new BroadcastReceiver() { |
| 319 | @Override |
| 320 | public void onReceive(Context context, Intent intent) { |
| 321 | final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1); |
| 322 | mHandler.obtainMessage(MSG_USER_SWITCHED, userId, 0).sendToTarget(); |
| 323 | } |
| 324 | }; |
| 325 | |
Mike Lockwood | 3fd13eb | 2011-07-13 09:23:45 -0400 | [diff] [blame] | 326 | public UsbHandler(Looper looper) { |
| 327 | super(looper); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 328 | try { |
Mike Lockwood | c264afeb5 | 2011-07-10 11:48:18 -0400 | [diff] [blame] | 329 | // persist.sys.usb.config should never be unset. But if it is, set it to "adb" |
| 330 | // so we have a chance of debugging what happened. |
| 331 | mDefaultFunctions = SystemProperties.get("persist.sys.usb.config", "adb"); |
Kazuhiro Ondo | afd8f18 | 2012-02-06 17:35:50 -0600 | [diff] [blame] | 332 | |
| 333 | // Check if USB mode needs to be overridden depending on OEM specific bootmode. |
| 334 | mDefaultFunctions = processOemUsbOverride(mDefaultFunctions); |
| 335 | |
Mike Lockwood | de296f6 | 2011-07-01 14:05:25 -0400 | [diff] [blame] | 336 | // sanity check the sys.usb.config system property |
| 337 | // this may be necessary if we crashed while switching USB configurations |
| 338 | String config = SystemProperties.get("sys.usb.config", "none"); |
Mike Lockwood | c264afeb5 | 2011-07-10 11:48:18 -0400 | [diff] [blame] | 339 | if (!config.equals(mDefaultFunctions)) { |
| 340 | Slog.w(TAG, "resetting config to persistent property: " + mDefaultFunctions); |
| 341 | SystemProperties.set("sys.usb.config", mDefaultFunctions); |
Mike Lockwood | de296f6 | 2011-07-01 14:05:25 -0400 | [diff] [blame] | 342 | } |
| 343 | |
Mike Lockwood | c264afeb5 | 2011-07-10 11:48:18 -0400 | [diff] [blame] | 344 | mCurrentFunctions = mDefaultFunctions; |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 345 | String state = FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim(); |
| 346 | updateState(state); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 347 | mAdbEnabled = containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ADB); |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 348 | |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 349 | // Upgrade step for previous versions that used persist.service.adb.enable |
| 350 | String value = SystemProperties.get("persist.service.adb.enable", ""); |
| 351 | if (value.length() > 0) { |
| 352 | char enable = value.charAt(0); |
| 353 | if (enable == '1') { |
| 354 | setAdbEnabled(true); |
| 355 | } else if (enable == '0') { |
| 356 | setAdbEnabled(false); |
| 357 | } |
| 358 | SystemProperties.set("persist.service.adb.enable", ""); |
| 359 | } |
| 360 | |
| 361 | // register observer to listen for settings changes |
| 362 | mContentResolver.registerContentObserver( |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 363 | Settings.Global.getUriFor(Settings.Global.ADB_ENABLED), |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 364 | false, new AdbSettingsObserver()); |
| 365 | |
| 366 | // Watch for USB configuration changes |
| 367 | mUEventObserver.startObserving(USB_STATE_MATCH); |
| 368 | mUEventObserver.startObserving(ACCESSORY_START_MATCH); |
Mike Lockwood | d462ecf | 2011-07-21 13:55:16 -0700 | [diff] [blame] | 369 | |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 370 | mContext.registerReceiver( |
| 371 | mBootCompletedReceiver, new IntentFilter(Intent.ACTION_BOOT_COMPLETED)); |
| 372 | mContext.registerReceiver( |
| 373 | mUserSwitchedReceiver, new IntentFilter(Intent.ACTION_USER_SWITCHED)); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 374 | } catch (Exception e) { |
| 375 | Slog.e(TAG, "Error initializing UsbHandler", e); |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | public void sendMessage(int what, boolean arg) { |
| 380 | removeMessages(what); |
| 381 | Message m = Message.obtain(this, what); |
| 382 | m.arg1 = (arg ? 1 : 0); |
| 383 | sendMessage(m); |
| 384 | } |
| 385 | |
| 386 | public void sendMessage(int what, Object arg) { |
| 387 | removeMessages(what); |
| 388 | Message m = Message.obtain(this, what); |
| 389 | m.obj = arg; |
| 390 | sendMessage(m); |
| 391 | } |
| 392 | |
Mike Lockwood | f59717d | 2011-06-22 15:19:33 -0400 | [diff] [blame] | 393 | public void sendMessage(int what, Object arg0, boolean arg1) { |
| 394 | removeMessages(what); |
| 395 | Message m = Message.obtain(this, what); |
| 396 | m.obj = arg0; |
| 397 | m.arg1 = (arg1 ? 1 : 0); |
| 398 | sendMessage(m); |
| 399 | } |
| 400 | |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 401 | public void updateState(String state) { |
| 402 | int connected, configured; |
| 403 | |
| 404 | if ("DISCONNECTED".equals(state)) { |
| 405 | connected = 0; |
| 406 | configured = 0; |
| 407 | } else if ("CONNECTED".equals(state)) { |
| 408 | connected = 1; |
| 409 | configured = 0; |
| 410 | } else if ("CONFIGURED".equals(state)) { |
| 411 | connected = 1; |
| 412 | configured = 1; |
| 413 | } else { |
| 414 | Slog.e(TAG, "unknown state " + state); |
| 415 | return; |
| 416 | } |
| 417 | removeMessages(MSG_UPDATE_STATE); |
| 418 | Message msg = Message.obtain(this, MSG_UPDATE_STATE); |
| 419 | msg.arg1 = connected; |
| 420 | msg.arg2 = configured; |
| 421 | // debounce disconnects to avoid problems bringing up USB tethering |
| 422 | sendMessageDelayed(msg, (connected == 0) ? UPDATE_DELAY : 0); |
| 423 | } |
| 424 | |
Mike Lockwood | f59717d | 2011-06-22 15:19:33 -0400 | [diff] [blame] | 425 | private boolean waitForState(String state) { |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 426 | // wait for the transition to complete. |
| 427 | // give up after 1 second. |
| 428 | for (int i = 0; i < 20; i++) { |
Mike Lockwood | 68736cb | 2011-07-29 11:32:28 -0400 | [diff] [blame] | 429 | // State transition is done when sys.usb.state is set to the new configuration |
Mike Lockwood | f59717d | 2011-06-22 15:19:33 -0400 | [diff] [blame] | 430 | if (state.equals(SystemProperties.get("sys.usb.state"))) return true; |
RoboErik | dab2072 | 2012-03-07 17:53:36 -0800 | [diff] [blame] | 431 | SystemClock.sleep(50); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 432 | } |
Mike Lockwood | fdc0c29 | 2011-07-01 11:17:43 -0400 | [diff] [blame] | 433 | Slog.e(TAG, "waitForState(" + state + ") FAILED"); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 434 | return false; |
| 435 | } |
| 436 | |
Mike Lockwood | f59717d | 2011-06-22 15:19:33 -0400 | [diff] [blame] | 437 | private boolean setUsbConfig(String config) { |
Mike Lockwood | fdc0c29 | 2011-07-01 11:17:43 -0400 | [diff] [blame] | 438 | if (DEBUG) Slog.d(TAG, "setUsbConfig(" + config + ")"); |
Mike Lockwood | f59717d | 2011-06-22 15:19:33 -0400 | [diff] [blame] | 439 | // set the new configuration |
| 440 | SystemProperties.set("sys.usb.config", config); |
| 441 | return waitForState(config); |
| 442 | } |
| 443 | |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 444 | private void setAdbEnabled(boolean enable) { |
Mike Lockwood | de296f6 | 2011-07-01 14:05:25 -0400 | [diff] [blame] | 445 | if (DEBUG) Slog.d(TAG, "setAdbEnabled: " + enable); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 446 | if (enable != mAdbEnabled) { |
| 447 | mAdbEnabled = enable; |
Mike Lockwood | f59717d | 2011-06-22 15:19:33 -0400 | [diff] [blame] | 448 | // Due to the persist.sys.usb.config property trigger, changing adb state requires |
| 449 | // switching to default function |
Mike Lockwood | 1984e79 | 2011-08-03 17:10:43 -0400 | [diff] [blame] | 450 | setEnabledFunctions(mDefaultFunctions, true); |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 451 | updateAdbNotification(); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 452 | } |
Benoit Goby | 4e68bd4 | 2012-04-25 18:06:00 -0700 | [diff] [blame] | 453 | if (mDebuggingManager != null) { |
| 454 | mDebuggingManager.setAdbEnabled(mAdbEnabled); |
| 455 | } |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 456 | } |
| 457 | |
Mike Lockwood | 68736cb | 2011-07-29 11:32:28 -0400 | [diff] [blame] | 458 | private void setEnabledFunctions(String functions, boolean makeDefault) { |
Kazuhiro Ondo | afd8f18 | 2012-02-06 17:35:50 -0600 | [diff] [blame] | 459 | |
| 460 | // Do not update persystent.sys.usb.config if the device is booted up |
| 461 | // with OEM specific mode. |
| 462 | if (functions != null && makeDefault && !needsOemUsbOverride()) { |
| 463 | |
Mike Lockwood | 8b4d36e | 2011-08-02 18:16:26 -0400 | [diff] [blame] | 464 | if (mAdbEnabled) { |
| 465 | functions = addFunction(functions, UsbManager.USB_FUNCTION_ADB); |
| 466 | } else { |
| 467 | functions = removeFunction(functions, UsbManager.USB_FUNCTION_ADB); |
| 468 | } |
Mike Lockwood | 68736cb | 2011-07-29 11:32:28 -0400 | [diff] [blame] | 469 | if (!mDefaultFunctions.equals(functions)) { |
| 470 | if (!setUsbConfig("none")) { |
| 471 | Slog.e(TAG, "Failed to disable USB"); |
| 472 | // revert to previous configuration if we fail |
| 473 | setUsbConfig(mCurrentFunctions); |
| 474 | return; |
| 475 | } |
| 476 | // setting this property will also change the current USB state |
| 477 | // via a property trigger |
| 478 | SystemProperties.set("persist.sys.usb.config", functions); |
| 479 | if (waitForState(functions)) { |
| 480 | mCurrentFunctions = functions; |
| 481 | mDefaultFunctions = functions; |
| 482 | } else { |
| 483 | Slog.e(TAG, "Failed to switch persistent USB config to " + functions); |
| 484 | // revert to previous configuration if we fail |
| 485 | SystemProperties.set("persist.sys.usb.config", mDefaultFunctions); |
| 486 | } |
| 487 | } |
| 488 | } else { |
| 489 | if (functions == null) { |
| 490 | functions = mDefaultFunctions; |
| 491 | } |
Kazuhiro Ondo | afd8f18 | 2012-02-06 17:35:50 -0600 | [diff] [blame] | 492 | |
| 493 | // Override with bootmode specific usb mode if needed |
| 494 | functions = processOemUsbOverride(functions); |
| 495 | |
Mike Lockwood | 8b4d36e | 2011-08-02 18:16:26 -0400 | [diff] [blame] | 496 | if (mAdbEnabled) { |
| 497 | functions = addFunction(functions, UsbManager.USB_FUNCTION_ADB); |
| 498 | } else { |
| 499 | functions = removeFunction(functions, UsbManager.USB_FUNCTION_ADB); |
| 500 | } |
Mike Lockwood | 68736cb | 2011-07-29 11:32:28 -0400 | [diff] [blame] | 501 | if (!mCurrentFunctions.equals(functions)) { |
| 502 | if (!setUsbConfig("none")) { |
| 503 | Slog.e(TAG, "Failed to disable USB"); |
| 504 | // revert to previous configuration if we fail |
| 505 | setUsbConfig(mCurrentFunctions); |
| 506 | return; |
| 507 | } |
| 508 | if (setUsbConfig(functions)) { |
| 509 | mCurrentFunctions = functions; |
| 510 | } else { |
| 511 | Slog.e(TAG, "Failed to switch USB config to " + functions); |
| 512 | // revert to previous configuration if we fail |
| 513 | setUsbConfig(mCurrentFunctions); |
| 514 | } |
| 515 | } |
| 516 | } |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | private void updateCurrentAccessory() { |
| 520 | if (!mHasUsbAccessory) return; |
| 521 | |
| 522 | if (mConfigured) { |
Mike Lockwood | 166b05e | 2012-04-24 10:45:18 -0700 | [diff] [blame] | 523 | if (mAccessoryStrings != null) { |
| 524 | mCurrentAccessory = new UsbAccessory(mAccessoryStrings); |
Mike Lockwood | fdc0c29 | 2011-07-01 11:17:43 -0400 | [diff] [blame] | 525 | Slog.d(TAG, "entering USB accessory mode: " + mCurrentAccessory); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 526 | // defer accessoryAttached if system is not ready |
Mike Lockwood | d462ecf | 2011-07-21 13:55:16 -0700 | [diff] [blame] | 527 | if (mBootCompleted) { |
Jeff Sharkey | fc3f24b | 2012-10-01 21:45:52 -0700 | [diff] [blame] | 528 | getCurrentSettings().accessoryAttached(mCurrentAccessory); |
Mike Lockwood | d462ecf | 2011-07-21 13:55:16 -0700 | [diff] [blame] | 529 | } // else handle in mBootCompletedReceiver |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 530 | } else { |
Mike Lockwood | fdc0c29 | 2011-07-01 11:17:43 -0400 | [diff] [blame] | 531 | Slog.e(TAG, "nativeGetAccessoryStrings failed"); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 532 | } |
| 533 | } else if (!mConnected) { |
| 534 | // make sure accessory mode is off |
| 535 | // and restore default functions |
Mike Lockwood | fdc0c29 | 2011-07-01 11:17:43 -0400 | [diff] [blame] | 536 | Slog.d(TAG, "exited USB accessory mode"); |
Mike Lockwood | 68736cb | 2011-07-29 11:32:28 -0400 | [diff] [blame] | 537 | setEnabledFunctions(mDefaultFunctions, false); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 538 | |
| 539 | if (mCurrentAccessory != null) { |
Mike Lockwood | d462ecf | 2011-07-21 13:55:16 -0700 | [diff] [blame] | 540 | if (mBootCompleted) { |
Jeff Sharkey | fc3f24b | 2012-10-01 21:45:52 -0700 | [diff] [blame] | 541 | getCurrentSettings().accessoryDetached(mCurrentAccessory); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 542 | } |
| 543 | mCurrentAccessory = null; |
Mike Lockwood | 166b05e | 2012-04-24 10:45:18 -0700 | [diff] [blame] | 544 | mAccessoryStrings = null; |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 545 | } |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | private void updateUsbState() { |
| 550 | // send a sticky broadcast containing current USB state |
| 551 | Intent intent = new Intent(UsbManager.ACTION_USB_STATE); |
| 552 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
| 553 | intent.putExtra(UsbManager.USB_CONNECTED, mConnected); |
| 554 | intent.putExtra(UsbManager.USB_CONFIGURED, mConfigured); |
| 555 | |
| 556 | if (mCurrentFunctions != null) { |
| 557 | String[] functions = mCurrentFunctions.split(","); |
| 558 | for (int i = 0; i < functions.length; i++) { |
| 559 | intent.putExtra(functions[i], true); |
| 560 | } |
| 561 | } |
| 562 | |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 563 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 564 | } |
| 565 | |
Mike Lockwood | bf91046 | 2012-05-09 16:19:20 -0700 | [diff] [blame] | 566 | private void updateAudioSourceFunction() { |
| 567 | boolean enabled = containsFunction(mCurrentFunctions, |
| 568 | UsbManager.USB_FUNCTION_AUDIO_SOURCE); |
| 569 | if (enabled != mAudioSourceEnabled) { |
| 570 | // send a sticky broadcast containing current USB state |
| 571 | Intent intent = new Intent(Intent.ACTION_USB_AUDIO_ACCESSORY_PLUG); |
| 572 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
| 573 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 574 | intent.putExtra("state", (enabled ? 1 : 0)); |
| 575 | if (enabled) { |
| 576 | try { |
| 577 | Scanner scanner = new Scanner(new File(AUDIO_SOURCE_PCM_PATH)); |
| 578 | int card = scanner.nextInt(); |
| 579 | int device = scanner.nextInt(); |
| 580 | intent.putExtra("card", card); |
| 581 | intent.putExtra("device", device); |
| 582 | } catch (FileNotFoundException e) { |
| 583 | Slog.e(TAG, "could not open audio source PCM file", e); |
| 584 | } |
Mike Lockwood | 9d5a4be | 2012-04-06 09:41:32 -0700 | [diff] [blame] | 585 | } |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 586 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Mike Lockwood | bf91046 | 2012-05-09 16:19:20 -0700 | [diff] [blame] | 587 | mAudioSourceEnabled = enabled; |
Mike Lockwood | 9d5a4be | 2012-04-06 09:41:32 -0700 | [diff] [blame] | 588 | } |
Mike Lockwood | 9d5a4be | 2012-04-06 09:41:32 -0700 | [diff] [blame] | 589 | } |
| 590 | |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 591 | @Override |
| 592 | public void handleMessage(Message msg) { |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 593 | switch (msg.what) { |
| 594 | case MSG_UPDATE_STATE: |
| 595 | mConnected = (msg.arg1 == 1); |
| 596 | mConfigured = (msg.arg2 == 1); |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 597 | updateUsbNotification(); |
| 598 | updateAdbNotification(); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 599 | if (containsFunction(mCurrentFunctions, |
| 600 | UsbManager.USB_FUNCTION_ACCESSORY)) { |
| 601 | updateCurrentAccessory(); |
| 602 | } |
| 603 | |
| 604 | if (!mConnected) { |
| 605 | // restore defaults when USB is disconnected |
Mike Lockwood | 68736cb | 2011-07-29 11:32:28 -0400 | [diff] [blame] | 606 | setEnabledFunctions(mDefaultFunctions, false); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 607 | } |
Mike Lockwood | d462ecf | 2011-07-21 13:55:16 -0700 | [diff] [blame] | 608 | if (mBootCompleted) { |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 609 | updateUsbState(); |
Mike Lockwood | bf91046 | 2012-05-09 16:19:20 -0700 | [diff] [blame] | 610 | updateAudioSourceFunction(); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 611 | } |
| 612 | break; |
| 613 | case MSG_ENABLE_ADB: |
| 614 | setAdbEnabled(msg.arg1 == 1); |
| 615 | break; |
Mike Lockwood | 166b05e | 2012-04-24 10:45:18 -0700 | [diff] [blame] | 616 | case MSG_SET_CURRENT_FUNCTIONS: |
| 617 | String functions = (String)msg.obj; |
Mike Lockwood | f59717d | 2011-06-22 15:19:33 -0400 | [diff] [blame] | 618 | boolean makeDefault = (msg.arg1 == 1); |
Mike Lockwood | 166b05e | 2012-04-24 10:45:18 -0700 | [diff] [blame] | 619 | setEnabledFunctions(functions, makeDefault); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 620 | break; |
| 621 | case MSG_SYSTEM_READY: |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 622 | updateUsbNotification(); |
| 623 | updateAdbNotification(); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 624 | updateUsbState(); |
Mike Lockwood | bf91046 | 2012-05-09 16:19:20 -0700 | [diff] [blame] | 625 | updateAudioSourceFunction(); |
Mike Lockwood | d462ecf | 2011-07-21 13:55:16 -0700 | [diff] [blame] | 626 | break; |
| 627 | case MSG_BOOT_COMPLETED: |
| 628 | mBootCompleted = true; |
| 629 | if (mCurrentAccessory != null) { |
Jeff Sharkey | fc3f24b | 2012-10-01 21:45:52 -0700 | [diff] [blame] | 630 | getCurrentSettings().accessoryAttached(mCurrentAccessory); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 631 | } |
Benoit Goby | 4e68bd4 | 2012-04-25 18:06:00 -0700 | [diff] [blame] | 632 | if (mDebuggingManager != null) { |
| 633 | mDebuggingManager.setAdbEnabled(mAdbEnabled); |
| 634 | } |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 635 | break; |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 636 | case MSG_USER_SWITCHED: { |
| 637 | final boolean mtpActive = |
| 638 | containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_MTP) |
| 639 | || containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_PTP); |
| 640 | if (mtpActive && mCurrentUser != UserHandle.USER_NULL) { |
| 641 | Slog.v(TAG, "Current user switched; resetting USB host stack for MTP"); |
| 642 | setUsbConfig("none"); |
| 643 | setUsbConfig(mCurrentFunctions); |
| 644 | } |
| 645 | mCurrentUser = msg.arg1; |
| 646 | break; |
| 647 | } |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 648 | } |
| 649 | } |
| 650 | |
| 651 | public UsbAccessory getCurrentAccessory() { |
| 652 | return mCurrentAccessory; |
| 653 | } |
| 654 | |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 655 | private void updateUsbNotification() { |
| 656 | if (mNotificationManager == null || !mUseUsbNotification) return; |
Mike Lockwood | fadd2b8 | 2011-08-16 13:34:34 -0700 | [diff] [blame] | 657 | int id = 0; |
Mike Lockwood | a501043 | 2011-07-27 09:50:06 -0400 | [diff] [blame] | 658 | Resources r = mContext.getResources(); |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 659 | if (mConnected) { |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 660 | if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_MTP)) { |
Mike Lockwood | fadd2b8 | 2011-08-16 13:34:34 -0700 | [diff] [blame] | 661 | id = com.android.internal.R.string.usb_mtp_notification_title; |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 662 | } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_PTP)) { |
Mike Lockwood | fadd2b8 | 2011-08-16 13:34:34 -0700 | [diff] [blame] | 663 | id = com.android.internal.R.string.usb_ptp_notification_title; |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 664 | } else if (containsFunction(mCurrentFunctions, |
| 665 | UsbManager.USB_FUNCTION_MASS_STORAGE)) { |
Mike Lockwood | fadd2b8 | 2011-08-16 13:34:34 -0700 | [diff] [blame] | 666 | id = com.android.internal.R.string.usb_cd_installer_notification_title; |
Mike Lockwood | 6e680de | 2011-07-21 15:36:09 -0700 | [diff] [blame] | 667 | } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ACCESSORY)) { |
Mike Lockwood | fadd2b8 | 2011-08-16 13:34:34 -0700 | [diff] [blame] | 668 | id = com.android.internal.R.string.usb_accessory_notification_title; |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 669 | } else { |
Mike Lockwood | a501043 | 2011-07-27 09:50:06 -0400 | [diff] [blame] | 670 | // There is a different notification for USB tethering so we don't need one here |
Dianne Hackborn | 7ff3011 | 2012-11-08 11:12:09 -0800 | [diff] [blame] | 671 | //if (!containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_RNDIS)) { |
| 672 | // Slog.e(TAG, "No known USB function in updateUsbNotification"); |
| 673 | //} |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 674 | } |
Mike Lockwood | a501043 | 2011-07-27 09:50:06 -0400 | [diff] [blame] | 675 | } |
| 676 | if (id != mUsbNotificationId) { |
| 677 | // clear notification if title needs changing |
Mike Lockwood | fadd2b8 | 2011-08-16 13:34:34 -0700 | [diff] [blame] | 678 | if (mUsbNotificationId != 0) { |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 679 | mNotificationManager.cancelAsUser(null, mUsbNotificationId, |
| 680 | UserHandle.ALL); |
Mike Lockwood | fadd2b8 | 2011-08-16 13:34:34 -0700 | [diff] [blame] | 681 | mUsbNotificationId = 0; |
Mike Lockwood | a501043 | 2011-07-27 09:50:06 -0400 | [diff] [blame] | 682 | } |
Mike Lockwood | fadd2b8 | 2011-08-16 13:34:34 -0700 | [diff] [blame] | 683 | if (id != 0) { |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 684 | CharSequence message = r.getText( |
| 685 | com.android.internal.R.string.usb_notification_message); |
Mike Lockwood | fadd2b8 | 2011-08-16 13:34:34 -0700 | [diff] [blame] | 686 | CharSequence title = r.getText(id); |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 687 | |
| 688 | Notification notification = new Notification(); |
| 689 | notification.icon = com.android.internal.R.drawable.stat_sys_data_usb; |
| 690 | notification.when = 0; |
| 691 | notification.flags = Notification.FLAG_ONGOING_EVENT; |
| 692 | notification.tickerText = title; |
| 693 | notification.defaults = 0; // please be quiet |
| 694 | notification.sound = null; |
| 695 | notification.vibrate = null; |
Daniel Sandler | 49a2ad1 | 2012-03-28 15:46:39 -0400 | [diff] [blame] | 696 | notification.priority = Notification.PRIORITY_MIN; |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 697 | |
Christopher Tate | 765f97d | 2011-08-23 20:14:33 -0700 | [diff] [blame] | 698 | Intent intent = Intent.makeRestartActivityTask( |
| 699 | new ComponentName("com.android.settings", |
| 700 | "com.android.settings.UsbSettings")); |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 701 | PendingIntent pi = PendingIntent.getActivityAsUser(mContext, 0, |
| 702 | intent, 0, null, UserHandle.CURRENT); |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 703 | notification.setLatestEventInfo(mContext, title, message, pi); |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 704 | mNotificationManager.notifyAsUser(null, id, notification, |
| 705 | UserHandle.ALL); |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 706 | mUsbNotificationId = id; |
| 707 | } |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 708 | } |
| 709 | } |
| 710 | |
| 711 | private void updateAdbNotification() { |
| 712 | if (mNotificationManager == null) return; |
Mike Lockwood | fadd2b8 | 2011-08-16 13:34:34 -0700 | [diff] [blame] | 713 | final int id = com.android.internal.R.string.adb_active_notification_title; |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 714 | if (mAdbEnabled && mConnected) { |
| 715 | if ("0".equals(SystemProperties.get("persist.adb.notify"))) return; |
| 716 | |
| 717 | if (!mAdbNotificationShown) { |
| 718 | Resources r = mContext.getResources(); |
Mike Lockwood | fadd2b8 | 2011-08-16 13:34:34 -0700 | [diff] [blame] | 719 | CharSequence title = r.getText(id); |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 720 | CharSequence message = r.getText( |
| 721 | com.android.internal.R.string.adb_active_notification_message); |
| 722 | |
| 723 | Notification notification = new Notification(); |
| 724 | notification.icon = com.android.internal.R.drawable.stat_sys_adb; |
| 725 | notification.when = 0; |
| 726 | notification.flags = Notification.FLAG_ONGOING_EVENT; |
| 727 | notification.tickerText = title; |
| 728 | notification.defaults = 0; // please be quiet |
| 729 | notification.sound = null; |
| 730 | notification.vibrate = null; |
Daniel Sandler | a25079e | 2012-05-10 10:48:56 -0400 | [diff] [blame] | 731 | notification.priority = Notification.PRIORITY_LOW; |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 732 | |
Christopher Tate | 765f97d | 2011-08-23 20:14:33 -0700 | [diff] [blame] | 733 | Intent intent = Intent.makeRestartActivityTask( |
| 734 | new ComponentName("com.android.settings", |
| 735 | "com.android.settings.DevelopmentSettings")); |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 736 | PendingIntent pi = PendingIntent.getActivityAsUser(mContext, 0, |
| 737 | intent, 0, null, UserHandle.CURRENT); |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 738 | notification.setLatestEventInfo(mContext, title, message, pi); |
| 739 | mAdbNotificationShown = true; |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 740 | mNotificationManager.notifyAsUser(null, id, notification, |
| 741 | UserHandle.ALL); |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 742 | } |
| 743 | } else if (mAdbNotificationShown) { |
| 744 | mAdbNotificationShown = false; |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 745 | mNotificationManager.cancelAsUser(null, id, UserHandle.ALL); |
Mike Lockwood | d8404d2 | 2011-06-23 16:04:29 -0400 | [diff] [blame] | 746 | } |
| 747 | } |
| 748 | |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 749 | public void dump(FileDescriptor fd, PrintWriter pw) { |
| 750 | pw.println(" USB Device State:"); |
| 751 | pw.println(" Current Functions: " + mCurrentFunctions); |
| 752 | pw.println(" Default Functions: " + mDefaultFunctions); |
| 753 | pw.println(" mConnected: " + mConnected); |
| 754 | pw.println(" mConfigured: " + mConfigured); |
| 755 | pw.println(" mCurrentAccessory: " + mCurrentAccessory); |
Mike Lockwood | 6ea146c | 2011-07-10 12:01:16 -0400 | [diff] [blame] | 756 | try { |
| 757 | pw.println(" Kernel state: " |
| 758 | + FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim()); |
| 759 | pw.println(" Kernel function list: " |
| 760 | + FileUtils.readTextFile(new File(FUNCTIONS_PATH), 0, null).trim()); |
| 761 | pw.println(" Mass storage backing file: " |
| 762 | + FileUtils.readTextFile(new File(MASS_STORAGE_FILE_PATH), 0, null).trim()); |
| 763 | } catch (IOException e) { |
| 764 | pw.println("IOException: " + e); |
| 765 | } |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 766 | } |
| 767 | } |
| 768 | |
| 769 | /* returns the currently attached USB accessory */ |
| 770 | public UsbAccessory getCurrentAccessory() { |
| 771 | return mHandler.getCurrentAccessory(); |
| 772 | } |
| 773 | |
| 774 | /* opens the currently attached USB accessory */ |
Mike Lockwood | abc4ac6 | 2011-07-11 10:34:35 -0400 | [diff] [blame] | 775 | public ParcelFileDescriptor openAccessory(UsbAccessory accessory) { |
| 776 | UsbAccessory currentAccessory = mHandler.getCurrentAccessory(); |
| 777 | if (currentAccessory == null) { |
| 778 | throw new IllegalArgumentException("no accessory attached"); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 779 | } |
Mike Lockwood | abc4ac6 | 2011-07-11 10:34:35 -0400 | [diff] [blame] | 780 | if (!currentAccessory.equals(accessory)) { |
| 781 | String error = accessory.toString() |
| 782 | + " does not match current accessory " |
| 783 | + currentAccessory; |
| 784 | throw new IllegalArgumentException(error); |
| 785 | } |
Jeff Sharkey | fc3f24b | 2012-10-01 21:45:52 -0700 | [diff] [blame] | 786 | getCurrentSettings().checkPermission(accessory); |
Mike Lockwood | abc4ac6 | 2011-07-11 10:34:35 -0400 | [diff] [blame] | 787 | return nativeOpenAccessory(); |
| 788 | } |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 789 | |
Mike Lockwood | 166b05e | 2012-04-24 10:45:18 -0700 | [diff] [blame] | 790 | public void setCurrentFunctions(String functions, boolean makeDefault) { |
| 791 | if (DEBUG) Slog.d(TAG, "setCurrentFunctions(" + functions + ") default: " + makeDefault); |
| 792 | mHandler.sendMessage(MSG_SET_CURRENT_FUNCTIONS, functions, makeDefault); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | public void setMassStorageBackingFile(String path) { |
| 796 | if (path == null) path = ""; |
| 797 | try { |
| 798 | FileUtils.stringToFile(MASS_STORAGE_FILE_PATH, path); |
| 799 | } catch (IOException e) { |
| 800 | Slog.e(TAG, "failed to write to " + MASS_STORAGE_FILE_PATH); |
| 801 | } |
| 802 | } |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 803 | |
Kazuhiro Ondo | afd8f18 | 2012-02-06 17:35:50 -0600 | [diff] [blame] | 804 | private void readOemUsbOverrideConfig() { |
| 805 | String[] configList = mContext.getResources().getStringArray( |
| 806 | com.android.internal.R.array.config_oemUsbModeOverride); |
| 807 | |
| 808 | if (configList != null) { |
| 809 | for (String config: configList) { |
| 810 | String[] items = config.split(":"); |
| 811 | if (items.length == 3) { |
| 812 | if (mOemModeMap == null) { |
| 813 | mOemModeMap = new HashMap<String, List<Pair<String, String>>>(); |
| 814 | } |
| 815 | List overrideList = mOemModeMap.get(items[0]); |
| 816 | if (overrideList == null) { |
| 817 | overrideList = new LinkedList<Pair<String, String>>(); |
| 818 | mOemModeMap.put(items[0], overrideList); |
| 819 | } |
| 820 | overrideList.add(new Pair<String, String>(items[1], items[2])); |
| 821 | } |
| 822 | } |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | private boolean needsOemUsbOverride() { |
| 827 | if (mOemModeMap == null) return false; |
| 828 | |
| 829 | String bootMode = SystemProperties.get(BOOT_MODE_PROPERTY, "unknown"); |
| 830 | return (mOemModeMap.get(bootMode) != null) ? true : false; |
| 831 | } |
| 832 | |
| 833 | private String processOemUsbOverride(String usbFunctions) { |
| 834 | if ((usbFunctions == null) || (mOemModeMap == null)) return usbFunctions; |
| 835 | |
| 836 | String bootMode = SystemProperties.get(BOOT_MODE_PROPERTY, "unknown"); |
| 837 | |
| 838 | List<Pair<String, String>> overrides = mOemModeMap.get(bootMode); |
| 839 | if (overrides != null) { |
| 840 | for (Pair<String, String> pair: overrides) { |
| 841 | if (pair.first.equals(usbFunctions)) { |
| 842 | Slog.d(TAG, "OEM USB override: " + pair.first + " ==> " + pair.second); |
| 843 | return pair.second; |
| 844 | } |
| 845 | } |
| 846 | } |
| 847 | // return passed in functions as is. |
| 848 | return usbFunctions; |
| 849 | } |
| 850 | |
Benoit Goby | 4e68bd4 | 2012-04-25 18:06:00 -0700 | [diff] [blame] | 851 | public void allowUsbDebugging(boolean alwaysAllow, String publicKey) { |
| 852 | if (mDebuggingManager != null) { |
| 853 | mDebuggingManager.allowUsbDebugging(alwaysAllow, publicKey); |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | public void denyUsbDebugging() { |
| 858 | if (mDebuggingManager != null) { |
| 859 | mDebuggingManager.denyUsbDebugging(); |
| 860 | } |
| 861 | } |
| 862 | |
Benoit Goby | cd7a17c | 2012-12-21 16:44:50 -0800 | [diff] [blame] | 863 | public void clearUsbDebuggingKeys() { |
| 864 | if (mDebuggingManager != null) { |
| 865 | mDebuggingManager.clearUsbDebuggingKeys(); |
| 866 | } else { |
| 867 | throw new RuntimeException("Cannot clear Usb Debugging keys, " |
| 868 | + "UsbDebuggingManager not enabled"); |
| 869 | } |
| 870 | } |
| 871 | |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 872 | public void dump(FileDescriptor fd, PrintWriter pw) { |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 873 | if (mHandler != null) { |
| 874 | mHandler.dump(fd, pw); |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 875 | } |
Benoit Goby | 4e68bd4 | 2012-04-25 18:06:00 -0700 | [diff] [blame] | 876 | if (mDebuggingManager != null) { |
| 877 | mDebuggingManager.dump(fd, pw); |
| 878 | } |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | private native String[] nativeGetAccessoryStrings(); |
| 882 | private native ParcelFileDescriptor nativeOpenAccessory(); |
Mike Lockwood | d462ecf | 2011-07-21 13:55:16 -0700 | [diff] [blame] | 883 | private native boolean nativeIsStartRequested(); |
Mike Lockwood | 166b05e | 2012-04-24 10:45:18 -0700 | [diff] [blame] | 884 | private native int nativeGetAudioMode(); |
Mike Lockwood | 46d0adf | 2011-05-26 10:27:39 -0400 | [diff] [blame] | 885 | } |