Loading services/java/com/android/server/usb/UsbDeviceManager.java +11 −13 Original line number Diff line number Diff line Loading @@ -45,7 +45,6 @@ import android.os.storage.StorageVolume; import android.os.SystemProperties; import android.os.UEventObserver; import android.provider.Settings; import android.util.Log; import android.util.Slog; import java.io.File; Loading @@ -62,7 +61,7 @@ import java.util.List; public class UsbDeviceManager { private static final String TAG = UsbDeviceManager.class.getSimpleName(); private static final boolean LOG = false; private static final boolean DEBUG = false; private static final String USB_STATE_MATCH = "DEVPATH=/devices/virtual/android_usb/android0"; Loading Loading @@ -114,16 +113,14 @@ public class UsbDeviceManager { private final UEventObserver mUEventObserver = new UEventObserver() { @Override public void onUEvent(UEventObserver.UEvent event) { if (Log.isLoggable(TAG, Log.VERBOSE)) { Slog.v(TAG, "USB UEVENT: " + event.toString()); } if (DEBUG) Slog.v(TAG, "USB UEVENT: " + event.toString()); String state = event.get("USB_STATE"); String accessory = event.get("ACCESSORY"); if (state != null) { mHandler.updateState(state); } else if ("START".equals(accessory)) { Slog.d(TAG, "got accessory start"); if (DEBUG) Slog.d(TAG, "got accessory start"); setCurrentFunction(UsbManager.USB_FUNCTION_ACCESSORY, false); } } Loading Loading @@ -320,12 +317,12 @@ public class UsbDeviceManager { } catch (InterruptedException e) { } } Log.e(TAG, "waitForState(" + state + ") FAILED"); Slog.e(TAG, "waitForState(" + state + ") FAILED"); return false; } private boolean setUsbConfig(String config) { Log.d(TAG, "setUsbConfig(" + config + ")"); if (DEBUG) Slog.d(TAG, "setUsbConfig(" + config + ")"); // set the new configuration SystemProperties.set("sys.usb.config", config); return waitForState(config); Loading @@ -334,7 +331,7 @@ public class UsbDeviceManager { private void doSetCurrentFunctions(String functions) { if (!mCurrentFunctions.equals(functions)) { if (!setUsbConfig("none") || !setUsbConfig(functions)) { Log.e(TAG, "Failed to switch USB configuration to " + functions); Slog.e(TAG, "Failed to switch USB configuration to " + functions); // revert to previous configuration if we fail setUsbConfig(mCurrentFunctions); } else { Loading Loading @@ -375,7 +372,7 @@ public class UsbDeviceManager { String[] strings = nativeGetAccessoryStrings(); if (strings != null) { mCurrentAccessory = new UsbAccessory(strings); Log.d(TAG, "entering USB accessory mode: " + mCurrentAccessory); Slog.d(TAG, "entering USB accessory mode: " + mCurrentAccessory); // defer accessoryAttached if system is not ready if (mSystemReady) { mSettingsManager.accessoryAttached(mCurrentAccessory); Loading @@ -383,12 +380,12 @@ public class UsbDeviceManager { mDeferAccessoryAttached = true; } } else { Log.e(TAG, "nativeGetAccessoryStrings failed"); Slog.e(TAG, "nativeGetAccessoryStrings failed"); } } else if (!mConnected) { // make sure accessory mode is off // and restore default functions Log.d(TAG, "exited USB accessory mode"); Slog.d(TAG, "exited USB accessory mode"); setEnabledFunctions(mDefaultFunctions); if (mCurrentAccessory != null) { Loading Loading @@ -502,7 +499,7 @@ public class UsbDeviceManager { com.android.internal.R.string.usb_cd_installer_notification_title); id = NOTIFICATION_INSTALLER; } else { Log.e(TAG, "No known USB function in updateUsbNotification"); Slog.e(TAG, "No known USB function in updateUsbNotification"); } if (id != mUsbNotificationId) { // clear notification if title needs changing Loading Loading @@ -613,6 +610,7 @@ public class UsbDeviceManager { } public void setCurrentFunction(String function, boolean makeDefault) { if (DEBUG) Slog.d(TAG, "setCurrentFunction(" + function + ") default: " + makeDefault); mHandler.sendMessage(MSG_SET_CURRENT_FUNCTION, function, makeDefault); } Loading services/java/com/android/server/usb/UsbHostManager.java +2 −3 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ import android.os.Parcelable; import android.os.ParcelFileDescriptor; import android.os.UEventObserver; import android.provider.Settings; import android.util.Log; import android.util.Slog; import java.io.File; Loading Loading @@ -112,7 +111,7 @@ public class UsbHostManager { synchronized (mLock) { if (mDevices.get(deviceName) != null) { Log.w(TAG, "device already on mDevices list: " + deviceName); Slog.w(TAG, "device already on mDevices list: " + deviceName); return; } Loading Loading @@ -148,7 +147,7 @@ public class UsbHostManager { } catch (Exception e) { // beware of index out of bound exceptions, which might happen if // a device does not set bNumEndpoints correctly Log.e(TAG, "error parsing USB descriptors", e); Slog.e(TAG, "error parsing USB descriptors", e); return; } Loading services/java/com/android/server/usb/UsbSettingsManager.java +17 −16 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ import android.hardware.usb.UsbManager; import android.os.Binder; import android.os.FileUtils; import android.os.Process; import android.util.Log; import android.util.Slog; import android.util.SparseBooleanArray; import android.util.Xml; Loading @@ -62,6 +62,7 @@ import java.util.List; class UsbSettingsManager { private static final String TAG = "UsbSettingsManager"; private static final boolean DEBUG = false; private static final File sSettingsFile = new File("/data/system/usb_device_manager.xml"); private final Context mContext; Loading Loading @@ -410,9 +411,9 @@ class UsbSettingsManager { } } } catch (FileNotFoundException e) { Log.w(TAG, "settings file not found"); if (DEBUG) Slog.d(TAG, "settings file not found"); } catch (Exception e) { Log.e(TAG, "error reading settings file, deleting to start fresh", e); Slog.e(TAG, "error reading settings file, deleting to start fresh", e); sSettingsFile.delete(); } finally { if (stream != null) { Loading @@ -428,7 +429,7 @@ class UsbSettingsManager { FileOutputStream fos = null; try { FileOutputStream fstr = new FileOutputStream(sSettingsFile); Log.d(TAG, "writing settings to " + fstr); if (DEBUG) Slog.d(TAG, "writing settings to " + fstr); BufferedOutputStream str = new BufferedOutputStream(fstr); FastXmlSerializer serializer = new FastXmlSerializer(); serializer.setOutput(str, "utf-8"); Loading Loading @@ -457,7 +458,7 @@ class UsbSettingsManager { FileUtils.sync(fstr); str.close(); } catch (Exception e) { Log.e(TAG, "error writing settings file, deleting to start fresh", e); Slog.e(TAG, "error writing settings file, deleting to start fresh", e); sSettingsFile.delete(); } } Loading @@ -472,7 +473,7 @@ class UsbSettingsManager { try { parser = ai.loadXmlMetaData(mPackageManager, metaDataName); if (parser == null) { Log.w(TAG, "no meta-data for " + info); Slog.w(TAG, "no meta-data for " + info); return false; } Loading @@ -494,7 +495,7 @@ class UsbSettingsManager { XmlUtils.nextElement(parser); } } catch (Exception e) { Log.w(TAG, "Unable to load component info " + info.toString(), e); Slog.w(TAG, "Unable to load component info " + info.toString(), e); } finally { if (parser != null) parser.close(); } Loading Loading @@ -553,7 +554,7 @@ class UsbSettingsManager { Intent intent = new Intent(UsbManager.ACTION_USB_DEVICE_DETACHED); intent.putExtra(UsbManager.EXTRA_DEVICE, device); Log.d(TAG, "usbDeviceRemoved, sending " + intent); if (DEBUG) Slog.d(TAG, "usbDeviceRemoved, sending " + intent); mContext.sendBroadcast(intent); } Loading Loading @@ -604,7 +605,7 @@ class UsbSettingsManager { try { mContext.startActivity(dialogIntent); } catch (ActivityNotFoundException e) { Log.e(TAG, "unable to start UsbAccessoryUriActivity"); Slog.e(TAG, "unable to start UsbAccessoryUriActivity"); } } } Loading Loading @@ -652,7 +653,7 @@ class UsbSettingsManager { defaultRI.activityInfo.name)); mContext.startActivity(intent); } catch (ActivityNotFoundException e) { Log.e(TAG, "startActivity failed", e); Slog.e(TAG, "startActivity failed", e); } } else { Intent resolverIntent = new Intent(); Loading @@ -679,7 +680,7 @@ class UsbSettingsManager { try { mContext.startActivity(resolverIntent); } catch (ActivityNotFoundException e) { Log.e(TAG, "unable to start activity " + resolverIntent); Slog.e(TAG, "unable to start activity " + resolverIntent); } } } Loading Loading @@ -733,7 +734,7 @@ class UsbSettingsManager { XmlUtils.nextElement(parser); } } catch (Exception e) { Log.w(TAG, "Unable to load component info " + aInfo.toString(), e); Slog.w(TAG, "Unable to load component info " + aInfo.toString(), e); } finally { if (parser != null) parser.close(); } Loading @@ -751,7 +752,7 @@ class UsbSettingsManager { info = mPackageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES | PackageManager.GET_META_DATA); } catch (NameNotFoundException e) { Log.e(TAG, "handlePackageUpdate could not find package " + packageName, e); Slog.e(TAG, "handlePackageUpdate could not find package " + packageName, e); return; } Loading Loading @@ -831,7 +832,7 @@ class UsbSettingsManager { try { mContext.startActivity(intent); } catch (ActivityNotFoundException e) { Log.e(TAG, "unable to start UsbPermissionActivity"); Slog.e(TAG, "unable to start UsbPermissionActivity"); } finally { Binder.restoreCallingIdentity(identity); } Loading @@ -847,7 +848,7 @@ class UsbSettingsManager { try { pi.send(mContext, 0, intent); } catch (PendingIntent.CanceledException e) { Log.w(TAG, "requestPermission PendingIntent was cancelled"); if (DEBUG) Slog.d(TAG, "requestPermission PendingIntent was cancelled"); } return; } Loading @@ -867,7 +868,7 @@ class UsbSettingsManager { try { pi.send(mContext, 0, intent); } catch (PendingIntent.CanceledException e) { Log.w(TAG, "requestPermission PendingIntent was cancelled"); if (DEBUG) Slog.d(TAG, "requestPermission PendingIntent was cancelled"); } return; } Loading Loading
services/java/com/android/server/usb/UsbDeviceManager.java +11 −13 Original line number Diff line number Diff line Loading @@ -45,7 +45,6 @@ import android.os.storage.StorageVolume; import android.os.SystemProperties; import android.os.UEventObserver; import android.provider.Settings; import android.util.Log; import android.util.Slog; import java.io.File; Loading @@ -62,7 +61,7 @@ import java.util.List; public class UsbDeviceManager { private static final String TAG = UsbDeviceManager.class.getSimpleName(); private static final boolean LOG = false; private static final boolean DEBUG = false; private static final String USB_STATE_MATCH = "DEVPATH=/devices/virtual/android_usb/android0"; Loading Loading @@ -114,16 +113,14 @@ public class UsbDeviceManager { private final UEventObserver mUEventObserver = new UEventObserver() { @Override public void onUEvent(UEventObserver.UEvent event) { if (Log.isLoggable(TAG, Log.VERBOSE)) { Slog.v(TAG, "USB UEVENT: " + event.toString()); } if (DEBUG) Slog.v(TAG, "USB UEVENT: " + event.toString()); String state = event.get("USB_STATE"); String accessory = event.get("ACCESSORY"); if (state != null) { mHandler.updateState(state); } else if ("START".equals(accessory)) { Slog.d(TAG, "got accessory start"); if (DEBUG) Slog.d(TAG, "got accessory start"); setCurrentFunction(UsbManager.USB_FUNCTION_ACCESSORY, false); } } Loading Loading @@ -320,12 +317,12 @@ public class UsbDeviceManager { } catch (InterruptedException e) { } } Log.e(TAG, "waitForState(" + state + ") FAILED"); Slog.e(TAG, "waitForState(" + state + ") FAILED"); return false; } private boolean setUsbConfig(String config) { Log.d(TAG, "setUsbConfig(" + config + ")"); if (DEBUG) Slog.d(TAG, "setUsbConfig(" + config + ")"); // set the new configuration SystemProperties.set("sys.usb.config", config); return waitForState(config); Loading @@ -334,7 +331,7 @@ public class UsbDeviceManager { private void doSetCurrentFunctions(String functions) { if (!mCurrentFunctions.equals(functions)) { if (!setUsbConfig("none") || !setUsbConfig(functions)) { Log.e(TAG, "Failed to switch USB configuration to " + functions); Slog.e(TAG, "Failed to switch USB configuration to " + functions); // revert to previous configuration if we fail setUsbConfig(mCurrentFunctions); } else { Loading Loading @@ -375,7 +372,7 @@ public class UsbDeviceManager { String[] strings = nativeGetAccessoryStrings(); if (strings != null) { mCurrentAccessory = new UsbAccessory(strings); Log.d(TAG, "entering USB accessory mode: " + mCurrentAccessory); Slog.d(TAG, "entering USB accessory mode: " + mCurrentAccessory); // defer accessoryAttached if system is not ready if (mSystemReady) { mSettingsManager.accessoryAttached(mCurrentAccessory); Loading @@ -383,12 +380,12 @@ public class UsbDeviceManager { mDeferAccessoryAttached = true; } } else { Log.e(TAG, "nativeGetAccessoryStrings failed"); Slog.e(TAG, "nativeGetAccessoryStrings failed"); } } else if (!mConnected) { // make sure accessory mode is off // and restore default functions Log.d(TAG, "exited USB accessory mode"); Slog.d(TAG, "exited USB accessory mode"); setEnabledFunctions(mDefaultFunctions); if (mCurrentAccessory != null) { Loading Loading @@ -502,7 +499,7 @@ public class UsbDeviceManager { com.android.internal.R.string.usb_cd_installer_notification_title); id = NOTIFICATION_INSTALLER; } else { Log.e(TAG, "No known USB function in updateUsbNotification"); Slog.e(TAG, "No known USB function in updateUsbNotification"); } if (id != mUsbNotificationId) { // clear notification if title needs changing Loading Loading @@ -613,6 +610,7 @@ public class UsbDeviceManager { } public void setCurrentFunction(String function, boolean makeDefault) { if (DEBUG) Slog.d(TAG, "setCurrentFunction(" + function + ") default: " + makeDefault); mHandler.sendMessage(MSG_SET_CURRENT_FUNCTION, function, makeDefault); } Loading
services/java/com/android/server/usb/UsbHostManager.java +2 −3 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ import android.os.Parcelable; import android.os.ParcelFileDescriptor; import android.os.UEventObserver; import android.provider.Settings; import android.util.Log; import android.util.Slog; import java.io.File; Loading Loading @@ -112,7 +111,7 @@ public class UsbHostManager { synchronized (mLock) { if (mDevices.get(deviceName) != null) { Log.w(TAG, "device already on mDevices list: " + deviceName); Slog.w(TAG, "device already on mDevices list: " + deviceName); return; } Loading Loading @@ -148,7 +147,7 @@ public class UsbHostManager { } catch (Exception e) { // beware of index out of bound exceptions, which might happen if // a device does not set bNumEndpoints correctly Log.e(TAG, "error parsing USB descriptors", e); Slog.e(TAG, "error parsing USB descriptors", e); return; } Loading
services/java/com/android/server/usb/UsbSettingsManager.java +17 −16 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ import android.hardware.usb.UsbManager; import android.os.Binder; import android.os.FileUtils; import android.os.Process; import android.util.Log; import android.util.Slog; import android.util.SparseBooleanArray; import android.util.Xml; Loading @@ -62,6 +62,7 @@ import java.util.List; class UsbSettingsManager { private static final String TAG = "UsbSettingsManager"; private static final boolean DEBUG = false; private static final File sSettingsFile = new File("/data/system/usb_device_manager.xml"); private final Context mContext; Loading Loading @@ -410,9 +411,9 @@ class UsbSettingsManager { } } } catch (FileNotFoundException e) { Log.w(TAG, "settings file not found"); if (DEBUG) Slog.d(TAG, "settings file not found"); } catch (Exception e) { Log.e(TAG, "error reading settings file, deleting to start fresh", e); Slog.e(TAG, "error reading settings file, deleting to start fresh", e); sSettingsFile.delete(); } finally { if (stream != null) { Loading @@ -428,7 +429,7 @@ class UsbSettingsManager { FileOutputStream fos = null; try { FileOutputStream fstr = new FileOutputStream(sSettingsFile); Log.d(TAG, "writing settings to " + fstr); if (DEBUG) Slog.d(TAG, "writing settings to " + fstr); BufferedOutputStream str = new BufferedOutputStream(fstr); FastXmlSerializer serializer = new FastXmlSerializer(); serializer.setOutput(str, "utf-8"); Loading Loading @@ -457,7 +458,7 @@ class UsbSettingsManager { FileUtils.sync(fstr); str.close(); } catch (Exception e) { Log.e(TAG, "error writing settings file, deleting to start fresh", e); Slog.e(TAG, "error writing settings file, deleting to start fresh", e); sSettingsFile.delete(); } } Loading @@ -472,7 +473,7 @@ class UsbSettingsManager { try { parser = ai.loadXmlMetaData(mPackageManager, metaDataName); if (parser == null) { Log.w(TAG, "no meta-data for " + info); Slog.w(TAG, "no meta-data for " + info); return false; } Loading @@ -494,7 +495,7 @@ class UsbSettingsManager { XmlUtils.nextElement(parser); } } catch (Exception e) { Log.w(TAG, "Unable to load component info " + info.toString(), e); Slog.w(TAG, "Unable to load component info " + info.toString(), e); } finally { if (parser != null) parser.close(); } Loading Loading @@ -553,7 +554,7 @@ class UsbSettingsManager { Intent intent = new Intent(UsbManager.ACTION_USB_DEVICE_DETACHED); intent.putExtra(UsbManager.EXTRA_DEVICE, device); Log.d(TAG, "usbDeviceRemoved, sending " + intent); if (DEBUG) Slog.d(TAG, "usbDeviceRemoved, sending " + intent); mContext.sendBroadcast(intent); } Loading Loading @@ -604,7 +605,7 @@ class UsbSettingsManager { try { mContext.startActivity(dialogIntent); } catch (ActivityNotFoundException e) { Log.e(TAG, "unable to start UsbAccessoryUriActivity"); Slog.e(TAG, "unable to start UsbAccessoryUriActivity"); } } } Loading Loading @@ -652,7 +653,7 @@ class UsbSettingsManager { defaultRI.activityInfo.name)); mContext.startActivity(intent); } catch (ActivityNotFoundException e) { Log.e(TAG, "startActivity failed", e); Slog.e(TAG, "startActivity failed", e); } } else { Intent resolverIntent = new Intent(); Loading @@ -679,7 +680,7 @@ class UsbSettingsManager { try { mContext.startActivity(resolverIntent); } catch (ActivityNotFoundException e) { Log.e(TAG, "unable to start activity " + resolverIntent); Slog.e(TAG, "unable to start activity " + resolverIntent); } } } Loading Loading @@ -733,7 +734,7 @@ class UsbSettingsManager { XmlUtils.nextElement(parser); } } catch (Exception e) { Log.w(TAG, "Unable to load component info " + aInfo.toString(), e); Slog.w(TAG, "Unable to load component info " + aInfo.toString(), e); } finally { if (parser != null) parser.close(); } Loading @@ -751,7 +752,7 @@ class UsbSettingsManager { info = mPackageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES | PackageManager.GET_META_DATA); } catch (NameNotFoundException e) { Log.e(TAG, "handlePackageUpdate could not find package " + packageName, e); Slog.e(TAG, "handlePackageUpdate could not find package " + packageName, e); return; } Loading Loading @@ -831,7 +832,7 @@ class UsbSettingsManager { try { mContext.startActivity(intent); } catch (ActivityNotFoundException e) { Log.e(TAG, "unable to start UsbPermissionActivity"); Slog.e(TAG, "unable to start UsbPermissionActivity"); } finally { Binder.restoreCallingIdentity(identity); } Loading @@ -847,7 +848,7 @@ class UsbSettingsManager { try { pi.send(mContext, 0, intent); } catch (PendingIntent.CanceledException e) { Log.w(TAG, "requestPermission PendingIntent was cancelled"); if (DEBUG) Slog.d(TAG, "requestPermission PendingIntent was cancelled"); } return; } Loading @@ -867,7 +868,7 @@ class UsbSettingsManager { try { pi.send(mContext, 0, intent); } catch (PendingIntent.CanceledException e) { Log.w(TAG, "requestPermission PendingIntent was cancelled"); if (DEBUG) Slog.d(TAG, "requestPermission PendingIntent was cancelled"); } return; } Loading