Search in sources :

Example 41 with PrivateStorageInfo

use of com.android.settingslib.deviceinfo.PrivateStorageInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class StorageDashboardFragment method initializeCachedValues.

@VisibleForTesting
public void initializeCachedValues() {
    PrivateStorageInfo info = mCachedStorageValuesHelper.getCachedPrivateStorageInfo();
    SparseArray<StorageAsyncLoader.AppsStorageResult> loaderResult = mCachedStorageValuesHelper.getCachedAppsStorageResult();
    if (info == null || loaderResult == null) {
        return;
    }
    mStorageInfo = info;
    mAppsResult = loaderResult;
}
Also used : PrivateStorageInfo(com.android.settingslib.deviceinfo.PrivateStorageInfo) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 42 with PrivateStorageInfo

use of com.android.settingslib.deviceinfo.PrivateStorageInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class StorageSettings method refresh.

private synchronized void refresh() {
    final Context context = getPrefContext();
    getPreferenceScreen().removeAll();
    mInternalCategory.removeAll();
    mExternalCategory.removeAll();
    mInternalCategory.addPreference(mInternalSummary);
    final StorageManagerVolumeProvider smvp = new StorageManagerVolumeProvider(mStorageManager);
    final PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(smvp);
    final long privateTotalBytes = info.totalBytes;
    final long privateUsedBytes = info.totalBytes - info.freeBytes;
    final List<VolumeInfo> volumes = mStorageManager.getVolumes();
    Collections.sort(volumes, VolumeInfo.getDescriptionComparator());
    for (VolumeInfo vol : volumes) {
        if (vol.getType() == VolumeInfo.TYPE_PRIVATE) {
            if (vol.getState() == VolumeInfo.STATE_UNMOUNTABLE) {
                mInternalCategory.addPreference(new StorageVolumePreference(context, vol, 0));
            } else {
                final long volumeTotalBytes = PrivateStorageInfo.getTotalSize(vol, sTotalInternalStorage);
                mInternalCategory.addPreference(new StorageVolumePreference(context, vol, volumeTotalBytes));
            }
        } else if (vol.getType() == VolumeInfo.TYPE_PUBLIC || vol.getType() == VolumeInfo.TYPE_STUB) {
            mExternalCategory.addPreference(new StorageVolumePreference(context, vol, 0));
        }
    }
    // Show missing private volumes
    final List<VolumeRecord> recs = mStorageManager.getVolumeRecords();
    for (VolumeRecord rec : recs) {
        if (rec.getType() == VolumeInfo.TYPE_PRIVATE && mStorageManager.findVolumeByUuid(rec.getFsUuid()) == null) {
            // TODO: add actual storage type to record
            final Preference pref = new Preference(context);
            pref.setKey(rec.getFsUuid());
            pref.setTitle(rec.getNickname());
            pref.setSummary(com.android.internal.R.string.ext_media_status_missing);
            pref.setIcon(R.drawable.ic_sim_sd);
            mInternalCategory.addPreference(pref);
        }
    }
    // Show unsupported disks to give a chance to init
    final List<DiskInfo> disks = mStorageManager.getDisks();
    for (DiskInfo disk : disks) {
        if (disk.volumeCount == 0 && disk.size > 0) {
            final Preference pref = new Preference(context);
            pref.setKey(disk.getId());
            pref.setTitle(disk.getDescription());
            pref.setSummary(com.android.internal.R.string.ext_media_status_unsupported);
            pref.setIcon(R.drawable.ic_sim_sd);
            mExternalCategory.addPreference(pref);
        }
    }
    final BytesResult result = Formatter.formatBytes(getResources(), privateUsedBytes, 0);
    mInternalSummary.setTitle(TextUtils.expandTemplate(getText(R.string.storage_size_large), result.value, result.units));
    mInternalSummary.setSummary(getString(R.string.storage_volume_used_total, Formatter.formatFileSize(context, privateTotalBytes)));
    if (mInternalCategory.getPreferenceCount() > 0) {
        getPreferenceScreen().addPreference(mInternalCategory);
    }
    if (mExternalCategory.getPreferenceCount() > 0) {
        getPreferenceScreen().addPreference(mExternalCategory);
    }
    if (mInternalCategory.getPreferenceCount() == 2 && mExternalCategory.getPreferenceCount() == 0) {
        // Only showing primary internal storage, so just shortcut
        if (!mHasLaunchedPrivateVolumeSettings) {
            mHasLaunchedPrivateVolumeSettings = true;
            final Bundle args = new Bundle();
            args.putString(VolumeInfo.EXTRA_VOLUME_ID, VolumeInfo.ID_PRIVATE_INTERNAL);
            new SubSettingLauncher(getActivity()).setDestination(StorageDashboardFragment.class.getName()).setArguments(args).setTitleRes(R.string.storage_settings).setSourceMetricsCategory(getMetricsCategory()).launch();
            finish();
        }
    }
}
Also used : Context(android.content.Context) PrivateStorageInfo(com.android.settingslib.deviceinfo.PrivateStorageInfo) Bundle(android.os.Bundle) DiskInfo(android.os.storage.DiskInfo) VolumeInfo(android.os.storage.VolumeInfo) BytesResult(android.text.format.Formatter.BytesResult) VolumeRecord(android.os.storage.VolumeRecord) Preference(androidx.preference.Preference) SubSettingLauncher(com.android.settings.core.SubSettingLauncher) StorageManagerVolumeProvider(com.android.settingslib.deviceinfo.StorageManagerVolumeProvider)

Example 43 with PrivateStorageInfo

use of com.android.settingslib.deviceinfo.PrivateStorageInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class TopLevelStoragePreferenceController method refreshSummary.

@Override
protected void refreshSummary(Preference preference) {
    if (preference == null) {
        return;
    }
    ThreadUtils.postOnBackgroundThread(() -> {
        final NumberFormat percentageFormat = NumberFormat.getPercentInstance();
        final PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(mStorageManagerVolumeProvider);
        final double privateUsedBytes = info.totalBytes - info.freeBytes;
        ThreadUtils.postOnMainThread(() -> {
            preference.setSummary(mContext.getString(R.string.storage_summary, percentageFormat.format(privateUsedBytes / info.totalBytes), Formatter.formatFileSize(mContext, info.freeBytes)));
        });
    });
}
Also used : PrivateStorageInfo(com.android.settingslib.deviceinfo.PrivateStorageInfo) NumberFormat(java.text.NumberFormat)

Example 44 with PrivateStorageInfo

use of com.android.settingslib.deviceinfo.PrivateStorageInfo in project android_packages_apps_Settings by omnirom.

the class VolumeSizesLoaderTest method getVolumeSize_getsValidSizes.

@Test
public void getVolumeSize_getsValidSizes() throws Exception {
    VolumeInfo info = mock(VolumeInfo.class);
    StorageVolumeProvider storageVolumeProvider = mock(StorageVolumeProvider.class);
    when(storageVolumeProvider.getTotalBytes(any(), any())).thenReturn(10000L);
    when(storageVolumeProvider.getFreeBytes(any(), any())).thenReturn(1000L);
    PrivateStorageInfo storageInfo = VolumeSizesLoader.getVolumeSize(storageVolumeProvider, null, info);
    assertThat(storageInfo.freeBytes).isEqualTo(1000L);
    assertThat(storageInfo.totalBytes).isEqualTo(10000L);
}
Also used : PrivateStorageInfo(com.android.settingslib.deviceinfo.PrivateStorageInfo) StorageVolumeProvider(com.android.settingslib.deviceinfo.StorageVolumeProvider) VolumeInfo(android.os.storage.VolumeInfo) Test(org.junit.Test)

Example 45 with PrivateStorageInfo

use of com.android.settingslib.deviceinfo.PrivateStorageInfo in project android_packages_apps_Settings by omnirom.

the class LowStorageSliceTest method getSlice_storageFree_shouldHaveErrorHint.

@Test
@Config(shadows = ShadowPrivateStorageInfo.class)
public void getSlice_storageFree_shouldHaveErrorHint() {
    ShadowPrivateStorageInfo.setPrivateStorageInfo(new PrivateStorageInfo(100L, 100L));
    final Slice slice = mLowStorageSlice.getSlice();
    assertThat(slice.hasHint(HINT_ERROR)).isTrue();
}
Also used : PrivateStorageInfo(com.android.settingslib.deviceinfo.PrivateStorageInfo) ShadowPrivateStorageInfo(com.android.settings.testutils.shadow.ShadowPrivateStorageInfo) Slice(androidx.slice.Slice) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

PrivateStorageInfo (com.android.settingslib.deviceinfo.PrivateStorageInfo)99 Test (org.junit.Test)86 View (android.view.View)21 RecyclerView (android.support.v7.widget.RecyclerView)15 CachedStorageValuesHelper (com.android.settings.deviceinfo.storage.CachedStorageValuesHelper)14 Slice (androidx.slice.Slice)9 VolumeInfo (android.os.storage.VolumeInfo)8 Config (org.robolectric.annotation.Config)8 SparseArray (android.util.SparseArray)7 StorageStatsSource (com.android.settingslib.applications.StorageStatsSource)7 StorageVolumeProvider (com.android.settingslib.deviceinfo.StorageVolumeProvider)7 VisibleForTesting (android.support.annotation.VisibleForTesting)6 RecyclerView (androidx.recyclerview.widget.RecyclerView)6 SliceMetadata (androidx.slice.SliceMetadata)5 IconCompat (androidx.core.graphics.drawable.IconCompat)4 ShadowPrivateStorageInfo (com.android.settings.testutils.shadow.ShadowPrivateStorageInfo)4 ListBuilder (androidx.slice.builders.ListBuilder)3 StorageManagerVolumeProvider (com.android.settingslib.deviceinfo.StorageManagerVolumeProvider)3 VisibleForTesting (androidx.annotation.VisibleForTesting)2 NumberFormat (java.text.NumberFormat)2