Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e6389f63 authored by Arc Wang's avatar Arc Wang Committed by Android (Google) Code Review
Browse files

Merge "Show USB flash drive in storage spinner when it's unmounted" into tm-dev

parents a264bc20 f81a4817
Loading
Loading
Loading
Loading
+14 −15
Original line number Original line Diff line number Diff line
@@ -84,10 +84,19 @@ public class ProfileSelectStorageFragment extends ProfileSelectFragment {
            }
            }


            final StorageEntry changedStorageEntry = new StorageEntry(getContext(), volumeInfo);
            final StorageEntry changedStorageEntry = new StorageEntry(getContext(), volumeInfo);
            switch (volumeInfo.getState()) {
            final int volumeState = volumeInfo.getState();
            switch (volumeState) {
                case VolumeInfo.STATE_REMOVED:
                case VolumeInfo.STATE_BAD_REMOVAL:
                    // Remove removed storage from list and don't show it on spinner.
                    if (!mStorageEntries.remove(changedStorageEntry)) {
                        break;
                    }
                case VolumeInfo.STATE_MOUNTED:
                case VolumeInfo.STATE_MOUNTED:
                case VolumeInfo.STATE_MOUNTED_READ_ONLY:
                case VolumeInfo.STATE_MOUNTED_READ_ONLY:
                case VolumeInfo.STATE_UNMOUNTABLE:
                case VolumeInfo.STATE_UNMOUNTABLE:
                case VolumeInfo.STATE_UNMOUNTED:
                case VolumeInfo.STATE_EJECTING:
                    // Add mounted or unmountable storage in the list and show it on spinner.
                    // Add mounted or unmountable storage in the list and show it on spinner.
                    // Unmountable storages are the storages which has a problem format and android
                    // Unmountable storages are the storages which has a problem format and android
                    // is not able to mount it automatically.
                    // is not able to mount it automatically.
@@ -95,24 +104,14 @@ public class ProfileSelectStorageFragment extends ProfileSelectFragment {
                    mStorageEntries.removeIf(storageEntry -> {
                    mStorageEntries.removeIf(storageEntry -> {
                        return storageEntry.equals(changedStorageEntry);
                        return storageEntry.equals(changedStorageEntry);
                    });
                    });
                    if (volumeState != VolumeInfo.STATE_REMOVED
                            && volumeState != VolumeInfo.STATE_BAD_REMOVAL) {
                        mStorageEntries.add(changedStorageEntry);
                        mStorageEntries.add(changedStorageEntry);
                    if (changedStorageEntry.equals(mSelectedStorageEntry)) {
                        mSelectedStorageEntry = changedStorageEntry;
                    }
                    }
                    refreshUi();
                    break;
                case VolumeInfo.STATE_REMOVED:
                case VolumeInfo.STATE_UNMOUNTED:
                case VolumeInfo.STATE_BAD_REMOVAL:
                case VolumeInfo.STATE_EJECTING:
                    // Remove removed storage from list and don't show it on spinner.
                    if (mStorageEntries.remove(changedStorageEntry)) {
                    if (changedStorageEntry.equals(mSelectedStorageEntry)) {
                    if (changedStorageEntry.equals(mSelectedStorageEntry)) {
                            mSelectedStorageEntry =
                        mSelectedStorageEntry = changedStorageEntry;
                                    StorageEntry.getDefaultInternalStorageEntry(getContext());
                    }
                    }
                    refreshUi();
                    refreshUi();
                    }
                    break;
                    break;
                default:
                default:
                    // Do nothing.
                    // Do nothing.
+14 −15
Original line number Original line Diff line number Diff line
@@ -115,10 +115,19 @@ public class StorageDashboardFragment extends DashboardFragment
            }
            }


            final StorageEntry changedStorageEntry = new StorageEntry(getContext(), volumeInfo);
            final StorageEntry changedStorageEntry = new StorageEntry(getContext(), volumeInfo);
            switch (volumeInfo.getState()) {
            final int volumeState = volumeInfo.getState();
            switch (volumeState) {
                case VolumeInfo.STATE_REMOVED:
                case VolumeInfo.STATE_BAD_REMOVAL:
                    // Remove removed storage from list and don't show it on spinner.
                    if (!mStorageEntries.remove(changedStorageEntry)) {
                        break;
                    }
                case VolumeInfo.STATE_MOUNTED:
                case VolumeInfo.STATE_MOUNTED:
                case VolumeInfo.STATE_MOUNTED_READ_ONLY:
                case VolumeInfo.STATE_MOUNTED_READ_ONLY:
                case VolumeInfo.STATE_UNMOUNTABLE:
                case VolumeInfo.STATE_UNMOUNTABLE:
                case VolumeInfo.STATE_UNMOUNTED:
                case VolumeInfo.STATE_EJECTING:
                    // Add mounted or unmountable storage in the list and show it on spinner.
                    // Add mounted or unmountable storage in the list and show it on spinner.
                    // Unmountable storages are the storages which has a problem format and android
                    // Unmountable storages are the storages which has a problem format and android
                    // is not able to mount it automatically.
                    // is not able to mount it automatically.
@@ -126,24 +135,14 @@ public class StorageDashboardFragment extends DashboardFragment
                    mStorageEntries.removeIf(storageEntry -> {
                    mStorageEntries.removeIf(storageEntry -> {
                        return storageEntry.equals(changedStorageEntry);
                        return storageEntry.equals(changedStorageEntry);
                    });
                    });
                    if (volumeState != VolumeInfo.STATE_REMOVED
                            && volumeState != VolumeInfo.STATE_BAD_REMOVAL) {
                        mStorageEntries.add(changedStorageEntry);
                        mStorageEntries.add(changedStorageEntry);
                    if (changedStorageEntry.equals(mSelectedStorageEntry)) {
                        mSelectedStorageEntry = changedStorageEntry;
                    }
                    }
                    refreshUi();
                    break;
                case VolumeInfo.STATE_REMOVED:
                case VolumeInfo.STATE_UNMOUNTED:
                case VolumeInfo.STATE_BAD_REMOVAL:
                case VolumeInfo.STATE_EJECTING:
                    // Remove removed storage from list and don't show it on spinner.
                    if (mStorageEntries.remove(changedStorageEntry)) {
                    if (changedStorageEntry.equals(mSelectedStorageEntry)) {
                    if (changedStorageEntry.equals(mSelectedStorageEntry)) {
                            mSelectedStorageEntry =
                        mSelectedStorageEntry = changedStorageEntry;
                                    StorageEntry.getDefaultInternalStorageEntry(getContext());
                    }
                    }
                    refreshUi();
                    refreshUi();
                    }
                    break;
                    break;
                default:
                default:
                    // Do nothing.
                    // Do nothing.
+16 −0
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import android.os.UserManager;
import android.os.storage.DiskInfo;
import android.os.storage.DiskInfo;
import android.os.storage.StorageManager;
import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.os.storage.VolumeInfo;
import android.util.Log;
import android.view.Menu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MenuItem;
@@ -53,6 +54,8 @@ import java.util.Objects;
public class VolumeOptionMenuController implements LifecycleObserver, OnCreateOptionsMenu,
public class VolumeOptionMenuController implements LifecycleObserver, OnCreateOptionsMenu,
        OnPrepareOptionsMenu, OnOptionsItemSelected {
        OnPrepareOptionsMenu, OnOptionsItemSelected {


    private static final String TAG = "VolumeOptionMenuController";

    @VisibleForTesting
    @VisibleForTesting
    MenuItem mRename;
    MenuItem mRename;
    @VisibleForTesting
    @VisibleForTesting
@@ -103,6 +106,17 @@ public class VolumeOptionMenuController implements LifecycleObserver, OnCreateOp
        mFree = menu.findItem(R.id.storage_free);
        mFree = menu.findItem(R.id.storage_free);
        mForget = menu.findItem(R.id.storage_forget);
        mForget = menu.findItem(R.id.storage_forget);


        updateOptionsMenu();
    }

    private void updateOptionsMenu() {
        if (mRename == null || mMount == null || mUnmount == null || mFormat == null
                || mFormatAsPortable == null || mFormatAsInternal == null || mMigrate == null
                || mFree == null || mForget == null) {
            Log.d(TAG, "Menu items are not available");
            return;
        }

        mRename.setVisible(false);
        mRename.setVisible(false);
        mMount.setVisible(false);
        mMount.setVisible(false);
        mUnmount.setVisible(false);
        mUnmount.setVisible(false);
@@ -252,5 +266,7 @@ public class VolumeOptionMenuController implements LifecycleObserver, OnCreateOp


    public void setSelectedStorageEntry(StorageEntry storageEntry) {
    public void setSelectedStorageEntry(StorageEntry storageEntry) {
        mStorageEntry = storageEntry;
        mStorageEntry = storageEntry;

        updateOptionsMenu();
    }
    }
}
}