From bb999181004e67b1f90201ac301981d79a2fcc3b Mon Sep 17 00:00:00 2001 From: Zoey Chen Date: Thu, 3 Nov 2022 07:43:46 +0000 Subject: [PATCH] [Settings] Apply the SettingsDataService to the SIM page, add the new column in the fwk. CallsDefaultSubscriptionController SmsDefaultSubscriptionController RoamingPreferenceController Bug: 257197354 Test: atest DefaultSubscriptionControllerTest, atest RoamingPreferenceController Change-Id: I1a3f64d518db167059286a3644e059394760691f --- .../mobile/dataservice/DataServiceUtils.java | 16 ++++++ .../dataservice/MobileNetworkDatabase.java | 2 +- .../dataservice/MobileNetworkInfoDao.java | 2 +- .../dataservice/MobileNetworkInfoEntity.java | 52 ++++++++++++++++++- .../mobile/dataservice/UiccInfoEntity.java | 41 +++++++++++++++ 5 files changed, 110 insertions(+), 3 deletions(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/DataServiceUtils.java b/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/DataServiceUtils.java index 30d382023b5d0..250187f210dca 100644 --- a/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/DataServiceUtils.java +++ b/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/DataServiceUtils.java @@ -23,8 +23,19 @@ import android.telephony.UiccPortInfo; import android.telephony.UiccSlotInfo; import android.telephony.UiccSlotMapping; +import java.util.List; + public class DataServiceUtils { + public static boolean shouldUpdateEntityList(List oldList, List newList) { + if ((oldList != null && + (newList.isEmpty() || !newList.equals(oldList))) + || (!newList.isEmpty() && oldList == null)) { + return true; + } + return false; + } + /** * Represents columns of the MobileNetworkInfoData table, define these columns from * {@see MobileNetworkUtils} or relevant common APIs. @@ -103,6 +114,11 @@ public class DataServiceUtils { */ public static final String COLUMN_SHOW_TOGGLE_FOR_PHYSICAL_SIM = "showToggleForPhysicalSim"; + /** + * The name of the subscription's data roaming state column, + * {@see TelephonyManager#isDataRoamingEnabled()}. + */ + public static final String COLUMN_IS_DATA_ROAMING_ENABLED = "isDataRoamingEnabled"; } /** diff --git a/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/MobileNetworkDatabase.java b/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/MobileNetworkDatabase.java index ca457b04448d6..c92204fa1f39b 100644 --- a/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/MobileNetworkDatabase.java +++ b/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/MobileNetworkDatabase.java @@ -120,7 +120,7 @@ public abstract class MobileNetworkDatabase extends RoomDatabase { * Query the mobileNetwork info by the subscription ID from the MobileNetworkInfoEntity * table. */ - public LiveData queryMobileNetworkInfoById(String id) { + public MobileNetworkInfoEntity queryMobileNetworkInfoById(String id) { return mMobileNetworkInfoDao().queryMobileNetworkInfoBySubId(id); } diff --git a/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/MobileNetworkInfoDao.java b/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/MobileNetworkInfoDao.java index 299a445e14a21..6709772139e2e 100644 --- a/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/MobileNetworkInfoDao.java +++ b/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/MobileNetworkInfoDao.java @@ -36,7 +36,7 @@ public interface MobileNetworkInfoDao { @Query("SELECT * FROM " + DataServiceUtils.MobileNetworkInfoData.TABLE_NAME + " WHERE " + DataServiceUtils.MobileNetworkInfoData.COLUMN_ID + " = :subId") - LiveData queryMobileNetworkInfoBySubId(String subId); + MobileNetworkInfoEntity queryMobileNetworkInfoBySubId(String subId); @Query("SELECT * FROM " + DataServiceUtils.MobileNetworkInfoData.TABLE_NAME + " WHERE " + DataServiceUtils.MobileNetworkInfoData.COLUMN_IS_MOBILE_DATA_ENABLED diff --git a/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/MobileNetworkInfoEntity.java b/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/MobileNetworkInfoEntity.java index a12e0c8467483..e72346d6c7547 100644 --- a/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/MobileNetworkInfoEntity.java +++ b/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/MobileNetworkInfoEntity.java @@ -16,6 +16,8 @@ package com.android.settingslib.mobile.dataservice; +import android.text.TextUtils; + import androidx.annotation.NonNull; import androidx.room.ColumnInfo; import androidx.room.Entity; @@ -28,7 +30,7 @@ public class MobileNetworkInfoEntity { boolean isContactDiscoveryVisible, boolean isMobileDataEnabled, boolean isCdmaOptions, boolean isGsmOptions, boolean isWorldMode, boolean shouldDisplayNetworkSelectOptions, boolean isTdscdmaSupported, boolean activeNetworkIsCellular, - boolean showToggleForPhysicalSim) { + boolean showToggleForPhysicalSim, boolean isDataRoamingEnabled) { this.subId = subId; this.isContactDiscoveryEnabled = isContactDiscoveryEnabled; this.isContactDiscoveryVisible = isContactDiscoveryVisible; @@ -40,6 +42,7 @@ public class MobileNetworkInfoEntity { this.isTdscdmaSupported = isTdscdmaSupported; this.activeNetworkIsCellular = activeNetworkIsCellular; this.showToggleForPhysicalSim = showToggleForPhysicalSim; + this.isDataRoamingEnabled = isDataRoamingEnabled; } @PrimaryKey @@ -78,6 +81,51 @@ public class MobileNetworkInfoEntity { @ColumnInfo(name = DataServiceUtils.MobileNetworkInfoData.COLUMN_SHOW_TOGGLE_FOR_PHYSICAL_SIM) public boolean showToggleForPhysicalSim; + @ColumnInfo(name = DataServiceUtils.MobileNetworkInfoData.COLUMN_IS_DATA_ROAMING_ENABLED) + public boolean isDataRoamingEnabled; + + @Override + public int hashCode() { + int result = 17; + result = 31 * result + subId.hashCode(); + result = 31 * result + Boolean.hashCode(isContactDiscoveryEnabled); + result = 31 * result + Boolean.hashCode(isContactDiscoveryVisible); + result = 31 * result + Boolean.hashCode(isMobileDataEnabled); + result = 31 * result + Boolean.hashCode(isCdmaOptions); + result = 31 * result + Boolean.hashCode(isGsmOptions); + result = 31 * result + Boolean.hashCode(isWorldMode); + result = 31 * result + Boolean.hashCode(shouldDisplayNetworkSelectOptions); + result = 31 * result + Boolean.hashCode(isTdscdmaSupported); + result = 31 * result + Boolean.hashCode(activeNetworkIsCellular); + result = 31 * result + Boolean.hashCode(showToggleForPhysicalSim); + result = 31 * result + Boolean.hashCode(isDataRoamingEnabled); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof MobileNetworkInfoEntity)) { + return false; + } + + MobileNetworkInfoEntity info = (MobileNetworkInfoEntity) obj; + return TextUtils.equals(subId, info.subId) + && isContactDiscoveryEnabled == info.isContactDiscoveryEnabled + && isContactDiscoveryVisible == info.isContactDiscoveryVisible + && isMobileDataEnabled == info.isMobileDataEnabled + && isCdmaOptions == info.isCdmaOptions + && isGsmOptions == info.isGsmOptions + && isWorldMode == info.isWorldMode + && shouldDisplayNetworkSelectOptions == info.shouldDisplayNetworkSelectOptions + && isTdscdmaSupported == info.isTdscdmaSupported + && activeNetworkIsCellular == info.activeNetworkIsCellular + && showToggleForPhysicalSim == info.showToggleForPhysicalSim + && isDataRoamingEnabled == info.isDataRoamingEnabled; + } + public String toString() { StringBuilder builder = new StringBuilder(); builder.append(" {MobileNetworkInfoEntity(subId = ") @@ -102,6 +150,8 @@ public class MobileNetworkInfoEntity { .append(activeNetworkIsCellular) .append(", showToggleForPhysicalSim = ") .append(showToggleForPhysicalSim) + .append(", isDataRoamingEnabled = ") + .append(isDataRoamingEnabled) .append(")}"); return builder.toString(); } diff --git a/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/UiccInfoEntity.java b/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/UiccInfoEntity.java index 532462bec1930..2ccf295007dcd 100644 --- a/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/UiccInfoEntity.java +++ b/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/UiccInfoEntity.java @@ -16,6 +16,8 @@ package com.android.settingslib.mobile.dataservice; +import android.text.TextUtils; + import androidx.annotation.NonNull; import androidx.room.ColumnInfo; import androidx.room.Entity; @@ -73,6 +75,45 @@ public class UiccInfoEntity { @ColumnInfo(name = DataServiceUtils.UiccInfoData.COLUMN_PORT_INDEX) public int portIndex; + + @Override + public int hashCode() { + int result = 17; + result = 31 * result + subId.hashCode(); + result = 31 * result + physicalSlotIndex.hashCode(); + result = 31 * result + logicalSlotIndex; + result = 31 * result + cardId; + result = 31 * result + Boolean.hashCode(isEuicc); + result = 31 * result + Boolean.hashCode(isMultipleEnabledProfilesSupported); + result = 31 * result + cardState; + result = 31 * result + Boolean.hashCode(isRemovable); + result = 31 * result + Boolean.hashCode(isActive); + result = 31 * result + portIndex; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof UiccInfoEntity)) { + return false; + } + + UiccInfoEntity info = (UiccInfoEntity) obj; + return TextUtils.equals(subId, info.subId) + && TextUtils.equals(physicalSlotIndex, info.physicalSlotIndex) + && logicalSlotIndex == info.logicalSlotIndex + && cardId == info.cardId + && isEuicc == info.isEuicc + && isMultipleEnabledProfilesSupported == info.isMultipleEnabledProfilesSupported + && cardState == info.cardState + && isRemovable == info.isRemovable + && isActive == info.isActive + && portIndex == info.portIndex; + } + public String toString() { StringBuilder builder = new StringBuilder(); builder.append(" {UiccInfoEntity(subId = ")