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