diff --git a/packages/SettingsLib/src/com/android/settingslib/AccessibilityContentDescriptions.java b/packages/SettingsLib/src/com/android/settingslib/AccessibilityContentDescriptions.java index eff9e74e0e708..ee65ef4e92b63 100644 --- a/packages/SettingsLib/src/com/android/settingslib/AccessibilityContentDescriptions.java +++ b/packages/SettingsLib/src/com/android/settingslib/AccessibilityContentDescriptions.java @@ -22,8 +22,11 @@ package com.android.settingslib; public class AccessibilityContentDescriptions { private AccessibilityContentDescriptions() {} + + public static final int PHONE_SIGNAL_STRENGTH_NONE = R.string.accessibility_no_phone; + public static final int[] PHONE_SIGNAL_STRENGTH = { - R.string.accessibility_no_phone, + PHONE_SIGNAL_STRENGTH_NONE, R.string.accessibility_phone_one_bar, R.string.accessibility_phone_two_bars, R.string.accessibility_phone_three_bars, diff --git a/packages/SettingsLib/src/com/android/settingslib/MobileNetworkTypeIcon.kt b/packages/SettingsLib/src/com/android/settingslib/MobileNetworkTypeIcon.kt new file mode 100644 index 0000000000000..3daf8c20d2417 --- /dev/null +++ b/packages/SettingsLib/src/com/android/settingslib/MobileNetworkTypeIcon.kt @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2022 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.settingslib + +import androidx.annotation.DrawableRes +import androidx.annotation.StringRes + +/** + * A specification for the icon displaying the mobile network type -- 4G, 5G, LTE, etc. (aka "RAT + * icon" or "data type icon"). This is *not* the signal strength triangle. + * + * This is intended to eventually replace [SignalIcon.MobileIconGroup]. But for now, + * [MobileNetworkTypeIcons] just reads from the existing set of [SignalIcon.MobileIconGroup] + * instances to not duplicate data. + * + * TODO(b/238425913): Remove [SignalIcon.MobileIconGroup] and replace it with this class so that we + * don't need to fill in the superfluous fields from its parent [SignalIcon.IconGroup] class. Then + * this class can become either a sealed class or an enum with parameters. + */ +data class MobileNetworkTypeIcon( + /** A human-readable name for this network type, used for logging. */ + val name: String, + + /** The resource ID of the icon drawable to use. */ + @DrawableRes val iconResId: Int, + + /** The resource ID of the content description to use. */ + @StringRes val contentDescriptionResId: Int, +) diff --git a/packages/SettingsLib/src/com/android/settingslib/MobileNetworkTypeIcons.kt b/packages/SettingsLib/src/com/android/settingslib/MobileNetworkTypeIcons.kt new file mode 100644 index 0000000000000..2c5ee89027665 --- /dev/null +++ b/packages/SettingsLib/src/com/android/settingslib/MobileNetworkTypeIcons.kt @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2022 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.settingslib + +import com.android.settingslib.mobile.TelephonyIcons.ICON_NAME_TO_ICON + +/** + * A utility class to fetch instances of [MobileNetworkTypeIcon] given a + * [SignalIcon.MobileIconGroup]. + * + * Use [getNetworkTypeIcon] to fetch the instances. + */ +class MobileNetworkTypeIcons { + companion object { + /** + * A map from a [SignalIcon.MobileIconGroup.name] to an instance of [MobileNetworkTypeIcon], + * which is the preferred class going forward. + */ + private val MOBILE_NETWORK_TYPE_ICONS: Map + + init { + // Build up the mapping from the old implementation to the new one. + val tempMap: MutableMap = mutableMapOf() + + ICON_NAME_TO_ICON.forEach { (_, mobileIconGroup) -> + tempMap[mobileIconGroup.name] = mobileIconGroup.toNetworkTypeIcon() + } + + MOBILE_NETWORK_TYPE_ICONS = tempMap + } + + /** + * A converter function between the old mobile network type icon implementation and the new + * one. Given an instance of the old class [mobileIconGroup], outputs an instance of the + * new class [MobileNetworkTypeIcon]. + */ + @JvmStatic + fun getNetworkTypeIcon( + mobileIconGroup: SignalIcon.MobileIconGroup + ): MobileNetworkTypeIcon { + return MOBILE_NETWORK_TYPE_ICONS[mobileIconGroup.name] + ?: mobileIconGroup.toNetworkTypeIcon() + } + + private fun SignalIcon.MobileIconGroup.toNetworkTypeIcon(): MobileNetworkTypeIcon { + return MobileNetworkTypeIcon( + name = this.name, + iconResId = this.dataType, + contentDescriptionResId = this.dataContentDescription + ) + } + } +} diff --git a/packages/SettingsLib/src/com/android/settingslib/SignalIcon.java b/packages/SettingsLib/src/com/android/settingslib/SignalIcon.java index 280e40726c031..6aaab3c564802 100644 --- a/packages/SettingsLib/src/com/android/settingslib/SignalIcon.java +++ b/packages/SettingsLib/src/com/android/settingslib/SignalIcon.java @@ -15,6 +15,9 @@ */ package com.android.settingslib; +import androidx.annotation.DrawableRes; +import androidx.annotation.StringRes; + /** * Icons for SysUI and Settings. */ @@ -66,34 +69,31 @@ public class SignalIcon { } /** - * Holds icons for a given MobileState. + * Holds RAT icons for a given MobileState. */ public static class MobileIconGroup extends IconGroup { - public final int dataContentDescription; // mContentDescriptionDataType - public final int dataType; + @StringRes public final int dataContentDescription; + @DrawableRes public final int dataType; public MobileIconGroup( String name, - int[][] sbIcons, - int[][] qsIcons, - int[] contentDesc, - int sbNullState, - int qsNullState, - int sbDiscState, - int qsDiscState, - int discContentDesc, int dataContentDesc, int dataType ) { super(name, - sbIcons, - qsIcons, - contentDesc, - sbNullState, - qsNullState, - sbDiscState, - qsDiscState, - discContentDesc); + // The rest of the values are the same for every type of MobileIconGroup, so + // just provide them here. + // TODO(b/238425913): Eventually replace with {@link MobileNetworkTypeIcon} so + // that we don't have to fill in these superfluous fields. + /* sbIcons= */ null, + /* qsIcons= */ null, + /* contentDesc= */ AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, + /* sbNullState= */ 0, + /* qsNullState= */ 0, + /* sbDiscState= */ 0, + /* qsDiscState= */ 0, + /* discContentDesc= */ + AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH_NONE); this.dataContentDescription = dataContentDesc; this.dataType = dataType; } diff --git a/packages/SettingsLib/src/com/android/settingslib/mobile/TelephonyIcons.java b/packages/SettingsLib/src/com/android/settingslib/mobile/TelephonyIcons.java index 23e0923d72805..094567c400a34 100644 --- a/packages/SettingsLib/src/com/android/settingslib/mobile/TelephonyIcons.java +++ b/packages/SettingsLib/src/com/android/settingslib/mobile/TelephonyIcons.java @@ -16,7 +16,6 @@ package com.android.settingslib.mobile; -import com.android.settingslib.AccessibilityContentDescriptions; import com.android.settingslib.R; import com.android.settingslib.SignalIcon.MobileIconGroup; @@ -49,297 +48,129 @@ public class TelephonyIcons { public static final MobileIconGroup CARRIER_NETWORK_CHANGE = new MobileIconGroup( "CARRIER_NETWORK_CHANGE", - null, - null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - 0, - 0, - 0, - 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], R.string.carrier_network_change_mode, - 0 + /* dataType= */ 0 ); public static final MobileIconGroup THREE_G = new MobileIconGroup( "3G", - null, - null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - 0, - 0, - 0, - 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], R.string.data_connection_3g, TelephonyIcons.ICON_3G ); public static final MobileIconGroup WFC = new MobileIconGroup( "WFC", - null, - null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - 0, - 0, - 0, - 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], - 0, - 0); + /* dataContentDescription= */ 0, + /* dataType= */ 0); public static final MobileIconGroup UNKNOWN = new MobileIconGroup( "Unknown", - null, - null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - 0, - 0, - 0, - 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], - 0, - 0); + /* dataContentDescription= */ 0, + /* dataType= */ 0); public static final MobileIconGroup E = new MobileIconGroup( "E", - null, - null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - 0, - 0, - 0, - 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], R.string.data_connection_edge, TelephonyIcons.ICON_E ); public static final MobileIconGroup ONE_X = new MobileIconGroup( "1X", - null, - null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - 0, - 0, - 0, - 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], R.string.data_connection_cdma, TelephonyIcons.ICON_1X ); public static final MobileIconGroup G = new MobileIconGroup( "G", - null, - null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - 0, - 0, - 0, - 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], R.string.data_connection_gprs, TelephonyIcons.ICON_G ); public static final MobileIconGroup H = new MobileIconGroup( "H", - null, - null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - 0, - 0, - 0, - 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], R.string.data_connection_3_5g, TelephonyIcons.ICON_H ); public static final MobileIconGroup H_PLUS = new MobileIconGroup( "H+", - null, - null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - 0, - 0, - 0, - 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], R.string.data_connection_3_5g_plus, TelephonyIcons.ICON_H_PLUS ); public static final MobileIconGroup FOUR_G = new MobileIconGroup( "4G", - null, - null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - 0, - 0, - 0, - 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], R.string.data_connection_4g, TelephonyIcons.ICON_4G ); public static final MobileIconGroup FOUR_G_PLUS = new MobileIconGroup( "4G+", - null, - null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - 0, - 0, - 0, - 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], R.string.data_connection_4g_plus, TelephonyIcons.ICON_4G_PLUS ); public static final MobileIconGroup LTE = new MobileIconGroup( "LTE", - null, - null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - 0, - 0, - 0, - 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], R.string.data_connection_lte, TelephonyIcons.ICON_LTE ); public static final MobileIconGroup LTE_PLUS = new MobileIconGroup( "LTE+", - null, - null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - 0, - 0, - 0, - 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], R.string.data_connection_lte_plus, TelephonyIcons.ICON_LTE_PLUS ); public static final MobileIconGroup FOUR_G_LTE = new MobileIconGroup( "4G LTE", - null, - null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - 0, - 0, - 0, - 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], R.string.data_connection_4g_lte, TelephonyIcons.ICON_4G_LTE ); public static final MobileIconGroup FOUR_G_LTE_PLUS = new MobileIconGroup( "4G LTE+", - null, - null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - 0, - 0, - 0, - 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], R.string.data_connection_4g_lte_plus, TelephonyIcons.ICON_4G_LTE_PLUS ); public static final MobileIconGroup LTE_CA_5G_E = new MobileIconGroup( "5Ge", - null, - null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - 0, - 0, - 0, - 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], R.string.data_connection_5ge_html, TelephonyIcons.ICON_5G_E ); public static final MobileIconGroup NR_5G = new MobileIconGroup( "5G", - null, - null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - 0, - 0, - 0, - 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], R.string.data_connection_5g, TelephonyIcons.ICON_5G ); public static final MobileIconGroup NR_5G_PLUS = new MobileIconGroup( "5G_PLUS", - null, - null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - 0, - 0, - 0, - 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], R.string.data_connection_5g_plus, TelephonyIcons.ICON_5G_PLUS ); public static final MobileIconGroup DATA_DISABLED = new MobileIconGroup( "DataDisabled", - null, - null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - 0, - 0, - 0, - 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], R.string.cell_data_off_content_description, 0 ); public static final MobileIconGroup NOT_DEFAULT_DATA = new MobileIconGroup( "NotDefaultData", - null, - null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - 0, - 0, - 0, - 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], R.string.not_default_data_content_description, - 0 + /* dataType= */ 0 ); public static final MobileIconGroup CARRIER_MERGED_WIFI = new MobileIconGroup( "CWF", - /* sbIcons= */ null, - /* qsIcons= */ null, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH, - /* sbNullState= */ 0, - /* qsNullState= */ 0, - /* sbDiscState= */ 0, - /* qsDiscState= */ 0, - AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0], R.string.data_connection_carrier_wifi, TelephonyIcons.ICON_CWF ); - // When adding a new MobileIconGround, check if the dataContentDescription has to be filtered + // When adding a new MobileIconGroup, check if the dataContentDescription has to be filtered // in QSCarrier#hasValidTypeContentDescription /** Mapping icon name(lower case) to the icon object. */ @@ -368,14 +199,6 @@ public class TelephonyIcons { ICON_NAME_TO_ICON.put("notdefaultdata", NOT_DEFAULT_DATA); } - public static final int[] WIFI_CALL_STRENGTH_ICONS = { - R.drawable.ic_wifi_call_strength_0, - R.drawable.ic_wifi_call_strength_1, - R.drawable.ic_wifi_call_strength_2, - R.drawable.ic_wifi_call_strength_3, - R.drawable.ic_wifi_call_strength_4 - }; - public static final int[] MOBILE_CALL_STRENGTH_ICONS = { R.drawable.ic_mobile_call_strength_0, R.drawable.ic_mobile_call_strength_1, @@ -384,4 +207,3 @@ public class TelephonyIcons { R.drawable.ic_mobile_call_strength_4 }; } - diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/MobileNetworkTypeIconsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/MobileNetworkTypeIconsTest.java new file mode 100644 index 0000000000000..39977dfa5c80b --- /dev/null +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/MobileNetworkTypeIconsTest.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2022 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.settingslib; + +import static com.google.common.truth.Truth.assertThat; + +import com.android.settingslib.mobile.TelephonyIcons; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; + +@RunWith(RobolectricTestRunner.class) +public class MobileNetworkTypeIconsTest { + + @Test + public void getNetworkTypeIcon_hPlus_returnsHPlus() { + MobileNetworkTypeIcon icon = + MobileNetworkTypeIcons.getNetworkTypeIcon(TelephonyIcons.H_PLUS); + + assertThat(icon.getName()).isEqualTo(TelephonyIcons.H_PLUS.name); + assertThat(icon.getIconResId()).isEqualTo(TelephonyIcons.ICON_H_PLUS); + } + + @Test + public void getNetworkTypeIcon_fourG_returnsFourG() { + MobileNetworkTypeIcon icon = + MobileNetworkTypeIcons.getNetworkTypeIcon(TelephonyIcons.FOUR_G); + + assertThat(icon.getName()).isEqualTo(TelephonyIcons.H_PLUS.name); + assertThat(icon.getIconResId()).isEqualTo(TelephonyIcons.ICON_4G); + } + + @Test + public void getNetworkTypeIcon_unknown_returnsUnknown() { + SignalIcon.MobileIconGroup unknownGroup = + new SignalIcon.MobileIconGroup("testUnknownNameHere", 45, 6); + + MobileNetworkTypeIcon icon = MobileNetworkTypeIcons.getNetworkTypeIcon(unknownGroup); + + assertThat(icon.getName()).isEqualTo("testUnknownNameHere"); + assertThat(icon.getIconResId()).isEqualTo(45); + assertThat(icon.getContentDescriptionResId()).isEqualTo(6); + } +}