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