diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 1735a517e25..f94b6ba5dbb 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2486,33 +2486,41 @@
+ android:theme="@style/GlifTheme.Light"
+ android:exported="false"
+ android:configChanges="keyboardHidden|orientation|screenSize"/>
+ android:theme="@style/GlifTheme.Light"
+ android:exported="false"
+ android:configChanges="keyboardHidden|orientation|screenSize"/>
+ android:theme="@style/GlifTheme.Light"
+ android:exported="false"
+ android:configChanges="keyboardHidden|orientation|screenSize"/>
+ android:theme="@style/GlifTheme.Light"
+ android:exported="false"
+ android:configChanges="keyboardHidden|orientation|screenSize"/>
diff --git a/res/drawable/ic_storage_wizard_external.xml b/res/drawable/ic_storage_wizard_external.xml
index 99e2698633d..c6fefa1e99d 100644
--- a/res/drawable/ic_storage_wizard_external.xml
+++ b/res/drawable/ic_storage_wizard_external.xml
@@ -1,3 +1,4 @@
+
+ android:width="360dp"
+ android:height="262dp"
+ android:viewportWidth="360"
+ android:viewportHeight="262">
+
+ android:fillColor="@android:color/transparent"
+ android:pathData="M335.709 262H24.2913C10.9223 262 0 250.821 0 237.11V24.89C0 11.1787 10.9223 0 24.2913 0H335.796C349.078 0 360 11.1787 360 24.89V237.285C360 250.821 349.078 262 335.709 262Z" />
+ android:fillColor="@android:color/transparent"
+ android:pathData="M153.786 66.0239H319.806C322.777 66.0239 325.223 68.4693 325.311 71.4386V183.575H148.282V71.4386C148.282 68.4693 150.728 66.0239 153.786 66.0239Z"
+ android:strokeWidth="5"
+ android:strokeColor="#E8EAED"/>
+ android:fillColor="#BDC1C6"
+ android:pathData="M182.272 180.605H171.961V183.4H182.272V180.605Z" />
+ android:fillColor="#BDC1C6"
+ android:pathData="M195.204 180.605H184.893V183.4H195.204V180.605Z" />
-
+ android:pathData="M78.8155 104.538V100.521C78.8155 99.9967 78.3786 99.5601 77.8544 99.5601V78.6001C77.8544 75.8054 75.5825 73.6221 72.8738 73.6221H26.8252C24.0291 73.6221 21.8447 75.8054 21.8447 78.6001V174.492C21.8447 177.287 24.1165 179.47 26.8252 179.47H72.7864C75.5825 179.47 77.767 177.199 77.767 174.492V125.585C78.2913 125.585 78.7282 125.149 78.7282 124.625V114.581C78.7282 114.057 78.2913 113.621 77.767 113.621V105.586C78.3786 105.499 78.8155 105.062 78.8155 104.538ZM76.8058 174.492C76.8058 176.675 74.9709 178.509 72.7864 178.509H26.8252C24.6408 178.509 22.8058 176.675 22.8058 174.492V78.6001C22.8058 76.4167 24.5534 74.5827 26.8252 74.5827H72.7864C74.9709 74.5827 76.8058 76.3294 76.8058 78.6001V174.492Z" />
+ android:fillColor="#81C995"
+ android:pathData="M35.2136 102.18H47.534V89.8658H35.2136V102.18ZM35.2136 103.926C34.2524 103.926 33.466 103.14 33.466 102.18V89.8658C33.466 88.9051 34.2524 88.1191 35.2136 88.1191H47.534C47.9709 88.1191 48.4077 88.2938 48.7573 88.6431C49.1068 88.9925 49.2815 89.4291 49.2815 89.8658V102.18C49.2815 103.14 48.4951 103.926 47.534 103.926H35.2136ZM36.0874 100.433H46.5728L43.2524 96.0665L40.6311 99.5598L38.6213 96.9398L36.0874 100.433ZM35.2136 89.8658V102.18V89.8658Z" />
+
+
+
+
+
+
+
+
+
+ android:pathData="M134.65 182.09H338.854V184.186C338.854 185.758 337.631 186.981 336.058 186.981H137.447C135.874 186.981 134.65 185.758 134.65 184.186V182.09Z" />
+ android:fillColor="#81C995"
+ android:pathData="M177.204 129.69H193.456V113.446H177.204V129.69ZM177.204 132.048C175.893 132.048 174.845 131 174.845 129.69V113.446C174.845 112.136 175.893 111.088 177.204 111.088H193.456C194.767 111.088 195.816 112.136 195.816 113.446V129.69C195.816 131 194.767 132.048 193.456 132.048H177.204ZM178.34 127.332H192.32L187.951 121.481L184.456 126.109L181.835 122.616L178.34 127.332ZM177.204 113.359V129.69V113.359Z" />
+
+
+
+
+
+
+
+
+
+ android:pathData="M107.126 114.669H109.66V112.136H107.126V114.669ZM117.087 114.669H119.621V112.136H117.087V114.669ZM107.126 109.691H109.66V104.713H107.126V109.691ZM112.107 114.669H114.641V109.691H112.107V114.669ZM112.107 107.158H114.641V104.626H112.107V107.158ZM117.087 109.691H119.621V104.713H117.087V109.691ZM105.903 118.424C105.204 118.424 104.592 118.162 104.155 117.726C103.718 117.289 103.456 116.678 103.456 115.979V101.045L110.971 93.5342H120.932C121.631 93.5342 122.243 93.7962 122.68 94.2328C123.204 94.7568 123.379 95.2808 123.379 95.9795V115.892C123.379 116.59 123.116 117.202 122.68 117.638C122.155 118.162 121.631 118.337 120.932 118.337L105.903 118.424ZM105.903 115.892H120.845V95.9795H111.932L105.903 102.006V115.892ZM105.903 115.892V102.006L111.932 95.9795H120.845V115.892H105.903Z" />
+ android:pathData="M96.7281 150.388L101.447 145.672L98.8252 143.052L89.7379 152.222L98.8252 161.305L101.447 158.772L96.7281 154.056H137.01V150.388H96.7281Z" />
-
+ android:fillColor="?android:attr/colorAccent"
+ android:pathData="M130.019 137.026L125.301 141.742L127.922 144.362L137.01 135.192L127.922 126.109L125.301 128.642L130.019 133.358H89.7379V137.026H130.019Z" />
+
+
\ No newline at end of file
diff --git a/res/drawable/ic_storage_wizard_internal.xml b/res/drawable/ic_storage_wizard_internal.xml
index 41768f7727d..70bafa944ce 100644
--- a/res/drawable/ic_storage_wizard_internal.xml
+++ b/res/drawable/ic_storage_wizard_internal.xml
@@ -1,3 +1,4 @@
+
+ android:width="360dp"
+ android:height="262dp"
+ android:viewportWidth="360"
+ android:viewportHeight="262">
+
+ android:fillColor="@android:color/transparent"
+ android:pathData="M335.691 262H24.3087C10.9485 262 0 250.795 0 237.127V24.9075C0 11.2049 10.9485 0 24.3087 0H335.787C349.051 0 360 11.2049 360 24.8725V237.224C360 250.795 349.051 262 335.691 262Z" />
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+ android:pathData="M164.604 152.545H170.764V146.432H164.604V152.545ZM189.236 152.545H195.396V146.432H189.236V152.545ZM164.604 140.231H170.764V127.926H164.604V140.231ZM176.924 152.545H183.041V140.231H176.924V152.545ZM176.924 134.074H183.041V127.961H176.924V134.074ZM189.236 140.187H195.396V127.926H189.236V140.187ZM161.528 161.733C159.896 161.728 158.332 161.078 157.177 159.924C156.023 158.77 155.373 157.207 155.368 155.576V118.695L173.883 100.224H198.516C200.14 100.228 201.698 100.872 202.851 102.017C204.004 103.161 204.66 104.713 204.676 106.337V155.576C204.671 157.207 204.021 158.77 202.866 159.924C201.712 161.078 200.148 161.728 198.516 161.733H161.528ZM161.528 155.576H198.472V106.381H176.505L161.528 121.306V155.619V155.576ZM161.528 155.576V121.306L176.505 106.381H198.516V155.619H161.528V155.576Z" />
+
\ No newline at end of file
diff --git a/res/drawable/ic_storage_wizard_ready.xml b/res/drawable/ic_storage_wizard_ready.xml
new file mode 100644
index 00000000000..c09c9ec5310
--- /dev/null
+++ b/res/drawable/ic_storage_wizard_ready.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/drawable/ic_swap_horiz.xml b/res/drawable/ic_swap_horiz.xml
index a38833becab..c41c9a34381 100644
--- a/res/drawable/ic_swap_horiz.xml
+++ b/res/drawable/ic_swap_horiz.xml
@@ -20,5 +20,5 @@
android:viewportHeight="24.0">
+ android:fillColor="?android:attr/textColorPrimary"/>
diff --git a/res/drawable/ic_test_tick.xml b/res/drawable/ic_test_tick.xml
new file mode 100644
index 00000000000..9585806e985
--- /dev/null
+++ b/res/drawable/ic_test_tick.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/storage_internal_format.xml b/res/layout/storage_internal_format.xml
index 0b49d7e1660..f8224c4b6a4 100644
--- a/res/layout/storage_internal_format.xml
+++ b/res/layout/storage_internal_format.xml
@@ -14,16 +14,16 @@
limitations under the License.
-->
-
+ android:layout_height="wrap_content"
+ android:fillViewport="true">
-
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
-
-
-
-
+ android:padding="4dp">
+
+
+
-
+
diff --git a/res/layout/storage_wizard_generic.xml b/res/layout/storage_wizard_generic.xml
index e7881d3be87..fc0bab1a8d8 100644
--- a/res/layout/storage_wizard_generic.xml
+++ b/res/layout/storage_wizard_generic.xml
@@ -14,32 +14,52 @@
limitations under the License.
-->
-
+ android:layout_height="wrap_content"
+ android:fitsSystemWindows="true">
-
+ android:layout_height="match_parent">
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
diff --git a/res/layout/storage_wizard_init.xml b/res/layout/storage_wizard_init.xml
index e1e783312b1..2d21e0e983c 100644
--- a/res/layout/storage_wizard_init.xml
+++ b/res/layout/storage_wizard_init.xml
@@ -14,124 +14,30 @@
limitations under the License.
-->
-
+ android:layout_height="wrap_content"
+ android:fitsSystemWindows="true">
-
+ android:layout_height="match_parent">
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
\ No newline at end of file
diff --git a/res/layout/storage_wizard_init_external.xml b/res/layout/storage_wizard_init_external.xml
new file mode 100644
index 00000000000..38df28bc436
--- /dev/null
+++ b/res/layout/storage_wizard_init_external.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/storage_wizard_init_internal.xml b/res/layout/storage_wizard_init_internal.xml
new file mode 100644
index 00000000000..0a180703ed8
--- /dev/null
+++ b/res/layout/storage_wizard_init_internal.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/storage_wizard_progress.xml b/res/layout/storage_wizard_progress.xml
index 577ec3cbfc8..890be7076e9 100644
--- a/res/layout/storage_wizard_progress.xml
+++ b/res/layout/storage_wizard_progress.xml
@@ -14,47 +14,55 @@
limitations under the License.
-->
-
+ android:layout_height="wrap_content"
+ android:fitsSystemWindows="true">
-
+ android:layout_height="match_parent">
-
-
+
-
+
+
-
+
-
+
-
+
+
+
+
diff --git a/res/menu/storage_volume.xml b/res/menu/storage_volume.xml
index 422355d0fb7..b8725fb5d02 100644
--- a/res/menu/storage_volume.xml
+++ b/res/menu/storage_volume.xml
@@ -29,10 +29,10 @@
android:title="@string/storage_menu_format" />
+ android:title="@string/storage_menu_format_option" />
+ android:title="@string/storage_menu_format_option" />
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 26ebbf699b7..a4f5e0432ac 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -498,4 +498,6 @@
40dp
30dp
27dp
+
+ 88dp
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2c18441151a..067e43d53fb 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3512,12 +3512,14 @@
Mount
Eject
-
- Format
+
+ Format SD card for portable storage
+
+ Format card
Format as portable
-
- Format as internal
+
+ Format
Migrate data
@@ -3590,8 +3592,10 @@
\n\nTo use this ^1, you have to set it up first.
- After formatting, you can use this ^1 in other devices.
-\n\nAll data on this ^1 will be erased. Consider backing up first.
+ You can format this SD card to store photos, videos, music,
+ and more and access them on other devices.
+ \n\nAll data on this SD card will be erased.
+ \n\nBefore formatting
\n\nBack up photos & other media
\nMove your media files to alternative storage on this device, or transfer them to a computer using a USB cable.
\n\nBack up apps
@@ -3615,16 +3619,19 @@
System includes files used to run Android version %s
-
+
+ Guest mode users cannot format SD cards
+
+
Set up your ^1
- Use as portable storage
+ Format SD card for portable storage
- For moving photos and other media between devices.
+ Save photos, videos, music, and more and access them from other devices
- Use as internal storage
+ Format SD card for internal storage
- For storing anything on this device only, including apps and photos. Requires formatting that prevents it from working with other devices.
+ Save apps \u0026 media to use on this phone only
Format as internal storage
@@ -3679,13 +3686,11 @@
- Your ^1 is ready to use
+ ^1 formatted
- Your ^1 is all set to use with photos and other media.
+ You can start using your ^1
- Your new ^1 is working.
-\n\nTo move photos, files, and app data to this device, go to Settings > Storage.
-
+ You can start using your ^1
Move ^1
@@ -3715,26 +3720,26 @@
How will you use this ^1?
-
- Use for extra tablet storage
-
- For apps, files, and media on this tablet only
+
+ Format SD card for internal storage
+
+ Store apps \u0026 media to use on this tablet only. <a href="https://support.google.com/android/answer/12153449">Learn more about setting up an SD card</a>
- Tablet storage
-
- Use for extra phone storage
-
- For apps, files, and media on this phone only
+ Format
+
+ Format SD card for internal storage
+
+ Store apps \u0026 media to use on this phone only. <a href="https://support.google.com/android/answer/12153449">Learn more about setting up an SD card</a>
- Phone storage
+ Format
Or
-
- Use for portable storage
-
- For transferring files and media between devices
+
+ Format SD card for portable storage
+
+ Store photos, videos, music, and more and access them from other devices. <a href="https://support.google.com/android/answer/12153449">Learn more about setting up an SD card</a>
- Portable storage
+ Format
Set up later
@@ -3743,6 +3748,9 @@
This ^1 needs to be formatted to store apps, files, and media.
\n\nFormatting will erase existing content on the ^2. To avoid losing content, back it up to another ^3 or device.
+
+ This ^1 needs to be formatted to store photos, videos, music, and more.
+ \n\nFormatting will erase existing content on the ^2. To avoid losing content, back it up to another ^3 or device.
Format ^1
@@ -3786,12 +3794,11 @@
Continue
- You can move content to ^1
+ You can start using your ^1
- To move content to ^1, go to Settings > Storage
+ You can start using your ^1
- Your content was moved to ^1.
-\n\nTo manage this ^2, go to Settings > Storage.
+ You can start using your ^1
Battery status
@@ -7836,6 +7843,10 @@
Back
Next
+
+ Switch to portable
+
+ Format another way
Finish
diff --git a/src/com/android/settings/deviceinfo/PublicVolumeSettings.java b/src/com/android/settings/deviceinfo/PublicVolumeSettings.java
index f7dd85ab67a..d43b2541db7 100644
--- a/src/com/android/settings/deviceinfo/PublicVolumeSettings.java
+++ b/src/com/android/settings/deviceinfo/PublicVolumeSettings.java
@@ -19,6 +19,7 @@ package com.android.settings.deviceinfo;
import android.app.ActivityManager;
import android.app.settings.SettingsEnums;
import android.content.Context;
+import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.UserManager;
@@ -57,15 +58,34 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
private String mVolumeId;
private VolumeInfo mVolume;
+ private final View.OnClickListener mUnmountListener = new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ new UnmountTask(getActivity(), mVolume).execute();
+ }
+ };
private DiskInfo mDisk;
-
private UsageProgressBarPreference mSummary;
-
private Preference mMount;
private Preference mFormatPublic;
- private Preference mFormatPrivate;
private Button mUnmount;
+ private final StorageEventListener mStorageListener = new StorageEventListener() {
+ @Override
+ public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState) {
+ if (Objects.equals(mVolume.getId(), vol.getId())) {
+ mVolume = vol;
+ update();
+ }
+ }
+ @Override
+ public void onVolumeRecordChanged(VolumeRecord rec) {
+ if (Objects.equals(mVolume.getFsUuid(), rec.getFsUuid())) {
+ mVolume = mStorageManager.findVolumeById(mVolumeId);
+ update();
+ }
+ }
+ };
private boolean mIsPermittedToAdopt;
private boolean isVolumeValid() {
@@ -120,10 +140,7 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
mUnmount = new Button(getActivity());
mUnmount.setText(R.string.storage_menu_unmount);
mUnmount.setOnClickListener(mUnmountListener);
- mFormatPublic = buildAction(R.string.storage_menu_format);
- if (mIsPermittedToAdopt) {
- mFormatPrivate = buildAction(R.string.storage_menu_format_private);
- }
+ mFormatPublic = buildAction(R.string.storage_menu_format_option);
}
@Override
@@ -176,9 +193,6 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
mUnmount.setVisibility(View.GONE);
}
addPreference(mFormatPublic);
- if (mDisk.isAdoptable() && mIsPermittedToAdopt) {
- addPreference(mFormatPrivate);
- }
}
private void addPreference(Preference pref) {
@@ -215,39 +229,14 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
@Override
public boolean onPreferenceTreeClick(Preference pref) {
+ final Intent intent = new Intent(getActivity(), StorageWizardInit.class);
+ intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, mVolume.getId());
if (pref == mMount) {
new MountTask(getActivity(), mVolume).execute();
} else if (pref == mFormatPublic) {
- StorageWizardFormatConfirm.showPublic(getActivity(), mDisk.getId());
- } else if (pref == mFormatPrivate) {
- StorageWizardFormatConfirm.showPrivate(getActivity(), mDisk.getId());
+ startActivity(intent);
}
return super.onPreferenceTreeClick(pref);
}
-
- private final View.OnClickListener mUnmountListener = new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- new UnmountTask(getActivity(), mVolume).execute();
- }
- };
-
- private final StorageEventListener mStorageListener = new StorageEventListener() {
- @Override
- public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState) {
- if (Objects.equals(mVolume.getId(), vol.getId())) {
- mVolume = vol;
- update();
- }
- }
-
- @Override
- public void onVolumeRecordChanged(VolumeRecord rec) {
- if (Objects.equals(mVolume.getFsUuid(), rec.getFsUuid())) {
- mVolume = mStorageManager.findVolumeById(mVolumeId);
- update();
- }
- }
- };
-}
+}
\ No newline at end of file
diff --git a/src/com/android/settings/deviceinfo/StorageWizardBase.java b/src/com/android/settings/deviceinfo/StorageWizardBase.java
index b1b956e5fb5..801baecbc4e 100644
--- a/src/com/android/settings/deviceinfo/StorageWizardBase.java
+++ b/src/com/android/settings/deviceinfo/StorageWizardBase.java
@@ -41,17 +41,19 @@ import android.widget.TextView;
import androidx.fragment.app.FragmentActivity;
import com.android.settings.R;
-import com.android.settingslib.Utils;
+import com.android.settings.SetupWizardUtils;
import com.google.android.setupcompat.template.FooterBarMixin;
import com.google.android.setupcompat.template.FooterButton;
import com.google.android.setupdesign.GlifLayout;
+import com.google.android.setupdesign.util.ThemeHelper;
import java.text.NumberFormat;
import java.util.List;
import java.util.Objects;
public abstract class StorageWizardBase extends FragmentActivity {
+
private static final String TAG = "StorageWizardBase";
protected static final String EXTRA_FORMAT_FORGET_UUID = "format_forget_uuid";
@@ -70,6 +72,8 @@ public abstract class StorageWizardBase extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
+ setTheme(SetupWizardUtils.getTheme(this, getIntent()));
+ ThemeHelper.trySetDynamicColor(this);
super.onCreate(savedInstanceState);
mStorage = getSystemService(StorageManager.class);
@@ -97,20 +101,20 @@ public abstract class StorageWizardBase extends FragmentActivity {
mFooterBarMixin = getGlifLayout().getMixin(FooterBarMixin.class);
mFooterBarMixin.setSecondaryButton(
- new FooterButton.Builder(this)
- .setText(R.string.wizard_back)
- .setListener(this::onNavigateBack)
- .setButtonType(FooterButton.ButtonType.OTHER)
- .setTheme(R.style.SudGlifButton_Secondary)
- .build()
+ new FooterButton.Builder(this)
+ .setText(R.string.wizard_back)
+ .setListener(this::onNavigateBack)
+ .setButtonType(FooterButton.ButtonType.OTHER)
+ .setTheme(R.style.SudGlifButton_Secondary)
+ .build()
);
mFooterBarMixin.setPrimaryButton(
- new FooterButton.Builder(this)
- .setText(R.string.wizard_next)
- .setListener(this::onNavigateNext)
- .setButtonType(FooterButton.ButtonType.NEXT)
- .setTheme(R.style.SudGlifButton_Primary)
- .build()
+ new FooterButton.Builder(this)
+ .setText(R.string.wizard_next)
+ .setListener(this::onNavigateNext)
+ .setButtonType(FooterButton.ButtonType.NEXT)
+ .setTheme(R.style.SudGlifButton_Primary)
+ .build()
);
mBack = mFooterBarMixin.getSecondaryButton();
mNext = mFooterBarMixin.getPrimaryButton();
@@ -149,7 +153,7 @@ public abstract class StorageWizardBase extends FragmentActivity {
protected void setCurrentProgress(int progress) {
getProgressBar().setProgress(progress);
((TextView) requireViewById(R.id.storage_wizard_progress_summary)).setText(
- NumberFormat.getPercentInstance().format((double) progress / 100));
+ NumberFormat.getPercentInstance().format((double) progress / 100));
}
protected void setHeaderText(int resId, CharSequence... args) {
@@ -167,14 +171,14 @@ public abstract class StorageWizardBase extends FragmentActivity {
protected void setAuxChecklist() {
final FrameLayout aux = requireViewById(R.id.storage_wizard_aux);
aux.addView(LayoutInflater.from(aux.getContext())
- .inflate(R.layout.storage_wizard_checklist, aux, false));
+ .inflate(R.layout.storage_wizard_checklist, aux, false));
aux.setVisibility(View.VISIBLE);
// Customize string based on disk
((TextView) aux.requireViewById(R.id.storage_wizard_migrate_v2_checklist_media))
- .setText(TextUtils.expandTemplate(
- getText(R.string.storage_wizard_migrate_v2_checklist_media),
- getDiskShortDescription()));
+ .setText(TextUtils.expandTemplate(
+ getText(R.string.storage_wizard_migrate_v2_checklist_media),
+ getDiskShortDescription()));
}
protected void setBackButtonText(int resId, CharSequence... args) {
@@ -198,7 +202,6 @@ public abstract class StorageWizardBase extends FragmentActivity {
protected void setIcon(int resId) {
final GlifLayout layout = getGlifLayout();
final Drawable icon = getDrawable(resId).mutate();
- icon.setTintList(Utils.getColorAccent(layout.getContext()));
layout.setIcon(icon);
}
@@ -250,14 +253,14 @@ public abstract class StorageWizardBase extends FragmentActivity {
final List vols = mStorage.getVolumes();
for (VolumeInfo vol : vols) {
if (Objects.equals(mDisk.getId(), vol.getDiskId()) && (vol.getType() == type)
- && (vol.getState() == VolumeInfo.STATE_MOUNTED)) {
+ && (vol.getState() == VolumeInfo.STATE_MOUNTED)) {
return vol;
}
}
if (--attempts > 0) {
Log.w(TAG, "Missing mounted volume of type " + type + " hosted by disk "
- + mDisk.getId() + "; trying again");
+ + mDisk.getId() + "; trying again");
SystemClock.sleep(250);
} else {
return null;
@@ -265,7 +268,8 @@ public abstract class StorageWizardBase extends FragmentActivity {
}
}
- protected @NonNull CharSequence getDiskDescription() {
+ protected @NonNull
+ CharSequence getDiskDescription() {
if (mDisk != null) {
return mDisk.getDescription();
} else if (mVolume != null) {
@@ -275,7 +279,8 @@ public abstract class StorageWizardBase extends FragmentActivity {
}
}
- protected @NonNull CharSequence getDiskShortDescription() {
+ protected @NonNull
+ CharSequence getDiskShortDescription() {
if (mDisk != null) {
return mDisk.getShortDescription();
} else if (mVolume != null) {
@@ -294,4 +299,4 @@ public abstract class StorageWizardBase extends FragmentActivity {
}
}
};
-}
+}
\ No newline at end of file
diff --git a/src/com/android/settings/deviceinfo/StorageWizardFormatConfirm.java b/src/com/android/settings/deviceinfo/StorageWizardFormatConfirm.java
index 9c18a0da608..e2d8c7edddc 100644
--- a/src/com/android/settings/deviceinfo/StorageWizardFormatConfirm.java
+++ b/src/com/android/settings/deviceinfo/StorageWizardFormatConfirm.java
@@ -84,15 +84,23 @@ public class StorageWizardFormatConfirm extends InstrumentedDialogFragment {
builder.setTitle(TextUtils.expandTemplate(
getText(R.string.storage_wizard_format_confirm_v2_title),
disk.getShortDescription()));
- builder.setMessage(TextUtils.expandTemplate(
- getText(R.string.storage_wizard_format_confirm_v2_body),
+ if (formatPrivate) {
+ builder.setMessage(TextUtils.expandTemplate(
+ getText(R.string.storage_wizard_format_confirm_v2_body),
+ disk.getDescription(),
+ disk.getShortDescription(),
+ disk.getShortDescription()));
+ } else {
+ builder.setMessage(TextUtils.expandTemplate(
+ getText(R.string.storage_wizard_format_confirm_v2_body_external),
disk.getDescription(),
disk.getShortDescription(),
disk.getShortDescription()));
+ }
builder.setNegativeButton(android.R.string.cancel, null);
builder.setPositiveButton(
- TextUtils.expandTemplate(getText(R.string.storage_wizard_format_confirm_v2_action),
+ TextUtils.expandTemplate(getText(R.string.storage_menu_format_option),
disk.getShortDescription()),
(dialog, which) -> {
final Intent intent = new Intent(context, StorageWizardFormatProgress.class);
@@ -104,4 +112,4 @@ public class StorageWizardFormatConfirm extends InstrumentedDialogFragment {
return builder.create();
}
-}
+}
\ No newline at end of file
diff --git a/src/com/android/settings/deviceinfo/StorageWizardInit.java b/src/com/android/settings/deviceinfo/StorageWizardInit.java
index 426395c24fe..3a0f7e61df7 100644
--- a/src/com/android/settings/deviceinfo/StorageWizardInit.java
+++ b/src/com/android/settings/deviceinfo/StorageWizardInit.java
@@ -18,21 +18,27 @@ package com.android.settings.deviceinfo;
import android.app.ActivityManager;
import android.app.settings.SettingsEnums;
-import android.content.Intent;
import android.os.Bundle;
import android.os.UserManager;
-import android.os.storage.DiskInfo;
-import android.os.storage.VolumeInfo;
+import android.text.Html;
+import android.text.Spannable;
+import android.text.method.LinkMovementMethod;
+import android.text.style.TypefaceSpan;
+import android.text.style.URLSpan;
import android.view.View;
-import android.widget.Button;
+import android.widget.TextView;
+import android.widget.Toast;
+import android.widget.ViewFlipper;
import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
public class StorageWizardInit extends StorageWizardBase {
- private Button mInternal;
private boolean mIsPermittedToAdopt;
+ private boolean mPortable;
+
+ private ViewFlipper mFlipper;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -41,63 +47,119 @@ public class StorageWizardInit extends StorageWizardBase {
finish();
return;
}
- setContentView(R.layout.storage_wizard_init);
mIsPermittedToAdopt = UserManager.get(this).isAdminUser()
- && !ActivityManager.isUserAMonkey();
+ && !ActivityManager.isUserAMonkey();
- setHeaderText(R.string.storage_wizard_init_v2_title, getDiskShortDescription());
+ if (!mIsPermittedToAdopt) {
+ //Notify guest users as to why formatting is disallowed
+ Toast.makeText(getApplicationContext(),
+ R.string.storage_wizard_guest, Toast.LENGTH_LONG).show();
+ finish();
+ return;
+ }
- mInternal = requireViewById(R.id.storage_wizard_init_internal);
+ setContentView(R.layout.storage_wizard_init);
+ setupHyperlink();
+ mPortable = true;
- setBackButtonText(R.string.storage_wizard_init_v2_later);
- setNextButtonVisibility(View.INVISIBLE);
+ mFlipper = (ViewFlipper) findViewById(R.id.viewFlipper);
+ mFlipper.setDisplayedChild(0);
+ setHeaderText(R.string.storage_wizard_init_v2_external_title,
+ getDiskShortDescription());
+
+ setNextButtonText(R.string.storage_wizard_init_v2_external_action);
+ setBackButtonText(R.string.wizard_back_adoptable);
+ setNextButtonVisibility(View.VISIBLE);
if (!mDisk.isAdoptable()) {
- // If not adoptable, we only have one choice
- mInternal.setEnabled(false);
- onNavigateExternal(null);
- } else if (!mIsPermittedToAdopt) {
- // TODO: Show a message about why this is disabled for guest and
- // that only an admin user can adopt an sd card.
- mInternal.setEnabled(false);
+ setBackButtonVisibility(View.GONE);
}
}
@Override
- public void onNavigateBack(View view) {
- finish();
+ public void onBackPressed() {
+ if (mPortable) {
+ super.onBackPressed();
+ } else {
+ mFlipper.showPrevious();
+ setBackButtonText(R.string.wizard_back_adoptable);
+ setHeaderText(R.string.storage_wizard_init_v2_external_title,
+ getDiskShortDescription());
+ setNextButtonText(R.string.storage_wizard_init_v2_external_action);
+ mPortable = true;
+ }
+ }
+
+ @Override
+ public void onNavigateBack(View v) {
+ if (mPortable == false) {
+ return;
+ }
+ if (!mIsPermittedToAdopt) {
+ // TODO: Show a message about why this is disabled for guest and
+ // that only an admin user can adopt an sd card.
+
+ v.setEnabled(false);
+ } else {
+ mFlipper.showNext();
+ setHeaderText(R.string.storage_wizard_init_v2_internal_title,
+ getDiskShortDescription());
+ setNextButtonText(R.string.storage_wizard_init_v2_internal_action);
+ setBackButtonVisibility(View.INVISIBLE);
+ mPortable = false;
+ }
+ }
+
+ @Override
+ public void onNavigateNext(View v) {
+ if (mPortable) {
+ onNavigateExternal(v);
+ } else {
+ onNavigateInternal(v);
+ }
}
public void onNavigateExternal(View view) {
if (view != null) {
// User made an explicit choice for external
FeatureFactory.getFactory(this).getMetricsFeatureProvider().action(this,
- SettingsEnums.ACTION_STORAGE_INIT_EXTERNAL);
- }
-
- if (mVolume != null && mVolume.getType() == VolumeInfo.TYPE_PUBLIC
- && mVolume.getState() != VolumeInfo.STATE_UNMOUNTABLE) {
- // Remember that user made decision
- mStorage.setVolumeInited(mVolume.getFsUuid(), true);
-
- final Intent intent = new Intent(this, StorageWizardReady.class);
- intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
- startActivity(intent);
- finish();
-
- } else {
- // Gotta format to get there
- StorageWizardFormatConfirm.showPublic(this, mDisk.getId());
+ SettingsEnums.ACTION_STORAGE_INIT_EXTERNAL);
}
+ StorageWizardFormatConfirm.showPublic(this, mDisk.getId());
}
public void onNavigateInternal(View view) {
if (view != null) {
// User made an explicit choice for internal
FeatureFactory.getFactory(this).getMetricsFeatureProvider().action(this,
- SettingsEnums.ACTION_STORAGE_INIT_INTERNAL);
+ SettingsEnums.ACTION_STORAGE_INIT_INTERNAL);
}
-
StorageWizardFormatConfirm.showPrivate(this, mDisk.getId());
}
+
+ private void setupHyperlink() {
+ TextView external_storage_textview = findViewById(R.id.storage_wizard_init_external_text);
+ TextView internal_storage_textview = findViewById(R.id.storage_wizard_init_internal_text);
+ String external_storage_text = getResources().getString(R.string.
+ storage_wizard_init_v2_external_summary);
+ String internal_storage_text = getResources().getString(R.string.
+ storage_wizard_init_v2_internal_summary);
+
+ Spannable external_storage_spannable = styleFont(external_storage_text);
+ Spannable internal_storage_spannable = styleFont(internal_storage_text);
+ external_storage_textview.setText(external_storage_spannable);
+ internal_storage_textview.setText(internal_storage_spannable);
+
+ external_storage_textview.setMovementMethod(LinkMovementMethod.getInstance());
+ internal_storage_textview.setMovementMethod(LinkMovementMethod.getInstance());
+ }
+
+ private Spannable styleFont(String text) {
+ Spannable s = (Spannable) Html.fromHtml(text);
+ for (URLSpan span : s.getSpans(0, s.length(), URLSpan.class)) {
+ TypefaceSpan typefaceSpan = new TypefaceSpan("sans-serif-medium");
+ s.setSpan(typefaceSpan, s.getSpanStart(span), s.getSpanEnd(span), 0);
+ }
+ return s;
+ }
}
diff --git a/src/com/android/settings/deviceinfo/StorageWizardReady.java b/src/com/android/settings/deviceinfo/StorageWizardReady.java
index 813bcc6e201..8de94724afd 100644
--- a/src/com/android/settings/deviceinfo/StorageWizardReady.java
+++ b/src/com/android/settings/deviceinfo/StorageWizardReady.java
@@ -19,6 +19,7 @@ package com.android.settings.deviceinfo;
import android.os.Bundle;
import android.os.storage.VolumeInfo;
import android.view.View;
+import android.widget.ImageView;
import com.android.settings.R;
@@ -48,7 +49,9 @@ public class StorageWizardReady extends StorageWizardBase {
setBodyText(R.string.storage_wizard_ready_v2_external_body,
getDiskDescription());
}
-
+ ImageView img = (ImageView) findViewById(R.id.storage_wizard_body_image);
+ img.setImageResource(R.drawable.ic_storage_wizard_ready);
+ setIcon(R.drawable.ic_test_tick);
setNextButtonText(R.string.done);
setBackButtonVisibility(View.INVISIBLE);
}
diff --git a/src/com/android/settings/deviceinfo/VolumeOptionMenuController.java b/src/com/android/settings/deviceinfo/VolumeOptionMenuController.java
index 4b87e422c1b..289db520ec0 100644
--- a/src/com/android/settings/deviceinfo/VolumeOptionMenuController.java
+++ b/src/com/android/settings/deviceinfo/VolumeOptionMenuController.java
@@ -30,6 +30,7 @@ import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
+import android.widget.Toast;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
@@ -55,7 +56,9 @@ public class VolumeOptionMenuController implements LifecycleObserver, OnCreateOp
OnPrepareOptionsMenu, OnOptionsItemSelected {
private static final String TAG = "VolumeOptionMenuController";
-
+ private final Context mContext;
+ private final Fragment mFragment;
+ private final PackageManager mPackageManager;
@VisibleForTesting
MenuItem mRename;
@VisibleForTesting
@@ -74,18 +77,12 @@ public class VolumeOptionMenuController implements LifecycleObserver, OnCreateOp
MenuItem mFree;
@VisibleForTesting
MenuItem mForget;
-
- private final Context mContext;
- private final Fragment mFragment;
- private final PackageManager mPackageManager;
- private final StorageManager mStorageManager;
private StorageEntry mStorageEntry;
public VolumeOptionMenuController(Context context, Fragment parent, StorageEntry storageEntry) {
mContext = context;
mFragment = parent;
mPackageManager = context.getPackageManager();
- mStorageManager = context.getSystemService(StorageManager.class);
mStorageEntry = storageEntry;
}
@@ -162,12 +159,7 @@ public class VolumeOptionMenuController implements LifecycleObserver, OnCreateOp
if (mStorageEntry.isPublic()) {
mRename.setVisible(true);
mUnmount.setVisible(true);
- mFormat.setVisible(true);
- final DiskInfo diskInfo = mStorageManager.findDiskById(mStorageEntry.getDiskId());
- mFormatAsInternal.setVisible(diskInfo != null
- && diskInfo.isAdoptable()
- && UserManager.get(mContext).isAdminUser()
- && !ActivityManager.isUserAMonkey());
+ mFormatAsInternal.setVisible(true);
return;
}
}
@@ -225,6 +217,16 @@ public class VolumeOptionMenuController implements LifecycleObserver, OnCreateOp
}
if (menuId == R.id.storage_format_as_portable) {
if (mStorageEntry.isPrivate()) {
+ boolean mIsPermittedToAdopt = UserManager.get(mContext).isAdminUser()
+ && !ActivityManager.isUserAMonkey();
+
+ if(!mIsPermittedToAdopt){
+ //Notify guest users as to why formatting is disallowed
+ Toast.makeText(mFragment.getActivity(),
+ R.string.storage_wizard_guest,Toast.LENGTH_LONG).show();
+ (mFragment.getActivity()).finish();
+ return false;
+ }
final Bundle args = new Bundle();
args.putString(VolumeInfo.EXTRA_VOLUME_ID, mStorageEntry.getId());
new SubSettingLauncher(mContext)
@@ -239,8 +241,9 @@ public class VolumeOptionMenuController implements LifecycleObserver, OnCreateOp
}
if (menuId == R.id.storage_format_as_internal) {
if (mStorageEntry.isPublic()) {
- StorageWizardFormatConfirm.showPrivate(mFragment.getActivity(),
- mStorageEntry.getDiskId());
+ final Intent intent = new Intent(mFragment.getActivity(), StorageWizardInit.class);
+ intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, mStorageEntry.getId());
+ mContext.startActivity(intent);
return true;
}
return false;
@@ -269,4 +272,4 @@ public class VolumeOptionMenuController implements LifecycleObserver, OnCreateOp
updateOptionsMenu();
}
-}
+}
\ No newline at end of file
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceControllerV2.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceControllerV2.java
index 6fd5f5841ba..175bba7189a 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceControllerV2.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceControllerV2.java
@@ -20,7 +20,6 @@ import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
-import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
@@ -28,6 +27,7 @@ import android.text.TextUtils;
import android.text.format.DateFormat;
import android.text.format.DateUtils;
import android.util.Log;
+import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
@@ -62,22 +62,19 @@ import java.util.Map;
/** Controls the update for chart graph and the list items. */
public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceController
implements PreferenceControllerMixin, LifecycleObserver, OnCreate, OnDestroy,
- OnSaveInstanceState, BatteryChartViewV2.OnSelectListener, OnResume,
- ExpandDividerPreference.OnExpandListener {
+ OnSaveInstanceState, OnResume, ExpandDividerPreference.OnExpandListener {
private static final String TAG = "BatteryChartPreferenceControllerV2";
private static final String KEY_FOOTER_PREF = "battery_graph_footer";
private static final String PACKAGE_NAME_NONE = "none";
- /** Desired battery history size for timestamp slots. */
- public static final int DESIRED_HISTORY_SIZE = 25;
- private static final int CHART_LEVEL_ARRAY_SIZE = 13;
- private static final int CHART_KEY_ARRAY_SIZE = DESIRED_HISTORY_SIZE;
+ private static final int TWENTY_FOUR_HOURS_TIME_SLOT_SIZE = 12;
private static final long VALID_USAGE_TIME_DURATION = DateUtils.HOUR_IN_MILLIS * 2;
private static final long VALID_DIFF_DURATION = DateUtils.MINUTE_IN_MILLIS * 3;
// Keys for bundle instance to restore configurations.
private static final String KEY_EXPAND_SYSTEM_INFO = "expand_system_info";
- private static final String KEY_CURRENT_TIME_SLOT = "current_time_slot";
+ private static final String KEY_DAILY_CHART_INDEX = "daily_chart_index";
+ private static final String KEY_HOURLY_CHART_INDEX = "hourly_chart_index";
private static int sUiMode = Configuration.UI_MODE_NIGHT_UNDEFINED;
@@ -91,23 +88,26 @@ public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceContro
@VisibleForTesting
PreferenceGroup mAppListPrefGroup;
@VisibleForTesting
- BatteryChartViewV2 mBatteryChartView;
- @VisibleForTesting
ExpandDividerPreference mExpandDividerPreference;
-
@VisibleForTesting
boolean mIsExpanded = false;
+
@VisibleForTesting
- long[] mBatteryHistoryKeys;
+ BatteryChartViewV2 mDailyChartView;
@VisibleForTesting
- BatteryChartViewModel mViewModel;
+ BatteryChartViewV2 mHourlyChartView;
+
@VisibleForTesting
- int mTrapezoidIndex = BatteryChartViewModel.SELECTED_INDEX_ALL;
+ int mDailyChartIndex = BatteryChartViewModel.SELECTED_INDEX_ALL;
+ @VisibleForTesting
+ int mHourlyChartIndex = BatteryChartViewModel.SELECTED_INDEX_ALL;
private boolean mIs24HourFormat;
private boolean mIsFooterPrefAdded = false;
private PreferenceScreen mPreferenceScreen;
private FooterPreference mFooterPreference;
+ private BatteryChartViewModel mDailyViewModel;
+ private List mHourlyViewModels;
private final String mPreferenceKey;
private final SettingsActivity mActivity;
@@ -152,12 +152,14 @@ public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceContro
if (savedInstanceState == null) {
return;
}
- mTrapezoidIndex =
- savedInstanceState.getInt(KEY_CURRENT_TIME_SLOT, mTrapezoidIndex);
+ mDailyChartIndex =
+ savedInstanceState.getInt(KEY_DAILY_CHART_INDEX, mDailyChartIndex);
+ mHourlyChartIndex =
+ savedInstanceState.getInt(KEY_HOURLY_CHART_INDEX, mHourlyChartIndex);
mIsExpanded =
savedInstanceState.getBoolean(KEY_EXPAND_SYSTEM_INFO, mIsExpanded);
- Log.d(TAG, String.format("onCreate() slotIndex=%d isExpanded=%b",
- mTrapezoidIndex, mIsExpanded));
+ Log.d(TAG, String.format("onCreate() dailyIndex=%d hourlyIndex=%d isExpanded=%b",
+ mDailyChartIndex, mHourlyChartIndex, mIsExpanded));
}
@Override
@@ -179,10 +181,11 @@ public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceContro
if (savedInstance == null) {
return;
}
- savedInstance.putInt(KEY_CURRENT_TIME_SLOT, mTrapezoidIndex);
+ savedInstance.putInt(KEY_DAILY_CHART_INDEX, mDailyChartIndex);
+ savedInstance.putInt(KEY_HOURLY_CHART_INDEX, mHourlyChartIndex);
savedInstance.putBoolean(KEY_EXPAND_SYSTEM_INFO, mIsExpanded);
- Log.d(TAG, String.format("onSaveInstanceState() slotIndex=%d isExpanded=%b",
- mTrapezoidIndex, mIsExpanded));
+ Log.d(TAG, String.format("onSaveInstanceState() dailyIndex=%d hourlyIndex=%d isExpanded=%b",
+ mDailyChartIndex, mHourlyChartIndex, mIsExpanded));
}
@Override
@@ -249,18 +252,6 @@ public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceContro
return true;
}
- @Override
- public void onSelect(int trapezoidIndex) {
- Log.d(TAG, "onChartSelect:" + trapezoidIndex);
- mTrapezoidIndex = trapezoidIndex;
- refreshUi();
- mMetricsFeatureProvider.action(
- mPrefContext,
- trapezoidIndex == BatteryChartViewModel.SELECTED_INDEX_ALL
- ? SettingsEnums.ACTION_BATTERY_USAGE_SHOW_ALL
- : SettingsEnums.ACTION_BATTERY_USAGE_TIME_SLOT);
- }
-
@Override
public void onExpand(boolean isExpanded) {
mIsExpanded = isExpanded;
@@ -273,68 +264,104 @@ public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceContro
void setBatteryHistoryMap(
final Map> batteryHistoryMap) {
- // Resets all battery history data relative variables.
- if (batteryHistoryMap == null || batteryHistoryMap.isEmpty()) {
- mBatteryIndexedMap = null;
- mBatteryHistoryKeys = null;
- mViewModel = null;
+ Log.d(TAG, "setBatteryHistoryMap() " + (batteryHistoryMap == null ? "null"
+ : ("size=" + batteryHistoryMap.size())));
+ final BatteryLevelData batteryLevelData =
+ DataProcessor.getBatteryLevelData(mContext, batteryHistoryMap);
+ Log.d(TAG, "getBatteryLevelData: " + batteryLevelData);
+ if (batteryLevelData == null) {
+ mDailyViewModel = null;
+ mHourlyViewModels = null;
addFooterPreferenceIfNeeded(false);
return;
}
- mBatteryHistoryKeys = getBatteryHistoryKeys(batteryHistoryMap);
- List levels = new ArrayList();
- for (int index = 0; index < CHART_LEVEL_ARRAY_SIZE; index++) {
- final long timestamp = mBatteryHistoryKeys[index * 2];
- final Map entryMap = batteryHistoryMap.get(timestamp);
- if (entryMap == null || entryMap.isEmpty()) {
- Log.e(TAG, "abnormal entry list in the timestamp:"
- + ConvertUtils.utcToLocalTime(mPrefContext, timestamp));
- levels.add(0);
- continue;
- }
- // Averages the battery level in each time slot to avoid corner conditions.
- float batteryLevelCounter = 0;
- for (BatteryHistEntry entry : entryMap.values()) {
- batteryLevelCounter += entry.mBatteryLevel;
- }
- levels.add(Math.round(batteryLevelCounter / entryMap.size()));
+ mDailyViewModel = new BatteryChartViewModel(
+ batteryLevelData.getDailyBatteryLevels().getLevels(),
+ generateTimestampDayOfWeekTexts(
+ mContext, batteryLevelData.getDailyBatteryLevels().getTimestamps()),
+ mDailyChartIndex);
+ mHourlyViewModels = new ArrayList<>();
+ for (BatteryLevelData.PeriodBatteryLevelData perDayData :
+ batteryLevelData.getHourlyBatteryLevelsPerDay()) {
+ mHourlyViewModels.add(new BatteryChartViewModel(
+ perDayData.getLevels(),
+ generateTimestampHourTexts(
+ mContext, perDayData.getTimestamps()),
+ mHourlyChartIndex));
}
- final List texts = generateTimestampTexts(mBatteryHistoryKeys, mContext);
- mViewModel = new BatteryChartViewModel(levels, texts, mTrapezoidIndex);
refreshUi();
- Log.d(TAG, String.format(
- "setBatteryHistoryMap() size=%d key=%s\nview model=%s",
- batteryHistoryMap.size(),
- ConvertUtils.utcToLocalTime(mPrefContext,
- mBatteryHistoryKeys[mBatteryHistoryKeys.length - 1]),
- mViewModel));
-
- // Loads item icon and label in the background.
- new LoadAllItemsInfoTask(batteryHistoryMap).execute();
+ // TODO: Loads item icon and label and build mBatteryIndexedMap.
}
- void setBatteryChartView(final BatteryChartViewV2 batteryChartView) {
- if (mBatteryChartView != batteryChartView) {
- mHandler.post(() -> setBatteryChartViewInner(batteryChartView));
+ void setBatteryChartView(@NonNull final BatteryChartViewV2 dailyChartView,
+ @NonNull final BatteryChartViewV2 hourlyChartView) {
+ if (mDailyChartView != dailyChartView || mHourlyChartView != hourlyChartView) {
+ mHandler.post(() -> setBatteryChartViewInner(dailyChartView, hourlyChartView));
}
}
- private void setBatteryChartViewInner(final BatteryChartViewV2 batteryChartView) {
- mBatteryChartView = batteryChartView;
- mBatteryChartView.setOnSelectListener(this);
+ private void setBatteryChartViewInner(@NonNull final BatteryChartViewV2 dailyChartView,
+ @NonNull final BatteryChartViewV2 hourlyChartView) {
+ mDailyChartView = dailyChartView;
+ mDailyChartView.setOnSelectListener(trapezoidIndex -> {
+ if (mDailyChartIndex == trapezoidIndex) {
+ return;
+ }
+ Log.d(TAG, "onDailyChartSelect:" + trapezoidIndex);
+ mDailyChartIndex = trapezoidIndex;
+ mHourlyChartIndex = BatteryChartView.SELECTED_INDEX_ALL;
+ refreshUi();
+ // TODO: Change to log daily data.
+ });
+ mHourlyChartView = hourlyChartView;
+ mHourlyChartView.setOnSelectListener(trapezoidIndex -> {
+ if (mHourlyChartIndex == trapezoidIndex) {
+ return;
+ }
+ Log.d(TAG, "onHourlyChartSelect:" + trapezoidIndex);
+ mHourlyChartIndex = trapezoidIndex;
+ refreshUi();
+ mMetricsFeatureProvider.action(
+ mPrefContext,
+ trapezoidIndex == BatteryChartViewModel.SELECTED_INDEX_ALL
+ ? SettingsEnums.ACTION_BATTERY_USAGE_SHOW_ALL
+ : SettingsEnums.ACTION_BATTERY_USAGE_TIME_SLOT);
+ });
refreshUi();
}
@VisibleForTesting
boolean refreshUi() {
- // Invalid refresh condition.
- if (mBatteryIndexedMap == null || mBatteryChartView == null) {
+ if (mBatteryIndexedMap == null || mDailyChartView == null || mHourlyChartView == null) {
return false;
}
- if (mViewModel != null) {
- mViewModel.setSelectedIndex(mTrapezoidIndex);
+
+ if (mDailyViewModel == null || mHourlyViewModels == null) {
+ // Fail to get battery level data, show an empty hourly chart view.
+ mDailyChartView.setVisibility(View.GONE);
+ mHourlyChartView.setViewModel(null);
+ return false;
+ }
+
+ if (isBatteryLevelDataInOneDay()) {
+ // Only 1 day data, hide the daily chart view.
+ mDailyChartView.setVisibility(View.GONE);
+ mDailyChartIndex = 0;
+ } else {
+ mDailyChartView.setVisibility(View.VISIBLE);
+ mDailyViewModel.setSelectedIndex(mDailyChartIndex);
+ mDailyChartView.setViewModel(mDailyViewModel);
+ }
+
+ if (mDailyChartIndex == BatteryChartViewModel.SELECTED_INDEX_ALL) {
+ // Multiple days are selected, hide the hourly chart view.
+ mHourlyChartView.setVisibility(View.GONE);
+ } else {
+ mHourlyChartView.setVisibility(View.VISIBLE);
+ final BatteryChartViewModel hourlyViewModel = mHourlyViewModels.get(mDailyChartIndex);
+ hourlyViewModel.setSelectedIndex(mHourlyChartIndex);
+ mHourlyChartView.setViewModel(hourlyViewModel);
}
- mBatteryChartView.setViewModel(mViewModel);
mHandler.post(() -> {
final long start = System.currentTimeMillis();
@@ -348,11 +375,13 @@ public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceContro
}
private void addAllPreferences() {
+ // TODO: Get the right diff entry according to daily and hourly chart selection.
+ final int index = mDailyChartIndex;
final List entries =
- mBatteryIndexedMap.get(Integer.valueOf(mTrapezoidIndex));
+ mBatteryIndexedMap.get(Integer.valueOf(index));
addFooterPreferenceIfNeeded(entries != null && !entries.isEmpty());
if (entries == null) {
- Log.w(TAG, "cannot find BatteryDiffEntry for:" + mTrapezoidIndex);
+ Log.w(TAG, "cannot find BatteryDiffEntry for:" + index);
return;
}
// Separates data into two groups and sort them individually.
@@ -370,7 +399,7 @@ public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceContro
appEntries.add(entry);
}
// Validates the usage time if users click a specific slot.
- if (mTrapezoidIndex >= 0) {
+ if (index >= 0) {
validateUsageTime(entry);
}
});
@@ -488,6 +517,7 @@ public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceContro
}
private String getSlotInformation(boolean isApp, String slotInformation) {
+ // TODO: Updates the right slot information from daily and hourly chart selection.
// Null means we show all information without a specific time slot.
if (slotInformation == null) {
return isApp
@@ -501,16 +531,8 @@ public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceContro
}
private String getSlotInformation() {
- if (mTrapezoidIndex < 0) {
- return null;
- }
- final String fromHour = ConvertUtils.utcToLocalTimeHour(mPrefContext,
- mBatteryHistoryKeys[mTrapezoidIndex * 2], mIs24HourFormat);
- final String toHour = ConvertUtils.utcToLocalTimeHour(mPrefContext,
- mBatteryHistoryKeys[(mTrapezoidIndex + 1) * 2], mIs24HourFormat);
- return mIs24HourFormat
- ? String.format("%sā%s", fromHour, toHour)
- : String.format("%s ā %s", fromHour, toHour);
+ // TODO: Generate the right slot information from daily and hourly chart selection.
+ return null;
}
@VisibleForTesting
@@ -584,13 +606,25 @@ public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceContro
mHandler.post(() -> mPreferenceScreen.addPreference(mFooterPreference));
}
- private static List generateTimestampTexts(
- @NonNull long[] timestamps, Context context) {
+ private boolean isBatteryLevelDataInOneDay() {
+ return mHourlyViewModels.size() == 1;
+ }
+
+ private static List generateTimestampDayOfWeekTexts(
+ @NonNull final Context context, @NonNull final List timestamps) {
+ final ArrayList texts = new ArrayList<>();
+ for (Long timestamp : timestamps) {
+ texts.add(ConvertUtils.utcToLocalTimeDayOfWeek(context, timestamp));
+ }
+ return texts;
+ }
+
+ private static List generateTimestampHourTexts(
+ @NonNull final Context context, @NonNull final List timestamps) {
final boolean is24HourFormat = DateFormat.is24HourFormat(context);
- final List texts = new ArrayList();
- for (int index = 0; index < CHART_LEVEL_ARRAY_SIZE; index++) {
- texts.add(ConvertUtils.utcToLocalTimeHour(context, timestamps[index * 2],
- is24HourFormat));
+ final ArrayList texts = new ArrayList<>();
+ for (Long timestamp : timestamps) {
+ texts.add(ConvertUtils.utcToLocalTimeHour(context, timestamp, is24HourFormat));
}
return texts;
}
@@ -620,6 +654,8 @@ public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceContro
return true;
}
+ // TODO: Change this method to fromLastFullCharged.
+
/** Used for {@link AppBatteryPreferenceController}. */
public static List getBatteryLast24HrUsageData(Context context) {
final long start = System.currentTimeMillis();
@@ -632,16 +668,27 @@ public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceContro
}
Log.d(TAG, String.format("getBatteryLast24HrData() size=%d time=%d/ms",
batteryHistoryMap.size(), (System.currentTimeMillis() - start)));
+
+ final List batteryHistoryKeyList =
+ new ArrayList<>(batteryHistoryMap.keySet());
+ Collections.sort(batteryHistoryKeyList);
+ final long[] batteryHistoryKeys = new long[TWENTY_FOUR_HOURS_TIME_SLOT_SIZE + 1];
+ for (int index = 0; index < batteryHistoryKeys.length; index++) {
+ batteryHistoryKeys[index] = batteryHistoryKeyList.get(index);
+ }
+
final Map> batteryIndexedMap =
ConvertUtils.getIndexedUsageMap(
context,
- /*timeSlotSize=*/ CHART_LEVEL_ARRAY_SIZE - 1,
- getBatteryHistoryKeys(batteryHistoryMap),
+ /*timeSlotSize=*/ TWENTY_FOUR_HOURS_TIME_SLOT_SIZE,
+ batteryHistoryKeys,
batteryHistoryMap,
/*purgeLowPercentageAndFakeData=*/ true);
return batteryIndexedMap.get(BatteryChartViewModel.SELECTED_INDEX_ALL);
}
+ // TODO: Change this method to fromLastFullCharged.
+
/** Used for {@link AppBatteryPreferenceController}. */
public static BatteryDiffEntry getBatteryLast24HrUsageData(
Context context, String packageName, int userId) {
@@ -663,65 +710,4 @@ public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceContro
}
return null;
}
-
- private static long[] getBatteryHistoryKeys(
- final Map> batteryHistoryMap) {
- final List batteryHistoryKeyList =
- new ArrayList<>(batteryHistoryMap.keySet());
- Collections.sort(batteryHistoryKeyList);
- final long[] batteryHistoryKeys = new long[CHART_KEY_ARRAY_SIZE];
- for (int index = 0; index < CHART_KEY_ARRAY_SIZE; index++) {
- batteryHistoryKeys[index] = batteryHistoryKeyList.get(index);
- }
- return batteryHistoryKeys;
- }
-
- // Loads all items icon and label in the background.
- private final class LoadAllItemsInfoTask
- extends AsyncTask>> {
-
- private long[] mBatteryHistoryKeysCache;
- private Map> mBatteryHistoryMap;
-
- private LoadAllItemsInfoTask(
- Map> batteryHistoryMap) {
- this.mBatteryHistoryMap = batteryHistoryMap;
- this.mBatteryHistoryKeysCache = mBatteryHistoryKeys;
- }
-
- @Override
- protected Map> doInBackground(Void... voids) {
- if (mPrefContext == null || mBatteryHistoryKeysCache == null) {
- return null;
- }
- final long startTime = System.currentTimeMillis();
- final Map> indexedUsageMap =
- ConvertUtils.getIndexedUsageMap(
- mPrefContext, /*timeSlotSize=*/ CHART_LEVEL_ARRAY_SIZE - 1,
- mBatteryHistoryKeysCache, mBatteryHistoryMap,
- /*purgeLowPercentageAndFakeData=*/ true);
- // Pre-loads each BatteryDiffEntry relative icon and label for all slots.
- for (List entries : indexedUsageMap.values()) {
- entries.forEach(entry -> entry.loadLabelAndIcon());
- }
- Log.d(TAG, String.format("execute LoadAllItemsInfoTask in %d/ms",
- (System.currentTimeMillis() - startTime)));
- return indexedUsageMap;
- }
-
- @Override
- protected void onPostExecute(
- Map> indexedUsageMap) {
- mBatteryHistoryMap = null;
- mBatteryHistoryKeysCache = null;
- if (indexedUsageMap == null) {
- return;
- }
- // Posts results back to main thread to refresh UI.
- mHandler.post(() -> {
- mBatteryIndexedMap = indexedUsageMap;
- refreshUi();
- });
- }
- }
}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryLevelData.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryLevelData.java
index 64f519ab9b3..4ff9eeba9b2 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryLevelData.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryLevelData.java
@@ -20,6 +20,8 @@ import androidx.annotation.NonNull;
import androidx.core.util.Preconditions;
import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
/** Wraps the battery timestamp and level data used for battery usage chart. */
public final class BatteryLevelData {
@@ -46,6 +48,12 @@ public final class BatteryLevelData {
public List getLevels() {
return mLevels;
}
+
+ @Override
+ public String toString() {
+ return String.format(Locale.ENGLISH, "timestamps: %s; levels: %s",
+ Objects.toString(mTimestamps), Objects.toString(mLevels));
+ }
}
/**
@@ -78,4 +86,13 @@ public final class BatteryLevelData {
public List getHourlyBatteryLevelsPerDay() {
return mHourlyBatteryLevelsPerDay;
}
-}
\ No newline at end of file
+
+ @Override
+ public String toString() {
+ return String.format(Locale.ENGLISH,
+ "dailyBatteryLevels: %s; hourlyBatteryLevelsPerDay: %s",
+ Objects.toString(mDailyBatteryLevels),
+ Objects.toString(mHourlyBatteryLevelsPerDay));
+ }
+}
+
diff --git a/src/com/android/settings/fuelgauge/batteryusage/ConvertUtils.java b/src/com/android/settings/fuelgauge/batteryusage/ConvertUtils.java
index 168fe0f5383..b89bfe68bad 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/ConvertUtils.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/ConvertUtils.java
@@ -140,7 +140,7 @@ public final class ConvertUtils {
/** Converts UTC timestamp to local time hour data. */
public static String utcToLocalTimeHour(
- Context context, long timestamp, boolean is24HourFormat) {
+ final Context context, final long timestamp, final boolean is24HourFormat) {
final Locale locale = getLocale(context);
// e.g. for 12-hour format: 9 pm
// e.g. for 24-hour format: 09:00
@@ -149,6 +149,13 @@ public final class ConvertUtils {
return DateFormat.format(pattern, timestamp).toString().toLowerCase(locale);
}
+ /** Converts UTC timestamp to local time day of week data. */
+ public static String utcToLocalTimeDayOfWeek(final Context context, final long timestamp) {
+ final Locale locale = getLocale(context);
+ final String pattern = DateFormat.getBestDateTimePattern(locale, "E");
+ return DateFormat.format(pattern, timestamp).toString().toUpperCase(locale);
+ }
+
/** Gets indexed battery usage data for each corresponding time slot. */
public static Map> getIndexedUsageMap(
final Context context,
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceControllerV2Test.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceControllerV2Test.java
index a25afed444b..b8862d43b88 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceControllerV2Test.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceControllerV2Test.java
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -32,6 +33,7 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.LocaleList;
import android.text.format.DateUtils;
+import android.view.View;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
@@ -64,8 +66,6 @@ import java.util.TimeZone;
public final class BatteryChartPreferenceControllerV2Test {
private static final String PREF_KEY = "pref_key";
private static final String PREF_SUMMARY = "fake preference summary";
- private static final int DESIRED_HISTORY_SIZE =
- BatteryChartPreferenceControllerV2.DESIRED_HISTORY_SIZE;
@Mock
private InstrumentedPreferenceFragment mFragment;
@@ -78,7 +78,9 @@ public final class BatteryChartPreferenceControllerV2Test {
@Mock
private BatteryHistEntry mBatteryHistEntry;
@Mock
- private BatteryChartViewV2 mBatteryChartView;
+ private BatteryChartViewV2 mDailyChartView;
+ @Mock
+ private BatteryChartViewV2 mHourlyChartView;
@Mock
private PowerGaugePreference mPowerGaugePreference;
@Mock
@@ -111,7 +113,8 @@ public final class BatteryChartPreferenceControllerV2Test {
mBatteryChartPreferenceController = createController();
mBatteryChartPreferenceController.mPrefContext = mContext;
mBatteryChartPreferenceController.mAppListPrefGroup = mAppListGroup;
- mBatteryChartPreferenceController.mBatteryChartView = mBatteryChartView;
+ mBatteryChartPreferenceController.mDailyChartView = mDailyChartView;
+ mBatteryChartPreferenceController.mHourlyChartView = mHourlyChartView;
mBatteryDiffEntry = new BatteryDiffEntry(
mContext,
/*foregroundUsageTimeInMs=*/ 1,
@@ -123,12 +126,10 @@ public final class BatteryChartPreferenceControllerV2Test {
BatteryDiffEntry.sResourceCache.put(
"fakeBatteryDiffEntryKey",
new BatteryEntry.NameAndIcon("fakeName", /*icon=*/ null, /*iconId=*/ 1));
- mBatteryChartPreferenceController.setBatteryHistoryMap(
- createBatteryHistoryMap());
}
@Test
- public void testOnDestroy_activityIsChanging_clearBatteryEntryCache() {
+ public void onDestroy_activityIsChanging_clearBatteryEntryCache() {
doReturn(true).when(mSettingsActivity).isChangingConfigurations();
// Ensures the testing environment is correct.
assertThat(BatteryDiffEntry.sResourceCache).hasSize(1);
@@ -138,7 +139,7 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testOnDestroy_activityIsNotChanging_notClearBatteryEntryCache() {
+ public void onDestroy_activityIsNotChanging_notClearBatteryEntryCache() {
doReturn(false).when(mSettingsActivity).isChangingConfigurations();
// Ensures the testing environment is correct.
assertThat(BatteryDiffEntry.sResourceCache).hasSize(1);
@@ -148,7 +149,7 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testOnDestroy_clearPreferenceCache() {
+ public void onDestroy_clearPreferenceCache() {
// Ensures the testing environment is correct.
mBatteryChartPreferenceController.mPreferenceCache.put(
PREF_KEY, mPowerGaugePreference);
@@ -160,81 +161,113 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testOnDestroy_removeAllPreferenceFromPreferenceGroup() {
+ public void onDestroy_removeAllPreferenceFromPreferenceGroup() {
mBatteryChartPreferenceController.onDestroy();
verify(mAppListGroup).removeAll();
}
@Test
- public void testSetBatteryHistoryMap_createExpectedKeysAndLevels() {
- mBatteryChartPreferenceController.setBatteryHistoryMap(
- createBatteryHistoryMap());
+ public void setBatteryChartViewModel_6Hours() {
+ // TODO: Removes the following line after loading mBatteryIndexedMap is supported.
+ mBatteryChartPreferenceController.mBatteryIndexedMap = new HashMap<>();
- // Verifies the created battery keys array.
- for (int index = 0; index < DESIRED_HISTORY_SIZE; index++) {
- assertThat(mBatteryChartPreferenceController.mBatteryHistoryKeys[index])
- // These values is are calculated by hand from createBatteryHistoryMap().
- .isEqualTo(generateTimestamp(index));
- }
- // Verifies the created battery levels array.
- for (int index = 0; index < 13; index++) {
- assertThat(mBatteryChartPreferenceController.mViewModel.levels().get(index))
- // These values is are calculated by hand from createBatteryHistoryMap().
- .isEqualTo(100 - index * 2);
- }
- assertThat(mBatteryChartPreferenceController.mBatteryIndexedMap).hasSize(13);
+ mBatteryChartPreferenceController.setBatteryHistoryMap(createBatteryHistoryMap(6));
+
+ verify(mDailyChartView).setVisibility(View.GONE);
+ verify(mHourlyChartView).setVisibility(View.VISIBLE);
+ verify(mHourlyChartView).setViewModel(new BatteryChartViewModel(
+ List.of(100, 97, 95),
+ List.of("8 am", "10 am", "12 pm"),
+ BatteryChartViewModel.SELECTED_INDEX_ALL));
}
@Test
- public void testSetBatteryHistoryMap_largeSize_createExpectedKeysAndLevels() {
- mBatteryChartPreferenceController.setBatteryHistoryMap(
- createBatteryHistoryMap());
+ public void setBatteryChartViewModel_60Hours() {
+ // TODO: Removes the following line after loading mBatteryIndexedMap is supported.
+ mBatteryChartPreferenceController.mBatteryIndexedMap = new HashMap<>();
- // Verifies the created battery keys array.
- for (int index = 0; index < DESIRED_HISTORY_SIZE; index++) {
- assertThat(mBatteryChartPreferenceController.mBatteryHistoryKeys[index])
- // These values is are calculated by hand from createBatteryHistoryMap().
- .isEqualTo(generateTimestamp(index));
- }
- // Verifies the created battery levels array.
- for (int index = 0; index < 13; index++) {
- assertThat(mBatteryChartPreferenceController.mViewModel.levels().get(index))
- // These values is are calculated by hand from createBatteryHistoryMap().
- .isEqualTo(100 - index * 2);
- }
- assertThat(mBatteryChartPreferenceController.mBatteryIndexedMap).hasSize(13);
+ mBatteryChartPreferenceController.setBatteryHistoryMap(createBatteryHistoryMap(60));
+
+ verify(mDailyChartView).setVisibility(View.VISIBLE);
+ verify(mHourlyChartView).setVisibility(View.GONE);
+ verify(mDailyChartView).setViewModel(new BatteryChartViewModel(
+ List.of(100, 83, 59, 41),
+ List.of("SAT", "SUN", "MON", "MON"),
+ BatteryChartViewModel.SELECTED_INDEX_ALL));
+
+ reset(mDailyChartView);
+ reset(mHourlyChartView);
+ mBatteryChartPreferenceController.mDailyChartIndex = 0;
+ mBatteryChartPreferenceController.refreshUi();
+ verify(mDailyChartView).setVisibility(View.VISIBLE);
+ verify(mHourlyChartView).setVisibility(View.VISIBLE);
+ verify(mDailyChartView).setViewModel(new BatteryChartViewModel(
+ List.of(100, 83, 59, 41),
+ List.of("SAT", "SUN", "MON", "MON"),
+ 0));
+ verify(mHourlyChartView).setViewModel(new BatteryChartViewModel(
+ List.of(100, 97, 95, 93, 91, 89, 87, 85, 83),
+ List.of("8 am", "10 am", "12 pm", "2 pm", "4 pm", "6 pm", "8 pm", "10 pm",
+ "12 am"),
+ BatteryChartViewModel.SELECTED_INDEX_ALL));
+
+ reset(mDailyChartView);
+ reset(mHourlyChartView);
+ mBatteryChartPreferenceController.mDailyChartIndex = 1;
+ mBatteryChartPreferenceController.mHourlyChartIndex = 6;
+ mBatteryChartPreferenceController.refreshUi();
+ verify(mDailyChartView).setVisibility(View.VISIBLE);
+ verify(mHourlyChartView).setVisibility(View.VISIBLE);
+ verify(mDailyChartView).setViewModel(new BatteryChartViewModel(
+ List.of(100, 83, 59, 41),
+ List.of("SAT", "SUN", "MON", "MON"),
+ 1));
+ verify(mHourlyChartView).setViewModel(new BatteryChartViewModel(
+ List.of(83, 81, 79, 77, 75, 73, 71, 69, 67, 65, 63, 61, 59),
+ List.of("12 am", "2 am", "4 am", "6 am", "8 am", "10 am", "12 pm", "2 pm",
+ "4 pm", "6 pm", "8 pm", "10 pm", "12 am"),
+ 6));
+
+ reset(mDailyChartView);
+ reset(mHourlyChartView);
+ mBatteryChartPreferenceController.mDailyChartIndex = 2;
+ mBatteryChartPreferenceController.mHourlyChartIndex =
+ BatteryChartViewModel.SELECTED_INDEX_ALL;
+ mBatteryChartPreferenceController.refreshUi();
+ verify(mDailyChartView).setVisibility(View.VISIBLE);
+ verify(mHourlyChartView).setVisibility(View.VISIBLE);
+ verify(mDailyChartView).setViewModel(new BatteryChartViewModel(
+ List.of(100, 83, 59, 41),
+ List.of("SAT", "SUN", "MON", "MON"),
+ 2));
+ verify(mHourlyChartView).setViewModel(new BatteryChartViewModel(
+ List.of(59, 57, 55, 53, 51, 49, 47, 45, 43, 41),
+ List.of("12 am", "2 am", "4 am", "6 am", "8 am", "10 am", "12 pm", "2 pm",
+ "4 pm", "6 pm"),
+ BatteryChartViewModel.SELECTED_INDEX_ALL));
}
@Test
- public void testSetBatteryChartViewModel() {
- verify(mBatteryChartPreferenceController.mBatteryChartView)
- .setViewModel(new BatteryChartViewModel(
- List.of(100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76),
- List.of("7 am", "9 am", "11 am", "1 pm", "3 pm", "5 pm", "7 pm",
- "9 pm", "11 pm", "1 am", "3 am", "5 am", "7 am"),
- BatteryChartViewModel.SELECTED_INDEX_ALL));
- }
-
- @Test
- public void testRefreshUi_refresh() {
- assertThat(mBatteryChartPreferenceController.refreshUi()).isTrue();
- }
-
- @Test
- public void testRefreshUi_batteryIndexedMapIsNull_ignoreRefresh() {
+ public void refreshUi_batteryIndexedMapIsNull_ignoreRefresh() {
mBatteryChartPreferenceController.setBatteryHistoryMap(null);
assertThat(mBatteryChartPreferenceController.refreshUi()).isFalse();
}
@Test
- public void testRefreshUi_batteryChartViewIsNull_ignoreRefresh() {
- mBatteryChartPreferenceController.mBatteryChartView = null;
+ public void refreshUi_dailyChartViewIsNull_ignoreRefresh() {
+ mBatteryChartPreferenceController.mDailyChartView = null;
assertThat(mBatteryChartPreferenceController.refreshUi()).isFalse();
}
@Test
- public void testRemoveAndCacheAllPrefs_emptyContent_ignoreRemoveAll() {
- mBatteryChartPreferenceController.mTrapezoidIndex = 1;
+ public void refreshUi_hourlyChartViewIsNull_ignoreRefresh() {
+ mBatteryChartPreferenceController.mHourlyChartView = null;
+ assertThat(mBatteryChartPreferenceController.refreshUi()).isFalse();
+ }
+
+ @Test
+ public void removeAndCacheAllPrefs_emptyContent_ignoreRemoveAll() {
+ mBatteryChartPreferenceController.mHourlyChartIndex = 1;
doReturn(0).when(mAppListGroup).getPreferenceCount();
mBatteryChartPreferenceController.refreshUi();
@@ -242,30 +275,14 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testRemoveAndCacheAllPrefs_buildCacheAndRemoveAllPreference() {
- mBatteryChartPreferenceController.mTrapezoidIndex = 1;
- doReturn(1).when(mAppListGroup).getPreferenceCount();
- doReturn(mPowerGaugePreference).when(mAppListGroup).getPreference(0);
- doReturn(PREF_KEY).when(mPowerGaugePreference).getKey();
- // Ensures the testing data is correct.
- assertThat(mBatteryChartPreferenceController.mPreferenceCache).isEmpty();
-
- mBatteryChartPreferenceController.refreshUi();
-
- assertThat(mBatteryChartPreferenceController.mPreferenceCache.get(PREF_KEY))
- .isEqualTo(mPowerGaugePreference);
- verify(mAppListGroup).removeAll();
- }
-
- @Test
- public void testAddPreferenceToScreen_emptyContent_ignoreAddPreference() {
+ public void addPreferenceToScreen_emptyContent_ignoreAddPreference() {
mBatteryChartPreferenceController.addPreferenceToScreen(
new ArrayList());
verify(mAppListGroup, never()).addPreference(any());
}
@Test
- public void testAddPreferenceToScreen_addPreferenceIntoScreen() {
+ public void addPreferenceToScreen_addPreferenceIntoScreen() {
final String appLabel = "fake app label";
doReturn(1).when(mAppListGroup).getPreferenceCount();
doReturn(mDrawable).when(mBatteryDiffEntry).getAppIcon();
@@ -294,7 +311,7 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testAddPreferenceToScreen_alreadyInScreen_notAddPreferenceAgain() {
+ public void addPreferenceToScreen_alreadyInScreen_notAddPreferenceAgain() {
final String appLabel = "fake app label";
doReturn(1).when(mAppListGroup).getPreferenceCount();
doReturn(mDrawable).when(mBatteryDiffEntry).getAppIcon();
@@ -309,7 +326,7 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testHandlePreferenceTreeiClick_notPowerGaugePreference_returnFalse() {
+ public void handlePreferenceTreeiClick_notPowerGaugePreference_returnFalse() {
assertThat(mBatteryChartPreferenceController.handlePreferenceTreeClick(mAppListGroup))
.isFalse();
@@ -320,7 +337,7 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testHandlePreferenceTreeClick_forAppEntry_returnTrue() {
+ public void handlePreferenceTreeClick_forAppEntry_returnTrue() {
doReturn(false).when(mBatteryHistEntry).isAppEntry();
doReturn(mBatteryDiffEntry).when(mPowerGaugePreference).getBatteryDiffEntry();
@@ -336,7 +353,7 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testHandlePreferenceTreeClick_forSystemEntry_returnTrue() {
+ public void handlePreferenceTreeClick_forSystemEntry_returnTrue() {
mBatteryChartPreferenceController.mBatteryUtils = mBatteryUtils;
doReturn(true).when(mBatteryHistEntry).isAppEntry();
doReturn(mBatteryDiffEntry).when(mPowerGaugePreference).getBatteryDiffEntry();
@@ -353,7 +370,7 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testSetPreferenceSummary_setNullContentIfTotalUsageTimeIsZero() {
+ public void setPreferenceSummary_setNullContentIfTotalUsageTimeIsZero() {
final PowerGaugePreference pref = new PowerGaugePreference(mContext);
pref.setSummary(PREF_SUMMARY);
@@ -365,7 +382,7 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testSetPreferenceSummary_setBackgroundUsageTimeOnly() {
+ public void setPreferenceSummary_setBackgroundUsageTimeOnly() {
final PowerGaugePreference pref = new PowerGaugePreference(mContext);
pref.setSummary(PREF_SUMMARY);
@@ -377,7 +394,7 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testSetPreferenceSummary_setTotalUsageTimeLessThanAMinute() {
+ public void setPreferenceSummary_setTotalUsageTimeLessThanAMinute() {
final PowerGaugePreference pref = new PowerGaugePreference(mContext);
pref.setSummary(PREF_SUMMARY);
@@ -389,7 +406,7 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testSetPreferenceSummary_setTotalTimeIfBackgroundTimeLessThanAMinute() {
+ public void setPreferenceSummary_setTotalTimeIfBackgroundTimeLessThanAMinute() {
final PowerGaugePreference pref = new PowerGaugePreference(mContext);
pref.setSummary(PREF_SUMMARY);
@@ -402,7 +419,7 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testSetPreferenceSummary_setTotalAndBackgroundUsageTime() {
+ public void setPreferenceSummary_setTotalAndBackgroundUsageTime() {
final PowerGaugePreference pref = new PowerGaugePreference(mContext);
pref.setSummary(PREF_SUMMARY);
@@ -414,7 +431,7 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testSetPreferenceSummary_notAllowShownPackage_setSummayAsNull() {
+ public void setPreferenceSummary_notAllowShownPackage_setSummayAsNull() {
final PowerGaugePreference pref = new PowerGaugePreference(mContext);
pref.setSummary(PREF_SUMMARY);
final BatteryDiffEntry batteryDiffEntry =
@@ -429,7 +446,7 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testValidateUsageTime_returnTrueIfBatteryDiffEntryIsValid() {
+ public void validateUsageTime_returnTrueIfBatteryDiffEntryIsValid() {
assertThat(BatteryChartPreferenceControllerV2.validateUsageTime(
createBatteryDiffEntry(
/*foregroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS,
@@ -438,7 +455,7 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testValidateUsageTime_foregroundTimeExceedThreshold_returnFalse() {
+ public void validateUsageTime_foregroundTimeExceedThreshold_returnFalse() {
assertThat(BatteryChartPreferenceControllerV2.validateUsageTime(
createBatteryDiffEntry(
/*foregroundUsageTimeInMs=*/ DateUtils.HOUR_IN_MILLIS * 3,
@@ -447,7 +464,7 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testValidateUsageTime_backgroundTimeExceedThreshold_returnFalse() {
+ public void validateUsageTime_backgroundTimeExceedThreshold_returnFalse() {
assertThat(BatteryChartPreferenceControllerV2.validateUsageTime(
createBatteryDiffEntry(
/*foregroundUsageTimeInMs=*/ 0,
@@ -456,7 +473,7 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testOnExpand_expandedIsTrue_addSystemEntriesToPreferenceGroup() {
+ public void onExpand_expandedIsTrue_addSystemEntriesToPreferenceGroup() {
doReturn(1).when(mAppListGroup).getPreferenceCount();
mBatteryChartPreferenceController.mSystemEntries.add(mBatteryDiffEntry);
doReturn("label").when(mBatteryDiffEntry).getAppLabel();
@@ -477,7 +494,7 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testOnExpand_expandedIsFalse_removeSystemEntriesFromPreferenceGroup() {
+ public void onExpand_expandedIsFalse_removeSystemEntriesFromPreferenceGroup() {
doReturn(PREF_KEY).when(mBatteryHistEntry).getKey();
doReturn(mPowerGaugePreference).when(mAppListGroup).findPreference(PREF_KEY);
mBatteryChartPreferenceController.mSystemEntries.add(mBatteryDiffEntry);
@@ -497,56 +514,14 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testOnSelect_selectSpecificTimeSlot_logMetric() {
- mBatteryChartPreferenceController.onSelect(1 /*slot index*/);
-
- verify(mMetricsFeatureProvider)
- .action(mContext, SettingsEnums.ACTION_BATTERY_USAGE_TIME_SLOT);
- }
-
- @Test
- public void testOnSelect_selectAll_logMetric() {
- mBatteryChartPreferenceController.onSelect(
- BatteryChartViewModel.SELECTED_INDEX_ALL /*slot index*/);
-
- verify(mMetricsFeatureProvider)
- .action(mContext, SettingsEnums.ACTION_BATTERY_USAGE_SHOW_ALL);
- }
-
- @Test
- public void testRefreshCategoryTitle_setHourIntoBothTitleTextView() {
- mBatteryChartPreferenceController = createController();
- setUpBatteryHistoryKeys();
- mBatteryChartPreferenceController.mAppListPrefGroup =
- spy(new PreferenceCategory(mContext));
- mBatteryChartPreferenceController.mExpandDividerPreference =
- spy(new ExpandDividerPreference(mContext));
- // Simulates select the first slot.
- mBatteryChartPreferenceController.mTrapezoidIndex = 0;
-
- mBatteryChartPreferenceController.refreshCategoryTitle();
-
- ArgumentCaptor captor = ArgumentCaptor.forClass(String.class);
- // Verifies the title in the preference group.
- verify(mBatteryChartPreferenceController.mAppListPrefGroup)
- .setTitle(captor.capture());
- assertThat(captor.getValue()).isNotEqualTo("App usage for past 24 hr");
- // Verifies the title in the expandable divider.
- captor = ArgumentCaptor.forClass(String.class);
- verify(mBatteryChartPreferenceController.mExpandDividerPreference)
- .setTitle(captor.capture());
- assertThat(captor.getValue()).isNotEqualTo("System usage for past 24 hr");
- }
-
- @Test
- public void testRefreshCategoryTitle_setLast24HrIntoBothTitleTextView() {
+ public void refreshCategoryTitle_setLast24HrIntoBothTitleTextView() {
mBatteryChartPreferenceController = createController();
mBatteryChartPreferenceController.mAppListPrefGroup =
spy(new PreferenceCategory(mContext));
mBatteryChartPreferenceController.mExpandDividerPreference =
spy(new ExpandDividerPreference(mContext));
// Simulates select all condition.
- mBatteryChartPreferenceController.mTrapezoidIndex =
+ mBatteryChartPreferenceController.mHourlyChartIndex =
BatteryChartViewModel.SELECTED_INDEX_ALL;
mBatteryChartPreferenceController.refreshCategoryTitle();
@@ -566,28 +541,27 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testOnSaveInstanceState_restoreSelectedIndexAndExpandState() {
+ public void onSaveInstanceState_restoreSelectedIndexAndExpandState() {
final int expectedIndex = 1;
final boolean isExpanded = true;
final Bundle bundle = new Bundle();
- mBatteryChartPreferenceController.mTrapezoidIndex = expectedIndex;
+ mBatteryChartPreferenceController.mHourlyChartIndex = expectedIndex;
mBatteryChartPreferenceController.mIsExpanded = isExpanded;
mBatteryChartPreferenceController.onSaveInstanceState(bundle);
// Replaces the original controller with other values.
- mBatteryChartPreferenceController.mTrapezoidIndex = -1;
+ mBatteryChartPreferenceController.mHourlyChartIndex = -1;
mBatteryChartPreferenceController.mIsExpanded = false;
mBatteryChartPreferenceController.onCreate(bundle);
- mBatteryChartPreferenceController.setBatteryHistoryMap(
- createBatteryHistoryMap());
+ mBatteryChartPreferenceController.setBatteryHistoryMap(createBatteryHistoryMap(25));
- assertThat(mBatteryChartPreferenceController.mTrapezoidIndex)
+ assertThat(mBatteryChartPreferenceController.mHourlyChartIndex)
.isEqualTo(expectedIndex);
assertThat(mBatteryChartPreferenceController.mIsExpanded).isTrue();
}
@Test
- public void testIsValidToShowSummary_returnExpectedResult() {
+ public void isValidToShowSummary_returnExpectedResult() {
assertThat(mBatteryChartPreferenceController
.isValidToShowSummary("com.google.android.apps.scone"))
.isTrue();
@@ -599,7 +573,7 @@ public final class BatteryChartPreferenceControllerV2Test {
}
@Test
- public void testIsValidToShowEntry_returnExpectedResult() {
+ public void isValidToShowEntry_returnExpectedResult() {
assertThat(mBatteryChartPreferenceController
.isValidToShowEntry("com.google.android.apps.scone"))
.isTrue();
@@ -615,9 +589,10 @@ public final class BatteryChartPreferenceControllerV2Test {
return 1619247600000L + index * DateUtils.HOUR_IN_MILLIS;
}
- private static Map> createBatteryHistoryMap() {
+ private static Map> createBatteryHistoryMap(
+ int numOfHours) {
final Map> batteryHistoryMap = new HashMap<>();
- for (int index = 0; index < DESIRED_HISTORY_SIZE; index++) {
+ for (int index = 0; index < numOfHours; index++) {
final ContentValues values = new ContentValues();
values.put("batteryLevel", Integer.valueOf(100 - index));
final BatteryHistEntry entry = new BatteryHistEntry(values);
@@ -635,14 +610,6 @@ public final class BatteryChartPreferenceControllerV2Test {
/*consumePower=*/ 0, mBatteryHistEntry);
}
- private void setUpBatteryHistoryKeys() {
- mBatteryChartPreferenceController.mBatteryHistoryKeys =
- // "2021-04-23 16:53:06 UTC", "1970-01-01 00:00:00 UTC", "2021-04-23 07:00:36 UTC"
- new long[]{1619196786769L, 0L, 1619247636826L};
- ConvertUtils.utcToLocalTimeHour(
- mContext, /*timestamp=*/ 0, /*is24HourFormat=*/ false);
- }
-
private BatteryChartPreferenceControllerV2 createController() {
final BatteryChartPreferenceControllerV2 controller =
new BatteryChartPreferenceControllerV2(
diff --git a/tests/unit/src/com/android/settings/deviceinfo/VolumeOptionMenuControllerTest.java b/tests/unit/src/com/android/settings/deviceinfo/VolumeOptionMenuControllerTest.java
index 8bd9b018d18..d347f919628 100644
--- a/tests/unit/src/com/android/settings/deviceinfo/VolumeOptionMenuControllerTest.java
+++ b/tests/unit/src/com/android/settings/deviceinfo/VolumeOptionMenuControllerTest.java
@@ -55,7 +55,6 @@ public class VolumeOptionMenuControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Menu mMenu;
@Mock private PackageManager mPackageManager;
- @Mock private StorageManager mStorageManager;
@Mock private VolumeInfo mExternalVolumeInfo;
@Mock private VolumeInfo mInternalVolumeInfo;
@@ -68,7 +67,6 @@ public class VolumeOptionMenuControllerTest {
mContext = spy(ApplicationProvider.getApplicationContext());
when(mContext.getPackageManager()).thenReturn(mPackageManager);
- when(mContext.getSystemService(StorageManager.class)).thenReturn(mStorageManager);
when(mInternalVolumeInfo.getId()).thenReturn(INTERNAL_VOLUME_ID);
when(mInternalVolumeInfo.getType()).thenReturn(VolumeInfo.TYPE_PRIVATE);
@@ -173,17 +171,16 @@ public class VolumeOptionMenuControllerTest {
when(mExternalVolumeInfo.getState()).thenReturn(VolumeInfo.STATE_MOUNTED);
when(mExternalVolumeInfo.getDiskId()).thenReturn(DISK_ID);
final DiskInfo externalDiskInfo = mock(DiskInfo.class);
- when(mStorageManager.findDiskById(DISK_ID)).thenReturn(externalDiskInfo);
mController.setSelectedStorageEntry(new StorageEntry(mContext, mExternalVolumeInfo));
mController.onPrepareOptionsMenu(mMenu);
verify(mController.mRename, atLeastOnce()).setVisible(true);
verify(mController.mUnmount, atLeastOnce()).setVisible(true);
- verify(mController.mFormat, atLeastOnce()).setVisible(true);
- verify(mController.mMount, never()).setVisible(true);
+ verify(mController.mFormatAsInternal, atLeastOnce()).setVisible(true);
verify(mController.mFormatAsPortable, never()).setVisible(true);
- verify(mController.mFormatAsInternal, never()).setVisible(true);
+ verify(mController.mFormat, never()).setVisible(true);
+ verify(mController.mMount, never()).setVisible(true);
verify(mController.mFree, never()).setVisible(true);
verify(mController.mForget, never()).setVisible(true);
}