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