diff options
87 files changed, 2079 insertions, 870 deletions
diff --git a/flags/domainselection.aconfig b/flags/domainselection.aconfig index 29b278f1a6..88a6e9e1e6 100644 --- a/flags/domainselection.aconfig +++ b/flags/domainselection.aconfig @@ -71,3 +71,14 @@ flag { purpose: PURPOSE_BUGFIX } } + +# OWNER=hwangoo TARGET=25Q2 +flag { + name: "perform_cross_stack_redial_check_for_emergency_call" + namespace: "telephony" + description: "This flag performs a quick cross stack redial if the subscription is being invalid and an exception occurs, while an emergency call is in progress." + bug:"389190613" + metadata { + purpose: PURPOSE_BUGFIX + } +} diff --git a/flags/subscription.aconfig b/flags/subscription.aconfig index 8a1a2d339a..ea12ce8d38 100644 --- a/flags/subscription.aconfig +++ b/flags/subscription.aconfig @@ -46,18 +46,6 @@ flag { bug: "325045841" } -# OWNER=songferngwang TARGET=24Q3 -flag { - name: "reset_primary_sim_default_values" - namespace: "telephony" - description: "Reset the default values to the remaining sim" - bug: "339394518" - - metadata { - purpose: PURPOSE_BUGFIX - } -} - # OWNER=jmattis TARGET=25Q2 flag { name: "subscription_plan_allow_status_and_end_date" diff --git a/proto/src/persist_atoms.proto b/proto/src/persist_atoms.proto index cca2435254..445664d035 100644 --- a/proto/src/persist_atoms.proto +++ b/proto/src/persist_atoms.proto @@ -728,6 +728,12 @@ message SatelliteController { optional int32 count_of_p2p_sms_available_notification_removed = 35; optional bool is_ntn_only_carrier = 36; optional int32 version_of_satellite_access_config = 37; + optional int32 count_of_incoming_datagram_type_sos_sms_success = 38; + optional int32 count_of_incoming_datagram_type_sos_sms_fail = 39; + optional int32 count_of_outgoing_datagram_type_sms_success = 40; + optional int32 count_of_outgoing_datagram_type_sms_fail = 41; + optional int32 count_of_incoming_datagram_type_sms_success = 42; + optional int32 count_of_incoming_datagram_type_sms_fail = 43; } message SatelliteSession { diff --git a/src/java/com/android/internal/telephony/GsmCdmaPhone.java b/src/java/com/android/internal/telephony/GsmCdmaPhone.java index ab9e3e8ca1..f08e237317 100644 --- a/src/java/com/android/internal/telephony/GsmCdmaPhone.java +++ b/src/java/com/android/internal/telephony/GsmCdmaPhone.java @@ -349,7 +349,6 @@ public class GsmCdmaPhone extends Phone { super(precisePhoneType == PhoneConstants.PHONE_TYPE_GSM ? "GSM" : "CDMA", notifier, context, ci, unitTestMode, phoneId, telephonyComponentFactory, featureFlags); - // phone type needs to be set before other initialization as other objects rely on it mPrecisePhoneType = precisePhoneType; mVoiceCallSessionStats = new VoiceCallSessionStats(mPhoneId, this, featureFlags); @@ -370,7 +369,7 @@ public class GsmCdmaPhone extends Phone { SignalStrengthController.class.getName()).makeSignalStrengthController(this); mSST = mTelephonyComponentFactory.inject(ServiceStateTracker.class.getName()) .makeServiceStateTracker(this, this.mCi, featureFlags); - if (hasCalling()) { + if (hasCalling() || hasMessaging()) { mEmergencyNumberTracker = mTelephonyComponentFactory .inject(EmergencyNumberTracker.class.getName()).makeEmergencyNumberTracker( this, this.mCi, mFeatureFlags); diff --git a/src/java/com/android/internal/telephony/MultiSimSettingController.java b/src/java/com/android/internal/telephony/MultiSimSettingController.java index 881addeaad..bdde74d622 100644 --- a/src/java/com/android/internal/telephony/MultiSimSettingController.java +++ b/src/java/com/android/internal/telephony/MultiSimSettingController.java @@ -648,10 +648,7 @@ public class MultiSimSettingController extends Handler { // Otherwise, if user just inserted their first SIM, or there's one primary and one // opportunistic subscription active (activeSubInfos.size() > 1), we automatically // set the primary to be default SIM and return. - boolean conditionForOnePrimarySim = - mFeatureFlags.resetPrimarySimDefaultValues() ? mPrimarySubList.size() == 1 - : mPrimarySubList.size() == 1 - && (change != PRIMARY_SUB_REMOVED || mActiveModemCount == 1); + boolean conditionForOnePrimarySim = mPrimarySubList.size() == 1; if (conditionForOnePrimarySim) { int subId = mPrimarySubList.get(0); if (DBG) log("updateDefaultValues: to only primary sub " + subId); diff --git a/src/java/com/android/internal/telephony/NetworkTypeController.java b/src/java/com/android/internal/telephony/NetworkTypeController.java index 3cefb5e35c..f05e002550 100644 --- a/src/java/com/android/internal/telephony/NetworkTypeController.java +++ b/src/java/com/android/internal/telephony/NetworkTypeController.java @@ -213,8 +213,8 @@ public class NetworkTypeController extends StateMachine { @NonNull private final Set<Integer> mAdditionalNrAdvancedBands = new HashSet<>(); @NonNull private String mPrimaryTimerState; @NonNull private String mSecondaryTimerState; - // TODO(b/316425811 remove the workaround) private int mNrAdvancedBandsSecondaryTimer; + private int mNrAdvancedPciChangeSecondaryTimer; @NonNull private String mPreviousState; @LinkStatus private int mPhysicalLinkStatus; private boolean mIsPhysicalChannelConfig16Supported; @@ -224,6 +224,7 @@ public class NetworkTypeController extends StateMachine { private boolean mEnableNrAdvancedWhileRoaming = true; private boolean mIsDeviceIdleMode = false; private boolean mPrimaryCellChangedWhileIdle = false; + private boolean mPciChangedDuringPrimaryTimer = false; // Cached copies below to prevent race conditions @NonNull private ServiceState mServiceState; @@ -485,6 +486,8 @@ public class NetworkTypeController extends StateMachine { CarrierConfigManager.KEY_LTE_ENDC_USING_USER_DATA_FOR_RRC_DETECTION_BOOL); mNrAdvancedBandsSecondaryTimer = config.getInt( CarrierConfigManager.KEY_NR_ADVANCED_BANDS_SECONDARY_TIMER_SECONDS_INT); + mNrAdvancedPciChangeSecondaryTimer = config.getInt( + CarrierConfigManager.KEY_NR_ADVANCED_PCI_CHANGE_SECONDARY_TIMER_SECONDS_INT); String nrIconConfiguration = config.getString( CarrierConfigManager.KEY_5G_ICON_CONFIGURATION_STRING); String overrideTimerRule = config.getString( @@ -1427,6 +1430,7 @@ public class NetworkTypeController extends StateMachine { mLastAnchorNrCellId = anchorNrCellId; mPhysicalChannelConfigs = physicalChannelConfigs; mDoesPccListIndicateIdle = false; + mPciChangedDuringPrimaryTimer = mIsPrimaryTimerActive; if (DBG) { log("Physical channel configs updated: anchorNrCell=" + mLastAnchorNrCellId + ", nrBandwidths=" + mRatchetedNrBandwidths + ", nrBands=" + mRatchetedNrBands @@ -1484,6 +1488,7 @@ public class NetworkTypeController extends StateMachine { private void transitionWithSecondaryTimerTo(IState destState) { String currentName = getCurrentState().getName(); OverrideTimerRule rule = mOverrideTimerRules.get(mPrimaryTimerState); + int duration = -1; if (DBG) { log("Transition with secondary timer from " + currentName + " to " + destState.getName()); @@ -1492,12 +1497,19 @@ public class NetworkTypeController extends StateMachine { log("Skip secondary timer from " + currentName + " to " + destState.getName() + " due to in call"); } else if (!mIsDeviceIdleMode && rule != null && rule.getSecondaryTimer(currentName) > 0) { - int duration = rule.getSecondaryTimer(currentName); + duration = rule.getSecondaryTimer(currentName); if (mLastShownNrDueToAdvancedBand && mNrAdvancedBandsSecondaryTimer > 0) { duration = mNrAdvancedBandsSecondaryTimer; if (DBG) log("timer adjusted by nr_advanced_bands_secondary_timer_seconds_int"); } if (DBG) log(duration + "s secondary timer started for state: " + currentName); + } else if (mNrAdvancedPciChangeSecondaryTimer > 0 + && mPciChangedDuringPrimaryTimer) { + duration = mNrAdvancedPciChangeSecondaryTimer; + if (DBG) log(duration + "s secondary timer started for PCI changed"); + } + + if (duration > 0) { mSecondaryTimerState = currentName; mPreviousState = currentName; mIsSecondaryTimerActive = true; @@ -1505,7 +1517,9 @@ public class NetworkTypeController extends StateMachine { mSecondaryTimerExpireTimestamp = SystemClock.uptimeMillis() + durationMillis; sendMessageDelayed(EVENT_SECONDARY_TIMER_EXPIRED, destState, durationMillis); } + mIsPrimaryTimerActive = false; + mPciChangedDuringPrimaryTimer = false; transitionTo(getCurrentState()); } @@ -1555,6 +1569,7 @@ public class NetworkTypeController extends StateMachine { } removeMessages(EVENT_PRIMARY_TIMER_EXPIRED); mIsPrimaryTimerActive = false; + mPciChangedDuringPrimaryTimer = false; mPrimaryTimerState = ""; transitionToCurrentState(); return; @@ -1598,6 +1613,7 @@ public class NetworkTypeController extends StateMachine { removeMessages(EVENT_PRIMARY_TIMER_EXPIRED); removeMessages(EVENT_SECONDARY_TIMER_EXPIRED); mIsPrimaryTimerActive = false; + mPciChangedDuringPrimaryTimer = false; mIsSecondaryTimerActive = false; mSecondaryTimerExpireTimestamp = 0; mPrimaryTimerState = ""; @@ -1821,10 +1837,11 @@ public class NetworkTypeController extends StateMachine { pw.flush(); pw.increaseIndent(); pw.println("mSubId=" + mPhone.getSubId()); - pw.println("mOverrideTimerRules=" + mOverrideTimerRules.toString()); + pw.println("mOverrideTimerRules=" + mOverrideTimerRules); pw.println("mLteEnhancedPattern=" + mLteEnhancedPattern); pw.println("mIsPhysicalChannelConfigOn=" + mIsPhysicalChannelConfigOn); pw.println("mIsPrimaryTimerActive=" + mIsPrimaryTimerActive); + pw.println("mPciChangedDuringPrimaryTimer=" + mPciChangedDuringPrimaryTimer); pw.println("mIsSecondaryTimerActive=" + mIsSecondaryTimerActive); pw.println("mIsTimerResetEnabledForLegacyStateRrcIdle=" + mIsTimerResetEnabledForLegacyStateRrcIdle); diff --git a/src/java/com/android/internal/telephony/Phone.java b/src/java/com/android/internal/telephony/Phone.java index c66022d7f1..e136e5a0e4 100644 --- a/src/java/com/android/internal/telephony/Phone.java +++ b/src/java/com/android/internal/telephony/Phone.java @@ -1060,16 +1060,17 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { } /** - * Notify the phone that an SMS has been sent. This will be used determine if the SMS was sent - * to an emergency address. + * Notify the phone that an SMS has been sent. This will be used to determine if the SMS was + * sent to an emergency address. + * * @param destinationAddress the address that the SMS was sent to. */ public void notifySmsSent(String destinationAddress) { - TelephonyManager m = (TelephonyManager) getContext().getSystemService( - Context.TELEPHONY_SERVICE); + TelephonyManager m = + (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE); if (mContext.getPackageManager() != null - && mContext.getPackageManager().hasSystemFeature( - PackageManager.FEATURE_TELEPHONY_CALLING)) { + && mContext.getPackageManager() + .hasSystemFeature(PackageManager.FEATURE_TELEPHONY_MESSAGING)) { if (m != null && m.isEmergencyNumber(destinationAddress)) { mLocalLog.log("Emergency SMS detected, recording time."); mTimeLastEmergencySmsSentMs = SystemClock.elapsedRealtime(); @@ -1967,6 +1968,13 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { } /** + * @return true if this device supports messaging, false otherwise. + */ + public boolean hasMessaging() { + return TelephonyCapabilities.supportsTelephonyMessaging(mFeatureFlags, mContext); + } + + /** * Retrieves the EmergencyNumberTracker of the phone instance. */ public EmergencyNumberTracker getEmergencyNumberTracker() { diff --git a/src/java/com/android/internal/telephony/RIL.java b/src/java/com/android/internal/telephony/RIL.java index ac0ee0d039..f5d06dbe76 100644 --- a/src/java/com/android/internal/telephony/RIL.java +++ b/src/java/com/android/internal/telephony/RIL.java @@ -1331,7 +1331,12 @@ public class RIL extends BaseCommands implements CommandsInterface { } private boolean canMakeRequest(String request, RadioServiceProxy proxy, Message result, - HalVersion version) { + HalVersion minVersion) { + return canMakeRequest(request, proxy, result, minVersion, null /* maxVersion */); + } + + private boolean canMakeRequest(String request, RadioServiceProxy proxy, Message result, + HalVersion minVersion, @Nullable HalVersion maxVersion) { int service = HAL_SERVICE_RADIO; if (proxy instanceof RadioDataProxy) { service = HAL_SERVICE_DATA; @@ -1358,9 +1363,20 @@ public class RIL extends BaseCommands implements CommandsInterface { } return false; } - if (mHalVersion.get(service).less(version)) { + if (mHalVersion.get(service).less(minVersion)) { riljLoge(String.format("%s not supported on service %s < %s.", - request, serviceToString(service), version)); + request, serviceToString(service), minVersion)); + if (result != null) { + AsyncResult.forMessage(result, null, + CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED)); + result.sendToTarget(); + } + return false; + } + + if (maxVersion != null && mHalVersion.get(service).greater(maxVersion)) { + riljLoge(String.format("%s not supported on service %s > %s.", + request, serviceToString(service), maxVersion)); if (result != null) { AsyncResult.forMessage(result, null, CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED)); @@ -3627,7 +3643,8 @@ public class RIL extends BaseCommands implements CommandsInterface { @Override public void getDeviceIdentity(Message result) { RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class); - if (!canMakeRequest("getDeviceIdentity", modemProxy, result, RADIO_HAL_VERSION_1_4)) { + if (!canMakeRequest("getDeviceIdentity", modemProxy, result, RADIO_HAL_VERSION_1_4, + RADIO_HAL_VERSION_2_2)) { return; } @@ -3882,7 +3899,7 @@ public class RIL extends BaseCommands implements CommandsInterface { public void getImsRegistrationState(Message result) { RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class); if (!canMakeRequest("getImsRegistrationState", networkProxy, result, - RADIO_HAL_VERSION_1_4)) { + RADIO_HAL_VERSION_1_4, RADIO_HAL_VERSION_2_2)) { return; } diff --git a/src/java/com/android/internal/telephony/SMSDispatcher.java b/src/java/com/android/internal/telephony/SMSDispatcher.java index 759273a76b..fd72c88d79 100644 --- a/src/java/com/android/internal/telephony/SMSDispatcher.java +++ b/src/java/com/android/internal/telephony/SMSDispatcher.java @@ -63,6 +63,7 @@ import android.service.carrier.CarrierMessagingServiceWrapper; import android.service.carrier.CarrierMessagingServiceWrapper.CarrierMessagingCallback; import android.telephony.AnomalyReporter; import android.telephony.CarrierConfigManager; +import android.telephony.NetworkRegistrationInfo; import android.telephony.PhoneNumberUtils; import android.telephony.ServiceState; import android.telephony.SmsManager; @@ -90,9 +91,11 @@ import com.android.internal.telephony.analytics.TelephonyAnalytics; import com.android.internal.telephony.analytics.TelephonyAnalytics.SmsMmsAnalytics; import com.android.internal.telephony.cdma.sms.UserData; import com.android.internal.telephony.flags.Flags; +import com.android.internal.telephony.satellite.SatelliteController; import com.android.internal.telephony.subscription.SubscriptionInfoInternal; import com.android.internal.telephony.subscription.SubscriptionManagerService; import com.android.internal.telephony.uicc.IccRecords; +import com.android.internal.telephony.util.ArrayUtils; import com.android.internal.telephony.util.TelephonyUtils; import com.android.telephony.Rlog; @@ -2226,6 +2229,7 @@ public abstract class SMSDispatcher extends Handler { if (mContext.checkCallingOrSelfPermission(SEND_SMS_NO_CONFIRMATION) == PackageManager.PERMISSION_GRANTED || trackers[0].mIsForVvm || trackers[0].mSkipShortCodeDestAddrCheck) { + Rlog.d(TAG, "checkDestination: app pre-approved"); return true; // app is pre-approved to send to short codes } else { int rule = mPremiumSmsRule.get(); @@ -2245,6 +2249,7 @@ public abstract class SMSDispatcher extends Handler { mSmsDispatchersController .getUsageMonitor() .checkDestination(trackers[0].mDestAddress, simCountryIso); + Rlog.d(TAG, "checkDestination: simCountryIso=" + simCountryIso); } if (rule == PREMIUM_RULE_USE_NETWORK || rule == PREMIUM_RULE_USE_BOTH) { String networkCountryIso = @@ -2264,7 +2269,9 @@ public abstract class SMSDispatcher extends Handler { .getUsageMonitor() .checkDestination( trackers[0].mDestAddress, networkCountryIso)); + Rlog.d(TAG, "checkDestination: networkCountryIso=" + networkCountryIso); } + Rlog.d(TAG, "checkDestination: smsCategory=" + smsCategory); if (smsCategory != SmsManager.SMS_CATEGORY_NOT_SHORT_CODE) { int xmlVersion = mSmsDispatchersController.getUsageMonitor() @@ -2286,6 +2293,14 @@ public abstract class SMSDispatcher extends Handler { return false; } + // Check whether to block premium sms in satellite mode. + if (shouldBlockPremiumSmsInSatelliteMode()) { + Rlog.d(TAG, "Block premium SMS in satellite mode." + + " messageId=" + SmsController.formatCrossStackMessageId( + getMultiTrackermessageId(trackers))); + return false; + } + // Wait for user confirmation unless the user has set permission to always allow/deny int premiumSmsPermission = mSmsDispatchersController @@ -2325,6 +2340,32 @@ public abstract class SMSDispatcher extends Handler { } } + /** Block premium sms in satellite mode. */ + @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE) + public boolean shouldBlockPremiumSmsInSatelliteMode() { + SatelliteController sc = SatelliteController.getInstance(); + + if (sc.isSatelliteBeingEnabled()) { + Rlog.d(TAG, "shouldBlockPremiumSmsInSatelliteMode: block premium sms when " + + "satellite is being enabled"); + return true; + } + + if (sc.isSatelliteEnabled()) { + int satelliteSubId = sc.getSelectedSatelliteSubId(); + int[] services = sc.getSupportedServicesOnCarrierRoamingNtn(satelliteSubId); + boolean isSmsSupported = ArrayUtils.contains( + services, NetworkRegistrationInfo.SERVICE_TYPE_SMS); + Rlog.d(TAG, "shouldBlockPremiumSmsInSatelliteMode: satelliteSubId=" + + satelliteSubId + " isSmsSupported=" + isSmsSupported + + " services=" + Arrays.toString(services)); + return !isSmsSupported; + } + + Rlog.d(TAG, "shouldBlockPremiumSmsInSatelliteMode: return false."); + return false; + } + /** * Deny sending a single or a multi-part SMS if the outgoing queue limit is reached. Used when * the message must be confirmed by the user due to excessive usage or potential premium SMS diff --git a/src/java/com/android/internal/telephony/TelephonyCapabilities.java b/src/java/com/android/internal/telephony/TelephonyCapabilities.java index c5bfe79052..35c862f4ae 100644 --- a/src/java/com/android/internal/telephony/TelephonyCapabilities.java +++ b/src/java/com/android/internal/telephony/TelephonyCapabilities.java @@ -219,4 +219,14 @@ public class TelephonyCapabilities { return context.getPackageManager().hasSystemFeature( PackageManager.FEATURE_TELEPHONY_CALLING); } + + /** + * @return true if this device supports telephony messaging, false if it does not. + */ + public static boolean supportsTelephonyMessaging(@NonNull FeatureFlags featureFlags, + Context context) { + if (!TelephonyCapabilities.minimalTelephonyCdmCheck(featureFlags)) return true; + return context.getPackageManager().hasSystemFeature( + PackageManager.FEATURE_TELEPHONY_MESSAGING); + } } diff --git a/src/java/com/android/internal/telephony/configupdate/ConfigParser.java b/src/java/com/android/internal/telephony/configupdate/ConfigParser.java index 5c3ac866df..f7691da908 100644 --- a/src/java/com/android/internal/telephony/configupdate/ConfigParser.java +++ b/src/java/com/android/internal/telephony/configupdate/ConfigParser.java @@ -18,6 +18,7 @@ package com.android.internal.telephony.configupdate; import android.annotation.NonNull; import android.annotation.Nullable; +import android.util.Log; import java.io.File; import java.io.FileInputStream; @@ -25,6 +26,7 @@ import java.io.IOException; import java.io.InputStream; public abstract class ConfigParser<T> { + private static final String TAG = "ConfigParser"; public static final int VERSION_UNKNOWN = -1; @@ -97,4 +99,13 @@ public abstract class ConfigParser<T> { * @param data the config data */ protected abstract void parseData(@Nullable byte[] data); + + + /** + * This API is used by CTS to override the version + */ + protected void overrideVersion(int version) { + mVersion = version; + Log.d(TAG, "overrideVersion: mVersion=" + mVersion); + } } diff --git a/src/java/com/android/internal/telephony/configupdate/TelephonyConfigUpdateInstallReceiver.java b/src/java/com/android/internal/telephony/configupdate/TelephonyConfigUpdateInstallReceiver.java index b299411ce4..60afc799c8 100644 --- a/src/java/com/android/internal/telephony/configupdate/TelephonyConfigUpdateInstallReceiver.java +++ b/src/java/com/android/internal/telephony/configupdate/TelephonyConfigUpdateInstallReceiver.java @@ -52,16 +52,21 @@ public class TelephonyConfigUpdateInstallReceiver extends ConfigUpdateInstallRec @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE) protected static final String NEW_CONFIG_CONTENT_PATH = "new_telephony_config.pb"; protected static final String VALID_CONFIG_CONTENT_PATH = "valid_telephony_config.pb"; + private static final String BACKUP_CONTENT_PATH = "backup_telephony_config.pb"; + protected static final String UPDATE_METADATA_PATH = "metadata/"; public static final String VERSION = "version"; + public static final String BACKUP_VERSION = "backup_version"; private ConcurrentHashMap<Executor, Callback> mCallbackHashMap = new ConcurrentHashMap<>(); @NonNull private final Object mConfigParserLock = new Object(); @GuardedBy("mConfigParserLock") private ConfigParser mConfigParser; - @NonNull private final ConfigUpdaterMetricsStats mConfigUpdaterMetricsStats; + @NonNull + private final ConfigUpdaterMetricsStats mConfigUpdaterMetricsStats; + private int mOriginalVersion; public static TelephonyConfigUpdateInstallReceiver sReceiverAdaptorInstance = new TelephonyConfigUpdateInstallReceiver(); @@ -139,6 +144,10 @@ public class TelephonyConfigUpdateInstallReceiver extends ConfigUpdateInstallRec @Override @VisibleForTesting(visibility = VisibleForTesting.Visibility.PROTECTED) public void postInstall(Context context, Intent intent) { + postInstall(); + } + + private void postInstall() { Log.d(TAG, "Telephony config is updated in file partition"); ConfigParser newConfigParser = getNewConfigParser(DOMAIN_SATELLITE, @@ -311,11 +320,11 @@ public class TelephonyConfigUpdateInstallReceiver extends ConfigUpdateInstallRec new ByteArrayInputStream(Integer.toString(-1).getBytes())); // new_telephony_config.pb - writeUpdate(updateDir, updateContent, new ByteArrayInputStream(new byte[] {})); + writeUpdate(updateDir, updateContent, new ByteArrayInputStream(new byte[]{})); // valid_telephony_config.pb File validConfigContentPath = new File(updateDir, VALID_CONFIG_CONTENT_PATH); - writeUpdate(updateDir, validConfigContentPath, new ByteArrayInputStream(new byte[] {})); + writeUpdate(updateDir, validConfigContentPath, new ByteArrayInputStream(new byte[]{})); } catch (IOException e) { Log.e(TAG, "Failed to clean telephony config files: " + e); return false; @@ -327,4 +336,92 @@ public class TelephonyConfigUpdateInstallReceiver extends ConfigUpdateInstallRec } return true; } + + + /** + * This API is used by CTS to override the version of the config data + * + * @param reset Whether to restore the original version + * @param version The overriding version + * @return {@code true} if successful, {@code false} otherwise + */ + public boolean overrideVersion(boolean reset, int version) { + Log.d(TAG, "overrideVersion: reset=" + reset + ", version=" + version); + if (reset) { + version = mOriginalVersion; + if (!restoreContentData()) { + return false; + } + } else { + mOriginalVersion = version; + if (!backupContentData()) { + return false; + } + } + return overrideVersion(version); + } + + private boolean overrideVersion(int version) { + synchronized (getInstance().mConfigParserLock) { + try { + writeUpdate(updateDir, updateVersion, + new ByteArrayInputStream(Long.toString(version).getBytes())); + if (getInstance().mConfigParser != null) { + getInstance().mConfigParser.overrideVersion(version); + } + } catch (IOException e) { + Log.e(TAG, "overrideVersion: e=" + e); + return false; + } + return true; + } + } + + private boolean isFileExists(@NonNull String fileName) { + Log.d(TAG, "isFileExists"); + if (fileName == null) { + Log.d(TAG, "fileName cannot be null"); + return false; + } + File sourceFile = new File(UPDATE_DIR, fileName); + return sourceFile.exists() && sourceFile.isFile(); + } + + private boolean backupContentData() { + if (!isFileExists(VALID_CONFIG_CONTENT_PATH)) { + Log.d(TAG, VALID_CONFIG_CONTENT_PATH + " is not exit, no need to backup"); + return true; + } + if (!copySourceFileToTargetFile(VALID_CONFIG_CONTENT_PATH, BACKUP_CONTENT_PATH)) { + Log.e(TAG, "backupContentData: fail to backup the config data"); + return false; + } + if (!copySourceFileToTargetFile(UPDATE_METADATA_PATH + VERSION, + UPDATE_METADATA_PATH + BACKUP_VERSION)) { + Log.e(TAG, "bakpuackupContentData: fail to backup the version"); + return false; + } + Log.d(TAG, "backupContentData: backup success"); + return true; + } + + private boolean restoreContentData() { + if (!isFileExists(BACKUP_CONTENT_PATH)) { + Log.d(TAG, BACKUP_CONTENT_PATH + " is not exit, no need to restore"); + return true; + } + if (!copySourceFileToTargetFile(BACKUP_CONTENT_PATH, NEW_CONFIG_CONTENT_PATH)) { + Log.e(TAG, "restoreContentData: fail to restore the config data"); + return false; + } + if (!copySourceFileToTargetFile(UPDATE_METADATA_PATH + BACKUP_VERSION, + UPDATE_METADATA_PATH + VERSION)) { + Log.e(TAG, "restoreContentData: fail to restore the version"); + return false; + } + Log.d(TAG, "restoreContentData: populate the data to SatelliteController"); + postInstall(); + Log.d(TAG, "restoreContentData: success"); + return true; + } } diff --git a/src/java/com/android/internal/telephony/data/AccessNetworksManager.java b/src/java/com/android/internal/telephony/data/AccessNetworksManager.java index d364120f2c..65c462a411 100644 --- a/src/java/com/android/internal/telephony/data/AccessNetworksManager.java +++ b/src/java/com/android/internal/telephony/data/AccessNetworksManager.java @@ -56,7 +56,6 @@ import com.android.internal.telephony.IIntegerConsumer; import com.android.internal.telephony.Phone; import com.android.internal.telephony.SlidingWindowEventCounter; import com.android.internal.telephony.flags.FeatureFlags; -import com.android.internal.util.FunctionalUtils; import com.android.telephony.Rlog; import java.io.FileDescriptor; @@ -324,12 +323,6 @@ public class AccessNetworksManager extends Handler { public void onNetworkValidationRequested(@NetCapability int networkCapability, @NonNull IIntegerConsumer resultCodeCallback) { DataNetworkController dnc = mPhone.getDataNetworkController(); - if (!mFeatureFlags.networkValidation()) { - FunctionalUtils.ignoreRemoteException(resultCodeCallback::accept) - .accept(DataServiceCallback.RESULT_ERROR_UNSUPPORTED); - return; - } - log("onNetworkValidationRequested: networkCapability = [" + DataUtils.networkCapabilityToString(networkCapability) + "]"); diff --git a/src/java/com/android/internal/telephony/data/DataNetwork.java b/src/java/com/android/internal/telephony/data/DataNetwork.java index ff934638fb..d8e6f6afef 100644 --- a/src/java/com/android/internal/telephony/data/DataNetwork.java +++ b/src/java/com/android/internal/telephony/data/DataNetwork.java @@ -3919,11 +3919,6 @@ public class DataNetwork extends StateMachine { */ private void updateValidationStatus( @PreciseDataConnectionState.NetworkValidationStatus int networkValidationStatus) { - if (!mFlags.networkValidation()) { - // Do nothing, if network validation feature is disabled - return; - } - // if network validation status is changed, notify preciseDataConnectionState. if (mNetworkValidationStatus != networkValidationStatus) { log("updateValidationStatus:" diff --git a/src/java/com/android/internal/telephony/data/DataNetworkController.java b/src/java/com/android/internal/telephony/data/DataNetworkController.java index 86cfbbade0..6b916f2c7a 100644 --- a/src/java/com/android/internal/telephony/data/DataNetworkController.java +++ b/src/java/com/android/internal/telephony/data/DataNetworkController.java @@ -1640,8 +1640,14 @@ public class DataNetworkController extends Handler { evaluation.addDataDisallowedReason(DataDisallowedReason.DATA_CONFIG_NOT_READY); } - if (mFeatureFlags.dataServiceCheck() && !isDataServiceSupported(transport)) { - evaluation.addDataDisallowedReason(DataDisallowedReason.SERVICE_OPTION_NOT_SUPPORTED); + if (mFeatureFlags.dataServiceCheck()) { + NetworkRegistrationInfo nri = mServiceState.getNetworkRegistrationInfo( + NetworkRegistrationInfo.DOMAIN_PS, transport); + if (nri != null && !nri.getAvailableServices().contains( + NetworkRegistrationInfo.SERVICE_TYPE_DATA)) { + evaluation.addDataDisallowedReason( + DataDisallowedReason.SERVICE_OPTION_NOT_SUPPORTED); + } } // Check CS call state and see if concurrent voice/data is allowed. @@ -1977,9 +1983,14 @@ public class DataNetworkController extends Handler { evaluation.addDataDisallowedReason(DataDisallowedReason.CDMA_EMERGENCY_CALLBACK_MODE); } - if (mFeatureFlags.dataServiceCheck() - && !isDataServiceSupported(dataNetwork.getTransport())) { - evaluation.addDataDisallowedReason(DataDisallowedReason.SERVICE_OPTION_NOT_SUPPORTED); + if (mFeatureFlags.dataServiceCheck()) { + NetworkRegistrationInfo nri = mServiceState.getNetworkRegistrationInfo( + NetworkRegistrationInfo.DOMAIN_PS, dataNetwork.getTransport()); + if (nri != null && nri.isInService() && !nri.getAvailableServices().contains( + NetworkRegistrationInfo.SERVICE_TYPE_DATA)) { + evaluation.addDataDisallowedReason( + DataDisallowedReason.SERVICE_OPTION_NOT_SUPPORTED); + } } // If the network is satellite, then the network must be restricted. @@ -2177,21 +2188,6 @@ public class DataNetworkController extends Handler { } /** - * Check if the available services support data service. - * {@link NetworkRegistrationInfo#SERVICE_TYPE_DATA} service or not. - * - * @param transport The preferred transport type for the request. The transport here is - * WWAN/WLAN. - * @return {@code true} if data services is supported, otherwise {@code false}. - */ - private boolean isDataServiceSupported(@TransportType int transport) { - NetworkRegistrationInfo nri = mServiceState.getNetworkRegistrationInfo( - NetworkRegistrationInfo.DOMAIN_PS, transport); - return nri != null && nri.getAvailableServices().contains( - NetworkRegistrationInfo.SERVICE_TYPE_DATA); - } - - /** * Check if the transport from connectivity service can satisfy the network request. Note the * transport here is connectivity service's transport (Wifi, cellular, satellite, etc..), not * the widely used {@link AccessNetworkConstants#TRANSPORT_TYPE_WLAN WLAN}, @@ -3391,6 +3387,7 @@ public class DataNetworkController extends Handler { mPendingImsDeregDataNetworks.remove(dataNetwork); mDataRetryManager.cancelPendingHandoverRetry(dataNetwork); if (dataNetwork.isInternetSupported()) updateOverallInternetDataState(); + onPcoDataChanged(dataNetwork); if (dataNetwork.getNetworkCapabilities().hasCapability( NetworkCapabilities.NET_CAPABILITY_IMS)) { @@ -3802,6 +3799,22 @@ public class DataNetworkController extends Handler { } /** + * Check if network available services list is changed + * + * @param oldNri Previous network registration info. + * @param newNri Current network registration info. + * @return {@code true} if available services list is changed else return false + */ + private boolean areNetworkAvailableServicesChanged(@NonNull NetworkRegistrationInfo oldNri, + @NonNull NetworkRegistrationInfo newNri) { + List<Integer> oldAvailableServicesList = oldNri.getAvailableServices(); + List<Integer> newAvailableServicesList = newNri.getAvailableServices(); + + return !(oldAvailableServicesList.size() == newAvailableServicesList.size() + && oldAvailableServicesList.stream().allMatch(newAvailableServicesList::contains)); + } + + /** * Check if needed to re-evaluate the existing data networks. * * @param oldNri Previous network registration info. @@ -3817,6 +3830,10 @@ public class DataNetworkController extends Handler { return false; } + if (areNetworkAvailableServicesChanged(oldNri, newNri)) { + return true; + } + if (oldNri.getAccessNetworkTechnology() != newNri.getAccessNetworkTechnology() // Some CarrierConfig disallows vops in nonVops area for specified home/roaming. || (oldNri.isRoaming() != newNri.isRoaming())) { @@ -3862,6 +3879,10 @@ public class DataNetworkController extends Handler { return false; } + if (areNetworkAvailableServicesChanged(oldPsNri, newPsNri)) { + return true; + } + if (oldPsNri == null || oldPsNri.getAccessNetworkTechnology() != newPsNri.getAccessNetworkTechnology() || (!oldPsNri.isInService() && newPsNri.isInService()) diff --git a/src/java/com/android/internal/telephony/emergency/EmergencyNumberTracker.java b/src/java/com/android/internal/telephony/emergency/EmergencyNumberTracker.java index 06ebff287d..e2b36f00e0 100644 --- a/src/java/com/android/internal/telephony/emergency/EmergencyNumberTracker.java +++ b/src/java/com/android/internal/telephony/emergency/EmergencyNumberTracker.java @@ -187,10 +187,14 @@ public class EmergencyNumberTracker extends Handler { mFeatureFlags = featureFlags; mResources = ctx.getResources(); - if (TelephonyCapabilities.minimalTelephonyCdmCheck(mFeatureFlags) - && !ctx.getPackageManager().hasSystemFeature( - PackageManager.FEATURE_TELEPHONY_CALLING)) { - throw new UnsupportedOperationException("EmergencyNumberTracker requires calling"); + if (TelephonyCapabilities.minimalTelephonyCdmCheck(mFeatureFlags)) { + if (!ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_CALLING) + && !ctx.getPackageManager() + .hasSystemFeature(PackageManager.FEATURE_TELEPHONY_MESSAGING)) { + throw new UnsupportedOperationException( + "EmergencyNumberTracker requires telephony calling or messaging feature to" + + " be enabled"); + } } if (mPhone != null) { diff --git a/src/java/com/android/internal/telephony/emergency/EmergencyStateTracker.java b/src/java/com/android/internal/telephony/emergency/EmergencyStateTracker.java index 3c95d77afc..ee00e45dca 100644 --- a/src/java/com/android/internal/telephony/emergency/EmergencyStateTracker.java +++ b/src/java/com/android/internal/telephony/emergency/EmergencyStateTracker.java @@ -312,8 +312,24 @@ public class EmergencyStateTracker { maybeNotifyTransportChangeCompleted(emergencyType, false); if (emergencyType == EMERGENCY_TYPE_CALL) { - setIsInEmergencyCall(true); - completeEmergencyMode(emergencyType); + // If the emergency registration result(mLastEmergencyRegistrationResult) is + // null, it means that the emergency mode is not set properly on the modem. + // Therefore, based on the emergency registration result and current + // subscription status, the current phone is not available for an emergency + // call, so we check if an emergency call is possible through cross stack. + if (mFeatureFlags.performCrossStackRedialCheckForEmergencyCall() + && mLastEmergencyRegistrationResult == null + && mPhone != null + && !SubscriptionManager.isValidSubscriptionId(mPhone.getSubId()) + && needToSwitchPhone(mPhone)) { + Rlog.i(TAG, "setEmergencyMode failed: need to switch stacks."); + mEmergencyMode = MODE_EMERGENCY_NONE; + completeEmergencyMode(emergencyType, + DisconnectCause.EMERGENCY_PERM_FAILURE); + } else { + setIsInEmergencyCall(true); + completeEmergencyMode(emergencyType); + } // Case 1) When the emergency call is setting the emergency mode and // the emergency SMS is being sent, completes the SMS future also. @@ -861,23 +877,25 @@ public class EmergencyStateTracker { private void completeEmergencyMode(@EmergencyType int emergencyType, @DisconnectCauses int result) { + CompletableFuture<Integer> emergencyModeFuture = null; + if (emergencyType == EMERGENCY_TYPE_CALL) { - if (mCallEmergencyModeFuture != null && !mCallEmergencyModeFuture.isDone()) { - mCallEmergencyModeFuture.complete(result); - } + emergencyModeFuture = mCallEmergencyModeFuture; if (result != DisconnectCause.NOT_DISCONNECTED) { clearEmergencyCallInfo(); } } else if (emergencyType == EMERGENCY_TYPE_SMS) { - if (mSmsEmergencyModeFuture != null && !mSmsEmergencyModeFuture.isDone()) { - mSmsEmergencyModeFuture.complete(result); - } + emergencyModeFuture = mSmsEmergencyModeFuture; if (result != DisconnectCause.NOT_DISCONNECTED) { clearEmergencySmsInfo(); } } + + if (emergencyModeFuture != null && !emergencyModeFuture.isDone()) { + emergencyModeFuture.complete(result); + } } /** diff --git a/src/java/com/android/internal/telephony/metrics/MetricsCollector.java b/src/java/com/android/internal/telephony/metrics/MetricsCollector.java index a5df6e6d9a..7863b25405 100644 --- a/src/java/com/android/internal/telephony/metrics/MetricsCollector.java +++ b/src/java/com/android/internal/telephony/metrics/MetricsCollector.java @@ -1485,7 +1485,13 @@ public class MetricsCollector implements StatsManager.StatsPullAtomCallback { satelliteController.countOfP2PSmsAvailableNotificationShown, satelliteController.countOfP2PSmsAvailableNotificationRemoved, satelliteController.isNtnOnlyCarrier, - satelliteController.versionOfSatelliteAccessConfig); + satelliteController.versionOfSatelliteAccessConfig, + satelliteController.countOfIncomingDatagramTypeSosSmsSuccess, + satelliteController.countOfIncomingDatagramTypeSosSmsFail, + satelliteController.countOfOutgoingDatagramTypeSmsSuccess, + satelliteController.countOfOutgoingDatagramTypeSmsFail, + satelliteController.countOfIncomingDatagramTypeSmsSuccess, + satelliteController.countOfIncomingDatagramTypeSmsFail); } private static StatsEvent buildStatsEvent(SatelliteSession satelliteSession) { diff --git a/src/java/com/android/internal/telephony/metrics/PersistAtomsStorage.java b/src/java/com/android/internal/telephony/metrics/PersistAtomsStorage.java index 9f6af3f7a1..4346da4b79 100644 --- a/src/java/com/android/internal/telephony/metrics/PersistAtomsStorage.java +++ b/src/java/com/android/internal/telephony/metrics/PersistAtomsStorage.java @@ -786,6 +786,18 @@ public class PersistAtomsStorage { += stats.countOfP2PSmsAvailableNotificationRemoved; // Does not update isNtnOnlyCarrier due to it is a dimension field. existingStats.versionOfSatelliteAccessConfig = stats.versionOfSatelliteAccessConfig; + existingStats.countOfIncomingDatagramTypeSosSmsSuccess + += stats.countOfIncomingDatagramTypeSosSmsSuccess; + existingStats.countOfIncomingDatagramTypeSosSmsFail + += stats.countOfIncomingDatagramTypeSosSmsFail; + existingStats.countOfOutgoingDatagramTypeSmsSuccess + += stats.countOfOutgoingDatagramTypeSmsSuccess; + existingStats.countOfOutgoingDatagramTypeSmsFail + += stats.countOfOutgoingDatagramTypeSmsFail; + existingStats.countOfIncomingDatagramTypeSmsSuccess + += stats.countOfIncomingDatagramTypeSmsSuccess; + existingStats.countOfIncomingDatagramTypeSmsFail + += stats.countOfIncomingDatagramTypeSmsFail; } else { mAtoms.satelliteController = insertAtRandomPlace(mAtoms.satelliteController, stats, mMaxNumSatelliteStats); diff --git a/src/java/com/android/internal/telephony/metrics/SatelliteStats.java b/src/java/com/android/internal/telephony/metrics/SatelliteStats.java index c8bdb5976f..a99613acdc 100644 --- a/src/java/com/android/internal/telephony/metrics/SatelliteStats.java +++ b/src/java/com/android/internal/telephony/metrics/SatelliteStats.java @@ -40,6 +40,7 @@ import com.android.internal.telephony.satellite.SatelliteConstants; import com.android.telephony.Rlog; import java.util.Arrays; +import java.util.Objects; import java.util.Optional; /** Tracks Satellite metrics for each phone */ @@ -105,6 +106,12 @@ public class SatelliteStats { private final int mCountOfP2PSmsAvailableNotificationRemoved; private static boolean sIsNtnOnlyCarrier; private static int sVersionOfSatelliteAccessConfig; + private final int mCountOfIncomingDatagramTypeSosSmsSuccess; + private final int mCountOfIncomingDatagramTypeSosSmsFail; + private final int mCountOfOutgoingDatagramTypeSmsSuccess; + private final int mCountOfOutgoingDatagramTypeSmsFail; + private final int mCountOfIncomingDatagramTypeSmsSuccess; + private final int mCountOfIncomingDatagramTypeSmsFail; private SatelliteControllerParams(Builder builder) { this.mCountOfSatelliteServiceEnablementsSuccess = @@ -181,6 +188,17 @@ public class SatelliteStats { this.sVersionOfSatelliteAccessConfig = builder.mVersionOfSatelliteAccessConfig.get(); } + + this.mCountOfIncomingDatagramTypeSosSmsSuccess = + builder.mCountOfIncomingDatagramTypeSosSmsSuccess; + this.mCountOfIncomingDatagramTypeSosSmsFail = + builder.mCountOfIncomingDatagramTypeSosSmsFail; + this.mCountOfOutgoingDatagramTypeSmsSuccess = + builder.mCountOfOutgoingDatagramTypeSmsSuccess; + this.mCountOfOutgoingDatagramTypeSmsFail = builder.mCountOfOutgoingDatagramTypeSmsFail; + this.mCountOfIncomingDatagramTypeSmsSuccess = + builder.mCountOfIncomingDatagramTypeSmsSuccess; + this.mCountOfIncomingDatagramTypeSmsFail = builder.mCountOfIncomingDatagramTypeSmsFail; } public int getCountOfSatelliteServiceEnablementsSuccess() { @@ -331,6 +349,30 @@ public class SatelliteStats { return sVersionOfSatelliteAccessConfig; } + public int getCountOfIncomingDatagramTypeSosSmsSuccess() { + return mCountOfIncomingDatagramTypeSosSmsSuccess; + } + + public int getCountOfIncomingDatagramTypeSosSmsFail() { + return mCountOfIncomingDatagramTypeSosSmsFail; + } + + public int getCountOfOutgoingDatagramTypeSmsSuccess() { + return mCountOfOutgoingDatagramTypeSmsSuccess; + } + + public int getCountOfOutgoingDatagramTypeSmsFail() { + return mCountOfOutgoingDatagramTypeSmsFail; + } + + public int getCountOfIncomingDatagramTypeSmsSuccess() { + return mCountOfIncomingDatagramTypeSmsSuccess; + } + + public int getCountOfIncomingDatagramTypeSmsFail() { + return mCountOfIncomingDatagramTypeSmsFail; + } + /** * A builder class to create {@link SatelliteControllerParams} data structure class */ @@ -372,6 +414,12 @@ public class SatelliteStats { private int mCountOfP2PSmsAvailableNotificationRemoved = 0; private Optional<Boolean> mIsNtnOnlyCarrier = Optional.empty(); private Optional<Integer> mVersionOfSatelliteAccessConfig = Optional.empty(); + private int mCountOfIncomingDatagramTypeSosSmsSuccess; + private int mCountOfIncomingDatagramTypeSosSmsFail; + private int mCountOfOutgoingDatagramTypeSmsSuccess; + private int mCountOfOutgoingDatagramTypeSmsFail; + private int mCountOfIncomingDatagramTypeSmsSuccess; + private int mCountOfIncomingDatagramTypeSmsFail; /** * Sets countOfSatelliteServiceEnablementsSuccess value of {@link SatelliteController} @@ -740,6 +788,67 @@ public class SatelliteStats { } /** + * Sets countOfIncomingDatagramTypeSosSmsSuccess value of {@link SatelliteController} + * atom then returns Builder class + */ + public Builder setCountOfIncomingDatagramTypeSosSmsSuccess( + int countOfIncomingDatagramTypeSosSmsSuccess) { + this.mCountOfIncomingDatagramTypeSosSmsSuccess = + countOfIncomingDatagramTypeSosSmsSuccess; + return this; + } + + /** + * Sets countOfIncomingDatagramTypeSosSmsFail value of {@link SatelliteController} atom + * then returns Builder class + */ + public Builder setCountOfIncomingDatagramTypeSosSmsFail( + int countOfIncomingDatagramTypeSosSmsFail) { + this.mCountOfIncomingDatagramTypeSosSmsFail = countOfIncomingDatagramTypeSosSmsFail; + return this; + } + + /** + * Sets countOfOutgoingDatagramTypeSmsSuccess value of {@link SatelliteController} atom + * then returns Builder class + */ + public Builder setCountOfOutgoingDatagramTypeSmsSuccess( + int countOfOutgoingDatagramTypeSmsSuccess) { + this.mCountOfOutgoingDatagramTypeSmsSuccess = countOfOutgoingDatagramTypeSmsSuccess; + return this; + } + + /** + * Sets countOfOutgoingDatagramTypeSmsFail value of {@link SatelliteController} atom + * then returns Builder class + */ + public Builder setCountOfOutgoingDatagramTypeSmsFail( + int countOfOutgoingDatagramTypeSmsFail) { + this.mCountOfOutgoingDatagramTypeSmsFail = countOfOutgoingDatagramTypeSmsFail; + return this; + } + + /** + * Sets countOfIncomingDatagramTypeSmsSuccess value of {@link SatelliteController} atom + * then returns Builder class + */ + public Builder setCountOfIncomingDatagramTypeSmsSuccess( + int countOfIncomingDatagramTypeSmsSuccess) { + this.mCountOfIncomingDatagramTypeSmsSuccess = countOfIncomingDatagramTypeSmsSuccess; + return this; + } + + /** + * Sets countOfIncomingDatagramTypeSmsFail value of {@link SatelliteController} atom + * then returns Builder class + */ + public Builder setCountOfIncomingDatagramTypeSmsFail( + int countOfIncomingDatagramTypeSmsFail) { + this.mCountOfIncomingDatagramTypeSmsFail = countOfIncomingDatagramTypeSmsFail; + return this; + } + + /** * Returns ControllerParams, which contains whole component of * {@link SatelliteController} atom */ @@ -799,6 +908,16 @@ public class SatelliteStats { + ", countOfP2PSmsAvailableNotificationRemoved=" + mCountOfP2PSmsAvailableNotificationRemoved + ", versionOfSatelliteAccessConfig=" + sVersionOfSatelliteAccessConfig + + ", countOfIncomingDatagramTypeSosSmsSuccess=" + + mCountOfIncomingDatagramTypeSosSmsSuccess + + ", countOfIncomingDatagramTypeSosSmsFail=" + + mCountOfIncomingDatagramTypeSosSmsFail + + ", countOfOutgoingDatagramTypeSmsSuccess=" + + mCountOfOutgoingDatagramTypeSmsSuccess + + ", countOfOutgoingDatagramTypeSmsFail=" + mCountOfOutgoingDatagramTypeSmsFail + + ", countOfIncomingDatagramTypeSmsSuccess=" + + mCountOfIncomingDatagramTypeSmsSuccess + + ", countOfIncomingDatagramTypeSmsFail=" + mCountOfIncomingDatagramTypeSmsFail + ")"; } } @@ -2053,6 +2172,7 @@ public class SatelliteStats { */ public Builder setSupportedSatelliteServices(int[] supportedSatelliteServices) { this.mSupportedSatelliteServices = supportedSatelliteServices; + Arrays.sort(this.mSupportedSatelliteServices); return this; } @@ -2182,7 +2302,6 @@ public class SatelliteStats { return mConfigDataSource; } - public int getCountOfEntitlementStatusQueryRequest() { return mCountOfEntitlementStatusQueryRequest; } @@ -2344,6 +2463,37 @@ public class SatelliteStats { } @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + CarrierRoamingSatelliteControllerStatsParams that = + (CarrierRoamingSatelliteControllerStatsParams) obj; + return mConfigDataSource == that.getConfigDataSource() + && mCountOfEntitlementStatusQueryRequest + == that.getCountOfEntitlementStatusQueryRequest() + && mCountOfSatelliteConfigUpdateRequest + == that.getCountOfSatelliteConfigUpdateRequest() + && mCountOfSatelliteNotificationDisplayed + == that.getCountOfSatelliteNotificationDisplayed() + && sSatelliteSessionGapMinSec == that.getSatelliteSessionGapMinSec() + && sSatelliteSessionGapAvgSec == that.getSatelliteSessionGapAvgSec() + && sSatelliteSessionGapMaxSec == that.getSatelliteSessionGapMaxSec() + && sCarrierId == that.getCarrierId() + && sIsDeviceEntitled == that.isDeviceEntitled() + && sIsMultiSim == that.isMultiSim() + && mCountOfSatelliteSessions == that.getCountOfSatelliteSessions(); + } + + @Override + public int hashCode() { + return Objects.hash(mConfigDataSource, mCountOfEntitlementStatusQueryRequest, + mCountOfSatelliteConfigUpdateRequest, mCountOfSatelliteNotificationDisplayed, + sSatelliteSessionGapMinSec, sSatelliteSessionGapAvgSec, + sSatelliteSessionGapMaxSec, sCarrierId, sIsDeviceEntitled, sIsMultiSim, + mCountOfSatelliteSessions); + } + + @Override public String toString() { return "CarrierRoamingSatelliteControllerStatsParams(" + "configDataSource=" + mConfigDataSource @@ -2495,6 +2645,7 @@ public class SatelliteStats { */ public Builder setEntitlementServiceType(int[] entitlementServiceType) { this.mEntitlementServiceType = entitlementServiceType; + Arrays.sort(this.mEntitlementServiceType); return this; } @@ -2890,6 +3041,16 @@ public class SatelliteStats { param.getCountOfP2PSmsAvailableNotificationRemoved(); proto.isNtnOnlyCarrier = param.isNtnOnlyCarrier(); proto.versionOfSatelliteAccessConfig = param.getVersionSatelliteAccessConfig(); + proto.countOfIncomingDatagramTypeSosSmsSuccess = + param.getCountOfIncomingDatagramTypeSosSmsSuccess(); + proto.countOfIncomingDatagramTypeSosSmsFail = + param.getCountOfIncomingDatagramTypeSosSmsFail(); + proto.countOfOutgoingDatagramTypeSmsSuccess = + param.getCountOfOutgoingDatagramTypeSmsSuccess(); + proto.countOfOutgoingDatagramTypeSmsFail = param.getCountOfOutgoingDatagramTypeSmsFail(); + proto.countOfIncomingDatagramTypeSmsSuccess = + param.getCountOfIncomingDatagramTypeSmsSuccess(); + proto.countOfIncomingDatagramTypeSmsFail = param.getCountOfIncomingDatagramTypeSmsFail(); if (DBG) logd("onSatelliteControllerMetrics" + param); mAtomsStorage.addSatelliteControllerStats(proto); } diff --git a/src/java/com/android/internal/telephony/satellite/DatagramDispatcher.java b/src/java/com/android/internal/telephony/satellite/DatagramDispatcher.java index 0b8589306f..bc7d5d142f 100644 --- a/src/java/com/android/internal/telephony/satellite/DatagramDispatcher.java +++ b/src/java/com/android/internal/telephony/satellite/DatagramDispatcher.java @@ -767,9 +767,11 @@ public class DatagramDispatcher extends Handler { if (resultCode == SATELLITE_RESULT_SUCCESS) { long smsTransmissionTime = mSmsTransmissionStartTime > 0 ? (System.currentTimeMillis() - mSmsTransmissionStartTime) : 0; + mControllerMetricsStats.reportOutgoingDatagramSuccessCount(datagramType, false); mSessionMetricsStats.addCountOfSuccessfulOutgoingDatagram( datagramType, smsTransmissionTime); } else { + mControllerMetricsStats.reportOutgoingDatagramFailCount(datagramType, false); mSessionMetricsStats.addCountOfFailedOutgoingDatagram( datagramType, resultCode); } diff --git a/src/java/com/android/internal/telephony/satellite/SatelliteConstants.java b/src/java/com/android/internal/telephony/satellite/SatelliteConstants.java index 866969fd16..7fbba14b2f 100644 --- a/src/java/com/android/internal/telephony/satellite/SatelliteConstants.java +++ b/src/java/com/android/internal/telephony/satellite/SatelliteConstants.java @@ -113,14 +113,20 @@ public class SatelliteConstants { public static final int TRIGGERING_EVENT_EXTERNAL_REQUEST = 1; // Satellite Access Controller has been triggered by an MCC change event. public static final int TRIGGERING_EVENT_MCC_CHANGED = 2; - //Satellite Access Controller has been triggered due to the location setting being enabled. + // Satellite Access Controller has been triggered due to the location setting being enabled. public static final int TRIGGERING_EVENT_LOCATION_SETTINGS_ENABLED = 3; + // Satellite Access Controller has been triggered due to the location setting being disabled. + public static final int TRIGGERING_EVENT_LOCATION_SETTINGS_DISABLED = 4; + // Satellite Access Controller has been triggered due to the config data updated. + public static final int TRIGGERING_EVENT_CONFIG_DATA_UPDATED = 5; @IntDef(prefix = {"TRIGGERING_EVENT_"}, value = { TRIGGERING_EVENT_UNKNOWN, TRIGGERING_EVENT_EXTERNAL_REQUEST, TRIGGERING_EVENT_MCC_CHANGED, - TRIGGERING_EVENT_LOCATION_SETTINGS_ENABLED + TRIGGERING_EVENT_LOCATION_SETTINGS_ENABLED, + TRIGGERING_EVENT_LOCATION_SETTINGS_DISABLED, + TRIGGERING_EVENT_CONFIG_DATA_UPDATED }) @Retention(RetentionPolicy.SOURCE) public @interface TriggeringEvent {} diff --git a/src/java/com/android/internal/telephony/satellite/SatelliteController.java b/src/java/com/android/internal/telephony/satellite/SatelliteController.java index 803d5454ed..93d222b512 100644 --- a/src/java/com/android/internal/telephony/satellite/SatelliteController.java +++ b/src/java/com/android/internal/telephony/satellite/SatelliteController.java @@ -2167,7 +2167,8 @@ public class SatelliteController extends Handler { int defaultSubId = mSubscriptionManagerService.getDefaultSubId(); boolean isEntitled = mSatelliteEntitlementStatusPerCarrier.get(defaultSubId, false); - mCarrierRoamingSatelliteControllerStats.reportIsDeviceEntitled(isEntitled); + mCarrierRoamingSatelliteControllerStats.reportIsDeviceEntitled(defaultSubId, + isEntitled); } sendMessageDelayed(obtainMessage( EVENT_WAIT_FOR_REPORT_ENTITLED_TO_MERTICS_HYSTERESIS_TIMED_OUT), @@ -2690,7 +2691,7 @@ public class SatelliteController extends Handler { * * @return {@code true} if the satellite modem is enabled and {@code false} otherwise. */ - private boolean isSatelliteEnabled() { + public boolean isSatelliteEnabled() { synchronized (mIsSatelliteEnabledLock) { if (mIsSatelliteEnabled == null) return false; return mIsSatelliteEnabled; @@ -2702,7 +2703,7 @@ public class SatelliteController extends Handler { * * @return {@code true} if the satellite modem is being enabled and {@code false} otherwise. */ - private boolean isSatelliteBeingEnabled() { + public boolean isSatelliteBeingEnabled() { if (mSatelliteSessionController != null && mSatelliteSessionController.isInEnablingState()) { return true; @@ -3874,6 +3875,9 @@ public class SatelliteController extends Handler { } else { logd("onSmsReceived: DatagramController is not initialized"); } + + mControllerMetricsStats.reportIncomingNtnSmsCount( + SatelliteManager.SATELLITE_RESULT_SUCCESS); } /** @@ -4395,7 +4399,8 @@ public class SatelliteController extends Handler { if (mSatelliteEntitlementStatusPerCarrier.get(subId, false) != entitlementEnabled) { logd("update the carrier satellite enabled to " + entitlementEnabled); mSatelliteEntitlementStatusPerCarrier.put(subId, entitlementEnabled); - mCarrierRoamingSatelliteControllerStats.reportIsDeviceEntitled(entitlementEnabled); + mCarrierRoamingSatelliteControllerStats.reportIsDeviceEntitled(subId, + entitlementEnabled); if (hasMessages(EVENT_WAIT_FOR_REPORT_ENTITLED_TO_MERTICS_HYSTERESIS_TIMED_OUT)) { removeMessages(EVENT_WAIT_FOR_REPORT_ENTITLED_TO_MERTICS_HYSTERESIS_TIMED_OUT); sendMessageDelayed(obtainMessage( @@ -5486,7 +5491,7 @@ public class SatelliteController extends Handler { if (!entitlementPlmnList.isEmpty()) { mMergedPlmnListPerCarrier.put(subId, entitlementPlmnList); plogd("mMergedPlmnListPerCarrier is updated by Entitlement"); - mCarrierRoamingSatelliteControllerStats.reportConfigDataSource( + mCarrierRoamingSatelliteControllerStats.reportConfigDataSource(subId, SatelliteConstants.CONFIG_DATA_SOURCE_ENTITLEMENT); return; } @@ -5501,7 +5506,7 @@ public class SatelliteController extends Handler { plogd("mMergedPlmnListPerCarrier is updated by ConfigUpdater : " + String.join(",", plmnList)); mMergedPlmnListPerCarrier.put(subId, plmnList); - mCarrierRoamingSatelliteControllerStats.reportConfigDataSource( + mCarrierRoamingSatelliteControllerStats.reportConfigDataSource(subId, SatelliteConstants.CONFIG_DATA_SOURCE_CONFIG_UPDATER); return; } @@ -5514,7 +5519,7 @@ public class SatelliteController extends Handler { .stream().toList(); plogd("mMergedPlmnListPerCarrier is updated by carrier config: " + String.join(",", carrierPlmnList)); - mCarrierRoamingSatelliteControllerStats.reportConfigDataSource( + mCarrierRoamingSatelliteControllerStats.reportConfigDataSource(subId, SatelliteConstants.CONFIG_DATA_SOURCE_CARRIER_CONFIG); } else { carrierPlmnList = new ArrayList<>(); @@ -6005,7 +6010,7 @@ public class SatelliteController extends Handler { } boolean result = entitlementStatus.equals("1"); mSatelliteEntitlementStatusPerCarrier.put(subId, result); - mCarrierRoamingSatelliteControllerStats.reportIsDeviceEntitled(result); + mCarrierRoamingSatelliteControllerStats.reportIsDeviceEntitled(subId, result); if (hasMessages(EVENT_WAIT_FOR_REPORT_ENTITLED_TO_MERTICS_HYSTERESIS_TIMED_OUT)) { removeMessages(EVENT_WAIT_FOR_REPORT_ENTITLED_TO_MERTICS_HYSTERESIS_TIMED_OUT); sendMessageDelayed(obtainMessage( @@ -6371,14 +6376,14 @@ public class SatelliteController extends Handler { sessionStats.onSessionStart(phone.getCarrierId(), phone, supported_satellite_services, dataPolicy); mCarrierRoamingSatelliteSessionStatsMap.put(subId, sessionStats); - mCarrierRoamingSatelliteControllerStats.onSessionStart(); + mCarrierRoamingSatelliteControllerStats.onSessionStart(subId); } else if (lastNotifiedNtnMode && !currNtnMode) { // Log satellite session end CarrierRoamingSatelliteSessionStats sessionStats = mCarrierRoamingSatelliteSessionStatsMap.get(subId); sessionStats.onSessionEnd(); mCarrierRoamingSatelliteSessionStatsMap.remove(subId); - mCarrierRoamingSatelliteControllerStats.onSessionEnd(); + mCarrierRoamingSatelliteControllerStats.onSessionEnd(subId); } } } @@ -7051,7 +7056,7 @@ public class SatelliteController extends Handler { Context.RECEIVER_EXPORTED); mIsNotificationShowing = true; - mCarrierRoamingSatelliteControllerStats.reportCountOfSatelliteNotificationDisplayed(); + mCarrierRoamingSatelliteControllerStats.reportCountOfSatelliteNotificationDisplayed(subId); mCarrierRoamingSatelliteControllerStats.reportCarrierId(getSatelliteCarrierId()); mSessionMetricsStats.addCountOfSatelliteNotificationDisplayed(); } diff --git a/src/java/com/android/internal/telephony/satellite/SatelliteSOSMessageRecommender.java b/src/java/com/android/internal/telephony/satellite/SatelliteSOSMessageRecommender.java index 03c294b141..d33f8280da 100644 --- a/src/java/com/android/internal/telephony/satellite/SatelliteSOSMessageRecommender.java +++ b/src/java/com/android/internal/telephony/satellite/SatelliteSOSMessageRecommender.java @@ -307,7 +307,7 @@ public class SatelliteSOSMessageRecommender extends Handler { private void handleSatelliteProvisionStateChangedEvent(boolean provisioned) { if (!provisioned - && !isSatelliteConnectedViaCarrierWithinHysteresisTime()) { + && !isSatelliteEmergencyMessagingViaCarrierAvailable()) { cleanUpResources(false); } } @@ -347,7 +347,7 @@ public class SatelliteSOSMessageRecommender extends Handler { if (!isCellularAvailable && isSatelliteAllowed() && ((isDeviceProvisioned() && isSatelliteAllowedByReasons()) - || isSatelliteConnectedViaCarrierWithinHysteresisTime()) + || isSatelliteEmergencyMessagingViaCarrierAvailable()) && shouldTrackCall(mEmergencyConnection.getState())) { plogd("handleTimeoutEvent: Sent EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer"); Bundle extras = createExtraBundleForEventDisplayEmergencyMessage( @@ -367,7 +367,7 @@ public class SatelliteSOSMessageRecommender extends Handler { private boolean isSatelliteAllowed() { synchronized (mLock) { - if (isSatelliteConnectedViaCarrierWithinHysteresisTime()) return true; + if (isSatelliteEmergencyMessagingViaCarrierAvailable()) return true; return mIsSatelliteAllowedForCurrentLocation; } } @@ -388,7 +388,12 @@ public class SatelliteSOSMessageRecommender extends Handler { return satelliteProvisioned != null ? satelliteProvisioned : false; } - private boolean isSatelliteConnectedViaCarrierWithinHysteresisTime() { + private boolean isSatelliteEmergencyMessagingViaCarrierAvailable() { + if (!mSatelliteController.isSatelliteEmergencyMessagingSupportedViaCarrier()) { + plogd("isSatelliteEmergencyMessagingViaCarrierAvailable: false, " + + "device does not support satellite emergency messaging via carrier"); + return false; + } return mIsSatelliteConnectedViaCarrierWithinHysteresisTime.get(); } @@ -567,7 +572,7 @@ public class SatelliteSOSMessageRecommender extends Handler { } private void selectEmergencyCallWaitForConnectionTimeoutDuration() { - if (isSatelliteConnectedViaCarrierWithinHysteresisTime()) { + if (isSatelliteEmergencyMessagingViaCarrierAvailable()) { int satelliteSubId = mSubIdOfSatelliteConnectedViaCarrierWithinHysteresisTime.get(); mTimeoutMillis = mSatelliteController.getCarrierEmergencyCallWaitForConnectionTimeoutMillis( @@ -769,7 +774,7 @@ public class SatelliteSOSMessageRecommender extends Handler { @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE) public int getEmergencyCallToSatelliteHandoverType() { - if (isSatelliteConnectedViaCarrierWithinHysteresisTime()) { + if (isSatelliteEmergencyMessagingViaCarrierAvailable()) { int satelliteSubId = mSubIdOfSatelliteConnectedViaCarrierWithinHysteresisTime.get(); return mSatelliteController.getCarrierRoamingNtnEmergencyCallToSatelliteHandoverType( satelliteSubId); @@ -841,6 +846,8 @@ public class SatelliteSOSMessageRecommender extends Handler { private void updateSatelliteConnectedViaCarrierWithinHysteresisTimeState() { Pair<Boolean, Integer> satelliteConnectedState = mSatelliteController.isSatelliteConnectedViaCarrierWithinHysteresisTime(); + plogd("updateSatelliteConnectedViaCarrierWithinHysteresisTimeState: subId=" + + satelliteConnectedState.second + ", connected="+ satelliteConnectedState.first); mIsSatelliteConnectedViaCarrierWithinHysteresisTime.set(satelliteConnectedState.first); if (satelliteConnectedState.first) { mSubIdOfSatelliteConnectedViaCarrierWithinHysteresisTime.set( diff --git a/src/java/com/android/internal/telephony/satellite/metrics/CarrierRoamingSatelliteControllerStats.java b/src/java/com/android/internal/telephony/satellite/metrics/CarrierRoamingSatelliteControllerStats.java index 8d7804551c..642f39855b 100644 --- a/src/java/com/android/internal/telephony/satellite/metrics/CarrierRoamingSatelliteControllerStats.java +++ b/src/java/com/android/internal/telephony/satellite/metrics/CarrierRoamingSatelliteControllerStats.java @@ -17,26 +17,35 @@ package com.android.internal.telephony.satellite.metrics; import android.annotation.NonNull; +import android.telephony.SubscriptionManager; +import android.telephony.TelephonyManager; import android.util.Log; import com.android.internal.annotations.VisibleForTesting; +import com.android.internal.telephony.Phone; +import com.android.internal.telephony.PhoneFactory; import com.android.internal.telephony.metrics.SatelliteStats; import com.android.internal.telephony.satellite.SatelliteConstants; import com.android.internal.telephony.subscription.SubscriptionManagerService; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class CarrierRoamingSatelliteControllerStats { private static final String TAG = CarrierRoamingSatelliteControllerStats.class.getSimpleName(); private static CarrierRoamingSatelliteControllerStats sInstance = null; private static final int ADD_COUNT = 1; private SatelliteStats mSatelliteStats; - private List<Long> mSessionStartTimeList; - private List<Long> mSessionEndTimeList; + /** Map key subId, value: list of session start time in milliseconds */ + private Map<Integer, List<Long>> mSessionStartTimeMap = new HashMap<>(); + /** Map key subId, list of session end time in milliseconds */ + private Map<Integer, List<Long>> mSessionEndTimeMap = new HashMap<>(); - private CarrierRoamingSatelliteControllerStats() { + @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE) + public CarrierRoamingSatelliteControllerStats() { mSatelliteStats = SatelliteStats.getInstance(); resetSessionGapLists(); } @@ -57,19 +66,22 @@ public class CarrierRoamingSatelliteControllerStats { } /** Report config data source */ - public void reportConfigDataSource(@SatelliteConstants.ConfigDataSource int configDataSource) { + public void reportConfigDataSource(int subId, + @SatelliteConstants.ConfigDataSource int configDataSource) { mSatelliteStats.onCarrierRoamingSatelliteControllerStatsMetrics( new SatelliteStats.CarrierRoamingSatelliteControllerStatsParams.Builder() .setConfigDataSource(configDataSource) + .setCarrierId(getCarrierIdFromSubscription(subId)) .setIsMultiSim(isMultiSim()) .build()); } /** Report count of entitlement status query request */ - public void reportCountOfEntitlementStatusQueryRequest() { + public void reportCountOfEntitlementStatusQueryRequest(int subId) { mSatelliteStats.onCarrierRoamingSatelliteControllerStatsMetrics( new SatelliteStats.CarrierRoamingSatelliteControllerStatsParams.Builder() .setCountOfEntitlementStatusQueryRequest(ADD_COUNT) + .setCarrierId(getCarrierIdFromSubscription(subId)) .setIsMultiSim(isMultiSim()) .build()); } @@ -84,10 +96,11 @@ public class CarrierRoamingSatelliteControllerStats { } /** Report count of satellite notification displayed */ - public void reportCountOfSatelliteNotificationDisplayed() { + public void reportCountOfSatelliteNotificationDisplayed(int subId) { mSatelliteStats.onCarrierRoamingSatelliteControllerStatsMetrics( new SatelliteStats.CarrierRoamingSatelliteControllerStatsParams.Builder() .setCountOfSatelliteNotificationDisplayed(ADD_COUNT) + .setCarrierId(getCarrierIdFromSubscription(subId)) .setIsMultiSim(isMultiSim()) .build()); } @@ -102,29 +115,38 @@ public class CarrierRoamingSatelliteControllerStats { } /** Capture whether the device is satellite entitled or not */ - public void reportIsDeviceEntitled(boolean isDeviceEntitled) { + public void reportIsDeviceEntitled(int subId, boolean isDeviceEntitled) { mSatelliteStats.onCarrierRoamingSatelliteControllerStatsMetrics( new SatelliteStats.CarrierRoamingSatelliteControllerStatsParams.Builder() .setIsDeviceEntitled(isDeviceEntitled) + .setCarrierId(getCarrierIdFromSubscription(subId)) .setIsMultiSim(isMultiSim()) .build()); } /** Log carrier roaming satellite session start */ - public void onSessionStart() { - mSessionStartTimeList.add(getCurrentTime()); + public void onSessionStart(int subId) { + List<Long> sessionStartTimeListForSubscription = mSessionStartTimeMap.getOrDefault(subId, + new ArrayList<>()); + sessionStartTimeListForSubscription.add(getCurrentTime()); + mSessionStartTimeMap.put(subId, sessionStartTimeListForSubscription); + mSatelliteStats.onCarrierRoamingSatelliteControllerStatsMetrics( new SatelliteStats.CarrierRoamingSatelliteControllerStatsParams.Builder() + .setCarrierId(getCarrierIdFromSubscription(subId)) .increaseCountOfSatelliteSessions() .build()); } /** Log carrier roaming satellite session end */ - public void onSessionEnd() { - mSessionEndTimeList.add(getCurrentTime()); - - int numberOfSatelliteSessions = getNumberOfSatelliteSessions(); - List<Integer> sessionGapList = getSatelliteSessionGapList(numberOfSatelliteSessions); + public void onSessionEnd(int subId) { + List<Long> sessionEndTimeListForSubscription = mSessionEndTimeMap.getOrDefault(subId, + new ArrayList<>()); + sessionEndTimeListForSubscription.add(getCurrentTime()); + mSessionEndTimeMap.put(subId, sessionEndTimeListForSubscription); + + int numberOfSatelliteSessions = getNumberOfSatelliteSessions(subId); + List<Integer> sessionGapList = getSatelliteSessionGapList(subId, numberOfSatelliteSessions); int satelliteSessionGapMinSec = 0; int satelliteSessionGapMaxSec = 0; if (!sessionGapList.isEmpty()) { @@ -137,29 +159,34 @@ public class CarrierRoamingSatelliteControllerStats { .setSatelliteSessionGapMinSec(satelliteSessionGapMinSec) .setSatelliteSessionGapAvgSec(getAvg(sessionGapList)) .setSatelliteSessionGapMaxSec(satelliteSessionGapMaxSec) + .setCarrierId(getCarrierIdFromSubscription(subId)) .setIsMultiSim(isMultiSim()) .build()); } /** Atom is pulled once per day. Reset session gap lists after the atom is pulled. */ public void resetSessionGapLists() { - mSessionStartTimeList = new ArrayList<>(); - mSessionEndTimeList = new ArrayList<>(); + mSessionStartTimeMap = new HashMap<>(); + mSessionEndTimeMap = new HashMap<>(); } - private int getNumberOfSatelliteSessions() { - return Math.min(mSessionStartTimeList.size(), mSessionEndTimeList.size()); + private int getNumberOfSatelliteSessions(int subId) { + return Math.min(mSessionStartTimeMap.getOrDefault(subId, new ArrayList<>()).size(), + mSessionEndTimeMap.getOrDefault(subId, new ArrayList<>()).size()); } - private List<Integer> getSatelliteSessionGapList(int numberOfSatelliteSessions) { + private List<Integer> getSatelliteSessionGapList(int subId, int numberOfSatelliteSessions) { if (numberOfSatelliteSessions == 0) { return new ArrayList<>(); } + List<Long> sessionStartTimeList = mSessionStartTimeMap.getOrDefault(subId, + new ArrayList<>()); + List<Long> sessionEndTimeList = mSessionEndTimeMap.getOrDefault(subId, new ArrayList<>()); List<Integer> sessionGapList = new ArrayList<>(); for (int i = 1; i < numberOfSatelliteSessions; i++) { - long prevSessionEndTime = mSessionEndTimeList.get(i - 1); - long currentSessionStartTime = mSessionStartTimeList.get(i); + long prevSessionEndTime = sessionEndTimeList.get(i - 1); + long currentSessionStartTime = sessionStartTimeList.get(i); if (currentSessionStartTime > prevSessionEndTime && prevSessionEndTime > 0) { sessionGapList.add((int) ( (currentSessionStartTime - prevSessionEndTime) / 1000)); @@ -181,7 +208,8 @@ public class CarrierRoamingSatelliteControllerStats { return total / list.size(); } - private long getCurrentTime() { + @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE) + protected long getCurrentTime() { return System.currentTimeMillis(); } @@ -190,6 +218,14 @@ public class CarrierRoamingSatelliteControllerStats { return SubscriptionManagerService.getInstance().getActiveSubIdList(true).length > 1; } + /** Returns the carrier ID of the given subscription id. */ + @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE) + protected int getCarrierIdFromSubscription(int subId) { + int phoneId = SubscriptionManager.getPhoneId(subId); + Phone phone = PhoneFactory.getPhone(phoneId); + return phone != null ? phone.getCarrierId() : TelephonyManager.UNKNOWN_CARRIER_ID; + } + private static void logd(@NonNull String log) { Log.d(TAG, log); } diff --git a/src/java/com/android/internal/telephony/satellite/metrics/ControllerMetricsStats.java b/src/java/com/android/internal/telephony/satellite/metrics/ControllerMetricsStats.java index aef0808b59..5d0fa9d2f6 100644 --- a/src/java/com/android/internal/telephony/satellite/metrics/ControllerMetricsStats.java +++ b/src/java/com/android/internal/telephony/satellite/metrics/ControllerMetricsStats.java @@ -145,6 +145,9 @@ public class ControllerMetricsStats { builder.setCountOfDatagramTypeLocationSharingSuccess(ADD_COUNT); } else if (datagramType == SatelliteManager.DATAGRAM_TYPE_KEEP_ALIVE) { builder.setCountOfDatagramTypeKeepAliveSuccess(ADD_COUNT).build(); + } else if (datagramType == SatelliteManager.DATAGRAM_TYPE_SMS) { + builder.setCountOfDatagramTypeSosSmsSuccess(ADD_COUNT) + .setCountOfOutgoingDatagramTypeSmsSuccess(ADD_COUNT); } } @@ -169,6 +172,9 @@ public class ControllerMetricsStats { builder.setCountOfDatagramTypeLocationSharingFail(ADD_COUNT); } else if (datagramType == SatelliteManager.DATAGRAM_TYPE_KEEP_ALIVE) { builder.setCountOfDatagramTypeKeepAliveFail(ADD_COUNT); + } else if (datagramType == SatelliteManager.DATAGRAM_TYPE_SMS) { + builder.setCountOfDatagramTypeSosSmsFail(ADD_COUNT) + .setCountOfOutgoingDatagramTypeSmsFail(ADD_COUNT); } } @@ -177,7 +183,7 @@ public class ControllerMetricsStats { mSatelliteStats.onSatelliteControllerMetrics(controllerParam); } - /** Report a counter when an attempt for incoming datagram is failed */ + /** Increase counters for successful and failed incoming datagram attempts */ public void reportIncomingDatagramCount( @NonNull @SatelliteManager.SatelliteResult int result, boolean isDemoMode) { SatelliteStats.SatelliteControllerParams.Builder builder = @@ -190,9 +196,12 @@ public class ControllerMetricsStats { } } else { if (result == SatelliteManager.SATELLITE_RESULT_SUCCESS) { - builder.setCountOfIncomingDatagramSuccess(ADD_COUNT); + builder.setCountOfIncomingDatagramSuccess(ADD_COUNT) + .setCountOfIncomingDatagramTypeSosSmsSuccess(ADD_COUNT); + } else { - builder.setCountOfIncomingDatagramFail(ADD_COUNT); + builder.setCountOfIncomingDatagramFail(ADD_COUNT) + .setCountOfIncomingDatagramTypeSosSmsFail(ADD_COUNT); } } SatelliteStats.SatelliteControllerParams controllerParam = builder.build(); @@ -200,6 +209,23 @@ public class ControllerMetricsStats { mSatelliteStats.onSatelliteControllerMetrics(controllerParam); } + /** Increase counters for successful and failed incoming ntn sms attempts */ + public void reportIncomingNtnSmsCount( + @NonNull @SatelliteManager.SatelliteResult int result) { + SatelliteStats.SatelliteControllerParams.Builder builder = + new SatelliteStats.SatelliteControllerParams.Builder(); + if (result == SatelliteManager.SATELLITE_RESULT_SUCCESS) { + builder.setCountOfIncomingDatagramTypeSosSmsSuccess(ADD_COUNT) + .setCountOfIncomingDatagramTypeSmsSuccess(ADD_COUNT); + } else { + builder.setCountOfIncomingDatagramTypeSosSmsFail(ADD_COUNT) + .setCountOfIncomingDatagramTypeSmsFail(ADD_COUNT); + } + SatelliteStats.SatelliteControllerParams controllerParam = builder.build(); + logd("reportIncomingNtnSmsCount(): " + controllerParam); + mSatelliteStats.onSatelliteControllerMetrics(controllerParam); + } + /** Report a counter when an attempt for de-provision is success or not */ public void reportProvisionCount(@NonNull @SatelliteManager.SatelliteResult int result) { SatelliteStats.SatelliteControllerParams controllerParam; diff --git a/src/java/com/android/internal/telephony/satellite/metrics/EntitlementMetricsStats.java b/src/java/com/android/internal/telephony/satellite/metrics/EntitlementMetricsStats.java index 828642c339..93185b2bb1 100644 --- a/src/java/com/android/internal/telephony/satellite/metrics/EntitlementMetricsStats.java +++ b/src/java/com/android/internal/telephony/satellite/metrics/EntitlementMetricsStats.java @@ -99,7 +99,7 @@ public class EntitlementMetricsStats { logd("reportEntitlementMetrics: " + entitlementParams); CarrierRoamingSatelliteControllerStats.getOrCreateInstance() - .reportCountOfEntitlementStatusQueryRequest(); + .reportCountOfEntitlementStatusQueryRequest(mSubId); } /** Returns the carrier ID of the given subscription id. */ diff --git a/src/java/com/android/internal/telephony/subscription/SubscriptionManagerService.java b/src/java/com/android/internal/telephony/subscription/SubscriptionManagerService.java index c586d19122..026bfff056 100644 --- a/src/java/com/android/internal/telephony/subscription/SubscriptionManagerService.java +++ b/src/java/com/android/internal/telephony/subscription/SubscriptionManagerService.java @@ -4158,8 +4158,7 @@ public class SubscriptionManagerService extends ISub.Stub { } UserHandle myUserHandle = UserHandle.of(UserHandle.getCallingUserId()); - return mFeatureFlags.subscriptionUserAssociationQuery() - && isSubscriptionAssociatedWithUserNoCheck(subscriptionId, myUserHandle); + return isSubscriptionAssociatedWithUserNoCheck(subscriptionId, myUserHandle); } /** diff --git a/tests/telephonytests/src/android/telephony/ims/ImsFeatureTest.java b/tests/telephonytests/src/android/telephony/ims/ImsFeatureTest.java index 2dc0b31e7a..175b87556b 100644 --- a/tests/telephonytests/src/android/telephony/ims/ImsFeatureTest.java +++ b/tests/telephonytests/src/android/telephony/ims/ImsFeatureTest.java @@ -19,7 +19,7 @@ package android.telephony.ims; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; diff --git a/tests/telephonytests/src/android/telephony/ims/ImsServiceTest.java b/tests/telephonytests/src/android/telephony/ims/ImsServiceTest.java index d9d387cce4..725f84d125 100644 --- a/tests/telephonytests/src/android/telephony/ims/ImsServiceTest.java +++ b/tests/telephonytests/src/android/telephony/ims/ImsServiceTest.java @@ -23,7 +23,7 @@ import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.fail; import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; diff --git a/tests/telephonytests/src/android/telephony/ims/SipTransportImplBaseTest.java b/tests/telephonytests/src/android/telephony/ims/SipTransportImplBaseTest.java index 11b1d22ae6..1fd9b6c6a2 100644 --- a/tests/telephonytests/src/android/telephony/ims/SipTransportImplBaseTest.java +++ b/tests/telephonytests/src/android/telephony/ims/SipTransportImplBaseTest.java @@ -22,7 +22,7 @@ import static junit.framework.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; diff --git a/tests/telephonytests/src/com/android/internal/telephony/CallManagerTest.java b/tests/telephonytests/src/com/android/internal/telephony/CallManagerTest.java index 82bbc1804d..7918115206 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/CallManagerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/CallManagerTest.java @@ -18,11 +18,11 @@ package com.android.internal.telephony; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; -import static org.mockito.Matchers.isNull; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyChar; import static org.mockito.Mockito.anyString; diff --git a/tests/telephonytests/src/com/android/internal/telephony/CarrierActionAgentTest.java b/tests/telephonytests/src/com/android/internal/telephony/CarrierActionAgentTest.java index ed45cd5c16..aa4f0caa9c 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/CarrierActionAgentTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/CarrierActionAgentTest.java @@ -16,7 +16,7 @@ package com.android.internal.telephony; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; diff --git a/tests/telephonytests/src/com/android/internal/telephony/CarrierPrivilegesTrackerTest.java b/tests/telephonytests/src/com/android/internal/telephony/CarrierPrivilegesTrackerTest.java index 1c58ef2a22..19e186fdbb 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/CarrierPrivilegesTrackerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/CarrierPrivilegesTrackerTest.java @@ -30,9 +30,9 @@ import static android.telephony.TelephonyManager.SIM_STATE_READY; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.never; diff --git a/tests/telephonytests/src/com/android/internal/telephony/CarrierResolverTest.java b/tests/telephonytests/src/com/android/internal/telephony/CarrierResolverTest.java index 753f85c905..d4c29149f6 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/CarrierResolverTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/CarrierResolverTest.java @@ -18,7 +18,7 @@ package com.android.internal.telephony; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; diff --git a/tests/telephonytests/src/com/android/internal/telephony/CarrierServicesSmsFilterTest.java b/tests/telephonytests/src/com/android/internal/telephony/CarrierServicesSmsFilterTest.java index e68d065833..7787be7387 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/CarrierServicesSmsFilterTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/CarrierServicesSmsFilterTest.java @@ -18,10 +18,10 @@ package com.android.internal.telephony; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.timeout; diff --git a/tests/telephonytests/src/com/android/internal/telephony/CarrierSignalAgentTest.java b/tests/telephonytests/src/com/android/internal/telephony/CarrierSignalAgentTest.java index 7710648aef..4cb637f314 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/CarrierSignalAgentTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/CarrierSignalAgentTest.java @@ -26,9 +26,9 @@ import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; diff --git a/tests/telephonytests/src/com/android/internal/telephony/CellIdentityCdmaTest.java b/tests/telephonytests/src/com/android/internal/telephony/CellIdentityCdmaTest.java deleted file mode 100644 index 53719b15a6..0000000000 --- a/tests/telephonytests/src/com/android/internal/telephony/CellIdentityCdmaTest.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) 2017 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.internal.telephony; - -import static org.junit.Assert.assertEquals; - -import android.os.Parcel; -import android.telephony.CellIdentityCdma; -import android.test.AndroidTestCase; - -import androidx.test.filters.SmallTest; - -import com.android.internal.telephony.flags.Flags; - -/** Unit tests for {@link CellIdentityCdma}. */ - -public class CellIdentityCdmaTest extends AndroidTestCase { - private static final String LOG_TAG = "CellIdentityCdmaTest"; - - // Network Id ranges from 0 to 65535. - private static final int NETWORK_ID = 65535; - // CDMA System Id ranges from 0 to 32767 - private static final int SYSTEM_ID = 32767; - // Base Station Id ranges from 0 to 65535 - private static final int BASESTATION_ID = 65535; - // Longitude ranges from -2592000 to 2592000. - private static final int LONGITUDE = 2592000; - // Latitude ranges from -1296000 to 1296000. - private static final int LATITUDE = 1296000; - private static final String ALPHA_LONG = "long"; - private static final String ALPHA_SHORT = "short"; - - @SmallTest - public void testConstructor() { - if (Flags.cleanupCdma()) return; - CellIdentityCdma ci = - new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE, - ALPHA_LONG, ALPHA_SHORT); - - assertEquals(NETWORK_ID, ci.getNetworkId()); - assertEquals(LATITUDE, ci.getLatitude()); - assertEquals(LONGITUDE, ci.getLongitude()); - assertEquals(ALPHA_LONG, ci.getOperatorAlphaLong()); - assertEquals(ALPHA_SHORT, ci.getOperatorAlphaShort()); - - String globalCi = Integer.toString(SYSTEM_ID, 16) + Integer.toString(NETWORK_ID, 16) - + Integer.toString(BASESTATION_ID, 16); - assertEquals(globalCi, ci.getGlobalCellId()); - } - - @SmallTest - public void testNullIsland() { - if (Flags.cleanupCdma()) return; - CellIdentityCdma ci = - new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, -1, 0, - ALPHA_LONG, ALPHA_SHORT); - - assertEquals(Integer.MAX_VALUE, ci.getLatitude()); - assertEquals(Integer.MAX_VALUE, ci.getLongitude()); - } - - @SmallTest - public void testEquals() { - if (Flags.cleanupCdma()) return; - CellIdentityCdma ciA = - new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE, - ALPHA_LONG, ALPHA_SHORT); - CellIdentityCdma ciB = - new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE, - ALPHA_LONG, ALPHA_SHORT); - - assertTrue(ciA.equals(ciB)); - - ciA = new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE, - null, null); - ciB = new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE, - null, null); - - assertTrue(ciA.equals(ciB)); - - ciA = new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE, - ALPHA_LONG, ALPHA_SHORT); - ciB = new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE, - null, null); - - assertFalse(ciA.equals(ciB)); - } - - @SmallTest - public void testParcel() { - if (Flags.cleanupCdma()) return; - CellIdentityCdma ci = - new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE, - ALPHA_LONG, ALPHA_SHORT); - - Parcel p = Parcel.obtain(); - ci.writeToParcel(p, 0); - p.setDataPosition(0); - - CellIdentityCdma newCi = CellIdentityCdma.CREATOR.createFromParcel(p); - assertEquals(ci, newCi); - } -} diff --git a/tests/telephonytests/src/com/android/internal/telephony/CellSignalStrengthCdmaTest.java b/tests/telephonytests/src/com/android/internal/telephony/CellSignalStrengthCdmaTest.java deleted file mode 100644 index ab5e732941..0000000000 --- a/tests/telephonytests/src/com/android/internal/telephony/CellSignalStrengthCdmaTest.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2018 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.internal.telephony; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import android.os.Parcel; -import android.telephony.CellSignalStrengthCdma; -import android.test.AndroidTestCase; - -import androidx.test.filters.SmallTest; - -import com.android.internal.telephony.flags.Flags; - -/** Unit tests for {@link CellSignalStrengthCdma}. */ - -public class CellSignalStrengthCdmaTest extends AndroidTestCase { - - private static final int CDMA_DBM = -74; - private static final int CDMA_ECIO = -124; - private static final int EVDO_DBM = -23; - private static final int EVDO_ECIO = -108; - private static final int EVDO_SNR = 7; - - @SmallTest - public void testConstructor() { - if (Flags.cleanupCdma()) return; - CellSignalStrengthCdma css = new CellSignalStrengthCdma( - CDMA_DBM, CDMA_ECIO, EVDO_DBM, EVDO_ECIO, EVDO_SNR); - assertEquals(CDMA_DBM, css.getCdmaDbm()); - assertEquals(CDMA_ECIO, css.getCdmaEcio()); - assertEquals(EVDO_DBM, css.getEvdoDbm()); - assertEquals(EVDO_ECIO, css.getEvdoEcio()); - assertEquals(EVDO_SNR, css.getEvdoSnr()); - } - - @SmallTest - public void testInvalidConstructor() { - if (Flags.cleanupCdma()) return; - CellSignalStrengthCdma css = new CellSignalStrengthCdma(200, 2000, 20, 400, 200); - assertEquals(Integer.MAX_VALUE, css.getCdmaDbm()); - assertEquals(Integer.MAX_VALUE, css.getCdmaEcio()); - assertEquals(Integer.MAX_VALUE, css.getEvdoDbm()); - assertEquals(Integer.MAX_VALUE, css.getEvdoEcio()); - assertEquals(Integer.MAX_VALUE, css.getEvdoSnr()); - } - - @SmallTest - public void testDefaultConstructor() { - if (Flags.cleanupCdma()) return; - CellSignalStrengthCdma css = new CellSignalStrengthCdma(); - assertEquals(Integer.MAX_VALUE, css.getCdmaDbm()); - assertEquals(Integer.MAX_VALUE, css.getCdmaEcio()); - assertEquals(Integer.MAX_VALUE, css.getEvdoDbm()); - assertEquals(Integer.MAX_VALUE, css.getEvdoEcio()); - assertEquals(Integer.MAX_VALUE, css.getEvdoSnr()); - } - - @SmallTest - public void testEquals() { - if (Flags.cleanupCdma()) return; - assertTrue(new CellSignalStrengthCdma( - CDMA_DBM, CDMA_ECIO, EVDO_DBM, EVDO_ECIO, EVDO_SNR).equals( - new CellSignalStrengthCdma( - CDMA_DBM, CDMA_ECIO, EVDO_DBM, EVDO_ECIO, EVDO_SNR))); - assertFalse(new CellSignalStrengthCdma( - CDMA_DBM, CDMA_ECIO, EVDO_DBM, EVDO_ECIO, EVDO_SNR).equals( - new CellSignalStrengthCdma(CDMA_DBM, CDMA_ECIO, -24, EVDO_ECIO, EVDO_SNR))); - } - - @SmallTest - public void testParcel() { - if (Flags.cleanupCdma()) return; - CellSignalStrengthCdma css = new CellSignalStrengthCdma( - CDMA_DBM, CDMA_ECIO, EVDO_DBM, EVDO_ECIO, EVDO_SNR); - - Parcel p = Parcel.obtain(); - css.writeToParcel(p, 0); - p.setDataPosition(0); - - CellSignalStrengthCdma newCss = CellSignalStrengthCdma.CREATOR.createFromParcel(p); - assertEquals(css, newCss); - } -} diff --git a/tests/telephonytests/src/com/android/internal/telephony/ContextFixture.java b/tests/telephonytests/src/com/android/internal/telephony/ContextFixture.java index 39139bfed9..fe6e1b9ec7 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/ContextFixture.java +++ b/tests/telephonytests/src/com/android/internal/telephony/ContextFixture.java @@ -20,9 +20,9 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; -import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -791,14 +791,14 @@ public class ContextFixture implements TestFixture<Context> { public ContextFixture() { MockitoAnnotations.initMocks(this); - doAnswer(new Answer<List<ResolveInfo>>() { + lenient().doAnswer(new Answer<List<ResolveInfo>>() { @Override public List<ResolveInfo> answer(InvocationOnMock invocation) throws Throwable { return doQueryIntentServices((Intent) invocation.getArguments()[0]); } }).when(mPackageManager).queryIntentServices((Intent) any(), anyInt()); - doAnswer(new Answer<List<ResolveInfo>>() { + lenient().doAnswer(new Answer<List<ResolveInfo>>() { @Override public List<ResolveInfo> answer(InvocationOnMock invocation) throws Throwable { return doQueryIntentServices((Intent) invocation.getArguments()[0]); @@ -812,30 +812,34 @@ public class ContextFixture implements TestFixture<Context> { Log.d(TAG, "NameNotFoundException: e=" + e); } - doAnswer((Answer<Boolean>) + lenient().doAnswer((Answer<Boolean>) invocation -> mSystemFeatures.contains((String) invocation.getArgument(0))) .when(mPackageManager).hasSystemFeature(any()); try { - doReturn(mResources).when(mPackageManager).getResourcesForApplication(anyString()); + lenient().doReturn(mResources).when(mPackageManager) + .getResourcesForApplication(anyString()); } catch (NameNotFoundException ex) { Log.d(TAG, "NameNotFoundException: ex=" + ex); } - doReturn(mBundle).when(mCarrierConfigManager).getConfigForSubId(anyInt()); - doReturn(mBundle).when(mCarrierConfigManager).getConfig(); - doReturn(mBundle).when(mCarrierConfigManager).getConfigForSubId(anyInt(), anyString()); - doAnswer(invocation -> mNetworkId++).when(mNetwork).getNetId(); - doReturn(mNetwork).when(mConnectivityManager).registerNetworkAgent( - any(), any(), any(), any(), any(), any(), anyInt()); + lenient().doReturn(mBundle).when(mCarrierConfigManager).getConfigForSubId(anyInt()); + lenient().doReturn(mBundle).when(mCarrierConfigManager).getConfig(); + lenient().doReturn(mBundle).when(mCarrierConfigManager).getConfigForSubId(anyInt(), + anyString()); + lenient().doAnswer(invocation -> mNetworkId++).when(mNetwork).getNetId(); + lenient().doReturn( + ConnectivityManager.MockHelpers.registerNetworkAgentResult(mNetwork, null)) + .when(mConnectivityManager).registerNetworkAgent( + any(), any(), any(), any(), any(), any(), anyInt()); - doReturn(true).when(mEuiccManager).isEnabled(); + lenient().doReturn(true).when(mEuiccManager).isEnabled(); mConfiguration.locale = Locale.US; - doReturn(mConfiguration).when(mResources).getConfiguration(); + lenient().doReturn(mConfiguration).when(mResources).getConfiguration(); mDisplayMetrics.density = 2.25f; - doReturn(mDisplayMetrics).when(mResources).getDisplayMetrics(); + lenient().doReturn(mDisplayMetrics).when(mResources).getDisplayMetrics(); mPermissionTable.add(PERMISSION_ENABLE_ALL); } diff --git a/tests/telephonytests/src/com/android/internal/telephony/DefaultPhoneNotifierTest.java b/tests/telephonytests/src/com/android/internal/telephony/DefaultPhoneNotifierTest.java index 522cdac813..7591161801 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/DefaultPhoneNotifierTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/DefaultPhoneNotifierTest.java @@ -23,7 +23,7 @@ import static android.telephony.SecurityAlgorithmUpdate.SECURITY_ALGORITHM_HMAC_ import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; diff --git a/tests/telephonytests/src/com/android/internal/telephony/DeviceStateMonitorTest.java b/tests/telephonytests/src/com/android/internal/telephony/DeviceStateMonitorTest.java index 6baf10a244..057b745594 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/DeviceStateMonitorTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/DeviceStateMonitorTest.java @@ -22,10 +22,10 @@ import static android.hardware.radio.V1_0.DeviceStateType.POWER_SAVE_MODE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.nullable; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; diff --git a/tests/telephonytests/src/com/android/internal/telephony/GbaManagerTest.java b/tests/telephonytests/src/com/android/internal/telephony/GbaManagerTest.java index e97b1c0a5e..97c496291f 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/GbaManagerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/GbaManagerTest.java @@ -22,9 +22,9 @@ import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; diff --git a/tests/telephonytests/src/com/android/internal/telephony/GsmCdmaPhoneTest.java b/tests/telephonytests/src/com/android/internal/telephony/GsmCdmaPhoneTest.java index 03d5d49cc5..3f777447a2 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/GsmCdmaPhoneTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/GsmCdmaPhoneTest.java @@ -37,8 +37,8 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.nullable; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.anyBoolean; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.anyString; @@ -640,16 +640,16 @@ public class GsmCdmaPhoneTest extends TelephonyTest { doReturn(true).when(mTelephonyManager).isEmergencyNumber(emergencyNumber); // Feature flag enabled - // Device does not have FEATURE_TELEPHONY_CALLING + // Device does not have FEATURE_TELEPHONY_MESSAGING doReturn(false).when(mPackageManager).hasSystemFeature( - eq(PackageManager.FEATURE_TELEPHONY_CALLING)); + eq(PackageManager.FEATURE_TELEPHONY_MESSAGING)); mPhoneUT.notifySmsSent(emergencyNumber); processAllMessages(); assertFalse(mPhoneUT.isInEmergencySmsMode()); - // Device has FEATURE_TELEPHONY_CALLING + // Device has FEATURE_TELEPHONY_MESSAGING doReturn(true).when(mPackageManager).hasSystemFeature( - eq(PackageManager.FEATURE_TELEPHONY_CALLING)); + eq(PackageManager.FEATURE_TELEPHONY_MESSAGING)); mPhoneUT.notifySmsSent(emergencyNumber); processAllMessages(); assertTrue(mPhoneUT.isInEmergencySmsMode()); diff --git a/tests/telephonytests/src/com/android/internal/telephony/LocaleTrackerTest.java b/tests/telephonytests/src/com/android/internal/telephony/LocaleTrackerTest.java index 6674af0173..7f9249b332 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/LocaleTrackerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/LocaleTrackerTest.java @@ -19,7 +19,7 @@ package com.android.internal.telephony; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.reset; diff --git a/tests/telephonytests/src/com/android/internal/telephony/MultiSimSettingControllerTest.java b/tests/telephonytests/src/com/android/internal/telephony/MultiSimSettingControllerTest.java index 855a5dcbb8..50455ea450 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/MultiSimSettingControllerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/MultiSimSettingControllerTest.java @@ -249,8 +249,6 @@ public class MultiSimSettingControllerTest extends TelephonyTest { bundle.putBoolean(CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, true); doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(anyInt()); - doReturn(true).when(mFeatureFlags).resetPrimarySimDefaultValues(); - replaceInstance(PhoneFactory.class, "sPhones", null, mPhones); // Capture listener to emulate the carrier config change notification used later ArgumentCaptor<CarrierConfigManager.CarrierConfigChangeListener> listenerArgumentCaptor = diff --git a/tests/telephonytests/src/com/android/internal/telephony/NetworkTypeControllerTest.java b/tests/telephonytests/src/com/android/internal/telephony/NetworkTypeControllerTest.java index ba9bc74171..4db6f56a9c 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/NetworkTypeControllerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/NetworkTypeControllerTest.java @@ -1373,6 +1373,60 @@ public class NetworkTypeControllerTest extends TelephonyTest { } @Test + public void testSecondaryPciTimerExpire() throws Exception { + testTransitionToCurrentStateNrConnectedMmwave(); + assertEquals(TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED, + mNetworkTypeController.getOverrideNetworkType()); + + mBundle.putString(CarrierConfigManager.KEY_5G_ICON_DISPLAY_GRACE_PERIOD_STRING, + "connected_mmwave,any,10;connected,any,10;not_restricted_rrc_con,any,10"); + mBundle.putInt(CarrierConfigManager.KEY_NR_ADVANCED_PCI_CHANGE_SECONDARY_TIMER_SECONDS_INT, + 30); + sendCarrierConfigChanged(); + + // should trigger 10 second primary timer + doReturn(NetworkRegistrationInfo.NR_STATE_NONE).when(mServiceState).getNrState(); + mNetworkTypeController.sendMessage(3 /* EVENT_SERVICE_STATE_CHANGED */); + processAllMessages(); + + assertEquals("legacy", getCurrentState().getName()); + assertEquals(TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED, + mNetworkTypeController.getOverrideNetworkType()); + assertTrue(mNetworkTypeController.areAnyTimersActive()); + + // Before primary timer expires, PCI changed, indicating 5G UW might soon recover + moveTimeForward(5 * 1000); + mNetworkTypeController.sendMessage(11 /* EVENT_PHYSICAL_CHANNEL_CONFIGS_CHANGED */, + new AsyncResult(null, + List.of(new PhysicalChannelConfig.Builder() + .setPhysicalCellId(2) + .setNetworkType(TelephonyManager.NETWORK_TYPE_NR) + .setCellConnectionStatus(CellInfo.CONNECTION_PRIMARY_SERVING) + .build()), + null)); + processAllMessages(); + + // primary timer expires + moveTimeForward(5 * 1000); + processAllMessages(); + + // should trigger 30 second secondary timer + assertEquals("legacy", getCurrentState().getName()); + assertEquals(TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED, + mNetworkTypeController.getOverrideNetworkType()); + assertTrue(mNetworkTypeController.areAnyTimersActive()); + + // secondary timer expires + moveTimeForward(30 * 1000); + processAllMessages(); + + assertEquals("legacy", getCurrentState().getName()); + assertEquals(TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE, + mNetworkTypeController.getOverrideNetworkType()); + assertFalse(mNetworkTypeController.areAnyTimersActive()); + } + + @Test public void testSecondaryTimerReset() throws Exception { doReturn(NetworkRegistrationInfo.NR_STATE_CONNECTED).when(mServiceState).getNrState(); mBundle.putString(CarrierConfigManager.KEY_5G_ICON_DISPLAY_GRACE_PERIOD_STRING, diff --git a/tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java b/tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java index cbcd89d1db..24267dbc99 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java @@ -28,7 +28,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.anyInt; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; diff --git a/tests/telephonytests/src/com/android/internal/telephony/RILTest.java b/tests/telephonytests/src/com/android/internal/telephony/RILTest.java index d537d77656..8a7c1f0ace 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/RILTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/RILTest.java @@ -32,7 +32,6 @@ import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CHANGE_SIM import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CONFERENCE; import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DATA_REGISTRATION_STATE; import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DELETE_SMS_ON_SIM; -import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DEVICE_IDENTITY; import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DEVICE_IMEI; import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DTMF; import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENABLE_UICC_APPLICATIONS; @@ -57,7 +56,6 @@ import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_UICC_A import static com.android.internal.telephony.RILConstants.RIL_REQUEST_HANGUP; import static com.android.internal.telephony.RILConstants.RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND; import static com.android.internal.telephony.RILConstants.RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND; -import static com.android.internal.telephony.RILConstants.RIL_REQUEST_IMS_REGISTRATION_STATE; import static com.android.internal.telephony.RILConstants.RIL_REQUEST_IMS_SEND_SMS; import static com.android.internal.telephony.RILConstants.RIL_REQUEST_LAST_CALL_FAIL_CAUSE; import static com.android.internal.telephony.RILConstants.RIL_REQUEST_NV_READ_ITEM; @@ -98,8 +96,8 @@ import static junit.framework.Assert.fail; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; @@ -1012,15 +1010,6 @@ public class RILTest extends TelephonyTest { @FlakyTest @Test - public void testGetDeviceIdentity() throws Exception { - mRILUnderTest.getDeviceIdentity(obtainMessage()); - verify(mRadioProxy).getDeviceIdentity(mSerialNumberCaptor.capture()); - verifyRILResponse( - mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_DEVICE_IDENTITY); - } - - @FlakyTest - @Test public void testExitEmergencyCallbackMode() throws Exception { mRILUnderTest.exitEmergencyCallbackMode(obtainMessage()); verify(mRadioProxy).exitEmergencyCallbackMode(mSerialNumberCaptor.capture()); @@ -1156,15 +1145,6 @@ public class RILTest extends TelephonyTest { @FlakyTest @Test - public void testGetImsRegistrationState() throws Exception { - mRILUnderTest.getImsRegistrationState(obtainMessage()); - verify(mRadioProxy).getImsRegistrationState(mSerialNumberCaptor.capture()); - verifyRILResponse( - mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_IMS_REGISTRATION_STATE); - } - - @FlakyTest - @Test public void testSendRetryImsGsmSms() throws Exception { String smscPdu = "smscPdu"; String pdu = "pdu"; diff --git a/tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java b/tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java index f89bb96fa9..316ccd7773 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java @@ -27,8 +27,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.atLeast; diff --git a/tests/telephonytests/src/com/android/internal/telephony/SimActivationTrackerTest.java b/tests/telephonytests/src/com/android/internal/telephony/SimActivationTrackerTest.java index 23d992a9b8..eb312f1c42 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/SimActivationTrackerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/SimActivationTrackerTest.java @@ -22,7 +22,7 @@ import static android.telephony.TelephonyManager.SIM_ACTIVATION_STATE_RESTRICTED import static android.telephony.TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/tests/telephonytests/src/com/android/internal/telephony/Sms7BitEncodingTranslatorTest.java b/tests/telephonytests/src/com/android/internal/telephony/Sms7BitEncodingTranslatorTest.java index 3295640bd1..263e784b9e 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/Sms7BitEncodingTranslatorTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/Sms7BitEncodingTranslatorTest.java @@ -18,7 +18,7 @@ package com.android.internal.telephony; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import static org.mockito.Matchers.anyInt; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; diff --git a/tests/telephonytests/src/com/android/internal/telephony/SmsDispatchersControllerTest.java b/tests/telephonytests/src/com/android/internal/telephony/SmsDispatchersControllerTest.java index 6b982a3e42..37362d5a17 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/SmsDispatchersControllerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/SmsDispatchersControllerTest.java @@ -26,9 +26,9 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.isNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doNothing; diff --git a/tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java b/tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java index fff3363969..26ab6da21e 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java @@ -21,13 +21,14 @@ import static com.android.internal.telephony.TelephonyStatsLog.CELLULAR_SERVICE_ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.nullable; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.spy; import android.app.ActivityManager; @@ -174,23 +175,6 @@ public abstract class TelephonyTest { new ArrayList<String>(), EmergencyNumber.EMERGENCY_NUMBER_SOURCE_NETWORK_SIGNALING, EmergencyNumber.EMERGENCY_CALL_ROUTING_NORMAL); - private static final Field MESSAGE_QUEUE_FIELD; - private static final Field MESSAGE_WHEN_FIELD; - private static final Field MESSAGE_NEXT_FIELD; - - static { - try { - MESSAGE_QUEUE_FIELD = MessageQueue.class.getDeclaredField("mMessages"); - MESSAGE_QUEUE_FIELD.setAccessible(true); - MESSAGE_WHEN_FIELD = Message.class.getDeclaredField("when"); - MESSAGE_WHEN_FIELD.setAccessible(true); - MESSAGE_NEXT_FIELD = Message.class.getDeclaredField("next"); - MESSAGE_NEXT_FIELD.setAccessible(true); - } catch (NoSuchFieldException e) { - throw new RuntimeException("Failed to initialize TelephonyTest", e); - } - } - // Mocked classes protected FeatureFlags mFeatureFlags; protected GsmCdmaPhone mPhone; @@ -580,11 +564,11 @@ public abstract class TelephonyTest { mDomainSelectionResolver = Mockito.mock(DomainSelectionResolver.class); mNullCipherNotifier = Mockito.mock(NullCipherNotifier.class); - doReturn(true).when(mFeatureFlags).hsumBroadcast(); - doReturn(true).when(mFeatureFlags).hsumPackageManager(); - doReturn(true).when(mFeatureFlags).dataServiceCheck(); - doReturn(true).when(mFeatureFlags).phoneTypeCleanup(); - doReturn(true).when(mFeatureFlags).cleanupCdma(); + lenient().doReturn(true).when(mFeatureFlags).hsumBroadcast(); + lenient().doReturn(true).when(mFeatureFlags).hsumPackageManager(); + lenient().doReturn(true).when(mFeatureFlags).dataServiceCheck(); + lenient().doReturn(true).when(mFeatureFlags).phoneTypeCleanup(); + lenient().doReturn(true).when(mFeatureFlags).cleanupCdma(); WorkerThread.reset(); TelephonyManager.disableServiceHandleCaching(); @@ -612,16 +596,16 @@ public abstract class TelephonyTest { Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0); mServiceManagerMockedServices.put("isub", mSubscriptionManagerService); - doReturn(mSubscriptionManagerService).when(mSubscriptionManagerService) + lenient().doReturn(mSubscriptionManagerService).when(mSubscriptionManagerService) .queryLocalInterface(anyString()); mPhone.mCi = mSimulatedCommands; mCT.mCi = mSimulatedCommands; - doReturn(mUiccCard).when(mPhone).getUiccCard(); - doReturn(mUiccCard).when(mUiccSlot).getUiccCard(); - doReturn(mUiccCard).when(mUiccController).getUiccCardForPhone(anyInt()); - doReturn(mUiccPort).when(mPhone).getUiccPort(); - doReturn(mUiccProfile).when(mUiccPort).getUiccProfile(); + lenient().doReturn(mUiccCard).when(mPhone).getUiccCard(); + lenient().doReturn(mUiccCard).when(mUiccSlot).getUiccCard(); + lenient().doReturn(mUiccCard).when(mUiccController).getUiccCardForPhone(anyInt()); + lenient().doReturn(mUiccPort).when(mPhone).getUiccPort(); + lenient().doReturn(mUiccProfile).when(mUiccPort).getUiccProfile(); mTelephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); mTelecomManager = mContext.getSystemService(TelecomManager.class); @@ -646,127 +630,130 @@ public abstract class TelephonyTest { mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); //mTelephonyComponentFactory - doReturn(mTelephonyComponentFactory).when(mTelephonyComponentFactory).inject(anyString()); - doReturn(mSST).when(mTelephonyComponentFactory) + lenient().doReturn(mTelephonyComponentFactory).when(mTelephonyComponentFactory) + .inject(anyString()); + lenient().doReturn(mSST).when(mTelephonyComponentFactory) .makeServiceStateTracker(nullable(GsmCdmaPhone.class), nullable(CommandsInterface.class), nullable(FeatureFlags.class)); - doReturn(mEmergencyNumberTracker).when(mTelephonyComponentFactory) + lenient().doReturn(mEmergencyNumberTracker).when(mTelephonyComponentFactory) .makeEmergencyNumberTracker(nullable(Phone.class), nullable(CommandsInterface.class), any(FeatureFlags.class)); - doReturn(getTestEmergencyNumber()).when(mEmergencyNumberTracker) + lenient().doReturn(getTestEmergencyNumber()).when(mEmergencyNumberTracker) .getEmergencyNumber(any()); - doReturn(mUiccProfile).when(mTelephonyComponentFactory) + lenient().doReturn(mUiccProfile).when(mTelephonyComponentFactory) .makeUiccProfile(nullable(Context.class), nullable(CommandsInterface.class), nullable(IccCardStatus.class), anyInt(), nullable(UiccCard.class), nullable(Object.class), any(FeatureFlags.class)); - doReturn(mCT).when(mTelephonyComponentFactory) + lenient().doReturn(mCT).when(mTelephonyComponentFactory) .makeGsmCdmaCallTracker(nullable(GsmCdmaPhone.class), any(FeatureFlags.class)); - doReturn(mIccPhoneBookIntManager).when(mTelephonyComponentFactory) + lenient().doReturn(mIccPhoneBookIntManager).when(mTelephonyComponentFactory) .makeIccPhoneBookInterfaceManager(nullable(Phone.class)); - doReturn(mDisplayInfoController).when(mTelephonyComponentFactory) + lenient().doReturn(mDisplayInfoController).when(mTelephonyComponentFactory) .makeDisplayInfoController(nullable(Phone.class), any(FeatureFlags.class)); - doReturn(mWspTypeDecoder).when(mTelephonyComponentFactory) + lenient().doReturn(mWspTypeDecoder).when(mTelephonyComponentFactory) .makeWspTypeDecoder(nullable(byte[].class)); - doReturn(mImsCT).when(mTelephonyComponentFactory) + lenient().doReturn(mImsCT).when(mTelephonyComponentFactory) .makeImsPhoneCallTracker(nullable(ImsPhone.class), any(FeatureFlags.class)); - doReturn(mCdmaSSM).when(mTelephonyComponentFactory) + lenient().doReturn(mCdmaSSM).when(mTelephonyComponentFactory) .getCdmaSubscriptionSourceManagerInstance(nullable(Context.class), nullable(CommandsInterface.class), nullable(Handler.class), anyInt(), nullable(Object.class)); - doReturn(mImsExternalCallTracker).when(mTelephonyComponentFactory) + lenient().doReturn(mImsExternalCallTracker).when(mTelephonyComponentFactory) .makeImsExternalCallTracker(nullable(ImsPhone.class)); - doReturn(mImsNrSaModeHandler).when(mTelephonyComponentFactory) + lenient().doReturn(mImsNrSaModeHandler).when(mTelephonyComponentFactory) .makeImsNrSaModeHandler(nullable(ImsPhone.class)); - doReturn(mAppSmsManager).when(mTelephonyComponentFactory) + lenient().doReturn(mAppSmsManager).when(mTelephonyComponentFactory) .makeAppSmsManager(nullable(Context.class)); - doReturn(mCarrierSignalAgent).when(mTelephonyComponentFactory) + lenient().doReturn(mCarrierSignalAgent).when(mTelephonyComponentFactory) .makeCarrierSignalAgent(nullable(Phone.class)); - doReturn(mCarrierActionAgent).when(mTelephonyComponentFactory) + lenient().doReturn(mCarrierActionAgent).when(mTelephonyComponentFactory) .makeCarrierActionAgent(nullable(Phone.class)); - doReturn(mDeviceStateMonitor).when(mTelephonyComponentFactory) + lenient().doReturn(mDeviceStateMonitor).when(mTelephonyComponentFactory) .makeDeviceStateMonitor(nullable(Phone.class), any(FeatureFlags.class)); - doReturn(mAccessNetworksManager).when(mTelephonyComponentFactory) + lenient().doReturn(mAccessNetworksManager).when(mTelephonyComponentFactory) .makeAccessNetworksManager(nullable(Phone.class), any(Looper.class)); - doReturn(mNitzStateMachine).when(mTelephonyComponentFactory) + lenient().doReturn(mNitzStateMachine).when(mTelephonyComponentFactory) .makeNitzStateMachine(nullable(GsmCdmaPhone.class)); - doReturn(mLocaleTracker).when(mTelephonyComponentFactory) + lenient().doReturn(mLocaleTracker).when(mTelephonyComponentFactory) .makeLocaleTracker(nullable(Phone.class), nullable(NitzStateMachine.class), nullable(Looper.class), any(FeatureFlags.class)); - doReturn(mEriManager).when(mTelephonyComponentFactory) + lenient().doReturn(mEriManager).when(mTelephonyComponentFactory) .makeEriManager(nullable(Phone.class), anyInt()); - doReturn(mLinkBandwidthEstimator).when(mTelephonyComponentFactory) + lenient().doReturn(mLinkBandwidthEstimator).when(mTelephonyComponentFactory) .makeLinkBandwidthEstimator(nullable(Phone.class), any(Looper.class)); - doReturn(mDataProfileManager).when(mTelephonyComponentFactory) + lenient().doReturn(mDataProfileManager).when(mTelephonyComponentFactory) .makeDataProfileManager(any(Phone.class), any(DataNetworkController.class), any(DataServiceManager.class), any(Looper.class), any(FeatureFlags.class), any(DataProfileManager.DataProfileManagerCallback.class)); - doReturn(mSafetySource).when(mTelephonyComponentFactory) + lenient().doReturn(mSafetySource).when(mTelephonyComponentFactory) .makeCellularNetworkSecuritySafetySource(any(Context.class)); - doReturn(mIdentifierDisclosureNotifier) + lenient().doReturn(mIdentifierDisclosureNotifier) .when(mTelephonyComponentFactory) .makeIdentifierDisclosureNotifier( nullable(CellularNetworkSecuritySafetySource.class)); - doReturn(mNullCipherNotifier) + lenient().doReturn(mNullCipherNotifier) .when(mTelephonyComponentFactory) .makeNullCipherNotifier(nullable(CellularNetworkSecuritySafetySource.class)); //mPhone - doReturn(mContext).when(mPhone).getContext(); - doReturn(mContext).when(mPhone2).getContext(); - doReturn(mContext).when(mImsPhone).getContext(); - doReturn(true).when(mPhone).getUnitTestMode(); - doReturn(mUiccProfile).when(mPhone).getIccCard(); - doReturn(mServiceState).when(mPhone).getServiceState(); - doReturn(mServiceState).when(mImsPhone).getServiceState(); - doReturn(mPhone).when(mImsPhone).getDefaultPhone(); - doReturn(true).when(mPhone).isPhoneTypeGsm(); - doReturn(PhoneConstants.PHONE_TYPE_GSM).when(mPhone).getPhoneType(); - doReturn(mCT).when(mPhone).getCallTracker(); - doReturn(mSST).when(mPhone).getServiceStateTracker(); - doReturn(mDeviceStateMonitor).when(mPhone).getDeviceStateMonitor(); - doReturn(mDisplayInfoController).when(mPhone).getDisplayInfoController(); - doReturn(mSignalStrengthController).when(mPhone).getSignalStrengthController(); - doReturn(mEmergencyNumberTracker).when(mPhone).getEmergencyNumberTracker(); - doReturn(mCarrierSignalAgent).when(mPhone).getCarrierSignalAgent(); - doReturn(mCarrierActionAgent).when(mPhone).getCarrierActionAgent(); - doReturn(mAppSmsManager).when(mPhone).getAppSmsManager(); - doReturn(mIccSmsInterfaceManager).when(mPhone).getIccSmsInterfaceManager(); - doReturn(mAccessNetworksManager).when(mPhone).getAccessNetworksManager(); - doReturn(mDataSettingsManager).when(mDataNetworkController).getDataSettingsManager(); - doReturn(mDataNetworkController).when(mPhone).getDataNetworkController(); - doReturn(mDataSettingsManager).when(mPhone).getDataSettingsManager(); - doReturn(mCarrierPrivilegesTracker).when(mPhone).getCarrierPrivilegesTracker(); - doReturn(mSignalStrength).when(mPhone).getSignalStrength(); - doReturn(mVoiceCallSessionStats).when(mPhone).getVoiceCallSessionStats(); - doReturn(mVoiceCallSessionStats).when(mImsPhone).getVoiceCallSessionStats(); - doReturn(mSmsStats).when(mPhone).getSmsStats(); - doReturn(mTelephonyAnalytics).when(mPhone).getTelephonyAnalytics(); - doReturn(mImsStats).when(mImsPhone).getImsStats(); + lenient().doReturn(mContext).when(mPhone).getContext(); + lenient().doReturn(mContext).when(mPhone2).getContext(); + lenient().doReturn(mContext).when(mImsPhone).getContext(); + lenient().doReturn(true).when(mPhone).getUnitTestMode(); + lenient().doReturn(mUiccProfile).when(mPhone).getIccCard(); + lenient().doReturn(mServiceState).when(mPhone).getServiceState(); + lenient().doReturn(mServiceState).when(mImsPhone).getServiceState(); + lenient().doReturn(mPhone).when(mImsPhone).getDefaultPhone(); + lenient().doReturn(true).when(mPhone).isPhoneTypeGsm(); + lenient().doReturn(PhoneConstants.PHONE_TYPE_GSM).when(mPhone).getPhoneType(); + lenient().doReturn(mCT).when(mPhone).getCallTracker(); + lenient().doReturn(mSST).when(mPhone).getServiceStateTracker(); + lenient().doReturn(mDeviceStateMonitor).when(mPhone).getDeviceStateMonitor(); + lenient().doReturn(mDisplayInfoController).when(mPhone).getDisplayInfoController(); + lenient().doReturn(mSignalStrengthController).when(mPhone).getSignalStrengthController(); + lenient().doReturn(mEmergencyNumberTracker).when(mPhone).getEmergencyNumberTracker(); + lenient().doReturn(mCarrierSignalAgent).when(mPhone).getCarrierSignalAgent(); + lenient().doReturn(mCarrierActionAgent).when(mPhone).getCarrierActionAgent(); + lenient().doReturn(mAppSmsManager).when(mPhone).getAppSmsManager(); + lenient().doReturn(mIccSmsInterfaceManager).when(mPhone).getIccSmsInterfaceManager(); + lenient().doReturn(mAccessNetworksManager).when(mPhone).getAccessNetworksManager(); + lenient().doReturn(mDataSettingsManager).when(mDataNetworkController) + .getDataSettingsManager(); + lenient().doReturn(mDataNetworkController).when(mPhone).getDataNetworkController(); + lenient().doReturn(mDataSettingsManager).when(mPhone).getDataSettingsManager(); + lenient().doReturn(mCarrierPrivilegesTracker).when(mPhone).getCarrierPrivilegesTracker(); + lenient().doReturn(mSignalStrength).when(mPhone).getSignalStrength(); + lenient().doReturn(mVoiceCallSessionStats).when(mPhone).getVoiceCallSessionStats(); + lenient().doReturn(mVoiceCallSessionStats).when(mImsPhone).getVoiceCallSessionStats(); + lenient().doReturn(mSmsStats).when(mPhone).getSmsStats(); + lenient().doReturn(mTelephonyAnalytics).when(mPhone).getTelephonyAnalytics(); + lenient().doReturn(mImsStats).when(mImsPhone).getImsStats(); mIccSmsInterfaceManager.mDispatchersController = mSmsDispatchersController; - doReturn(mLinkBandwidthEstimator).when(mPhone).getLinkBandwidthEstimator(); - doReturn(mCellIdentity).when(mPhone).getCurrentCellIdentity(); - doReturn(mCellLocation).when(mCellIdentity).asCellLocation(); - doReturn(mDataConfigManager).when(mDataNetworkController).getDataConfigManager(); - doReturn(mDataProfileManager).when(mDataNetworkController).getDataProfileManager(); - doReturn(mDataRetryManager).when(mDataNetworkController).getDataRetryManager(); - doReturn(mCarrierPrivilegesTracker).when(mPhone).getCarrierPrivilegesTracker(); - doReturn(0).when(mPhone).getPhoneId(); - doReturn(1).when(mPhone2).getPhoneId(); - doReturn(true).when(mPhone).hasCalling(); - doReturn(true).when(mPhone2).hasCalling(); + lenient().doReturn(mLinkBandwidthEstimator).when(mPhone).getLinkBandwidthEstimator(); + lenient().doReturn(mCellIdentity).when(mPhone).getCurrentCellIdentity(); + lenient().doReturn(mCellLocation).when(mCellIdentity).asCellLocation(); + lenient().doReturn(mDataConfigManager).when(mDataNetworkController).getDataConfigManager(); + lenient().doReturn(mDataProfileManager).when(mDataNetworkController) + .getDataProfileManager(); + lenient().doReturn(mDataRetryManager).when(mDataNetworkController).getDataRetryManager(); + lenient().doReturn(mCarrierPrivilegesTracker).when(mPhone).getCarrierPrivilegesTracker(); + lenient().doReturn(0).when(mPhone).getPhoneId(); + lenient().doReturn(1).when(mPhone2).getPhoneId(); + lenient().doReturn(true).when(mPhone).hasCalling(); + lenient().doReturn(true).when(mPhone2).hasCalling(); //mUiccController - doReturn(mUiccCardApplication3gpp).when(mUiccController).getUiccCardApplication(anyInt(), - eq(UiccController.APP_FAM_3GPP)); - doReturn(mUiccCardApplication3gpp2).when(mUiccController).getUiccCardApplication(anyInt(), - eq(UiccController.APP_FAM_3GPP2)); - doReturn(mUiccCardApplicationIms).when(mUiccController).getUiccCardApplication(anyInt(), - eq(UiccController.APP_FAM_IMS)); - doReturn(mUiccCard).when(mUiccController).getUiccCard(anyInt()); - doReturn(mUiccPort).when(mUiccController).getUiccPort(anyInt()); - - doAnswer(new Answer<IccRecords>() { + lenient().doReturn(mUiccCardApplication3gpp).when(mUiccController).getUiccCardApplication( + anyInt(), eq(UiccController.APP_FAM_3GPP)); + lenient().doReturn(mUiccCardApplication3gpp2).when(mUiccController).getUiccCardApplication( + anyInt(), eq(UiccController.APP_FAM_3GPP2)); + lenient().doReturn(mUiccCardApplicationIms).when(mUiccController).getUiccCardApplication( + anyInt(), eq(UiccController.APP_FAM_IMS)); + lenient().doReturn(mUiccCard).when(mUiccController).getUiccCard(anyInt()); + lenient().doReturn(mUiccPort).when(mUiccController).getUiccPort(anyInt()); + + lenient().doAnswer(new Answer<IccRecords>() { public IccRecords answer(InvocationOnMock invocation) { switch ((Integer) invocation.getArguments()[1]) { case UiccController.APP_FAM_3GPP: @@ -781,53 +768,54 @@ public abstract class TelephonyTest { } } }).when(mUiccController).getIccRecords(anyInt(), anyInt()); - doReturn(new UiccSlot[] {mUiccSlot}).when(mUiccController).getUiccSlots(); - doReturn(mUiccSlot).when(mUiccController).getUiccSlotForPhone(anyInt()); - doReturn(mPinStorage).when(mUiccController).getPinStorage(); + lenient().doReturn(new UiccSlot[] {mUiccSlot}).when(mUiccController).getUiccSlots(); + lenient().doReturn(mUiccSlot).when(mUiccController).getUiccSlotForPhone(anyInt()); + lenient().doReturn(mPinStorage).when(mUiccController).getPinStorage(); //UiccCardApplication - doReturn(mSimRecords).when(mUiccCardApplication3gpp).getIccRecords(); - doReturn(mRuimRecords).when(mUiccCardApplication3gpp2).getIccRecords(); - doReturn(mIsimUiccRecords).when(mUiccCardApplicationIms).getIccRecords(); + lenient().doReturn(mSimRecords).when(mUiccCardApplication3gpp).getIccRecords(); + lenient().doReturn(mRuimRecords).when(mUiccCardApplication3gpp2).getIccRecords(); + lenient().doReturn(mIsimUiccRecords).when(mUiccCardApplicationIms).getIccRecords(); //mUiccProfile - doReturn(mSimRecords).when(mUiccProfile).getIccRecords(); - doAnswer(new Answer<IccRecords>() { + lenient().doReturn(mSimRecords).when(mUiccProfile).getIccRecords(); + lenient().doAnswer(new Answer<IccRecords>() { public IccRecords answer(InvocationOnMock invocation) { return mSimRecords; } }).when(mUiccProfile).getIccRecords(); //mUiccProfile - doReturn(mUiccCardApplication3gpp).when(mUiccProfile).getApplication( + lenient().doReturn(mUiccCardApplication3gpp).when(mUiccProfile).getApplication( eq(UiccController.APP_FAM_3GPP)); - doReturn(mUiccCardApplication3gpp2).when(mUiccProfile).getApplication( + lenient().doReturn(mUiccCardApplication3gpp2).when(mUiccProfile).getApplication( eq(UiccController.APP_FAM_3GPP2)); - doReturn(mUiccCardApplicationIms).when(mUiccProfile).getApplication( + lenient().doReturn(mUiccCardApplicationIms).when(mUiccProfile).getApplication( eq(UiccController.APP_FAM_IMS)); //SMS - doReturn(true).when(mSmsStorageMonitor).isStorageAvailable(); - doReturn(true).when(mSmsUsageMonitor).check(nullable(String.class), anyInt()); - doReturn(true).when(mTelephonyManager).getSmsReceiveCapableForPhone(anyInt(), anyBoolean()); - doReturn(true).when(mTelephonyManager).getSmsSendCapableForPhone( + lenient().doReturn(true).when(mSmsStorageMonitor).isStorageAvailable(); + lenient().doReturn(true).when(mSmsUsageMonitor).check(nullable(String.class), anyInt()); + lenient().doReturn(true).when(mTelephonyManager).getSmsReceiveCapableForPhone(anyInt(), + anyBoolean()); + lenient().doReturn(true).when(mTelephonyManager).getSmsSendCapableForPhone( anyInt(), anyBoolean()); //Misc - doReturn(ServiceState.RIL_RADIO_TECHNOLOGY_LTE).when(mServiceState) + lenient().doReturn(ServiceState.RIL_RADIO_TECHNOLOGY_LTE).when(mServiceState) .getRilDataRadioTechnology(); - doReturn(new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_LTE, + lenient().doReturn(new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_LTE, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE, false, false, false)) .when(mDisplayInfoController).getTelephonyDisplayInfo(); - doReturn(mPhone).when(mCT).getPhone(); - doReturn(mImsEcbm).when(mImsManager).getEcbmInterface(); - doReturn(mPhone).when(mInboundSmsHandler).getPhone(); - doReturn(mImsCallProfile).when(mImsCall).getCallProfile(); - doReturn(mIBinder).when(mIIntentSender).asBinder(); + lenient().doReturn(mPhone).when(mCT).getPhone(); + lenient().doReturn(mImsEcbm).when(mImsManager).getEcbmInterface(); + lenient().doReturn(mPhone).when(mInboundSmsHandler).getPhone(); + lenient().doReturn(mImsCallProfile).when(mImsCall).getCallProfile(); + lenient().doReturn(mIBinder).when(mIIntentSender).asBinder(); doAnswer(invocation -> { Intent[] intents = invocation.getArgument(6); if (intents != null && intents.length > 0) { - doReturn(intents[0]).when(mIActivityManager) + lenient().doReturn(intents[0]).when(mIActivityManager) .getIntentForIntentSender(mIIntentSender); } return mIIntentSender; @@ -835,8 +823,9 @@ public abstract class TelephonyTest { nullable(String.class), nullable(String.class), nullable(IBinder.class), nullable(String.class), anyInt(), nullable(Intent[].class), nullable(String[].class), anyInt(), nullable(Bundle.class), anyInt()); - doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(anyInt()); - doReturn(true).when(mTelephonyManager).isDataCapable(); + lenient().doReturn(mTelephonyManager).when(mTelephonyManager) + .createForSubscriptionId(anyInt()); + lenient().doReturn(true).when(mTelephonyManager).isDataCapable(); mContextFixture.addSystemFeature(PackageManager.FEATURE_TELECOM); mContextFixture.addSystemFeature(PackageManager.FEATURE_TELEPHONY_CALLING); @@ -844,45 +833,46 @@ public abstract class TelephonyTest { mContextFixture.addSystemFeature(PackageManager.FEATURE_TELEPHONY_EUICC); mContextFixture.addSystemFeature(PackageManager.FEATURE_TELEPHONY_MESSAGING); - doReturn(TelephonyManager.PHONE_TYPE_GSM).when(mTelephonyManager).getPhoneType(); - doReturn(mServiceState).when(mSST).getServiceState(); - doReturn(mServiceStateStats).when(mSST).getServiceStateStats(); + lenient().doReturn(TelephonyManager.PHONE_TYPE_GSM).when(mTelephonyManager).getPhoneType(); + lenient().doReturn(mServiceState).when(mSST).getServiceState(); + lenient().doReturn(mServiceStateStats).when(mSST).getServiceStateStats(); mSST.mSS = mServiceState; mSST.mRestrictedState = mRestrictedState; mServiceManagerMockedServices.put("connectivity_metrics_logger", mConnMetLoggerBinder); mServiceManagerMockedServices.put("package", mMockPackageManager); mServiceManagerMockedServices.put("legacy_permission", mMockLegacyPermissionManager); logd("mMockLegacyPermissionManager replaced"); - doReturn(new int[]{AccessNetworkConstants.TRANSPORT_TYPE_WWAN, + lenient().doReturn(new int[]{AccessNetworkConstants.TRANSPORT_TYPE_WWAN, AccessNetworkConstants.TRANSPORT_TYPE_WLAN}) .when(mAccessNetworksManager).getAvailableTransports(); - doReturn(true).when(mDataSettingsManager).isDataEnabled(); - doReturn(mNetworkRegistrationInfo).when(mServiceState).getNetworkRegistrationInfo( + lenient().doReturn(true).when(mDataSettingsManager).isDataEnabled(); + lenient().doReturn(mNetworkRegistrationInfo).when(mServiceState).getNetworkRegistrationInfo( anyInt(), anyInt()); - doReturn(RIL.RADIO_HAL_VERSION_2_0).when(mPhone).getHalVersion(anyInt()); - doReturn(2).when(mSignalStrength).getLevel(); - doReturn(mMockRadioConfigProxy).when(mMockRadioConfig).getRadioConfigProxy(any()); + lenient().doReturn(RIL.RADIO_HAL_VERSION_2_0).when(mPhone).getHalVersion(anyInt()); + lenient().doReturn(2).when(mSignalStrength).getLevel(); + lenient().doReturn(mMockRadioConfigProxy).when(mMockRadioConfig).getRadioConfigProxy(any()); // WiFi - doReturn(mWifiInfo).when(mWifiManager).getConnectionInfo(); - doReturn(2).when(mWifiManager).calculateSignalLevel(anyInt()); - doReturn(4).when(mWifiManager).getMaxSignalLevel(); + lenient().doReturn(mWifiInfo).when(mWifiManager).getConnectionInfo(); + lenient().doReturn(2).when(mWifiManager).calculateSignalLevel(anyInt()); + lenient().doReturn(4).when(mWifiManager).getMaxSignalLevel(); - doAnswer(invocation -> { + lenient().doAnswer(invocation -> { NetworkCapabilities nc = invocation.getArgument(0); return new VcnNetworkPolicyResult( false /* isTearDownRequested */, nc); }).when(mVcnManager).applyVcnNetworkPolicy(any(), any()); //SIM - doReturn(1).when(mTelephonyManager).getSimCount(); - doReturn(1).when(mTelephonyManager).getPhoneCount(); - doReturn(1).when(mTelephonyManager).getActiveModemCount(); + lenient().doReturn(1).when(mTelephonyManager).getSimCount(); + lenient().doReturn(1).when(mTelephonyManager).getPhoneCount(); + lenient().doReturn(1).when(mTelephonyManager).getActiveModemCount(); // Have getMaxPhoneCount always return the same value with getPhoneCount by default. - doAnswer((invocation)->Math.max(mTelephonyManager.getActiveModemCount(), + lenient().doAnswer((invocation)->Math.max(mTelephonyManager.getActiveModemCount(), mTelephonyManager.getPhoneCount())) .when(mTelephonyManager).getSupportedModemCount(); - doReturn(mStatsManager).when(mContext).getSystemService(eq(Context.NETWORK_STATS_SERVICE)); + lenient().doReturn(mStatsManager).when(mContext) + .getSystemService(eq(Context.NETWORK_STATS_SERVICE)); //Data //Initial state is: userData enabled, provisioned. @@ -893,56 +883,57 @@ public abstract class TelephonyTest { Settings.Global.DEVICE_PROVISIONING_MOBILE_DATA_ENABLED, 1); Settings.Global.putInt(resolver, Settings.Global.DATA_ROAMING, 0); - doReturn(90).when(mDataConfigManager).getNetworkCapabilityPriority( + lenient().doReturn(90).when(mDataConfigManager).getNetworkCapabilityPriority( eq(NetworkCapabilities.NET_CAPABILITY_EIMS)); - doReturn(80).when(mDataConfigManager).getNetworkCapabilityPriority( + lenient().doReturn(80).when(mDataConfigManager).getNetworkCapabilityPriority( eq(NetworkCapabilities.NET_CAPABILITY_SUPL)); - doReturn(70).when(mDataConfigManager).getNetworkCapabilityPriority( + lenient().doReturn(70).when(mDataConfigManager).getNetworkCapabilityPriority( eq(NetworkCapabilities.NET_CAPABILITY_MMS)); - doReturn(70).when(mDataConfigManager).getNetworkCapabilityPriority( + lenient().doReturn(70).when(mDataConfigManager).getNetworkCapabilityPriority( eq(NetworkCapabilities.NET_CAPABILITY_XCAP)); - doReturn(50).when(mDataConfigManager).getNetworkCapabilityPriority( + lenient().doReturn(50).when(mDataConfigManager).getNetworkCapabilityPriority( eq(NetworkCapabilities.NET_CAPABILITY_CBS)); - doReturn(50).when(mDataConfigManager).getNetworkCapabilityPriority( + lenient().doReturn(50).when(mDataConfigManager).getNetworkCapabilityPriority( eq(NetworkCapabilities.NET_CAPABILITY_MCX)); - doReturn(50).when(mDataConfigManager).getNetworkCapabilityPriority( + lenient().doReturn(50).when(mDataConfigManager).getNetworkCapabilityPriority( eq(NetworkCapabilities.NET_CAPABILITY_FOTA)); - doReturn(40).when(mDataConfigManager).getNetworkCapabilityPriority( + lenient().doReturn(40).when(mDataConfigManager).getNetworkCapabilityPriority( eq(NetworkCapabilities.NET_CAPABILITY_IMS)); - doReturn(30).when(mDataConfigManager).getNetworkCapabilityPriority( + lenient().doReturn(30).when(mDataConfigManager).getNetworkCapabilityPriority( eq(NetworkCapabilities.NET_CAPABILITY_DUN)); - doReturn(20).when(mDataConfigManager).getNetworkCapabilityPriority( + lenient().doReturn(20).when(mDataConfigManager).getNetworkCapabilityPriority( eq(NetworkCapabilities.NET_CAPABILITY_ENTERPRISE)); - doReturn(20).when(mDataConfigManager).getNetworkCapabilityPriority( + lenient().doReturn(20).when(mDataConfigManager).getNetworkCapabilityPriority( eq(NetworkCapabilities.NET_CAPABILITY_INTERNET)); - doReturn(60000).when(mDataConfigManager).getAnomalyNetworkConnectingTimeoutMs(); - doReturn(60000).when(mDataConfigManager) + lenient().doReturn(60000).when(mDataConfigManager).getAnomalyNetworkConnectingTimeoutMs(); + lenient().doReturn(60000).when(mDataConfigManager) .getAnomalyNetworkDisconnectingTimeoutMs(); - doReturn(60000).when(mDataConfigManager).getNetworkHandoverTimeoutMs(); - doReturn(new DataConfigManager.EventFrequency(300000, 12)) + lenient().doReturn(60000).when(mDataConfigManager).getNetworkHandoverTimeoutMs(); + lenient().doReturn(new DataConfigManager.EventFrequency(300000, 12)) .when(mDataConfigManager).getAnomalySetupDataCallThreshold(); - doReturn(new DataConfigManager.EventFrequency(0, 2)) + lenient().doReturn(new DataConfigManager.EventFrequency(0, 2)) .when(mDataConfigManager).getAnomalyImsReleaseRequestThreshold(); - doReturn(new DataConfigManager.EventFrequency(300000, 12)) + lenient().doReturn(new DataConfigManager.EventFrequency(300000, 12)) .when(mDataConfigManager).getAnomalyNetworkUnwantedThreshold(); // CellularNetworkValidator - doReturn(SubscriptionManager.INVALID_PHONE_INDEX) + lenient().doReturn(SubscriptionManager.INVALID_PHONE_INDEX) .when(mCellularNetworkValidator).getSubIdInValidation(); - doReturn(true).when(mCellularNetworkValidator).isValidationFeatureSupported(); + lenient().doReturn(true).when(mCellularNetworkValidator).isValidationFeatureSupported(); // Metrics - doReturn(null).when(mContext).getFileStreamPath(anyString()); - doReturn(mPersistAtomsStorage).when(mMetricsCollector).getAtomsStorage(); - doReturn(mDefaultNetworkMonitor).when(mMetricsCollector).getDefaultNetworkMonitor(); - doReturn(mWifiManager).when(mContext).getSystemService(eq(Context.WIFI_SERVICE)); - doReturn(mDeviceStateHelper).when(mMetricsCollector).getDeviceStateHelper(); - doReturn(CELLULAR_SERVICE_STATE__FOLD_STATE__STATE_UNKNOWN) + lenient().doReturn(null).when(mContext).getFileStreamPath(anyString()); + lenient().doReturn(mPersistAtomsStorage).when(mMetricsCollector).getAtomsStorage(); + lenient().doReturn(mDefaultNetworkMonitor).when(mMetricsCollector) + .getDefaultNetworkMonitor(); + lenient().doReturn(mWifiManager).when(mContext).getSystemService(eq(Context.WIFI_SERVICE)); + lenient().doReturn(mDeviceStateHelper).when(mMetricsCollector).getDeviceStateHelper(); + lenient().doReturn(CELLULAR_SERVICE_STATE__FOLD_STATE__STATE_UNKNOWN) .when(mDeviceStateHelper) .getFoldState(); - doReturn(null).when(mContext).getSystemService(eq(Context.DEVICE_STATE_SERVICE)); + lenient().doReturn(null).when(mContext).getSystemService(eq(Context.DEVICE_STATE_SERVICE)); - doReturn(false).when(mDomainSelectionResolver).isDomainSelectionSupported(); + lenient().doReturn(false).when(mDomainSelectionResolver).isDomainSelectionSupported(); DomainSelectionResolver.setDomainSelectionResolver(mDomainSelectionResolver); //Use reflection to mock singletons @@ -1341,36 +1332,12 @@ public abstract class TelephonyTest { } /** - * @return The longest delay from all the message queues. - */ - private long getLongestDelay() { - long delay = 0; - for (TestableLooper looper : mTestableLoopers) { - MessageQueue queue = looper.getLooper().getQueue(); - try { - Message msg = (Message) MESSAGE_QUEUE_FIELD.get(queue); - while (msg != null) { - delay = Math.max(msg.getWhen(), delay); - msg = (Message) MESSAGE_NEXT_FIELD.get(msg); - } - } catch (IllegalAccessException e) { - throw new RuntimeException("Access failed in TelephonyTest", e); - } - } - return delay; - } - - /** * @return {@code true} if there are any messages in the queue. */ private boolean messagesExist() { for (TestableLooper looper : mTestableLoopers) { - MessageQueue queue = looper.getLooper().getQueue(); - try { - Message msg = (Message) MESSAGE_QUEUE_FIELD.get(queue); - if (msg != null) return true; - } catch (IllegalAccessException e) { - throw new RuntimeException("Access failed in TelephonyTest", e); + if (looper.peekWhen() > 0) { + return true; } } return false; @@ -1380,8 +1347,14 @@ public abstract class TelephonyTest { * Handle all messages including the delayed messages. */ public void processAllFutureMessages() { + final long now = SystemClock.uptimeMillis(); while (messagesExist()) { - moveTimeForward(getLongestDelay()); + for (TestableLooper looper : mTestableLoopers) { + long nextDelay = looper.peekWhen() - now; + if (nextDelay > 0) { + looper.moveTimeForward(nextDelay); + } + } processAllMessages(); } } @@ -1406,20 +1379,7 @@ public abstract class TelephonyTest { */ public void moveTimeForward(long milliSeconds) { for (TestableLooper looper : mTestableLoopers) { - MessageQueue queue = looper.getLooper().getQueue(); - try { - Message msg = (Message) MESSAGE_QUEUE_FIELD.get(queue); - while (msg != null) { - long updatedWhen = msg.getWhen() - milliSeconds; - if (updatedWhen < 0) { - updatedWhen = 0; - } - MESSAGE_WHEN_FIELD.set(msg, updatedWhen); - msg = (Message) MESSAGE_NEXT_FIELD.get(msg); - } - } catch (IllegalAccessException e) { - throw new RuntimeException("Access failed in TelephonyTest", e); - } + looper.moveTimeForward(milliSeconds); } } } diff --git a/tests/telephonytests/src/com/android/internal/telephony/VisualVoicemailSmsFilterTest.java b/tests/telephonytests/src/com/android/internal/telephony/VisualVoicemailSmsFilterTest.java index 9f763371f7..df094ce613 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/VisualVoicemailSmsFilterTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/VisualVoicemailSmsFilterTest.java @@ -16,7 +16,7 @@ package com.android.internal.telephony; -import static org.mockito.Matchers.anyInt; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.when; import android.content.ComponentName; diff --git a/tests/telephonytests/src/com/android/internal/telephony/WapPushOverSmsTest.java b/tests/telephonytests/src/com/android/internal/telephony/WapPushOverSmsTest.java index 58e5617d39..2fdd4424ab 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/WapPushOverSmsTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/WapPushOverSmsTest.java @@ -17,8 +17,8 @@ package com.android.internal.telephony; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.nullable; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.doReturn; diff --git a/tests/telephonytests/src/com/android/internal/telephony/cat/CATServiceTest.java b/tests/telephonytests/src/com/android/internal/telephony/cat/CATServiceTest.java index a07ddbef87..7ee48323cb 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/cat/CATServiceTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/cat/CATServiceTest.java @@ -211,7 +211,7 @@ public class CATServiceTest extends TelephonyTest { mCatService.sendStkSms("test", "12345", 1, cmdPrms, mProxyController); verify(mSmsController, Mockito.times(1)).sendTextForSubscriber(anyInt(), anyString(), nullable(String.class), anyString(), nullable(String.class), - anyString(), Mockito.anyObject(), any(), eq(false), anyLong(), eq(true), eq(true)); + anyString(), Mockito.any(), any(), eq(false), anyLong(), eq(true), eq(true)); } @Test diff --git a/tests/telephonytests/src/com/android/internal/telephony/data/AccessNetworksManagerTest.java b/tests/telephonytests/src/com/android/internal/telephony/data/AccessNetworksManagerTest.java index ddd72e3438..1203510770 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/data/AccessNetworksManagerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/data/AccessNetworksManagerTest.java @@ -42,7 +42,6 @@ import android.telephony.AccessNetworkConstants; import android.telephony.AccessNetworkConstants.AccessNetworkType; import android.telephony.NetworkService; import android.telephony.data.ApnSetting; -import android.telephony.data.DataServiceCallback; import android.telephony.data.IQualifiedNetworksService; import android.telephony.data.IQualifiedNetworksServiceCallback; import android.testing.AndroidTestingRunner; @@ -323,9 +322,7 @@ public class AccessNetworksManagerTest extends TelephonyTest { } @Test - public void testRequestNetworkValidation_WithFlagEnabled() throws Exception { - when(mFeatureFlags.networkValidation()).thenReturn(true); - + public void testRequestNetworkValidation() throws Exception { mQnsCallback.onNetworkValidationRequested(NetworkCapabilities.NET_CAPABILITY_IMS, mIIntegerConsumer); processAllMessages(); @@ -333,23 +330,6 @@ public class AccessNetworksManagerTest extends TelephonyTest { } @Test - public void testRequestNetworkValidation_WithFlagDisabled() throws Exception { - mIIntegerConsumerResults.clear(); - when(mFeatureFlags.networkValidation()).thenReturn(false); - - mQnsCallback.onNetworkValidationRequested(NetworkCapabilities.NET_CAPABILITY_IMS, - mIIntegerConsumer); - processAllMessages(); - - assertThat(waitForIIntegerConsumerResult(1 /*numOfEvents*/)).isTrue(); - assertThat((long) mIIntegerConsumerResults.get(0)) - .isEqualTo(DataServiceCallback.RESULT_ERROR_UNSUPPORTED); - verify(mDataNetworkController, never()).requestNetworkValidation( - NetworkCapabilities.NET_CAPABILITY_IMS, - mIntegerConsumer); - } - - @Test public void testCallbackForReconnectQualifiedNetworkType() throws Exception { mAccessNetworksManager.registerCallback(mMockedCallback); diff --git a/tests/telephonytests/src/com/android/internal/telephony/data/CellularNetworkValidatorTest.java b/tests/telephonytests/src/com/android/internal/telephony/data/CellularNetworkValidatorTest.java index 9226f47b43..7ae55b7883 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/data/CellularNetworkValidatorTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/data/CellularNetworkValidatorTest.java @@ -24,7 +24,7 @@ import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; diff --git a/tests/telephonytests/src/com/android/internal/telephony/data/DataNetworkControllerTest.java b/tests/telephonytests/src/com/android/internal/telephony/data/DataNetworkControllerTest.java index 7fb743cf7a..a7bd9bc131 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/data/DataNetworkControllerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/data/DataNetworkControllerTest.java @@ -186,7 +186,7 @@ public class DataNetworkControllerTest extends TelephonyTest { private LinkBandwidthEstimatorCallback mLinkBandwidthEstimatorCallback; private boolean mIsNonTerrestrialNetwork = false; - private ArrayList<Integer> mCarrierSupportedSatelliteServices = new ArrayList<>(); + private ArrayList<Integer> mCarrierSupportedServices = new ArrayList<>(); private final DataProfile mGeneralPurposeDataProfile = new DataProfile.Builder() .setApnSetting(new ApnSetting.Builder() @@ -692,7 +692,7 @@ public class DataNetworkControllerTest extends TelephonyTest { .setDomain(NetworkRegistrationInfo.DOMAIN_PS) .setDataSpecificInfo(dsri) .setIsNonTerrestrialNetwork(mIsNonTerrestrialNetwork) - .setAvailableServices(mCarrierSupportedSatelliteServices) + .setAvailableServices(mCarrierSupportedServices) .setEmergencyOnly(isEmergencyOnly) .build()); @@ -702,7 +702,7 @@ public class DataNetworkControllerTest extends TelephonyTest { .setRegistrationState(iwlanRegState) .setDomain(NetworkRegistrationInfo.DOMAIN_PS) .setIsNonTerrestrialNetwork(mIsNonTerrestrialNetwork) - .setAvailableServices(mCarrierSupportedSatelliteServices) + .setAvailableServices(mCarrierSupportedServices) .setEmergencyOnly(isEmergencyOnly) .build()); @@ -1124,7 +1124,7 @@ public class DataNetworkControllerTest extends TelephonyTest { doReturn(CarrierConfigManager.SATELLITE_DATA_SUPPORT_ONLY_RESTRICTED) .when(mSatelliteController) .getSatelliteDataServicePolicyForPlmn(anyInt(), any()); - mCarrierSupportedSatelliteServices.add(NetworkRegistrationInfo.SERVICE_TYPE_DATA); + mCarrierSupportedServices.add(NetworkRegistrationInfo.SERVICE_TYPE_DATA); serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, NetworkRegistrationInfo.REGISTRATION_STATE_HOME); logd("DataNetworkControllerTest -Setup!"); @@ -1538,15 +1538,144 @@ public class DataNetworkControllerTest extends TelephonyTest { public void testMovingFromInServiceToNoService() throws Exception { testSetupDataNetwork(); - serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, + // clear available services at no service + mCarrierSupportedServices.clear(); + + serviceStateChanged(TelephonyManager.NETWORK_TYPE_UNKNOWN, NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING); // Verify we don't tear down the data network. verifyInternetConnected(); + } + + @Test + public void testInServiceAvailableServicesChanged() throws Exception { + testSetupDataNetwork(); + + List<DataDisallowedReason> reasons = mDataNetworkControllerUT + .getInternetDataDisallowedReasons(); + assertThat(reasons).isEmpty(); + + // Add available services sms to existing available services with data + mCarrierSupportedServices.add(NetworkRegistrationInfo.SERVICE_TYPE_SMS); + + serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, + NetworkRegistrationInfo.REGISTRATION_STATE_HOME); + + // Verify we don't tear down the data network. + verifyInternetConnected(); + + + mCarrierSupportedServices.clear(); + // Add available services data and mms + mCarrierSupportedServices.add(NetworkRegistrationInfo.SERVICE_TYPE_DATA); + mCarrierSupportedServices.add(NetworkRegistrationInfo.SERVICE_TYPE_MMS); + + serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, + NetworkRegistrationInfo.REGISTRATION_STATE_HOME); - serviceStateChanged(TelephonyManager.NETWORK_TYPE_UNKNOWN, - NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING); // Verify we don't tear down the data network. verifyInternetConnected(); + + // clear all available services + mCarrierSupportedServices.clear(); + serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, + NetworkRegistrationInfo.REGISTRATION_STATE_HOME); + + // Verify internet is not connected + verifyNoConnectedNetworkHasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET); + + reasons = mDataNetworkControllerUT.getInternetDataDisallowedReasons(); + assertThat(reasons).contains(DataDisallowedReason.SERVICE_OPTION_NOT_SUPPORTED); + + } + + @Test + public void testHomeToRoamingAvailableServicesChangedWithDataRoamingDisabled() + throws Exception { + testSetupDataNetwork(); + + List<DataDisallowedReason> reasons = mDataNetworkControllerUT + .getInternetDataDisallowedReasons(); + assertThat(reasons).isEmpty(); + + // Disable data roaming setting + mDataNetworkControllerUT.getDataSettingsManager().setDataRoamingEnabled(false); + + // Home to roaming with same available services + serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, + NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING); + + // Verify internet is not connected due to roaming disabled + verifyNoConnectedNetworkHasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET); + + reasons = mDataNetworkControllerUT.getInternetDataDisallowedReasons(); + assertThat(reasons).contains(DataDisallowedReason.ROAMING_DISABLED); + } + + @Test + public void testHomeToRoamingAvailableServicesChangedWithDataRoamingEnabled() + throws Exception { + testSetupDataNetwork(); + + List<DataDisallowedReason> reasons = mDataNetworkControllerUT + .getInternetDataDisallowedReasons(); + assertThat(reasons).isEmpty(); + + // Enable data roaming setting + mDataNetworkControllerUT.getDataSettingsManager().setDataRoamingEnabled(true); + + // Home to roaming with same available services + serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, + NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING); + + // Verify we don't tear down the data network since available services as still data + // with data roaming enabled + verifyInternetConnected(); + + // clear all available services + mCarrierSupportedServices.clear(); + // At roaming + serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, + NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING); + + // Verify internet is not connected + verifyNoConnectedNetworkHasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET); + + reasons = mDataNetworkControllerUT.getInternetDataDisallowedReasons(); + assertThat(reasons).contains(DataDisallowedReason.SERVICE_OPTION_NOT_SUPPORTED); + } + + @Test + public void testOnAvailableServiceChanged_WithReevaluateNetworkRequest() + throws Exception { + // clear available services at no service + mCarrierSupportedServices.clear(); + + serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, + NetworkRegistrationInfo.REGISTRATION_STATE_HOME); + + // Set network request transport with Internet capability + mDataNetworkControllerUT.addNetworkRequest( + createNetworkRequest(NetworkCapabilities.NET_CAPABILITY_INTERNET)); + processAllMessages(); + + // Verify internet is not connected due to roaming disabled + verifyNoConnectedNetworkHasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET); + + List<DataDisallowedReason> reasons = mDataNetworkControllerUT + .getInternetDataDisallowedReasons(); + assertThat(reasons).contains(DataDisallowedReason.SERVICE_OPTION_NOT_SUPPORTED); + + // add available services with data, re-evaluate network request + mCarrierSupportedServices.add(NetworkRegistrationInfo.SERVICE_TYPE_DATA); + serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, + NetworkRegistrationInfo.REGISTRATION_STATE_HOME); + + // Verify now internet was connected + verifyInternetConnected(); + + reasons = mDataNetworkControllerUT.getInternetDataDisallowedReasons(); + assertThat(reasons).isEmpty(); } @Test @@ -1572,7 +1701,6 @@ public class DataNetworkControllerTest extends TelephonyTest { verifyNoConnectedNetworkHasCapability(NetworkCapabilities.NET_CAPABILITY_IMS); verifyConnectedNetworkHasCapabilities(NetworkCapabilities.NET_CAPABILITY_INTERNET); - // PS unrestricted, new setup is allowed mDataNetworkControllerUT.obtainMessage(7/*EVENT_PS_RESTRICT_DISABLED*/).sendToTarget(); processAllMessages(); @@ -2129,7 +2257,7 @@ public class DataNetworkControllerTest extends TelephonyTest { // reset satellite network and roaming registration mIsNonTerrestrialNetwork = false; - mCarrierSupportedSatelliteServices.clear(); + mCarrierSupportedServices.clear(); serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, NetworkRegistrationInfo.REGISTRATION_STATE_HOME); } @@ -3915,6 +4043,13 @@ public class DataNetworkControllerTest extends TelephonyTest { processAllMessages(); verify(mMockedDataNetworkControllerCallback).onNrAdvancedCapableByPcoChanged(eq(true)); + + // Deactivate the data, verify notify PCO gone. + mDataNetworkControllerUT.tearDownAllDataNetworks( + DataNetwork.TEAR_DOWN_REASON_AIRPLANE_MODE_ON); + processAllFutureMessages(); + + verify(mMockedDataNetworkControllerCallback).onNrAdvancedCapableByPcoChanged(eq(false)); } @Test @@ -5839,8 +5974,8 @@ public class DataNetworkControllerTest extends TelephonyTest { @Test public void testNotRestrictedDataConnectionRequest_WithoutDataServiceSupport() throws Exception { - mCarrierSupportedSatelliteServices.clear(); - mCarrierSupportedSatelliteServices.add(NetworkRegistrationInfo.SERVICE_TYPE_VOICE); + mCarrierSupportedServices.clear(); + mCarrierSupportedServices.add(NetworkRegistrationInfo.SERVICE_TYPE_VOICE); serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, NetworkRegistrationInfo.REGISTRATION_STATE_HOME); @@ -5856,7 +5991,7 @@ public class DataNetworkControllerTest extends TelephonyTest { Mockito.clearInvocations(mMockedDataNetworkControllerCallback); // reset satellite network and roaming registration - mCarrierSupportedSatelliteServices.clear(); + mCarrierSupportedServices.clear(); serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, NetworkRegistrationInfo.REGISTRATION_STATE_HOME); } @@ -5865,8 +6000,8 @@ public class DataNetworkControllerTest extends TelephonyTest { public void testConnection_WithDataServiceCheckFlagDisabled_WithoutDataServiceSupport() throws Exception { doReturn(false).when(mFeatureFlags).dataServiceCheck(); - mCarrierSupportedSatelliteServices.clear(); - mCarrierSupportedSatelliteServices.add(NetworkRegistrationInfo.SERVICE_TYPE_VOICE); + mCarrierSupportedServices.clear(); + mCarrierSupportedServices.add(NetworkRegistrationInfo.SERVICE_TYPE_VOICE); serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, NetworkRegistrationInfo.REGISTRATION_STATE_HOME); @@ -5882,7 +6017,7 @@ public class DataNetworkControllerTest extends TelephonyTest { Mockito.clearInvocations(mMockedDataNetworkControllerCallback); // reset satellite network and roaming registration - mCarrierSupportedSatelliteServices.clear(); + mCarrierSupportedServices.clear(); serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, NetworkRegistrationInfo.REGISTRATION_STATE_HOME); } @@ -5890,8 +6025,8 @@ public class DataNetworkControllerTest extends TelephonyTest { @Test public void testRestrictedDataConnectionRequest_WithoutDataServiceSupport() throws Exception { - mCarrierSupportedSatelliteServices.clear(); - mCarrierSupportedSatelliteServices.add(NetworkRegistrationInfo.SERVICE_TYPE_VOICE); + mCarrierSupportedServices.clear(); + mCarrierSupportedServices.add(NetworkRegistrationInfo.SERVICE_TYPE_VOICE); serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, NetworkRegistrationInfo.REGISTRATION_STATE_HOME); @@ -5911,7 +6046,7 @@ public class DataNetworkControllerTest extends TelephonyTest { Mockito.clearInvocations(mMockedDataNetworkControllerCallback); // reset satellite network and roaming registration - mCarrierSupportedSatelliteServices.clear(); + mCarrierSupportedServices.clear(); serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, NetworkRegistrationInfo.REGISTRATION_STATE_HOME); } @@ -5940,7 +6075,7 @@ public class DataNetworkControllerTest extends TelephonyTest { // reset satellite network and roaming registration mIsNonTerrestrialNetwork = false; - mCarrierSupportedSatelliteServices.clear(); + mCarrierSupportedServices.clear(); serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, NetworkRegistrationInfo.REGISTRATION_STATE_HOME); } @@ -5975,7 +6110,7 @@ public class DataNetworkControllerTest extends TelephonyTest { // reset satellite network and roaming registration mIsNonTerrestrialNetwork = false; - mCarrierSupportedSatelliteServices.clear(); + mCarrierSupportedServices.clear(); serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, NetworkRegistrationInfo.REGISTRATION_STATE_HOME); } @@ -6010,7 +6145,7 @@ public class DataNetworkControllerTest extends TelephonyTest { // reset satellite network and roaming registration mIsNonTerrestrialNetwork = false; - mCarrierSupportedSatelliteServices.clear(); + mCarrierSupportedServices.clear(); serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, NetworkRegistrationInfo.REGISTRATION_STATE_HOME); } @@ -6046,7 +6181,7 @@ public class DataNetworkControllerTest extends TelephonyTest { // reset satellite network and roaming registration mIsNonTerrestrialNetwork = false; - mCarrierSupportedSatelliteServices.clear(); + mCarrierSupportedServices.clear(); serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, NetworkRegistrationInfo.REGISTRATION_STATE_HOME); } diff --git a/tests/telephonytests/src/com/android/internal/telephony/data/DataNetworkTest.java b/tests/telephonytests/src/com/android/internal/telephony/data/DataNetworkTest.java index 3289715096..6e92353d1e 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/data/DataNetworkTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/data/DataNetworkTest.java @@ -25,7 +25,7 @@ import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doAnswer; @@ -34,7 +34,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import android.net.ConnectivityManager; import android.net.InetAddresses; @@ -2294,8 +2293,7 @@ public class DataNetworkTest extends TelephonyTest { } @Test - public void testValidationStatusOnPreciseDataConnectionState_FlagEnabled() throws Exception { - when(mFeatureFlags.networkValidation()).thenReturn(true); + public void testValidationStatusOnPreciseDataConnectionState() throws Exception { setupIwlanDataNetwork(); ArgumentCaptor<PreciseDataConnectionState> pdcsCaptor = @@ -2344,37 +2342,7 @@ public class DataNetworkTest extends TelephonyTest { } @Test - public void testValidationStatus_FlagDisabled() throws Exception { - // network validation flag disabled - when(mFeatureFlags.networkValidation()).thenReturn(false); - setupIwlanDataNetwork(); - - // precise data connection state posted for setup data call response - ArgumentCaptor<PreciseDataConnectionState> pdcsCaptor = - ArgumentCaptor.forClass(PreciseDataConnectionState.class); - verify(mPhone, times(2)).notifyDataConnection(pdcsCaptor.capture()); - - // data state updated with network validation status - DataCallResponse response = createDataCallResponse(123, - DataCallResponse.LINK_STATUS_ACTIVE, Collections.emptyList(), null, - PreciseDataConnectionState.NETWORK_VALIDATION_SUCCESS); - mDataNetworkUT.sendMessage(8 /*EVENT_DATA_STATE_CHANGED*/, new AsyncResult( - AccessNetworkConstants.TRANSPORT_TYPE_WLAN, List.of(response), null)); - processAllMessages(); - - // Verify updated validation status at precise data connection state not posted due to flag - // disabled - pdcsCaptor = ArgumentCaptor.forClass(PreciseDataConnectionState.class); - verify(mPhone, times(2)).notifyDataConnection(pdcsCaptor.capture()); - List<PreciseDataConnectionState> pdcsList = pdcsCaptor.getAllValues(); - assertThat(pdcsList.get(1).getNetworkValidationStatus()) - .isEqualTo(PreciseDataConnectionState.NETWORK_VALIDATION_UNSUPPORTED); - } - - @Test - public void testHandoverWithSuccessNetworkValidation_FlagEnabled() throws Exception { - when(mFeatureFlags.networkValidation()).thenReturn(true); - + public void testHandoverWithSuccessNetworkValidation() throws Exception { setupDataNetwork(); setSuccessfulSetupDataResponse( diff --git a/tests/telephonytests/src/com/android/internal/telephony/data/DataStallRecoveryManagerTest.java b/tests/telephonytests/src/com/android/internal/telephony/data/DataStallRecoveryManagerTest.java index 5dc1d871a9..8cbd61fc7e 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/data/DataStallRecoveryManagerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/data/DataStallRecoveryManagerTest.java @@ -19,7 +19,7 @@ package com.android.internal.telephony.data; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; diff --git a/tests/telephonytests/src/com/android/internal/telephony/data/PhoneSwitcherTest.java b/tests/telephonytests/src/com/android/internal/telephony/data/PhoneSwitcherTest.java index a9c2ece883..cd2e88a33a 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/data/PhoneSwitcherTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/data/PhoneSwitcherTest.java @@ -42,7 +42,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; diff --git a/tests/telephonytests/src/com/android/internal/telephony/emergency/EmergencyStateTrackerTest.java b/tests/telephonytests/src/com/android/internal/telephony/emergency/EmergencyStateTrackerTest.java index 28edeae002..2909966b2b 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/emergency/EmergencyStateTrackerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/emergency/EmergencyStateTrackerTest.java @@ -21,6 +21,7 @@ import static android.telephony.NetworkRegistrationInfo.DOMAIN_CS; import static android.telephony.NetworkRegistrationInfo.DOMAIN_CS_PS; import static android.telephony.NetworkRegistrationInfo.DOMAIN_PS; import static android.telephony.NetworkRegistrationInfo.REGISTRATION_STATE_HOME; +import static android.telephony.NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING; import static android.telephony.TelephonyManager.EMERGENCY_CALLBACK_MODE_CALL; import static android.telephony.TelephonyManager.EMERGENCY_CALLBACK_MODE_SMS; @@ -38,7 +39,6 @@ import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyBoolean; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.anyLong; -import static org.mockito.Mockito.anyVararg; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; @@ -75,10 +75,12 @@ import androidx.test.filters.SmallTest; import com.android.internal.telephony.Call; import com.android.internal.telephony.CallStateException; +import com.android.internal.telephony.CommandException; import com.android.internal.telephony.Connection; import com.android.internal.telephony.GsmCdmaPhone; import com.android.internal.telephony.Phone; import com.android.internal.telephony.PhoneConstants; +import com.android.internal.telephony.RILConstants; import com.android.internal.telephony.TelephonyIntents; import com.android.internal.telephony.TelephonyTest; import com.android.internal.telephony.data.PhoneSwitcher; @@ -108,6 +110,12 @@ public class EmergencyStateTrackerTest extends TelephonyTest { private static final int TEST_WAIT_FOR_IN_SERVICE_TIMEOUT_MS = 3000; private static final EmergencyRegistrationResult E_REG_RESULT = new EmergencyRegistrationResult( EUTRAN, REGISTRATION_STATE_HOME, DOMAIN_CS_PS, true, true, 0, 1, "001", "01", "US"); + private static final EmergencyRegistrationResult UNKNOWN_E_REG_RESULT = + new EmergencyRegistrationResult( + AccessNetworkConstants.AccessNetworkType.UNKNOWN, + REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING, + NetworkRegistrationInfo.DOMAIN_UNKNOWN, + false, false, 0, 0, "", "", ""); @Mock EmergencyStateTracker.PhoneFactoryProxy mPhoneFactoryProxy; @Mock EmergencyStateTracker.PhoneSwitcherProxy mPhoneSwitcherProxy; @@ -126,6 +134,7 @@ public class EmergencyStateTrackerTest extends TelephonyTest { .when(mTelephonyManagerProxy).getSimState(anyInt()); doReturn(true).when(mFeatureFlags).emergencyCallbackModeNotification(); doReturn(true).when(mFeatureFlags).disableEcbmBasedOnRat(); + doReturn(true).when(mFeatureFlags).performCrossStackRedialCheckForEmergencyCall(); } @After @@ -2529,7 +2538,7 @@ public class EmergencyStateTrackerTest extends TelephonyTest { when(phone.getSubId()).thenReturn(1); setEcmSupportedConfig(phone, true); PersistableBundle bundle = mCarrierConfigManager.getConfigForSubId(phone.getSubId()); - doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(anyInt(), anyVararg()); + doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(anyInt(), any()); EmergencyStateTracker testEst = setupEmergencyStateTracker( false /* isSuplDdsSwitchRequiredForEmergencyCall */); @@ -3054,7 +3063,7 @@ public class EmergencyStateTrackerTest extends TelephonyTest { PersistableBundle bundle = mCarrierConfigManager.getConfigForSubId(testPhone.getSubId()); bundle.putBoolean(CarrierConfigManager.KEY_BROADCAST_EMERGENCY_CALL_STATE_CHANGES_BOOL, true); - doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(anyInt(), anyVararg()); + doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(anyInt(), any()); // onCarrierConfigChanged with valid subscription carrierConfigChangeListener.onCarrierConfigChanged( testPhone.getPhoneId(), testPhone.getSubId(), @@ -3492,6 +3501,74 @@ public class EmergencyStateTrackerTest extends TelephonyTest { verify(phone1, never()).setEmergencyMode(anyInt(), any(Message.class)); } + @Test + @SmallTest + public void testSwitchPhoneWhenNonEmergencyNtnSessionInProgress() { + EmergencyStateTracker emergencyStateTracker = setupEmergencyStateTracker( + /* isSuplDdsSwitchRequiredForEmergencyCall= */ true); + Phone phone0 = setupTestPhoneForEmergencyCall(/* isRoaming= */ true, + /* isRadioOn= */ true); + setUpAsyncResultForSetEmergencyMode( + phone0, UNKNOWN_E_REG_RESULT, RILConstants.INTERNAL_ERR); + // Start an emergency call over Phone0 + CompletableFuture<Integer> future = emergencyStateTracker.startEmergencyCall(phone0, + mTestConnection1, false); + + Phone phone1 = getPhone(1); + // Phone0: Disable NTN + doReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID) + .when(phone0).getSubId(); + doReturn(TelephonyManager.SIM_STATE_ABSENT) + .when(mTelephonyManagerProxy).getSimState(eq(0)); + // Phone1: Enable TN + doReturn(2).when(phone1).getSubId(); + doReturn(TelephonyManager.SIM_STATE_READY) + .when(mTelephonyManagerProxy).getSimState(eq(1)); + + processAllMessages(); + + verify(phone0).setEmergencyMode(eq(MODE_EMERGENCY_WWAN), any(Message.class)); + assertFalse(emergencyStateTracker.isInEmergencyMode()); + assertTrue(future.isDone()); + // Expect: DisconnectCause#EMERGENCY_PERM_FAILURE + assertEquals(future.getNow(DisconnectCause.NOT_DISCONNECTED), + Integer.valueOf(DisconnectCause.EMERGENCY_PERM_FAILURE)); + } + + @Test + @SmallTest + public void testSwitchPhoneWhenNonEmergencyNtnSessionInProgressAndFlagDisabled() { + doReturn(false).when(mFeatureFlags).performCrossStackRedialCheckForEmergencyCall(); + EmergencyStateTracker emergencyStateTracker = setupEmergencyStateTracker( + /* isSuplDdsSwitchRequiredForEmergencyCall= */ true); + Phone phone0 = setupTestPhoneForEmergencyCall(/* isRoaming= */ true, + /* isRadioOn= */ true); + setUpAsyncResultForSetEmergencyMode( + phone0, UNKNOWN_E_REG_RESULT, RILConstants.INTERNAL_ERR); + // Start an emergency call over Phone0 + CompletableFuture<Integer> future = emergencyStateTracker.startEmergencyCall(phone0, + mTestConnection1, false); + + Phone phone1 = getPhone(1); + // Phone0: Disable NTN + doReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID) + .when(phone0).getSubId(); + doReturn(TelephonyManager.SIM_STATE_ABSENT) + .when(mTelephonyManagerProxy).getSimState(eq(0)); + // Phone1: Enable TN + doReturn(2).when(phone1).getSubId(); + doReturn(TelephonyManager.SIM_STATE_READY) + .when(mTelephonyManagerProxy).getSimState(eq(1)); + + processAllMessages(); + + verify(phone0).setEmergencyMode(eq(MODE_EMERGENCY_WWAN), any(Message.class)); + assertTrue(future.isDone()); + // Expect: DisconnectCause#NOT_DISCONNECTED + assertEquals(future.getNow(DisconnectCause.NOT_DISCONNECTED), + Integer.valueOf(DisconnectCause.NOT_DISCONNECTED)); + } + private EmergencyStateTracker setupEmergencyStateTracker( boolean isSuplDdsSwitchRequiredForEmergencyCall) { doReturn(mPhoneSwitcher).when(mPhoneSwitcherProxy).getPhoneSwitcher(); @@ -3572,6 +3649,17 @@ public class EmergencyStateTrackerTest extends TelephonyTest { }).when(phone).setEmergencyMode(anyInt(), any(Message.class)); } + private void setUpAsyncResultForSetEmergencyMode(Phone phone, + EmergencyRegistrationResult regResult, int rilError) { + doAnswer((invocation) -> { + Object[] args = invocation.getArguments(); + final Message msg = (Message) args[1]; + AsyncResult.forMessage(msg, regResult, CommandException.fromRilErrno(rilError)); + msg.sendToTarget(); + return null; + }).when(phone).setEmergencyMode(anyInt(), any(Message.class)); + } + private void setUpAsyncResultForExitEmergencyMode(Phone phone) { doAnswer((invocation) -> { Object[] args = invocation.getArguments(); diff --git a/tests/telephonytests/src/com/android/internal/telephony/euicc/EuiccConnectorTest.java b/tests/telephonytests/src/com/android/internal/telephony/euicc/EuiccConnectorTest.java index 3ec3ab554b..a95d0d72b1 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/euicc/EuiccConnectorTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/euicc/EuiccConnectorTest.java @@ -21,8 +21,8 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; diff --git a/tests/telephonytests/src/com/android/internal/telephony/gsm/GsmInboundSmsHandlerTest.java b/tests/telephonytests/src/com/android/internal/telephony/gsm/GsmInboundSmsHandlerTest.java index e542a41447..5affa6e9a4 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/gsm/GsmInboundSmsHandlerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/gsm/GsmInboundSmsHandlerTest.java @@ -22,12 +22,12 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.nullable; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; diff --git a/tests/telephonytests/src/com/android/internal/telephony/gsm/GsmSmsDispatcherTest.java b/tests/telephonytests/src/com/android/internal/telephony/gsm/GsmSmsDispatcherTest.java index 69358073db..e99a05466a 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/gsm/GsmSmsDispatcherTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/gsm/GsmSmsDispatcherTest.java @@ -25,9 +25,10 @@ import static com.android.internal.telephony.TelephonyTestUtils.waitForMs; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; +import static org.junit.Assume.assumeFalse; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -42,6 +43,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.PackageManager; import android.content.pm.ServiceInfo; import android.location.Country; import android.location.CountryDetector; @@ -54,11 +56,13 @@ import android.provider.Settings; import android.service.carrier.CarrierMessagingService; import android.service.carrier.ICarrierMessagingCallback; import android.service.carrier.ICarrierMessagingService; +import android.telephony.NetworkRegistrationInfo; import android.telephony.ServiceState; import android.telephony.SmsManager; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; +import androidx.test.InstrumentationRegistry; import androidx.test.filters.FlakyTest; import androidx.test.filters.MediumTest; import androidx.test.filters.SmallTest; @@ -72,6 +76,7 @@ import com.android.internal.telephony.TelephonyTest; import com.android.internal.telephony.TelephonyTestUtils; import com.android.internal.telephony.TestApplication; import com.android.internal.telephony.flags.Flags; +import com.android.internal.telephony.satellite.SatelliteController; import com.android.internal.telephony.uicc.IccUtils; import com.android.internal.telephony.uicc.IsimUiccRecords; @@ -100,6 +105,7 @@ public class GsmSmsDispatcherTest extends TelephonyTest { private SMSDispatcher.SmsTracker mSmsTracker; private ISub.Stub mISubStub; private ICarrierMessagingService.Stub mICarrierAppMessagingService; + private SatelliteController mMockSatelliteController; private Object mLock = new Object(); private boolean mReceivedTestIntent; @@ -147,6 +153,9 @@ public class GsmSmsDispatcherTest extends TelephonyTest { mSmsTracker = mock(SMSDispatcher.SmsTracker.class); mISubStub = mock(ISub.Stub.class); mICarrierAppMessagingService = mock(ICarrierMessagingService.Stub.class); + mMockSatelliteController = mock(SatelliteController.class); + replaceInstance(SatelliteController.class, "sInstance", null, + mMockSatelliteController); // Note that this replaces only cached services in ServiceManager. If a service is not found // in the cache, a real instance is used. @@ -534,9 +543,15 @@ public class GsmSmsDispatcherTest extends TelephonyTest { } } + private void skipOnAutomotive() { + assumeFalse(InstrumentationRegistry.getTargetContext().getPackageManager().hasSystemFeature( + PackageManager.FEATURE_AUTOMOTIVE)); + } + @Test @SmallTest public void testSendMultipartSmsByCarrierAppNoResponse() throws Exception { + skipOnAutomotive(); // TODO(b/401440427): don't skip mockCarrierApp(); // do not mock result, instead reduce the timeout for test mGsmSmsDispatcher.mCarrierMessagingTimeout = 100; @@ -694,4 +709,27 @@ public class GsmSmsDispatcherTest extends TelephonyTest { assertFalse(isMtSmsPollingMessage); } + + @Test + public void testShouldBlockPremiumSmsInSatelliteMode() { + doReturn(true).when(mMockSatelliteController).isSatelliteBeingEnabled(); + assertTrue(mGsmSmsDispatcher.shouldBlockPremiumSmsInSatelliteMode()); + + int subId = mPhone.getSubId(); + doReturn(subId).when(mMockSatelliteController).getSelectedSatelliteSubId(); + doReturn(false).when(mMockSatelliteController).isSatelliteBeingEnabled(); + doReturn(true).when(mMockSatelliteController).isSatelliteEnabled(); + doReturn(new int[]{NetworkRegistrationInfo.SERVICE_TYPE_DATA}).when( + mMockSatelliteController).getSupportedServicesOnCarrierRoamingNtn(anyInt()); + assertTrue(mGsmSmsDispatcher.shouldBlockPremiumSmsInSatelliteMode()); + + doReturn(true).when(mMockSatelliteController).isSatelliteEnabled(); + doReturn(new int[]{NetworkRegistrationInfo.SERVICE_TYPE_DATA, + NetworkRegistrationInfo.SERVICE_TYPE_SMS}).when( + mMockSatelliteController).getSupportedServicesOnCarrierRoamingNtn(anyInt()); + assertFalse(mGsmSmsDispatcher.shouldBlockPremiumSmsInSatelliteMode()); + + doReturn(false).when(mMockSatelliteController).isSatelliteEnabled(); + assertFalse(mGsmSmsDispatcher.shouldBlockPremiumSmsInSatelliteMode()); + } } diff --git a/tests/telephonytests/src/com/android/internal/telephony/ims/ImsEnablementTrackerTest.java b/tests/telephonytests/src/com/android/internal/telephony/ims/ImsEnablementTrackerTest.java index 270960cfc6..62e9e87a63 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/ims/ImsEnablementTrackerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/ims/ImsEnablementTrackerTest.java @@ -23,11 +23,11 @@ import static com.android.internal.telephony.ims.ImsEnablementTracker.COMMAND_RE import static junit.framework.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoMoreInteractions; import android.os.Handler; import android.os.Looper; @@ -224,7 +224,7 @@ public class ImsEnablementTrackerTest extends ImsTestBase { mTracker.disableIms(SLOT_1, SUB_1); waitForHandler(mHandler); - verifyZeroInteractions(mMockServiceControllerBinder); + verifyNoMoreInteractions(mMockServiceControllerBinder); assertTrue(mTracker.isState(SLOT_1, mTracker.STATE_IMS_DISABLED)); } @@ -299,7 +299,7 @@ public class ImsEnablementTrackerTest extends ImsTestBase { mTracker.enableIms(SLOT_1, SUB_1); waitForHandler(mHandler); - verifyZeroInteractions(mMockServiceControllerBinder); + verifyNoMoreInteractions(mMockServiceControllerBinder); assertTrue(mTracker.isState(SLOT_1, mTracker.STATE_IMS_ENABLED)); } @@ -417,7 +417,7 @@ public class ImsEnablementTrackerTest extends ImsTestBase { mTracker.enableIms(SLOT_1, SUB_1); waitForHandler(mHandler); - verifyZeroInteractions(mMockServiceControllerBinder); + verifyNoMoreInteractions(mMockServiceControllerBinder); assertTrue(mTracker.isState(SLOT_1, mTracker.STATE_IMS_RESETTING)); } @@ -435,7 +435,7 @@ public class ImsEnablementTrackerTest extends ImsTestBase { mTracker.disableIms(SLOT_1, SUB_1); waitForHandler(mHandler); - verifyZeroInteractions(mMockServiceControllerBinder); + verifyNoMoreInteractions(mMockServiceControllerBinder); assertTrue(mTracker.isState(SLOT_1, mTracker.STATE_IMS_RESETTING)); } diff --git a/tests/telephonytests/src/com/android/internal/telephony/ims/ImsResolverTest.java b/tests/telephonytests/src/com/android/internal/telephony/ims/ImsResolverTest.java index 130fba8ba4..bfc3e4ad3a 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/ims/ImsResolverTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/ims/ImsResolverTest.java @@ -23,9 +23,9 @@ import static junit.framework.Assert.assertTrue; import static junit.framework.TestCase.assertFalse; import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; diff --git a/tests/telephonytests/src/com/android/internal/telephony/ims/ImsServiceControllerTest.java b/tests/telephonytests/src/com/android/internal/telephony/ims/ImsServiceControllerTest.java index 5f16d9b9cf..529acf3968 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/ims/ImsServiceControllerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/ims/ImsServiceControllerTest.java @@ -22,9 +22,9 @@ import static junit.framework.Assert.assertTrue; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; diff --git a/tests/telephonytests/src/com/android/internal/telephony/ims/ImsTestBase.java b/tests/telephonytests/src/com/android/internal/telephony/ims/ImsTestBase.java index c6b0fa1cc6..43d8345ba3 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/ims/ImsTestBase.java +++ b/tests/telephonytests/src/com/android/internal/telephony/ims/ImsTestBase.java @@ -23,6 +23,7 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.MessageQueue; +import android.os.SystemClock; import android.testing.TestableLooper; import androidx.test.InstrumentationRegistry; @@ -31,7 +32,6 @@ import com.android.internal.telephony.TelephonyTest; import org.mockito.MockitoAnnotations; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -41,22 +41,6 @@ import java.util.concurrent.TimeUnit; * Helper class to load Mockito Resources into a test. */ public class ImsTestBase { - private static final Field MESSAGE_QUEUE_FIELD; - private static final Field MESSAGE_WHEN_FIELD; - private static final Field MESSAGE_NEXT_FIELD; - - static { - try { - MESSAGE_QUEUE_FIELD = MessageQueue.class.getDeclaredField("mMessages"); - MESSAGE_QUEUE_FIELD.setAccessible(true); - MESSAGE_WHEN_FIELD = Message.class.getDeclaredField("when"); - MESSAGE_WHEN_FIELD.setAccessible(true); - MESSAGE_NEXT_FIELD = Message.class.getDeclaredField("next"); - MESSAGE_NEXT_FIELD.setAccessible(true); - } catch (NoSuchFieldException e) { - throw new RuntimeException("Failed to initialize TelephonyTest", e); - } - } protected Context mContext; protected List<TestableLooper> mTestableLoopers = new ArrayList<>(); @@ -131,36 +115,12 @@ public class ImsTestBase { } /** - * @return The longest delay from all the message queues. - */ - private long getLongestDelay() { - long delay = 0; - for (TestableLooper looper : mTestableLoopers) { - MessageQueue queue = looper.getLooper().getQueue(); - try { - Message msg = (Message) MESSAGE_QUEUE_FIELD.get(queue); - while (msg != null) { - delay = Math.max(msg.getWhen(), delay); - msg = (Message) MESSAGE_NEXT_FIELD.get(msg); - } - } catch (IllegalAccessException e) { - throw new RuntimeException("Access failed in TelephonyTest", e); - } - } - return delay; - } - - /** * @return {@code true} if there are any messages in the queue. */ private boolean messagesExist() { for (TestableLooper looper : mTestableLoopers) { - MessageQueue queue = looper.getLooper().getQueue(); - try { - Message msg = (Message) MESSAGE_QUEUE_FIELD.get(queue); - if (msg != null) return true; - } catch (IllegalAccessException e) { - throw new RuntimeException("Access failed in TelephonyTest", e); + if (looper.peekWhen() > 0) { + return true; } } return false; @@ -170,8 +130,14 @@ public class ImsTestBase { * Handle all messages including the delayed messages. */ public void processAllFutureMessages() { + final long now = SystemClock.uptimeMillis(); while (messagesExist()) { - moveTimeForward(getLongestDelay()); + for (TestableLooper looper : mTestableLoopers) { + long nextDelay = looper.peekWhen() - now; + if (nextDelay > 0) { + looper.moveTimeForward(nextDelay); + } + } processAllMessages(); } } @@ -196,20 +162,7 @@ public class ImsTestBase { */ public void moveTimeForward(long milliSeconds) { for (TestableLooper looper : mTestableLoopers) { - MessageQueue queue = looper.getLooper().getQueue(); - try { - Message msg = (Message) MESSAGE_QUEUE_FIELD.get(queue); - while (msg != null) { - long updatedWhen = msg.getWhen() - milliSeconds; - if (updatedWhen < 0) { - updatedWhen = 0; - } - MESSAGE_WHEN_FIELD.set(msg, updatedWhen); - msg = (Message) MESSAGE_NEXT_FIELD.get(msg); - } - } catch (IllegalAccessException e) { - throw new RuntimeException("Access failed in TelephonyTest", e); - } + looper.moveTimeForward(milliSeconds); } } } diff --git a/tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsPhoneTest.java b/tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsPhoneTest.java index 5903032063..26ef9b99d8 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsPhoneTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsPhoneTest.java @@ -43,11 +43,11 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyChar; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.nullable; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyChar; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doAnswer; diff --git a/tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsRegistrationCallbackHelperTest.java b/tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsRegistrationCallbackHelperTest.java index 451c31550d..6cc2f4f694 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsRegistrationCallbackHelperTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsRegistrationCallbackHelperTest.java @@ -26,7 +26,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Matchers.anyInt; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; diff --git a/tests/telephonytests/src/com/android/internal/telephony/metrics/PersistAtomsStorageTest.java b/tests/telephonytests/src/com/android/internal/telephony/metrics/PersistAtomsStorageTest.java index 7bd82341cd..5bc8e680f5 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/metrics/PersistAtomsStorageTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/metrics/PersistAtomsStorageTest.java @@ -1153,6 +1153,13 @@ public class PersistAtomsStorageTest extends TelephonyTest { mSatelliteController1.countOfP2PSmsAvailableNotificationShown = 3; mSatelliteController1.countOfP2PSmsAvailableNotificationRemoved = 5; mSatelliteController1.isNtnOnlyCarrier = false; + mSatelliteController1.versionOfSatelliteAccessConfig = 10; + mSatelliteController1.countOfIncomingDatagramTypeSosSmsSuccess = 1; + mSatelliteController1.countOfIncomingDatagramTypeSosSmsFail = 2; + mSatelliteController1.countOfOutgoingDatagramTypeSmsSuccess = 3; + mSatelliteController1.countOfOutgoingDatagramTypeSmsFail = 4; + mSatelliteController1.countOfIncomingDatagramTypeSmsSuccess = 5; + mSatelliteController1.countOfIncomingDatagramTypeSmsFail = 6; mSatelliteController2 = new SatelliteController(); mSatelliteController2.countOfSatelliteServiceEnablementsSuccess = 2 + 1; @@ -1187,6 +1194,13 @@ public class PersistAtomsStorageTest extends TelephonyTest { mSatelliteController2.countOfP2PSmsAvailableNotificationShown = 30; mSatelliteController2.countOfP2PSmsAvailableNotificationRemoved = 50; mSatelliteController2.isNtnOnlyCarrier = true; + mSatelliteController2.versionOfSatelliteAccessConfig = 12; + mSatelliteController2.countOfIncomingDatagramTypeSosSmsSuccess = 11; + mSatelliteController2.countOfIncomingDatagramTypeSosSmsFail = 12; + mSatelliteController2.countOfOutgoingDatagramTypeSmsSuccess = 31; + mSatelliteController2.countOfOutgoingDatagramTypeSmsFail = 14; + mSatelliteController2.countOfIncomingDatagramTypeSmsSuccess = 15; + mSatelliteController2.countOfIncomingDatagramTypeSmsFail = 16; // SatelliteController atom has one data point mSatelliteControllers = @@ -4458,6 +4472,20 @@ public class PersistAtomsStorageTest extends TelephonyTest { expected.countOfP2PSmsAvailableNotificationRemoved = mSatelliteController1.countOfP2PSmsAvailableNotificationRemoved * 2; expected.isNtnOnlyCarrier = mSatelliteController1.isNtnOnlyCarrier; + expected.versionOfSatelliteAccessConfig = + mSatelliteController1.versionOfSatelliteAccessConfig; + expected.countOfIncomingDatagramTypeSosSmsSuccess = + mSatelliteController1.countOfIncomingDatagramTypeSosSmsSuccess * 2; + expected.countOfIncomingDatagramTypeSosSmsFail = + mSatelliteController1.countOfIncomingDatagramTypeSosSmsFail * 2; + expected.countOfOutgoingDatagramTypeSmsSuccess = + mSatelliteController1.countOfOutgoingDatagramTypeSmsSuccess * 2; + expected.countOfOutgoingDatagramTypeSmsFail = + mSatelliteController1.countOfOutgoingDatagramTypeSmsFail * 2; + expected.countOfIncomingDatagramTypeSmsSuccess = + mSatelliteController1.countOfIncomingDatagramTypeSmsSuccess * 2; + expected.countOfIncomingDatagramTypeSmsFail = + mSatelliteController1.countOfIncomingDatagramTypeSmsFail * 2; // Service state and service switch should be added successfully verifyCurrentStateSavedToFileOnce(); @@ -4610,6 +4638,26 @@ public class PersistAtomsStorageTest extends TelephonyTest { satelliteController1.countOfP2PSmsAvailableNotificationRemoved + satelliteController2.countOfP2PSmsAvailableNotificationRemoved; expected.isNtnOnlyCarrier = false; + expected.versionOfSatelliteAccessConfig = + mSatelliteController2.versionOfSatelliteAccessConfig; + expected.countOfIncomingDatagramTypeSosSmsSuccess = + mSatelliteController1.countOfIncomingDatagramTypeSosSmsSuccess + + mSatelliteController2.countOfIncomingDatagramTypeSosSmsSuccess; + expected.countOfIncomingDatagramTypeSosSmsFail = + mSatelliteController1.countOfIncomingDatagramTypeSosSmsFail + + mSatelliteController2.countOfIncomingDatagramTypeSosSmsFail; + expected.countOfOutgoingDatagramTypeSmsSuccess = + mSatelliteController1.countOfOutgoingDatagramTypeSmsSuccess + + mSatelliteController2.countOfOutgoingDatagramTypeSmsSuccess; + expected.countOfOutgoingDatagramTypeSmsFail = + mSatelliteController1.countOfOutgoingDatagramTypeSmsFail + + mSatelliteController2.countOfOutgoingDatagramTypeSmsFail; + expected.countOfIncomingDatagramTypeSmsSuccess = + mSatelliteController1.countOfIncomingDatagramTypeSmsSuccess + + mSatelliteController2.countOfIncomingDatagramTypeSmsSuccess; + expected.countOfIncomingDatagramTypeSmsFail = + mSatelliteController1.countOfIncomingDatagramTypeSmsFail + + mSatelliteController2.countOfIncomingDatagramTypeSmsFail; // Service state and service switch should be added successfully verifyCurrentStateSavedToFileOnce(); @@ -6058,6 +6106,20 @@ public class PersistAtomsStorageTest extends TelephonyTest { stats.countOfP2PSmsAvailableNotificationShown); assertEquals(expectedStats.countOfP2PSmsAvailableNotificationRemoved, stats.countOfP2PSmsAvailableNotificationRemoved); + assertEquals(expectedStats.versionOfSatelliteAccessConfig, + stats.versionOfSatelliteAccessConfig); + assertEquals(expectedStats.countOfIncomingDatagramTypeSosSmsSuccess, + stats.countOfIncomingDatagramTypeSosSmsSuccess); + assertEquals(expectedStats.countOfIncomingDatagramTypeSosSmsFail, + stats.countOfIncomingDatagramTypeSosSmsFail); + assertEquals(expectedStats.countOfOutgoingDatagramTypeSmsSuccess, + stats.countOfOutgoingDatagramTypeSmsSuccess); + assertEquals(expectedStats.countOfOutgoingDatagramTypeSmsFail, + stats.countOfOutgoingDatagramTypeSmsFail); + assertEquals(expectedStats.countOfIncomingDatagramTypeSmsSuccess, + stats.countOfIncomingDatagramTypeSmsSuccess); + assertEquals(expectedStats.countOfIncomingDatagramTypeSmsFail, + stats.countOfIncomingDatagramTypeSmsFail); actualCount++; } } diff --git a/tests/telephonytests/src/com/android/internal/telephony/metrics/SatelliteStatsTest.java b/tests/telephonytests/src/com/android/internal/telephony/metrics/SatelliteStatsTest.java index 0cd5ea1b1f..d438198448 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/metrics/SatelliteStatsTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/metrics/SatelliteStatsTest.java @@ -48,6 +48,7 @@ import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; +import java.util.Arrays; import java.util.concurrent.TimeUnit; public class SatelliteStatsTest extends TelephonyTest { @@ -110,6 +111,13 @@ public class SatelliteStatsTest extends TelephonyTest { .setCountOfP2PSmsAvailableNotificationShown(3) .setCountOfP2PSmsAvailableNotificationRemoved(3) .setIsNtnOnlyCarrier(false) + .setVersionOfSatelliteAccessControl(10) + .setCountOfIncomingDatagramTypeSosSmsSuccess(1) + .setCountOfIncomingDatagramTypeSmsFail(2) + .setCountOfOutgoingDatagramTypeSmsSuccess(3) + .setCountOfOutgoingDatagramTypeSmsFail(4) + .setCountOfIncomingDatagramTypeSmsSuccess(5) + .setCountOfIncomingDatagramTypeSmsFail(6) .build(); mSatelliteStats.onSatelliteControllerMetrics(param); @@ -181,6 +189,20 @@ public class SatelliteStatsTest extends TelephonyTest { stats.countOfP2PSmsAvailableNotificationRemoved); assertEquals(SatelliteStats.SatelliteControllerParams.isNtnOnlyCarrier(), stats.isNtnOnlyCarrier); + assertEquals(SatelliteStats.SatelliteControllerParams.getVersionSatelliteAccessConfig(), + stats.versionOfSatelliteAccessConfig); + assertEquals(param.getCountOfIncomingDatagramTypeSosSmsSuccess(), + stats.countOfIncomingDatagramTypeSosSmsSuccess); + assertEquals(param.getCountOfIncomingDatagramTypeSosSmsFail(), + stats.countOfIncomingDatagramTypeSosSmsFail); + assertEquals(param.getCountOfOutgoingDatagramTypeSmsSuccess(), + stats.countOfOutgoingDatagramTypeSmsSuccess); + assertEquals(param.getCountOfOutgoingDatagramTypeSmsFail(), + stats.countOfOutgoingDatagramTypeSmsFail); + assertEquals(param.getCountOfIncomingDatagramTypeSmsSuccess(), + stats.countOfIncomingDatagramTypeSmsSuccess); + assertEquals(param.getCountOfIncomingDatagramTypeSmsSuccess(), + stats.countOfIncomingDatagramTypeSmsSuccess); verifyNoMoreInteractions(mPersistAtomsStorage); } @@ -636,4 +658,38 @@ public class SatelliteStatsTest extends TelephonyTest { assertEquals(param.getConfigDataSource(), stats.configDataSource); verifyNoMoreInteractions(mPersistAtomsStorage); } + + @Test + public void testReportRepeatedDataWithAscendingOrder() { + int[] supportedSatelliteServicesArray = {3, 2, 1}; + SatelliteStats.CarrierRoamingSatelliteSessionParams sessionParams = + new SatelliteStats.CarrierRoamingSatelliteSessionParams.Builder() + .setSupportedSatelliteServices(supportedSatelliteServicesArray) + .build(); + mSatelliteStats.onCarrierRoamingSatelliteSessionMetrics(sessionParams); + ArgumentCaptor<CarrierRoamingSatelliteSession> sessionArgumentCaptor = + ArgumentCaptor.forClass(CarrierRoamingSatelliteSession.class); + verify(mPersistAtomsStorage).addCarrierRoamingSatelliteSessionStats( + sessionArgumentCaptor.capture()); + CarrierRoamingSatelliteSession sessionStats = sessionArgumentCaptor.getValue(); + + Arrays.sort(supportedSatelliteServicesArray); + assertEquals(supportedSatelliteServicesArray, sessionStats.supportedSatelliteServices); + verifyNoMoreInteractions(mPersistAtomsStorage); + + int[] entitlementServiceTypeArray = {2, 3, 1}; + SatelliteStats.SatelliteEntitlementParams entitlementParams = + new SatelliteStats.SatelliteEntitlementParams.Builder() + .setEntitlementServiceType(entitlementServiceTypeArray) + .build(); + mSatelliteStats.onSatelliteEntitlementMetrics(entitlementParams); + ArgumentCaptor<SatelliteEntitlement> entitlementArgumentCaptor = + ArgumentCaptor.forClass(SatelliteEntitlement.class); + verify(mPersistAtomsStorage).addSatelliteEntitlementStats( + entitlementArgumentCaptor.capture()); + SatelliteEntitlement entitlementStats = entitlementArgumentCaptor.getValue(); + Arrays.sort(entitlementServiceTypeArray); + assertEquals(entitlementServiceTypeArray, entitlementStats.entitlementServiceType); + verifyNoMoreInteractions(mPersistAtomsStorage); + } } diff --git a/tests/telephonytests/src/com/android/internal/telephony/satellite/CarrierRoamingSatelliteControllerStatsTest.java b/tests/telephonytests/src/com/android/internal/telephony/satellite/CarrierRoamingSatelliteControllerStatsTest.java new file mode 100644 index 0000000000..9b76d3a45d --- /dev/null +++ b/tests/telephonytests/src/com/android/internal/telephony/satellite/CarrierRoamingSatelliteControllerStatsTest.java @@ -0,0 +1,595 @@ +/* + * 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.internal.telephony.satellite; + +import static android.telephony.TelephonyManager.UNKNOWN_CARRIER_ID; + +import static com.android.internal.telephony.satellite.SatelliteConstants.CONFIG_DATA_SOURCE_CONFIG_UPDATER; +import static com.android.internal.telephony.satellite.SatelliteConstants.CONFIG_DATA_SOURCE_ENTITLEMENT; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.Mockito.clearInvocations; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import android.testing.AndroidTestingRunner; +import android.testing.TestableLooper; + +import com.android.internal.telephony.TelephonyTest; +import com.android.internal.telephony.metrics.SatelliteStats; +import com.android.internal.telephony.satellite.metrics.CarrierRoamingSatelliteControllerStats; +import com.android.internal.telephony.subscription.SubscriptionManagerService; +import com.android.telephony.Rlog; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentMatchers; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +@RunWith(AndroidTestingRunner.class) +@TestableLooper.RunWithLooper +public class CarrierRoamingSatelliteControllerStatsTest extends TelephonyTest { + private static final String TAG = "CarrierRoamingSatelliteControllerStatsTest"; + private static final int TEST_SUB_ID_0 = 0; + private static final int TEST_SUB_ID_1 = 1; + private static final int TEST_CARRIER_ID_0 = 1000; + private static final int TEST_CARRIER_ID_1 = 1111; + private static final long SESSION_TIME = 100L; + private static final long SESSION_GAP_1 = 1000000L; + private static final long SESSION_GAP_2 = 2000000L; + private static final long SESSION_GAP_3 = 4000000L; + + private TestCarrierRoamingSatelliteControllerStats mTestCarrierRoamingSatelliteControllerStats; + @Mock + private SatelliteStats mMockSatelliteStats; + @Mock + private SubscriptionManagerService mMockSubscriptionManagerService; + + @Before + public void setUp() throws Exception { + super.setUp(getClass().getSimpleName()); + MockitoAnnotations.initMocks(this); + logd(TAG + " Setup!"); + BackupAndRestoreCarrierRoamContParam.backUpStaticParams(); + replaceInstance(SatelliteStats.class, "sInstance", null, mMockSatelliteStats); + mTestCarrierRoamingSatelliteControllerStats = + new TestCarrierRoamingSatelliteControllerStats(); + replaceInstance(SubscriptionManagerService.class, "sInstance", null, + mMockSubscriptionManagerService); + } + + @After + public void tearDown() throws Exception { + Rlog.d(TAG, "tearDown()"); + BackupAndRestoreCarrierRoamContParam.restoreStaticParams(); + super.tearDown(); + } + + @Test + public void testReportConfigDataSource() { + final ExpectedCarrierRoamingSatelliteControllerStatsParam expected = + new ExpectedCarrierRoamingSatelliteControllerStatsParam(); + doReturn(new int[]{TEST_SUB_ID_0}).when( + mMockSubscriptionManagerService).getActiveSubIdList(anyBoolean()); + + initializeStaticParams(); + expected.initializeParams(); + expected.setConfigDataSource(CONFIG_DATA_SOURCE_ENTITLEMENT); + expected.setCarrierId(TEST_CARRIER_ID_0); + expected.setIsMultiSim(false); + clearInvocations(mMockSatelliteStats); + mTestCarrierRoamingSatelliteControllerStats.reportConfigDataSource(TEST_SUB_ID_0, + CONFIG_DATA_SOURCE_ENTITLEMENT); + verify(mMockSatelliteStats, times(1)).onCarrierRoamingSatelliteControllerStatsMetrics( + ArgumentMatchers.argThat(argument -> verifyAssets(expected, argument))); + + doReturn(new int[]{TEST_SUB_ID_0, TEST_SUB_ID_1}).when( + mMockSubscriptionManagerService).getActiveSubIdList(anyBoolean()); + initializeStaticParams(); + expected.initializeParams(); + expected.setConfigDataSource(CONFIG_DATA_SOURCE_CONFIG_UPDATER); + expected.setCarrierId(TEST_CARRIER_ID_1); + expected.setIsMultiSim(true); + clearInvocations(mMockSatelliteStats); + mTestCarrierRoamingSatelliteControllerStats.reportConfigDataSource(TEST_SUB_ID_1, + CONFIG_DATA_SOURCE_CONFIG_UPDATER); + verify(mMockSatelliteStats, times(1)).onCarrierRoamingSatelliteControllerStatsMetrics( + ArgumentMatchers.argThat(argument -> verifyAssets(expected, argument))); + } + + @Test + public void testReportCountOfEntitlementStatusQueryRequest() { + final ExpectedCarrierRoamingSatelliteControllerStatsParam expected = + new ExpectedCarrierRoamingSatelliteControllerStatsParam(); + doReturn(new int[]{TEST_SUB_ID_0}).when( + mMockSubscriptionManagerService).getActiveSubIdList(anyBoolean()); + + initializeStaticParams(); + expected.initializeParams(); + expected.setCountOfEntitlementStatusQueryRequest(1); + expected.setCarrierId(TEST_CARRIER_ID_0); + expected.setIsMultiSim(false); + clearInvocations(mMockSatelliteStats); + mTestCarrierRoamingSatelliteControllerStats.reportCountOfEntitlementStatusQueryRequest( + TEST_SUB_ID_0); + verify(mMockSatelliteStats, times(1)).onCarrierRoamingSatelliteControllerStatsMetrics( + ArgumentMatchers.argThat(argument -> verifyAssets(expected, argument))); + + doReturn(new int[]{TEST_SUB_ID_0, TEST_SUB_ID_1}).when( + mMockSubscriptionManagerService).getActiveSubIdList(anyBoolean()); + initializeStaticParams(); + expected.initializeParams(); + expected.setCountOfEntitlementStatusQueryRequest(1); + expected.setCarrierId(TEST_CARRIER_ID_1); + expected.setIsMultiSim(true); + clearInvocations(mMockSatelliteStats); + mTestCarrierRoamingSatelliteControllerStats.reportCountOfEntitlementStatusQueryRequest( + TEST_SUB_ID_1); + verify(mMockSatelliteStats, times(1)).onCarrierRoamingSatelliteControllerStatsMetrics( + ArgumentMatchers.argThat(argument -> verifyAssets(expected, argument))); + } + + @Test + public void testReportCountOfSatelliteConfigUpdateRequest() { + final ExpectedCarrierRoamingSatelliteControllerStatsParam expected = + new ExpectedCarrierRoamingSatelliteControllerStatsParam(); + doReturn(new int[]{TEST_SUB_ID_0}).when( + mMockSubscriptionManagerService).getActiveSubIdList(anyBoolean()); + initializeStaticParams(); + expected.initializeParams(); + expected.setCountOfSatelliteConfigUpdateRequest(1); + expected.setCarrierId(UNKNOWN_CARRIER_ID); + expected.setIsMultiSim(false); + + clearInvocations(mMockSatelliteStats); + mTestCarrierRoamingSatelliteControllerStats.reportCountOfSatelliteConfigUpdateRequest(); + verify(mMockSatelliteStats, times(1)).onCarrierRoamingSatelliteControllerStatsMetrics( + ArgumentMatchers.argThat(argument -> verifyAssets(expected, argument))); + + doReturn(new int[]{TEST_SUB_ID_0, TEST_SUB_ID_1}).when( + mMockSubscriptionManagerService).getActiveSubIdList(anyBoolean()); + initializeStaticParams(); + expected.initializeParams(); + expected.setCountOfSatelliteConfigUpdateRequest(1); + expected.setCarrierId(UNKNOWN_CARRIER_ID); + expected.setIsMultiSim(true); + + clearInvocations(mMockSatelliteStats); + mTestCarrierRoamingSatelliteControllerStats.reportCountOfSatelliteConfigUpdateRequest(); + verify(mMockSatelliteStats, times(1)).onCarrierRoamingSatelliteControllerStatsMetrics( + ArgumentMatchers.argThat(argument -> verifyAssets(expected, argument))); + } + + @Test + public void testReportCountOfSatelliteNotificationDisplayed() { + final ExpectedCarrierRoamingSatelliteControllerStatsParam expected = + new ExpectedCarrierRoamingSatelliteControllerStatsParam(); + doReturn(new int[]{TEST_SUB_ID_0}).when( + mMockSubscriptionManagerService).getActiveSubIdList(anyBoolean()); + initializeStaticParams(); + expected.initializeParams(); + expected.setCountOfSatelliteNotificationDisplayed(1); + expected.setCarrierId(TEST_CARRIER_ID_0); + expected.setIsMultiSim(false); + + clearInvocations(mMockSatelliteStats); + mTestCarrierRoamingSatelliteControllerStats.reportCountOfSatelliteNotificationDisplayed( + TEST_SUB_ID_0); + verify(mMockSatelliteStats, times(1)).onCarrierRoamingSatelliteControllerStatsMetrics( + ArgumentMatchers.argThat(argument -> verifyAssets(expected, argument))); + + doReturn(new int[]{TEST_SUB_ID_0, TEST_SUB_ID_1}).when( + mMockSubscriptionManagerService).getActiveSubIdList(anyBoolean()); + initializeStaticParams(); + expected.initializeParams(); + expected.setCountOfSatelliteNotificationDisplayed(1); + expected.setCarrierId(TEST_CARRIER_ID_1); + expected.setIsMultiSim(true); + clearInvocations(mMockSatelliteStats); + mTestCarrierRoamingSatelliteControllerStats.reportCountOfSatelliteNotificationDisplayed( + TEST_SUB_ID_1); + verify(mMockSatelliteStats, times(1)).onCarrierRoamingSatelliteControllerStatsMetrics( + ArgumentMatchers.argThat(argument -> verifyAssets(expected, argument))); + } + + @Test + public void testReportCarrierId() { + final ExpectedCarrierRoamingSatelliteControllerStatsParam expected = + new ExpectedCarrierRoamingSatelliteControllerStatsParam(); + doReturn(new int[]{TEST_SUB_ID_0}).when( + mMockSubscriptionManagerService).getActiveSubIdList(anyBoolean()); + initializeStaticParams(); + expected.initializeParams(); + expected.setCarrierId(TEST_CARRIER_ID_0); + expected.setIsMultiSim(false); + + clearInvocations(mMockSatelliteStats); + mTestCarrierRoamingSatelliteControllerStats.reportCarrierId(TEST_CARRIER_ID_0); + verify(mMockSatelliteStats, times(1)).onCarrierRoamingSatelliteControllerStatsMetrics( + ArgumentMatchers.argThat(argument -> verifyAssets(expected, argument))); + + doReturn(new int[]{TEST_SUB_ID_0, TEST_SUB_ID_1}).when( + mMockSubscriptionManagerService).getActiveSubIdList(anyBoolean()); + initializeStaticParams(); + expected.initializeParams(); + expected.setCarrierId(TEST_CARRIER_ID_1); + expected.setIsMultiSim(true); + clearInvocations(mMockSatelliteStats); + mTestCarrierRoamingSatelliteControllerStats.reportCarrierId(TEST_CARRIER_ID_1); + verify(mMockSatelliteStats, times(1)).onCarrierRoamingSatelliteControllerStatsMetrics( + ArgumentMatchers.argThat(argument -> verifyAssets(expected, argument))); + } + + @Test + public void testReportIsDeviceEntitled() { + final ExpectedCarrierRoamingSatelliteControllerStatsParam expected = + new ExpectedCarrierRoamingSatelliteControllerStatsParam(); + doReturn(new int[]{TEST_SUB_ID_0}).when( + mMockSubscriptionManagerService).getActiveSubIdList(anyBoolean()); + initializeStaticParams(); + expected.initializeParams(); + expected.setIsDeviceEntitled(true); + expected.setCarrierId(TEST_CARRIER_ID_0); + expected.setIsMultiSim(false); + + clearInvocations(mMockSatelliteStats); + mTestCarrierRoamingSatelliteControllerStats.reportIsDeviceEntitled(TEST_SUB_ID_0, true); + verify(mMockSatelliteStats, times(1)).onCarrierRoamingSatelliteControllerStatsMetrics( + ArgumentMatchers.argThat(argument -> verifyAssets(expected, argument))); + + doReturn(new int[]{TEST_SUB_ID_0, TEST_SUB_ID_1}).when( + mMockSubscriptionManagerService).getActiveSubIdList(anyBoolean()); + initializeStaticParams(); + expected.initializeParams(); + expected.setIsDeviceEntitled(false); + expected.setCarrierId(TEST_CARRIER_ID_1); + expected.setIsMultiSim(true); + clearInvocations(mMockSatelliteStats); + mTestCarrierRoamingSatelliteControllerStats.reportIsDeviceEntitled(TEST_SUB_ID_1, false); + verify(mMockSatelliteStats, times(1)).onCarrierRoamingSatelliteControllerStatsMetrics( + ArgumentMatchers.argThat(argument -> verifyAssets(expected, argument))); + } + + @Test + public void testSatelliteSessionGaps() { + final ExpectedCarrierRoamingSatelliteControllerStatsParam expected = + new ExpectedCarrierRoamingSatelliteControllerStatsParam(); + doReturn(new int[]{TEST_SUB_ID_0}).when( + mMockSubscriptionManagerService).getActiveSubIdList(anyBoolean()); + initializeStaticParams(); + expected.initializeParams(); + expected.setCarrierId(TEST_CARRIER_ID_0); + expected.setIsMultiSim(false); + clearInvocations(mMockSatelliteStats); + // first satellite session starts + mTestCarrierRoamingSatelliteControllerStats.setCurrentTime(0L); + // session counter is increased when session starts + expected.setCountOfSatelliteSessions(1); + mTestCarrierRoamingSatelliteControllerStats.onSessionStart(TEST_SUB_ID_0); + verify(mMockSatelliteStats, times(1)).onCarrierRoamingSatelliteControllerStatsMetrics( + ArgumentMatchers.argThat(argument -> verifyAssets(expected, argument))); + + clearInvocations(mMockSatelliteStats); + // first satellite session ends + mTestCarrierRoamingSatelliteControllerStats.increaseCurrentTime(SESSION_TIME); + mTestCarrierRoamingSatelliteControllerStats.onSessionEnd(TEST_SUB_ID_0); + + // session gaps would be 0 + expected.setSatelliteSessionGapMinSec(0); + expected.setSatelliteSessionGapAvgSec(0); + expected.setSatelliteSessionGapMaxSec(0); + // session counter is not reported when session ends + expected.setCountOfSatelliteSessions(0); + verify(mMockSatelliteStats, times(1)).onCarrierRoamingSatelliteControllerStatsMetrics( + ArgumentMatchers.argThat(argument -> verifyAssets(expected, argument))); + + clearInvocations(mMockSatelliteStats); + // second session starts, gap between 1st and 2nd session is 1000sec + mTestCarrierRoamingSatelliteControllerStats.increaseCurrentTime(SESSION_GAP_1); + expected.setCountOfSatelliteSessions(1); + mTestCarrierRoamingSatelliteControllerStats.onSessionStart(TEST_SUB_ID_0); + verify(mMockSatelliteStats, times(1)).onCarrierRoamingSatelliteControllerStatsMetrics( + ArgumentMatchers.argThat(argument -> verifyAssets(expected, argument))); + + clearInvocations(mMockSatelliteStats); + // second session end + mTestCarrierRoamingSatelliteControllerStats.increaseCurrentTime(SESSION_TIME); + mTestCarrierRoamingSatelliteControllerStats.onSessionEnd(TEST_SUB_ID_0); + + // session gap min / avg / max would be 1000 each + expected.setSatelliteSessionGapMinSec(1000); + expected.setSatelliteSessionGapAvgSec(1000); + expected.setSatelliteSessionGapMaxSec(1000); + expected.setCountOfSatelliteSessions(0); + verify(mMockSatelliteStats, times(1)).onCarrierRoamingSatelliteControllerStatsMetrics( + ArgumentMatchers.argThat(argument -> verifyAssets(expected, argument))); + + clearInvocations(mMockSatelliteStats); + // 3rd session starts, gap between 2nd and 3rd session is 2000 + mTestCarrierRoamingSatelliteControllerStats.increaseCurrentTime(SESSION_GAP_2); + expected.setCountOfSatelliteSessions(1); + mTestCarrierRoamingSatelliteControllerStats.onSessionStart(TEST_SUB_ID_0); + verify(mMockSatelliteStats, times(1)).onCarrierRoamingSatelliteControllerStatsMetrics( + ArgumentMatchers.argThat(argument -> verifyAssets(expected, argument))); + + clearInvocations(mMockSatelliteStats); + // 3rd session end + mTestCarrierRoamingSatelliteControllerStats.increaseCurrentTime(SESSION_TIME); + mTestCarrierRoamingSatelliteControllerStats.onSessionEnd(TEST_SUB_ID_0); + + // session gap min would be 1000 + expected.setSatelliteSessionGapMinSec(1000); + // session gap avg would be 1500 + int avgGapSec = (int) ((SESSION_GAP_1 + SESSION_GAP_2) / (2 * 1000)); + expected.setSatelliteSessionGapAvgSec(avgGapSec); + // session gap max would be 2000 + expected.setSatelliteSessionGapMaxSec(2000); + expected.setCountOfSatelliteSessions(0); + verify(mMockSatelliteStats, times(1)).onCarrierRoamingSatelliteControllerStatsMetrics( + ArgumentMatchers.argThat(argument -> verifyAssets(expected, argument))); + + clearInvocations(mMockSatelliteStats); + // 4th session starts, gap between 3rd and 4th session is 4000 + mTestCarrierRoamingSatelliteControllerStats.increaseCurrentTime(SESSION_GAP_3); + expected.setCountOfSatelliteSessions(1); + mTestCarrierRoamingSatelliteControllerStats.onSessionStart(TEST_SUB_ID_0); + verify(mMockSatelliteStats, times(1)).onCarrierRoamingSatelliteControllerStatsMetrics( + ArgumentMatchers.argThat(argument -> verifyAssets(expected, argument))); + + clearInvocations(mMockSatelliteStats); + // 4th session end + mTestCarrierRoamingSatelliteControllerStats.increaseCurrentTime(SESSION_TIME); + mTestCarrierRoamingSatelliteControllerStats.onSessionEnd(TEST_SUB_ID_0); + + // session gap min would be 1000 + expected.setSatelliteSessionGapMinSec(1000); + // session gap avg would be 2333 + avgGapSec = (int) ((SESSION_GAP_1 + SESSION_GAP_2 + SESSION_GAP_3) / (3 * 1000)); + expected.setSatelliteSessionGapAvgSec(avgGapSec); + // session gap max would be 4000 + expected.setSatelliteSessionGapMaxSec(4000); + expected.setCountOfSatelliteSessions(0); + verify(mMockSatelliteStats, times(1)).onCarrierRoamingSatelliteControllerStatsMetrics( + ArgumentMatchers.argThat(argument -> verifyAssets(expected, argument))); + } + + private static class BackupAndRestoreCarrierRoamContParam { + private static int sSatelliteSessionGapMinSec; + private static int sSatelliteSessionGapAvgSec; + private static int sSatelliteSessionGapMaxSec; + private static int sCarrierId; + private static boolean sIsDeviceEntitled; + private static boolean sIsMultiSim; + + public static void backUpStaticParams() { + SatelliteStats.CarrierRoamingSatelliteControllerStatsParams param = + new SatelliteStats.CarrierRoamingSatelliteControllerStatsParams.Builder() + .build(); + sSatelliteSessionGapMinSec = param.getSatelliteSessionGapMinSec(); + sSatelliteSessionGapAvgSec = param.getSatelliteSessionGapAvgSec(); + sSatelliteSessionGapMaxSec = param.getSatelliteSessionGapMaxSec(); + sCarrierId = param.getCarrierId(); + sIsDeviceEntitled = param.isDeviceEntitled(); + sIsMultiSim = param.isMultiSim(); + } + + public static void restoreStaticParams() { + SatelliteStats.getInstance().onCarrierRoamingSatelliteControllerStatsMetrics( + new SatelliteStats.CarrierRoamingSatelliteControllerStatsParams.Builder() + .setSatelliteSessionGapMinSec(sSatelliteSessionGapMinSec) + .setSatelliteSessionGapAvgSec(sSatelliteSessionGapAvgSec) + .setSatelliteSessionGapMaxSec(sSatelliteSessionGapMaxSec) + .setCarrierId(sCarrierId) + .setIsDeviceEntitled(sIsDeviceEntitled) + .setIsMultiSim(sIsMultiSim) + .build()); + } + } + + private void initializeStaticParams() { + SatelliteStats.getInstance().onCarrierRoamingSatelliteControllerStatsMetrics( + new SatelliteStats.CarrierRoamingSatelliteControllerStatsParams.Builder() + .setSatelliteSessionGapMinSec(0) + .setSatelliteSessionGapAvgSec(0) + .setSatelliteSessionGapMaxSec(0) + .setCarrierId(UNKNOWN_CARRIER_ID) + .setIsDeviceEntitled(false) + .setIsMultiSim(false) + .build()); + } + + private boolean verifyAssets(ExpectedCarrierRoamingSatelliteControllerStatsParam expected, + SatelliteStats.CarrierRoamingSatelliteControllerStatsParams actual) { + assertEquals(expected.getConfigDataSource(), actual.getConfigDataSource()); + assertEquals(expected.getCountOfEntitlementStatusQueryRequest(), + actual.getCountOfEntitlementStatusQueryRequest()); + assertEquals(expected.getCountOfSatelliteConfigUpdateRequest(), + actual.getCountOfSatelliteConfigUpdateRequest()); + assertEquals(expected.getCountOfSatelliteNotificationDisplayed(), + actual.getCountOfSatelliteNotificationDisplayed()); + assertEquals(expected.getSatelliteSessionGapMinSec(), + actual.getSatelliteSessionGapMinSec()); + assertEquals(expected.getSatelliteSessionGapAvgSec(), + actual.getSatelliteSessionGapAvgSec()); + assertEquals(expected.getSatelliteSessionGapMaxSec(), + actual.getSatelliteSessionGapMaxSec()); + assertEquals(expected.getCarrierId(), actual.getCarrierId()); + assertEquals(expected.isDeviceEntitled(), actual.isDeviceEntitled()); + assertEquals(expected.isMultiSim(), actual.isMultiSim()); + assertEquals(expected.getCountOfSatelliteSessions(), actual.getCountOfSatelliteSessions()); + return true; + } + + private static class ExpectedCarrierRoamingSatelliteControllerStatsParam { + private int mConfigDataSource; + private int mCountOfEntitlementStatusQueryRequest; + private int mCountOfSatelliteConfigUpdateRequest; + private int mCountOfSatelliteNotificationDisplayed; + private int mSatelliteSessionGapMinSec; + private int mSatelliteSessionGapAvgSec; + private int mSatelliteSessionGapMaxSec; + private int mCarrierId; + private boolean mIsDeviceEntitled; + private boolean mIsMultiSim; + private int mCountOfSatelliteSessions; + + public int getConfigDataSource() { + return mConfigDataSource; + } + + public int getCountOfEntitlementStatusQueryRequest() { + return mCountOfEntitlementStatusQueryRequest; + } + + public int getCountOfSatelliteConfigUpdateRequest() { + return mCountOfSatelliteConfigUpdateRequest; + } + + public int getCountOfSatelliteNotificationDisplayed() { + return mCountOfSatelliteNotificationDisplayed; + } + + public int getSatelliteSessionGapMinSec() { + return mSatelliteSessionGapMinSec; + } + + public int getSatelliteSessionGapAvgSec() { + return mSatelliteSessionGapAvgSec; + } + + public int getSatelliteSessionGapMaxSec() { + return mSatelliteSessionGapMaxSec; + } + + public int getCarrierId() { + return mCarrierId; + } + + public boolean isDeviceEntitled() { + return mIsDeviceEntitled; + } + + public boolean isMultiSim() { + return mIsMultiSim; + } + + public int getCountOfSatelliteSessions() { + return mCountOfSatelliteSessions; + } + + + public void setConfigDataSource(int configDataSource) { + mConfigDataSource = configDataSource; + } + + public void setCountOfEntitlementStatusQueryRequest( + int countOfEntitlementStatusQueryRequest) { + mCountOfEntitlementStatusQueryRequest = countOfEntitlementStatusQueryRequest; + } + + public void setCountOfSatelliteConfigUpdateRequest( + int countOfSatelliteConfigUpdateRequest) { + mCountOfSatelliteConfigUpdateRequest = countOfSatelliteConfigUpdateRequest; + } + + public void setCountOfSatelliteNotificationDisplayed( + int countOfSatelliteNotificationDisplayed) { + mCountOfSatelliteNotificationDisplayed = countOfSatelliteNotificationDisplayed; + } + + public void setSatelliteSessionGapMinSec(int satelliteSessionGapMinSec) { + mSatelliteSessionGapMinSec = satelliteSessionGapMinSec; + } + + public void setSatelliteSessionGapAvgSec(int satelliteSessionGapAvgSec) { + mSatelliteSessionGapAvgSec = satelliteSessionGapAvgSec; + } + + public void setSatelliteSessionGapMaxSec(int satelliteSessionGapMaxSec) { + mSatelliteSessionGapMaxSec = satelliteSessionGapMaxSec; + } + + public void setCarrierId(int carrierId) { + mCarrierId = carrierId; + } + + public void setIsDeviceEntitled(boolean isDeviceEntitled) { + mIsDeviceEntitled = isDeviceEntitled; + } + + public void setIsMultiSim(boolean isMultiSim) { + mIsMultiSim = isMultiSim; + } + + public void setCountOfSatelliteSessions(int countOfSatelliteSessions) { + mCountOfSatelliteSessions = countOfSatelliteSessions; + } + + public void initializeParams() { + mConfigDataSource = SatelliteConstants.CONFIG_DATA_SOURCE_UNKNOWN; + mCountOfEntitlementStatusQueryRequest = 0; + mCountOfSatelliteConfigUpdateRequest = 0; + mCountOfSatelliteNotificationDisplayed = 0; + mSatelliteSessionGapMinSec = 0; + mSatelliteSessionGapAvgSec = 0; + mSatelliteSessionGapMaxSec = 0; + mCarrierId = UNKNOWN_CARRIER_ID; + mIsDeviceEntitled = false; + mIsMultiSim = false; + mCountOfSatelliteSessions = 0; + } + } + + static class TestCarrierRoamingSatelliteControllerStats extends + CarrierRoamingSatelliteControllerStats { + private long mCurrentTime; + TestCarrierRoamingSatelliteControllerStats() { + super(); + logd("constructing TestCarrierRoamingSatelliteControllerStats"); + } + + @Override + public int getCarrierIdFromSubscription(int subId) { + logd("getCarrierIdFromSubscription()"); + if (subId == TEST_SUB_ID_0) { + return TEST_CARRIER_ID_0; + } else if (subId == TEST_SUB_ID_1) { + return TEST_CARRIER_ID_1; + } else { + return UNKNOWN_CARRIER_ID; + } + } + + @Override + public long getCurrentTime() { + return mCurrentTime; + } + + public void setCurrentTime(long currentTime) { + mCurrentTime = currentTime; + } + + public void increaseCurrentTime(long incTime) { + mCurrentTime += incTime; + } + } +} diff --git a/tests/telephonytests/src/com/android/internal/telephony/satellite/DatagramControllerTest.java b/tests/telephonytests/src/com/android/internal/telephony/satellite/DatagramControllerTest.java index 7cb53d28b3..f4d7e61cc9 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/satellite/DatagramControllerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/satellite/DatagramControllerTest.java @@ -35,7 +35,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -148,9 +148,9 @@ public class DatagramControllerTest extends TelephonyTest { int errorCode = SATELLITE_RESULT_SUCCESS; mDatagramControllerUT.updateSendStatus(SUB_ID, DATAGRAM_TYPE_KEEP_ALIVE, SATELLITE_DATAGRAM_TRANSFER_STATE_SENDING, sendPendingCount, errorCode); - verifyZeroInteractions(mMockSatelliteSessionController); - verifyZeroInteractions(mMockPointingAppController); - verifyZeroInteractions(mMockDatagramReceiver); + verifyNoMoreInteractions(mMockSatelliteSessionController); + verifyNoMoreInteractions(mMockPointingAppController); + verifyNoMoreInteractions(mMockDatagramReceiver); } @Test diff --git a/tests/telephonytests/src/com/android/internal/telephony/satellite/DatagramDispatcherTest.java b/tests/telephonytests/src/com/android/internal/telephony/satellite/DatagramDispatcherTest.java index cb1715d958..f3830689bb 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/satellite/DatagramDispatcherTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/satellite/DatagramDispatcherTest.java @@ -43,7 +43,6 @@ import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import android.annotation.NonNull; @@ -230,7 +229,7 @@ public class DatagramDispatcherTest extends TelephonyTest { eq(SATELLITE_RESULT_SUCCESS)); mInOrder.verify(mMockDatagramController).getDatagramWaitTimeForConnectedState( eq(SatelliteServiceUtils.isLastSosMessage(datagramType))); - verifyZeroInteractions(mMockSatelliteModemInterface); + verifyNoMoreInteractions(mMockSatelliteModemInterface); assertTrue(mDatagramDispatcherUT.isDatagramWaitForConnectedStateTimerStarted()); doReturn(false).when(mMockDatagramController) @@ -273,7 +272,7 @@ public class DatagramDispatcherTest extends TelephonyTest { mDatagramDispatcherUT.sendSatelliteDatagram(SUB_ID, datagramType, mDatagram, true, mResultListener::offer); processAllMessages(); - verifyZeroInteractions(mMockSatelliteModemInterface); + verifyNoMoreInteractions(mMockSatelliteModemInterface); mInOrder.verify(mMockDatagramController) .needsWaitingForSatelliteConnected(eq(datagramType)); mInOrder.verify(mMockDatagramController).getDatagramWaitTimeForConnectedState( @@ -282,7 +281,7 @@ public class DatagramDispatcherTest extends TelephonyTest { moveTimeForward(TEST_DATAGRAM_WAIT_FOR_CONNECTED_STATE_TIMEOUT_MILLIS); processAllMessages(); - verifyZeroInteractions(mMockSatelliteModemInterface); + verifyNoMoreInteractions(mMockSatelliteModemInterface); mInOrder.verify(mMockDatagramController) .updateSendStatus(eq(mPhone.getSubId()), eq(datagramType), @@ -305,7 +304,7 @@ public class DatagramDispatcherTest extends TelephonyTest { mDatagramDispatcherUT.onSatelliteModemStateChanged( SatelliteManager.SATELLITE_MODEM_STATE_CONNECTED); processAllMessages(); - verifyZeroInteractions(mMockSatelliteModemInterface); + verifyNoMoreInteractions(mMockSatelliteModemInterface); assertEquals(0, mResultListener.size()); clearInvocations(mMockSatelliteModemInterface); @@ -315,7 +314,7 @@ public class DatagramDispatcherTest extends TelephonyTest { mDatagramDispatcherUT.sendSatelliteDatagram(SUB_ID, datagramType, mDatagram, true, mResultListener::offer); processAllMessages(); - verifyZeroInteractions(mMockSatelliteModemInterface); + verifyNoMoreInteractions(mMockSatelliteModemInterface); mInOrder.verify(mMockDatagramController) .needsWaitingForSatelliteConnected(eq(datagramType)); mInOrder.verify(mMockDatagramController).getDatagramWaitTimeForConnectedState( @@ -329,7 +328,7 @@ public class DatagramDispatcherTest extends TelephonyTest { mDatagramDispatcherUT.onSatelliteModemStateChanged( SatelliteManager.SATELLITE_MODEM_STATE_OFF); processAllMessages(); - verifyZeroInteractions(mMockSatelliteModemInterface); + verifyNoMoreInteractions(mMockSatelliteModemInterface); assertEquals(1, mResultListener.size()); assertThat(mResultListener.peek()).isEqualTo( SatelliteManager.SATELLITE_RESULT_REQUEST_ABORTED); @@ -805,7 +804,7 @@ public class DatagramDispatcherTest extends TelephonyTest { eq(SATELLITE_RESULT_SUCCESS)); mInOrder.verify(mMockDatagramController).getDatagramWaitTimeForConnectedState( eq(SatelliteServiceUtils.isLastSosMessage(datagramType))); - verifyZeroInteractions(mMockSmsDispatchersController); + verifyNoMoreInteractions(mMockSmsDispatchersController); assertTrue(mDatagramDispatcherUT.isDatagramWaitForConnectedStateTimerStarted()); doReturn(false).when(mMockDatagramController) @@ -899,7 +898,7 @@ public class DatagramDispatcherTest extends TelephonyTest { eq(SATELLITE_RESULT_SUCCESS)); mInOrder.verify(mMockDatagramController).getDatagramWaitTimeForConnectedState( eq(SatelliteServiceUtils.isLastSosMessage(datagramType))); - verifyZeroInteractions(mMockSmsDispatchersController); + verifyNoMoreInteractions(mMockSmsDispatchersController); assertTrue(mDatagramDispatcherUT.isDatagramWaitForConnectedStateTimerStarted()); moveTimeForward(TEST_DATAGRAM_WAIT_FOR_CONNECTED_STATE_TIMEOUT_MILLIS); @@ -922,7 +921,7 @@ public class DatagramDispatcherTest extends TelephonyTest { mDatagramDispatcherUT.onSatelliteModemStateChanged( SatelliteManager.SATELLITE_MODEM_STATE_CONNECTED); processAllMessages(); - verifyZeroInteractions(mMockSmsDispatchersController); + verifyNoMoreInteractions(mMockSmsDispatchersController); } @Test @@ -947,7 +946,7 @@ public class DatagramDispatcherTest extends TelephonyTest { eq(SATELLITE_RESULT_SUCCESS)); mInOrder.verify(mMockDatagramController).getDatagramWaitTimeForConnectedState( eq(SatelliteServiceUtils.isLastSosMessage(datagramType))); - verifyZeroInteractions(mMockSmsDispatchersController); + verifyNoMoreInteractions(mMockSmsDispatchersController); assertTrue(mDatagramDispatcherUT.isDatagramWaitForConnectedStateTimerStarted()); mDatagramDispatcherUT.onSatelliteModemStateChanged( @@ -1008,7 +1007,7 @@ public class DatagramDispatcherTest extends TelephonyTest { eq(SATELLITE_RESULT_SUCCESS)); mInOrder.verify(mMockDatagramController).getDatagramWaitTimeForConnectedState( eq(SatelliteServiceUtils.isLastSosMessage(datagramTypeSms))); - verifyZeroInteractions(mMockSmsDispatchersController); + verifyNoMoreInteractions(mMockSmsDispatchersController); assertTrue(mDatagramDispatcherUT.isDatagramWaitForConnectedStateTimerStarted()); mDatagramDispatcherUT.sendSatelliteDatagram(SUB_ID, datagramTypeSos, mDatagram, @@ -1020,7 +1019,7 @@ public class DatagramDispatcherTest extends TelephonyTest { eq(SatelliteManager.SATELLITE_DATAGRAM_TRANSFER_STATE_WAITING_TO_CONNECT), eq(2), eq(SATELLITE_RESULT_SUCCESS)); - verifyZeroInteractions(mMockSatelliteModemInterface); + verifyNoMoreInteractions(mMockSatelliteModemInterface); assertTrue(mDatagramDispatcherUT.isDatagramWaitForConnectedStateTimerStarted()); doReturn(false).when(mMockDatagramController) @@ -1108,7 +1107,7 @@ public class DatagramDispatcherTest extends TelephonyTest { mDatagramDispatcherUT.sendSatelliteDatagram(SUB_ID, datagramTypeSos, mDatagram, true, mResultListener::offer); processAllMessages(); - verifyZeroInteractions(mMockSatelliteModemInterface); + verifyNoMoreInteractions(mMockSatelliteModemInterface); mDatagramDispatcherUT.onSendSmsDone(mPhone.getSubId(), mPendingSms.uniqueMessageId, true); processAllMessages(); @@ -1172,7 +1171,7 @@ public class DatagramDispatcherTest extends TelephonyTest { mDatagramDispatcherUT.obtainMessage(10 /*EVENT_MT_SMS_POLLING_THROTTLE_TIMED_OUT*/, new AsyncResult(null, null, null))); - verifyZeroInteractions(mMockSmsDispatchersController); + verifyNoMoreInteractions(mMockSmsDispatchersController); } @Test @@ -1189,7 +1188,7 @@ public class DatagramDispatcherTest extends TelephonyTest { mDatagramDispatcherUT.obtainMessage(10 /*EVENT_MT_SMS_POLLING_THROTTLE_TIMED_OUT*/, new AsyncResult(null, null, null))); - verifyZeroInteractions(mMockSmsDispatchersController); + verifyNoMoreInteractions(mMockSmsDispatchersController); } @@ -1216,7 +1215,7 @@ public class DatagramDispatcherTest extends TelephonyTest { mDatagramDispatcherUT.setDeviceAlignedWithSatellite(false); - verifyZeroInteractions(mMockSmsDispatchersController); + verifyNoMoreInteractions(mMockSmsDispatchersController); } @Test diff --git a/tests/telephonytests/src/com/android/internal/telephony/satellite/DatagramReceiverTest.java b/tests/telephonytests/src/com/android/internal/telephony/satellite/DatagramReceiverTest.java index 738a44e7d0..b72cff85e6 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/satellite/DatagramReceiverTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/satellite/DatagramReceiverTest.java @@ -38,7 +38,6 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import android.annotation.NonNull; @@ -190,7 +189,7 @@ public class DatagramReceiverTest extends TelephonyTest { eq(SatelliteManager.SATELLITE_DATAGRAM_TRANSFER_STATE_WAITING_TO_CONNECT), eq(0), eq(SatelliteManager.SATELLITE_RESULT_SUCCESS)); mInOrder.verify(mMockDatagramController).getDatagramWaitTimeForConnectedState(eq(false)); - verifyZeroInteractions(mMockSatelliteModemInterface); + verifyNoMoreInteractions(mMockSatelliteModemInterface); assertTrue(mDatagramReceiverUT.isDatagramWaitForConnectedStateTimerStarted()); doReturn(false).when(mMockDatagramController) @@ -220,7 +219,7 @@ public class DatagramReceiverTest extends TelephonyTest { mInOrder.verify(mMockDatagramController) .needsWaitingForSatelliteConnected(eq(SatelliteManager.DATAGRAM_TYPE_UNKNOWN)); mInOrder.verify(mMockDatagramController).getDatagramWaitTimeForConnectedState(eq(false)); - verifyZeroInteractions(mMockSatelliteModemInterface); + verifyNoMoreInteractions(mMockSatelliteModemInterface); assertTrue(mDatagramReceiverUT.isDatagramWaitForConnectedStateTimerStarted()); moveTimeForward(TEST_DATAGRAM_WAIT_FOR_CONNECTED_STATE_TIMEOUT_MILLIS); @@ -233,7 +232,7 @@ public class DatagramReceiverTest extends TelephonyTest { eq(SatelliteManager.DATAGRAM_TYPE_SOS_MESSAGE), eq(SatelliteManager.SATELLITE_DATAGRAM_TRANSFER_STATE_IDLE), eq(0), eq(SatelliteManager.SATELLITE_RESULT_SUCCESS)); - verifyZeroInteractions(mMockSatelliteModemInterface); + verifyNoMoreInteractions(mMockSatelliteModemInterface); assertEquals(1, mResultListener.size()); assertThat(mResultListener.peek()).isEqualTo( SatelliteManager.SATELLITE_RESULT_NOT_REACHABLE); @@ -244,7 +243,7 @@ public class DatagramReceiverTest extends TelephonyTest { mDatagramReceiverUT.onSatelliteModemStateChanged( SatelliteManager.SATELLITE_MODEM_STATE_CONNECTED); processAllMessages(); - verifyZeroInteractions(mMockSatelliteModemInterface); + verifyNoMoreInteractions(mMockSatelliteModemInterface); assertEquals(0, mResultListener.size()); } diff --git a/tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteControllerTest.java b/tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteControllerTest.java index e475630a6e..26e0dc0e46 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteControllerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteControllerTest.java @@ -107,7 +107,6 @@ import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.anyVararg; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.clearInvocations; @@ -648,7 +647,7 @@ public class SatelliteControllerTest extends TelephonyTest { mCarrierConfigBundle = mContextFixture.getCarrierConfigBundle(); doReturn(mCarrierConfigBundle) - .when(mCarrierConfigManager).getConfigForSubId(anyInt(), anyVararg()); + .when(mCarrierConfigManager).getConfigForSubId(anyInt(), any()); doAnswer(invocation -> { Executor executor = invocation.getArgument(0); CarrierConfigManager.CarrierConfigChangeListener listener = invocation.getArgument(1); @@ -3919,7 +3918,7 @@ public class SatelliteControllerTest extends TelephonyTest { KEY_EMERGENCY_CALL_TO_SATELLITE_T911_HANDOVER_TIMEOUT_MILLIS_INT, timeoutMillisForCarrier1); doReturn(carrierConfigBundle1) - .when(mCarrierConfigManager).getConfigForSubId(eq(SUB_ID), anyVararg()); + .when(mCarrierConfigManager).getConfigForSubId(eq(SUB_ID), any()); int timeoutMillisForCarrier2 = 2000; PersistableBundle carrierConfigBundle2 = new PersistableBundle(); @@ -3931,7 +3930,7 @@ public class SatelliteControllerTest extends TelephonyTest { KEY_EMERGENCY_CALL_TO_SATELLITE_T911_HANDOVER_TIMEOUT_MILLIS_INT, timeoutMillisForCarrier2); doReturn(carrierConfigBundle2) - .when(mCarrierConfigManager).getConfigForSubId(eq(SUB_ID1), anyVararg()); + .when(mCarrierConfigManager).getConfigForSubId(eq(SUB_ID1), any()); for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair : mCarrierConfigChangedListenerList) { diff --git a/tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteSOSMessageRecommenderTest.java b/tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteSOSMessageRecommenderTest.java index 0a60b856c0..2d8fb21e73 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteSOSMessageRecommenderTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteSOSMessageRecommenderTest.java @@ -332,6 +332,43 @@ public class SatelliteSOSMessageRecommenderTest extends TelephonyTest { } @Test + public void testTimeoutBeforeEmergencyCallEnd_EventDisplayEmergencyMessageNotSent_Test2() { + /* + * This test is to test the case where the device is provisioned, supports satellite + * via OEM, and is connected via carrier within the hysteresis time. However, satellite + * is not allowed at current location and emergency messaing via carrier is not supported. + * In this case, the EVENT_DISPLAY_EMERGENCY_MESSAGE should not be sent. + */ + mTestSatelliteController.setSatelliteConnectedViaCarrierWithinHysteresisTime(true, SUB_ID1); + mTestSatelliteController.isSatelliteEmergencyMessagingSupportedViaCarrier = false; + mTestSatelliteController.isOemEnabledSatelliteSupported = true; + mTestSatelliteController.setDeviceProvisioned(true); + mTestSOSMessageRecommender.isSatelliteAllowedCallback = null; + mTestSOSMessageRecommender.onEmergencyCallStarted(mTestConnection, false); + processAllMessages(); + assertEquals(1, mTestSOSMessageRecommender.getCountOfTimerStarted()); + assertRegisterForStateChangedEventsTriggered(mPhone, 1, 1); + assertRegisterForStateChangedEventsTriggered(mPhone2, 1, 1); + assertNull(mTestSOSMessageRecommender.isSatelliteAllowedCallback); + + // Move Location service to emergency mode + mTestSOSMessageRecommender.onEmergencyCallConnectionStateChanged( + mTestConnection.getTelecomCallId(), Connection.STATE_DIALING); + processAllMessages(); + assertNotNull(mTestSOSMessageRecommender.isSatelliteAllowedCallback); + + // Wait for the timeout to expires + mTestSOSMessageRecommender.isSatelliteAllowedCallback.onResult(false); + moveTimeForward(TEST_EMERGENCY_CALL_TO_SOS_MSG_HYSTERESIS_TIMEOUT_MILLIS); + processAllMessages(); + assertFalse(mTestConnection.isEventSent(TelephonyManager.EVENT_DISPLAY_EMERGENCY_MESSAGE)); + assertUnregisterForStateChangedEventsTriggered(mPhone, 1, 1); + assertUnregisterForStateChangedEventsTriggered(mPhone2, 1, 1); + verify(mMockSatelliteStats, times(1)).onSatelliteSosMessageRecommender(any()); + assertFalse(mTestSOSMessageRecommender.isDialerNotified()); + } + + @Test public void testTimeoutBeforeEmergencyCallEnd_T911_FromNotConnectedToConnected() { mTestSOSMessageRecommender.isSatelliteAllowedCallback = null; mTestSatelliteController.setSatelliteConnectedViaCarrierWithinHysteresisTime(false, -1); @@ -684,6 +721,20 @@ public class SatelliteSOSMessageRecommenderTest extends TelephonyTest { processAllMessages(); assertEquals(carrierTimeoutMillis, mTestSOSMessageRecommender.getTimeOutMillis()); verify(mMockSatelliteStats, never()).onSatelliteSosMessageRecommender(any()); + + // OEM supports satellite, device is connected to carrier satellite within hysteresis time, + // but emergency messaging via carrier is not supported. Thus, OEM timer will be used. + mTestSatelliteController.isSatelliteEmergencyMessagingSupportedViaCarrier = false; + mTestSatelliteController.setSatelliteConnectedViaCarrierWithinHysteresisTime(true, SUB_ID1); + subscriptionInfo = new SubscriptionInfo.Builder() + .setId(SUB_ID1).setOnlyNonTerrestrialNetwork(true).build(); + when(mMockSubscriptionManagerService.getSubscriptionInfo(eq(SUB_ID1))) + .thenReturn(subscriptionInfo); + mTestSOSMessageRecommender.onEmergencyCallStarted(mTestConnection, false); + processAllMessages(); + assertEquals(TEST_EMERGENCY_CALL_TO_SOS_MSG_HYSTERESIS_TIMEOUT_MILLIS, + mTestSOSMessageRecommender.getTimeOutMillis()); + verify(mMockSatelliteStats, never()).onSatelliteSosMessageRecommender(any()); } @Test @@ -717,6 +768,22 @@ public class SatelliteSOSMessageRecommenderTest extends TelephonyTest { } @Test + public void testGetEmergencyCallToSatelliteHandoverType_OnlySatelliteViaOemAvailable() { + mSetFlagsRule.enableFlags(Flags.FLAG_CARRIER_ROAMING_NB_IOT_NTN); + + mTestSatelliteController.setSatelliteConnectedViaCarrierWithinHysteresisTime(true, SUB_ID1); + mTestSatelliteController.isSatelliteEmergencyMessagingSupportedViaCarrier = false; + mTestSatelliteController.isOemEnabledSatelliteSupported = true; + mTestSatelliteController.setDeviceProvisioned(true); + mTestSOSMessageRecommender.onEmergencyCallStarted(mTestConnection, false); + assertEquals(EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS, + mTestSOSMessageRecommender.getEmergencyCallToSatelliteHandoverType()); + verify(mMockSatelliteStats, never()).onSatelliteSosMessageRecommender(any()); + + mSetFlagsRule.disableFlags(Flags.FLAG_CARRIER_ROAMING_NB_IOT_NTN); + } + + @Test public void testGetEmergencyCallToSatelliteHandoverType_OemAndCarrierNotAvailable() { mSetFlagsRule.enableFlags(Flags.FLAG_CARRIER_ROAMING_NB_IOT_NTN); diff --git a/tests/telephonytests/src/com/android/internal/telephony/uicc/IccPhoneBookInterfaceManagerTest.java b/tests/telephonytests/src/com/android/internal/telephony/uicc/IccPhoneBookInterfaceManagerTest.java index 53627ca94d..8cf8c6e89c 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/uicc/IccPhoneBookInterfaceManagerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/uicc/IccPhoneBookInterfaceManagerTest.java @@ -18,8 +18,7 @@ package com.android.internal.telephony.uicc; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; @@ -87,7 +86,7 @@ public class IccPhoneBookInterfaceManagerTest extends TelephonyTest { response.sendToTarget(); return null; } - }).when(mAdnRecordCache).requestLoadAllAdnLike(anyInt(), anyInt(), (Message) anyObject()); + }).when(mAdnRecordCache).requestLoadAllAdnLike(anyInt(), anyInt(), (Message) any()); doAnswer(invocation -> { Message response = (Message) invocation.getArguments()[0]; @@ -95,7 +94,7 @@ public class IccPhoneBookInterfaceManagerTest extends TelephonyTest { AsyncResult.forMessage(response).result = mAdnList; response.sendToTarget(); return null; - }).when(mSimPhonebookRecordCache).requestLoadAllPbRecords((Message)anyObject()); + }).when(mSimPhonebookRecordCache).requestLoadAllPbRecords((Message)any()); mIccPhoneBookInterfaceManagerHandler = new IccPhoneBookInterfaceManagerHandler(TAG); mIccPhoneBookInterfaceManagerHandler.start(); @@ -131,7 +130,7 @@ public class IccPhoneBookInterfaceManagerTest extends TelephonyTest { response.sendToTarget(); return null; } - }).when(mAdnRecordCache).requestLoadAllAdnLike(anyInt(), anyInt(), (Message) anyObject()); + }).when(mAdnRecordCache).requestLoadAllAdnLike(anyInt(), anyInt(), (Message) any()); List<AdnRecord> adnListResultNew = mIccPhoneBookInterfaceMgr.getAdnRecordsInEf( IccConstants.EF_ADN); //the later read return null due to exception @@ -153,7 +152,7 @@ public class IccPhoneBookInterfaceManagerTest extends TelephonyTest { AsyncResult.forMessage(response).exception = new RuntimeException(); response.sendToTarget(); return null; - }).when(mSimPhonebookRecordCache).requestLoadAllPbRecords((Message) anyObject()); + }).when(mSimPhonebookRecordCache).requestLoadAllPbRecords((Message) any()); List<AdnRecord> adnListResultNew = mIccPhoneBookInterfaceMgr.getAdnRecordsInEf( IccConstants.EF_ADN); //the later read return null due to exception @@ -177,7 +176,7 @@ public class IccPhoneBookInterfaceManagerTest extends TelephonyTest { } }).when(mAdnRecordCache).updateAdnBySearch( anyInt(), any(), any(), - any(), (Message) anyObject()); + any(), (Message) any()); ContentValues values = new ContentValues(); values.put(IccProvider.STR_TAG, ""); @@ -206,7 +205,7 @@ public class IccPhoneBookInterfaceManagerTest extends TelephonyTest { response.sendToTarget(); return null; }).when(mSimPhonebookRecordCache).updateSimPbAdnBySearch(any(), - any(), (Message) anyObject()); + any(), (Message) any()); ContentValues values = new ContentValues(); values.put(IccProvider.STR_TAG, ""); diff --git a/tests/telephonytests/src/com/android/internal/telephony/uicc/SIMRecordsTest.java b/tests/telephonytests/src/com/android/internal/telephony/uicc/SIMRecordsTest.java index e109ebb475..7dc13a0b9c 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/uicc/SIMRecordsTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/uicc/SIMRecordsTest.java @@ -23,7 +23,7 @@ import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.isNull; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; diff --git a/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccCarrierPrivilegeRulesTest.java b/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccCarrierPrivilegeRulesTest.java index 9a444d7b0f..7e95107fee 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccCarrierPrivilegeRulesTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccCarrierPrivilegeRulesTest.java @@ -17,8 +17,8 @@ package com.android.internal.telephony.uicc; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.doAnswer; diff --git a/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccPortTest.java b/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccPortTest.java index 47b7c53259..ac11c920c4 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccPortTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccPortTest.java @@ -23,7 +23,7 @@ import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; diff --git a/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccSlotTest.java b/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccSlotTest.java index 8449eccb79..1de15fef9c 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccSlotTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccSlotTest.java @@ -21,7 +21,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -428,8 +428,8 @@ public class UiccSlotTest extends TelephonyTest { mIccCardStatus.mSlotPortMapping.mPortIndex = 0; mUiccSlot.update(mSimulatedCommands, mIccCardStatus, phoneId, slotIndex); verify(mTelephonyComponentFactory).makeUiccProfile( - anyObject(), eq(mSimulatedCommands), eq(mIccCardStatus), anyInt(), anyObject(), - anyObject(), anyObject()); + any(), eq(mSimulatedCommands), eq(mIccCardStatus), anyInt(), any(), + any(), any()); assertEquals(IccCardStatus.CardState.CARDSTATE_PRESENT, mUiccSlot.getCardState()); assertNotNull(mUiccSlot.getUiccCard()); @@ -451,8 +451,8 @@ public class UiccSlotTest extends TelephonyTest { mIccCardStatus.mCardState = IccCardStatus.CardState.CARDSTATE_PRESENT; mUiccSlot.update(mSimulatedCommands, mIccCardStatus, phoneId, slotIndex); verify(mTelephonyComponentFactory).makeUiccProfile( - anyObject(), eq(mSimulatedCommands), eq(mIccCardStatus), anyInt(), anyObject(), - anyObject(), anyObject()); + any(), eq(mSimulatedCommands), eq(mIccCardStatus), anyInt(), any(), + any(), any()); assertEquals(IccCardStatus.CardState.CARDSTATE_PRESENT, mUiccSlot.getCardState()); assertNotNull(mUiccSlot.getUiccCard()); diff --git a/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccStateChangedLauncherTest.java b/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccStateChangedLauncherTest.java index c9b159c32e..5eeb949377 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccStateChangedLauncherTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccStateChangedLauncherTest.java @@ -19,7 +19,6 @@ package com.android.internal.telephony.uicc; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; -import static org.mockito.Mockito.anyObject; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -99,7 +98,7 @@ public class UiccStateChangedLauncherTest extends TelephonyTest { ArgumentCaptor<Integer> integerArgumentCaptor = ArgumentCaptor.forClass(Integer.class); verify(UiccController.getInstance(), times(1)).registerForIccChanged(eq(uiccLauncher), integerArgumentCaptor.capture(), - anyObject()); + any()); Message msg = Message.obtain(); msg.what = integerArgumentCaptor.getValue(); @@ -163,6 +162,6 @@ public class UiccStateChangedLauncherTest extends TelephonyTest { UiccStateChangedLauncher uiccLauncher = new UiccStateChangedLauncher(mContext, UiccController.getInstance(), mFeatureFlags); verify(UiccController.getInstance(), never()).registerForIccChanged(eq(uiccLauncher), - anyInt(), anyObject()); + anyInt(), any()); } } |