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