Merge "UsbManager: Use resource IDs for notification IDs"
This commit is contained in:
committed by
Android (Google) Code Review
commit
33ffb3661e
@@ -253,13 +253,6 @@ public class UsbDeviceManager {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final int NOTIFICATION_NONE = 0;
|
|
||||||
private static final int NOTIFICATION_MTP = 1;
|
|
||||||
private static final int NOTIFICATION_PTP = 2;
|
|
||||||
private static final int NOTIFICATION_INSTALLER = 3;
|
|
||||||
private static final int NOTIFICATION_ACCESSORY = 4;
|
|
||||||
private static final int NOTIFICATION_ADB = 5;
|
|
||||||
|
|
||||||
public UsbHandler(Looper looper) {
|
public UsbHandler(Looper looper) {
|
||||||
super(looper);
|
super(looper);
|
||||||
try {
|
try {
|
||||||
@@ -536,27 +529,18 @@ public class UsbDeviceManager {
|
|||||||
|
|
||||||
private void updateUsbNotification() {
|
private void updateUsbNotification() {
|
||||||
if (mNotificationManager == null || !mUseUsbNotification) return;
|
if (mNotificationManager == null || !mUseUsbNotification) return;
|
||||||
int id = NOTIFICATION_NONE;
|
int id = 0;
|
||||||
Resources r = mContext.getResources();
|
Resources r = mContext.getResources();
|
||||||
CharSequence title = null;
|
|
||||||
if (mConnected) {
|
if (mConnected) {
|
||||||
if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_MTP)) {
|
if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_MTP)) {
|
||||||
title = r.getText(
|
id = com.android.internal.R.string.usb_mtp_notification_title;
|
||||||
com.android.internal.R.string.usb_mtp_notification_title);
|
|
||||||
id = NOTIFICATION_MTP;
|
|
||||||
} else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_PTP)) {
|
} else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_PTP)) {
|
||||||
title = r.getText(
|
id = com.android.internal.R.string.usb_ptp_notification_title;
|
||||||
com.android.internal.R.string.usb_ptp_notification_title);
|
|
||||||
id = NOTIFICATION_PTP;
|
|
||||||
} else if (containsFunction(mCurrentFunctions,
|
} else if (containsFunction(mCurrentFunctions,
|
||||||
UsbManager.USB_FUNCTION_MASS_STORAGE)) {
|
UsbManager.USB_FUNCTION_MASS_STORAGE)) {
|
||||||
title = r.getText(
|
id = com.android.internal.R.string.usb_cd_installer_notification_title;
|
||||||
com.android.internal.R.string.usb_cd_installer_notification_title);
|
|
||||||
id = NOTIFICATION_INSTALLER;
|
|
||||||
} else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ACCESSORY)) {
|
} else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ACCESSORY)) {
|
||||||
title = r.getText(
|
id = com.android.internal.R.string.usb_accessory_notification_title;
|
||||||
com.android.internal.R.string.usb_accessory_notification_title);
|
|
||||||
id = NOTIFICATION_ACCESSORY;
|
|
||||||
} else {
|
} else {
|
||||||
// There is a different notification for USB tethering so we don't need one here
|
// There is a different notification for USB tethering so we don't need one here
|
||||||
if (!containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_RNDIS)) {
|
if (!containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_RNDIS)) {
|
||||||
@@ -566,13 +550,14 @@ public class UsbDeviceManager {
|
|||||||
}
|
}
|
||||||
if (id != mUsbNotificationId) {
|
if (id != mUsbNotificationId) {
|
||||||
// clear notification if title needs changing
|
// clear notification if title needs changing
|
||||||
if (mUsbNotificationId != NOTIFICATION_NONE) {
|
if (mUsbNotificationId != 0) {
|
||||||
mNotificationManager.cancel(mUsbNotificationId);
|
mNotificationManager.cancel(mUsbNotificationId);
|
||||||
mUsbNotificationId = NOTIFICATION_NONE;
|
mUsbNotificationId = 0;
|
||||||
}
|
}
|
||||||
if (id != NOTIFICATION_NONE) {
|
if (id != 0) {
|
||||||
CharSequence message = r.getText(
|
CharSequence message = r.getText(
|
||||||
com.android.internal.R.string.usb_notification_message);
|
com.android.internal.R.string.usb_notification_message);
|
||||||
|
CharSequence title = r.getText(id);
|
||||||
|
|
||||||
Notification notification = new Notification();
|
Notification notification = new Notification();
|
||||||
notification.icon = com.android.internal.R.drawable.stat_sys_data_usb;
|
notification.icon = com.android.internal.R.drawable.stat_sys_data_usb;
|
||||||
@@ -600,13 +585,13 @@ public class UsbDeviceManager {
|
|||||||
|
|
||||||
private void updateAdbNotification() {
|
private void updateAdbNotification() {
|
||||||
if (mNotificationManager == null) return;
|
if (mNotificationManager == null) return;
|
||||||
|
final int id = com.android.internal.R.string.adb_active_notification_title;
|
||||||
if (mAdbEnabled && mConnected) {
|
if (mAdbEnabled && mConnected) {
|
||||||
if ("0".equals(SystemProperties.get("persist.adb.notify"))) return;
|
if ("0".equals(SystemProperties.get("persist.adb.notify"))) return;
|
||||||
|
|
||||||
if (!mAdbNotificationShown) {
|
if (!mAdbNotificationShown) {
|
||||||
Resources r = mContext.getResources();
|
Resources r = mContext.getResources();
|
||||||
CharSequence title = r.getText(
|
CharSequence title = r.getText(id);
|
||||||
com.android.internal.R.string.adb_active_notification_title);
|
|
||||||
CharSequence message = r.getText(
|
CharSequence message = r.getText(
|
||||||
com.android.internal.R.string.adb_active_notification_message);
|
com.android.internal.R.string.adb_active_notification_message);
|
||||||
|
|
||||||
@@ -629,11 +614,11 @@ public class UsbDeviceManager {
|
|||||||
intent, 0);
|
intent, 0);
|
||||||
notification.setLatestEventInfo(mContext, title, message, pi);
|
notification.setLatestEventInfo(mContext, title, message, pi);
|
||||||
mAdbNotificationShown = true;
|
mAdbNotificationShown = true;
|
||||||
mNotificationManager.notify(NOTIFICATION_ADB, notification);
|
mNotificationManager.notify(id, notification);
|
||||||
}
|
}
|
||||||
} else if (mAdbNotificationShown) {
|
} else if (mAdbNotificationShown) {
|
||||||
mAdbNotificationShown = false;
|
mAdbNotificationShown = false;
|
||||||
mNotificationManager.cancel(NOTIFICATION_ADB);
|
mNotificationManager.cancel(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user