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 |
| 151 | final List<VolumeInfo> vols = mStorageManager.getVolumes(); |
| 152 | for (VolumeInfo vol : vols) { |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 153 | onVolumeStateChangedInternal(vol); |
| 154 | } |
| 155 | |
| 156 | mContext.getPackageManager().registerMoveCallback(mMoveCallback, new Handler()); |
| 157 | |
| 158 | updateMissingPrivateVolumes(); |
| 159 | } |
| 160 | |
| 161 | private void updateMissingPrivateVolumes() { |
| 162 | final List<VolumeRecord> recs = mStorageManager.getVolumeRecords(); |
| 163 | for (VolumeRecord rec : recs) { |
| 164 | if (rec.getType() != VolumeInfo.TYPE_PRIVATE) continue; |
| 165 | |
| 166 | final String fsUuid = rec.getFsUuid(); |
| 167 | final VolumeInfo info = mStorageManager.findVolumeByUuid(fsUuid); |
| 168 | if (info != null && info.isMountedWritable()) { |
| 169 | // Yay, private volume is here! |
| 170 | mNotificationManager.cancelAsUser(fsUuid, PRIVATE_ID, UserHandle.ALL); |
| 171 | |
| 172 | } else { |
| 173 | // Boo, annoy the user to reinsert the private volume |
| 174 | final CharSequence title = mContext.getString(R.string.ext_media_missing_title, |
| 175 | rec.getNickname()); |
| 176 | final CharSequence text = mContext.getString(R.string.ext_media_missing_message); |
| 177 | |
| 178 | final Notification notif = new Notification.Builder(mContext) |
| 179 | .setSmallIcon(R.drawable.stat_notify_sdcard) |
| 180 | .setColor(mContext.getColor(R.color.system_notification_accent_color)) |
| 181 | .setContentTitle(title) |
| 182 | .setContentText(text) |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 183 | .setContentIntent(buildForgetPendingIntent(rec)) |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 184 | .setStyle(new Notification.BigTextStyle().bigText(text)) |
| 185 | .setVisibility(Notification.VISIBILITY_PUBLIC) |
| 186 | .setLocalOnly(true) |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 187 | .setCategory(Notification.CATEGORY_SYSTEM) |
| 188 | .setOngoing(true) |
| 189 | .build(); |
| 190 | |
| 191 | mNotificationManager.notifyAsUser(fsUuid, PRIVATE_ID, notif, UserHandle.ALL); |
| 192 | } |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 196 | private void onDiskScannedInternal(DiskInfo disk, int volumeCount) { |
| 197 | if (volumeCount == 0) { |
| 198 | // No supported volumes found, give user option to format |
| 199 | final CharSequence title = mContext.getString( |
| 200 | R.string.ext_media_unmountable_notification_title, disk.getDescription()); |
| 201 | final CharSequence text = mContext.getString( |
| 202 | R.string.ext_media_unmountable_notification_message, disk.getDescription()); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 203 | |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 204 | final Notification notif = new Notification.Builder(mContext) |
| 205 | .setSmallIcon(getSmallIcon(disk, VolumeInfo.STATE_UNMOUNTABLE)) |
| 206 | .setColor(mContext.getColor(R.color.system_notification_accent_color)) |
| 207 | .setContentTitle(title) |
| 208 | .setContentText(text) |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 209 | .setContentIntent(buildInitPendingIntent(disk)) |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 210 | .setStyle(new Notification.BigTextStyle().bigText(text)) |
| 211 | .setVisibility(Notification.VISIBILITY_PUBLIC) |
| 212 | .setLocalOnly(true) |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 213 | .setCategory(Notification.CATEGORY_ERROR) |
| 214 | .build(); |
| 215 | |
| 216 | mNotificationManager.notifyAsUser(disk.getId(), DISK_ID, notif, UserHandle.ALL); |
| 217 | |
| 218 | } else { |
| 219 | // Yay, we have volumes! |
| 220 | mNotificationManager.cancelAsUser(disk.getId(), DISK_ID, UserHandle.ALL); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | private void onVolumeStateChangedInternal(VolumeInfo vol) { |
| 225 | switch (vol.getType()) { |
| 226 | case VolumeInfo.TYPE_PRIVATE: |
| 227 | onPrivateVolumeStateChangedInternal(vol); |
| 228 | break; |
| 229 | case VolumeInfo.TYPE_PUBLIC: |
| 230 | onPublicVolumeStateChangedInternal(vol); |
| 231 | break; |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | private void onPrivateVolumeStateChangedInternal(VolumeInfo vol) { |
| 236 | Log.d(TAG, "Notifying about private volume: " + vol.toString()); |
| 237 | |
| 238 | updateMissingPrivateVolumes(); |
| 239 | } |
| 240 | |
| 241 | private void onPublicVolumeStateChangedInternal(VolumeInfo vol) { |
| 242 | Log.d(TAG, "Notifying about public volume: " + vol.toString()); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 243 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 244 | final Notification notif; |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 245 | switch (vol.getState()) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 246 | case VolumeInfo.STATE_UNMOUNTED: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 247 | notif = onVolumeUnmounted(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 248 | break; |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 249 | case VolumeInfo.STATE_CHECKING: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 250 | notif = onVolumeChecking(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 251 | break; |
| 252 | case VolumeInfo.STATE_MOUNTED: |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 253 | case VolumeInfo.STATE_MOUNTED_READ_ONLY: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 254 | notif = onVolumeMounted(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 255 | break; |
| 256 | case VolumeInfo.STATE_FORMATTING: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 257 | notif = onVolumeFormatting(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 258 | break; |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 259 | case VolumeInfo.STATE_EJECTING: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 260 | notif = onVolumeEjecting(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 261 | break; |
| 262 | case VolumeInfo.STATE_UNMOUNTABLE: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 263 | notif = onVolumeUnmountable(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 264 | break; |
| 265 | case VolumeInfo.STATE_REMOVED: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 266 | notif = onVolumeRemoved(vol); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 267 | break; |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 268 | case VolumeInfo.STATE_BAD_REMOVAL: |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 269 | notif = onVolumeBadRemoval(vol); |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 270 | break; |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 271 | default: |
| 272 | notif = null; |
| 273 | break; |
| 274 | } |
| 275 | |
| 276 | if (notif != null) { |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 277 | mNotificationManager.notifyAsUser(vol.getId(), PUBLIC_ID, notif, UserHandle.ALL); |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 278 | } else { |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 279 | mNotificationManager.cancelAsUser(vol.getId(), PUBLIC_ID, UserHandle.ALL); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 283 | private Notification onVolumeUnmounted(VolumeInfo vol) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 284 | // Ignored |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 285 | return null; |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 286 | } |
| 287 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 288 | private Notification onVolumeChecking(VolumeInfo vol) { |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 289 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 290 | final CharSequence title = mContext.getString( |
| 291 | R.string.ext_media_checking_notification_title, disk.getDescription()); |
| 292 | final CharSequence text = mContext.getString( |
| 293 | R.string.ext_media_checking_notification_message, disk.getDescription()); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 294 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 295 | return buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 296 | .setCategory(Notification.CATEGORY_PROGRESS) |
| 297 | .setPriority(Notification.PRIORITY_LOW) |
| 298 | .setOngoing(true) |
| 299 | .build(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 300 | } |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 301 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 302 | private Notification onVolumeMounted(VolumeInfo vol) { |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 303 | final VolumeRecord rec = mStorageManager.findRecordByUuid(vol.getFsUuid()); |
| 304 | |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 305 | // Don't annoy when user dismissed in past |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 306 | if (rec.isSnoozed()) return null; |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 307 | |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 308 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 309 | if (disk.isAdoptable() && !rec.isInited()) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 310 | final CharSequence title = disk.getDescription(); |
| 311 | final CharSequence text = mContext.getString( |
| 312 | R.string.ext_media_new_notification_message, disk.getDescription()); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 313 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 314 | final PendingIntent initIntent = buildInitPendingIntent(vol); |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 315 | return buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 316 | .addAction(new Action(0, mContext.getString(R.string.ext_media_init_action), |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 317 | initIntent)) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 318 | .addAction(new Action(0, mContext.getString(R.string.ext_media_unmount_action), |
| 319 | buildUnmountPendingIntent(vol))) |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 320 | .setContentIntent(initIntent) |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 321 | .setDeleteIntent(buildSnoozeIntent(vol)) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 322 | .setCategory(Notification.CATEGORY_SYSTEM) |
| 323 | .build(); |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 324 | |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 325 | } else { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 326 | final CharSequence title = disk.getDescription(); |
| 327 | final CharSequence text = mContext.getString( |
| 328 | R.string.ext_media_ready_notification_message, disk.getDescription()); |
| 329 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 330 | final PendingIntent browseIntent = buildBrowsePendingIntent(vol); |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 331 | return buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 332 | .addAction(new Action(0, mContext.getString(R.string.ext_media_browse_action), |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 333 | browseIntent)) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 334 | .addAction(new Action(0, mContext.getString(R.string.ext_media_unmount_action), |
| 335 | buildUnmountPendingIntent(vol))) |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 336 | .setContentIntent(browseIntent) |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 337 | .setDeleteIntent(buildSnoozeIntent(vol)) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 338 | .setCategory(Notification.CATEGORY_SYSTEM) |
| 339 | .setPriority(Notification.PRIORITY_LOW) |
| 340 | .build(); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 341 | } |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 344 | private Notification onVolumeFormatting(VolumeInfo vol) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 345 | // Ignored |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 346 | return null; |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 349 | private Notification onVolumeEjecting(VolumeInfo vol) { |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 350 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 351 | final CharSequence title = mContext.getString( |
| 352 | R.string.ext_media_unmounting_notification_title, disk.getDescription()); |
| 353 | final CharSequence text = mContext.getString( |
| 354 | R.string.ext_media_unmounting_notification_message, disk.getDescription()); |
| 355 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 356 | return buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 357 | .setCategory(Notification.CATEGORY_PROGRESS) |
| 358 | .setPriority(Notification.PRIORITY_LOW) |
| 359 | .setOngoing(true) |
| 360 | .build(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 363 | private Notification onVolumeUnmountable(VolumeInfo vol) { |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 364 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 365 | final CharSequence title = mContext.getString( |
| 366 | R.string.ext_media_unmountable_notification_title, disk.getDescription()); |
| 367 | final CharSequence text = mContext.getString( |
| 368 | R.string.ext_media_unmountable_notification_message, disk.getDescription()); |
| 369 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 370 | return buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 371 | .setContentIntent(buildVolumeSettingsPendingIntent(vol)) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 372 | .setCategory(Notification.CATEGORY_ERROR) |
| 373 | .build(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 376 | private Notification onVolumeRemoved(VolumeInfo vol) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 377 | if (!vol.isPrimary()) { |
| 378 | // Ignore non-primary media |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 379 | return null; |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 382 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 383 | final CharSequence title = mContext.getString( |
| 384 | R.string.ext_media_nomedia_notification_title, disk.getDescription()); |
| 385 | final CharSequence text = mContext.getString( |
| 386 | R.string.ext_media_nomedia_notification_message, disk.getDescription()); |
| 387 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 388 | return buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 389 | .setCategory(Notification.CATEGORY_ERROR) |
| 390 | .build(); |
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 onVolumeBadRemoval(VolumeInfo vol) { |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 394 | if (!vol.isPrimary()) { |
| 395 | // Ignore non-primary media |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 396 | return null; |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 399 | final DiskInfo disk = vol.getDisk(); |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 400 | final CharSequence title = mContext.getString( |
| 401 | R.string.ext_media_badremoval_notification_title, disk.getDescription()); |
| 402 | final CharSequence text = mContext.getString( |
| 403 | R.string.ext_media_badremoval_notification_message, disk.getDescription()); |
| 404 | |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 405 | return buildNotificationBuilder(vol, title, text) |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 406 | .setCategory(Notification.CATEGORY_ERROR) |
| 407 | .build(); |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 410 | private void onMoveProgress(MoveInfo move, int status, long estMillis) { |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 411 | final CharSequence title; |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 412 | if (!TextUtils.isEmpty(move.label)) { |
| 413 | title = mContext.getString(R.string.ext_media_move_specific_title, move.label); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 414 | } else { |
| 415 | title = mContext.getString(R.string.ext_media_move_title); |
| 416 | } |
| 417 | |
| 418 | final CharSequence text; |
| 419 | if (estMillis < 0) { |
| 420 | text = null; |
| 421 | } else { |
| 422 | text = DateUtils.formatDuration(estMillis); |
| 423 | } |
| 424 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 425 | final PendingIntent intent; |
| 426 | if (move.packageName != null) { |
| 427 | intent = buildWizardMovePendingIntent(move); |
| 428 | } else { |
| 429 | intent = buildWizardMigratePendingIntent(move); |
| 430 | } |
| 431 | |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 432 | final Notification notif = new Notification.Builder(mContext) |
| 433 | .setSmallIcon(R.drawable.stat_notify_sdcard) |
| 434 | .setColor(mContext.getColor(R.color.system_notification_accent_color)) |
| 435 | .setContentTitle(title) |
| 436 | .setContentText(text) |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 437 | .setContentIntent(intent) |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 438 | .setStyle(new Notification.BigTextStyle().bigText(text)) |
| 439 | .setVisibility(Notification.VISIBILITY_PUBLIC) |
| 440 | .setLocalOnly(true) |
| 441 | .setCategory(Notification.CATEGORY_PROGRESS) |
| 442 | .setPriority(Notification.PRIORITY_LOW) |
| 443 | .setProgress(100, status, false) |
| 444 | .setOngoing(true) |
| 445 | .build(); |
| 446 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 447 | mNotificationManager.notifyAsUser(move.packageName, MOVE_ID, notif, UserHandle.ALL); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 450 | private void onMoveFinished(MoveInfo move, int status) { |
| 451 | if (move.packageName != null) { |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 452 | // We currently ignore finished app moves; just clear the last |
| 453 | // published progress |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 454 | mNotificationManager.cancelAsUser(move.packageName, MOVE_ID, UserHandle.ALL); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 455 | return; |
| 456 | } |
| 457 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 458 | final VolumeInfo privateVol = mContext.getPackageManager().getPrimaryStorageCurrentVolume(); |
| 459 | final String descrip = mStorageManager.getBestVolumeDescription(privateVol); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 460 | |
| 461 | final CharSequence title; |
| 462 | final CharSequence text; |
| 463 | if (status == PackageManager.MOVE_SUCCEEDED) { |
| 464 | title = mContext.getString(R.string.ext_media_move_success_title); |
| 465 | text = mContext.getString(R.string.ext_media_move_success_message, descrip); |
| 466 | } else { |
| 467 | title = mContext.getString(R.string.ext_media_move_failure_title); |
| 468 | text = mContext.getString(R.string.ext_media_move_failure_message); |
| 469 | } |
| 470 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 471 | // Jump back into the wizard flow if we moved to a real disk |
| 472 | final PendingIntent intent; |
| 473 | if (privateVol != null && privateVol.getDisk() != null) { |
| 474 | intent = buildWizardReadyPendingIntent(privateVol.getDisk()); |
| 475 | } else { |
| 476 | intent = buildVolumeSettingsPendingIntent(privateVol); |
| 477 | } |
| 478 | |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 479 | final Notification notif = new Notification.Builder(mContext) |
| 480 | .setSmallIcon(R.drawable.stat_notify_sdcard) |
| 481 | .setColor(mContext.getColor(R.color.system_notification_accent_color)) |
| 482 | .setContentTitle(title) |
| 483 | .setContentText(text) |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 484 | .setContentIntent(intent) |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 485 | .setStyle(new Notification.BigTextStyle().bigText(text)) |
| 486 | .setVisibility(Notification.VISIBILITY_PUBLIC) |
| 487 | .setLocalOnly(true) |
| 488 | .setCategory(Notification.CATEGORY_SYSTEM) |
| 489 | .setPriority(Notification.PRIORITY_LOW) |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 490 | .setAutoCancel(true) |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 491 | .build(); |
| 492 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 493 | mNotificationManager.notifyAsUser(move.packageName, MOVE_ID, notif, UserHandle.ALL); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | private int getSmallIcon(DiskInfo disk, int state) { |
| 497 | if (disk.isSd()) { |
| 498 | switch (state) { |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 499 | case VolumeInfo.STATE_CHECKING: |
| 500 | case VolumeInfo.STATE_EJECTING: |
| 501 | return R.drawable.stat_notify_sdcard_prepare; |
| 502 | default: |
| 503 | return R.drawable.stat_notify_sdcard; |
| 504 | } |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 505 | } else if (disk.isUsb()) { |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 506 | return R.drawable.stat_sys_data_usb; |
| 507 | } else { |
| 508 | return R.drawable.stat_notify_sdcard; |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | private Notification.Builder buildNotificationBuilder(VolumeInfo vol, CharSequence title, |
| 513 | CharSequence text) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 514 | return new Notification.Builder(mContext) |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 515 | .setSmallIcon(getSmallIcon(vol.getDisk(), vol.getState())) |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 516 | .setColor(mContext.getColor(R.color.system_notification_accent_color)) |
| 517 | .setContentTitle(title) |
| 518 | .setContentText(text) |
| 519 | .setStyle(new Notification.BigTextStyle().bigText(text)) |
| 520 | .setVisibility(Notification.VISIBILITY_PUBLIC) |
| 521 | .setLocalOnly(true); |
| 522 | } |
| 523 | |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 524 | private PendingIntent buildInitPendingIntent(DiskInfo disk) { |
| 525 | final Intent intent = new Intent(); |
| 526 | intent.setClassName("com.android.settings", |
| 527 | "com.android.settings.deviceinfo.StorageWizardInit"); |
| 528 | intent.putExtra(DiskInfo.EXTRA_DISK_ID, disk.getId()); |
| 529 | |
| 530 | final int requestKey = disk.getId().hashCode(); |
| 531 | return PendingIntent.getActivityAsUser(mContext, requestKey, intent, |
| 532 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
| 533 | } |
| 534 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 535 | private PendingIntent buildInitPendingIntent(VolumeInfo vol) { |
| 536 | final Intent intent = new Intent(); |
| 537 | intent.setClassName("com.android.settings", |
| 538 | "com.android.settings.deviceinfo.StorageWizardInit"); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 539 | intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId()); |
| 540 | |
| 541 | final int requestKey = vol.getId().hashCode(); |
| 542 | return PendingIntent.getActivityAsUser(mContext, requestKey, intent, |
| 543 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | private PendingIntent buildUnmountPendingIntent(VolumeInfo vol) { |
| 547 | final Intent intent = new Intent(); |
| 548 | intent.setClassName("com.android.settings", |
| 549 | "com.android.settings.deviceinfo.StorageUnmountReceiver"); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 550 | intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId()); |
| 551 | |
| 552 | final int requestKey = vol.getId().hashCode(); |
| 553 | return PendingIntent.getBroadcastAsUser(mContext, requestKey, intent, |
| 554 | PendingIntent.FLAG_CANCEL_CURRENT, UserHandle.CURRENT); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | private PendingIntent buildBrowsePendingIntent(VolumeInfo vol) { |
| 558 | final Intent intent = vol.buildBrowseIntent(); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 559 | |
| 560 | final int requestKey = vol.getId().hashCode(); |
| 561 | return PendingIntent.getActivityAsUser(mContext, requestKey, intent, |
| 562 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 565 | private PendingIntent buildVolumeSettingsPendingIntent(VolumeInfo vol) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 566 | final Intent intent = new Intent(); |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 567 | switch (vol.getType()) { |
| 568 | case VolumeInfo.TYPE_PRIVATE: |
| 569 | intent.setClassName("com.android.settings", |
| 570 | "com.android.settings.Settings$PrivateVolumeSettingsActivity"); |
| 571 | break; |
| 572 | case VolumeInfo.TYPE_PUBLIC: |
| 573 | intent.setClassName("com.android.settings", |
| 574 | "com.android.settings.Settings$PublicVolumeSettingsActivity"); |
| 575 | break; |
| 576 | default: |
| 577 | return null; |
| 578 | } |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 579 | intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId()); |
| 580 | |
| 581 | final int requestKey = vol.getId().hashCode(); |
| 582 | return PendingIntent.getActivityAsUser(mContext, requestKey, intent, |
| 583 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
| 584 | } |
| 585 | |
| 586 | private PendingIntent buildSnoozeIntent(VolumeInfo vol) { |
| 587 | final Intent intent = new Intent(ACTION_SNOOZE_VOLUME); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 588 | intent.putExtra(VolumeRecord.EXTRA_FS_UUID, vol.getFsUuid()); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 589 | |
| 590 | final int requestKey = vol.getId().hashCode(); |
| 591 | return PendingIntent.getBroadcastAsUser(mContext, requestKey, intent, |
| 592 | PendingIntent.FLAG_CANCEL_CURRENT, UserHandle.CURRENT); |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 593 | } |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 594 | |
| 595 | private PendingIntent buildForgetPendingIntent(VolumeRecord rec) { |
| 596 | final Intent intent = new Intent(); |
| 597 | intent.setClassName("com.android.settings", |
| 598 | "com.android.settings.Settings$PrivateVolumeForgetActivity"); |
| 599 | intent.putExtra(VolumeRecord.EXTRA_FS_UUID, rec.getFsUuid()); |
| 600 | |
| 601 | final int requestKey = rec.getFsUuid().hashCode(); |
| 602 | return PendingIntent.getActivityAsUser(mContext, requestKey, intent, |
| 603 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
| 604 | } |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame^] | 605 | |
| 606 | private PendingIntent buildWizardMigratePendingIntent(MoveInfo move) { |
| 607 | final Intent intent = new Intent(); |
| 608 | intent.setClassName("com.android.settings", |
| 609 | "com.android.settings.deviceinfo.StorageWizardMigrateProgress"); |
| 610 | intent.putExtra(PackageManager.EXTRA_MOVE_ID, move.moveId); |
| 611 | |
| 612 | final VolumeInfo vol = mStorageManager.findVolumeByQualifiedUuid(move.volumeUuid); |
| 613 | intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId()); |
| 614 | |
| 615 | return PendingIntent.getActivityAsUser(mContext, move.moveId, intent, |
| 616 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
| 617 | } |
| 618 | |
| 619 | private PendingIntent buildWizardMovePendingIntent(MoveInfo move) { |
| 620 | final Intent intent = new Intent(); |
| 621 | intent.setClassName("com.android.settings", |
| 622 | "com.android.settings.deviceinfo.StorageWizardMoveProgress"); |
| 623 | intent.putExtra(PackageManager.EXTRA_MOVE_ID, move.moveId); |
| 624 | |
| 625 | return PendingIntent.getActivityAsUser(mContext, move.moveId, intent, |
| 626 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
| 627 | } |
| 628 | |
| 629 | private PendingIntent buildWizardReadyPendingIntent(DiskInfo disk) { |
| 630 | final Intent intent = new Intent(); |
| 631 | intent.setClassName("com.android.settings", |
| 632 | "com.android.settings.deviceinfo.StorageWizardReady"); |
| 633 | intent.putExtra(DiskInfo.EXTRA_DISK_ID, disk.getId()); |
| 634 | |
| 635 | final int requestKey = disk.getId().hashCode(); |
| 636 | return PendingIntent.getActivityAsUser(mContext, requestKey, intent, |
| 637 | PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); |
| 638 | } |
San Mehat | 64e6a45 | 2010-02-04 20:53:48 -0800 | [diff] [blame] | 639 | } |