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 | |
Philip P. Moltmann | 75b230b | 2016-04-11 15:27:58 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 20 | import android.app.Notification; |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 21 | import android.app.Notification.Action; |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 22 | import android.app.NotificationManager; |
| 23 | import android.app.PendingIntent; |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 24 | import android.content.BroadcastReceiver; |
| 25 | import android.content.Context; |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 26 | import android.content.Intent; |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 27 | import android.content.IntentFilter; |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 28 | import android.content.pm.PackageManager; |
| 29 | import android.content.pm.PackageManager.MoveCallback; |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 30 | import android.os.Bundle; |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 31 | import android.os.Handler; |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 32 | import android.os.UserHandle; |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 33 | import android.os.storage.DiskInfo; |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 34 | import android.os.storage.StorageEventListener; |
| 35 | import android.os.storage.StorageManager; |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 36 | import android.os.storage.VolumeInfo; |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 37 | import android.os.storage.VolumeRecord; |
| 38 | import android.text.TextUtils; |
| 39 | import android.text.format.DateUtils; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 40 | import android.util.Log; |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 41 | import android.util.SparseArray; |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 42 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 43 | import com.android.internal.R; |
John Spurlock | 3e309b2 | 2013-06-25 11:01:29 -0400 | [diff] [blame] | 44 | import com.android.systemui.SystemUI; |
| 45 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 46 | import java.util.List; |
| 47 | |
John Spurlock | 3e309b2 | 2013-06-25 11:01:29 -0400 | [diff] [blame] | 48 | public class StorageNotification extends SystemUI { |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 49 | private static final String TAG = "StorageNotification"; |
| 50 | |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 51 | private static final int PUBLIC_ID = 0x53505542; // SPUB |
| 52 | private static final int PRIVATE_ID = 0x53505256; // SPRV |
| 53 | private static final int DISK_ID = 0x5344534b; // SDSK |
| 54 | private static final int MOVE_ID = 0x534d4f56; // SMOV |
Daniel Sandler | c07907e | 2010-02-22 15:08:41 -0500 | [diff] [blame] | 55 | |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 56 | private static final String ACTION_SNOOZE_VOLUME = "com.android.systemui.action.SNOOZE_VOLUME"; |
Jeff Sharkey | df27d3b | 2015-06-16 13:51:48 -0700 | [diff] [blame] | 57 | private static final String ACTION_FINISH_WIZARD = "com.android.systemui.action.FINISH_WIZARD"; |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 58 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 59 | // TODO: delay some notifications to avoid bumpy fast operations |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 60 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 61 | private NotificationManager mNotificationManager; |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 62 | private StorageManager mStorageManager; |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 63 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 64 | private static class MoveInfo { |
| 65 | public int moveId; |
| 66 | public Bundle extras; |
| 67 | public String packageName; |
| 68 | public String label; |
| 69 | public String volumeUuid; |
| 70 | } |
| 71 | |
| 72 | private final SparseArray<MoveInfo> mMoves = new SparseArray<>(); |
| 73 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 74 | private final StorageEventListener mListener = new StorageEventListener() { |
| 75 | @Override |
| 76 | public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState) { |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 77 | onVolumeStateChangedInternal(vol); |
John Spurlock | 3e309b2 | 2013-06-25 11:01:29 -0400 | [diff] [blame] | 78 | } |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 79 | |
| 80 | @Override |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 81 | public void onVolumeRecordChanged(VolumeRecord rec) { |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 82 | // Avoid kicking notifications when getting early metadata before |
| 83 | // mounted. If already mounted, we're being kicked because of a |
| 84 | // nickname or init'ed change. |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 85 | final VolumeInfo vol = mStorageManager.findVolumeByUuid(rec.getFsUuid()); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 86 | if (vol != null && vol.isMountedReadable()) { |
| 87 | onVolumeStateChangedInternal(vol); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 88 | } |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 89 | } |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 90 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 91 | @Override |
| 92 | public void onVolumeForgotten(String fsUuid) { |
| 93 | // Stop annoying the user |
| 94 | mNotificationManager.cancelAsUser(fsUuid, PRIVATE_ID, UserHandle.ALL); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public void onDiskScanned(DiskInfo disk, int volumeCount) { |
| 99 | onDiskScannedInternal(disk, volumeCount); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 100 | } |
Philip P. Moltmann | 75b230b | 2016-04-11 15:27:58 -0700 | [diff] [blame] | 101 | |
| 102 | @Override |
| 103 | public void onDiskDestroyed(DiskInfo disk) { |
| 104 | onDiskDestroyedInternal(disk); |
| 105 | } |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | private final BroadcastReceiver mSnoozeReceiver = new BroadcastReceiver() { |
| 109 | @Override |
| 110 | public void onReceive(Context context, Intent intent) { |
| 111 | // TODO: kick this onto background thread |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 112 | final String fsUuid = intent.getStringExtra(VolumeRecord.EXTRA_FS_UUID); |
| 113 | mStorageManager.setVolumeSnoozed(fsUuid, true); |
| 114 | } |
| 115 | }; |
| 116 | |
Jeff Sharkey | df27d3b | 2015-06-16 13:51:48 -0700 | [diff] [blame] | 117 | private final BroadcastReceiver mFinishReceiver = new BroadcastReceiver() { |
| 118 | @Override |
| 119 | public void onReceive(Context context, Intent intent) { |
| 120 | // When finishing the adoption wizard, clean up any notifications |
| 121 | // for moving primary storage |
| 122 | mNotificationManager.cancelAsUser(null, MOVE_ID, UserHandle.ALL); |
| 123 | } |
| 124 | }; |
| 125 | |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 126 | private final MoveCallback mMoveCallback = new MoveCallback() { |
| 127 | @Override |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 128 | public void onCreated(int moveId, Bundle extras) { |
| 129 | final MoveInfo move = new MoveInfo(); |
| 130 | move.moveId = moveId; |
| 131 | move.extras = extras; |
| 132 | if (extras != null) { |
| 133 | move.packageName = extras.getString(Intent.EXTRA_PACKAGE_NAME); |
| 134 | move.label = extras.getString(Intent.EXTRA_TITLE); |
| 135 | move.volumeUuid = extras.getString(VolumeRecord.EXTRA_FS_UUID); |
| 136 | } |
| 137 | mMoves.put(moveId, move); |
| 138 | } |
| 139 | |
| 140 | @Override |
| 141 | public void onStatusChanged(int moveId, int status, long estMillis) { |
| 142 | final MoveInfo move = mMoves.get(moveId); |
| 143 | if (move == null) { |
| 144 | Log.w(TAG, "Ignoring unknown move " + moveId); |
| 145 | return; |
| 146 | } |
| 147 | |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 148 | if (PackageManager.isMoveStatusFinished(status)) { |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 149 | onMoveFinished(move, status); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 150 | } else { |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 151 | onMoveProgress(move, status, estMillis); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 152 | } |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 153 | } |
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 | |
John Spurlock | 3e309b2 | 2013-06-25 11:01:29 -0400 | [diff] [blame] | 156 | @Override |
| 157 | public void start() { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 158 | mNotificationManager = mContext.getSystemService(NotificationManager.class); |
John Spurlock | 3e309b2 | 2013-06-25 11:01:29 -0400 | [diff] [blame] | 159 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 160 | mStorageManager = mContext.getSystemService(StorageManager.class); |
| 161 | mStorageManager.registerListener(mListener); |
Daniel Sandler | 5b8743f | 2010-11-03 09:43:46 -0400 | [diff] [blame] | 162 | |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 163 | mContext.registerReceiver(mSnoozeReceiver, new IntentFilter(ACTION_SNOOZE_VOLUME), |
| 164 | android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS, null); |
Jeff Sharkey | df27d3b | 2015-06-16 13:51:48 -0700 | [diff] [blame] | 165 | mContext.registerReceiver(mFinishReceiver, new IntentFilter(ACTION_FINISH_WIZARD), |
| 166 | android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS, null); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 167 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 168 | // Kick current state into place |
Jeff Sharkey | f5a6bd7 | 2015-05-19 14:42:38 -0700 | [diff] [blame] | 169 | final List<DiskInfo> disks = mStorageManager.getDisks(); |
| 170 | for (DiskInfo disk : disks) { |
| 171 | onDiskScannedInternal(disk, disk.volumeCount); |
| 172 | } |
| 173 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 174 | final List<VolumeInfo> vols = mStorageManager.getVolumes(); |
| 175 | for (VolumeInfo vol : vols) { |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 176 | onVolumeStateChangedInternal(vol); |
| 177 | } |
| 178 | |
| 179 | mContext.getPackageManager().registerMoveCallback(mMoveCallback, new Handler()); |
| 180 | |
| 181 | updateMissingPrivateVolumes(); |
| 182 | } |
| 183 | |
| 184 | private void updateMissingPrivateVolumes() { |
| 185 | final List<VolumeRecord> recs = mStorageManager.getVolumeRecords(); |
| 186 | for (VolumeRecord rec : recs) { |
| 187 | if (rec.getType() != VolumeInfo.TYPE_PRIVATE) continue; |
| 188 | |
| 189 | final String fsUuid = rec.getFsUuid(); |
| 190 | final VolumeInfo info = mStorageManager.findVolumeByUuid(fsUuid); |
Jeff Sharkey | 52fc3c0f | 2015-06-14 20:58:54 -0700 | [diff] [blame] | 191 | if ((info != null && info.isMountedWritable()) || rec.isSnoozed()) { |
| 192 | // Yay, private volume is here, or user snoozed |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 193 | mNotificationManager.cancelAsUser(fsUuid, PRIVATE_ID, UserHandle.ALL); |
| 194 | |
| 195 | } else { |
| 196 | // Boo, annoy the user to reinsert the private volume |
| 197 | final CharSequence title = mContext.getString(R.string.ext_media_missing_title, |
| 198 | rec.getNickname()); |
| 199 | final CharSequence text = mContext.getString(R.string.ext_media_missing_message); |
| 200 | |
| 201 | final Notification notif = new Notification.Builder(mContext) |
Jeff Sharkey | a49d5fc | 2015-05-13 11:40:30 -0700 | [diff] [blame] | 202 | .setSmallIcon(R.drawable.ic_sd_card_48dp) |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 203 | .setColor(mContext.getColor(R.color.system_notification_accent_color)) |
| 204 | .setContentTitle(title) |
| 205 | .setContentText(text) |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 206 | .setContentIntent(buildForgetPendingIntent(rec)) |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 207 | .setStyle(new Notification.BigTextStyle().bigText(text)) |
| 208 | .setVisibility(Notification.VISIBILITY_PUBLIC) |
| 209 | .setLocalOnly(true) |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 210 | .setCategory(Notification.CATEGORY_SYSTEM) |
Jeff Sharkey | 52fc3c0f | 2015-06-14 20:58:54 -0700 | [diff] [blame] | 211 | .setDeleteIntent(buildSnoozeIntent(fsUuid)) |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 212 | .build(); |
| 213 | |
| 214 | mNotificationManager.notifyAsUser(fsUuid, PRIVATE_ID, notif, UserHandle.ALL); |
| 215 | } |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 219 | private void onDiskScannedInternal(DiskInfo disk, int volumeCount) { |
Jeff Sharkey | f5a6bd7 | 2015-05-19 14:42:38 -0700 | [diff] [blame] | 220 | if (volumeCount == 0 && disk.size > 0) { |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 221 | // No supported volumes found, give user option to format |
| 222 | final CharSequence title = mContext.getString( |
Jeff Sharkey | 52fc3c0f | 2015-06-14 20:58:54 -0700 | [diff] [blame] | 223 | R.string.ext_media_unsupported_notification_title, disk.getDescription()); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 224 | final CharSequence text = mContext.getString( |
Jeff Sharkey | 52fc3c0f | 2015-06-14 20:58:54 -0700 | [diff] [blame] | 225 | R.string.ext_media_unsupported_notification_message, disk.getDescription()); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 226 | |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 227 | final Notification notif = new Notification.Builder(mContext) |
| 228 | .setSmallIcon(getSmallIcon(disk, VolumeInfo.STATE_UNMOUNTABLE)) |
| 229 | .setColor(mContext.getColor(R.color.system_notification_accent_color)) |
| 230 | .setContentTitle(title) |
| 231 | .setContentText(text) |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 232 | .setContentIntent(buildInitPendingIntent(disk)) |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 233 | .setStyle(new Notification.BigTextStyle().bigText(text)) |
| 234 | .setVisibility(Notification.VISIBILITY_PUBLIC) |
| 235 | .setLocalOnly(true) |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 236 | .setCategory(Notification.CATEGORY_ERROR) |
| 237 | .build(); |
| 238 | |
| 239 | mNotificationManager.notifyAsUser(disk.getId(), DISK_ID, notif, UserHandle.ALL); |
| 240 | |
| 241 | } else { |
| 242 | // Yay, we have volumes! |
| 243 | mNotificationManager.cancelAsUser(disk.getId(), DISK_ID, UserHandle.ALL); |
| 244 | } |
| 245 | } |
| 246 | |
Philip P. Moltmann | 75b230b | 2016-04-11 15:27:58 -0700 | [diff] [blame] | 247 | /** |
| 248 | * Remove all notifications for a disk when it goes away. |
| 249 | * |
| 250 | * @param disk The disk that went away. |
| 251 | */ |
| 252 | private void onDiskDestroyedInternal(@NonNull DiskInfo disk) { |
| 253 | mNotificationManager.cancelAsUser(disk.getId(), DISK_ID, UserHandle.ALL); |
| 254 | } |
| 255 | |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 256 | private void onVolumeStateChangedInternal(VolumeInfo vol) { |
| 257 | switch (vol.getType()) { |
| 258 | case VolumeInfo.TYPE_PRIVATE: |
| 259 | onPrivateVolumeStateChangedInternal(vol); |
| 260 | break; |
| 261 | case VolumeInfo.TYPE_PUBLIC: |
| 262 | onPublicVolumeStateChangedInternal(vol); |
| 263 | break; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | private void onPrivateVolumeStateChangedInternal(VolumeInfo vol) { |
| 268 | Log.d(TAG, "Notifying about private volume: " + vol.toString()); |
| 269 | |
| 270 | updateMissingPrivateVolumes(); |
| 271 | } |
| 272 | |
| 273 | private void onPublicVolumeStateChangedInternal(VolumeInfo vol) { |
| 274 | Log.d(TAG, "Notifying about public volume: " + vol.toString()); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 275 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 276 | final Notification notif; |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 277 | switch (vol.getState()) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 278 | case VolumeInfo.STATE_UNMOUNTED: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 279 | notif = onVolumeUnmounted(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 280 | break; |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 281 | case VolumeInfo.STATE_CHECKING: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 282 | notif = onVolumeChecking(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 283 | break; |
| 284 | case VolumeInfo.STATE_MOUNTED: |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 285 | case VolumeInfo.STATE_MOUNTED_READ_ONLY: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 286 | notif = onVolumeMounted(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 287 | break; |
| 288 | case VolumeInfo.STATE_FORMATTING: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 289 | notif = onVolumeFormatting(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 290 | break; |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 291 | case VolumeInfo.STATE_EJECTING: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 292 | notif = onVolumeEjecting(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 293 | break; |
| 294 | case VolumeInfo.STATE_UNMOUNTABLE: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 295 | notif = onVolumeUnmountable(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 296 | break; |
| 297 | case VolumeInfo.STATE_REMOVED: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 298 | notif = onVolumeRemoved(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 299 | break; |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 300 | case VolumeInfo.STATE_BAD_REMOVAL: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 301 | notif = onVolumeBadRemoval(vol); |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 302 | break; |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 303 | default: |
| 304 | notif = null; |
| 305 | break; |
| 306 | } |
| 307 | |
| 308 | if (notif != null) { |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 309 | mNotificationManager.notifyAsUser(vol.getId(), PUBLIC_ID, notif, UserHandle.ALL); |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 310 | } else { |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 311 | mNotificationManager.cancelAsUser(vol.getId(), PUBLIC_ID, UserHandle.ALL); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 315 | private Notification onVolumeUnmounted(VolumeInfo vol) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 316 | // Ignored |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 317 | return null; |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 320 | private Notification onVolumeChecking(VolumeInfo vol) { |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 321 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 322 | final CharSequence title = mContext.getString( |
| 323 | R.string.ext_media_checking_notification_title, disk.getDescription()); |
| 324 | final CharSequence text = mContext.getString( |
| 325 | R.string.ext_media_checking_notification_message, disk.getDescription()); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 326 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 327 | return buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 328 | .setCategory(Notification.CATEGORY_PROGRESS) |
| 329 | .setPriority(Notification.PRIORITY_LOW) |
| 330 | .setOngoing(true) |
| 331 | .build(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 332 | } |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 333 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 334 | private Notification onVolumeMounted(VolumeInfo vol) { |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 335 | final VolumeRecord rec = mStorageManager.findRecordByUuid(vol.getFsUuid()); |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 336 | final DiskInfo disk = vol.getDisk(); |
Makoto Onuki | b138cb2 | 2015-06-23 17:32:02 -0700 | [diff] [blame] | 337 | |
| 338 | // Don't annoy when user dismissed in past. (But make sure the disk is adoptable; we |
| 339 | // used to allow snoozing non-adoptable disks too.) |
| 340 | if (rec.isSnoozed() && disk.isAdoptable()) { |
| 341 | return null; |
| 342 | } |
| 343 | |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 344 | if (disk.isAdoptable() && !rec.isInited()) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 345 | final CharSequence title = disk.getDescription(); |
| 346 | final CharSequence text = mContext.getString( |
| 347 | R.string.ext_media_new_notification_message, disk.getDescription()); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 348 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 349 | final PendingIntent initIntent = buildInitPendingIntent(vol); |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 350 | return buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | a49d5fc | 2015-05-13 11:40:30 -0700 | [diff] [blame] | 351 | .addAction(new Action(R.drawable.ic_settings_24dp, |
| 352 | mContext.getString(R.string.ext_media_init_action), initIntent)) |
| 353 | .addAction(new Action(R.drawable.ic_eject_24dp, |
| 354 | mContext.getString(R.string.ext_media_unmount_action), |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 355 | buildUnmountPendingIntent(vol))) |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 356 | .setContentIntent(initIntent) |
Jeff Sharkey | 52fc3c0f | 2015-06-14 20:58:54 -0700 | [diff] [blame] | 357 | .setDeleteIntent(buildSnoozeIntent(vol.getFsUuid())) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 358 | .setCategory(Notification.CATEGORY_SYSTEM) |
| 359 | .build(); |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 360 | |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 361 | } else { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 362 | final CharSequence title = disk.getDescription(); |
| 363 | final CharSequence text = mContext.getString( |
| 364 | R.string.ext_media_ready_notification_message, disk.getDescription()); |
| 365 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 366 | final PendingIntent browseIntent = buildBrowsePendingIntent(vol); |
Makoto Onuki | b138cb2 | 2015-06-23 17:32:02 -0700 | [diff] [blame] | 367 | final Notification.Builder builder = buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | a49d5fc | 2015-05-13 11:40:30 -0700 | [diff] [blame] | 368 | .addAction(new Action(R.drawable.ic_folder_24dp, |
| 369 | mContext.getString(R.string.ext_media_browse_action), |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 370 | browseIntent)) |
Jeff Sharkey | a49d5fc | 2015-05-13 11:40:30 -0700 | [diff] [blame] | 371 | .addAction(new Action(R.drawable.ic_eject_24dp, |
| 372 | mContext.getString(R.string.ext_media_unmount_action), |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 373 | buildUnmountPendingIntent(vol))) |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 374 | .setContentIntent(browseIntent) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 375 | .setCategory(Notification.CATEGORY_SYSTEM) |
Makoto Onuki | b138cb2 | 2015-06-23 17:32:02 -0700 | [diff] [blame] | 376 | .setPriority(Notification.PRIORITY_LOW); |
| 377 | // Non-adoptable disks can't be snoozed. |
| 378 | if (disk.isAdoptable()) { |
| 379 | builder.setDeleteIntent(buildSnoozeIntent(vol.getFsUuid())); |
| 380 | } |
| 381 | |
| 382 | return builder.build(); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 383 | } |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 386 | private Notification onVolumeFormatting(VolumeInfo vol) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 387 | // Ignored |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 388 | return null; |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 391 | private Notification onVolumeEjecting(VolumeInfo vol) { |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 392 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 393 | final CharSequence title = mContext.getString( |
| 394 | R.string.ext_media_unmounting_notification_title, disk.getDescription()); |
| 395 | final CharSequence text = mContext.getString( |
| 396 | R.string.ext_media_unmounting_notification_message, disk.getDescription()); |
| 397 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 398 | return buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 399 | .setCategory(Notification.CATEGORY_PROGRESS) |
| 400 | .setPriority(Notification.PRIORITY_LOW) |
| 401 | .setOngoing(true) |
| 402 | .build(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 405 | private Notification onVolumeUnmountable(VolumeInfo vol) { |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 406 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 407 | final CharSequence title = mContext.getString( |
| 408 | R.string.ext_media_unmountable_notification_title, disk.getDescription()); |
| 409 | final CharSequence text = mContext.getString( |
| 410 | R.string.ext_media_unmountable_notification_message, disk.getDescription()); |
| 411 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 412 | return buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | 52fc3c0f | 2015-06-14 20:58:54 -0700 | [diff] [blame] | 413 | .setContentIntent(buildInitPendingIntent(vol)) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 414 | .setCategory(Notification.CATEGORY_ERROR) |
| 415 | .build(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 418 | private Notification onVolumeRemoved(VolumeInfo vol) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 419 | if (!vol.isPrimary()) { |
| 420 | // Ignore non-primary media |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 421 | return null; |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 424 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 425 | final CharSequence title = mContext.getString( |
| 426 | R.string.ext_media_nomedia_notification_title, disk.getDescription()); |
| 427 | final CharSequence text = mContext.getString( |
| 428 | R.string.ext_media_nomedia_notification_message, disk.getDescription()); |
| 429 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 430 | return buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 431 | .setCategory(Notification.CATEGORY_ERROR) |
| 432 | .build(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 435 | private Notification onVolumeBadRemoval(VolumeInfo vol) { |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 436 | if (!vol.isPrimary()) { |
| 437 | // Ignore non-primary media |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 438 | return null; |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 441 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 442 | final CharSequence title = mContext.getString( |
| 443 | R.string.ext_media_badremoval_notification_title, disk.getDescription()); |
| 444 | final CharSequence text = mContext.getString( |
| 445 | R.string.ext_media_badremoval_notification_message, disk.getDescription()); |
| 446 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 447 | return buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 448 | .setCategory(Notification.CATEGORY_ERROR) |
| 449 | .build(); |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 452 | private void onMoveProgress(MoveInfo move, int status, long estMillis) { |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 453 | final CharSequence title; |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 454 | if (!TextUtils.isEmpty(move.label)) { |
| 455 | title = mContext.getString(R.string.ext_media_move_specific_title, move.label); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 456 | } else { |
| 457 | title = mContext.getString(R.string.ext_media_move_title); |
| 458 | } |
| 459 | |
| 460 | final CharSequence text; |
| 461 | if (estMillis < 0) { |
| 462 | text = null; |
| 463 | } else { |
| 464 | text = DateUtils.formatDuration(estMillis); |
| 465 | } |
| 466 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 467 | final PendingIntent intent; |
| 468 | if (move.packageName != null) { |
| 469 | intent = buildWizardMovePendingIntent(move); |
| 470 | } else { |
| 471 | intent = buildWizardMigratePendingIntent(move); |
| 472 | } |
| 473 | |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 474 | final Notification notif = new Notification.Builder(mContext) |
Jeff Sharkey | a49d5fc | 2015-05-13 11:40:30 -0700 | [diff] [blame] | 475 | .setSmallIcon(R.drawable.ic_sd_card_48dp) |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 476 | .setColor(mContext.getColor(R.color.system_notification_accent_color)) |
| 477 | .setContentTitle(title) |
| 478 | .setContentText(text) |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 479 | .setContentIntent(intent) |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 480 | .setStyle(new Notification.BigTextStyle().bigText(text)) |
| 481 | .setVisibility(Notification.VISIBILITY_PUBLIC) |
| 482 | .setLocalOnly(true) |
| 483 | .setCategory(Notification.CATEGORY_PROGRESS) |
| 484 | .setPriority(Notification.PRIORITY_LOW) |
| 485 | .setProgress(100, status, false) |
| 486 | .setOngoing(true) |
| 487 | .build(); |
| 488 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 489 | mNotificationManager.notifyAsUser(move.packageName, MOVE_ID, notif, UserHandle.ALL); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 492 | private void onMoveFinished(MoveInfo move, int status) { |
| 493 | if (move.packageName != null) { |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 494 | // We currently ignore finished app moves; just clear the last |
| 495 | // published progress |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 496 | mNotificationManager.cancelAsUser(move.packageName, MOVE_ID, UserHandle.ALL); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 497 | return; |
| 498 | } |
| 499 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 500 | final VolumeInfo privateVol = mContext.getPackageManager().getPrimaryStorageCurrentVolume(); |
| 501 | final String descrip = mStorageManager.getBestVolumeDescription(privateVol); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 502 | |
| 503 | final CharSequence title; |
| 504 | final CharSequence text; |
| 505 | if (status == PackageManager.MOVE_SUCCEEDED) { |
| 506 | title = mContext.getString(R.string.ext_media_move_success_title); |
| 507 | text = mContext.getString(R.string.ext_media_move_success_message, descrip); |
| 508 | } else { |
| 509 | title = mContext.getString(R.string.ext_media_move_failure_title); |
| 510 | text = mContext.getString(R.string.ext_media_move_failure_message); |
| 511 | } |
| 512 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 513 | // Jump back into the wizard flow if we moved to a real disk |
| 514 | final PendingIntent intent; |
| 515 | if (privateVol != null && privateVol.getDisk() != null) { |
| 516 | intent = buildWizardReadyPendingIntent(privateVol.getDisk()); |
Jeff Sharkey | ef10ee0 | 2015-07-05 14:17:27 -0700 | [diff] [blame] | 517 | } else if (privateVol != null) { |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 518 | intent = buildVolumeSettingsPendingIntent(privateVol); |
Jeff Sharkey | ef10ee0 | 2015-07-05 14:17:27 -0700 | [diff] [blame] | 519 | } else { |
| 520 | intent = null; |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 523 | final Notification notif = new Notification.Builder(mContext) |
Jeff Sharkey | a49d5fc | 2015-05-13 11:40:30 -0700 | [diff] [blame] | 524 | .setSmallIcon(R.drawable.ic_sd_card_48dp) |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 525 | .setColor(mContext.getColor(R.color.system_notification_accent_color)) |
| 526 | .setContentTitle(title) |
| 527 | .setContentText(text) |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 528 | .setContentIntent(intent) |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 529 | .setStyle(new Notification.BigTextStyle().bigText(text)) |
| 530 | .setVisibility(Notification.VISIBILITY_PUBLIC) |
| 531 | .setLocalOnly(true) |
| 532 | .setCategory(Notification.CATEGORY_SYSTEM) |
| 533 | .setPriority(Notification.PRIORITY_LOW) |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 534 | .setAutoCancel(true) |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 535 | .build(); |
| 536 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 537 | mNotificationManager.notifyAsUser(move.packageName, MOVE_ID, notif, UserHandle.ALL); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | private int getSmallIcon(DiskInfo disk, int state) { |
| 541 | if (disk.isSd()) { |
| 542 | switch (state) { |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 543 | case VolumeInfo.STATE_CHECKING: |
| 544 | case VolumeInfo.STATE_EJECTING: |
Jeff Sharkey | a49d5fc | 2015-05-13 11:40:30 -0700 | [diff] [blame] | 545 | return R.drawable.ic_sd_card_48dp; |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 546 | default: |
Jeff Sharkey | a49d5fc | 2015-05-13 11:40:30 -0700 | [diff] [blame] | 547 | return R.drawable.ic_sd_card_48dp; |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 548 | } |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 549 | } else if (disk.isUsb()) { |
Jeff Sharkey | a49d5fc | 2015-05-13 11:40:30 -0700 | [diff] [blame] | 550 | return R.drawable.ic_usb_48dp; |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 551 | } else { |
Jeff Sharkey | a49d5fc | 2015-05-13 11:40:30 -0700 | [diff] [blame] | 552 | return R.drawable.ic_sd_card_48dp; |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 553 | } |
| 554 | } |
| 555 | |
| 556 | private Notification.Builder buildNotificationBuilder(VolumeInfo vol, CharSequence title, |
| 557 | CharSequence text) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 558 | return new Notification.Builder(mContext) |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 559 | .setSmallIcon(getSmallIcon(vol.getDisk(), vol.getState())) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 560 | .setColor(mContext.getColor(R.color.system_notification_accent_color)) |
| 561 | .setContentTitle(title) |
| 562 | .setContentText(text) |
| 563 | .setStyle(new Notification.BigTextStyle().bigText(text)) |
| 564 | .setVisibility(Notification.VISIBILITY_PUBLIC) |
| 565 | .setLocalOnly(true); |
| 566 | } |
| 567 | |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 568 | private PendingIntent buildInitPendingIntent(DiskInfo disk) { |
| 569 | final Intent intent = new Intent(); |
| 570 | intent.setClassName("com.android.settings", |
| 571 | "com.android.settings.deviceinfo.StorageWizardInit"); |
| 572 | intent.putExtra(DiskInfo.EXTRA_DISK_ID, disk.getId()); |
| 573 | |
| 574 | final int requestKey = disk.getId().hashCode(); |
| 575 | return PendingIntent.getActivityAsUser(mContext, requestKey, intent, |
| 576 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
| 577 | } |
| 578 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 579 | private PendingIntent buildInitPendingIntent(VolumeInfo vol) { |
| 580 | final Intent intent = new Intent(); |
| 581 | intent.setClassName("com.android.settings", |
| 582 | "com.android.settings.deviceinfo.StorageWizardInit"); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 583 | intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId()); |
| 584 | |
| 585 | final int requestKey = vol.getId().hashCode(); |
| 586 | return PendingIntent.getActivityAsUser(mContext, requestKey, intent, |
| 587 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | private PendingIntent buildUnmountPendingIntent(VolumeInfo vol) { |
| 591 | final Intent intent = new Intent(); |
| 592 | intent.setClassName("com.android.settings", |
| 593 | "com.android.settings.deviceinfo.StorageUnmountReceiver"); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 594 | intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId()); |
| 595 | |
| 596 | final int requestKey = vol.getId().hashCode(); |
| 597 | return PendingIntent.getBroadcastAsUser(mContext, requestKey, intent, |
| 598 | PendingIntent.FLAG_CANCEL_CURRENT, UserHandle.CURRENT); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | private PendingIntent buildBrowsePendingIntent(VolumeInfo vol) { |
| 602 | final Intent intent = vol.buildBrowseIntent(); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 603 | |
| 604 | final int requestKey = vol.getId().hashCode(); |
| 605 | return PendingIntent.getActivityAsUser(mContext, requestKey, intent, |
| 606 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 609 | private PendingIntent buildVolumeSettingsPendingIntent(VolumeInfo vol) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 610 | final Intent intent = new Intent(); |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 611 | switch (vol.getType()) { |
| 612 | case VolumeInfo.TYPE_PRIVATE: |
| 613 | intent.setClassName("com.android.settings", |
| 614 | "com.android.settings.Settings$PrivateVolumeSettingsActivity"); |
| 615 | break; |
| 616 | case VolumeInfo.TYPE_PUBLIC: |
| 617 | intent.setClassName("com.android.settings", |
| 618 | "com.android.settings.Settings$PublicVolumeSettingsActivity"); |
| 619 | break; |
| 620 | default: |
| 621 | return null; |
| 622 | } |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 623 | intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId()); |
| 624 | |
| 625 | final int requestKey = vol.getId().hashCode(); |
| 626 | return PendingIntent.getActivityAsUser(mContext, requestKey, intent, |
| 627 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
| 628 | } |
| 629 | |
Jeff Sharkey | 52fc3c0f | 2015-06-14 20:58:54 -0700 | [diff] [blame] | 630 | private PendingIntent buildSnoozeIntent(String fsUuid) { |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 631 | final Intent intent = new Intent(ACTION_SNOOZE_VOLUME); |
Jeff Sharkey | 52fc3c0f | 2015-06-14 20:58:54 -0700 | [diff] [blame] | 632 | intent.putExtra(VolumeRecord.EXTRA_FS_UUID, fsUuid); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 633 | |
Jeff Sharkey | 52fc3c0f | 2015-06-14 20:58:54 -0700 | [diff] [blame] | 634 | final int requestKey = fsUuid.hashCode(); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 635 | return PendingIntent.getBroadcastAsUser(mContext, requestKey, intent, |
| 636 | PendingIntent.FLAG_CANCEL_CURRENT, UserHandle.CURRENT); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 637 | } |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 638 | |
| 639 | private PendingIntent buildForgetPendingIntent(VolumeRecord rec) { |
| 640 | final Intent intent = new Intent(); |
| 641 | intent.setClassName("com.android.settings", |
| 642 | "com.android.settings.Settings$PrivateVolumeForgetActivity"); |
| 643 | intent.putExtra(VolumeRecord.EXTRA_FS_UUID, rec.getFsUuid()); |
| 644 | |
| 645 | final int requestKey = rec.getFsUuid().hashCode(); |
| 646 | return PendingIntent.getActivityAsUser(mContext, requestKey, intent, |
| 647 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
| 648 | } |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 649 | |
| 650 | private PendingIntent buildWizardMigratePendingIntent(MoveInfo move) { |
| 651 | final Intent intent = new Intent(); |
| 652 | intent.setClassName("com.android.settings", |
| 653 | "com.android.settings.deviceinfo.StorageWizardMigrateProgress"); |
| 654 | intent.putExtra(PackageManager.EXTRA_MOVE_ID, move.moveId); |
| 655 | |
| 656 | final VolumeInfo vol = mStorageManager.findVolumeByQualifiedUuid(move.volumeUuid); |
Suprabh Shukla | af6c419 | 2016-04-27 14:05:54 -0700 | [diff] [blame^] | 657 | if (vol != null) { |
| 658 | intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId()); |
| 659 | } |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 660 | return PendingIntent.getActivityAsUser(mContext, move.moveId, intent, |
| 661 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
| 662 | } |
| 663 | |
| 664 | private PendingIntent buildWizardMovePendingIntent(MoveInfo move) { |
| 665 | final Intent intent = new Intent(); |
| 666 | intent.setClassName("com.android.settings", |
| 667 | "com.android.settings.deviceinfo.StorageWizardMoveProgress"); |
| 668 | intent.putExtra(PackageManager.EXTRA_MOVE_ID, move.moveId); |
| 669 | |
| 670 | return PendingIntent.getActivityAsUser(mContext, move.moveId, intent, |
| 671 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
| 672 | } |
| 673 | |
| 674 | private PendingIntent buildWizardReadyPendingIntent(DiskInfo disk) { |
| 675 | final Intent intent = new Intent(); |
| 676 | intent.setClassName("com.android.settings", |
| 677 | "com.android.settings.deviceinfo.StorageWizardReady"); |
| 678 | intent.putExtra(DiskInfo.EXTRA_DISK_ID, disk.getId()); |
| 679 | |
| 680 | final int requestKey = disk.getId().hashCode(); |
| 681 | return PendingIntent.getActivityAsUser(mContext, requestKey, intent, |
| 682 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
| 683 | } |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 684 | } |