Find graceful description when missing disk.
Certain volumes (like internal storage) don't have a corresponding
DiskInfo object, so we need to fall back to using the VolumeInfo
description instead.
Bug: 77991425
Test: atest com.android.settings.ui.StorageWizardTest
Change-Id: I92d377035b6028dd31527100da54bfb1d1828ae9
diff --git a/src/com/android/settings/deviceinfo/StorageWizardBase.java b/src/com/android/settings/deviceinfo/StorageWizardBase.java
index 4787ac5..40fc249 100644
--- a/src/com/android/settings/deviceinfo/StorageWizardBase.java
+++ b/src/com/android/settings/deviceinfo/StorageWizardBase.java
@@ -22,6 +22,7 @@
import static com.android.settings.deviceinfo.StorageSettings.TAG;
import android.annotation.LayoutRes;
+import android.annotation.NonNull;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
@@ -145,7 +146,7 @@
((TextView) aux.requireViewById(R.id.storage_wizard_migrate_v2_checklist_media))
.setText(TextUtils.expandTemplate(
getText(R.string.storage_wizard_migrate_v2_checklist_media),
- mDisk.getShortDescription()));
+ getDiskShortDescription()));
}
protected void setBackButtonText(int resId, CharSequence... args) {
@@ -228,6 +229,26 @@
}
}
+ protected @NonNull CharSequence getDiskDescription() {
+ if (mDisk != null) {
+ return mDisk.getDescription();
+ } else if (mVolume != null) {
+ return mVolume.getDescription();
+ } else {
+ return getText(R.string.unknown);
+ }
+ }
+
+ protected @NonNull CharSequence getDiskShortDescription() {
+ if (mDisk != null) {
+ return mDisk.getShortDescription();
+ } else if (mVolume != null) {
+ return mVolume.getDescription();
+ } else {
+ return getText(R.string.unknown);
+ }
+ }
+
private final StorageEventListener mStorageListener = new StorageEventListener() {
@Override
public void onDiskDestroyed(DiskInfo disk) {
diff --git a/src/com/android/settings/deviceinfo/StorageWizardFormatProgress.java b/src/com/android/settings/deviceinfo/StorageWizardFormatProgress.java
index 8e3f8ef..0711907 100644
--- a/src/com/android/settings/deviceinfo/StorageWizardFormatProgress.java
+++ b/src/com/android/settings/deviceinfo/StorageWizardFormatProgress.java
@@ -57,8 +57,8 @@
mFormatPrivate = getIntent().getBooleanExtra(EXTRA_FORMAT_PRIVATE, false);
- setHeaderText(R.string.storage_wizard_format_progress_title, mDisk.getShortDescription());
- setBodyText(R.string.storage_wizard_format_progress_body, mDisk.getDescription());
+ setHeaderText(R.string.storage_wizard_format_progress_title, getDiskShortDescription());
+ setBodyText(R.string.storage_wizard_format_progress_body, getDiskDescription());
mTask = (PartitionTask) getLastNonConfigurationInstance();
if (mTask == null) {
diff --git a/src/com/android/settings/deviceinfo/StorageWizardFormatSlow.java b/src/com/android/settings/deviceinfo/StorageWizardFormatSlow.java
index 9c80ff6..37df2170 100644
--- a/src/com/android/settings/deviceinfo/StorageWizardFormatSlow.java
+++ b/src/com/android/settings/deviceinfo/StorageWizardFormatSlow.java
@@ -39,10 +39,10 @@
mFormatPrivate = getIntent().getBooleanExtra(EXTRA_FORMAT_PRIVATE, false);
- setHeaderText(R.string.storage_wizard_slow_v2_title, mDisk.getShortDescription());
- setBodyText(R.string.storage_wizard_slow_v2_body, mDisk.getDescription(),
- mDisk.getShortDescription(), mDisk.getShortDescription(),
- mDisk.getShortDescription());
+ setHeaderText(R.string.storage_wizard_slow_v2_title, getDiskShortDescription());
+ setBodyText(R.string.storage_wizard_slow_v2_body, getDiskDescription(),
+ getDiskShortDescription(), getDiskShortDescription(),
+ getDiskShortDescription());
setBackButtonText(R.string.storage_wizard_slow_v2_start_over);
setNextButtonText(R.string.storage_wizard_slow_v2_continue);
diff --git a/src/com/android/settings/deviceinfo/StorageWizardInit.java b/src/com/android/settings/deviceinfo/StorageWizardInit.java
index 2233cf9..0fc850b 100644
--- a/src/com/android/settings/deviceinfo/StorageWizardInit.java
+++ b/src/com/android/settings/deviceinfo/StorageWizardInit.java
@@ -45,7 +45,7 @@
mIsPermittedToAdopt = UserManager.get(this).isAdminUser()
&& !ActivityManager.isUserAMonkey();
- setHeaderText(R.string.storage_wizard_init_v2_title, mDisk.getShortDescription());
+ setHeaderText(R.string.storage_wizard_init_v2_title, getDiskShortDescription());
mExternal = requireViewById(R.id.storage_wizard_init_external);
mInternal = requireViewById(R.id.storage_wizard_init_internal);
diff --git a/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java b/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java
index 755f093..969a50a 100644
--- a/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java
+++ b/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java
@@ -59,7 +59,7 @@
}
setIcon(R.drawable.ic_swap_horiz);
- setHeaderText(R.string.storage_wizard_migrate_v2_title, mDisk.getShortDescription());
+ setHeaderText(R.string.storage_wizard_migrate_v2_title, getDiskShortDescription());
setBodyText(R.string.memory_calculating_size);
setAuxChecklist();
@@ -67,7 +67,7 @@
@Override
public void onPostExecute(String size, String time) {
setBodyText(R.string.storage_wizard_migrate_v2_body,
- mDisk.getDescription(), size, time);
+ getDiskDescription(), size, time);
}
};
diff --git a/src/com/android/settings/deviceinfo/StorageWizardReady.java b/src/com/android/settings/deviceinfo/StorageWizardReady.java
index c5c4ca2..fdb8d8a 100644
--- a/src/com/android/settings/deviceinfo/StorageWizardReady.java
+++ b/src/com/android/settings/deviceinfo/StorageWizardReady.java
@@ -33,20 +33,20 @@
}
setContentView(R.layout.storage_wizard_generic);
- setHeaderText(R.string.storage_wizard_ready_title, mDisk.getShortDescription());
+ setHeaderText(R.string.storage_wizard_ready_title, getDiskShortDescription());
final VolumeInfo privateVol = findFirstVolume(VolumeInfo.TYPE_PRIVATE);
if (privateVol != null) {
if (getIntent().getBooleanExtra(EXTRA_MIGRATE_SKIP, false)) {
setBodyText(R.string.storage_wizard_ready_v2_internal_body,
- mDisk.getDescription());
+ getDiskDescription());
} else {
setBodyText(R.string.storage_wizard_ready_v2_internal_moved_body,
- mDisk.getDescription(), mDisk.getShortDescription());
+ getDiskDescription(), getDiskShortDescription());
}
} else {
setBodyText(R.string.storage_wizard_ready_v2_external_body,
- mDisk.getDescription());
+ getDiskDescription());
}
setNextButtonText(R.string.done);