diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-03-03 00:20:56 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-03-03 00:20:56 +0000 |
commit | 8ba1b2674d6661d2de2215dc99c376304884d2b5 (patch) | |
tree | fa2b5a3e886b947363c6e8b66099614c9a0d8da6 | |
parent | 6a8408acc4a110a15b4b659da618bc721f53d106 (diff) | |
parent | 813dca20d4c3879c447cc2c7522e8fbd1a0127c9 (diff) | |
download | telephony-8ba1b2674d6661d2de2215dc99c376304884d2b5.tar.gz |
Snap for 9682271 from 813dca20d4c3879c447cc2c7522e8fbd1a0127c9 to tm-qpr3-release
Change-Id: Ib57c417004e66b029dd8a66ff140309a178af622
3 files changed, 53 insertions, 167 deletions
diff --git a/src/java/com/android/internal/telephony/data/DataNetworkController.java b/src/java/com/android/internal/telephony/data/DataNetworkController.java index 671917da45..cdcf258763 100644 --- a/src/java/com/android/internal/telephony/data/DataNetworkController.java +++ b/src/java/com/android/internal/telephony/data/DataNetworkController.java @@ -2270,7 +2270,7 @@ public class DataNetworkController extends Handler { /** Called when subscription info changed. */ private void onSubscriptionChanged() { if (mSubId != mPhone.getSubId()) { - log("onSubscriptionChanged: mSubId changed from " + mSubId + " to " + log("onDataConfigUpdated: mSubId changed from " + mSubId + " to " + mPhone.getSubId()); if (isImsGracefulTearDownSupported()) { if (SubscriptionManager.isValidSubscriptionId(mPhone.getSubId())) { diff --git a/src/java/com/android/internal/telephony/data/DataProfileManager.java b/src/java/com/android/internal/telephony/data/DataProfileManager.java index 6cd41baf7a..c7e5433b11 100644 --- a/src/java/com/android/internal/telephony/data/DataProfileManager.java +++ b/src/java/com/android/internal/telephony/data/DataProfileManager.java @@ -19,12 +19,8 @@ package com.android.internal.telephony.data; import android.annotation.CallbackExecutor; import android.annotation.NonNull; import android.annotation.Nullable; -import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.ContentValues; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; import android.database.ContentObserver; import android.database.Cursor; import android.net.NetworkCapabilities; @@ -71,9 +67,6 @@ import java.util.stream.Collectors; public class DataProfileManager extends Handler { private static final boolean VDBG = true; - /** Event for SIM loaded. */ - private static final int EVENT_SIM_LOADED = 1; - /** Event for APN database changed. */ private static final int EVENT_APN_DATABASE_CHANGED = 2; @@ -160,60 +153,7 @@ public class DataProfileManager extends Handler { mWwanDataServiceManager = dataServiceManager; mDataConfigManager = dataNetworkController.getDataConfigManager(); mDataProfileManagerCallbacks.add(callback); - - IntentFilter filter = new IntentFilter(); - filter.addAction(TelephonyManager.ACTION_SIM_APPLICATION_STATE_CHANGED); - mPhone.getContext().registerReceiver(new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - if (intent.getAction().equals( - TelephonyManager.ACTION_SIM_APPLICATION_STATE_CHANGED)) { - if (mPhone.getPhoneId() == intent.getIntExtra( - CarrierConfigManager.EXTRA_SLOT_INDEX, - SubscriptionManager.INVALID_SIM_SLOT_INDEX)) { - sendMessageAtFrontOfQueue(obtainMessage(EVENT_SIM_LOADED)); - } - } - } - }, filter, null, mPhone); - registerAllEvents(); - log("created."); - } - - /** - * Called when SIM loaded. - */ - private void onSimLoaded() { - // Below is for boot up camping optimization purpose. We do not need to wait until carrier - // config ready to load the profiles. Although preferred data profile might be affected by - // the carrier config, that's only for the first time boot up. In that case, the preferred - // data profile from the db would be empty, and we can wait until carrier config ready to - // determine the preferred data profile. By just loading the essential profiles when SIM - // loaded, the boot up camping time is slightly improved. - // - // The default (i.e. framework generated) data profiles for enterprise, emergency, and IMS - // will also be added at that time if they are missing from all profiles. - log("onSimLoaded: subId=" + mPhone.getSubId()); - if (SubscriptionManager.isValidSubscriptionId(mPhone.getSubId())) { - int preferredProfileId = getPreferredDataProfileIdFromDb(); - if (preferredProfileId < 0) { - // Preferred data profile does not exist. This might be the first time boot up. - // Deferred until carrier config loaded so we can determine the correct preferred - // data profile. It is intended to bail out here. If we load all the data profiles - // without knowing the preferred data profile, we might end up with setting up - // with the wrong one. - log("onSimLoaded: Preferred data profile does not exist."); - return; - } - mPreferredDataProfile = getPreferredDataProfileFromDb(); - mPreferredDataProfileSetId = getPreferredDataProfileSetId(); - log("onSimLoaded: mPreferredDataProfileSetId=" + mPreferredDataProfileSetId); - - mAllDataProfiles.clear(); - mAllDataProfiles.addAll(loadDataProfilesFromDatabase()); - log("onSimLoaded: Loaded " + mAllDataProfiles); - } } /** @@ -247,9 +187,6 @@ public class DataProfileManager extends Handler { @Override public void handleMessage(Message msg) { switch (msg.what) { - case EVENT_SIM_LOADED: - onSimLoaded(); - break; case EVENT_SIM_REFRESH: log("Update data profiles due to SIM refresh."); updateDataProfiles(FORCED_UPDATE_IA); @@ -304,61 +241,50 @@ public class DataProfileManager extends Handler { cursor.close(); return dataProfile; } - /** - * Load all data profiles associated with the current SIM from the database. + * Update all data profiles, including preferred data profile, and initial attach data profile. + * Also send those profiles down to the modem if needed. * - * @return The loaded profiles. Empty list if not found. + * @param forceUpdateIa If {@code true}, we should always send IA again to modem. */ - private @NonNull List<DataProfile> loadDataProfilesFromDatabase() { - log("loadDataProfilesFromDatabase: subId=" + mPhone.getSubId()); + private void updateDataProfiles(boolean forceUpdateIa) { List<DataProfile> profiles = new ArrayList<>(); - Cursor cursor = mPhone.getContext().getContentResolver().query( - Uri.withAppendedPath(Telephony.Carriers.SIM_APN_URI, "filtered/subId/" - + mPhone.getSubId()), null, null, null, Telephony.Carriers._ID); - if (cursor == null) { - loge("Cannot access APN database through telephony provider."); - return new ArrayList<>(); - } - boolean isInternetSupported = false; - while (cursor.moveToNext()) { - ApnSetting apn = ApnSetting.makeApnSetting(cursor); - if (apn != null) { - DataProfile dataProfile = new DataProfile.Builder() - .setApnSetting(apn) - .setTrafficDescriptor(new TrafficDescriptor(apn.getApnName(), null)) - .setPreferred(false) - .build(); - profiles.add(dataProfile); - log("Added " + dataProfile); - - isInternetSupported |= apn.canHandleType(ApnSetting.TYPE_DEFAULT); - if (mDataConfigManager.isApnConfigAnomalyReportEnabled()) { - checkApnSetting(apn); + if (mDataConfigManager.isConfigCarrierSpecific()) { + Cursor cursor = mPhone.getContext().getContentResolver().query( + Uri.withAppendedPath(Telephony.Carriers.SIM_APN_URI, "filtered/subId/" + + mPhone.getSubId()), null, null, null, Telephony.Carriers._ID); + if (cursor == null) { + loge("Cannot access APN database through telephony provider."); + return; + } + boolean isInternetSupported = false; + while (cursor.moveToNext()) { + ApnSetting apn = ApnSetting.makeApnSetting(cursor); + if (apn != null) { + DataProfile dataProfile = new DataProfile.Builder() + .setApnSetting(apn) + .setTrafficDescriptor(new TrafficDescriptor(apn.getApnName(), null)) + .setPreferred(false) + .build(); + profiles.add(dataProfile); + log("Added " + dataProfile); + + isInternetSupported |= apn.canHandleType(ApnSetting.TYPE_DEFAULT); + if (mDataConfigManager.isApnConfigAnomalyReportEnabled()) { + checkApnSetting(apn); + } } } - } - cursor.close(); + cursor.close(); - if (!isInternetSupported - && !profiles.isEmpty() // APN database has been read successfully - && mDataConfigManager.isApnConfigAnomalyReportEnabled()) { - reportAnomaly("Carrier doesn't support internet.", - "9af73e18-b523-4dc5-adab-363eb6613305"); + if (!isInternetSupported + && !profiles.isEmpty() // APN database has been read successfully + && mDataConfigManager.isApnConfigAnomalyReportEnabled()) { + reportAnomaly("Carrier doesn't support internet.", + "9af73e18-b523-4dc5-adab-363eb6613305"); + } } - return profiles; - } - - /** - * Update all data profiles, including preferred data profile, and initial attach data profile. - * Also send those profiles down to the modem if needed. - * - * @param forceUpdateIa If {@code true}, we should always send IA again to modem. - */ - private void updateDataProfiles(boolean forceUpdateIa) { - List<DataProfile> profiles = loadDataProfilesFromDatabase(); - // Check if any of the profile already supports ENTERPRISE, if not, check if DPC has // configured one and retrieve the same. DataProfile dataProfile = profiles.stream() @@ -490,39 +416,28 @@ public class DataProfileManager extends Handler { } /** - * @return The preferred data profile id. {@code -1} if not found. - */ - private int getPreferredDataProfileIdFromDb() { - try (Cursor cursor = mPhone.getContext().getContentResolver().query( - Uri.withAppendedPath(Telephony.Carriers.PREFERRED_APN_URI, - String.valueOf(mPhone.getSubId())), null, null, null, - Telephony.Carriers.DEFAULT_SORT_ORDER)) { - if (cursor != null) { - if (cursor.getCount() > 0) { - cursor.moveToFirst(); - return cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers._ID)); - } - } - } - return -1; - } - - /** * Get the preferred data profile for internet data. * * @return The preferred data profile. */ private @Nullable DataProfile getPreferredDataProfileFromDb() { - int preferredDataProfileId = getPreferredDataProfileIdFromDb(); - if (preferredDataProfileId < 0) { - log("getPreferredDataProfileFromDb: null"); - return null; + Cursor cursor = mPhone.getContext().getContentResolver().query( + Uri.withAppendedPath(Telephony.Carriers.PREFERRED_APN_URI, + String.valueOf(mPhone.getSubId())), null, null, null, + Telephony.Carriers.DEFAULT_SORT_ORDER); + DataProfile dataProfile = null; + if (cursor != null) { + if (cursor.getCount() > 0) { + cursor.moveToFirst(); + int apnId = cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers._ID)); + dataProfile = mAllDataProfiles.stream() + .filter(dp -> dp.getApnSetting() != null + && dp.getApnSetting().getId() == apnId) + .findFirst() + .orElse(null); + } + cursor.close(); } - DataProfile dataProfile = mAllDataProfiles.stream() - .filter(dp -> dp.getApnSetting() != null - && dp.getApnSetting().getId() == preferredDataProfileId) - .findFirst() - .orElse(null); log("getPreferredDataProfileFromDb: " + dataProfile); return dataProfile; } diff --git a/tests/telephonytests/src/com/android/internal/telephony/data/DataProfileManagerTest.java b/tests/telephonytests/src/com/android/internal/telephony/data/DataProfileManagerTest.java index 10f9c67c82..806ebdc12a 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/data/DataProfileManagerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/data/DataProfileManagerTest.java @@ -407,7 +407,7 @@ public class DataProfileManagerTest extends TelephonyTest { public void setPreferredApn(String apnName) { for (Object apnSetting : mAllApnSettings) { - if (Objects.equals(apnName, ((Object[]) apnSetting)[3])) { + if (apnName == ((Object[]) apnSetting)[3]) { mPreferredApnId = (int) ((Object[]) apnSetting)[0]; mPreferredApnSet = (int) ((Object[]) apnSetting)[28]; logd("mPreferredApnId=" + mPreferredApnId + " ,mPreferredApnSet=" @@ -1124,33 +1124,4 @@ public class DataProfileManagerTest extends TelephonyTest { assertThat(mDataProfileManagerUT.getDataProfileForNetworkRequest(tnr, TelephonyManager.NETWORK_TYPE_LTE, false)).isNull(); } - - @Test - public void testSimLoaded() { - mDataProfileManagerUT = new DataProfileManager(mPhone, mDataNetworkController, - mMockedWwanDataServiceManager, Looper.myLooper(), mDataProfileManagerCallback); - - mDataProfileManagerUT.obtainMessage(1 /* EVENT_SIM_LOADED */).sendToTarget(); - processAllMessages(); - - DataProfile dataProfile = mDataProfileManagerUT.getDataProfileForNetworkRequest( - new TelephonyNetworkRequest(new NetworkRequest.Builder() - .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) - .build(), mPhone), - TelephonyManager.NETWORK_TYPE_LTE, false); - - // Because preferred APN is not set, SIM load event will not trigger loading data profiles. - assertThat(dataProfile).isNull(); - - mApnSettingContentProvider.setPreferredApn(GENERAL_PURPOSE_APN); - mDataProfileManagerUT.obtainMessage(1 /* EVENT_SIM_LOADED */).sendToTarget(); - processAllMessages(); - - dataProfile = mDataProfileManagerUT.getDataProfileForNetworkRequest( - new TelephonyNetworkRequest(new NetworkRequest.Builder() - .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) - .build(), mPhone), - TelephonyManager.NETWORK_TYPE_LTE, false); - assertThat(dataProfile.getApnSetting().getApnName()).isEqualTo(GENERAL_PURPOSE_APN); - } } |