Merge "Split System category" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
80d12dbc25
26
res/drawable/ic_android_vd_theme_24.xml
Normal file
26
res/drawable/ic_android_vd_theme_24.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<!--
|
||||
~ Copyright (C) 2024 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960"
|
||||
android:tint="?android:attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M40,720Q49,613 105.5,523Q162,433 256,380L182,252Q176,243 179,233Q182,223 192,218Q200,213 210,216Q220,219 226,228L300,356Q386,320 480,320Q574,320 660,356L734,228Q740,219 750,216Q760,213 768,218Q778,223 781,233Q784,243 778,252L704,380Q798,433 854.5,523Q911,613 920,720L40,720ZM280,610Q301,610 315.5,595.5Q330,581 330,560Q330,539 315.5,524.5Q301,510 280,510Q259,510 244.5,524.5Q230,539 230,560Q230,581 244.5,595.5Q259,610 280,610ZM680,610Q701,610 715.5,595.5Q730,581 730,560Q730,539 715.5,524.5Q701,510 680,510Q659,510 644.5,524.5Q630,539 630,560Q630,581 644.5,595.5Q659,610 680,610Z"/>
|
||||
</vector>
|
||||
|
25
res/drawable/ic_database_vd_theme_24.xml
Normal file
25
res/drawable/ic_database_vd_theme_24.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<!--
|
||||
~ Copyright (C) 2024 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960"
|
||||
android:tint="?android:attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M480,440Q630,440 735,393Q840,346 840,280Q840,214 735,167Q630,120 480,120Q330,120 225,167Q120,214 120,280Q120,346 225,393Q330,440 480,440ZM480,540Q521,540 582.5,531.5Q644,523 701,504Q758,485 799,454.5Q840,424 840,380L840,480Q840,524 799,554.5Q758,585 701,604Q644,623 582.5,631.5Q521,640 480,640Q439,640 377.5,631.5Q316,623 259,604Q202,585 161,554.5Q120,524 120,480L120,380Q120,424 161,454.5Q202,485 259,504Q316,523 377.5,531.5Q439,540 480,540ZM480,740Q521,740 582.5,731.5Q644,723 701,704Q758,685 799,654.5Q840,624 840,580L840,680Q840,724 799,754.5Q758,785 701,804Q644,823 582.5,831.5Q521,840 480,840Q439,840 377.5,831.5Q316,823 259,804Q202,785 161,754.5Q120,724 120,680L120,580Q120,624 161,654.5Q202,685 259,704Q316,723 377.5,731.5Q439,740 480,740Z"/>
|
||||
</vector>
|
@@ -61,19 +61,31 @@
|
||||
android:title="@string/storage_documents_and_other"
|
||||
android:icon="@drawable/ic_folder_vd_theme_24"
|
||||
android:order="106"/>
|
||||
<com.android.settings.deviceinfo.StorageItemPreference
|
||||
android:key="pref_system"
|
||||
android:title="@string/storage_system"
|
||||
android:icon="@drawable/ic_system_update"
|
||||
android:order="107"/>
|
||||
<com.android.settings.deviceinfo.StorageItemPreference
|
||||
android:key="pref_trash"
|
||||
android:title="@string/storage_trash"
|
||||
android:icon="@drawable/ic_trash_can"
|
||||
android:order="108"/>
|
||||
<!-- Preference order 100~200 are 'ONLY' for storage category preferences above. -->
|
||||
android:order="107"/>
|
||||
<!-- Preference order 100~200 are 'ONLY' for storage category
|
||||
preferences that are sorted by size. -->
|
||||
<PreferenceCategory
|
||||
android:key="storage_category_splitter"
|
||||
android:title="@string/storage_system_label"
|
||||
android:order="201"
|
||||
settings:searchable="false">
|
||||
<com.android.settings.deviceinfo.StorageItemPreference
|
||||
android:key="pref_system"
|
||||
android:title="@string/storage_os_name"
|
||||
android:icon="@drawable/ic_android_vd_theme_24"
|
||||
android:order="202"/>
|
||||
<com.android.settings.deviceinfo.StorageItemPreference
|
||||
android:key="temporary_files"
|
||||
android:title="@string/storage_temporary_files"
|
||||
android:icon="@drawable/ic_database_vd_theme_24"
|
||||
android:order="203"/>
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:key="pref_non_current_users"
|
||||
android:title="@string/storage_other_users"
|
||||
android:order="201" />
|
||||
android:order="204" />
|
||||
</PreferenceScreen>
|
||||
|
@@ -80,19 +80,31 @@
|
||||
android:title="@string/storage_documents_and_other"
|
||||
android:icon="@drawable/ic_folder_vd_theme_24"
|
||||
android:order="106"/>
|
||||
<com.android.settings.deviceinfo.StorageItemPreference
|
||||
android:key="pref_system"
|
||||
android:title="@string/storage_system"
|
||||
android:icon="@drawable/ic_system_update"
|
||||
android:order="107"/>
|
||||
<com.android.settings.deviceinfo.StorageItemPreference
|
||||
android:key="pref_trash"
|
||||
android:title="@string/storage_trash"
|
||||
android:icon="@drawable/ic_trash_can"
|
||||
android:order="108"/>
|
||||
<!-- Preference order 100~200 are 'ONLY' for storage category preferences above. -->
|
||||
android:order="107"/>
|
||||
<!-- Preference order 100~200 are 'ONLY' for storage category
|
||||
preferences that are sorted by size. -->
|
||||
<PreferenceCategory
|
||||
android:key="storage_category_splitter"
|
||||
android:title="@string/storage_system_label"
|
||||
android:order="201"
|
||||
settings:searchable="false">
|
||||
<com.android.settings.deviceinfo.StorageItemPreference
|
||||
android:key="pref_system"
|
||||
android:title="@string/storage_os_name"
|
||||
android:icon="@drawable/ic_android_vd_theme_24"
|
||||
android:order="202"/>
|
||||
<com.android.settings.deviceinfo.StorageItemPreference
|
||||
android:key="temporary_files"
|
||||
android:title="@string/storage_temporary_files"
|
||||
android:icon="@drawable/ic_database_vd_theme_24"
|
||||
android:order="203"/>
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:key="pref_non_current_users"
|
||||
android:title="@string/storage_other_users"
|
||||
android:order="201" />
|
||||
android:order="204" />
|
||||
</PreferenceScreen>
|
||||
|
@@ -30,8 +30,10 @@ import android.content.pm.UserInfo;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.provider.MediaStore;
|
||||
import android.provider.MediaStore.Files.FileColumns;
|
||||
import android.provider.MediaStore.MediaColumns;
|
||||
@@ -94,6 +96,7 @@ public class StorageAsyncLoader
|
||||
media /* queryArgs */);
|
||||
result.audioSize = getFilesSize(info.id, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
|
||||
media /* queryArgs */);
|
||||
result.systemSize = getSystemSize();
|
||||
|
||||
final Bundle documentsAndOtherQueryArgs = new Bundle();
|
||||
documentsAndOtherQueryArgs.putString(ContentResolver.QUERY_ARG_SQL_SELECTION,
|
||||
@@ -140,6 +143,16 @@ public class StorageAsyncLoader
|
||||
}
|
||||
}
|
||||
|
||||
private long getSystemSize() {
|
||||
try {
|
||||
return mStatsManager.getTotalBytes(StorageManager.UUID_DEFAULT)
|
||||
- Environment.getDataDirectory().getTotalSpace();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Exception in calculating System category size", e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private StorageResult getAppsAndGamesSize(int userId) {
|
||||
Log.d(TAG, "Loading apps");
|
||||
final List<ApplicationInfo> applicationInfos =
|
||||
@@ -225,6 +238,7 @@ public class StorageAsyncLoader
|
||||
public long videosSize;
|
||||
public long documentsAndOtherSize;
|
||||
public long trashSize;
|
||||
public long systemSize;
|
||||
|
||||
public long cacheSize;
|
||||
public long duplicateCodeSize;
|
||||
|
@@ -35,6 +35,7 @@ public class StorageCacheHelper {
|
||||
private static final String DOCUMENTS_AND_OTHER_SIZE_KEY = "documents_and_other_size_key";
|
||||
private static final String TRASH_SIZE_KEY = "trash_size_key";
|
||||
private static final String SYSTEM_SIZE_KEY = "system_size_key";
|
||||
private static final String TEMPORARY_FILES_SIZE_KEY = "temporary_files_size_key";
|
||||
private static final String USED_SIZE_KEY = "used_size_key";
|
||||
|
||||
private final SharedPreferences mSharedPreferences;
|
||||
@@ -66,6 +67,7 @@ public class StorageCacheHelper {
|
||||
.putLong(DOCUMENTS_AND_OTHER_SIZE_KEY, data.documentsAndOtherSize)
|
||||
.putLong(TRASH_SIZE_KEY, data.trashSize)
|
||||
.putLong(SYSTEM_SIZE_KEY, data.systemSize)
|
||||
.putLong(TEMPORARY_FILES_SIZE_KEY, data.temporaryFilesSize)
|
||||
.apply();
|
||||
}
|
||||
|
||||
@@ -109,6 +111,7 @@ public class StorageCacheHelper {
|
||||
result.documentsAndOtherSize = mSharedPreferences.getLong(DOCUMENTS_AND_OTHER_SIZE_KEY, 0);
|
||||
result.trashSize = mSharedPreferences.getLong(TRASH_SIZE_KEY, 0);
|
||||
result.systemSize = mSharedPreferences.getLong(SYSTEM_SIZE_KEY, 0);
|
||||
result.temporaryFilesSize = mSharedPreferences.getLong(TEMPORARY_FILES_SIZE_KEY, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -126,5 +129,6 @@ public class StorageCacheHelper {
|
||||
public long documentsAndOtherSize;
|
||||
public long trashSize;
|
||||
public long systemSize;
|
||||
public long temporaryFilesSize;
|
||||
}
|
||||
}
|
||||
|
@@ -27,6 +27,7 @@ import android.content.pm.UserInfo;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
@@ -40,6 +41,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -52,6 +54,7 @@ import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
||||
import com.android.settings.deviceinfo.StorageItemPreference;
|
||||
import com.android.settings.deviceinfo.storage.StorageUtils.SystemInfoFragment;
|
||||
import com.android.settings.deviceinfo.storage.StorageUtils.TemporaryFilesInfoFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
@@ -74,6 +77,7 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
||||
private static final String TAG = "StorageItemPreference";
|
||||
|
||||
private static final String SYSTEM_FRAGMENT_TAG = "SystemInfo";
|
||||
private static final String TEMPORARY_FILES_FRAGMENT_TAG = "TemporaryFilesInfo";
|
||||
|
||||
@VisibleForTesting
|
||||
static final String PUBLIC_STORAGE_KEY = "pref_public_storage";
|
||||
@@ -92,6 +96,10 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
||||
@VisibleForTesting
|
||||
static final String SYSTEM_KEY = "pref_system";
|
||||
@VisibleForTesting
|
||||
static final String TEMPORARY_FILES_KEY = "temporary_files";
|
||||
@VisibleForTesting
|
||||
static final String CATEGORY_SPLITTER = "storage_category_splitter";
|
||||
@VisibleForTesting
|
||||
static final String TRASH_KEY = "pref_trash";
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -133,9 +141,13 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
||||
@VisibleForTesting
|
||||
@Nullable StorageItemPreference mDocumentsAndOtherPreference;
|
||||
@VisibleForTesting
|
||||
@Nullable StorageItemPreference mTrashPreference;
|
||||
@VisibleForTesting
|
||||
@Nullable StorageItemPreference mSystemPreference;
|
||||
@VisibleForTesting
|
||||
@Nullable StorageItemPreference mTrashPreference;
|
||||
@Nullable StorageItemPreference mTemporaryFilesPreference;
|
||||
@VisibleForTesting
|
||||
@Nullable PreferenceCategory mCategorySplitterPreferenceCategory;
|
||||
|
||||
private final int mProfileType;
|
||||
|
||||
@@ -220,6 +232,13 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
||||
dialog.setTargetFragment(mFragment, 0);
|
||||
dialog.show(mFragment.getFragmentManager(), SYSTEM_FRAGMENT_TAG);
|
||||
return true;
|
||||
case TEMPORARY_FILES_KEY:
|
||||
final TemporaryFilesInfoFragment temporaryFilesDialog =
|
||||
new TemporaryFilesInfoFragment();
|
||||
temporaryFilesDialog.setTargetFragment(mFragment, 0);
|
||||
temporaryFilesDialog.show(mFragment.getFragmentManager(),
|
||||
TEMPORARY_FILES_FRAGMENT_TAG);
|
||||
return true;
|
||||
case TRASH_KEY:
|
||||
launchTrashIntent();
|
||||
return true;
|
||||
@@ -285,6 +304,8 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
||||
mAppsPreference.setVisible(visible);
|
||||
mGamesPreference.setVisible(visible);
|
||||
mSystemPreference.setVisible(visible);
|
||||
mTemporaryFilesPreference.setVisible(visible);
|
||||
mCategorySplitterPreferenceCategory.setVisible(visible);
|
||||
mTrashPreference.setVisible(visible);
|
||||
|
||||
// If we don't have a shared volume for our internal storage (or the shared volume isn't
|
||||
@@ -315,7 +336,6 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
||||
mPrivateStorageItemPreferences.add(mAppsPreference);
|
||||
mPrivateStorageItemPreferences.add(mGamesPreference);
|
||||
mPrivateStorageItemPreferences.add(mDocumentsAndOtherPreference);
|
||||
mPrivateStorageItemPreferences.add(mSystemPreference);
|
||||
mPrivateStorageItemPreferences.add(mTrashPreference);
|
||||
}
|
||||
mScreen.removePreference(mImagesPreference);
|
||||
@@ -324,7 +344,6 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
||||
mScreen.removePreference(mAppsPreference);
|
||||
mScreen.removePreference(mGamesPreference);
|
||||
mScreen.removePreference(mDocumentsAndOtherPreference);
|
||||
mScreen.removePreference(mSystemPreference);
|
||||
mScreen.removePreference(mTrashPreference);
|
||||
|
||||
// Sort display order by size.
|
||||
@@ -361,6 +380,7 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
||||
tintPreference(mGamesPreference);
|
||||
tintPreference(mDocumentsAndOtherPreference);
|
||||
tintPreference(mSystemPreference);
|
||||
tintPreference(mTemporaryFilesPreference);
|
||||
tintPreference(mTrashPreference);
|
||||
}
|
||||
|
||||
@@ -389,7 +409,9 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
||||
mAppsPreference = screen.findPreference(APPS_KEY);
|
||||
mGamesPreference = screen.findPreference(GAMES_KEY);
|
||||
mDocumentsAndOtherPreference = screen.findPreference(DOCUMENTS_AND_OTHER_KEY);
|
||||
mCategorySplitterPreferenceCategory = screen.findPreference(CATEGORY_SPLITTER);
|
||||
mSystemPreference = screen.findPreference(SYSTEM_KEY);
|
||||
mTemporaryFilesPreference = screen.findPreference(TEMPORARY_FILES_KEY);
|
||||
mTrashPreference = screen.findPreference(TRASH_KEY);
|
||||
}
|
||||
|
||||
@@ -417,6 +439,12 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
||||
mTrashPreference.setStorageSize(storageCache.trashSize, mTotalSize, animate);
|
||||
if (mSystemPreference != null) {
|
||||
mSystemPreference.setStorageSize(storageCache.systemSize, mTotalSize, animate);
|
||||
mSystemPreference.setTitle(mContext.getString(R.string.storage_os_name,
|
||||
Build.VERSION.RELEASE));
|
||||
}
|
||||
if (mTemporaryFilesPreference != null) {
|
||||
mTemporaryFilesPreference.setStorageSize(storageCache.temporaryFilesSize, mTotalSize,
|
||||
animate);
|
||||
}
|
||||
// Cache the size info
|
||||
if (result != null) {
|
||||
@@ -445,6 +473,7 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
||||
storageCache.gamesSize = data.gamesSize;
|
||||
storageCache.documentsAndOtherSize = data.documentsAndOtherSize;
|
||||
storageCache.trashSize = data.trashSize;
|
||||
storageCache.systemSize = data.systemSize;
|
||||
// Everything else that hasn't already been attributed is tracked as
|
||||
// belonging to system.
|
||||
long attributedSize = 0;
|
||||
@@ -460,7 +489,9 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
||||
+ otherData.allAppsExceptGamesSize;
|
||||
attributedSize -= otherData.duplicateCodeSize;
|
||||
}
|
||||
storageCache.systemSize = Math.max(DataUnit.GIBIBYTES.toBytes(1),
|
||||
// System size is equal for each user and should be added only once
|
||||
attributedSize += data.systemSize;
|
||||
storageCache.temporaryFilesSize = Math.max(DataUnit.GIBIBYTES.toBytes(1),
|
||||
mUsedBytes - attributedSize);
|
||||
return storageCache;
|
||||
}
|
||||
|
@@ -23,7 +23,6 @@ import android.content.Intent;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.storage.DiskInfo;
|
||||
import android.os.storage.StorageManager;
|
||||
@@ -34,6 +33,7 @@ import android.text.format.Formatter;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
@@ -206,7 +206,7 @@ public class StorageUtils {
|
||||
/** Shows information about system storage. */
|
||||
public static class SystemInfoFragment extends InstrumentedDialogFragment {
|
||||
/** Shows the fragment. */
|
||||
public static void show(Fragment parent) {
|
||||
public static void show(@NonNull Fragment parent) {
|
||||
if (!parent.isAdded()) return;
|
||||
|
||||
final SystemInfoFragment dialog = new SystemInfoFragment();
|
||||
@@ -222,8 +222,33 @@ public class StorageUtils {
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
return new AlertDialog.Builder(getActivity())
|
||||
.setMessage(getContext().getString(R.string.storage_detail_dialog_system,
|
||||
Build.VERSION.RELEASE_OR_PREVIEW_DISPLAY))
|
||||
.setMessage(getContext().getString(R.string.storage_os_detail_dialog_system))
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.create();
|
||||
}
|
||||
}
|
||||
|
||||
/** Shows information about temporary system files. */
|
||||
public static class TemporaryFilesInfoFragment extends InstrumentedDialogFragment {
|
||||
/** Shows the fragment. */
|
||||
public static void show(@NonNull Fragment parent) {
|
||||
if (!parent.isAdded()) return;
|
||||
|
||||
final TemporaryFilesInfoFragment dialog = new TemporaryFilesInfoFragment();
|
||||
dialog.setTargetFragment(parent, 0);
|
||||
dialog.show(parent.getFragmentManager(), "temporaryFilesInfo");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.DIALOG_TEMPORARY_FILES_INFO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
return new AlertDialog.Builder(getActivity())
|
||||
.setMessage(getContext().getString(
|
||||
R.string.storage_other_files_detail_dialog_system))
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.create();
|
||||
}
|
||||
|
@@ -41,6 +41,7 @@ public class StorageCacheHelperTest {
|
||||
private static final long FAKE_TOTAL_SIZE = 256000L;
|
||||
private static final long FAKE_TOTAL_USED_SIZE = 50000L;
|
||||
private static final long FAKE_USED_SIZE = 6500L;
|
||||
private static final long FAKE_TEMPORARY_FILES_SIZE = 2500L;
|
||||
|
||||
private Context mContext;
|
||||
private StorageCacheHelper mHelper;
|
||||
@@ -70,6 +71,7 @@ public class StorageCacheHelperTest {
|
||||
StorageCacheHelper.StorageCache storageCache = mHelper.retrieveCachedSize();
|
||||
|
||||
assertThat(storageCache.imagesSize).isEqualTo(FAKE_IMAGES_SIZE);
|
||||
assertThat(storageCache.temporaryFilesSize).isEqualTo(FAKE_TEMPORARY_FILES_SIZE);
|
||||
assertThat(storageCache.totalSize).isEqualTo(0);
|
||||
}
|
||||
|
||||
@@ -100,6 +102,7 @@ public class StorageCacheHelperTest {
|
||||
result.gamesSize = FAKE_GAMES_SIZE;
|
||||
result.videosSize = FAKE_VIDEOS_SIZE;
|
||||
result.allAppsExceptGamesSize = FAKE_APPS_SIZE;
|
||||
result.temporaryFilesSize = FAKE_TEMPORARY_FILES_SIZE;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@@ -45,6 +45,7 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -126,7 +127,10 @@ public class StorageItemPreferenceControllerTest {
|
||||
final StorageItemPreference documentsAndOther = spy(new StorageItemPreference(mContext));
|
||||
documentsAndOther.setIcon(R.drawable.ic_folder_vd_theme_24);
|
||||
final StorageItemPreference system = spy(new StorageItemPreference(mContext));
|
||||
system.setIcon(com.android.settingslib.R.drawable.ic_system_update);
|
||||
system.setIcon(R.drawable.ic_android_vd_theme_24);
|
||||
final StorageItemPreference temporaryFiles = spy(new StorageItemPreference(mContext));
|
||||
temporaryFiles.setIcon(R.drawable.ic_database_vd_theme_24);
|
||||
final PreferenceCategory categorySplitter = spy(new PreferenceCategory(mContext));
|
||||
final StorageItemPreference trash = spy(new StorageItemPreference(mContext));
|
||||
trash.setIcon(R.drawable.ic_trash_can);
|
||||
|
||||
@@ -147,6 +151,10 @@ public class StorageItemPreferenceControllerTest {
|
||||
.thenReturn(documentsAndOther);
|
||||
when(screen.findPreference(eq(StorageItemPreferenceController.SYSTEM_KEY)))
|
||||
.thenReturn(system);
|
||||
when(screen.findPreference(eq(StorageItemPreferenceController.TEMPORARY_FILES_KEY)))
|
||||
.thenReturn(temporaryFiles);
|
||||
when(screen.findPreference(eq(StorageItemPreferenceController.CATEGORY_SPLITTER)))
|
||||
.thenReturn(categorySplitter);
|
||||
when(screen.findPreference(eq(StorageItemPreferenceController.TRASH_KEY)))
|
||||
.thenReturn(trash);
|
||||
|
||||
@@ -219,6 +227,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
assertThat(mController.mGamesPreference.isVisible()).isFalse();
|
||||
assertThat(mController.mDocumentsAndOtherPreference.isVisible()).isFalse();
|
||||
assertThat(mController.mSystemPreference.isVisible()).isFalse();
|
||||
assertThat(mController.mTemporaryFilesPreference.isVisible()).isFalse();
|
||||
assertThat(mController.mTrashPreference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@@ -329,6 +338,16 @@ public class StorageItemPreferenceControllerTest {
|
||||
.add(nullable(StorageUtils.SystemInfoFragment.class), nullable(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClickTemporaryFiles() {
|
||||
mPreference.setKey(StorageItemPreferenceController.TEMPORARY_FILES_KEY);
|
||||
assertThat(mController.handlePreferenceTreeClick(mPreference)).isTrue();
|
||||
|
||||
verify(mFragment.getFragmentManager().beginTransaction())
|
||||
.add(nullable(StorageUtils.TemporaryFilesInfoFragment.class),
|
||||
nullable(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowUserManager.class)
|
||||
public void testMeasurementCompletedUpdatesPreferences() {
|
||||
@@ -343,6 +362,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
result.documentsAndOtherSize = MEGABYTE_IN_BYTES * 50;
|
||||
result.trashSize = KILOBYTE_IN_BYTES * 100;
|
||||
result.allAppsExceptGamesSize = MEGABYTE_IN_BYTES * 90;
|
||||
result.systemSize = MEGABYTE_IN_BYTES * 60;
|
||||
|
||||
final SparseArray<StorageAsyncLoader.StorageResult> results = new SparseArray<>();
|
||||
results.put(0, result);
|
||||
@@ -356,6 +376,8 @@ public class StorageItemPreferenceControllerTest {
|
||||
assertThat(mController.mDocumentsAndOtherPreference.getSummary().toString())
|
||||
.isEqualTo("50 MB");
|
||||
assertThat(mController.mTrashPreference.getSummary().toString()).isEqualTo("100 kB");
|
||||
assertThat(mController.mSystemPreference.getSummary().toString())
|
||||
.isEqualTo("60 MB");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -373,6 +395,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
verify(mController.mDocumentsAndOtherPreference, times(2))
|
||||
.setIcon(nullable(Drawable.class));
|
||||
verify(mController.mSystemPreference, times(2)).setIcon(nullable(Drawable.class));
|
||||
verify(mController.mTemporaryFilesPreference, times(2)).setIcon(nullable(Drawable.class));
|
||||
verify(mController.mTrashPreference, times(2)).setIcon(nullable(Drawable.class));
|
||||
}
|
||||
|
||||
@@ -437,6 +460,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
assertThat(mController.mGamesPreference.isVisible()).isFalse();
|
||||
assertThat(mController.mDocumentsAndOtherPreference.isVisible()).isFalse();
|
||||
assertThat(mController.mSystemPreference.isVisible()).isFalse();
|
||||
assertThat(mController.mTemporaryFilesPreference.isVisible()).isFalse();
|
||||
assertThat(mController.mTrashPreference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user