Loading packages/SystemUI/src/com/android/systemui/util/Utils.java +12 −5 Original line number Original line Diff line number Diff line Loading @@ -21,9 +21,7 @@ import android.content.Context; import android.content.Intent; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.PackageManager; import android.content.res.Resources; import android.content.res.Resources; import android.content.res.TypedArray; import android.provider.Settings; import android.provider.Settings; import android.view.ContextThemeWrapper; import android.view.DisplayCutout; import android.view.DisplayCutout; import com.android.internal.policy.SystemBarUtils; import com.android.internal.policy.SystemBarUtils; Loading @@ -35,6 +33,8 @@ import java.util.function.Consumer; public class Utils { public class Utils { private static Boolean sUseQsMediaPlayer = null; /** /** * Allows lambda iteration over a list. It is done in reverse order so it is safe * Allows lambda iteration over a list. It is done in reverse order so it is safe * to add or remove items during the iteration. Skips over null items. * to add or remove items during the iteration. Skips over null items. Loading Loading @@ -81,9 +81,16 @@ public class Utils { * Off by default, but can be disabled by setting to 0 * Off by default, but can be disabled by setting to 0 */ */ public static boolean useQsMediaPlayer(Context context) { public static boolean useQsMediaPlayer(Context context) { // TODO(b/192412820): Replace SHOW_MEDIA_ON_QUICK_SETTINGS with compile-time value // Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS can't be toggled at runtime, so simply // cache the first result we fetch and use that going forward. Do this to avoid unnecessary // binder calls which may happen on the critical path. if (sUseQsMediaPlayer == null) { int flag = Settings.Global.getInt(context.getContentResolver(), int flag = Settings.Global.getInt(context.getContentResolver(), Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 1); Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 1); return flag > 0; sUseQsMediaPlayer = flag > 0; } return sUseQsMediaPlayer; } } /** /** Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationSectionsFeatureManagerTest.kt +13 −5 Original line number Original line Diff line number Diff line Loading @@ -21,10 +21,13 @@ import android.provider.Settings import android.testing.AndroidTestingRunner import android.testing.AndroidTestingRunner import androidx.test.filters.SmallTest import androidx.test.filters.SmallTest import com.android.dx.mockito.inline.extended.ExtendedMockito import com.android.internal.config.sysui.SystemUiDeviceConfigFlags.NOTIFICATIONS_USE_PEOPLE_FILTERING import com.android.internal.config.sysui.SystemUiDeviceConfigFlags.NOTIFICATIONS_USE_PEOPLE_FILTERING import com.android.systemui.SysuiTestCase import com.android.systemui.SysuiTestCase import com.android.systemui.util.DeviceConfigProxyFake import com.android.systemui.util.DeviceConfigProxyFake import com.android.systemui.util.Utils import com.android.systemui.util.mockito.any import org.junit.After import org.junit.After import org.junit.Assert.assertFalse import org.junit.Assert.assertFalse Loading @@ -32,28 +35,33 @@ import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Before import org.junit.Test import org.junit.Test import org.junit.runner.RunWith import org.junit.runner.RunWith import org.mockito.Mockito.`when` import org.mockito.MockitoSession import org.mockito.quality.Strictness @RunWith(AndroidTestingRunner::class) @RunWith(AndroidTestingRunner::class) @SmallTest @SmallTest class NotificationSectionsFeatureManagerTest : SysuiTestCase() { class NotificationSectionsFeatureManagerTest : SysuiTestCase() { var manager: NotificationSectionsFeatureManager? = null var manager: NotificationSectionsFeatureManager? = null val proxyFake = DeviceConfigProxyFake() val proxyFake = DeviceConfigProxyFake() var originalQsMediaPlayer: Int = 0 private lateinit var staticMockSession: MockitoSession @Before @Before public fun setup() { public fun setup() { manager = NotificationSectionsFeatureManager(proxyFake, mContext) manager = NotificationSectionsFeatureManager(proxyFake, mContext) manager!!.clearCache() manager!!.clearCache() originalQsMediaPlayer = Settings.Global.getInt(context.getContentResolver(), staticMockSession = ExtendedMockito.mockitoSession() Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 1) .mockStatic<Utils>(Utils::class.java) .strictness(Strictness.LENIENT) .startMocking() `when`(Utils.useQsMediaPlayer(any())).thenReturn(false) Settings.Global.putInt(context.getContentResolver(), Settings.Global.putInt(context.getContentResolver(), Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 0) Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 0) } } @After @After public fun teardown() { public fun teardown() { Settings.Global.putInt(context.getContentResolver(), staticMockSession.finishMocking() Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, originalQsMediaPlayer) } } @Test @Test Loading Loading
packages/SystemUI/src/com/android/systemui/util/Utils.java +12 −5 Original line number Original line Diff line number Diff line Loading @@ -21,9 +21,7 @@ import android.content.Context; import android.content.Intent; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.PackageManager; import android.content.res.Resources; import android.content.res.Resources; import android.content.res.TypedArray; import android.provider.Settings; import android.provider.Settings; import android.view.ContextThemeWrapper; import android.view.DisplayCutout; import android.view.DisplayCutout; import com.android.internal.policy.SystemBarUtils; import com.android.internal.policy.SystemBarUtils; Loading @@ -35,6 +33,8 @@ import java.util.function.Consumer; public class Utils { public class Utils { private static Boolean sUseQsMediaPlayer = null; /** /** * Allows lambda iteration over a list. It is done in reverse order so it is safe * Allows lambda iteration over a list. It is done in reverse order so it is safe * to add or remove items during the iteration. Skips over null items. * to add or remove items during the iteration. Skips over null items. Loading Loading @@ -81,9 +81,16 @@ public class Utils { * Off by default, but can be disabled by setting to 0 * Off by default, but can be disabled by setting to 0 */ */ public static boolean useQsMediaPlayer(Context context) { public static boolean useQsMediaPlayer(Context context) { // TODO(b/192412820): Replace SHOW_MEDIA_ON_QUICK_SETTINGS with compile-time value // Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS can't be toggled at runtime, so simply // cache the first result we fetch and use that going forward. Do this to avoid unnecessary // binder calls which may happen on the critical path. if (sUseQsMediaPlayer == null) { int flag = Settings.Global.getInt(context.getContentResolver(), int flag = Settings.Global.getInt(context.getContentResolver(), Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 1); Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 1); return flag > 0; sUseQsMediaPlayer = flag > 0; } return sUseQsMediaPlayer; } } /** /** Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationSectionsFeatureManagerTest.kt +13 −5 Original line number Original line Diff line number Diff line Loading @@ -21,10 +21,13 @@ import android.provider.Settings import android.testing.AndroidTestingRunner import android.testing.AndroidTestingRunner import androidx.test.filters.SmallTest import androidx.test.filters.SmallTest import com.android.dx.mockito.inline.extended.ExtendedMockito import com.android.internal.config.sysui.SystemUiDeviceConfigFlags.NOTIFICATIONS_USE_PEOPLE_FILTERING import com.android.internal.config.sysui.SystemUiDeviceConfigFlags.NOTIFICATIONS_USE_PEOPLE_FILTERING import com.android.systemui.SysuiTestCase import com.android.systemui.SysuiTestCase import com.android.systemui.util.DeviceConfigProxyFake import com.android.systemui.util.DeviceConfigProxyFake import com.android.systemui.util.Utils import com.android.systemui.util.mockito.any import org.junit.After import org.junit.After import org.junit.Assert.assertFalse import org.junit.Assert.assertFalse Loading @@ -32,28 +35,33 @@ import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Before import org.junit.Test import org.junit.Test import org.junit.runner.RunWith import org.junit.runner.RunWith import org.mockito.Mockito.`when` import org.mockito.MockitoSession import org.mockito.quality.Strictness @RunWith(AndroidTestingRunner::class) @RunWith(AndroidTestingRunner::class) @SmallTest @SmallTest class NotificationSectionsFeatureManagerTest : SysuiTestCase() { class NotificationSectionsFeatureManagerTest : SysuiTestCase() { var manager: NotificationSectionsFeatureManager? = null var manager: NotificationSectionsFeatureManager? = null val proxyFake = DeviceConfigProxyFake() val proxyFake = DeviceConfigProxyFake() var originalQsMediaPlayer: Int = 0 private lateinit var staticMockSession: MockitoSession @Before @Before public fun setup() { public fun setup() { manager = NotificationSectionsFeatureManager(proxyFake, mContext) manager = NotificationSectionsFeatureManager(proxyFake, mContext) manager!!.clearCache() manager!!.clearCache() originalQsMediaPlayer = Settings.Global.getInt(context.getContentResolver(), staticMockSession = ExtendedMockito.mockitoSession() Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 1) .mockStatic<Utils>(Utils::class.java) .strictness(Strictness.LENIENT) .startMocking() `when`(Utils.useQsMediaPlayer(any())).thenReturn(false) Settings.Global.putInt(context.getContentResolver(), Settings.Global.putInt(context.getContentResolver(), Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 0) Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 0) } } @After @After public fun teardown() { public fun teardown() { Settings.Global.putInt(context.getContentResolver(), staticMockSession.finishMocking() Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, originalQsMediaPlayer) } } @Test @Test Loading