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