Add storage_summary_donut above ProfileSelectStorageFragment

- Modify ProfileSelectFragment to support add preference xml in the
top, and tabLayout below the preferences. Base preference layout is
dummy_preference_screen.xml which contains no preference.
ProfileSelectStorageFragment contains StorageSummaryDonutPreference
above the tabLayout.
- Make StorageSummaryDonutPreferenceController self workable without
StorageDashboardFragment dependence.
- Rename inactive_apps.xml to dummy_preference_screen.xml
- Move ShadowPrivateStorageInfo from LowStorageSliceTest

Bug: 141601408
Test: manual
Change-Id: Ide12840dc81bb104f328e230ecda5d35bba01d7a
This commit is contained in:
Raff Tsai
2019-11-15 11:02:25 +08:00
parent dee1548f61
commit 84327f6aa3
18 changed files with 228 additions and 96 deletions

View File

@@ -41,6 +41,7 @@ import com.android.settings.applications.manageapplications.ManageApplications;
import com.android.settings.core.FeatureFlags;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
import com.android.settings.deviceinfo.PrivateVolumeSettings.SystemInfoFragment;
import com.android.settings.deviceinfo.StorageItemPreference;
import com.android.settings.overlay.FeatureFactory;
@@ -392,14 +393,15 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
private Bundle getWorkAnnotatedBundle(int additionalCapacity) {
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.PERSONAL_WORK_PROFILE)) {
final Bundle args = new Bundle(3 + additionalCapacity);
args.putBoolean(ManageApplications.EXTRA_WORK_ONLY, mIsWorkProfile);
final Bundle args = new Bundle(2 + additionalCapacity);
args.putInt(ProfileSelectFragment.EXTRA_PROFILE,
mIsWorkProfile ? ProfileSelectFragment.WORK : ProfileSelectFragment.PERSONAL);
args.putInt(ManageApplications.EXTRA_WORK_ID, mUserId);
args.putBoolean(ManageApplications.EXTRA_PERSONAL_ONLY, !mIsWorkProfile);
return args;
} else {
final Bundle args = new Bundle(2 + additionalCapacity);
args.putBoolean(ManageApplications.EXTRA_WORK_ONLY, mIsWorkProfile);
args.putInt(ProfileSelectFragment.EXTRA_PROFILE,
mIsWorkProfile ? ProfileSelectFragment.WORK : ProfileSelectFragment.ALL);
args.putInt(ManageApplications.EXTRA_WORK_ID, mUserId);
return args;
}

View File

@@ -17,6 +17,7 @@
package com.android.settings.deviceinfo.storage;
import android.content.Context;
import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.text.TextUtils;
import android.text.format.Formatter;
@@ -25,22 +26,29 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.deviceinfo.PrivateStorageInfo;
import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
import com.android.settingslib.deviceinfo.StorageVolumeProvider;
import com.android.settingslib.utils.ThreadUtils;
import java.text.NumberFormat;
/**
* StorgaeSummaryPreferenceController updates the donut storage summary preference to have the
* SummaryPreferenceController updates the donut storage summary preference to have the
* correct sizes showing.
*/
public class StorageSummaryDonutPreferenceController extends AbstractPreferenceController implements
PreferenceControllerMixin {
public class StorageSummaryDonutPreferenceController extends BasePreferenceController {
private long mUsedBytes;
private long mTotalBytes;
private StorageSummaryDonutPreference mSummary;
private final StorageManager mStorageManager;
private final StorageManagerVolumeProvider mStorageManagerVolumeProvider;
public StorageSummaryDonutPreferenceController(Context context) {
super(context);
public StorageSummaryDonutPreferenceController(Context context, String key) {
super(context, key);
mStorageManager = mContext.getSystemService(StorageManager.class);
mStorageManagerVolumeProvider = new StorageManagerVolumeProvider(mStorageManager);
}
/**
@@ -58,19 +66,31 @@ public class StorageSummaryDonutPreferenceController extends AbstractPreferenceC
@Override
public void displayPreference(PreferenceScreen screen) {
mSummary = screen.findPreference("pref_summary");
mSummary = screen.findPreference(getPreferenceKey());
mSummary.setEnabled(true);
ThreadUtils.postOnBackgroundThread(() -> {
final NumberFormat percentageFormat = NumberFormat.getPercentInstance();
final PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(
mStorageManagerVolumeProvider);
final double privateUsedBytes = info.totalBytes - info.freeBytes;
mTotalBytes = info.totalBytes;
mUsedBytes = info.totalBytes - info.freeBytes;
ThreadUtils.postOnMainThread(() -> {
updateState(mSummary);
});
});
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
StorageSummaryDonutPreference summary = (StorageSummaryDonutPreference) preference;
summary.setTitle(convertUsedBytesToFormattedText(mContext, mUsedBytes));
summary.setSummary(mContext.getString(R.string.storage_volume_total,
mSummary.setTitle(convertUsedBytesToFormattedText(mContext, mUsedBytes));
mSummary.setSummary(mContext.getString(R.string.storage_volume_total,
Formatter.formatShortFileSize(mContext, mTotalBytes)));
summary.setPercent(mUsedBytes, mTotalBytes);
summary.setEnabled(true);
mSummary.setPercent(mUsedBytes, mTotalBytes);
mSummary.setEnabled(true);
}
/** Invalidates the data on the view and re-renders. */
@@ -81,13 +101,8 @@ public class StorageSummaryDonutPreferenceController extends AbstractPreferenceC
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public String getPreferenceKey() {
return "pref_summary";
public int getAvailabilityStatus() {
return AVAILABLE;
}
/**