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

Commit 25b62b11 authored by Daniel Nishi's avatar Daniel Nishi Committed by android-build-merger
Browse files

Merge "Don't crash in SecondaryUserController." into oc-dev am: aa3685fe

am: 129eb177

Change-Id: Iae6c55f2e6f26dc6b147d70c070109398c528636
parents c2e16ca9 129eb177
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ public class SecondaryUserController extends PreferenceController

    private @NonNull UserInfo mUser;
    private @Nullable StorageItemPreference mStoragePreference;
    private Drawable mUserIcon;
    private long mSize;
    private long mTotalSizeBytes;

@@ -113,6 +114,7 @@ public class SecondaryUserController extends PreferenceController

            group.setVisible(true);
            group.addPreference(mStoragePreference);
            maybeSetIcon();
        }
    }

@@ -163,9 +165,13 @@ public class SecondaryUserController extends PreferenceController

    @Override
    public void handleUserIcons(SparseArray<Drawable> fetchedIcons) {
        Drawable userIcon = fetchedIcons.get(mUser.id);
        if (userIcon != null) {
            mStoragePreference.setIcon(userIcon);
        mUserIcon = fetchedIcons.get(mUser.id);
        maybeSetIcon();
    }

    private void maybeSetIcon() {
        if (mUserIcon != null && mStoragePreference != null) {
            mStoragePreference.setIcon(mUserIcon);
        }
    }

+16 −0
Original line number Diff line number Diff line
@@ -211,4 +211,20 @@ public class SecondaryUserControllerTest {
        Preference preference = argumentCaptor.getValue();
        assertThat(preference.getIcon()).isEqualTo(drawable);
    }

    @Test
    public void setIcon_doesntNpeOnNullPreference() throws Exception {
        SparseArray<Drawable> icons = new SparseArray<>();
        Bitmap userBitmap =
                BitmapFactory.decodeResource(
                        RuntimeEnvironment.application.getResources(), R.drawable.home);
        UserIconDrawable drawable = new UserIconDrawable(100 /* size */).setIcon(userBitmap).bake();
        icons.put(10, drawable);
        mPrimaryUser.name = TEST_NAME;
        mPrimaryUser.id = 10;

        mController.handleUserIcons(icons);

        // Doesn't crash
    }
}