Loading packages/MtpDocumentsProvider/res/values/strings.xml +5 −1 Original line number Diff line number Diff line Loading @@ -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> packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsService.java +31 −27 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -67,6 +66,7 @@ public class MtpDocumentsService extends Service { break; case ACTION_CLOSE_DEVICE: mNotificationManager.cancel(device.getDeviceId()); provider.closeDevice(device.getDeviceId()); break; Loading @@ -90,15 +90,25 @@ 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 { message = provider.getDeviceName(deviceIds[0]) + " is being connected."; 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. Loading @@ -111,15 +121,9 @@ public class MtpDocumentsService extends Service { } } } } 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 */); Loading Loading
packages/MtpDocumentsProvider/res/values/strings.xml +5 −1 Original line number Diff line number Diff line Loading @@ -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>
packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsService.java +31 −27 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -67,6 +66,7 @@ public class MtpDocumentsService extends Service { break; case ACTION_CLOSE_DEVICE: mNotificationManager.cancel(device.getDeviceId()); provider.closeDevice(device.getDeviceId()); break; Loading @@ -90,15 +90,25 @@ 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 { message = provider.getDeviceName(deviceIds[0]) + " is being connected."; 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. Loading @@ -111,15 +121,9 @@ public class MtpDocumentsService extends Service { } } } } 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 */); Loading