UsbManager: Clean up extras for ACTION_USB_STATE broadcast
Also added name for new PTP USB function Change-Id: Ia2775ba2b23ef6a6108ca7e060239eb51c2eecc8 Signed-off-by: Mike Lockwood <lockwood@android.com>
This commit is contained in:
@@ -50,11 +50,20 @@ public class UsbManager {
|
||||
* This is a sticky broadcast for clients that includes USB connected/disconnected state,
|
||||
* <ul>
|
||||
* <li> {@link #USB_CONNECTED} boolean indicating whether USB is connected or disconnected.
|
||||
* <li> {@link #USB_CONFIGURATION} a Bundle containing name/value pairs where the name
|
||||
* is the name of a USB function and the value is either {@link #USB_FUNCTION_ENABLED}
|
||||
* or {@link #USB_FUNCTION_DISABLED}. The possible function names include
|
||||
* {@link #USB_FUNCTION_MASS_STORAGE}, {@link #USB_FUNCTION_ADB}, {@link #USB_FUNCTION_RNDIS},
|
||||
* {@link #USB_FUNCTION_MTP} and {@link #USB_FUNCTION_ACCESSORY}.
|
||||
* <li> {@link #USB_CONFIGURATION} integer containing current USB configuration
|
||||
* currently zero if not configured, one for configured.
|
||||
* <li> {@link #USB_FUNCTION_MASS_STORAGE} boolean extra indicating whether the
|
||||
* mass storage function is enabled
|
||||
* <li> {@link #USB_FUNCTION_ADB} boolean extra indicating whether the
|
||||
* adb function is enabled
|
||||
* <li> {@link #USB_FUNCTION_RNDIS} boolean extra indicating whether the
|
||||
* RNDIS ethernet function is enabled
|
||||
* <li> {@link #USB_FUNCTION_MTP} boolean extra indicating whether the
|
||||
* MTP function is enabled
|
||||
* <li> {@link #USB_FUNCTION_PTP} boolean extra indicating whether the
|
||||
* PTP function is enabled
|
||||
* <li> {@link #USB_FUNCTION_PTP} boolean extra indicating whether the
|
||||
* accessory function is enabled
|
||||
* </ul>
|
||||
*
|
||||
* {@hide}
|
||||
@@ -158,6 +167,14 @@ public class UsbManager {
|
||||
*/
|
||||
public static final String USB_FUNCTION_MTP = "mtp";
|
||||
|
||||
/**
|
||||
* Name of the PTP USB function.
|
||||
* Used in extras for the {@link #ACTION_USB_STATE} broadcast
|
||||
*
|
||||
* {@hide}
|
||||
*/
|
||||
public static final String USB_FUNCTION_PTP = "ptp";
|
||||
|
||||
/**
|
||||
* Name of the Accessory USB function.
|
||||
* Used in extras for the {@link #ACTION_USB_STATE} broadcast
|
||||
@@ -166,24 +183,6 @@ public class UsbManager {
|
||||
*/
|
||||
public static final String USB_FUNCTION_ACCESSORY = "accessory";
|
||||
|
||||
/**
|
||||
* Value indicating that a USB function is enabled.
|
||||
* Used in {@link #USB_CONFIGURATION} extras bundle for the
|
||||
* {@link #ACTION_USB_STATE} broadcast
|
||||
*
|
||||
* {@hide}
|
||||
*/
|
||||
public static final String USB_FUNCTION_ENABLED = "enabled";
|
||||
|
||||
/**
|
||||
* Value indicating that a USB function is disabled.
|
||||
* Used in {@link #USB_CONFIGURATION} extras bundle for the
|
||||
* {@link #ACTION_USB_STATE} broadcast
|
||||
*
|
||||
* {@hide}
|
||||
*/
|
||||
public static final String USB_FUNCTION_DISABLED = "disabled";
|
||||
|
||||
/**
|
||||
* Name of extra for {@link #ACTION_USB_DEVICE_ATTACHED} and
|
||||
* {@link #ACTION_USB_DEVICE_DETACHED} broadcasts
|
||||
|
||||
@@ -333,8 +333,7 @@ public class NotificationManagerService extends INotificationManager.Stub
|
||||
if (action.equals(UsbManager.ACTION_USB_STATE)) {
|
||||
Bundle extras = intent.getExtras();
|
||||
boolean usbConnected = extras.getBoolean(UsbManager.USB_CONNECTED);
|
||||
boolean adbEnabled = (UsbManager.USB_FUNCTION_ENABLED.equals(
|
||||
extras.getString(UsbManager.USB_FUNCTION_ADB)));
|
||||
boolean adbEnabled = extras.getBoolean(UsbManager.USB_FUNCTION_ADB);
|
||||
updateAdbNotification(usbConnected && adbEnabled);
|
||||
} else if (action.equals(Intent.ACTION_PACKAGE_REMOVED)
|
||||
|| action.equals(Intent.ACTION_PACKAGE_RESTARTED)
|
||||
|
||||
@@ -84,7 +84,6 @@ public class UsbDeviceManager {
|
||||
|
||||
// lists of enabled and disabled USB functions
|
||||
private final ArrayList<String> mEnabledFunctions = new ArrayList<String>();
|
||||
private final ArrayList<String> mDisabledFunctions = new ArrayList<String>();
|
||||
|
||||
private boolean mSystemReady;
|
||||
|
||||
@@ -120,15 +119,11 @@ public class UsbDeviceManager {
|
||||
if (!mEnabledFunctions.contains(function)) {
|
||||
mEnabledFunctions.add(function);
|
||||
}
|
||||
mDisabledFunctions.remove(function);
|
||||
|
||||
if (UsbManager.USB_FUNCTION_ACCESSORY.equals(function)) {
|
||||
readCurrentAccessoryLocked();
|
||||
}
|
||||
} else {
|
||||
if (!mDisabledFunctions.contains(function)) {
|
||||
mDisabledFunctions.add(function);
|
||||
}
|
||||
mEnabledFunctions.remove(function);
|
||||
}
|
||||
}
|
||||
@@ -260,8 +255,6 @@ public class UsbDeviceManager {
|
||||
// so don't treat it as a default function.
|
||||
mDefaultFunctions.add(functionName);
|
||||
}
|
||||
} else {
|
||||
mDisabledFunctions.add(functionName);
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
@@ -278,9 +271,9 @@ public class UsbDeviceManager {
|
||||
// FIXME - if we booted in accessory mode, then we have no way to figure out
|
||||
// which functions are enabled by default.
|
||||
// For now, assume that MTP or mass storage are the only possibilities
|
||||
if (mDisabledFunctions.contains(UsbManager.USB_FUNCTION_MTP)) {
|
||||
if (!mEnabledFunctions.contains(UsbManager.USB_FUNCTION_MTP)) {
|
||||
mDefaultFunctions.add(UsbManager.USB_FUNCTION_MTP);
|
||||
} else if (mDisabledFunctions.contains(UsbManager.USB_FUNCTION_MASS_STORAGE)) {
|
||||
} else if (!mEnabledFunctions.contains(UsbManager.USB_FUNCTION_MASS_STORAGE)) {
|
||||
mDefaultFunctions.add(UsbManager.USB_FUNCTION_MASS_STORAGE);
|
||||
}
|
||||
}
|
||||
@@ -335,15 +328,6 @@ public class UsbDeviceManager {
|
||||
* This handler is for deferred handling of events related to device mode and accessories.
|
||||
*/
|
||||
private final Handler mHandler = new Handler() {
|
||||
private void addEnabledFunctionsLocked(Intent intent) {
|
||||
// include state of all USB functions in our extras
|
||||
for (int i = 0; i < mEnabledFunctions.size(); i++) {
|
||||
intent.putExtra(mEnabledFunctions.get(i), UsbManager.USB_FUNCTION_ENABLED);
|
||||
}
|
||||
for (int i = 0; i < mDisabledFunctions.size(); i++) {
|
||||
intent.putExtra(mDisabledFunctions.get(i), UsbManager.USB_FUNCTION_DISABLED);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
@@ -390,7 +374,9 @@ public class UsbDeviceManager {
|
||||
intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
|
||||
intent.putExtra(UsbManager.USB_CONNECTED, mConnected != 0);
|
||||
intent.putExtra(UsbManager.USB_CONFIGURATION, mConfiguration);
|
||||
addEnabledFunctionsLocked(intent);
|
||||
for (int i = 0; i < mEnabledFunctions.size(); i++) {
|
||||
intent.putExtra(mEnabledFunctions.get(i), true);
|
||||
}
|
||||
mContext.sendStickyBroadcast(intent);
|
||||
}
|
||||
break;
|
||||
@@ -411,11 +397,6 @@ public class UsbDeviceManager {
|
||||
pw.print(mEnabledFunctions.get(i) + " ");
|
||||
}
|
||||
pw.println("");
|
||||
pw.print(" Disabled Functions: ");
|
||||
for (int i = 0; i < mDisabledFunctions.size(); i++) {
|
||||
pw.print(mDisabledFunctions.get(i) + " ");
|
||||
}
|
||||
pw.println("");
|
||||
pw.print(" Default Functions: ");
|
||||
for (int i = 0; i < mDefaultFunctions.size(); i++) {
|
||||
pw.print(mDefaultFunctions.get(i) + " ");
|
||||
|
||||
Reference in New Issue
Block a user