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

Commit 1ec22035 authored by Ioana Alexandru's avatar Ioana Alexandru Committed by Android (Google) Code Review
Browse files

Merge changes from topics "aioana_icon_resId", "aioana_zenmodeinteractor_iconcopy" into main

* changes:
  Make ZenModeInteractor#getModeIcon return an Icon with a drawable copy
  Make Icon.Loaded take a packageName
parents feb597e0 66125dac
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -123,7 +123,7 @@ fun PinPad(viewModel: PinBouncerViewModel, verticalSpacing: Dp, modifier: Modifi
        ActionButton(
            icon =
                Icon.Resource(
                    res =
                    resId =
                        if (backspaceButtonAppearance == ActionButtonAppearance.Shown) {
                            R.drawable.pin_bouncer_delete_outline
                        } else {
@@ -153,7 +153,7 @@ fun PinPad(viewModel: PinBouncerViewModel, verticalSpacing: Dp, modifier: Modifi
        ActionButton(
            icon =
                Icon.Resource(
                    res = R.drawable.pin_bouncer_confirm,
                    resId = R.drawable.pin_bouncer_confirm,
                    contentDescription =
                        ContentDescription.Resource(R.string.keyboardview_keycode_enter),
                ),
+2 −2
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ fun Icon(icon: Icon, modifier: Modifier = Modifier, tint: Color = LocalContentCo
            Icon(rememberDrawablePainter(icon.drawable), contentDescription, modifier, tint)
        }
        is Icon.Resource -> {
            Icon(painterResource(icon.res), contentDescription, modifier, tint)
            Icon(painterResource(icon.resId), contentDescription, modifier, tint)
        }
    }
}
@@ -71,7 +71,7 @@ fun Icon(icon: Icon, tint: (() -> Color)?, modifier: Modifier = Modifier) {
        }
        is Icon.Resource -> {
            Icon(
                painterResource(icon.res),
                painterResource(icon.resId),
                tint ?: { localContentColor },
                contentDescription,
                modifier,
+1 −1
Original line number Diff line number Diff line
@@ -413,7 +413,7 @@ private fun FooterIcon(icon: Icon, modifier: Modifier = Modifier, tint: Color) {
        is Icon.Loaded -> {
            Icon(icon.drawable.toBitmap().asImageBitmap(), contentDescription, modifier, tint)
        }
        is Icon.Resource -> Icon(painterResource(icon.res), contentDescription, modifier, tint)
        is Icon.Resource -> Icon(painterResource(icon.resId), contentDescription, modifier, tint)
    }
}

+87 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.common.shared.model

import android.graphics.drawable.TestStubDrawable
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

@SmallTest
@RunWith(AndroidJUnit4::class)
class IconTest : SysuiTestCase() {
    @Test
    fun loadedIcons_withSameDrawableAndDescription_areEqual() {
        val drawable = TestStubDrawable("icon")
        val icon1 = Icon.Loaded(drawable, ContentDescription.Loaded("description"))
        val icon2 = Icon.Loaded(drawable, ContentDescription.Loaded("description"))

        assertThat(icon1 == icon2).isTrue()
        assertThat(icon1.hashCode()).isEqualTo(icon2.hashCode())
    }

    @Test
    fun loadedIcons_withSameDrawableAndDifferentDescription_areNotEqual() {
        val drawable = TestStubDrawable("icon")
        val icon1 = Icon.Loaded(drawable, ContentDescription.Loaded("description"))
        val icon2 = Icon.Loaded(drawable, ContentDescription.Loaded("different description"))

        assertThat(icon1 == icon2).isFalse()
        assertThat(icon1.hashCode()).isNotEqualTo(icon2.hashCode())
    }

    @Test
    fun loadedIcons_withDifferentDrawables_areNotEqual() {
        val icon1 = Icon.Loaded(TestStubDrawable("icon1"), null)
        val icon2 = Icon.Loaded(TestStubDrawable("icon2"), null)

        assertThat(icon1 == icon2).isFalse()
        assertThat(icon1.hashCode()).isNotEqualTo(icon2.hashCode())
    }

    @Test
    fun loadedIcons_withSameResIdAndDescription_areEqual() {
        val icon1 = Icon.Loaded(TestStubDrawable("icon1"), null, 123)
        val icon2 = Icon.Loaded(TestStubDrawable("icon2"), null, 123)

        assertThat(icon1 == icon2).isTrue()
        assertThat(icon1.hashCode()).isEqualTo(icon2.hashCode())
    }

    @Test
    fun loadedIcons_withSameResIdAndDifferentPackage_areNotEqual() {
        val drawable = TestStubDrawable("icon")
        val icon1 = Icon.Loaded(drawable, null, 123, "package1")
        val icon2 = Icon.Loaded(drawable, null, 123, "package2")

        assertThat(icon1 == icon2).isFalse()
        assertThat(icon1.hashCode()).isNotEqualTo(icon2.hashCode())
    }

    @Test
    fun loadedIcons_withOneNullResId_areNotEqual() {
        val drawable = TestStubDrawable("icon")
        val icon1 = Icon.Loaded(drawable, null, 123)
        val icon2 = Icon.Loaded(drawable, null)

        assertThat(icon1 == icon2).isFalse()
        assertThat(icon1.hashCode()).isNotEqualTo(icon2.hashCode())
    }
}
+6 −6
Original line number Diff line number Diff line
@@ -20,9 +20,9 @@ package com.android.systemui.keyguard.data.quickaffordance
import android.content.Context
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.res.R
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.keyguard.shared.quickaffordance.ActivationState
import com.android.systemui.res.R
import com.android.systemui.statusbar.policy.FlashlightController
import com.android.systemui.utils.leaks.FakeFlashlightController
import com.android.systemui.utils.leaks.LeakCheckedTest
@@ -75,7 +75,7 @@ class FlashlightQuickAffordanceConfigTest : LeakCheckedTest() {
            R.drawable.qs_flashlight_icon_on,
            ((lastValue as KeyguardQuickAffordanceConfig.LockScreenState.Visible).icon
                    as? Icon.Resource)
                ?.res
                ?.resId,
        )
        job.cancel()
    }
@@ -98,7 +98,7 @@ class FlashlightQuickAffordanceConfigTest : LeakCheckedTest() {
            R.drawable.qs_flashlight_icon_off,
            ((lastValue as KeyguardQuickAffordanceConfig.LockScreenState.Visible).icon
                    as? Icon.Resource)
                ?.res
                ?.resId,
        )
        job.cancel()
    }
@@ -121,7 +121,7 @@ class FlashlightQuickAffordanceConfigTest : LeakCheckedTest() {
            R.drawable.qs_flashlight_icon_off,
            ((lastValue as KeyguardQuickAffordanceConfig.LockScreenState.Visible).icon
                    as? Icon.Resource)
                ?.res
                ?.resId,
        )
        job.cancel()
    }
@@ -161,7 +161,7 @@ class FlashlightQuickAffordanceConfigTest : LeakCheckedTest() {
            (lastValue as KeyguardQuickAffordanceConfig.LockScreenState.Visible).activationState
                is ActivationState.Active
        )
        assertEquals(R.drawable.qs_flashlight_icon_on, (lastValue.icon as? Icon.Resource)?.res)
        assertEquals(R.drawable.qs_flashlight_icon_on, (lastValue.icon as? Icon.Resource)?.resId)
        job.cancel()
    }

@@ -183,7 +183,7 @@ class FlashlightQuickAffordanceConfigTest : LeakCheckedTest() {
            (lastValue as KeyguardQuickAffordanceConfig.LockScreenState.Visible).activationState
                is ActivationState.Inactive
        )
        assertEquals(R.drawable.qs_flashlight_icon_off, (lastValue.icon as? Icon.Resource)?.res)
        assertEquals(R.drawable.qs_flashlight_icon_off, (lastValue.icon as? Icon.Resource)?.resId)
        job.cancel()
    }

Loading