Checkpoint of new storage UI.

Top-level storage UI now shows list of all devices, both internal
and adopted/private volumes, and public/shared volumes.

When viewing a private volume, show traditional clustering of data
types, including summary of other users.  For adopted volumes, any
actions are tucked away in a menu, since they're not primary.  Misc
files browsing is now provided by DocumentsUI.

Teach StorageMeasurement about new private volumes, including
handling emulated volumes stacked above them.  When measuring, only
consider apps actually hosted on the current volume UUID.

When viewing a public volume, we default to launching into file
management mode, and offer a simple eject button at the top-level
view.  File management mode is offered by new DocumentsUI browse
intent, and a Settings link there redirects back to us for actual
operations like ejecting/formatting.  When unmounted, we launch
into our action view.

Actions like ejecting/formatting just show simple toasts for now.

Bug: 19993667
Change-Id: Ie990ef3c01fb3717aaf8c79bfc53aac7edefdcf7
This commit is contained in:
Jeff Sharkey
2015-04-11 21:27:33 -07:00
parent 09c0c1385a
commit 42833b2ff4
20 changed files with 1565 additions and 1502 deletions

View File

@@ -0,0 +1,205 @@
/*
* 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.deviceinfo;
import static com.android.settings.deviceinfo.StorageSettings.EXTRA_VOLUME_ID;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.os.SystemProperties;
import android.os.storage.StorageEventListener;
import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.preference.Preference;
import android.preference.PreferenceScreen;
import android.provider.DocumentsContract;
import android.text.format.Formatter;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.util.Preconditions;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.deviceinfo.StorageSettings.FormatTask;
import com.android.settings.deviceinfo.StorageSettings.MountTask;
import com.android.settings.deviceinfo.StorageSettings.UnmountTask;
import java.io.File;
import java.util.Objects;
/**
* Panel showing summary and actions for a {@link VolumeInfo#TYPE_PUBLIC}
* storage volume.
*/
public class PublicVolumeSettings extends SettingsPreferenceFragment {
// TODO: disable unmount when providing over MTP/PTP
private static final String PREF_FORMAT_INTERNAL = "debug.format_internal";
private StorageManager mStorageManager;
private VolumeInfo mVolume;
private int mNextOrder = 0;
private UsageBarPreference mGraph;
private StorageItemPreference mTotal;
private StorageItemPreference mAvailable;
private Preference mMount;
private Preference mUnmount;
private Preference mFormat;
private Preference mFormatInternal;
private long mTotalSize;
private long mAvailSize;
@Override
protected int getMetricsCategory() {
return MetricsLogger.DEVICEINFO_STORAGE;
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
final Context context = getActivity();
mStorageManager = context.getSystemService(StorageManager.class);
if (DocumentsContract.ACTION_DOCUMENT_ROOT_SETTINGS.equals(
getActivity().getIntent().getAction())) {
final Uri rootUri = getActivity().getIntent().getData();
final String fsUuid = DocumentsContract.getRootId(rootUri);
mVolume = mStorageManager.findVolumeByUuid(fsUuid);
} else {
final String volId = getArguments().getString(EXTRA_VOLUME_ID);
mVolume = mStorageManager.findVolumeById(volId);
}
Preconditions.checkNotNull(mVolume);
Preconditions.checkState(mVolume.type == VolumeInfo.TYPE_PUBLIC);
addPreferencesFromResource(R.xml.device_info_storage_volume);
mGraph = buildGraph();
mTotal = buildItem(R.string.memory_size, 0);
mAvailable = buildItem(R.string.memory_available, R.color.memory_avail);
mMount = buildAction(R.string.storage_menu_mount);
mUnmount = buildAction(R.string.storage_menu_unmount);
mFormat = buildAction(R.string.storage_menu_format);
mFormatInternal = buildAction(R.string.storage_menu_format_internal);
}
public void refresh() {
getActivity().setTitle(mStorageManager.getBestVolumeDescription(mVolume.id));
final Context context = getActivity();
final PreferenceScreen screen = getPreferenceScreen();
screen.removeAll();
if (mVolume.state == VolumeInfo.STATE_MOUNTED) {
screen.addPreference(mGraph);
screen.addPreference(mTotal);
screen.addPreference(mAvailable);
}
if (mVolume.state == VolumeInfo.STATE_UNMOUNTED) {
screen.addPreference(mMount);
}
if (mVolume.state == VolumeInfo.STATE_MOUNTED) {
screen.addPreference(mUnmount);
}
screen.addPreference(mFormat);
if (SystemProperties.getBoolean(PREF_FORMAT_INTERNAL, false)) {
screen.addPreference(mFormatInternal);
}
final File file = new File(mVolume.path);
mTotalSize = file.getTotalSpace();
mAvailSize = file.getFreeSpace();
mTotal.setSummary(Formatter.formatFileSize(context, mTotalSize));
mAvailable.setSummary(Formatter.formatFileSize(context, mAvailSize));
mGraph.clear();
mGraph.addEntry(0, (mTotalSize - mAvailSize) / (float) mTotalSize,
android.graphics.Color.GRAY);
mGraph.commit();
}
private UsageBarPreference buildGraph() {
final UsageBarPreference pref = new UsageBarPreference(getActivity());
pref.setOrder(mNextOrder++);
return pref;
}
private StorageItemPreference buildItem(int titleRes, int colorRes) {
final StorageItemPreference pref = new StorageItemPreference(getActivity(), titleRes,
colorRes);
pref.setOrder(mNextOrder++);
return pref;
}
private Preference buildAction(int titleRes) {
final Preference pref = new Preference(getActivity());
pref.setTitle(titleRes);
pref.setOrder(mNextOrder++);
return pref;
}
@Override
public void onResume() {
super.onResume();
mStorageManager.registerListener(mStorageListener);
refresh();
}
@Override
public void onPause() {
super.onPause();
mStorageManager.unregisterListener(mStorageListener);
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference pref) {
final Context context = getActivity();
if (pref == mMount) {
new MountTask(context, mVolume.id).execute();
} else if (pref == mUnmount) {
new UnmountTask(context, mVolume.id).execute();
} else if (pref == mFormat) {
new FormatTask(context, mVolume.id).execute();
} else if (pref == mFormatInternal) {
// TODO: implement this
}
return super.onPreferenceTreeClick(preferenceScreen, pref);
}
private final StorageEventListener mStorageListener = new StorageEventListener() {
@Override
public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState) {
if (Objects.equals(mVolume.id, vol.id)) {
mVolume = vol;
refresh();
}
}
};
}