Merge "Add a movies & tv apps category to storage settings." into oc-dev

This commit is contained in:
Daniel Nishi
2017-04-13 18:39:53 +00:00
committed by Android (Google) Code Review
11 changed files with 115 additions and 8 deletions

View File

@@ -0,0 +1,25 @@
<!--
Copyright (C) 2017 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="24.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M18,3v2h-2L16,3L8,3v2L6,5L6,3L4,3v18h2v-2h2v2h8v-2h2v2h2L20,3h-2zM8,17L6,17v-2h2v2zM8,13L6,13v-2h2v2zM8,9L6,9L6,7h2v2zM18,17h-2v-2h2v2zM18,13h-2v-2h2v2zM18,9h-2L16,7h2v2z"/>
</vector>

View File

@@ -46,16 +46,21 @@
android:title="@string/storage_games"
android:icon="@drawable/ic_videogame_vd_theme_24"
android:order="4" />
<com.android.settings.deviceinfo.StorageItemPreference
android:key="pref_movies"
android:title="@string/storage_movies_tv"
android:icon="@drawable/ic_theaters_vd_theme_24"
android:order="5" />
<com.android.settings.deviceinfo.StorageItemPreference
android:key="pref_other_apps"
android:title="@string/storage_other_apps"
android:icon="@drawable/ic_apps_vd_theme_24"
android:order="5" />
android:order="6" />
<com.android.settings.deviceinfo.StorageItemPreference
android:key="pref_files"
android:title="@string/storage_files"
android:icon="@drawable/ic_folder_vd_theme_24"
android:order="6" />
android:order="7" />
<com.android.settings.deviceinfo.StorageItemPreference
android:key="pref_system"
android:title="@string/storage_detail_system"

View File

@@ -33,6 +33,9 @@
android:title="@string/storage_games"
android:icon="@drawable/ic_videogame_vd_theme_24"
android:order="4" />
<com.android.settings.deviceinfo.StorageItemPreference
android:key="pref_movies"
android:title="@string/storage_movies_tv" />
<com.android.settings.deviceinfo.StorageItemPreference
android:key="pref_other_apps"
android:title="@string/storage_other_apps"

View File

@@ -121,6 +121,7 @@ public class Settings extends SettingsActivity {
public static class ManageDomainUrlsActivity extends SettingsActivity { /* empty */ }
public static class AutomaticStorageManagerSettingsActivity extends SettingsActivity { /* empty */ }
public static class GamesStorageActivity extends SettingsActivity { /* empty */ }
public static class MoviesStorageActivity extends SettingsActivity { /* empty */ }
public static class TopLevelSettings extends SettingsActivity { /* empty */ }
public static class ApnSettingsActivity extends SettingsActivity { /* empty */ }

View File

@@ -63,6 +63,7 @@ import com.android.settings.Settings.AllApplicationsActivity;
import com.android.settings.Settings.GamesStorageActivity;
import com.android.settings.Settings.HighPowerApplicationsActivity;
import com.android.settings.Settings.ManageExternalSourcesActivity;
import com.android.settings.Settings.MoviesStorageActivity;
import com.android.settings.Settings.NotificationAppListActivity;
import com.android.settings.Settings.OverlaySettingsActivity;
import com.android.settings.Settings.StorageUseActivity;
@@ -256,6 +257,7 @@ public class ManageApplications extends InstrumentedPreferenceFragment
public static final int LIST_TYPE_WRITE_SETTINGS = 7;
public static final int LIST_TYPE_MANAGE_SOURCES = 8;
public static final int LIST_TYPE_GAMES = 9;
public static final int LIST_TYPE_MOVIES = 10;
// List types that should show instant apps.
@@ -316,6 +318,9 @@ public class ManageApplications extends InstrumentedPreferenceFragment
} else if (className.equals(GamesStorageActivity.class.getName())) {
mListType = LIST_TYPE_GAMES;
mSortOrder = R.id.sort_order_size;
} else if (className.equals(MoviesStorageActivity.class.getName())) {
mListType = LIST_TYPE_MOVIES;
mSortOrder = R.id.sort_order_size;
} else {
mListType = LIST_TYPE_MAIN;
}
@@ -424,6 +429,8 @@ public class ManageApplications extends InstrumentedPreferenceFragment
}
if (mListType == LIST_TYPE_GAMES) {
mApplications.setOverrideFilter(ApplicationsState.FILTER_GAMES);
} else if (mListType == LIST_TYPE_MOVIES) {
mApplications.setOverrideFilter(ApplicationsState.FILTER_MOVIES);
}
}
@@ -450,6 +457,7 @@ public class ManageApplications extends InstrumentedPreferenceFragment
case LIST_TYPE_NOTIFICATION:
case LIST_TYPE_STORAGE:
case LIST_TYPE_GAMES:
case LIST_TYPE_MOVIES:
return mSortOrder == R.id.sort_order_alpha;
default:
return false;
@@ -470,6 +478,8 @@ public class ManageApplications extends InstrumentedPreferenceFragment
return MetricsEvent.APPLICATIONS_STORAGE_APPS;
case LIST_TYPE_GAMES:
return MetricsEvent.APPLICATIONS_STORAGE_GAMES;
case LIST_TYPE_MOVIES:
return MetricsEvent.APPLICATIONS_STORAGE_MOVIES;
case LIST_TYPE_USAGE_ACCESS:
return MetricsEvent.USAGE_ACCESS;
case LIST_TYPE_HIGH_POWER:
@@ -577,6 +587,9 @@ public class ManageApplications extends InstrumentedPreferenceFragment
case LIST_TYPE_GAMES:
startAppInfoFragment(AppStorageSettings.class, R.string.game_storage_settings);
break;
case LIST_TYPE_MOVIES:
startAppInfoFragment(AppStorageSettings.class, R.string.storage_movies_tv);
break;
// TODO: Figure out if there is a way where we can spin up the profile's settings
// process ahead of time, to avoid a long load of data when user clicks on a managed app.
// Maybe when they load the list of apps that contains managed profile apps.

View File

@@ -140,6 +140,7 @@ public class StorageProfileFragment extends DashboardFragment
// TODO(b/35927909): Attribute app sizes better than zeroing out for profiles.
result.gamesSize = 0;
result.musicAppsSize = 0;
result.videoAppsSize = 0;
result.otherAppsSize = 0;
return result;
}

View File

@@ -18,6 +18,7 @@ package com.android.settings.deviceinfo.storage;
import static android.content.pm.ApplicationInfo.CATEGORY_AUDIO;
import static android.content.pm.ApplicationInfo.CATEGORY_GAME;
import static android.content.pm.ApplicationInfo.CATEGORY_VIDEO;
import android.content.Context;
import android.content.pm.ApplicationInfo;
@@ -99,6 +100,9 @@ public class StorageAsyncLoader
case CATEGORY_AUDIO:
result.musicAppsSize += attributedAppSizeInBytes;
break;
case CATEGORY_VIDEO:
result.videoAppsSize += attributedAppSizeInBytes;
break;
default:
// The deprecated game flag does not set the category.
if ((app.flags & ApplicationInfo.FLAG_IS_GAME) != 0) {
@@ -123,6 +127,7 @@ public class StorageAsyncLoader
public static class AppsStorageResult {
public long gamesSize;
public long musicAppsSize;
public long videoAppsSize;
public long otherAppsSize;
public long systemSize;
public StorageStatsSource.ExternalStorageStats externalStats;

View File

@@ -65,6 +65,8 @@ public class StorageItemPreferenceController extends PreferenceController {
@VisibleForTesting
static final String GAME_KEY = "pref_games";
@VisibleForTesting
static final String MOVIES_KEY = "pref_movies";
@VisibleForTesting
static final String OTHER_APPS_KEY = "pref_other_apps";
@VisibleForTesting
static final String SYSTEM_KEY = "pref_system";
@@ -82,6 +84,7 @@ public class StorageItemPreferenceController extends PreferenceController {
private StorageItemPreference mPhotoPreference;
private StorageItemPreference mAudioPreference;
private StorageItemPreference mGamePreference;
private StorageItemPreference mMoviesPreference;
private StorageItemPreference mAppPreference;
private StorageItemPreference mFilePreference;
private StorageItemPreference mSystemPreference;
@@ -123,6 +126,9 @@ public class StorageItemPreferenceController extends PreferenceController {
case GAME_KEY:
intent = getGamesIntent();
break;
case MOVIES_KEY:
intent = getMoviesIntent();
break;
case OTHER_APPS_KEY:
// Because we are likely constructed with a null volume, this is theoretically
// possible.
@@ -204,6 +210,7 @@ public class StorageItemPreferenceController extends PreferenceController {
mPhotoPreference = (StorageItemPreference) screen.findPreference(PHOTO_KEY);
mAudioPreference = (StorageItemPreference) screen.findPreference(AUDIO_KEY);
mGamePreference = (StorageItemPreference) screen.findPreference(GAME_KEY);
mMoviesPreference = (StorageItemPreference) screen.findPreference(MOVIES_KEY);
mAppPreference = (StorageItemPreference) screen.findPreference(OTHER_APPS_KEY);
mSystemPreference = (StorageItemPreference) screen.findPreference(SYSTEM_KEY);
mFilePreference = (StorageItemPreference) screen.findPreference(FILES_KEY);
@@ -217,6 +224,7 @@ public class StorageItemPreferenceController extends PreferenceController {
mAudioPreference.setStorageSize(
data.musicAppsSize + data.externalStats.audioBytes, mTotalSize);
mGamePreference.setStorageSize(data.gamesSize, mTotalSize);
mMoviesPreference.setStorageSize(data.videoAppsSize, mTotalSize);
mAppPreference.setStorageSize(data.otherAppsSize, mTotalSize);
if (mSystemPreference != null) {
mSystemPreference.setStorageSize(mSystemSize + data.systemSize, mTotalSize);
@@ -243,6 +251,7 @@ public class StorageItemPreferenceController extends PreferenceController {
list.add(PHOTO_KEY);
list.add(AUDIO_KEY);
list.add(GAME_KEY);
list.add(MOVIES_KEY);
list.add(OTHER_APPS_KEY);
list.add(SYSTEM_KEY);
list.add(FILES_KEY);
@@ -289,6 +298,15 @@ public class StorageItemPreferenceController extends PreferenceController {
null, false, mMetricsFeatureProvider.getMetricsCategory(mFragment));
}
private Intent getMoviesIntent() {
Bundle args = new Bundle(1);
args.putString(ManageApplications.EXTRA_CLASSNAME,
Settings.MoviesStorageActivity.class.getName());
return Utils.onBuildStartFragmentIntent(mContext,
ManageApplications.class.getName(), args, null, R.string.storage_movies_tv,
null, false, mMetricsFeatureProvider.getMetricsCategory(mFragment));
}
private Intent getFilesIntent() {
return mSvp.findEmulatedForPrivate(mVolume).buildBrowseIntent();
}

View File

@@ -44,6 +44,7 @@ public class StorageProfileFragmentTest {
result.musicAppsSize = 100;
result.otherAppsSize = 200;
result.gamesSize = 300;
result.videoAppsSize = 400;
result.externalStats = new StorageStatsSource.ExternalStorageStats(6, 1, 2, 3);
SparseArray<StorageAsyncLoader.AppsStorageResult> resultsArray = new SparseArray<>();
resultsArray.put(0, result);
@@ -57,6 +58,7 @@ public class StorageProfileFragmentTest {
StorageAsyncLoader.AppsStorageResult extractedResult = resultCaptor.getValue();
assertThat(extractedResult.musicAppsSize).isEqualTo(0);
assertThat(extractedResult.videoAppsSize).isEqualTo(0);
assertThat(extractedResult.otherAppsSize).isEqualTo(0);
assertThat(extractedResult.gamesSize).isEqualTo(0);
assertThat(extractedResult.externalStats.audioBytes).isEqualTo(1);

View File

@@ -189,6 +189,24 @@ public class StorageItemPreferenceControllerTest {
.isEqualTo(R.string.game_storage_settings);
}
@Test
public void testClickMovies() {
mPreference.setKey("pref_movies");
mController.handlePreferenceTreeClick(mPreference);
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
any(UserHandle.class));
Intent intent = argumentCaptor.getValue();
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)).isEqualTo(
ManageApplications.class.getName());
assertThat(intent.getIntExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, 0))
.isEqualTo(R.string.storage_movies_tv);
}
@Test
public void testClickSystem() {
mPreference.setKey("pref_system");
@@ -203,6 +221,7 @@ public class StorageItemPreferenceControllerTest {
StorageItemPreference audio = new StorageItemPreference(mContext);
StorageItemPreference image = new StorageItemPreference(mContext);
StorageItemPreference games = new StorageItemPreference(mContext);
StorageItemPreference movies = new StorageItemPreference(mContext);
StorageItemPreference apps = new StorageItemPreference(mContext);
StorageItemPreference system = new StorageItemPreference(mContext);
StorageItemPreference files = new StorageItemPreference(mContext);
@@ -213,6 +232,8 @@ public class StorageItemPreferenceControllerTest {
eq(StorageItemPreferenceController.PHOTO_KEY))).thenReturn(image);
when(screen.findPreference(
eq(StorageItemPreferenceController.GAME_KEY))).thenReturn(games);
when(screen.findPreference(
eq(StorageItemPreferenceController.MOVIES_KEY))).thenReturn(movies);
when(screen.findPreference(
eq(StorageItemPreferenceController.OTHER_APPS_KEY))).thenReturn(apps);
when(screen.findPreference(
@@ -224,6 +245,7 @@ public class StorageItemPreferenceControllerTest {
mController.setSystemSize(KILOBYTE * 6);
StorageAsyncLoader.AppsStorageResult result = new StorageAsyncLoader.AppsStorageResult();
result.gamesSize = KILOBYTE * 8;
result.videoAppsSize = KILOBYTE * 16;
result.musicAppsSize = KILOBYTE * 4;
result.otherAppsSize = KILOBYTE * 9;
result.systemSize = KILOBYTE * 10;
@@ -240,6 +262,7 @@ public class StorageItemPreferenceControllerTest {
assertThat(audio.getSummary().toString()).isEqualTo("14.00KB"); // 4KB apps + 10KB files
assertThat(image.getSummary().toString()).isEqualTo("35.00KB"); // 15KB video + 20KB images
assertThat(games.getSummary().toString()).isEqualTo("8.00KB");
assertThat(movies.getSummary().toString()).isEqualTo("16.00KB");
assertThat(apps.getSummary().toString()).isEqualTo("9.00KB");
assertThat(system.getSummary().toString()).isEqualTo("16.00KB");
assertThat(files.getSummary().toString()).isEqualTo("5.00KB");

View File

@@ -169,6 +169,17 @@ public class StorageAsyncLoaderTest {
assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(11L);
}
@Test
public void testVideoAppsAreFiltered() throws Exception {
addPackage(PACKAGE_NAME_1, 0, 1, 10, ApplicationInfo.CATEGORY_VIDEO);
SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
assertThat(result.size()).isEqualTo(1);
assertThat(result.get(PRIMARY_USER_ID).videoAppsSize).isEqualTo(11L);
assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(0);
}
private ApplicationInfo addPackage(
String packageName, long cacheSize, long codeSize, long dataSize, int category) {
StorageStatsSource.AppStorageStats storageStats =