blob: 11885c55b51d70ea7ff555c365f40c671bb01b6c [file] [log] [blame]
San Mehat64e6a452010-02-04 20:53:48 -08001/*
Jeff Sharkey56bd3122015-04-14 10:30:34 -07002 * Copyright (C) 2015 The Android Open Source Project
San Mehat64e6a452010-02-04 20:53:48 -08003 *
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 Onoratofe4f3ae2010-06-04 11:25:26 -070017package com.android.systemui.usb;
San Mehat64e6a452010-02-04 20:53:48 -080018
Philip P. Moltmann75b230b2016-04-11 15:27:58 -070019import android.annotation.NonNull;
San Mehat64e6a452010-02-04 20:53:48 -080020import android.app.Notification;
Jeff Sharkey56bd3122015-04-14 10:30:34 -070021import android.app.Notification.Action;
San Mehat64e6a452010-02-04 20:53:48 -080022import android.app.NotificationManager;
23import android.app.PendingIntent;
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -070024import android.content.BroadcastReceiver;
25import android.content.Context;
San Mehat64e6a452010-02-04 20:53:48 -080026import android.content.Intent;
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -070027import android.content.IntentFilter;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070028import android.content.pm.PackageManager;
29import android.content.pm.PackageManager.MoveCallback;
Jeff Sharkey50a05452015-04-29 11:24:52 -070030import android.os.Bundle;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070031import android.os.Handler;
Jeff Sharkeye3644412019-04-27 17:13:57 -060032import android.os.StrictMode;
Dianne Hackborn50cdf7c32012-09-23 17:08:57 -070033import android.os.UserHandle;
Jeff Sharkey56bd3122015-04-14 10:30:34 -070034import android.os.storage.DiskInfo;
San Mehatb1043402010-02-05 08:26:50 -080035import android.os.storage.StorageEventListener;
36import android.os.storage.StorageManager;
Jeff Sharkey56bd3122015-04-14 10:30:34 -070037import android.os.storage.VolumeInfo;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070038import android.os.storage.VolumeRecord;
Dmitri Plotnikov519c0882017-02-13 14:37:05 -080039import android.provider.Settings;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070040import android.text.TextUtils;
41import android.text.format.DateUtils;
John Spurlockcd686b52013-06-05 10:13:46 -040042import android.util.Log;
Jeff Sharkey50a05452015-04-29 11:24:52 -070043import android.util.SparseArray;
San Mehat64e6a452010-02-04 20:53:48 -080044
Jeff Sharkey56bd3122015-04-14 10:30:34 -070045import com.android.internal.R;
Chris Wren5e6c0ff2017-01-05 12:57:06 -050046import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
John Spurlock3e309b22013-06-25 11:01:29 -040047import com.android.systemui.SystemUI;
Dan Sandler8e032e12017-01-25 13:41:38 -050048import com.android.systemui.util.NotificationChannels;
John Spurlock3e309b22013-06-25 11:01:29 -040049
Jeff Sharkey56bd3122015-04-14 10:30:34 -070050import java.util.List;
51
John Spurlock3e309b22013-06-25 11:01:29 -040052public class StorageNotification extends SystemUI {
San Mehat64e6a452010-02-04 20:53:48 -080053 private static final String TAG = "StorageNotification";
54
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -070055 private static final String ACTION_SNOOZE_VOLUME = "com.android.systemui.action.SNOOZE_VOLUME";
Jeff Sharkeydf27d3b2015-06-16 13:51:48 -070056 private static final String ACTION_FINISH_WIZARD = "com.android.systemui.action.FINISH_WIZARD";
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -070057
Jeff Sharkey56bd3122015-04-14 10:30:34 -070058 // TODO: delay some notifications to avoid bumpy fast operations
San Mehat64e6a452010-02-04 20:53:48 -080059
Jeff Sharkey56bd3122015-04-14 10:30:34 -070060 private NotificationManager mNotificationManager;
San Mehatb1043402010-02-05 08:26:50 -080061 private StorageManager mStorageManager;
San Mehat64e6a452010-02-04 20:53:48 -080062
Dave Mankoffa5d8a392019-10-10 12:21:09 -040063 public StorageNotification(Context context) {
64 super(context);
65 }
66
Jeff Sharkey50a05452015-04-29 11:24:52 -070067 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 Sharkey56bd3122015-04-14 10:30:34 -070077 private final StorageEventListener mListener = new StorageEventListener() {
78 @Override
79 public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070080 onVolumeStateChangedInternal(vol);
John Spurlock3e309b22013-06-25 11:01:29 -040081 }
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -070082
83 @Override
Jeff Sharkey50a05452015-04-29 11:24:52 -070084 public void onVolumeRecordChanged(VolumeRecord rec) {
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -070085 // 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 Sharkey50a05452015-04-29 11:24:52 -070088 final VolumeInfo vol = mStorageManager.findVolumeByUuid(rec.getFsUuid());
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070089 if (vol != null && vol.isMountedReadable()) {
90 onVolumeStateChangedInternal(vol);
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -070091 }
Jeff Sharkey50a05452015-04-29 11:24:52 -070092 }
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070093
Jeff Sharkey50a05452015-04-29 11:24:52 -070094 @Override
95 public void onVolumeForgotten(String fsUuid) {
96 // Stop annoying the user
Chris Wren5e6c0ff2017-01-05 12:57:06 -050097 mNotificationManager.cancelAsUser(fsUuid, SystemMessage.NOTE_STORAGE_PRIVATE,
98 UserHandle.ALL);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070099 }
100
101 @Override
102 public void onDiskScanned(DiskInfo disk, int volumeCount) {
103 onDiskScannedInternal(disk, volumeCount);
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -0700104 }
Philip P. Moltmann75b230b2016-04-11 15:27:58 -0700105
106 @Override
107 public void onDiskDestroyed(DiskInfo disk) {
108 onDiskDestroyedInternal(disk);
109 }
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -0700110 };
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 Sharkeyb36586a2015-04-27 08:42:28 -0700116 final String fsUuid = intent.getStringExtra(VolumeRecord.EXTRA_FS_UUID);
117 mStorageManager.setVolumeSnoozed(fsUuid, true);
118 }
119 };
120
Jeff Sharkeydf27d3b2015-06-16 13:51:48 -0700121 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 Wren5e6c0ff2017-01-05 12:57:06 -0500126 mNotificationManager.cancelAsUser(null, SystemMessage.NOTE_STORAGE_MOVE,
127 UserHandle.ALL);
Jeff Sharkeydf27d3b2015-06-16 13:51:48 -0700128 }
129 };
130
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700131 private final MoveCallback mMoveCallback = new MoveCallback() {
132 @Override
Jeff Sharkey50a05452015-04-29 11:24:52 -0700133 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 Sharkeyb36586a2015-04-27 08:42:28 -0700153 if (PackageManager.isMoveStatusFinished(status)) {
Jeff Sharkey50a05452015-04-29 11:24:52 -0700154 onMoveFinished(move, status);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700155 } else {
Jeff Sharkey50a05452015-04-29 11:24:52 -0700156 onMoveProgress(move, status, estMillis);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700157 }
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -0700158 }
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700159 };
San Mehat64e6a452010-02-04 20:53:48 -0800160
John Spurlock3e309b22013-06-25 11:01:29 -0400161 @Override
162 public void start() {
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700163 mNotificationManager = mContext.getSystemService(NotificationManager.class);
John Spurlock3e309b22013-06-25 11:01:29 -0400164
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700165 mStorageManager = mContext.getSystemService(StorageManager.class);
166 mStorageManager.registerListener(mListener);
Daniel Sandler5b8743f2010-11-03 09:43:46 -0400167
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -0700168 mContext.registerReceiver(mSnoozeReceiver, new IntentFilter(ACTION_SNOOZE_VOLUME),
169 android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS, null);
Jeff Sharkeydf27d3b2015-06-16 13:51:48 -0700170 mContext.registerReceiver(mFinishReceiver, new IntentFilter(ACTION_FINISH_WIZARD),
171 android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS, null);
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -0700172
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700173 // Kick current state into place
Jeff Sharkeyf5a6bd72015-05-19 14:42:38 -0700174 final List<DiskInfo> disks = mStorageManager.getDisks();
175 for (DiskInfo disk : disks) {
176 onDiskScannedInternal(disk, disk.volumeCount);
177 }
178
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700179 final List<VolumeInfo> vols = mStorageManager.getVolumes();
180 for (VolumeInfo vol : vols) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700181 onVolumeStateChangedInternal(vol);
182 }
183
184 mContext.getPackageManager().registerMoveCallback(mMoveCallback, new Handler());
185
186 updateMissingPrivateVolumes();
187 }
188
189 private void updateMissingPrivateVolumes() {
Dmitri Plotnikov519c0882017-02-13 14:37:05 -0800190 if (isTv()) {
191 // On TV, TvSettings displays a modal full-screen activity in this case.
192 return;
193 }
194
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700195 final List<VolumeRecord> recs = mStorageManager.getVolumeRecords();
196 for (VolumeRecord rec : recs) {
197 if (rec.getType() != VolumeInfo.TYPE_PRIVATE) continue;
198
199 final String fsUuid = rec.getFsUuid();
200 final VolumeInfo info = mStorageManager.findVolumeByUuid(fsUuid);
Jeff Sharkey52fc3c0f2015-06-14 20:58:54 -0700201 if ((info != null && info.isMountedWritable()) || rec.isSnoozed()) {
202 // Yay, private volume is here, or user snoozed
Chris Wren5e6c0ff2017-01-05 12:57:06 -0500203 mNotificationManager.cancelAsUser(fsUuid, SystemMessage.NOTE_STORAGE_PRIVATE,
204 UserHandle.ALL);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700205
206 } else {
207 // Boo, annoy the user to reinsert the private volume
208 final CharSequence title = mContext.getString(R.string.ext_media_missing_title,
209 rec.getNickname());
210 final CharSequence text = mContext.getString(R.string.ext_media_missing_message);
211
Geoffrey Pitsch1dc93bc2017-01-31 16:38:11 -0500212 Notification.Builder builder =
213 new Notification.Builder(mContext, NotificationChannels.STORAGE)
214 .setSmallIcon(R.drawable.ic_sd_card_48dp)
215 .setColor(mContext.getColor(
216 R.color.system_notification_accent_color))
217 .setContentTitle(title)
218 .setContentText(text)
219 .setContentIntent(buildForgetPendingIntent(rec))
220 .setStyle(new Notification.BigTextStyle().bigText(text))
221 .setVisibility(Notification.VISIBILITY_PUBLIC)
222 .setLocalOnly(true)
223 .setCategory(Notification.CATEGORY_SYSTEM)
Dmitri Plotnikov519c0882017-02-13 14:37:05 -0800224 .setDeleteIntent(buildSnoozeIntent(fsUuid))
225 .extend(new Notification.TvExtender());
Julia Reynolds037d8082018-03-18 15:25:19 -0400226 SystemUI.overrideNotificationAppName(mContext, builder, false);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700227
Chris Wren5e6c0ff2017-01-05 12:57:06 -0500228 mNotificationManager.notifyAsUser(fsUuid, SystemMessage.NOTE_STORAGE_PRIVATE,
229 builder.build(), UserHandle.ALL);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700230 }
San Mehat64e6a452010-02-04 20:53:48 -0800231 }
232 }
233
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700234 private void onDiskScannedInternal(DiskInfo disk, int volumeCount) {
Jeff Sharkeyf5a6bd72015-05-19 14:42:38 -0700235 if (volumeCount == 0 && disk.size > 0) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700236 // No supported volumes found, give user option to format
237 final CharSequence title = mContext.getString(
Jeff Sharkey52fc3c0f2015-06-14 20:58:54 -0700238 R.string.ext_media_unsupported_notification_title, disk.getDescription());
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700239 final CharSequence text = mContext.getString(
Jeff Sharkey52fc3c0f2015-06-14 20:58:54 -0700240 R.string.ext_media_unsupported_notification_message, disk.getDescription());
San Mehat64e6a452010-02-04 20:53:48 -0800241
Geoffrey Pitsch1dc93bc2017-01-31 16:38:11 -0500242 Notification.Builder builder =
243 new Notification.Builder(mContext, NotificationChannels.STORAGE)
244 .setSmallIcon(getSmallIcon(disk, VolumeInfo.STATE_UNMOUNTABLE))
245 .setColor(mContext.getColor(R.color.system_notification_accent_color))
246 .setContentTitle(title)
247 .setContentText(text)
248 .setContentIntent(buildInitPendingIntent(disk))
249 .setStyle(new Notification.BigTextStyle().bigText(text))
250 .setVisibility(Notification.VISIBILITY_PUBLIC)
251 .setLocalOnly(true)
Dmitri Plotnikov519c0882017-02-13 14:37:05 -0800252 .setCategory(Notification.CATEGORY_ERROR)
253 .extend(new Notification.TvExtender());
Julia Reynolds037d8082018-03-18 15:25:19 -0400254 SystemUI.overrideNotificationAppName(mContext, builder, false);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700255
Chris Wren5e6c0ff2017-01-05 12:57:06 -0500256 mNotificationManager.notifyAsUser(disk.getId(), SystemMessage.NOTE_STORAGE_DISK,
257 builder.build(), UserHandle.ALL);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700258
259 } else {
260 // Yay, we have volumes!
Chris Wren5e6c0ff2017-01-05 12:57:06 -0500261 mNotificationManager.cancelAsUser(disk.getId(), SystemMessage.NOTE_STORAGE_DISK,
262 UserHandle.ALL);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700263 }
264 }
265
Philip P. Moltmann75b230b2016-04-11 15:27:58 -0700266 /**
267 * Remove all notifications for a disk when it goes away.
268 *
269 * @param disk The disk that went away.
270 */
271 private void onDiskDestroyedInternal(@NonNull DiskInfo disk) {
Chris Wren5e6c0ff2017-01-05 12:57:06 -0500272 mNotificationManager.cancelAsUser(disk.getId(), SystemMessage.NOTE_STORAGE_DISK,
273 UserHandle.ALL);
Philip P. Moltmann75b230b2016-04-11 15:27:58 -0700274 }
275
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700276 private void onVolumeStateChangedInternal(VolumeInfo vol) {
277 switch (vol.getType()) {
278 case VolumeInfo.TYPE_PRIVATE:
279 onPrivateVolumeStateChangedInternal(vol);
280 break;
281 case VolumeInfo.TYPE_PUBLIC:
282 onPublicVolumeStateChangedInternal(vol);
283 break;
284 }
285 }
286
287 private void onPrivateVolumeStateChangedInternal(VolumeInfo vol) {
288 Log.d(TAG, "Notifying about private volume: " + vol.toString());
289
290 updateMissingPrivateVolumes();
291 }
292
293 private void onPublicVolumeStateChangedInternal(VolumeInfo vol) {
294 Log.d(TAG, "Notifying about public volume: " + vol.toString());
San Mehat64e6a452010-02-04 20:53:48 -0800295
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700296 final Notification notif;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700297 switch (vol.getState()) {
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700298 case VolumeInfo.STATE_UNMOUNTED:
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700299 notif = onVolumeUnmounted(vol);
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700300 break;
Jeff Sharkey7e92ef32015-04-17 17:35:07 -0700301 case VolumeInfo.STATE_CHECKING:
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700302 notif = onVolumeChecking(vol);
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700303 break;
304 case VolumeInfo.STATE_MOUNTED:
Jeff Sharkey27de30d2015-04-18 16:20:27 -0700305 case VolumeInfo.STATE_MOUNTED_READ_ONLY:
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700306 notif = onVolumeMounted(vol);
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700307 break;
308 case VolumeInfo.STATE_FORMATTING:
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700309 notif = onVolumeFormatting(vol);
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700310 break;
Jeff Sharkey7e92ef32015-04-17 17:35:07 -0700311 case VolumeInfo.STATE_EJECTING:
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700312 notif = onVolumeEjecting(vol);
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700313 break;
314 case VolumeInfo.STATE_UNMOUNTABLE:
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700315 notif = onVolumeUnmountable(vol);
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700316 break;
317 case VolumeInfo.STATE_REMOVED:
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700318 notif = onVolumeRemoved(vol);
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700319 break;
Jeff Sharkey7e92ef32015-04-17 17:35:07 -0700320 case VolumeInfo.STATE_BAD_REMOVAL:
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700321 notif = onVolumeBadRemoval(vol);
Jeff Sharkey7e92ef32015-04-17 17:35:07 -0700322 break;
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700323 default:
324 notif = null;
325 break;
326 }
327
328 if (notif != null) {
Chris Wren5e6c0ff2017-01-05 12:57:06 -0500329 mNotificationManager.notifyAsUser(vol.getId(), SystemMessage.NOTE_STORAGE_PUBLIC,
Jeff Sharkeyf8543802018-03-28 10:31:55 -0600330 notif, UserHandle.of(vol.getMountUserId()));
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700331 } else {
Chris Wren5e6c0ff2017-01-05 12:57:06 -0500332 mNotificationManager.cancelAsUser(vol.getId(), SystemMessage.NOTE_STORAGE_PUBLIC,
Jeff Sharkeyf8543802018-03-28 10:31:55 -0600333 UserHandle.of(vol.getMountUserId()));
San Mehat64e6a452010-02-04 20:53:48 -0800334 }
335 }
336
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700337 private Notification onVolumeUnmounted(VolumeInfo vol) {
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700338 // Ignored
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700339 return null;
San Mehat64e6a452010-02-04 20:53:48 -0800340 }
341
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700342 private Notification onVolumeChecking(VolumeInfo vol) {
Jeff Sharkey27de30d2015-04-18 16:20:27 -0700343 final DiskInfo disk = vol.getDisk();
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700344 final CharSequence title = mContext.getString(
345 R.string.ext_media_checking_notification_title, disk.getDescription());
346 final CharSequence text = mContext.getString(
347 R.string.ext_media_checking_notification_message, disk.getDescription());
San Mehat64e6a452010-02-04 20:53:48 -0800348
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700349 return buildNotificationBuilder(vol, title, text)
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700350 .setCategory(Notification.CATEGORY_PROGRESS)
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700351 .setOngoing(true)
352 .build();
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700353 }
San Mehat64e6a452010-02-04 20:53:48 -0800354
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700355 private Notification onVolumeMounted(VolumeInfo vol) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700356 final VolumeRecord rec = mStorageManager.findRecordByUuid(vol.getFsUuid());
Jeff Sharkey27de30d2015-04-18 16:20:27 -0700357 final DiskInfo disk = vol.getDisk();
Makoto Onukib138cb22015-06-23 17:32:02 -0700358
359 // Don't annoy when user dismissed in past. (But make sure the disk is adoptable; we
360 // used to allow snoozing non-adoptable disks too.)
361 if (rec.isSnoozed() && disk.isAdoptable()) {
362 return null;
363 }
364
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700365 if (disk.isAdoptable() && !rec.isInited()) {
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700366 final CharSequence title = disk.getDescription();
367 final CharSequence text = mContext.getString(
368 R.string.ext_media_new_notification_message, disk.getDescription());
San Mehat64e6a452010-02-04 20:53:48 -0800369
Jeff Sharkey50a05452015-04-29 11:24:52 -0700370 final PendingIntent initIntent = buildInitPendingIntent(vol);
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700371 return buildNotificationBuilder(vol, title, text)
Jeff Sharkeya49d5fc2015-05-13 11:40:30 -0700372 .addAction(new Action(R.drawable.ic_settings_24dp,
373 mContext.getString(R.string.ext_media_init_action), initIntent))
374 .addAction(new Action(R.drawable.ic_eject_24dp,
375 mContext.getString(R.string.ext_media_unmount_action),
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700376 buildUnmountPendingIntent(vol)))
Jeff Sharkey50a05452015-04-29 11:24:52 -0700377 .setContentIntent(initIntent)
Jeff Sharkey52fc3c0f2015-06-14 20:58:54 -0700378 .setDeleteIntent(buildSnoozeIntent(vol.getFsUuid()))
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700379 .build();
John Spurlock209bede2013-07-17 12:23:27 -0400380
San Mehat64e6a452010-02-04 20:53:48 -0800381 } else {
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700382 final CharSequence title = disk.getDescription();
383 final CharSequence text = mContext.getString(
384 R.string.ext_media_ready_notification_message, disk.getDescription());
385
Jeff Sharkey50a05452015-04-29 11:24:52 -0700386 final PendingIntent browseIntent = buildBrowsePendingIntent(vol);
Makoto Onukib138cb22015-06-23 17:32:02 -0700387 final Notification.Builder builder = buildNotificationBuilder(vol, title, text)
Jeff Sharkeya49d5fc2015-05-13 11:40:30 -0700388 .addAction(new Action(R.drawable.ic_folder_24dp,
389 mContext.getString(R.string.ext_media_browse_action),
Jeff Sharkey50a05452015-04-29 11:24:52 -0700390 browseIntent))
Jeff Sharkeya49d5fc2015-05-13 11:40:30 -0700391 .addAction(new Action(R.drawable.ic_eject_24dp,
392 mContext.getString(R.string.ext_media_unmount_action),
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700393 buildUnmountPendingIntent(vol)))
Dmitri Plotnikovb2653e62017-04-11 11:45:00 -0700394 .setContentIntent(browseIntent)
Dan Sandler8e032e12017-01-25 13:41:38 -0500395 .setCategory(Notification.CATEGORY_SYSTEM);
Makoto Onukib138cb22015-06-23 17:32:02 -0700396 // Non-adoptable disks can't be snoozed.
397 if (disk.isAdoptable()) {
398 builder.setDeleteIntent(buildSnoozeIntent(vol.getFsUuid()));
399 }
400
401 return builder.build();
San Mehat64e6a452010-02-04 20:53:48 -0800402 }
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700403 }
404
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700405 private Notification onVolumeFormatting(VolumeInfo vol) {
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700406 // Ignored
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700407 return null;
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700408 }
409
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700410 private Notification onVolumeEjecting(VolumeInfo vol) {
Jeff Sharkey27de30d2015-04-18 16:20:27 -0700411 final DiskInfo disk = vol.getDisk();
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700412 final CharSequence title = mContext.getString(
413 R.string.ext_media_unmounting_notification_title, disk.getDescription());
414 final CharSequence text = mContext.getString(
415 R.string.ext_media_unmounting_notification_message, disk.getDescription());
416
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700417 return buildNotificationBuilder(vol, title, text)
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700418 .setCategory(Notification.CATEGORY_PROGRESS)
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700419 .setOngoing(true)
420 .build();
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700421 }
422
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700423 private Notification onVolumeUnmountable(VolumeInfo vol) {
Jeff Sharkey27de30d2015-04-18 16:20:27 -0700424 final DiskInfo disk = vol.getDisk();
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700425 final CharSequence title = mContext.getString(
426 R.string.ext_media_unmountable_notification_title, disk.getDescription());
427 final CharSequence text = mContext.getString(
428 R.string.ext_media_unmountable_notification_message, disk.getDescription());
429
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700430 return buildNotificationBuilder(vol, title, text)
Jeff Sharkey52fc3c0f2015-06-14 20:58:54 -0700431 .setContentIntent(buildInitPendingIntent(vol))
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700432 .setCategory(Notification.CATEGORY_ERROR)
433 .build();
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700434 }
435
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700436 private Notification onVolumeRemoved(VolumeInfo vol) {
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700437 if (!vol.isPrimary()) {
438 // Ignore non-primary media
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700439 return null;
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700440 }
441
Jeff Sharkey27de30d2015-04-18 16:20:27 -0700442 final DiskInfo disk = vol.getDisk();
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700443 final CharSequence title = mContext.getString(
444 R.string.ext_media_nomedia_notification_title, disk.getDescription());
445 final CharSequence text = mContext.getString(
446 R.string.ext_media_nomedia_notification_message, disk.getDescription());
447
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700448 return buildNotificationBuilder(vol, title, text)
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700449 .setCategory(Notification.CATEGORY_ERROR)
450 .build();
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700451 }
452
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700453 private Notification onVolumeBadRemoval(VolumeInfo vol) {
Jeff Sharkey7e92ef32015-04-17 17:35:07 -0700454 if (!vol.isPrimary()) {
455 // Ignore non-primary media
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700456 return null;
Jeff Sharkey7e92ef32015-04-17 17:35:07 -0700457 }
458
Jeff Sharkey27de30d2015-04-18 16:20:27 -0700459 final DiskInfo disk = vol.getDisk();
Jeff Sharkey7e92ef32015-04-17 17:35:07 -0700460 final CharSequence title = mContext.getString(
461 R.string.ext_media_badremoval_notification_title, disk.getDescription());
462 final CharSequence text = mContext.getString(
463 R.string.ext_media_badremoval_notification_message, disk.getDescription());
464
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700465 return buildNotificationBuilder(vol, title, text)
Jeff Sharkey7e92ef32015-04-17 17:35:07 -0700466 .setCategory(Notification.CATEGORY_ERROR)
467 .build();
Jeff Sharkey7e92ef32015-04-17 17:35:07 -0700468 }
469
Jeff Sharkey50a05452015-04-29 11:24:52 -0700470 private void onMoveProgress(MoveInfo move, int status, long estMillis) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700471 final CharSequence title;
Jeff Sharkey50a05452015-04-29 11:24:52 -0700472 if (!TextUtils.isEmpty(move.label)) {
473 title = mContext.getString(R.string.ext_media_move_specific_title, move.label);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700474 } else {
475 title = mContext.getString(R.string.ext_media_move_title);
476 }
477
478 final CharSequence text;
479 if (estMillis < 0) {
480 text = null;
481 } else {
482 text = DateUtils.formatDuration(estMillis);
483 }
484
Jeff Sharkey50a05452015-04-29 11:24:52 -0700485 final PendingIntent intent;
486 if (move.packageName != null) {
487 intent = buildWizardMovePendingIntent(move);
488 } else {
489 intent = buildWizardMigratePendingIntent(move);
490 }
491
Geoffrey Pitsch1dc93bc2017-01-31 16:38:11 -0500492 Notification.Builder builder =
493 new Notification.Builder(mContext, NotificationChannels.STORAGE)
494 .setSmallIcon(R.drawable.ic_sd_card_48dp)
495 .setColor(mContext.getColor(R.color.system_notification_accent_color))
496 .setContentTitle(title)
497 .setContentText(text)
498 .setContentIntent(intent)
499 .setStyle(new Notification.BigTextStyle().bigText(text))
500 .setVisibility(Notification.VISIBILITY_PUBLIC)
501 .setLocalOnly(true)
502 .setCategory(Notification.CATEGORY_PROGRESS)
503 .setProgress(100, status, false)
504 .setOngoing(true);
Julia Reynolds037d8082018-03-18 15:25:19 -0400505 SystemUI.overrideNotificationAppName(mContext, builder, false);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700506
Chris Wren5e6c0ff2017-01-05 12:57:06 -0500507 mNotificationManager.notifyAsUser(move.packageName, SystemMessage.NOTE_STORAGE_MOVE,
Adrian Roose25c18d2016-06-17 15:59:49 -0700508 builder.build(), UserHandle.ALL);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700509 }
510
Jeff Sharkey50a05452015-04-29 11:24:52 -0700511 private void onMoveFinished(MoveInfo move, int status) {
512 if (move.packageName != null) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700513 // We currently ignore finished app moves; just clear the last
514 // published progress
Chris Wren5e6c0ff2017-01-05 12:57:06 -0500515 mNotificationManager.cancelAsUser(move.packageName, SystemMessage.NOTE_STORAGE_MOVE,
516 UserHandle.ALL);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700517 return;
518 }
519
Jeff Sharkey50a05452015-04-29 11:24:52 -0700520 final VolumeInfo privateVol = mContext.getPackageManager().getPrimaryStorageCurrentVolume();
521 final String descrip = mStorageManager.getBestVolumeDescription(privateVol);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700522
523 final CharSequence title;
524 final CharSequence text;
525 if (status == PackageManager.MOVE_SUCCEEDED) {
526 title = mContext.getString(R.string.ext_media_move_success_title);
527 text = mContext.getString(R.string.ext_media_move_success_message, descrip);
528 } else {
529 title = mContext.getString(R.string.ext_media_move_failure_title);
530 text = mContext.getString(R.string.ext_media_move_failure_message);
531 }
532
Jeff Sharkey50a05452015-04-29 11:24:52 -0700533 // Jump back into the wizard flow if we moved to a real disk
534 final PendingIntent intent;
535 if (privateVol != null && privateVol.getDisk() != null) {
536 intent = buildWizardReadyPendingIntent(privateVol.getDisk());
Jeff Sharkeyef10ee02015-07-05 14:17:27 -0700537 } else if (privateVol != null) {
Jeff Sharkey50a05452015-04-29 11:24:52 -0700538 intent = buildVolumeSettingsPendingIntent(privateVol);
Jeff Sharkeyef10ee02015-07-05 14:17:27 -0700539 } else {
540 intent = null;
Jeff Sharkey50a05452015-04-29 11:24:52 -0700541 }
542
Geoffrey Pitsch1dc93bc2017-01-31 16:38:11 -0500543 Notification.Builder builder =
544 new Notification.Builder(mContext, NotificationChannels.STORAGE)
545 .setSmallIcon(R.drawable.ic_sd_card_48dp)
546 .setColor(mContext.getColor(R.color.system_notification_accent_color))
547 .setContentTitle(title)
548 .setContentText(text)
549 .setContentIntent(intent)
550 .setStyle(new Notification.BigTextStyle().bigText(text))
551 .setVisibility(Notification.VISIBILITY_PUBLIC)
552 .setLocalOnly(true)
553 .setCategory(Notification.CATEGORY_SYSTEM)
554 .setAutoCancel(true);
Julia Reynolds037d8082018-03-18 15:25:19 -0400555 SystemUI.overrideNotificationAppName(mContext, builder, false);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700556
Chris Wren5e6c0ff2017-01-05 12:57:06 -0500557 mNotificationManager.notifyAsUser(move.packageName, SystemMessage.NOTE_STORAGE_MOVE,
558 builder.build(), UserHandle.ALL);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700559 }
560
561 private int getSmallIcon(DiskInfo disk, int state) {
562 if (disk.isSd()) {
563 switch (state) {
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700564 case VolumeInfo.STATE_CHECKING:
565 case VolumeInfo.STATE_EJECTING:
Jeff Sharkeya49d5fc2015-05-13 11:40:30 -0700566 return R.drawable.ic_sd_card_48dp;
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700567 default:
Jeff Sharkeya49d5fc2015-05-13 11:40:30 -0700568 return R.drawable.ic_sd_card_48dp;
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700569 }
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700570 } else if (disk.isUsb()) {
Jeff Sharkeya49d5fc2015-05-13 11:40:30 -0700571 return R.drawable.ic_usb_48dp;
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700572 } else {
Jeff Sharkeya49d5fc2015-05-13 11:40:30 -0700573 return R.drawable.ic_sd_card_48dp;
Jeff Sharkeye6c04f92015-04-18 21:38:05 -0700574 }
575 }
576
577 private Notification.Builder buildNotificationBuilder(VolumeInfo vol, CharSequence title,
578 CharSequence text) {
Geoffrey Pitsch1dc93bc2017-01-31 16:38:11 -0500579 Notification.Builder builder =
580 new Notification.Builder(mContext, NotificationChannels.STORAGE)
581 .setSmallIcon(getSmallIcon(vol.getDisk(), vol.getState()))
582 .setColor(mContext.getColor(R.color.system_notification_accent_color))
583 .setContentTitle(title)
584 .setContentText(text)
585 .setStyle(new Notification.BigTextStyle().bigText(text))
586 .setVisibility(Notification.VISIBILITY_PUBLIC)
Dmitri Plotnikov519c0882017-02-13 14:37:05 -0800587 .setLocalOnly(true)
588 .extend(new Notification.TvExtender());
Julia Reynolds037d8082018-03-18 15:25:19 -0400589 overrideNotificationAppName(mContext, builder, false);
Adrian Roose25c18d2016-06-17 15:59:49 -0700590 return builder;
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700591 }
592
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700593 private PendingIntent buildInitPendingIntent(DiskInfo disk) {
594 final Intent intent = new Intent();
Dmitri Plotnikov519c0882017-02-13 14:37:05 -0800595 if (isTv()) {
596 intent.setPackage("com.android.tv.settings");
597 intent.setAction("com.android.tv.settings.action.NEW_STORAGE");
598 } else {
599 intent.setClassName("com.android.settings",
600 "com.android.settings.deviceinfo.StorageWizardInit");
601 }
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700602 intent.putExtra(DiskInfo.EXTRA_DISK_ID, disk.getId());
603
604 final int requestKey = disk.getId().hashCode();
605 return PendingIntent.getActivityAsUser(mContext, requestKey, intent,
606 PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT);
607 }
608
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700609 private PendingIntent buildInitPendingIntent(VolumeInfo vol) {
610 final Intent intent = new Intent();
Dmitri Plotnikov519c0882017-02-13 14:37:05 -0800611 if (isTv()) {
612 intent.setPackage("com.android.tv.settings");
613 intent.setAction("com.android.tv.settings.action.NEW_STORAGE");
614 } else {
615 intent.setClassName("com.android.settings",
616 "com.android.settings.deviceinfo.StorageWizardInit");
617 }
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -0700618 intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId());
619
620 final int requestKey = vol.getId().hashCode();
621 return PendingIntent.getActivityAsUser(mContext, requestKey, intent,
622 PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT);
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700623 }
624
625 private PendingIntent buildUnmountPendingIntent(VolumeInfo vol) {
626 final Intent intent = new Intent();
Dmitri Plotnikov519c0882017-02-13 14:37:05 -0800627 if (isTv()) {
628 intent.setPackage("com.android.tv.settings");
629 intent.setAction("com.android.tv.settings.action.UNMOUNT_STORAGE");
630 intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId());
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -0700631
Dmitri Plotnikov519c0882017-02-13 14:37:05 -0800632 final int requestKey = vol.getId().hashCode();
633 return PendingIntent.getActivityAsUser(mContext, requestKey, intent,
634 PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT);
Heemin Seog91fab5c2019-06-17 15:11:27 -0700635 } else if (isAutomotive()) {
636 intent.setClassName("com.android.car.settings",
637 "com.android.car.settings.storage.StorageUnmountReceiver");
638 intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId());
639
640 final int requestKey = vol.getId().hashCode();
641 return PendingIntent.getBroadcastAsUser(mContext, requestKey, intent,
642 PendingIntent.FLAG_CANCEL_CURRENT, UserHandle.CURRENT);
Dmitri Plotnikov519c0882017-02-13 14:37:05 -0800643 } else {
644 intent.setClassName("com.android.settings",
645 "com.android.settings.deviceinfo.StorageUnmountReceiver");
646 intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId());
647
648 final int requestKey = vol.getId().hashCode();
649 return PendingIntent.getBroadcastAsUser(mContext, requestKey, intent,
650 PendingIntent.FLAG_CANCEL_CURRENT, UserHandle.CURRENT);
651 }
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700652 }
653
654 private PendingIntent buildBrowsePendingIntent(VolumeInfo vol) {
Jeff Sharkeye3644412019-04-27 17:13:57 -0600655 final StrictMode.VmPolicy oldPolicy = StrictMode.allowVmViolations();
656 try {
657 final Intent intent = vol.buildBrowseIntentForUser(vol.getMountUserId());
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -0700658
Jeff Sharkeye3644412019-04-27 17:13:57 -0600659 final int requestKey = vol.getId().hashCode();
660 return PendingIntent.getActivityAsUser(mContext, requestKey, intent,
661 PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT);
662 } finally {
663 StrictMode.setVmPolicy(oldPolicy);
664 }
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700665 }
666
Jeff Sharkey50a05452015-04-29 11:24:52 -0700667 private PendingIntent buildVolumeSettingsPendingIntent(VolumeInfo vol) {
Jeff Sharkey56bd3122015-04-14 10:30:34 -0700668 final Intent intent = new Intent();
Dmitri Plotnikov519c0882017-02-13 14:37:05 -0800669 if (isTv()) {
670 intent.setPackage("com.android.tv.settings");
671 intent.setAction(Settings.ACTION_INTERNAL_STORAGE_SETTINGS);
672 } else {
673 switch (vol.getType()) {
674 case VolumeInfo.TYPE_PRIVATE:
675 intent.setClassName("com.android.settings",
676 "com.android.settings.Settings$PrivateVolumeSettingsActivity");
677 break;
678 case VolumeInfo.TYPE_PUBLIC:
679 intent.setClassName("com.android.settings",
680 "com.android.settings.Settings$PublicVolumeSettingsActivity");
681 break;
682 default:
683 return null;
684 }
Jeff Sharkey50a05452015-04-29 11:24:52 -0700685 }
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -0700686 intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId());
687
688 final int requestKey = vol.getId().hashCode();
689 return PendingIntent.getActivityAsUser(mContext, requestKey, intent,
690 PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT);
691 }
692
Jeff Sharkey52fc3c0f2015-06-14 20:58:54 -0700693 private PendingIntent buildSnoozeIntent(String fsUuid) {
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -0700694 final Intent intent = new Intent(ACTION_SNOOZE_VOLUME);
Jeff Sharkey52fc3c0f2015-06-14 20:58:54 -0700695 intent.putExtra(VolumeRecord.EXTRA_FS_UUID, fsUuid);
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -0700696
Jeff Sharkey52fc3c0f2015-06-14 20:58:54 -0700697 final int requestKey = fsUuid.hashCode();
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -0700698 return PendingIntent.getBroadcastAsUser(mContext, requestKey, intent,
699 PendingIntent.FLAG_CANCEL_CURRENT, UserHandle.CURRENT);
San Mehat64e6a452010-02-04 20:53:48 -0800700 }
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700701
702 private PendingIntent buildForgetPendingIntent(VolumeRecord rec) {
Dmitri Plotnikov519c0882017-02-13 14:37:05 -0800703 // Not used on TV
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700704 final Intent intent = new Intent();
705 intent.setClassName("com.android.settings",
706 "com.android.settings.Settings$PrivateVolumeForgetActivity");
707 intent.putExtra(VolumeRecord.EXTRA_FS_UUID, rec.getFsUuid());
708
709 final int requestKey = rec.getFsUuid().hashCode();
710 return PendingIntent.getActivityAsUser(mContext, requestKey, intent,
711 PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT);
712 }
Jeff Sharkey50a05452015-04-29 11:24:52 -0700713
714 private PendingIntent buildWizardMigratePendingIntent(MoveInfo move) {
715 final Intent intent = new Intent();
Dmitri Plotnikov519c0882017-02-13 14:37:05 -0800716 if (isTv()) {
717 intent.setPackage("com.android.tv.settings");
718 intent.setAction("com.android.tv.settings.action.MIGRATE_STORAGE");
719 } else {
720 intent.setClassName("com.android.settings",
721 "com.android.settings.deviceinfo.StorageWizardMigrateProgress");
722 }
Jeff Sharkey50a05452015-04-29 11:24:52 -0700723 intent.putExtra(PackageManager.EXTRA_MOVE_ID, move.moveId);
724
725 final VolumeInfo vol = mStorageManager.findVolumeByQualifiedUuid(move.volumeUuid);
Suprabh Shuklaaf6c4192016-04-27 14:05:54 -0700726 if (vol != null) {
727 intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId());
728 }
Jeff Sharkey50a05452015-04-29 11:24:52 -0700729 return PendingIntent.getActivityAsUser(mContext, move.moveId, intent,
730 PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT);
731 }
732
733 private PendingIntent buildWizardMovePendingIntent(MoveInfo move) {
734 final Intent intent = new Intent();
Dmitri Plotnikov519c0882017-02-13 14:37:05 -0800735 if (isTv()) {
736 intent.setPackage("com.android.tv.settings");
737 intent.setAction("com.android.tv.settings.action.MOVE_APP");
738 } else {
739 intent.setClassName("com.android.settings",
740 "com.android.settings.deviceinfo.StorageWizardMoveProgress");
741 }
Jeff Sharkey50a05452015-04-29 11:24:52 -0700742 intent.putExtra(PackageManager.EXTRA_MOVE_ID, move.moveId);
743
744 return PendingIntent.getActivityAsUser(mContext, move.moveId, intent,
745 PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT);
746 }
747
748 private PendingIntent buildWizardReadyPendingIntent(DiskInfo disk) {
749 final Intent intent = new Intent();
Dmitri Plotnikov519c0882017-02-13 14:37:05 -0800750 if (isTv()) {
751 intent.setPackage("com.android.tv.settings");
752 intent.setAction(Settings.ACTION_INTERNAL_STORAGE_SETTINGS);
753 } else {
754 intent.setClassName("com.android.settings",
755 "com.android.settings.deviceinfo.StorageWizardReady");
756 }
Jeff Sharkey50a05452015-04-29 11:24:52 -0700757 intent.putExtra(DiskInfo.EXTRA_DISK_ID, disk.getId());
758
759 final int requestKey = disk.getId().hashCode();
760 return PendingIntent.getActivityAsUser(mContext, requestKey, intent,
761 PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT);
762 }
Dmitri Plotnikov519c0882017-02-13 14:37:05 -0800763
Heemin Seog91fab5c2019-06-17 15:11:27 -0700764 private boolean isAutomotive() {
765 PackageManager packageManager = mContext.getPackageManager();
766 return packageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
767 }
768
Dmitri Plotnikov519c0882017-02-13 14:37:05 -0800769 private boolean isTv() {
770 PackageManager packageManager = mContext.getPackageManager();
771 return packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK);
772 }
San Mehat64e6a452010-02-04 20:53:48 -0800773}