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 | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 103 | // New state means we tear down any old notifications |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 104 | mNotificationManager.cancelAsUser(vol.getId(), NOTIF_ID, UserHandle.ALL); |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 105 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 106 | switch (newState) { |
| 107 | case VolumeInfo.STATE_UNMOUNTED: |
| 108 | onVolumeUnmounted(vol); |
| 109 | break; |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 110 | case VolumeInfo.STATE_CHECKING: |
| 111 | onVolumeChecking(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 112 | break; |
| 113 | case VolumeInfo.STATE_MOUNTED: |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame^] | 114 | case VolumeInfo.STATE_MOUNTED_READ_ONLY: |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 115 | onVolumeMounted(vol); |
| 116 | break; |
| 117 | case VolumeInfo.STATE_FORMATTING: |
| 118 | onVolumeFormatting(vol); |
| 119 | break; |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 120 | case VolumeInfo.STATE_EJECTING: |
| 121 | onVolumeEjecting(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 122 | break; |
| 123 | case VolumeInfo.STATE_UNMOUNTABLE: |
| 124 | onVolumeUnmountable(vol); |
| 125 | break; |
| 126 | case VolumeInfo.STATE_REMOVED: |
| 127 | onVolumeRemoved(vol); |
| 128 | break; |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 129 | case VolumeInfo.STATE_BAD_REMOVAL: |
| 130 | onVolumeBadRemoval(vol); |
| 131 | break; |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 135 | private void onVolumeUnmounted(VolumeInfo vol) { |
| 136 | // Ignored |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 137 | } |
| 138 | |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 139 | private void onVolumeChecking(VolumeInfo vol) { |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame^] | 140 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 141 | final CharSequence title = mContext.getString( |
| 142 | R.string.ext_media_checking_notification_title, disk.getDescription()); |
| 143 | final CharSequence text = mContext.getString( |
| 144 | R.string.ext_media_checking_notification_message, disk.getDescription()); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 145 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 146 | final Notification notif = buildNotificationBuilder(title, text) |
| 147 | .setSmallIcon(R.drawable.stat_notify_sdcard_prepare) |
| 148 | .setCategory(Notification.CATEGORY_PROGRESS) |
| 149 | .setPriority(Notification.PRIORITY_LOW) |
| 150 | .setOngoing(true) |
| 151 | .build(); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 152 | |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 153 | mNotificationManager.notifyAsUser(vol.getId(), NOTIF_ID, notif, UserHandle.ALL); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 154 | } |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 155 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 156 | private void onVolumeMounted(VolumeInfo vol) { |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 157 | // Don't annoy when user dismissed in past |
| 158 | if (vol.isSnoozed()) return; |
| 159 | |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame^] | 160 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 161 | final Notification notif; |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 162 | if (disk.isAdoptable() && !vol.isInited()) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 163 | final CharSequence title = disk.getDescription(); |
| 164 | final CharSequence text = mContext.getString( |
| 165 | R.string.ext_media_new_notification_message, disk.getDescription()); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 166 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 167 | notif = buildNotificationBuilder(title, text) |
| 168 | .setSmallIcon(R.drawable.stat_notify_sdcard) |
| 169 | .addAction(new Action(0, mContext.getString(R.string.ext_media_init_action), |
| 170 | buildInitPendingIntent(vol))) |
| 171 | .addAction(new Action(0, mContext.getString(R.string.ext_media_unmount_action), |
| 172 | buildUnmountPendingIntent(vol))) |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 173 | .setDeleteIntent(buildSnoozeIntent(vol)) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 174 | .setCategory(Notification.CATEGORY_SYSTEM) |
| 175 | .build(); |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 176 | |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 177 | } else { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 178 | final CharSequence title = disk.getDescription(); |
| 179 | final CharSequence text = mContext.getString( |
| 180 | R.string.ext_media_ready_notification_message, disk.getDescription()); |
| 181 | |
| 182 | notif = buildNotificationBuilder(title, text) |
| 183 | .setSmallIcon(R.drawable.stat_notify_sdcard) |
| 184 | .addAction(new Action(0, mContext.getString(R.string.ext_media_browse_action), |
| 185 | buildBrowsePendingIntent(vol))) |
| 186 | .addAction(new Action(0, mContext.getString(R.string.ext_media_unmount_action), |
| 187 | buildUnmountPendingIntent(vol))) |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 188 | .setDeleteIntent(buildSnoozeIntent(vol)) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 189 | .setCategory(Notification.CATEGORY_SYSTEM) |
| 190 | .setPriority(Notification.PRIORITY_LOW) |
| 191 | .build(); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 192 | } |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 193 | |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 194 | mNotificationManager.notifyAsUser(vol.getId(), NOTIF_ID, notif, UserHandle.ALL); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | private void onVolumeFormatting(VolumeInfo vol) { |
| 198 | // Ignored |
| 199 | } |
| 200 | |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 201 | private void onVolumeEjecting(VolumeInfo vol) { |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame^] | 202 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 203 | final CharSequence title = mContext.getString( |
| 204 | R.string.ext_media_unmounting_notification_title, disk.getDescription()); |
| 205 | final CharSequence text = mContext.getString( |
| 206 | R.string.ext_media_unmounting_notification_message, disk.getDescription()); |
| 207 | |
| 208 | final Notification notif = buildNotificationBuilder(title, text) |
| 209 | .setSmallIcon(R.drawable.stat_notify_sdcard_prepare) |
| 210 | .setCategory(Notification.CATEGORY_PROGRESS) |
| 211 | .setPriority(Notification.PRIORITY_LOW) |
| 212 | .setOngoing(true) |
| 213 | .build(); |
| 214 | |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 215 | mNotificationManager.notifyAsUser(vol.getId(), NOTIF_ID, notif, UserHandle.ALL); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | private void onVolumeUnmountable(VolumeInfo vol) { |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame^] | 219 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 220 | final CharSequence title = mContext.getString( |
| 221 | R.string.ext_media_unmountable_notification_title, disk.getDescription()); |
| 222 | final CharSequence text = mContext.getString( |
| 223 | R.string.ext_media_unmountable_notification_message, disk.getDescription()); |
| 224 | |
| 225 | final Notification notif = buildNotificationBuilder(title, text) |
| 226 | .setSmallIcon(R.drawable.stat_notify_sdcard) |
| 227 | .setContentIntent(buildDetailsPendingIntent(vol)) |
| 228 | .setCategory(Notification.CATEGORY_ERROR) |
| 229 | .build(); |
| 230 | |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 231 | mNotificationManager.notifyAsUser(vol.getId(), NOTIF_ID, notif, UserHandle.ALL); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | private void onVolumeRemoved(VolumeInfo vol) { |
| 235 | if (!vol.isPrimary()) { |
| 236 | // Ignore non-primary media |
| 237 | return; |
| 238 | } |
| 239 | |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame^] | 240 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 241 | final CharSequence title = mContext.getString( |
| 242 | R.string.ext_media_nomedia_notification_title, disk.getDescription()); |
| 243 | final CharSequence text = mContext.getString( |
| 244 | R.string.ext_media_nomedia_notification_message, disk.getDescription()); |
| 245 | |
| 246 | final Notification notif = buildNotificationBuilder(title, text) |
| 247 | .setSmallIcon(R.drawable.stat_notify_sdcard) |
| 248 | .setCategory(Notification.CATEGORY_ERROR) |
| 249 | .build(); |
| 250 | |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 251 | mNotificationManager.notifyAsUser(vol.getId(), NOTIF_ID, notif, UserHandle.ALL); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 254 | private void onVolumeBadRemoval(VolumeInfo vol) { |
| 255 | if (!vol.isPrimary()) { |
| 256 | // Ignore non-primary media |
| 257 | return; |
| 258 | } |
| 259 | |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame^] | 260 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 261 | final CharSequence title = mContext.getString( |
| 262 | R.string.ext_media_badremoval_notification_title, disk.getDescription()); |
| 263 | final CharSequence text = mContext.getString( |
| 264 | R.string.ext_media_badremoval_notification_message, disk.getDescription()); |
| 265 | |
| 266 | final Notification notif = buildNotificationBuilder(title, text) |
| 267 | .setSmallIcon(R.drawable.stat_notify_sdcard) |
| 268 | .setCategory(Notification.CATEGORY_ERROR) |
| 269 | .build(); |
| 270 | |
| 271 | mNotificationManager.notifyAsUser(vol.getId(), NOTIF_ID, notif, UserHandle.ALL); |
| 272 | } |
| 273 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 274 | private Notification.Builder buildNotificationBuilder(CharSequence title, CharSequence text) { |
| 275 | return new Notification.Builder(mContext) |
| 276 | .setColor(mContext.getColor(R.color.system_notification_accent_color)) |
| 277 | .setContentTitle(title) |
| 278 | .setContentText(text) |
| 279 | .setStyle(new Notification.BigTextStyle().bigText(text)) |
| 280 | .setVisibility(Notification.VISIBILITY_PUBLIC) |
| 281 | .setLocalOnly(true); |
| 282 | } |
| 283 | |
| 284 | private PendingIntent buildInitPendingIntent(VolumeInfo vol) { |
| 285 | final Intent intent = new Intent(); |
| 286 | intent.setClassName("com.android.settings", |
| 287 | "com.android.settings.deviceinfo.StorageWizardInit"); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 288 | intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId()); |
| 289 | |
| 290 | final int requestKey = vol.getId().hashCode(); |
| 291 | return PendingIntent.getActivityAsUser(mContext, requestKey, intent, |
| 292 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | private PendingIntent buildUnmountPendingIntent(VolumeInfo vol) { |
| 296 | final Intent intent = new Intent(); |
| 297 | intent.setClassName("com.android.settings", |
| 298 | "com.android.settings.deviceinfo.StorageUnmountReceiver"); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 299 | intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId()); |
| 300 | |
| 301 | final int requestKey = vol.getId().hashCode(); |
| 302 | return PendingIntent.getBroadcastAsUser(mContext, requestKey, intent, |
| 303 | PendingIntent.FLAG_CANCEL_CURRENT, UserHandle.CURRENT); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | private PendingIntent buildBrowsePendingIntent(VolumeInfo vol) { |
| 307 | final Intent intent = vol.buildBrowseIntent(); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 308 | |
| 309 | final int requestKey = vol.getId().hashCode(); |
| 310 | return PendingIntent.getActivityAsUser(mContext, requestKey, intent, |
| 311 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | private PendingIntent buildDetailsPendingIntent(VolumeInfo vol) { |
| 315 | final Intent intent = new Intent(); |
| 316 | intent.setClassName("com.android.settings", |
| 317 | "com.android.settings.Settings$StorageVolumeSettingsActivity"); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 318 | intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId()); |
| 319 | |
| 320 | final int requestKey = vol.getId().hashCode(); |
| 321 | return PendingIntent.getActivityAsUser(mContext, requestKey, intent, |
| 322 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
| 323 | } |
| 324 | |
| 325 | private PendingIntent buildSnoozeIntent(VolumeInfo vol) { |
| 326 | final Intent intent = new Intent(ACTION_SNOOZE_VOLUME); |
| 327 | intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId()); |
| 328 | |
| 329 | final int requestKey = vol.getId().hashCode(); |
| 330 | return PendingIntent.getBroadcastAsUser(mContext, requestKey, intent, |
| 331 | PendingIntent.FLAG_CANCEL_CURRENT, UserHandle.CURRENT); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 332 | } |
| 333 | } |