San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 1 | /* |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 2 | * Copyright (C) 2015 The Android Open Source Project |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Joe Onorato | fe4f3ae | 2010-06-04 11:25:26 -0700 | [diff] [blame] | 17 | package com.android.systemui.usb; |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 18 | |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 19 | import android.app.Notification; |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 20 | import android.app.Notification.Action; |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 21 | import android.app.NotificationManager; |
| 22 | import android.app.PendingIntent; |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 23 | import android.content.BroadcastReceiver; |
| 24 | import android.content.Context; |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 25 | import android.content.Intent; |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 26 | import android.content.IntentFilter; |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 27 | import android.os.UserHandle; |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 28 | import android.os.storage.DiskInfo; |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 29 | import android.os.storage.StorageEventListener; |
| 30 | import android.os.storage.StorageManager; |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 31 | import android.os.storage.VolumeInfo; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 32 | import android.util.Log; |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 33 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 34 | import com.android.internal.R; |
John Spurlock | 3e309b2 | 2013-06-25 11:01:29 -0400 | [diff] [blame] | 35 | import com.android.systemui.SystemUI; |
| 36 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 37 | import java.util.List; |
| 38 | |
John Spurlock | 3e309b2 | 2013-06-25 11:01:29 -0400 | [diff] [blame] | 39 | public class StorageNotification extends SystemUI { |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 40 | private static final String TAG = "StorageNotification"; |
| 41 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 42 | private static final int NOTIF_ID = 0x53544f52; // STOR |
Daniel Sandler | c07907e | 2010-02-22 15:08:41 -0500 | [diff] [blame] | 43 | |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 44 | private static final String ACTION_SNOOZE_VOLUME = "com.android.systemui.action.SNOOZE_VOLUME"; |
| 45 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 46 | // TODO: delay some notifications to avoid bumpy fast operations |
| 47 | // TODO: annoy user when private media is missing |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 48 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 49 | private NotificationManager mNotificationManager; |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 50 | private StorageManager mStorageManager; |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 51 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 52 | private final StorageEventListener mListener = new StorageEventListener() { |
| 53 | @Override |
| 54 | public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState) { |
| 55 | onVolumeStateChangedInternal(vol, oldState, newState); |
John Spurlock | 3e309b2 | 2013-06-25 11:01:29 -0400 | [diff] [blame] | 56 | } |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 57 | |
| 58 | @Override |
| 59 | public void onVolumeMetadataChanged(VolumeInfo vol) { |
| 60 | // Avoid kicking notifications when getting early metadata before |
| 61 | // mounted. If already mounted, we're being kicked because of a |
| 62 | // nickname or init'ed change. |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 63 | if (vol.isMountedReadable()) { |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 64 | onVolumeStateChangedInternal(vol, vol.getState(), vol.getState()); |
| 65 | } |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | private final BroadcastReceiver mSnoozeReceiver = new BroadcastReceiver() { |
| 70 | @Override |
| 71 | public void onReceive(Context context, Intent intent) { |
| 72 | // TODO: kick this onto background thread |
| 73 | final String volId = intent.getStringExtra(VolumeInfo.EXTRA_VOLUME_ID); |
| 74 | mStorageManager.setVolumeSnoozed(volId, true); |
| 75 | } |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 76 | }; |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 77 | |
John Spurlock | 3e309b2 | 2013-06-25 11:01:29 -0400 | [diff] [blame] | 78 | @Override |
| 79 | public void start() { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 80 | mNotificationManager = mContext.getSystemService(NotificationManager.class); |
John Spurlock | 3e309b2 | 2013-06-25 11:01:29 -0400 | [diff] [blame] | 81 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 82 | mStorageManager = mContext.getSystemService(StorageManager.class); |
| 83 | mStorageManager.registerListener(mListener); |
Daniel Sandler | 5b8743f | 2010-11-03 09:43:46 -0400 | [diff] [blame] | 84 | |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 85 | mContext.registerReceiver(mSnoozeReceiver, new IntentFilter(ACTION_SNOOZE_VOLUME), |
| 86 | android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS, null); |
| 87 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 88 | // Kick current state into place |
| 89 | final List<VolumeInfo> vols = mStorageManager.getVolumes(); |
| 90 | for (VolumeInfo vol : vols) { |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 91 | onVolumeStateChangedInternal(vol, vol.getState(), vol.getState()); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 95 | public void onVolumeStateChangedInternal(VolumeInfo vol, int oldState, int newState) { |
| 96 | // We only care about public volumes |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 97 | if (vol.getType() != VolumeInfo.TYPE_PUBLIC) { |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 98 | return; |
| 99 | } |
| 100 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 101 | Log.d(TAG, vol.toString()); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 102 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 103 | final Notification notif; |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 104 | switch (newState) { |
| 105 | case VolumeInfo.STATE_UNMOUNTED: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 106 | notif = onVolumeUnmounted(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 107 | break; |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 108 | case VolumeInfo.STATE_CHECKING: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 109 | notif = onVolumeChecking(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 110 | break; |
| 111 | case VolumeInfo.STATE_MOUNTED: |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 112 | case VolumeInfo.STATE_MOUNTED_READ_ONLY: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 113 | notif = onVolumeMounted(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 114 | break; |
| 115 | case VolumeInfo.STATE_FORMATTING: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 116 | notif = onVolumeFormatting(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 117 | break; |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 118 | case VolumeInfo.STATE_EJECTING: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 119 | notif = onVolumeEjecting(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 120 | break; |
| 121 | case VolumeInfo.STATE_UNMOUNTABLE: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 122 | notif = onVolumeUnmountable(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 123 | break; |
| 124 | case VolumeInfo.STATE_REMOVED: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 125 | notif = onVolumeRemoved(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 126 | break; |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 127 | case VolumeInfo.STATE_BAD_REMOVAL: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 128 | notif = onVolumeBadRemoval(vol); |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 129 | break; |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 130 | default: |
| 131 | notif = null; |
| 132 | break; |
| 133 | } |
| 134 | |
| 135 | if (notif != null) { |
| 136 | mNotificationManager.notifyAsUser(vol.getId(), NOTIF_ID, notif, UserHandle.ALL); |
| 137 | } else { |
| 138 | mNotificationManager.cancelAsUser(vol.getId(), NOTIF_ID, UserHandle.ALL); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 142 | private Notification onVolumeUnmounted(VolumeInfo vol) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 143 | // Ignored |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 144 | return null; |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 145 | } |
| 146 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 147 | private Notification onVolumeChecking(VolumeInfo vol) { |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 148 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 149 | final CharSequence title = mContext.getString( |
| 150 | R.string.ext_media_checking_notification_title, disk.getDescription()); |
| 151 | final CharSequence text = mContext.getString( |
| 152 | R.string.ext_media_checking_notification_message, disk.getDescription()); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 153 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 154 | return buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 155 | .setCategory(Notification.CATEGORY_PROGRESS) |
| 156 | .setPriority(Notification.PRIORITY_LOW) |
| 157 | .setOngoing(true) |
| 158 | .build(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 159 | } |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 160 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 161 | private Notification onVolumeMounted(VolumeInfo vol) { |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 162 | // Don't annoy when user dismissed in past |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 163 | if (vol.isSnoozed()) return null; |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 164 | |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 165 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 166 | if (disk.isAdoptable() && !vol.isInited()) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 167 | final CharSequence title = disk.getDescription(); |
| 168 | final CharSequence text = mContext.getString( |
| 169 | R.string.ext_media_new_notification_message, disk.getDescription()); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 170 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 171 | return buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 172 | .addAction(new Action(0, mContext.getString(R.string.ext_media_init_action), |
| 173 | buildInitPendingIntent(vol))) |
| 174 | .addAction(new Action(0, mContext.getString(R.string.ext_media_unmount_action), |
| 175 | buildUnmountPendingIntent(vol))) |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 176 | .setDeleteIntent(buildSnoozeIntent(vol)) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 177 | .setCategory(Notification.CATEGORY_SYSTEM) |
| 178 | .build(); |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 179 | |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 180 | } else { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 181 | final CharSequence title = disk.getDescription(); |
| 182 | final CharSequence text = mContext.getString( |
| 183 | R.string.ext_media_ready_notification_message, disk.getDescription()); |
| 184 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 185 | return buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 186 | .addAction(new Action(0, mContext.getString(R.string.ext_media_browse_action), |
| 187 | buildBrowsePendingIntent(vol))) |
| 188 | .addAction(new Action(0, mContext.getString(R.string.ext_media_unmount_action), |
| 189 | buildUnmountPendingIntent(vol))) |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 190 | .setDeleteIntent(buildSnoozeIntent(vol)) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 191 | .setCategory(Notification.CATEGORY_SYSTEM) |
| 192 | .setPriority(Notification.PRIORITY_LOW) |
| 193 | .build(); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 194 | } |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 197 | private Notification onVolumeFormatting(VolumeInfo vol) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 198 | // Ignored |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 199 | return null; |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 202 | private Notification onVolumeEjecting(VolumeInfo vol) { |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 203 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 204 | final CharSequence title = mContext.getString( |
| 205 | R.string.ext_media_unmounting_notification_title, disk.getDescription()); |
| 206 | final CharSequence text = mContext.getString( |
| 207 | R.string.ext_media_unmounting_notification_message, disk.getDescription()); |
| 208 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 209 | return buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 210 | .setCategory(Notification.CATEGORY_PROGRESS) |
| 211 | .setPriority(Notification.PRIORITY_LOW) |
| 212 | .setOngoing(true) |
| 213 | .build(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 216 | private Notification onVolumeUnmountable(VolumeInfo vol) { |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 217 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 218 | final CharSequence title = mContext.getString( |
| 219 | R.string.ext_media_unmountable_notification_title, disk.getDescription()); |
| 220 | final CharSequence text = mContext.getString( |
| 221 | R.string.ext_media_unmountable_notification_message, disk.getDescription()); |
| 222 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 223 | return buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 224 | .setContentIntent(buildDetailsPendingIntent(vol)) |
| 225 | .setCategory(Notification.CATEGORY_ERROR) |
| 226 | .build(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 229 | private Notification onVolumeRemoved(VolumeInfo vol) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 230 | if (!vol.isPrimary()) { |
| 231 | // Ignore non-primary media |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 232 | return null; |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 235 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 236 | final CharSequence title = mContext.getString( |
| 237 | R.string.ext_media_nomedia_notification_title, disk.getDescription()); |
| 238 | final CharSequence text = mContext.getString( |
| 239 | R.string.ext_media_nomedia_notification_message, disk.getDescription()); |
| 240 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 241 | return buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 242 | .setCategory(Notification.CATEGORY_ERROR) |
| 243 | .build(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 246 | private Notification onVolumeBadRemoval(VolumeInfo vol) { |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 247 | if (!vol.isPrimary()) { |
| 248 | // Ignore non-primary media |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 249 | return null; |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 252 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 253 | final CharSequence title = mContext.getString( |
| 254 | R.string.ext_media_badremoval_notification_title, disk.getDescription()); |
| 255 | final CharSequence text = mContext.getString( |
| 256 | R.string.ext_media_badremoval_notification_message, disk.getDescription()); |
| 257 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 258 | return buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 259 | .setCategory(Notification.CATEGORY_ERROR) |
| 260 | .build(); |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 263 | private int getSmallIcon(VolumeInfo vol) { |
| 264 | if (vol.disk.isSd()) { |
| 265 | switch (vol.getState()) { |
| 266 | case VolumeInfo.STATE_CHECKING: |
| 267 | case VolumeInfo.STATE_EJECTING: |
| 268 | return R.drawable.stat_notify_sdcard_prepare; |
| 269 | default: |
| 270 | return R.drawable.stat_notify_sdcard; |
| 271 | } |
| 272 | } else if (vol.disk.isUsb()) { |
| 273 | return R.drawable.stat_sys_data_usb; |
| 274 | } else { |
| 275 | return R.drawable.stat_notify_sdcard; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | private Notification.Builder buildNotificationBuilder(VolumeInfo vol, CharSequence title, |
| 280 | CharSequence text) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 281 | return new Notification.Builder(mContext) |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame^] | 282 | .setSmallIcon(getSmallIcon(vol)) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 283 | .setColor(mContext.getColor(R.color.system_notification_accent_color)) |
| 284 | .setContentTitle(title) |
| 285 | .setContentText(text) |
| 286 | .setStyle(new Notification.BigTextStyle().bigText(text)) |
| 287 | .setVisibility(Notification.VISIBILITY_PUBLIC) |
| 288 | .setLocalOnly(true); |
| 289 | } |
| 290 | |
| 291 | private PendingIntent buildInitPendingIntent(VolumeInfo vol) { |
| 292 | final Intent intent = new Intent(); |
| 293 | intent.setClassName("com.android.settings", |
| 294 | "com.android.settings.deviceinfo.StorageWizardInit"); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 295 | intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId()); |
| 296 | |
| 297 | final int requestKey = vol.getId().hashCode(); |
| 298 | return PendingIntent.getActivityAsUser(mContext, requestKey, intent, |
| 299 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | private PendingIntent buildUnmountPendingIntent(VolumeInfo vol) { |
| 303 | final Intent intent = new Intent(); |
| 304 | intent.setClassName("com.android.settings", |
| 305 | "com.android.settings.deviceinfo.StorageUnmountReceiver"); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 306 | intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId()); |
| 307 | |
| 308 | final int requestKey = vol.getId().hashCode(); |
| 309 | return PendingIntent.getBroadcastAsUser(mContext, requestKey, intent, |
| 310 | PendingIntent.FLAG_CANCEL_CURRENT, UserHandle.CURRENT); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | private PendingIntent buildBrowsePendingIntent(VolumeInfo vol) { |
| 314 | final Intent intent = vol.buildBrowseIntent(); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 315 | |
| 316 | final int requestKey = vol.getId().hashCode(); |
| 317 | return PendingIntent.getActivityAsUser(mContext, requestKey, intent, |
| 318 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | private PendingIntent buildDetailsPendingIntent(VolumeInfo vol) { |
| 322 | final Intent intent = new Intent(); |
| 323 | intent.setClassName("com.android.settings", |
| 324 | "com.android.settings.Settings$StorageVolumeSettingsActivity"); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 325 | intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId()); |
| 326 | |
| 327 | final int requestKey = vol.getId().hashCode(); |
| 328 | return PendingIntent.getActivityAsUser(mContext, requestKey, intent, |
| 329 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
| 330 | } |
| 331 | |
| 332 | private PendingIntent buildSnoozeIntent(VolumeInfo vol) { |
| 333 | final Intent intent = new Intent(ACTION_SNOOZE_VOLUME); |
| 334 | intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId()); |
| 335 | |
| 336 | final int requestKey = vol.getId().hashCode(); |
| 337 | return PendingIntent.getBroadcastAsUser(mContext, requestKey, intent, |
| 338 | PendingIntent.FLAG_CANCEL_CURRENT, UserHandle.CURRENT); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 339 | } |
| 340 | } |