Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e6bffff9 authored by Daichi Hirono's avatar Daichi Hirono
Browse files

Update "accessing files" notification resources.

 * Replace tentative resources with real ones.
 * Show the notification for each device as per request from UX.

BUG=26625702

Change-Id: Ibcfe7075e4827d5aee216ce5c0007f6dd4572efe
parent 69c8cc29
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -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>
+31 −27
Original line number Diff line number Diff line
@@ -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,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.
@@ -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 */);