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

Commit 83817552 authored by Daniel Nishi's avatar Daniel Nishi
Browse files

Fix Settings crash in Storage settings.

If you tap aggressively before the fragment has fully initialized, it
was possible to NPE. This null-checks to avoid this.

Change-Id: I3488245d230cf1e16b23e34614c8e6b43ea14ff1
Fixes: 37945253
Test: Robotest
parent 83392792
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -300,6 +300,10 @@ public class StorageItemPreferenceController extends PreferenceController {
    }

    private Intent getAudioIntent() {
        if (mVolume == null) {
            return null;
        }

        Bundle args = new Bundle();
        args.putString(ManageApplications.EXTRA_CLASSNAME,
                Settings.StorageUseActivity.class.getName());
@@ -312,6 +316,10 @@ public class StorageItemPreferenceController extends PreferenceController {
    }

    private Intent getAppsIntent() {
        if (mVolume == null) {
            return null;
        }

        Bundle args = new Bundle();
        args.putString(ManageApplications.EXTRA_CLASSNAME,
                Settings.StorageUseActivity.class.getName());
+16 −0
Original line number Diff line number Diff line
@@ -146,6 +146,14 @@ public class StorageItemPreferenceControllerTest {
                ManageApplications.STORAGE_TYPE_MUSIC);
    }

    @Test
    public void handlePreferenceTreeClick_tappingAudioWhileUninitializedDoesntCrash() {
        mController.setVolume(null);

        mPreference.setKey("pref_music_audio");
        mController.handlePreferenceTreeClick(mPreference);
    }

    @Test
    public void testClickApps() {
        mPreference.setKey("pref_other_apps");
@@ -164,6 +172,14 @@ public class StorageItemPreferenceControllerTest {
                .isEqualTo(R.string.apps_storage);
    }

    @Test
    public void handlePreferenceTreeClick_tappingAppsWhileUninitializedDoesntCrash() {
        mController.setVolume(null);

        mPreference.setKey("pref_other_apps");
        mController.handlePreferenceTreeClick(mPreference);
    }

    @Test
    public void testClickFiles() {
        when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(mVolume);