diff options
| author | 2016-01-25 08:28:23 +0000 | |
|---|---|---|
| committer | 2016-01-25 08:28:23 +0000 | |
| commit | 7d1ca068a229191653f66e440f4209a2a2c3f05e (patch) | |
| tree | 091dba57919821cd8638878de586bacb0e02c174 | |
| parent | e76958297a52de290e8d985a8a5d56c12ba8c779 (diff) | |
| parent | e6bffff9d944390a7656f003fac4d47359fae0db (diff) | |
Merge "Update "accessing files" notification resources."
| -rw-r--r-- | packages/MtpDocumentsProvider/res/values/strings.xml | 6 | ||||
| -rw-r--r-- | packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsService.java | 58 |
2 files changed, 36 insertions, 28 deletions
diff --git a/packages/MtpDocumentsProvider/res/values/strings.xml b/packages/MtpDocumentsProvider/res/values/strings.xml index 7a4087b601fe..43a420cf6d97 100644 --- a/packages/MtpDocumentsProvider/res/values/strings.xml +++ b/packages/MtpDocumentsProvider/res/values/strings.xml @@ -16,9 +16,13 @@ <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <!-- Title of the external storage application [CHAR LIMIT=32] --> - <string name="app_label">MTP Storage</string> + <string name="app_label">Files</string> <!-- Name of MTP root shown in UI. Please align the two strings (device model and storage name) in proper order in the language. [CHAR LIMIT=32] --> <string name="root_name"><xliff:g id="device_model" example="Nexus 9">%1$s</xliff:g> <xliff:g id="storage_name" example="Internal Storage">%2$s</xliff:g></string> + <!-- Title of notification showing Files app is accessing files in a MTP device. [CHAR LIMIT=60]--> + <string name="accessing_notification_title">Accessing files from <xliff:g id="device_model" example="Nexus 9">%1$s</xliff:g></string> + <!-- Description of notification showing Files app is accessing files in a MTP device. [CHAR LIMIT=60]--> + <string name="accessing_notification_description">Don\'t disconnect the device</string> </resources> diff --git a/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsService.java b/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsService.java index b0cff83ef22e..5bede8617d60 100644 --- a/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsService.java +++ b/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsService.java @@ -37,7 +37,6 @@ public class MtpDocumentsService extends Service { static final String ACTION_OPEN_DEVICE = "com.android.mtp.OPEN_DEVICE"; static final String ACTION_CLOSE_DEVICE = "com.android.mtp.CLOSE_DEVICE"; static final String EXTRA_DEVICE = "device"; - private static final int FOREGROUND_NOTIFICATION_ID = 1; NotificationManager mNotificationManager; @@ -67,6 +66,7 @@ public class MtpDocumentsService extends Service { break; case ACTION_CLOSE_DEVICE: + mNotificationManager.cancel(device.getDeviceId()); provider.closeDevice(device.getDeviceId()); break; @@ -90,36 +90,40 @@ public class MtpDocumentsService extends Service { private boolean updateForegroundState() { final MtpDocumentsProvider provider = MtpDocumentsProvider.getInstance(); final int[] deviceIds = provider.getOpenedDeviceIds(); - String message = null; - if (deviceIds.length != 0) { - // TODO: Localize the message. - // TODO: Add buttons "Open in Files" and "Open in Apps" if needed. - if (deviceIds.length > 1) { - message = deviceIds.length + " devices are being connected."; - } else { + int notificationId = 0; + Notification notification = null; + for (final int deviceId : deviceIds) { + try { + final String title = getResources().getString( + R.string.accessing_notification_title, + provider.getDeviceName(deviceIds[0])); + final String description = getResources().getString( + R.string.accessing_notification_description); + notificationId = deviceId; + notification = new Notification.Builder(this) + .setLocalOnly(true) + .setContentTitle(title) + .setContentText(description) + .setSmallIcon(com.android.internal.R.drawable.stat_sys_data_usb) + .setCategory(Notification.CATEGORY_SYSTEM) + .setPriority(Notification.PRIORITY_LOW) + .build(); + mNotificationManager.notify(deviceId, notification); + } catch (IOException exp) { + logErrorMessage(exp); + // If we failed to obtain device name, it looks the device is unusable. + // Because this is the last device we opened, we should hide the notification + // for the case. try { - message = provider.getDeviceName(deviceIds[0]) + " is being connected."; - } catch (IOException exp) { - logErrorMessage(exp); - // If we failed to obtain device name, it looks the device is unusable. - // Because this is the last device we opened, we should hide the notification - // for the case. - try { - provider.closeDevice(deviceIds[0]); - } catch (IOException | InterruptedException closeError) { - logErrorMessage(closeError); - } + provider.closeDevice(deviceIds[0]); + } catch (IOException | InterruptedException closeError) { + logErrorMessage(closeError); } } } - if (message != null) { - final Notification notification = new Notification.Builder(this) - .setContentTitle(message) - .setSmallIcon(android.R.drawable.ic_menu_camera) - .setCategory(Notification.CATEGORY_SYSTEM) - .setPriority(Notification.PRIORITY_LOW) - .build(); - startForeground(FOREGROUND_NOTIFICATION_ID, notification); + + if (notification != null) { + startForeground(notificationId, notification); return true; } else { stopForeground(true /* removeNotification */); |