Merge "Cleanup Storage Settings" into sc-dev

This commit is contained in:
Arc Wang
2021-05-05 03:13:37 +00:00
committed by Android (Google) Code Review
12 changed files with 76 additions and 709 deletions

View File

@@ -1,49 +0,0 @@
/*
* Copyright (C) 2015 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.
*/
package com.android.settings.applications.manageapplications;
import androidx.fragment.app.Fragment;
/**
* FileViewHolderController handles adapting the AppViewHolder to work as a general purpose
* storage categorization preference in the ManageApplications view.
*/
public interface FileViewHolderController {
/**
* Begins a synchronous query for statistics for the files.
*/
void queryStats();
/**
* Returns if the preference should be shown.
*/
boolean shouldShow();
/**
* Initializes the view within an AppViewHolder.
*
* @param holder The holder to use to initialize.
*/
void setupView(ApplicationViewHolder holder);
/**
* Handles the behavior when the view is clicked.
*
* @param fragment Fragment where the click originated.
*/
void onClick(Fragment fragment);
}

View File

@@ -83,7 +83,6 @@ import com.android.settings.Settings;
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.OverlaySettingsActivity;
import com.android.settings.Settings.StorageUseActivity;
import com.android.settings.Settings.UsageAccessSettingsActivity;
@@ -130,7 +129,6 @@ import com.android.settingslib.applications.ApplicationsState.AppEntry;
import com.android.settingslib.applications.ApplicationsState.AppFilter;
import com.android.settingslib.applications.ApplicationsState.CompoundFilter;
import com.android.settingslib.applications.ApplicationsState.VolumeFilter;
import com.android.settingslib.applications.StorageStatsSource;
import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
import com.android.settingslib.utils.ThreadUtils;
import com.android.settingslib.widget.settingsspinner.SettingsSpinnerAdapter;
@@ -182,9 +180,7 @@ public class ManageApplications extends InstrumentedFragment
// Storage types. Used to determine what the extra item in the list of preferences is.
public static final int STORAGE_TYPE_DEFAULT = 0; // Show all apps that are not categorized.
public static final int STORAGE_TYPE_MUSIC = 1;
public static final int STORAGE_TYPE_LEGACY = 2; // Show apps even if they can be categorized.
public static final int STORAGE_TYPE_PHOTOS_VIDEOS = 3;
public static final int STORAGE_TYPE_LEGACY = 1; // Show apps even if they can be categorized.
/**
* Intents with action {@code android.settings.MANAGE_APP_OVERLAY_PERMISSION}
@@ -230,12 +226,10 @@ public class ManageApplications extends InstrumentedFragment
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;
public static final int LIST_TYPE_PHOTOGRAPHY = 11;
public static final int LIST_TYPE_WIFI_ACCESS = 13;
public static final int LIST_MANAGE_EXTERNAL_STORAGE = 14;
public static final int LIST_TYPE_ALARMS_AND_REMINDERS = 15;
public static final int LIST_TYPE_MEDIA_MANAGEMENT_APPS = 16;
public static final int LIST_TYPE_WIFI_ACCESS = 10;
public static final int LIST_MANAGE_EXTERNAL_STORAGE = 11;
public static final int LIST_TYPE_ALARMS_AND_REMINDERS = 12;
public static final int LIST_TYPE_MEDIA_MANAGEMENT_APPS = 13;
// List types that should show instant apps.
public static final Set<Integer> LIST_TYPES_WITH_INSTANT = new ArraySet<>(Arrays.asList(
@@ -314,13 +308,6 @@ public class ManageApplications extends InstrumentedFragment
} 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 if (className.equals(Settings.PhotosStorageActivity.class.getName())) {
mListType = LIST_TYPE_PHOTOGRAPHY;
mSortOrder = R.id.sort_order_size;
mStorageType = args.getInt(EXTRA_STORAGE_TYPE, STORAGE_TYPE_DEFAULT);
} else if (className.equals(Settings.ChangeWifiStateActivity.class.getName())) {
mListType = LIST_TYPE_WIFI_ACCESS;
screenTitle = R.string.change_wifi_state_title;
@@ -429,24 +416,6 @@ public class ManageApplications extends InstrumentedFragment
mApplications.mHasReceivedBridgeCallback =
savedInstanceState.getBoolean(EXTRA_HAS_BRIDGE, false);
}
int userId = mIsWorkOnly ? mWorkUserId : UserHandle.myUserId();
if (mStorageType == STORAGE_TYPE_MUSIC) {
Context context = getContext();
mApplications.setExtraViewController(
new MusicViewHolderController(
context,
new StorageStatsSource(context),
mVolumeUuid,
UserHandle.of(userId)));
} else if (mStorageType == STORAGE_TYPE_PHOTOS_VIDEOS) {
Context context = getContext();
mApplications.setExtraViewController(
new PhotosViewHolderController(
context,
new StorageStatsSource(context),
mVolumeUuid,
UserHandle.of(userId)));
}
mRecyclerView = mListContainer.findViewById(R.id.apps_list);
mRecyclerView.setItemAnimator(null);
mRecyclerView.setLayoutManager(new LinearLayoutManager(
@@ -508,19 +477,13 @@ public class ManageApplications extends InstrumentedFragment
static AppFilter getCompositeFilter(int listType, int storageType, String volumeUuid) {
AppFilter filter = new VolumeFilter(volumeUuid);
if (listType == LIST_TYPE_STORAGE) {
if (storageType == STORAGE_TYPE_MUSIC) {
filter = new CompoundFilter(ApplicationsState.FILTER_AUDIO, filter);
} else if (storageType == STORAGE_TYPE_DEFAULT) {
if (storageType == STORAGE_TYPE_DEFAULT) {
filter = new CompoundFilter(ApplicationsState.FILTER_APPS_EXCEPT_GAMES, filter);
}
return filter;
}
if (listType == LIST_TYPE_GAMES) {
return new CompoundFilter(ApplicationsState.FILTER_GAMES, filter);
} else if (listType == LIST_TYPE_MOVIES) {
return new CompoundFilter(ApplicationsState.FILTER_MOVIES, filter);
} else if (listType == LIST_TYPE_PHOTOGRAPHY) {
return new CompoundFilter(ApplicationsState.FILTER_PHOTOS, filter);
}
return null;
}
@@ -533,16 +496,9 @@ public class ManageApplications extends InstrumentedFragment
case LIST_TYPE_NOTIFICATION:
return SettingsEnums.MANAGE_APPLICATIONS_NOTIFICATIONS;
case LIST_TYPE_STORAGE:
if (mStorageType == STORAGE_TYPE_MUSIC) {
return SettingsEnums.APPLICATIONS_STORAGE_MUSIC;
}
return SettingsEnums.APPLICATIONS_STORAGE_APPS;
case LIST_TYPE_GAMES:
return SettingsEnums.APPLICATIONS_STORAGE_GAMES;
case LIST_TYPE_MOVIES:
return SettingsEnums.APPLICATIONS_STORAGE_MOVIES;
case LIST_TYPE_PHOTOGRAPHY:
return SettingsEnums.APPLICATIONS_STORAGE_PHOTOS;
case LIST_TYPE_USAGE_ACCESS:
return SettingsEnums.USAGE_ACCESS;
case LIST_TYPE_HIGH_POWER:
@@ -668,12 +624,6 @@ public class ManageApplications extends InstrumentedFragment
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;
case LIST_TYPE_PHOTOGRAPHY:
startAppInfoFragment(AppStorageSettings.class, R.string.storage_photos_videos);
break;
case LIST_TYPE_WIFI_ACCESS:
startAppInfoFragment(ChangeWifiStateDetails.class,
R.string.change_wifi_state_title);
@@ -760,10 +710,6 @@ public class ManageApplications extends InstrumentedFragment
return R.string.help_uri_apps_manage_sources;
case LIST_TYPE_GAMES:
return R.string.help_uri_apps_overlay;
case LIST_TYPE_MOVIES:
return R.string.help_uri_apps_movies;
case LIST_TYPE_PHOTOGRAPHY:
return R.string.help_uri_apps_photography;
case LIST_TYPE_WIFI_ACCESS:
return R.string.help_uri_apps_wifi_access;
case LIST_MANAGE_EXTERNAL_STORAGE:
@@ -856,8 +802,6 @@ public class ManageApplications extends InstrumentedFragment
mCurrentPkgName = entry.info.packageName;
mCurrentUid = entry.info.uid;
startApplicationDetailsActivity();
} else {
mApplications.mExtraViewController.onClick(this);
}
}
@@ -1046,7 +990,6 @@ public class ManageApplications extends InstrumentedFragment
private AppFilter mCompositeFilter;
private boolean mHasReceivedLoadEntries;
private boolean mHasReceivedBridgeCallback;
private FileViewHolderController mExtraViewController;
private SearchFilter mSearchFilter;
private PowerAllowlistBackend mBackend;
@@ -1146,18 +1089,6 @@ public class ManageApplications extends InstrumentedFragment
}
}
public void setExtraViewController(FileViewHolderController extraViewController) {
mExtraViewController = extraViewController;
// Start to query extra view's stats on background, and once done post result to main
// thread.
ThreadUtils.postOnBackgroundThread(() -> {
mExtraViewController.queryStats();
ThreadUtils.postOnMainThread(() -> {
onExtraViewCompleted();
});
});
}
public void resume(int sort) {
if (DEBUG) Log.i(TAG, "Resume! mResumed=" + mResumed);
if (!mResumed) {
@@ -1219,10 +1150,7 @@ public class ManageApplications extends InstrumentedFragment
@Override
public int getItemViewType(int position) {
boolean isLastItem = (getItemCount() - 1) == position;
return hasExtraView() && isLastItem
? VIEW_TYPE_EXTRA_VIEW
: VIEW_TYPE_APP;
return VIEW_TYPE_APP;
}
public void rebuild() {
@@ -1454,20 +1382,12 @@ public class ManageApplications extends InstrumentedFragment
}
}
public void onExtraViewCompleted() {
if (!hasExtraView()) {
return;
}
// Update last item - this is assumed to be the extra view.
notifyItemChanged(getItemCount() - 1);
}
@Override
public int getItemCount() {
if (mEntries == null) {
return 0;
}
return mEntries.size() + (hasExtraView() ? 1 : 0);
return mEntries.size();
}
public int getApplicationCount() {
@@ -1499,24 +1419,20 @@ public class ManageApplications extends InstrumentedFragment
@Override
public void onBindViewHolder(ApplicationViewHolder holder, int position) {
if (mEntries != null && mExtraViewController != null && position == mEntries.size()) {
// set up view for extra view controller
mExtraViewController.setupView(holder);
} else {
// Bind the data efficiently with the holder
ApplicationsState.AppEntry entry = mEntries.get(position);
synchronized (entry) {
holder.setTitle(entry.label);
mState.ensureLabelDescription(entry);
holder.itemView.setContentDescription(entry.labelDescription);
mState.ensureIcon(entry);
holder.setIcon(entry.icon);
updateSummary(holder, entry);
updateSwitch(holder, entry);
holder.updateDisableView(entry.info);
}
holder.setEnabled(isEnabled(position));
// Bind the data efficiently with the holder
final ApplicationsState.AppEntry entry = mEntries.get(position);
synchronized (entry) {
holder.setTitle(entry.label);
mState.ensureLabelDescription(entry);
holder.itemView.setContentDescription(entry.labelDescription);
mState.ensureIcon(entry);
holder.setIcon(entry.icon);
updateSummary(holder, entry);
updateSwitch(holder, entry);
holder.updateDisableView(entry.info);
}
holder.setEnabled(isEnabled(position));
holder.itemView.setOnClickListener(mManageApplications);
}
@@ -1589,11 +1505,6 @@ public class ManageApplications extends InstrumentedFragment
}
}
private boolean hasExtraView() {
return mExtraViewController != null
&& mExtraViewController.shouldShow();
}
public static class OnScrollListener extends RecyclerView.OnScrollListener {
private int mScrollState = SCROLL_STATE_IDLE;
private boolean mDelayNotifyDataChange;

View File

@@ -1,90 +0,0 @@
/*
* Copyright (C) 2016 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.
*/
package com.android.settings.applications.manageapplications;
import android.content.Context;
import android.content.Intent;
import android.os.UserHandle;
import android.provider.DocumentsContract;
import android.text.format.Formatter;
import android.util.Log;
import androidx.annotation.WorkerThread;
import androidx.fragment.app.Fragment;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settingslib.applications.StorageStatsSource;
import java.io.IOException;
/**
* MusicViewHolderController controls an Audio/Music file view in the ManageApplications view.
*/
public class MusicViewHolderController implements FileViewHolderController {
private static final String TAG = "MusicViewHolderCtrl";
private static final String AUTHORITY_MEDIA = "com.android.providers.media.documents";
private Context mContext;
private StorageStatsSource mSource;
private String mVolumeUuid;
private long mMusicSize;
private UserHandle mUser;
public MusicViewHolderController(
Context context, StorageStatsSource source, String volumeUuid, UserHandle user) {
mContext = context;
mSource = source;
mVolumeUuid = volumeUuid;
mUser = user;
}
@Override
@WorkerThread
public void queryStats() {
try {
mMusicSize = mSource.getExternalStorageStats(mVolumeUuid, mUser).audioBytes;
} catch (IOException e) {
mMusicSize = 0;
Log.w(TAG, e);
}
}
@Override
public boolean shouldShow() {
return true;
}
@Override
public void setupView(ApplicationViewHolder holder) {
holder.setIcon(R.drawable.ic_headset_24dp);
holder.setTitle(mContext.getText(R.string.audio_files_title));
holder.setSummary(Formatter.formatFileSize(mContext, mMusicSize));
}
@Override
public void onClick(Fragment fragment) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(
DocumentsContract.buildRootUri(AUTHORITY_MEDIA, "audio_root"),
DocumentsContract.Root.MIME_TYPE_ITEM);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.putExtra(Intent.EXTRA_USER_ID, mUser.getIdentifier());
Utils.launchIntent(fragment, intent);
}
}

View File

@@ -1,89 +0,0 @@
/*
* Copyright (C) 2016 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.
*/
package com.android.settings.applications.manageapplications;
import android.content.Context;
import android.content.Intent;
import android.os.UserHandle;
import android.text.format.Formatter;
import android.util.Log;
import androidx.annotation.WorkerThread;
import androidx.fragment.app.Fragment;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settingslib.applications.StorageStatsSource;
import java.io.IOException;
/** PhotosViewHolderController controls an Audio/Music file view in the ManageApplications view. */
public class PhotosViewHolderController implements FileViewHolderController {
private static final String TAG = "PhotosViewHolderCtrl";
private static final String IMAGE_MIME_TYPE = "image/*";
private Context mContext;
private StorageStatsSource mSource;
private String mVolumeUuid;
private long mFilesSize;
private UserHandle mUser;
public PhotosViewHolderController(
Context context, StorageStatsSource source, String volumeUuid, UserHandle user) {
mContext = context;
mSource = source;
mVolumeUuid = volumeUuid;
mUser = user;
}
@Override
@WorkerThread
public void queryStats() {
try {
StorageStatsSource.ExternalStorageStats stats =
mSource.getExternalStorageStats(mVolumeUuid, mUser);
mFilesSize = stats.imageBytes + stats.videoBytes;
} catch (IOException e) {
mFilesSize = 0;
Log.w(TAG, e);
}
}
@Override
public boolean shouldShow() {
return true;
}
@Override
public void setupView(ApplicationViewHolder holder) {
holder.setIcon(R.drawable.ic_photo_library);
holder.setTitle(mContext.getText(R.string.storage_detail_images));
holder.setSummary(Formatter.formatFileSize(mContext, mFilesSize));
}
@Override
public void onClick(Fragment fragment) {
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
intent.setType(IMAGE_MIME_TYPE);
intent.putExtra(Intent.EXTRA_FROM_STORAGE, true);
intent.putExtra(Intent.EXTRA_USER_ID, mUser.getIdentifier());
Utils.launchIntent(fragment, intent);
}
}