1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.internal.telephony.satellite; 18 19 import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY; 20 import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY; 21 import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED; 22 import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_OPEN; 23 import static android.hardware.devicestate.feature.flags.Flags.FLAG_DEVICE_STATE_PROPERTY_MIGRATION; 24 import static android.telephony.CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC; 25 import static android.telephony.CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL; 26 import static android.telephony.CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL; 27 import static android.telephony.CarrierConfigManager.KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT; 28 import static android.telephony.CarrierConfigManager.KEY_CARRIER_SUPPORTED_SATELLITE_NOTIFICATION_HYSTERESIS_SEC_INT; 29 import static android.telephony.CarrierConfigManager.KEY_EMERGENCY_CALL_TO_SATELLITE_T911_HANDOVER_TIMEOUT_MILLIS_INT; 30 import static android.telephony.CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL; 31 import static android.telephony.CarrierConfigManager.KEY_SATELLITE_CONNECTION_HYSTERESIS_SEC_INT; 32 import static android.telephony.CarrierConfigManager.KEY_SATELLITE_ESOS_SUPPORTED_BOOL; 33 import static android.telephony.CarrierConfigManager.KEY_SATELLITE_NIDD_APN_NAME_STRING; 34 import static android.telephony.CarrierConfigManager.KEY_SATELLITE_ROAMING_P2P_SMS_SUPPORTED_BOOL; 35 import static android.telephony.CarrierConfigManager.KEY_SATELLITE_ROAMING_TURN_OFF_SESSION_FOR_EMERGENCY_CALL_BOOL; 36 import static android.telephony.CarrierConfigManager.SATELLITE_DATA_SUPPORT_ALL; 37 import static android.telephony.CarrierConfigManager.SATELLITE_DATA_SUPPORT_BANDWIDTH_CONSTRAINED; 38 import static android.telephony.NetworkRegistrationInfo.SERVICE_TYPE_DATA; 39 import static android.telephony.NetworkRegistrationInfo.SERVICE_TYPE_SMS; 40 import static android.telephony.NetworkRegistrationInfo.SERVICE_TYPE_VOICE; 41 import static android.telephony.SubscriptionManager.SATELLITE_ENTITLEMENT_STATUS; 42 import static android.telephony.satellite.NtnSignalStrength.NTN_SIGNAL_STRENGTH_GOOD; 43 import static android.telephony.satellite.NtnSignalStrength.NTN_SIGNAL_STRENGTH_GREAT; 44 import static android.telephony.satellite.NtnSignalStrength.NTN_SIGNAL_STRENGTH_NONE; 45 import static android.telephony.satellite.NtnSignalStrength.NTN_SIGNAL_STRENGTH_POOR; 46 import static android.telephony.satellite.SatelliteManager.KEY_DEMO_MODE_ENABLED; 47 import static android.telephony.satellite.SatelliteManager.KEY_DEPROVISION_SATELLITE_TOKENS; 48 import static android.telephony.satellite.SatelliteManager.KEY_EMERGENCY_MODE_ENABLED; 49 import static android.telephony.satellite.SatelliteManager.KEY_NTN_SIGNAL_STRENGTH; 50 import static android.telephony.satellite.SatelliteManager.KEY_PROVISION_SATELLITE_TOKENS; 51 import static android.telephony.satellite.SatelliteManager.KEY_REQUEST_PROVISION_SUBSCRIBER_ID_TOKEN; 52 import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_CAPABILITIES; 53 import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED; 54 import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_ENABLED; 55 import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_NEXT_VISIBILITY; 56 import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_PROVISIONED; 57 import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_SUPPORTED; 58 import static android.telephony.satellite.SatelliteManager.METADATA_SATELLITE_MANUAL_CONNECT_P2P_SUPPORT; 59 import static android.telephony.satellite.SatelliteManager.NT_RADIO_TECHNOLOGY_EMTC_NTN; 60 import static android.telephony.satellite.SatelliteManager.NT_RADIO_TECHNOLOGY_NB_IOT_NTN; 61 import static android.telephony.satellite.SatelliteManager.NT_RADIO_TECHNOLOGY_NR_NTN; 62 import static android.telephony.satellite.SatelliteManager.NT_RADIO_TECHNOLOGY_PROPRIETARY; 63 import static android.telephony.satellite.SatelliteManager.SATELLITE_COMMUNICATION_RESTRICTION_REASON_ENTITLEMENT; 64 import static android.telephony.satellite.SatelliteManager.SATELLITE_COMMUNICATION_RESTRICTION_REASON_GEOLOCATION; 65 import static android.telephony.satellite.SatelliteManager.SATELLITE_COMMUNICATION_RESTRICTION_REASON_USER; 66 import static android.telephony.satellite.SatelliteManager.SATELLITE_MODEM_STATE_CONNECTED; 67 import static android.telephony.satellite.SatelliteManager.SATELLITE_MODEM_STATE_NOT_CONNECTED; 68 import static android.telephony.satellite.SatelliteManager.SATELLITE_MODEM_STATE_OFF; 69 import static android.telephony.satellite.SatelliteManager.SATELLITE_MODEM_STATE_UNAVAILABLE; 70 import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_DISABLE_IN_PROGRESS; 71 import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_EMERGENCY_CALL_IN_PROGRESS; 72 import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_ERROR; 73 import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_INVALID_ARGUMENTS; 74 import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_INVALID_MODEM_STATE; 75 import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_INVALID_TELEPHONY_STATE; 76 import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_MODEM_ERROR; 77 import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_MODEM_TIMEOUT; 78 import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_NOT_SUPPORTED; 79 import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_NO_RESOURCES; 80 import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_RADIO_NOT_AVAILABLE; 81 import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_REQUEST_ABORTED; 82 import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_REQUEST_IN_PROGRESS; 83 import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_REQUEST_NOT_SUPPORTED; 84 import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SERVICE_NOT_PROVISIONED; 85 import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SERVICE_PROVISION_IN_PROGRESS; 86 import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS; 87 88 import static com.android.internal.telephony.satellite.SatelliteController.DEFAULT_CARRIER_EMERGENCY_CALL_WAIT_FOR_CONNECTION_TIMEOUT_MILLIS; 89 import static com.android.internal.telephony.satellite.SatelliteController.SATELLITE_DATA_PLAN_METERED; 90 import static com.android.internal.telephony.satellite.SatelliteController.SATELLITE_DATA_PLAN_UNMETERED; 91 import static com.android.internal.telephony.satellite.SatelliteController.SATELLITE_MODE_ENABLED_FALSE; 92 import static com.android.internal.telephony.satellite.SatelliteController.SATELLITE_MODE_ENABLED_TRUE; 93 94 import static org.junit.Assert.assertArrayEquals; 95 import static org.junit.Assert.assertEquals; 96 import static org.junit.Assert.assertFalse; 97 import static org.junit.Assert.assertNotEquals; 98 import static org.junit.Assert.assertNotNull; 99 import static org.junit.Assert.assertNull; 100 import static org.junit.Assert.assertThrows; 101 import static org.junit.Assert.assertTrue; 102 import static org.junit.Assert.fail; 103 import static org.mockito.ArgumentMatchers.any; 104 import static org.mockito.ArgumentMatchers.anyBoolean; 105 import static org.mockito.ArgumentMatchers.anyInt; 106 import static org.mockito.ArgumentMatchers.anyList; 107 import static org.mockito.ArgumentMatchers.anyLong; 108 import static org.mockito.ArgumentMatchers.anyString; 109 import static org.mockito.ArgumentMatchers.anyVararg; 110 import static org.mockito.ArgumentMatchers.eq; 111 import static org.mockito.Mockito.atLeastOnce; 112 import static org.mockito.Mockito.clearInvocations; 113 import static org.mockito.Mockito.doAnswer; 114 import static org.mockito.Mockito.doNothing; 115 import static org.mockito.Mockito.doReturn; 116 import static org.mockito.Mockito.mock; 117 import static org.mockito.Mockito.never; 118 import static org.mockito.Mockito.reset; 119 import static org.mockito.Mockito.times; 120 import static org.mockito.Mockito.verify; 121 import static org.mockito.Mockito.verifyZeroInteractions; 122 import static org.mockito.Mockito.when; 123 124 import android.annotation.NonNull; 125 import android.annotation.Nullable; 126 import android.app.NotificationManager; 127 import android.content.BroadcastReceiver; 128 import android.content.Context; 129 import android.content.Intent; 130 import android.content.IntentFilter; 131 import android.content.SharedPreferences; 132 import android.content.pm.ApplicationInfo; 133 import android.content.pm.PackageManager; 134 import android.content.res.Resources; 135 import android.hardware.devicestate.DeviceState; 136 import android.net.Uri; 137 import android.os.AsyncResult; 138 import android.os.Bundle; 139 import android.os.CancellationSignal; 140 import android.os.Handler; 141 import android.os.ICancellationSignal; 142 import android.os.Looper; 143 import android.os.Message; 144 import android.os.OutcomeReceiver; 145 import android.os.PersistableBundle; 146 import android.os.RemoteException; 147 import android.os.ResultReceiver; 148 import android.platform.test.annotations.RequiresFlagsDisabled; 149 import android.platform.test.annotations.RequiresFlagsEnabled; 150 import android.platform.test.flag.junit.CheckFlagsRule; 151 import android.platform.test.flag.junit.DeviceFlagsValueProvider; 152 import android.telephony.AccessNetworkConstants; 153 import android.telephony.CarrierConfigManager; 154 import android.telephony.CellSignalStrength; 155 import android.telephony.NetworkRegistrationInfo; 156 import android.telephony.Rlog; 157 import android.telephony.ServiceState; 158 import android.telephony.SignalStrength; 159 import android.telephony.SubscriptionInfo; 160 import android.telephony.SubscriptionManager; 161 import android.telephony.satellite.EarfcnRange; 162 import android.telephony.satellite.INtnSignalStrengthCallback; 163 import android.telephony.satellite.ISatelliteCapabilitiesCallback; 164 import android.telephony.satellite.ISatelliteDatagramCallback; 165 import android.telephony.satellite.ISatelliteModemStateCallback; 166 import android.telephony.satellite.ISatelliteProvisionStateCallback; 167 import android.telephony.satellite.ISatelliteSupportedStateCallback; 168 import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; 169 import android.telephony.satellite.ISelectedNbIotSatelliteSubscriptionCallback; 170 import android.telephony.satellite.NtnSignalStrength; 171 import android.telephony.satellite.SatelliteCapabilities; 172 import android.telephony.satellite.SatelliteDatagram; 173 import android.telephony.satellite.SatelliteInfo; 174 import android.telephony.satellite.SatelliteManager; 175 import android.telephony.satellite.SatelliteManager.SatelliteException; 176 import android.telephony.satellite.SatelliteModemEnableRequestAttributes; 177 import android.telephony.satellite.SatellitePosition; 178 import android.telephony.satellite.SatelliteSubscriberInfo; 179 import android.telephony.satellite.SatelliteSubscriberProvisionStatus; 180 import android.telephony.satellite.SatelliteSubscriptionInfo; 181 import android.telephony.satellite.SystemSelectionSpecifier; 182 import android.testing.AndroidTestingRunner; 183 import android.testing.TestableLooper; 184 import android.util.IntArray; 185 import android.util.Pair; 186 import android.util.SparseArray; 187 import android.util.SparseBooleanArray; 188 189 import com.android.internal.R; 190 import com.android.internal.telephony.IIntegerConsumer; 191 import com.android.internal.telephony.IVoidConsumer; 192 import com.android.internal.telephony.Phone; 193 import com.android.internal.telephony.PhoneFactory; 194 import com.android.internal.telephony.TelephonyTest; 195 import com.android.internal.telephony.configupdate.ConfigProviderAdaptor; 196 import com.android.internal.telephony.configupdate.TelephonyConfigUpdateInstallReceiver; 197 import com.android.internal.telephony.flags.FeatureFlags; 198 import com.android.internal.telephony.satellite.metrics.ControllerMetricsStats; 199 import com.android.internal.telephony.satellite.metrics.ProvisionMetricsStats; 200 import com.android.internal.telephony.satellite.metrics.SessionMetricsStats; 201 import com.android.internal.telephony.subscription.SubscriptionInfoInternal; 202 import com.android.internal.telephony.subscription.SubscriptionManagerService; 203 204 import org.junit.After; 205 import org.junit.Before; 206 import org.junit.Rule; 207 import org.junit.Test; 208 import org.junit.runner.RunWith; 209 import org.mockito.ArgumentCaptor; 210 import org.mockito.Mock; 211 import org.mockito.MockitoAnnotations; 212 213 import java.lang.reflect.Field; 214 import java.util.ArrayList; 215 import java.util.Arrays; 216 import java.util.HashMap; 217 import java.util.HashSet; 218 import java.util.List; 219 import java.util.Map; 220 import java.util.Optional; 221 import java.util.Set; 222 import java.util.UUID; 223 import java.util.concurrent.CountDownLatch; 224 import java.util.concurrent.Executor; 225 import java.util.concurrent.Semaphore; 226 import java.util.concurrent.TimeUnit; 227 import java.util.stream.Collectors; 228 229 @RunWith(AndroidTestingRunner.class) 230 @TestableLooper.RunWithLooper 231 public class SatelliteControllerTest extends TelephonyTest { 232 private static final String TAG = "SatelliteControllerTest"; 233 234 private static final long TIMEOUT = 500; 235 private static final int SUB_ID = 0; 236 private static final int SUB_ID1 = 1; 237 private static final int MAX_BYTES_PER_OUT_GOING_DATAGRAM = 339; 238 private static final String TEST_SATELLITE_TOKEN = "TEST_SATELLITE_TOKEN"; 239 private static final String TEST_NEXT_SATELLITE_TOKEN = "TEST_NEXT_SATELLITE_TOKEN"; 240 private static final String[] EMPTY_STRING_ARRAY = {}; 241 private static final List<String> EMPTY_STRING_LIST = new ArrayList<>(); 242 private static final String SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY = 243 "satellite_system_notification_done_key"; 244 private static final int[] ACTIVE_SUB_IDS = {SUB_ID}; 245 private static final int TEST_WAIT_FOR_SATELLITE_ENABLING_RESPONSE_TIMEOUT_MILLIS = 246 (int) TimeUnit.SECONDS.toMillis(60); 247 private static final int TEST_WAIT_FOR_CELLULAR_MODEM_OFF_TIMEOUT_MILLIS = 248 (int) TimeUnit.SECONDS.toMillis(60); 249 250 251 private static final String SATELLITE_PLMN = "00103"; 252 private List<Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener>> 253 mCarrierConfigChangedListenerList = new ArrayList<>(); 254 255 private TestSatelliteController mSatelliteControllerUT; 256 private TestSharedPreferences mSharedPreferences; 257 private PersistableBundle mCarrierConfigBundle; 258 private ServiceState mServiceState2; 259 260 private SubscriptionInfo testSubscriptionInfo; 261 private SubscriptionInfo testSubscriptionInfo2; 262 263 @Mock private SatelliteController mMockSatelliteController; 264 @Mock private DatagramController mMockDatagramController; 265 @Mock private SatelliteModemInterface mMockSatelliteModemInterface; 266 @Mock private SatelliteSessionController mMockSatelliteSessionController; 267 @Mock private PointingAppController mMockPointingAppController; 268 @Mock private ControllerMetricsStats mMockControllerMetricsStats; 269 @Mock private ProvisionMetricsStats mMockProvisionMetricsStats; 270 @Mock private SessionMetricsStats mMockSessionMetricsStats; 271 @Mock private SubscriptionManagerService mMockSubscriptionManagerService; 272 @Mock private NotificationManager mMockNotificationManager; 273 private List<Integer> mIIntegerConsumerResults = new ArrayList<>(); 274 @Mock private ISatelliteTransmissionUpdateCallback mStartTransmissionUpdateCallback; 275 @Mock private ISatelliteTransmissionUpdateCallback mStopTransmissionUpdateCallback; 276 @Mock private FeatureFlags mFeatureFlags; 277 @Mock private TelephonyConfigUpdateInstallReceiver mMockTelephonyConfigUpdateInstallReceiver; 278 @Mock private SatelliteConfigParser mMockConfigParser; 279 @Mock private CellSignalStrength mCellSignalStrength; 280 @Mock private SatelliteConfig mMockConfig; 281 @Mock private DemoSimulator mMockDemoSimulator; 282 @Mock private Resources mResources; 283 @Mock private SubscriptionManager mSubscriptionManager; 284 @Mock private SubscriptionInfo mSubscriptionInfo; 285 @Mock private PackageManager mMockPManager; 286 287 private Semaphore mIIntegerConsumerSemaphore = new Semaphore(0); 288 private IIntegerConsumer mIIntegerConsumer = new IIntegerConsumer.Stub() { 289 @Override 290 public void accept(int result) { 291 logd("mIIntegerConsumer: result=" + result); 292 mIIntegerConsumerResults.add(result); 293 try { 294 mIIntegerConsumerSemaphore.release(); 295 } catch (Exception ex) { 296 loge("mIIntegerConsumer: Got exception in releasing semaphore, ex=" + ex); 297 } 298 } 299 }; 300 301 private boolean mIsSatelliteServiceSupported = true; 302 private boolean mIsPointingRequired = true; 303 private Set<Integer> mSupportedRadioTechnologies = new HashSet<>(Arrays.asList( 304 NT_RADIO_TECHNOLOGY_NR_NTN, 305 NT_RADIO_TECHNOLOGY_EMTC_NTN, 306 NT_RADIO_TECHNOLOGY_NB_IOT_NTN, 307 NT_RADIO_TECHNOLOGY_PROPRIETARY)); 308 private SatelliteCapabilities mSatelliteCapabilities = new SatelliteCapabilities( 309 mSupportedRadioTechnologies, mIsPointingRequired, MAX_BYTES_PER_OUT_GOING_DATAGRAM, 310 new HashMap<>()); 311 private SatelliteCapabilities mEmptySatelliteCapabilities = new SatelliteCapabilities( 312 new HashSet<>(), mIsPointingRequired, MAX_BYTES_PER_OUT_GOING_DATAGRAM, 313 new HashMap<>()); 314 final int mCarrierId = 0; 315 final String mImsi = "1234567890123"; 316 final String mNiddApn = "testApn"; 317 final String mMsisdn = "0987654321"; 318 final String mSubscriberId = mImsi.substring(0, 6) + mMsisdn; 319 final String mIccId = "1000000000000001"; 320 final String mIccId2 = "2000000000000002"; 321 final String mImsi2 = "2345678901234"; 322 final String mMsisdn2 = "9876543210"; 323 final String mSubscriberId2 = mIccId2; 324 325 private Semaphore mSatelliteCapabilitiesSemaphore = new Semaphore(0); 326 private SatelliteCapabilities mQueriedSatelliteCapabilities = null; 327 private int mQueriedSatelliteCapabilitiesResultCode = SATELLITE_RESULT_SUCCESS; 328 private ResultReceiver mSatelliteCapabilitiesReceiver = new ResultReceiver(null) { 329 @Override 330 protected void onReceiveResult(int resultCode, Bundle resultData) { 331 mQueriedSatelliteCapabilitiesResultCode = resultCode; 332 logd("mSatelliteCapabilitiesReceiver: resultCode=" + resultCode); 333 if (resultCode == SATELLITE_RESULT_SUCCESS) { 334 if (resultData.containsKey(KEY_SATELLITE_CAPABILITIES)) { 335 mQueriedSatelliteCapabilities = resultData.getParcelable( 336 KEY_SATELLITE_CAPABILITIES, SatelliteCapabilities.class); 337 } else { 338 loge("KEY_SATELLITE_SUPPORTED does not exist."); 339 mQueriedSatelliteCapabilities = null; 340 } 341 } else { 342 mQueriedSatelliteCapabilities = null; 343 } 344 try { 345 mSatelliteCapabilitiesSemaphore.release(); 346 } catch (Exception ex) { 347 loge("mSatelliteCapabilitiesReceiver: Got exception in releasing semaphore, ex=" 348 + ex); 349 } 350 } 351 }; 352 353 private boolean mQueriedSatelliteSupported = false; 354 private int mQueriedSatelliteSupportedResultCode = SATELLITE_RESULT_SUCCESS; 355 private Semaphore mSatelliteSupportSemaphore = new Semaphore(0); 356 private ResultReceiver mSatelliteSupportReceiver = new ResultReceiver(null) { 357 @Override 358 protected void onReceiveResult(int resultCode, Bundle resultData) { 359 mQueriedSatelliteSupportedResultCode = resultCode; 360 logd("mSatelliteSupportReceiver: resultCode=" + resultCode); 361 if (resultCode == SATELLITE_RESULT_SUCCESS) { 362 if (resultData.containsKey(KEY_SATELLITE_SUPPORTED)) { 363 mQueriedSatelliteSupported = resultData.getBoolean(KEY_SATELLITE_SUPPORTED); 364 } else { 365 loge("KEY_SATELLITE_SUPPORTED does not exist."); 366 mQueriedSatelliteSupported = false; 367 } 368 } else { 369 mQueriedSatelliteSupported = false; 370 } 371 try { 372 mSatelliteSupportSemaphore.release(); 373 } catch (Exception ex) { 374 loge("mSatelliteSupportReceiver: Got exception in releasing semaphore, ex=" + ex); 375 } 376 } 377 }; 378 379 private boolean mQueriedIsSatelliteEnabled = false; 380 private int mQueriedIsSatelliteEnabledResultCode = SATELLITE_RESULT_SUCCESS; 381 private Semaphore mIsSatelliteEnabledSemaphore = new Semaphore(0); 382 private ResultReceiver mIsSatelliteEnabledReceiver = new ResultReceiver(null) { 383 @Override 384 protected void onReceiveResult(int resultCode, Bundle resultData) { 385 logd("mIsSatelliteEnabledReceiver: resultCode=" + resultCode); 386 mQueriedIsSatelliteEnabledResultCode = resultCode; 387 if (resultCode == SATELLITE_RESULT_SUCCESS) { 388 if (resultData.containsKey(KEY_SATELLITE_ENABLED)) { 389 mQueriedIsSatelliteEnabled = resultData.getBoolean(KEY_SATELLITE_ENABLED); 390 } else { 391 loge("KEY_SATELLITE_ENABLED does not exist."); 392 mQueriedIsSatelliteEnabled = false; 393 } 394 } else { 395 mQueriedIsSatelliteEnabled = false; 396 } 397 try { 398 mIsSatelliteEnabledSemaphore.release(); 399 } catch (Exception ex) { 400 loge("mIsSatelliteEnabledReceiver: Got exception in releasing semaphore, ex=" + ex); 401 } 402 } 403 }; 404 405 private boolean mQueriedIsDemoModeEnabled = false; 406 private int mQueriedIsDemoModeEnabledResultCode = SATELLITE_RESULT_SUCCESS; 407 private Semaphore mIsDemoModeEnabledSemaphore = new Semaphore(0); 408 private ResultReceiver mIsDemoModeEnabledReceiver = new ResultReceiver(null) { 409 @Override 410 protected void onReceiveResult(int resultCode, Bundle resultData) { 411 mQueriedIsDemoModeEnabledResultCode = resultCode; 412 logd("mIsDemoModeEnabledReceiver: resultCode=" + resultCode); 413 if (resultCode == SATELLITE_RESULT_SUCCESS) { 414 if (resultData.containsKey(KEY_DEMO_MODE_ENABLED)) { 415 mQueriedIsDemoModeEnabled = resultData.getBoolean(KEY_DEMO_MODE_ENABLED); 416 } else { 417 loge("KEY_DEMO_MODE_ENABLED does not exist."); 418 mQueriedIsDemoModeEnabled = false; 419 } 420 } else { 421 mQueriedIsDemoModeEnabled = false; 422 } 423 try { 424 mIsDemoModeEnabledSemaphore.release(); 425 } catch (Exception ex) { 426 loge("mIsDemoModeEnabledReceiver: Got exception in releasing semaphore, ex=" + ex); 427 } 428 } 429 }; 430 431 private boolean mQueriedIsSatelliteProvisioned = false; 432 private int mQueriedIsSatelliteProvisionedResultCode = SATELLITE_RESULT_SUCCESS; 433 private Semaphore mIsSatelliteProvisionedSemaphore = new Semaphore(0); 434 private ResultReceiver mIsSatelliteProvisionedReceiver = new ResultReceiver(null) { 435 @Override 436 protected void onReceiveResult(int resultCode, Bundle resultData) { 437 mQueriedIsSatelliteProvisionedResultCode = resultCode; 438 logd("mIsSatelliteProvisionedReceiver: resultCode=" + resultCode); 439 if (resultCode == SATELLITE_RESULT_SUCCESS) { 440 if (resultData.containsKey(KEY_SATELLITE_PROVISIONED)) { 441 mQueriedIsSatelliteProvisioned = 442 resultData.getBoolean(KEY_SATELLITE_PROVISIONED); 443 } else { 444 loge("KEY_SATELLITE_PROVISIONED does not exist."); 445 mQueriedIsSatelliteProvisioned = false; 446 } 447 } else { 448 mQueriedIsSatelliteProvisioned = false; 449 } 450 try { 451 mIsSatelliteProvisionedSemaphore.release(); 452 } catch (Exception ex) { 453 loge("mIsSatelliteProvisionedReceiver: Got exception in releasing semaphore ex=" 454 + ex); 455 } 456 } 457 }; 458 459 private boolean mQueriedSatelliteAllowed = false; 460 private int mQueriedSatelliteAllowedResultCode = SATELLITE_RESULT_SUCCESS; 461 private Semaphore mSatelliteAllowedSemaphore = new Semaphore(0); 462 private ResultReceiver mSatelliteAllowedReceiver = new ResultReceiver(null) { 463 @Override 464 protected void onReceiveResult(int resultCode, Bundle resultData) { 465 mQueriedSatelliteAllowedResultCode = resultCode; 466 logd("mSatelliteAllowedReceiver: resultCode=" + resultCode); 467 if (resultCode == SATELLITE_RESULT_SUCCESS) { 468 if (resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) { 469 mQueriedSatelliteAllowed = resultData.getBoolean( 470 KEY_SATELLITE_COMMUNICATION_ALLOWED); 471 } else { 472 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist."); 473 mQueriedSatelliteAllowed = false; 474 } 475 } else { 476 mQueriedSatelliteAllowed = false; 477 } 478 try { 479 mSatelliteAllowedSemaphore.release(); 480 } catch (Exception ex) { 481 loge("mSatelliteAllowedReceiver: Got exception in releasing semaphore, ex=" + ex); 482 } 483 } 484 }; 485 486 private int mQueriedSatelliteVisibilityTime = -1; 487 private int mSatelliteNextVisibilityTime = 3600; 488 private int mQueriedSatelliteVisibilityTimeResultCode = SATELLITE_RESULT_SUCCESS; 489 private Semaphore mSatelliteVisibilityTimeSemaphore = new Semaphore(0); 490 private ResultReceiver mSatelliteVisibilityTimeReceiver = new ResultReceiver(null) { 491 @Override 492 protected void onReceiveResult(int resultCode, Bundle resultData) { 493 mQueriedSatelliteVisibilityTimeResultCode = resultCode; 494 logd("mSatelliteVisibilityTimeReceiver: resultCode=" + resultCode); 495 if (resultCode == SATELLITE_RESULT_SUCCESS) { 496 if (resultData.containsKey(KEY_SATELLITE_NEXT_VISIBILITY)) { 497 mQueriedSatelliteVisibilityTime = resultData.getInt( 498 KEY_SATELLITE_NEXT_VISIBILITY); 499 } else { 500 loge("KEY_SATELLITE_NEXT_VISIBILITY does not exist."); 501 mQueriedSatelliteVisibilityTime = -1; 502 } 503 } else { 504 mQueriedSatelliteVisibilityTime = -1; 505 } 506 try { 507 mSatelliteVisibilityTimeSemaphore.release(); 508 } catch (Exception ex) { 509 loge("mSatelliteVisibilityTimeReceiver: Got exception in releasing semaphore, ex=" 510 + ex); 511 } 512 } 513 }; 514 515 private @NtnSignalStrength.NtnSignalStrengthLevel int mQueriedNtnSignalStrengthLevel = 516 NTN_SIGNAL_STRENGTH_NONE; 517 private int mQueriedNtnSignalStrengthResultCode = SATELLITE_RESULT_SUCCESS; 518 private Semaphore mRequestNtnSignalStrengthSemaphore = new Semaphore(0); 519 private ResultReceiver mRequestNtnSignalStrengthReceiver = new ResultReceiver(null) { 520 @Override 521 protected void onReceiveResult(int resultCode, Bundle resultData) { 522 mQueriedNtnSignalStrengthResultCode = resultCode; 523 logd("KEY_NTN_SIGNAL_STRENGTH: resultCode=" + resultCode); 524 if (resultCode == SATELLITE_RESULT_SUCCESS) { 525 if (resultData.containsKey(KEY_NTN_SIGNAL_STRENGTH)) { 526 NtnSignalStrength result = resultData.getParcelable(KEY_NTN_SIGNAL_STRENGTH); 527 logd("result.getLevel()=" + result.getLevel()); 528 mQueriedNtnSignalStrengthLevel = result.getLevel(); 529 } else { 530 loge("KEY_NTN_SIGNAL_STRENGTH does not exist."); 531 mQueriedNtnSignalStrengthLevel = NTN_SIGNAL_STRENGTH_NONE; 532 } 533 } else { 534 mQueriedNtnSignalStrengthLevel = NTN_SIGNAL_STRENGTH_NONE; 535 } 536 try { 537 mRequestNtnSignalStrengthSemaphore.release(); 538 } catch (Exception ex) { 539 loge("mRequestNtnSignalStrengthReceiver: Got exception in releasing semaphore, ex=" 540 + ex); 541 } 542 } 543 }; 544 545 private boolean mRequestIsEmergency = false; 546 private ResultReceiver mRequestIsEmergencyReceiver = new ResultReceiver(null) { 547 @Override 548 protected void onReceiveResult(int resultCode, Bundle resultData) { 549 logd("requestIsEmergencyReceiver: resultCode=" + resultCode); 550 if (resultCode == SATELLITE_RESULT_SUCCESS) { 551 if (resultData.containsKey(KEY_EMERGENCY_MODE_ENABLED)) { 552 mRequestIsEmergency = resultData.getBoolean( 553 KEY_EMERGENCY_MODE_ENABLED); 554 } else { 555 loge("KEY_EMERGENCY_MODE_ENABLED does not exist."); 556 557 } 558 } 559 } 560 }; 561 562 private int mQueriedSystemSelectionChannelUpdatedResultCode = SATELLITE_RESULT_SUCCESS; 563 private Semaphore mSystemSelectionChannelUpdatedSemaphore = new Semaphore(0); 564 private ResultReceiver mSystemSelectionChannelUpdatedReceiver = new ResultReceiver(null) { 565 @Override 566 protected void onReceiveResult(int resultCode, Bundle resultData) { 567 mQueriedSystemSelectionChannelUpdatedResultCode = resultCode; 568 try { 569 mSystemSelectionChannelUpdatedSemaphore.release(); 570 } catch (Exception ex) { 571 fail("mSystemSelectionChannelUpdatedReceiver: Got exception in releasing " 572 + "semaphore, ex=" 573 + ex); 574 } 575 } 576 }; 577 578 @Rule 579 public final CheckFlagsRule mCheckFlagsRule = 580 DeviceFlagsValueProvider.createCheckFlagsRule(); 581 582 @Before setUp()583 public void setUp() throws Exception { 584 super.setUp(getClass().getSimpleName()); 585 MockitoAnnotations.initMocks(this); 586 logd(TAG + " Setup!"); 587 588 replaceInstance(SatelliteController.class, "sInstance", null, 589 mMockSatelliteController); 590 replaceInstance(DatagramController.class, "sInstance", null, 591 mMockDatagramController); 592 replaceInstance(SatelliteModemInterface.class, "sInstance", null, 593 mMockSatelliteModemInterface); 594 replaceInstance(SatelliteSessionController.class, "sInstance", null, 595 mMockSatelliteSessionController); 596 replaceInstance(PointingAppController.class, "sInstance", null, 597 mMockPointingAppController); 598 replaceInstance(ControllerMetricsStats.class, "sInstance", null, 599 mMockControllerMetricsStats); 600 replaceInstance(ProvisionMetricsStats.class, "sInstance", null, 601 mMockProvisionMetricsStats); 602 replaceInstance(SessionMetricsStats.class, "sInstance", null, 603 mMockSessionMetricsStats); 604 replaceInstance(SubscriptionManagerService.class, "sInstance", null, 605 mMockSubscriptionManagerService); 606 replaceInstance(PhoneFactory.class, "sPhones", null, new Phone[]{mPhone, mPhone2}); 607 replaceInstance(TelephonyConfigUpdateInstallReceiver.class, "sReceiverAdaptorInstance", 608 null, mMockTelephonyConfigUpdateInstallReceiver); 609 replaceInstance(DemoSimulator.class, "sInstance", null, mMockDemoSimulator); 610 611 doNothing().when(mMockSatelliteController).moveSatelliteToOffStateAndCleanUpResources( 612 SATELLITE_RESULT_REQUEST_ABORTED); 613 mServiceState2 = mock(ServiceState.class); 614 when(mPhone.getServiceState()).thenReturn(mServiceState); 615 when(mPhone.getSubId()).thenReturn(SUB_ID); 616 when(mPhone.getPhoneId()).thenReturn(0); 617 when(mPhone.getSignalStrengthController()).thenReturn(mSignalStrengthController); 618 when(mPhone2.getServiceState()).thenReturn(mServiceState2); 619 when(mPhone2.getSubId()).thenReturn(SUB_ID1); 620 when(mPhone2.getPhoneId()).thenReturn(1); 621 when(mPhone2.getSignalStrengthController()).thenReturn(mSignalStrengthController); 622 623 mContextFixture.putStringArrayResource( 624 R.array.config_satellite_providers, 625 EMPTY_STRING_ARRAY); 626 mContextFixture.putIntResource( 627 R.integer.config_wait_for_satellite_enabling_response_timeout_millis, 628 TEST_WAIT_FOR_SATELLITE_ENABLING_RESPONSE_TIMEOUT_MILLIS); 629 mContextFixture.putIntResource( 630 R.integer.config_satellite_wait_for_cellular_modem_off_timeout_millis, 631 TEST_WAIT_FOR_CELLULAR_MODEM_OFF_TIMEOUT_MILLIS); 632 mContextFixture.putIntArrayResource( 633 R.array.config_foldedDeviceStates, 634 new int[0]); 635 doReturn(ACTIVE_SUB_IDS).when(mMockSubscriptionManagerService).getActiveSubIdList(true); 636 637 mCarrierConfigBundle = mContextFixture.getCarrierConfigBundle(); 638 doReturn(mCarrierConfigBundle) 639 .when(mCarrierConfigManager).getConfigForSubId(anyInt(), anyVararg()); 640 doAnswer(invocation -> { 641 Executor executor = invocation.getArgument(0); 642 CarrierConfigManager.CarrierConfigChangeListener listener = invocation.getArgument(1); 643 mCarrierConfigChangedListenerList.add(new Pair<>(executor, listener)); 644 return null; 645 }).when(mCarrierConfigManager).registerCarrierConfigChangeListener( 646 any(Executor.class), 647 any(CarrierConfigManager.CarrierConfigChangeListener.class)); 648 649 mSharedPreferences = new TestSharedPreferences(); 650 when(mContext.getSharedPreferences(anyString(), anyInt())).thenReturn(mSharedPreferences); 651 doReturn(mIsSatelliteServiceSupported) 652 .when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 653 setUpResponseForRequestSatelliteCapabilities( 654 mSatelliteCapabilities, SATELLITE_RESULT_SUCCESS); 655 setUpResponseForRequestIsSatelliteSupported(false, 656 SATELLITE_RESULT_RADIO_NOT_AVAILABLE); 657 doNothing().when(mMockDatagramController).setDemoMode(anyBoolean()); 658 doNothing().when(mMockSatelliteSessionController) 659 .onSatelliteEnabledStateChanged(anyBoolean()); 660 doNothing().when(mMockSatelliteSessionController).onSatelliteModemStateChanged(anyInt()); 661 doNothing().when(mMockSatelliteSessionController).setDemoMode(anyBoolean()); 662 doNothing().when(mMockSatelliteSessionController).cleanUpResource(); 663 doNothing().when(mMockControllerMetricsStats).onSatelliteEnabled(); 664 doNothing().when(mMockControllerMetricsStats).reportServiceEnablementSuccessCount(); 665 doNothing().when(mMockControllerMetricsStats).reportServiceEnablementFailCount(); 666 doReturn(mMockSessionMetricsStats) 667 .when(mMockSessionMetricsStats).setInitializationResult(anyInt()); 668 doReturn(mMockSessionMetricsStats) 669 .when(mMockSessionMetricsStats).setSatelliteTechnology(anyInt()); 670 doReturn(mMockSessionMetricsStats) 671 .when(mMockSessionMetricsStats).setTerminationResult(anyInt()); 672 doReturn(mMockSessionMetricsStats) 673 .when(mMockSessionMetricsStats).setInitializationProcessingTime(anyLong()); 674 doReturn(mMockSessionMetricsStats) 675 .when(mMockSessionMetricsStats).setTerminationProcessingTime(anyLong()); 676 doReturn(mMockSessionMetricsStats) 677 .when(mMockSessionMetricsStats).setSessionDurationSec(anyInt()); 678 doReturn(mMockSessionMetricsStats) 679 .when(mMockSessionMetricsStats).setIsDemoMode(anyBoolean()); 680 doReturn(mMockSessionMetricsStats) 681 .when(mMockSessionMetricsStats).setCarrierId(anyInt()); 682 doReturn(mMockSessionMetricsStats) 683 .when(mMockSessionMetricsStats).setIsNtnOnlyCarrier(anyBoolean()); 684 doNothing().when(mMockSessionMetricsStats).reportSessionMetrics(); 685 686 doReturn(mMockProvisionMetricsStats).when(mMockProvisionMetricsStats) 687 .setResultCode(anyInt()); 688 doReturn(mMockProvisionMetricsStats).when(mMockProvisionMetricsStats) 689 .setIsProvisionRequest(anyBoolean()); 690 doReturn(mMockProvisionMetricsStats).when(mMockProvisionMetricsStats) 691 .setCarrierId(anyInt()); 692 doReturn(mMockProvisionMetricsStats).when(mMockProvisionMetricsStats) 693 .setIsNtnOnlyCarrier(anyBoolean()); 694 doNothing().when(mMockProvisionMetricsStats).reportProvisionMetrics(); 695 doNothing().when(mMockControllerMetricsStats).reportDeprovisionCount(anyInt()); 696 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(true); 697 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 698 doReturn(mSST).when(mPhone).getServiceStateTracker(); 699 doReturn(mSST).when(mPhone2).getServiceStateTracker(); 700 doReturn(mServiceState).when(mSST).getServiceState(); 701 doReturn(Context.NOTIFICATION_SERVICE).when(mContext).getSystemServiceName( 702 NotificationManager.class); 703 doReturn(mMockNotificationManager).when(mContext).getSystemService( 704 Context.NOTIFICATION_SERVICE); 705 mSatelliteControllerUT = 706 new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); 707 verify(mMockSatelliteModemInterface).registerForPendingDatagrams( 708 any(Handler.class), 709 eq(27) /* EVENT_PENDING_DATAGRAMS */, 710 eq(null)); 711 verify(mMockSatelliteModemInterface).registerForSatelliteModemStateChanged( 712 any(Handler.class), 713 eq(28) /* EVENT_SATELLITE_MODEM_STATE_CHANGED */, 714 eq(null)); 715 716 doReturn(mMockConfigParser).when(mMockTelephonyConfigUpdateInstallReceiver) 717 .getConfigParser(ConfigProviderAdaptor.DOMAIN_SATELLITE); 718 doReturn(mSubscriptionInfo).when(mMockSubscriptionManagerService).getSubscriptionInfo( 719 anyInt()); 720 doReturn("").when(mSubscriptionInfo).getIccId(); 721 } 722 723 @After tearDown()724 public void tearDown() throws Exception { 725 logd(TAG + " tearDown"); 726 mSatelliteControllerUT = null; 727 super.tearDown(); 728 } 729 730 @Test testShouldTurnOffCarrierSatelliteForEmergencyCall()731 public void testShouldTurnOffCarrierSatelliteForEmergencyCall() throws Exception { 732 DatagramController datagramController = mock(DatagramController.class); 733 replaceInstance(SatelliteController.class, "mDatagramController", 734 mSatelliteControllerUT, datagramController); 735 736 // Verify should turn off satellite 737 mCarrierConfigBundle.putBoolean( 738 KEY_SATELLITE_ROAMING_TURN_OFF_SESSION_FOR_EMERGENCY_CALL_BOOL, true); 739 doReturn(false).when(datagramController).isEmergencyCommunicationEstablished(); 740 invokeCarrierConfigChanged(); 741 mSatelliteControllerUT.setSatellitePhone(1); 742 processAllMessages(); 743 744 assertTrue(mSatelliteControllerUT.shouldTurnOffCarrierSatelliteForEmergencyCall()); 745 746 // Verify should NOT turn off satellite 747 mCarrierConfigBundle.putBoolean( 748 KEY_SATELLITE_ROAMING_TURN_OFF_SESSION_FOR_EMERGENCY_CALL_BOOL, false); 749 doReturn(true).when(datagramController).isEmergencyCommunicationEstablished(); 750 invokeCarrierConfigChanged(); 751 mSatelliteControllerUT.setSatellitePhone(1); 752 processAllMessages(); 753 754 assertFalse(mSatelliteControllerUT.shouldTurnOffCarrierSatelliteForEmergencyCall()); 755 } 756 757 @Test testRequestTimeForNextSatelliteVisibility()758 public void testRequestTimeForNextSatelliteVisibility() { 759 mSatelliteVisibilityTimeSemaphore.drainPermits(); 760 setUpResponseForRequestIsSatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 761 verifySatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 762 mSatelliteControllerUT.requestTimeForNextSatelliteVisibility( 763 mSatelliteVisibilityTimeReceiver); 764 processAllMessages(); 765 assertTrue(waitForRequestTimeForNextSatelliteVisibilityResult(1)); 766 assertEquals(SATELLITE_RESULT_NOT_SUPPORTED, mQueriedSatelliteVisibilityTimeResultCode); 767 768 resetSatelliteControllerUT(); 769 mSatelliteControllerUT.requestTimeForNextSatelliteVisibility( 770 mSatelliteVisibilityTimeReceiver); 771 processAllMessages(); 772 assertTrue(waitForRequestTimeForNextSatelliteVisibilityResult(1)); 773 assertEquals(SATELLITE_RESULT_INVALID_TELEPHONY_STATE, 774 mQueriedSatelliteVisibilityTimeResultCode); 775 776 resetSatelliteControllerUT(); 777 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 778 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 779 setUpResponseForRequestTimeForNextSatelliteVisibility(mSatelliteNextVisibilityTime, 780 SATELLITE_RESULT_SUCCESS); 781 mSatelliteControllerUT.requestTimeForNextSatelliteVisibility( 782 mSatelliteVisibilityTimeReceiver); 783 processAllMessages(); 784 assertTrue(waitForRequestTimeForNextSatelliteVisibilityResult(1)); 785 assertEquals(SATELLITE_RESULT_SERVICE_NOT_PROVISIONED, 786 mQueriedSatelliteVisibilityTimeResultCode); 787 788 resetSatelliteControllerUT(); 789 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 790 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 791 setUpResponseForRequestIsSatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 792 verifySatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 793 setUpResponseForRequestTimeForNextSatelliteVisibility(mSatelliteNextVisibilityTime, 794 SATELLITE_RESULT_SUCCESS); 795 mSatelliteControllerUT.requestTimeForNextSatelliteVisibility( 796 mSatelliteVisibilityTimeReceiver); 797 processAllMessages(); 798 assertTrue(waitForRequestTimeForNextSatelliteVisibilityResult(1)); 799 assertEquals(SATELLITE_RESULT_SERVICE_NOT_PROVISIONED, 800 mQueriedSatelliteVisibilityTimeResultCode); 801 802 resetSatelliteControllerUT(); 803 provisionSatelliteService(); 804 setUpResponseForRequestTimeForNextSatelliteVisibility(mSatelliteNextVisibilityTime, 805 SATELLITE_RESULT_SUCCESS); 806 mSatelliteControllerUT.requestTimeForNextSatelliteVisibility( 807 mSatelliteVisibilityTimeReceiver); 808 processAllMessages(); 809 assertTrue(waitForRequestTimeForNextSatelliteVisibilityResult(1)); 810 assertEquals(SATELLITE_RESULT_SUCCESS, mQueriedSatelliteVisibilityTimeResultCode); 811 assertEquals(mSatelliteNextVisibilityTime, mQueriedSatelliteVisibilityTime); 812 813 resetSatelliteControllerUT(); 814 provisionSatelliteService(); 815 setUpNullResponseForRequestTimeForNextSatelliteVisibility( 816 SATELLITE_RESULT_SUCCESS); 817 mSatelliteControllerUT.requestTimeForNextSatelliteVisibility( 818 mSatelliteVisibilityTimeReceiver); 819 processAllMessages(); 820 assertTrue(waitForRequestTimeForNextSatelliteVisibilityResult(1)); 821 assertEquals(SATELLITE_RESULT_INVALID_TELEPHONY_STATE, 822 mQueriedSatelliteVisibilityTimeResultCode); 823 824 resetSatelliteControllerUT(); 825 provisionSatelliteService(); 826 setUpNullResponseForRequestTimeForNextSatelliteVisibility( 827 SATELLITE_RESULT_INVALID_MODEM_STATE); 828 mSatelliteControllerUT.requestTimeForNextSatelliteVisibility( 829 mSatelliteVisibilityTimeReceiver); 830 processAllMessages(); 831 assertTrue(waitForRequestTimeForNextSatelliteVisibilityResult(1)); 832 assertEquals(SATELLITE_RESULT_INVALID_MODEM_STATE, 833 mQueriedSatelliteVisibilityTimeResultCode); 834 } 835 836 @Test testRadioStateChanged()837 public void testRadioStateChanged() { 838 mIsSatelliteEnabledSemaphore.drainPermits(); 839 840 when(mMockSatelliteModemInterface.isSatelliteServiceConnected()).thenReturn(false); 841 setRadioPower(false); 842 processAllMessages(); 843 verify(mMockSatelliteModemInterface, never()) 844 .requestIsSatelliteSupported(any(Message.class)); 845 846 setRadioPower(true); 847 processAllMessages(); 848 verify(mMockSatelliteModemInterface, never()) 849 .requestIsSatelliteSupported(any(Message.class)); 850 851 when(mMockSatelliteModemInterface.isSatelliteServiceConnected()).thenReturn(true); 852 setRadioPower(false); 853 processAllMessages(); 854 verify(mMockSatelliteModemInterface, times(1)) 855 .requestIsSatelliteSupported(any(Message.class)); 856 857 setRadioPower(true); 858 processAllMessages(); 859 verify(mMockSatelliteModemInterface, times(2)) 860 .requestIsSatelliteSupported(any(Message.class)); 861 862 setUpResponseForRequestIsSatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 863 setRadioPower(false); 864 processAllMessages(); 865 verify(mMockSatelliteModemInterface, times(3)) 866 .requestIsSatelliteSupported(any(Message.class)); 867 868 setRadioPower(true); 869 processAllMessages(); 870 verify(mMockSatelliteModemInterface, times(4)) 871 .requestIsSatelliteSupported(any(Message.class)); 872 873 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 874 setRadioPower(false); 875 processAllMessages(); 876 verify(mMockSatelliteModemInterface, times(5)) 877 .requestIsSatelliteSupported(any(Message.class)); 878 879 setRadioPower(true); 880 processAllMessages(); 881 verify(mMockSatelliteModemInterface, times(5)) 882 .requestIsSatelliteSupported(any(Message.class)); 883 assertTrue(mSatelliteControllerUT.isRadioOn()); 884 assertFalse(mSatelliteControllerUT.isRadioOffRequested()); 885 assertFalse(mSatelliteControllerUT.isWaitForCellularModemOffTimerStarted()); 886 887 // Radio is off during TN -> NTN image switch, SatelliteController should not set radio 888 // state to OFF 889 setRadioPower(false); 890 processAllMessages(); 891 assertTrue(mSatelliteControllerUT.isRadioOn()); 892 assertFalse(mSatelliteControllerUT.isRadioOffRequested()); 893 assertFalse(mSatelliteControllerUT.isWaitForCellularModemOffTimerStarted()); 894 895 // Turn on radio 896 setRadioPower(true); 897 processAllMessages(); 898 assertTrue(mSatelliteControllerUT.isRadioOn()); 899 assertFalse(mSatelliteControllerUT.isRadioOffRequested()); 900 assertFalse(mSatelliteControllerUT.isWaitForCellularModemOffTimerStarted()); 901 902 // APM is triggered 903 mSatelliteControllerUT.onSetCellularRadioPowerStateRequested(false); 904 processAllMessages(); 905 assertTrue(mSatelliteControllerUT.isRadioOn()); 906 assertTrue(mSatelliteControllerUT.isRadioOffRequested()); 907 assertTrue(mSatelliteControllerUT.isWaitForCellularModemOffTimerStarted()); 908 909 // SatelliteController should set the radio state to OFF 910 setRadioPower(false); 911 processAllMessages(); 912 assertFalse(mSatelliteControllerUT.isRadioOn()); 913 assertFalse(mSatelliteControllerUT.isRadioOffRequested()); 914 assertFalse(mSatelliteControllerUT.isWaitForCellularModemOffTimerStarted()); 915 916 // Turn on radio 917 setRadioPower(true); 918 processAllMessages(); 919 assertTrue(mSatelliteControllerUT.isRadioOn()); 920 assertFalse(mSatelliteControllerUT.isRadioOffRequested()); 921 assertFalse(mSatelliteControllerUT.isWaitForCellularModemOffTimerStarted()); 922 923 // APM is triggered 924 mSatelliteControllerUT.onSetCellularRadioPowerStateRequested(false); 925 processAllMessages(); 926 assertTrue(mSatelliteControllerUT.isRadioOn()); 927 assertTrue(mSatelliteControllerUT.isRadioOffRequested()); 928 assertTrue(mSatelliteControllerUT.isWaitForCellularModemOffTimerStarted()); 929 930 // Modem fails to power off radio. APM is disabled 931 mSatelliteControllerUT.onSetCellularRadioPowerStateRequested(true); 932 processAllMessages(); 933 assertTrue(mSatelliteControllerUT.isRadioOn()); 934 assertFalse(mSatelliteControllerUT.isRadioOffRequested()); 935 assertFalse(mSatelliteControllerUT.isWaitForCellularModemOffTimerStarted()); 936 937 // APM is triggered 938 mSatelliteControllerUT.onSetCellularRadioPowerStateRequested(false); 939 processAllMessages(); 940 assertTrue(mSatelliteControllerUT.isRadioOn()); 941 assertTrue(mSatelliteControllerUT.isRadioOffRequested()); 942 assertTrue(mSatelliteControllerUT.isWaitForCellularModemOffTimerStarted()); 943 944 // The timer WaitForCellularModemOff time out 945 moveTimeForward(TEST_WAIT_FOR_CELLULAR_MODEM_OFF_TIMEOUT_MILLIS); 946 processAllMessages(); 947 assertTrue(mSatelliteControllerUT.isRadioOn()); 948 assertFalse(mSatelliteControllerUT.isRadioOffRequested()); 949 assertFalse(mSatelliteControllerUT.isWaitForCellularModemOffTimerStarted()); 950 951 // APM is triggered 952 mSatelliteControllerUT.onSetCellularRadioPowerStateRequested(false); 953 processAllMessages(); 954 assertTrue(mSatelliteControllerUT.isRadioOn()); 955 assertTrue(mSatelliteControllerUT.isRadioOffRequested()); 956 assertTrue(mSatelliteControllerUT.isWaitForCellularModemOffTimerStarted()); 957 958 // Modem failed to power off the radio 959 mSatelliteControllerUT.onPowerOffCellularRadioFailed(); 960 processAllMessages(); 961 assertTrue(mSatelliteControllerUT.isRadioOn()); 962 assertFalse(mSatelliteControllerUT.isRadioOffRequested()); 963 assertFalse(mSatelliteControllerUT.isWaitForCellularModemOffTimerStarted()); 964 } 965 966 @Test testRadioPowerOff()967 public void testRadioPowerOff() { 968 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 969 NetworkRegistrationInfo satelliteNri = new NetworkRegistrationInfo.Builder() 970 .setIsNonTerrestrialNetwork(true) 971 .setAvailableServices(List.of(NetworkRegistrationInfo.SERVICE_TYPE_DATA)) 972 .build(); 973 mCarrierConfigBundle.putInt(KEY_SATELLITE_CONNECTION_HYSTERESIS_SEC_INT, 1 * 60); 974 mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, true); 975 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 976 : mCarrierConfigChangedListenerList) { 977 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 978 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 979 ); 980 } 981 when(mServiceState.getNetworkRegistrationInfoList()).thenReturn(List.of(satelliteNri)); 982 when(mServiceState.isUsingNonTerrestrialNetwork()).thenReturn(true); 983 sendServiceStateChangedEvent(); 984 processAllMessages(); 985 assertTrue(mSatelliteControllerUT.isInSatelliteModeForCarrierRoaming(mPhone)); 986 assertEquals(List.of(SERVICE_TYPE_DATA), 987 mSatelliteControllerUT.getCapabilitiesForCarrierRoamingSatelliteMode(mPhone)); 988 989 when(mServiceState.isUsingNonTerrestrialNetwork()).thenReturn(false); 990 setRadioPower(false); 991 processAllMessages(); 992 assertFalse(mSatelliteControllerUT.isInSatelliteModeForCarrierRoaming(mPhone)); 993 assertEquals(new ArrayList<>(), 994 mSatelliteControllerUT.getCapabilitiesForCarrierRoamingSatelliteMode(mPhone)); 995 } 996 997 @Test testRequestSatelliteEnabled()998 public void testRequestSatelliteEnabled() { 999 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 1000 when(mFeatureFlags.satelliteStateChangeListener()).thenReturn(true); 1001 mIsSatelliteEnabledSemaphore.drainPermits(); 1002 1003 // Fail to enable satellite when SatelliteController is not fully loaded yet. 1004 mIIntegerConsumerResults.clear(); 1005 mIIntegerConsumerSemaphore.drainPermits(); 1006 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 1007 processAllMessages(); 1008 assertTrue(waitForIIntegerConsumerResult(1)); 1009 assertEquals(SATELLITE_RESULT_INVALID_TELEPHONY_STATE, 1010 (long) mIIntegerConsumerResults.get(0)); 1011 1012 // Fail to enable satellite when the device does not support satellite. 1013 mIIntegerConsumerResults.clear(); 1014 mIIntegerConsumerSemaphore.drainPermits(); 1015 setUpResponseForRequestIsSatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 1016 verifySatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 1017 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 1018 processAllMessages(); 1019 assertTrue(waitForIIntegerConsumerResult(1)); 1020 assertEquals(SATELLITE_RESULT_NOT_SUPPORTED, (long) mIIntegerConsumerResults.get(0)); 1021 1022 // Fail to enable satellite when the device is not provisioned yet. 1023 mIIntegerConsumerResults.clear(); 1024 mIIntegerConsumerSemaphore.drainPermits(); 1025 resetSatelliteControllerUT(); 1026 verify(mMockSatelliteSessionController, times(1)).onSatelliteEnabledStateChanged(eq(false)); 1027 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1028 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1029 setUpResponseForRequestIsSatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 1030 verifySatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 1031 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 1032 processAllMessages(); 1033 assertTrue(waitForIIntegerConsumerResult(1)); 1034 assertEquals(SATELLITE_RESULT_SERVICE_NOT_PROVISIONED, 1035 (long) mIIntegerConsumerResults.get(0)); 1036 1037 setProvisionedState(true); 1038 processAllMessages(); 1039 verifySatelliteProvisioned(true, SATELLITE_RESULT_SUCCESS); 1040 1041 // Fail to enable satellite when the emergency call is in progress 1042 mIIntegerConsumerResults.clear(); 1043 mIIntegerConsumerSemaphore.drainPermits(); 1044 mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled = false; 1045 mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled = false; 1046 setUpResponseForRequestSatelliteEnabled(true, false, false, SATELLITE_RESULT_SUCCESS); 1047 doReturn(true).when(mTelecomManager).isInEmergencyCall(); 1048 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 1049 mSatelliteControllerUT.setSatelliteSessionController(mMockSatelliteSessionController); 1050 processAllMessages(); 1051 assertTrue(waitForIIntegerConsumerResult(1)); 1052 assertEquals(SATELLITE_RESULT_EMERGENCY_CALL_IN_PROGRESS, 1053 (long) mIIntegerConsumerResults.get(0)); 1054 doReturn(false).when(mTelecomManager).isInEmergencyCall(); 1055 1056 // Successfully enable satellite 1057 reset(mTelephonyRegistryManager); 1058 mIIntegerConsumerResults.clear(); 1059 mIIntegerConsumerSemaphore.drainPermits(); 1060 mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled = false; 1061 mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled = false; 1062 setUpResponseForRequestSatelliteEnabled(true, false, true, SATELLITE_RESULT_SUCCESS); 1063 mSatelliteControllerUT.requestSatelliteEnabled(true, false, true, mIIntegerConsumer); 1064 mSatelliteControllerUT.setSatelliteSessionController(mMockSatelliteSessionController); 1065 processAllMessages(); 1066 assertTrue(waitForIIntegerConsumerResult(1)); 1067 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 1068 verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); 1069 verify(mMockSatelliteSessionController, times(1)).onEmergencyModeChanged(eq(true)); 1070 assertTrue(mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled); 1071 assertTrue(mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled); 1072 assertEquals( 1073 SATELLITE_MODE_ENABLED_TRUE, mSatelliteControllerUT.satelliteModeSettingValue); 1074 verify(mMockSatelliteSessionController, times(1)).onSatelliteEnabledStateChanged(eq(true)); 1075 verify(mMockSatelliteSessionController, times(2)).setDemoMode(eq(false)); 1076 verify(mMockDatagramController, times(2)).setDemoMode(eq(false)); 1077 verify(mMockControllerMetricsStats, times(1)).onSatelliteEnabled(); 1078 verify(mMockControllerMetricsStats, times(1)).reportServiceEnablementSuccessCount(); 1079 verify(mTelephonyRegistryManager).notifySatelliteStateChanged(eq(true)); 1080 1081 // Successfully disable satellite when radio is turned off. 1082 reset(mTelephonyRegistryManager); 1083 clearInvocations(mMockSatelliteSessionController); 1084 clearInvocations(mMockDatagramController); 1085 mSatelliteControllerUT.setSatelliteSessionController(mMockSatelliteSessionController); 1086 mSatelliteControllerUT.isSatelliteBeingDisabled = true; 1087 mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled = false; 1088 mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled = false; 1089 setUpResponseForRequestSatelliteEnabled(false, false, false, SATELLITE_RESULT_SUCCESS); 1090 setRadioPower(false); 1091 mSatelliteControllerUT.onSetCellularRadioPowerStateRequested(false); 1092 processAllMessages(); 1093 sendSatelliteModemStateChangedEvent(SATELLITE_MODEM_STATE_OFF, null); 1094 processAllMessages(); 1095 verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); 1096 verify(mMockSatelliteSessionController, times(1)).onEmergencyModeChanged(eq(false)); 1097 assertTrue(mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled); 1098 assertTrue(mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled); 1099 assertEquals( 1100 SATELLITE_MODE_ENABLED_FALSE, mSatelliteControllerUT.satelliteModeSettingValue); 1101 verify(mMockSatelliteSessionController, times(2)).onSatelliteEnabledStateChanged(eq(false)); 1102 verify(mMockSatelliteSessionController, times(2)).setDemoMode(eq(false)); 1103 verify(mMockDatagramController, times(2)).setDemoMode(eq(false)); 1104 verify(mMockControllerMetricsStats, times(1)).onSatelliteDisabled(); 1105 mSatelliteControllerUT.isSatelliteBeingDisabled = false; 1106 verify(mTelephonyRegistryManager, atLeastOnce()).notifySatelliteStateChanged(eq(false)); 1107 1108 // Fail to enable satellite when radio is off. 1109 mIIntegerConsumerResults.clear(); 1110 mIIntegerConsumerSemaphore.drainPermits(); 1111 setUpResponseForRequestSatelliteEnabled(true, false, false, SATELLITE_RESULT_SUCCESS); 1112 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 1113 processAllMessages(); 1114 assertTrue(waitForIIntegerConsumerResult(1)); 1115 // Radio is not on, can not enable satellite 1116 assertEquals(SATELLITE_RESULT_INVALID_MODEM_STATE, (long) mIIntegerConsumerResults.get(0)); 1117 1118 setRadioPower(true); 1119 processAllMessages(); 1120 verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); 1121 1122 // Fail to enable satellite with an error response from modem when radio is on. 1123 mIIntegerConsumerResults.clear(); 1124 mIIntegerConsumerSemaphore.drainPermits(); 1125 clearInvocations(mMockPointingAppController); 1126 mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled = false; 1127 mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled = false; 1128 setUpResponseForRequestSatelliteEnabled(true, false, false, 1129 SATELLITE_RESULT_INVALID_MODEM_STATE); 1130 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 1131 processAllMessages(); 1132 assertTrue(waitForIIntegerConsumerResult(1)); 1133 assertEquals(SATELLITE_RESULT_INVALID_MODEM_STATE, (long) mIIntegerConsumerResults.get(0)); 1134 verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); 1135 verify(mMockPointingAppController, never()).startPointingUI(anyBoolean(), anyBoolean(), 1136 anyBoolean()); 1137 assertFalse(mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled); 1138 assertFalse(mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled); 1139 verify(mMockControllerMetricsStats, times(1)).reportServiceEnablementFailCount(); 1140 1141 // Successfully enable satellite when radio is on. 1142 reset(mTelephonyRegistryManager); 1143 mIIntegerConsumerResults.clear(); 1144 mIIntegerConsumerSemaphore.drainPermits(); 1145 mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled = false; 1146 mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled = false; 1147 setUpResponseForRequestSatelliteEnabled(true, false, false, SATELLITE_RESULT_SUCCESS); 1148 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 1149 processAllMessages(); 1150 assertTrue(waitForIIntegerConsumerResult(1)); 1151 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 1152 verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); 1153 assertTrue(mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled); 1154 assertTrue(mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled); 1155 assertEquals(SATELLITE_MODE_ENABLED_TRUE, mSatelliteControllerUT.satelliteModeSettingValue); 1156 verify(mMockSatelliteSessionController, times(1)).onSatelliteEnabledStateChanged(eq(true)); 1157 verify(mMockSatelliteSessionController, times(3)).setDemoMode(eq(false)); 1158 verify(mMockDatagramController, times(3)).setDemoMode(eq(false)); 1159 verify(mMockControllerMetricsStats, times(2)).onSatelliteEnabled(); 1160 verify(mMockControllerMetricsStats, times(2)).reportServiceEnablementSuccessCount(); 1161 verify(mTelephonyRegistryManager).notifySatelliteStateChanged(eq(true)); 1162 1163 // Successfully enable satellite when it is already enabled. 1164 mIIntegerConsumerResults.clear(); 1165 mIIntegerConsumerSemaphore.drainPermits(); 1166 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 1167 processAllMessages(); 1168 assertTrue(waitForIIntegerConsumerResult(1)); 1169 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 1170 verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); 1171 1172 // Fail to enable satellite with a different demo mode when it is already enabled. 1173 mIIntegerConsumerResults.clear(); 1174 mIIntegerConsumerSemaphore.drainPermits(); 1175 mSatelliteControllerUT.requestSatelliteEnabled(true, true, false, mIIntegerConsumer); 1176 processAllMessages(); 1177 assertTrue(waitForIIntegerConsumerResult(1)); 1178 assertEquals(SATELLITE_RESULT_INVALID_ARGUMENTS, (long) mIIntegerConsumerResults.get(0)); 1179 verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); 1180 1181 // Successfully disable satellite. 1182 reset(mTelephonyRegistryManager); 1183 mIIntegerConsumerResults.clear(); 1184 mIIntegerConsumerSemaphore.drainPermits(); 1185 setUpResponseForRequestSatelliteEnabled(false, false, false, SATELLITE_RESULT_SUCCESS); 1186 mSatelliteControllerUT.requestSatelliteEnabled(false, false, false, mIIntegerConsumer); 1187 processAllMessages(); 1188 assertTrue(waitForIIntegerConsumerResult(1)); 1189 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 1190 verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); 1191 verify(mTelephonyRegistryManager, atLeastOnce()).notifySatelliteStateChanged(eq(false)); 1192 1193 // Disable satellite when satellite is already disabled. 1194 mIIntegerConsumerResults.clear(); 1195 mIIntegerConsumerSemaphore.drainPermits(); 1196 mSatelliteControllerUT.requestSatelliteEnabled(false, false, false, mIIntegerConsumer); 1197 processAllMessages(); 1198 assertTrue(waitForIIntegerConsumerResult(1)); 1199 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 1200 verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); 1201 1202 // Disable satellite with a different demo mode when satellite is already disabled. 1203 mIIntegerConsumerResults.clear(); 1204 mIIntegerConsumerSemaphore.drainPermits(); 1205 mSatelliteControllerUT.requestSatelliteEnabled(false, true, false, mIIntegerConsumer); 1206 processAllMessages(); 1207 assertTrue(waitForIIntegerConsumerResult(1)); 1208 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 1209 verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); 1210 1211 // Send a second request while the first request in progress 1212 mIIntegerConsumerResults.clear(); 1213 mIIntegerConsumerSemaphore.drainPermits(); 1214 setUpNoResponseForRequestSatelliteEnabled(true, false, false); 1215 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 1216 processAllMessages(); 1217 assertFalse(waitForIIntegerConsumerResult(1)); 1218 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 1219 processAllMessages(); 1220 assertTrue(waitForIIntegerConsumerResult(1)); 1221 assertEquals(SATELLITE_RESULT_REQUEST_IN_PROGRESS, (long) mIIntegerConsumerResults.get(0)); 1222 1223 mIIntegerConsumerResults.clear(); 1224 mIIntegerConsumerSemaphore.drainPermits(); 1225 resetSatelliteControllerUT(); 1226 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1227 setProvisionedState(false); 1228 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1229 setProvisionedState(true); 1230 processAllMessages(); 1231 verifySatelliteProvisioned(true, SATELLITE_RESULT_SUCCESS); 1232 // The enable request should be aborted when satellite modem move to OFF state. 1233 assertTrue(waitForIIntegerConsumerResult(1)); 1234 assertEquals(SATELLITE_RESULT_REQUEST_ABORTED, (long) mIIntegerConsumerResults.get(0)); 1235 1236 // Successfully enable satellite 1237 mIIntegerConsumerResults.clear(); 1238 mIIntegerConsumerSemaphore.drainPermits(); 1239 setUpResponseForRequestSatelliteEnabled(true, false, false, SATELLITE_RESULT_SUCCESS); 1240 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 1241 processAllMessages(); 1242 assertTrue(waitForIIntegerConsumerResult(1)); 1243 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 1244 verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); 1245 1246 // Move to satellite-disabling in progress. 1247 mIIntegerConsumerResults.clear(); 1248 mIIntegerConsumerSemaphore.drainPermits(); 1249 setUpNoResponseForRequestSatelliteEnabled(false, false, false); 1250 mSatelliteControllerUT.requestSatelliteEnabled(false, false, false, mIIntegerConsumer); 1251 processAllMessages(); 1252 assertFalse(waitForIIntegerConsumerResult(1)); 1253 1254 // Disable is in progress. Thus, a new request to enable satellite will be rejected. 1255 mIIntegerConsumerResults.clear(); 1256 mIIntegerConsumerSemaphore.drainPermits(); 1257 mSatelliteControllerUT.setSatelliteSessionController(mMockSatelliteSessionController); 1258 mSatelliteControllerUT.isSatelliteBeingDisabled = true; 1259 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 1260 processAllMessages(); 1261 assertTrue(waitForIIntegerConsumerResult(1)); 1262 assertEquals(SATELLITE_RESULT_DISABLE_IN_PROGRESS, (long) mIIntegerConsumerResults.get(0)); 1263 1264 mIIntegerConsumerResults.clear(); 1265 mIIntegerConsumerSemaphore.drainPermits(); 1266 resetSatelliteControllerUTToOffAndProvisionedState(); 1267 mSatelliteControllerUT.isSatelliteBeingDisabled = false; 1268 1269 /** 1270 * Make areAllRadiosDisabled return false and move mWaitingForRadioDisabled to true, which 1271 * will lead to no response for requestSatelliteEnabled. 1272 */ 1273 mSatelliteControllerUT.allRadiosDisabled = false; 1274 mIIntegerConsumerResults.clear(); 1275 mIIntegerConsumerSemaphore.drainPermits(); 1276 setUpResponseForRequestSatelliteEnabled(true, false, false, SATELLITE_RESULT_SUCCESS); 1277 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 1278 processAllMessages(); 1279 assertFalse(waitForIIntegerConsumerResult(1)); 1280 1281 mIIntegerConsumerResults.clear(); 1282 mIIntegerConsumerSemaphore.drainPermits(); 1283 setUpResponseForRequestSatelliteEnabled(false, false, false, SATELLITE_RESULT_SUCCESS); 1284 mSatelliteControllerUT.requestSatelliteEnabled(false, false, false, mIIntegerConsumer); 1285 processAllMessages(); 1286 // We should receive 2 callbacks for the above 2 requests. 1287 assertTrue(waitForIIntegerConsumerResult(2)); 1288 // Successful result for disable request 1289 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 1290 // The enable request should be aborted after getting the successful confirmation of the 1291 // disable request. 1292 assertEquals(SATELLITE_RESULT_REQUEST_ABORTED, (long) mIIntegerConsumerResults.get(1)); 1293 1294 resetSatelliteControllerUTToOffAndProvisionedState(); 1295 1296 // Repeat the same test as above but with error response from modem for the second request 1297 mSatelliteControllerUT.allRadiosDisabled = false; 1298 setUpResponseForRequestSatelliteEnabled(true, false, false, SATELLITE_RESULT_SUCCESS); 1299 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 1300 processAllMessages(); 1301 // No response for the enable request because all radios are not disabled yet 1302 assertFalse(waitForIIntegerConsumerResult(1)); 1303 1304 mIIntegerConsumerResults.clear(); 1305 mIIntegerConsumerSemaphore.drainPermits(); 1306 setUpResponseForRequestSatelliteEnabled(false, false, false, SATELLITE_RESULT_NO_RESOURCES); 1307 mSatelliteControllerUT.requestSatelliteEnabled(false, false, false, mIIntegerConsumer); 1308 processAllMessages(); 1309 // We should receive result for the disable request. 1310 assertTrue(waitForIIntegerConsumerResult(1)); 1311 assertEquals(SATELLITE_RESULT_NO_RESOURCES, (long) mIIntegerConsumerResults.get(0)); 1312 mSatelliteControllerUT.allRadiosDisabled = true; 1313 1314 resetSatelliteControllerUTToOnAndProvisionedState(); 1315 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(false); 1316 mSatelliteControllerUT.onSetCellularRadioPowerStateRequested(false); 1317 processAllMessages(); 1318 // Satellite should not be powered off since the feature flag oemEnabledSatelliteFlag is 1319 // disabled 1320 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(true); 1321 verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); 1322 1323 // Successfully disable satellite. 1324 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(true); 1325 mIIntegerConsumerResults.clear(); 1326 mIIntegerConsumerSemaphore.drainPermits(); 1327 setUpResponseForRequestSatelliteEnabled(false, false, false, SATELLITE_RESULT_SUCCESS); 1328 mSatelliteControllerUT.requestSatelliteEnabled(false, false, false, mIIntegerConsumer); 1329 processAllMessages(); 1330 assertTrue(waitForIIntegerConsumerResult(1)); 1331 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 1332 verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); 1333 1334 // Fail to enable satellite when radio is being powered off. 1335 mIIntegerConsumerResults.clear(); 1336 mIIntegerConsumerSemaphore.drainPermits(); 1337 setUpResponseForRequestSatelliteEnabled(true, false, false, SATELLITE_RESULT_SUCCESS); 1338 mSatelliteControllerUT.onSetCellularRadioPowerStateRequested(false); 1339 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 1340 processAllMessages(); 1341 assertTrue(waitForIIntegerConsumerResult(1)); 1342 // Radio is being powered off, can not enable satellite 1343 assertEquals(SATELLITE_RESULT_INVALID_MODEM_STATE, (long) mIIntegerConsumerResults.get(0)); 1344 1345 // Modem failed to power off 1346 mSatelliteControllerUT.onPowerOffCellularRadioFailed(); 1347 1348 // Successfully enable satellite when radio is on. 1349 mIIntegerConsumerResults.clear(); 1350 mIIntegerConsumerSemaphore.drainPermits(); 1351 mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled = false; 1352 mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled = false; 1353 setUpResponseForRequestSatelliteEnabled(true, false, false, SATELLITE_RESULT_SUCCESS); 1354 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 1355 processAllMessages(); 1356 assertTrue(waitForIIntegerConsumerResult(1)); 1357 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 1358 verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); 1359 1360 // Clean up all previous resources 1361 processAllFutureMessages(); 1362 mIIntegerConsumerSemaphore.drainPermits(); 1363 1364 // Successfully disable satellite. 1365 mIIntegerConsumerResults.clear(); 1366 mIIntegerConsumerSemaphore.drainPermits(); 1367 setUpResponseForRequestSatelliteEnabled(false, false, false, SATELLITE_RESULT_SUCCESS); 1368 mSatelliteControllerUT.requestSatelliteEnabled(false, false, false, mIIntegerConsumer); 1369 processAllMessages(); 1370 assertTrue(waitForIIntegerConsumerResult(1)); 1371 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 1372 verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); 1373 1374 // Move to satellite-enabling in progress. 1375 setUpNoResponseForRequestSatelliteEnabled(true, false, false); 1376 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 1377 processAllMessages(); 1378 assertFalse(waitForIIntegerConsumerResult(1)); 1379 1380 // Successfully disable satellite. 1381 mIIntegerConsumerResults.clear(); 1382 mIIntegerConsumerSemaphore.drainPermits(); 1383 setUpResponseForRequestSatelliteEnabled(false, false, false, SATELLITE_RESULT_SUCCESS); 1384 mSatelliteControllerUT.requestSatelliteEnabled(false, false, false, mIIntegerConsumer); 1385 processAllMessages(); 1386 assertTrue(waitForIIntegerConsumerResult(2)); 1387 // Should get success result for the disable request 1388 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 1389 // The enable request should be aborted 1390 assertEquals(SATELLITE_RESULT_REQUEST_ABORTED, (long) mIIntegerConsumerResults.get(1)); 1391 // All timers waiting for enablement response should be stopped 1392 assertFalse(mSatelliteControllerUT.isAnyWaitForSatelliteEnablingResponseTimerStarted()); 1393 verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); 1394 } 1395 1396 @Test testGetRequestIsEmergency()1397 public void testGetRequestIsEmergency() { 1398 mIsSatelliteEnabledSemaphore.drainPermits(); 1399 doReturn(true).when(mFeatureFlags).carrierRoamingNbIotNtn(); 1400 1401 // Successfully enable satellite 1402 mIIntegerConsumerResults.clear(); 1403 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1404 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1405 1406 // Set provisioned state 1407 setProvisionedState(true); 1408 processAllMessages(); 1409 verifySatelliteProvisioned(true, SATELLITE_RESULT_SUCCESS); 1410 1411 mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled = false; 1412 mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled = false; 1413 // Set response for enabling request 1414 setUpResponseForRequestSatelliteEnabled(true, false, true/*emergency*/, 1415 SATELLITE_RESULT_SUCCESS); 1416 // Request satellite enabling for emergency 1417 mSatelliteControllerUT.requestSatelliteEnabled(true, false, true /*isEmergency*/, 1418 mIIntegerConsumer); 1419 mSatelliteControllerUT.setSatelliteSessionController(mMockSatelliteSessionController); 1420 processAllMessages(); 1421 1422 assertTrue(waitForIIntegerConsumerResult(1)); 1423 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 1424 verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); 1425 1426 // Verify satellite enabled for emergency 1427 assertTrue(mSatelliteControllerUT.getRequestIsEmergency()); 1428 mSatelliteControllerUT.requestIsEmergencyModeEnabled(mRequestIsEmergencyReceiver); 1429 assertTrue(mRequestIsEmergency); 1430 } 1431 1432 @Test testRequestSatelliteCapabilities()1433 public void testRequestSatelliteCapabilities() { 1434 mSatelliteCapabilitiesSemaphore.drainPermits(); 1435 mSatelliteControllerUT.requestSatelliteCapabilities(mSatelliteCapabilitiesReceiver); 1436 processAllMessages(); 1437 assertTrue(waitForRequestSatelliteCapabilitiesResult(1)); 1438 assertEquals(SATELLITE_RESULT_INVALID_TELEPHONY_STATE, 1439 mQueriedSatelliteCapabilitiesResultCode); 1440 1441 setUpResponseForRequestIsSatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 1442 verifySatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 1443 mSatelliteControllerUT.requestSatelliteCapabilities(mSatelliteCapabilitiesReceiver); 1444 processAllMessages(); 1445 assertTrue(waitForRequestSatelliteCapabilitiesResult(1)); 1446 assertEquals(SATELLITE_RESULT_NOT_SUPPORTED, mQueriedSatelliteCapabilitiesResultCode); 1447 1448 resetSatelliteControllerUT(); 1449 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1450 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1451 setUpResponseForRequestSatelliteCapabilities(mSatelliteCapabilities, 1452 SATELLITE_RESULT_SUCCESS); 1453 mSatelliteControllerUT.requestSatelliteCapabilities(mSatelliteCapabilitiesReceiver); 1454 processAllMessages(); 1455 assertTrue(waitForRequestSatelliteCapabilitiesResult(1)); 1456 assertEquals(SATELLITE_RESULT_SUCCESS, mQueriedSatelliteCapabilitiesResultCode); 1457 assertEquals(mSatelliteCapabilities, mQueriedSatelliteCapabilities); 1458 assertTrue( 1459 mQueriedSatelliteCapabilities.getSupportedRadioTechnologies().contains( 1460 mSatelliteControllerUT.getSupportedNtnRadioTechnology())); 1461 1462 resetSatelliteControllerUT(); 1463 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1464 setUpNullResponseForRequestSatelliteCapabilities(SATELLITE_RESULT_SUCCESS); 1465 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1466 mSatelliteControllerUT.requestSatelliteCapabilities(mSatelliteCapabilitiesReceiver); 1467 processAllMessages(); 1468 assertTrue(waitForRequestSatelliteCapabilitiesResult(1)); 1469 assertEquals(SATELLITE_RESULT_INVALID_TELEPHONY_STATE, 1470 mQueriedSatelliteCapabilitiesResultCode); 1471 1472 resetSatelliteControllerUT(); 1473 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1474 setUpNullResponseForRequestSatelliteCapabilities(SATELLITE_RESULT_INVALID_MODEM_STATE); 1475 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1476 mSatelliteControllerUT.requestSatelliteCapabilities(mSatelliteCapabilitiesReceiver); 1477 processAllMessages(); 1478 assertTrue(waitForRequestSatelliteCapabilitiesResult(1)); 1479 assertEquals(SATELLITE_RESULT_INVALID_MODEM_STATE, mQueriedSatelliteCapabilitiesResultCode); 1480 } 1481 1482 @Test testStartSatelliteTransmissionUpdates()1483 public void testStartSatelliteTransmissionUpdates() { 1484 mIIntegerConsumerSemaphore.drainPermits(); 1485 mIIntegerConsumerResults.clear(); 1486 mSatelliteControllerUT.startSatelliteTransmissionUpdates(mIIntegerConsumer, 1487 mStartTransmissionUpdateCallback); 1488 processAllMessages(); 1489 assertTrue(waitForIIntegerConsumerResult(1)); 1490 assertEquals(SATELLITE_RESULT_INVALID_TELEPHONY_STATE, 1491 (long) mIIntegerConsumerResults.get(0)); 1492 1493 mIIntegerConsumerResults.clear(); 1494 setUpResponseForRequestIsSatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 1495 verifySatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 1496 mSatelliteControllerUT.startSatelliteTransmissionUpdates(mIIntegerConsumer, 1497 mStartTransmissionUpdateCallback); 1498 processAllMessages(); 1499 assertTrue(waitForIIntegerConsumerResult(1)); 1500 assertEquals(SATELLITE_RESULT_NOT_SUPPORTED, (long) mIIntegerConsumerResults.get(0)); 1501 1502 resetSatelliteControllerUT(); 1503 mIIntegerConsumerResults.clear(); 1504 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1505 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1506 mSatelliteControllerUT.startSatelliteTransmissionUpdates(mIIntegerConsumer, 1507 mStartTransmissionUpdateCallback); 1508 processAllMessages(); 1509 assertTrue(waitForIIntegerConsumerResult(1)); 1510 assertEquals(SATELLITE_RESULT_SERVICE_NOT_PROVISIONED, 1511 (long) mIIntegerConsumerResults.get(0)); 1512 1513 resetSatelliteControllerUT(); 1514 mIIntegerConsumerResults.clear(); 1515 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1516 setUpResponseForRequestIsSatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 1517 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1518 verifySatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 1519 setUpResponseForStartSatelliteTransmissionUpdates(SATELLITE_RESULT_SUCCESS); 1520 mSatelliteControllerUT.startSatelliteTransmissionUpdates(mIIntegerConsumer, 1521 mStartTransmissionUpdateCallback); 1522 processAllMessages(); 1523 assertTrue(waitForIIntegerConsumerResult(1)); 1524 assertEquals(SATELLITE_RESULT_SERVICE_NOT_PROVISIONED, 1525 (long) mIIntegerConsumerResults.get(0)); 1526 1527 resetSatelliteControllerUT(); 1528 provisionSatelliteService(); 1529 mIIntegerConsumerResults.clear(); 1530 setUpResponseForStartSatelliteTransmissionUpdates(SATELLITE_RESULT_SUCCESS); 1531 mSatelliteControllerUT.startSatelliteTransmissionUpdates(mIIntegerConsumer, 1532 mStartTransmissionUpdateCallback); 1533 verify(mMockPointingAppController).registerForSatelliteTransmissionUpdates(anyInt(), 1534 eq(mStartTransmissionUpdateCallback)); 1535 processAllMessages(); 1536 assertTrue(waitForIIntegerConsumerResult(1)); 1537 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 1538 verify(mMockPointingAppController).startSatelliteTransmissionUpdates(any(Message.class)); 1539 verify(mMockPointingAppController).setStartedSatelliteTransmissionUpdates(eq(true)); 1540 1541 resetSatelliteControllerUT(); 1542 provisionSatelliteService(); 1543 mIIntegerConsumerResults.clear(); 1544 setUpResponseForStartSatelliteTransmissionUpdates(SATELLITE_RESULT_INVALID_TELEPHONY_STATE); 1545 mSatelliteControllerUT.startSatelliteTransmissionUpdates(mIIntegerConsumer, 1546 mStartTransmissionUpdateCallback); 1547 processAllMessages(); 1548 assertTrue(waitForIIntegerConsumerResult(1)); 1549 assertEquals(SATELLITE_RESULT_INVALID_TELEPHONY_STATE, 1550 (long) mIIntegerConsumerResults.get(0)); 1551 verify(mMockPointingAppController).unregisterForSatelliteTransmissionUpdates(anyInt(), 1552 any(), eq(mStartTransmissionUpdateCallback)); 1553 verify(mMockPointingAppController).setStartedSatelliteTransmissionUpdates(eq(false)); 1554 } 1555 1556 @Test testStopSatelliteTransmissionUpdates()1557 public void testStopSatelliteTransmissionUpdates() { 1558 resetSatelliteControllerUT(); 1559 mIIntegerConsumerResults.clear(); 1560 provisionSatelliteService(); 1561 setUpResponseForStopSatelliteTransmissionUpdates(SATELLITE_RESULT_SUCCESS); 1562 mSatelliteControllerUT.stopSatelliteTransmissionUpdates(mIIntegerConsumer, 1563 mStopTransmissionUpdateCallback); 1564 verify(mMockPointingAppController).unregisterForSatelliteTransmissionUpdates(anyInt(), 1565 any(), eq(mStopTransmissionUpdateCallback)); 1566 processAllMessages(); 1567 assertTrue(waitForIIntegerConsumerResult(1)); 1568 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 1569 verify(mMockPointingAppController).stopSatelliteTransmissionUpdates(any(Message.class)); 1570 1571 resetSatelliteControllerUT(); 1572 provisionSatelliteService(); 1573 mIIntegerConsumerResults.clear(); 1574 setUpResponseForStopSatelliteTransmissionUpdates(SATELLITE_RESULT_INVALID_TELEPHONY_STATE); 1575 mSatelliteControllerUT.stopSatelliteTransmissionUpdates(mIIntegerConsumer, 1576 mStopTransmissionUpdateCallback); 1577 verify(mMockPointingAppController, times(2)).unregisterForSatelliteTransmissionUpdates( 1578 anyInt(), any(), eq(mStopTransmissionUpdateCallback)); 1579 processAllMessages(); 1580 verify(mMockPointingAppController, times(2)).stopSatelliteTransmissionUpdates( 1581 any(Message.class)); 1582 assertTrue(waitForIIntegerConsumerResult(1)); 1583 assertEquals(SATELLITE_RESULT_INVALID_TELEPHONY_STATE, 1584 (long) mIIntegerConsumerResults.get(0)); 1585 } 1586 1587 @Test testRequestIsDemoModeEnabled()1588 public void testRequestIsDemoModeEnabled() { 1589 mIsDemoModeEnabledSemaphore.drainPermits(); 1590 resetSatelliteControllerUT(); 1591 mSatelliteControllerUT.requestIsDemoModeEnabled(mIsDemoModeEnabledReceiver); 1592 assertTrue(waitForRequestIsDemoModeEnabledResult(1)); 1593 assertEquals(SATELLITE_RESULT_INVALID_TELEPHONY_STATE, mQueriedIsDemoModeEnabledResultCode); 1594 assertFalse(mQueriedIsDemoModeEnabled); 1595 1596 resetSatelliteControllerUT(); 1597 setUpResponseForRequestIsSatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 1598 verifySatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 1599 mSatelliteControllerUT.requestIsDemoModeEnabled(mIsDemoModeEnabledReceiver); 1600 assertTrue(waitForRequestIsDemoModeEnabledResult(1)); 1601 assertEquals(SATELLITE_RESULT_NOT_SUPPORTED, mQueriedIsDemoModeEnabledResultCode); 1602 assertFalse(mQueriedIsDemoModeEnabled); 1603 1604 resetSatelliteControllerUT(); 1605 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1606 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1607 mSatelliteControllerUT.requestIsDemoModeEnabled(mIsDemoModeEnabledReceiver); 1608 assertTrue(waitForRequestIsDemoModeEnabledResult(1)); 1609 assertEquals(SATELLITE_RESULT_SERVICE_NOT_PROVISIONED, mQueriedIsDemoModeEnabledResultCode); 1610 assertFalse(mQueriedIsDemoModeEnabled); 1611 1612 resetSatelliteControllerUT(); 1613 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1614 setUpResponseForRequestIsSatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 1615 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1616 verifySatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 1617 mSatelliteControllerUT.requestIsDemoModeEnabled(mIsDemoModeEnabledReceiver); 1618 assertTrue(waitForRequestIsDemoModeEnabledResult(1)); 1619 assertEquals(SATELLITE_RESULT_SERVICE_NOT_PROVISIONED, mQueriedIsDemoModeEnabledResultCode); 1620 assertFalse(mQueriedIsDemoModeEnabled); 1621 1622 resetSatelliteControllerUT(); 1623 boolean isDemoModeEnabled = mSatelliteControllerUT.isDemoModeEnabled(); 1624 provisionSatelliteService(); 1625 mSatelliteControllerUT.requestIsDemoModeEnabled(mIsDemoModeEnabledReceiver); 1626 assertTrue(waitForRequestIsDemoModeEnabledResult(1)); 1627 assertEquals(SATELLITE_RESULT_SUCCESS, mQueriedIsDemoModeEnabledResultCode); 1628 assertEquals(isDemoModeEnabled, mQueriedIsDemoModeEnabled); 1629 } 1630 1631 @Test testIsSatelliteEnabled()1632 public void testIsSatelliteEnabled() { 1633 logd("testIsSatelliteEnabled: starting"); 1634 assertFalse(mSatelliteControllerUT.isSatelliteEnabledOrBeingEnabled()); 1635 setUpResponseForRequestIsSatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); 1636 mIsSatelliteEnabledSemaphore.drainPermits(); 1637 mSatelliteControllerUT.requestIsSatelliteEnabled(mIsSatelliteEnabledReceiver); 1638 processAllMessages(); 1639 assertTrue(waitForRequestIsSatelliteEnabledResult(1)); 1640 assertEquals( 1641 SATELLITE_RESULT_INVALID_TELEPHONY_STATE, mQueriedIsSatelliteEnabledResultCode); 1642 1643 1644 logd("testIsSatelliteEnabled: setUpResponseForRequestIsSatelliteSupported"); 1645 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1646 logd("testIsSatelliteEnabled: verifySatelliteSupported"); 1647 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1648 mSatelliteControllerUT.requestIsSatelliteEnabled(mIsSatelliteEnabledReceiver); 1649 processAllMessages(); 1650 assertEquals(SATELLITE_RESULT_SUCCESS, mQueriedIsSatelliteEnabledResultCode); 1651 assertEquals(mSatelliteControllerUT.isSatelliteEnabledOrBeingEnabled(), 1652 mQueriedIsSatelliteEnabled); 1653 } 1654 1655 @Test testOnSatelliteServiceConnected()1656 public void testOnSatelliteServiceConnected() { 1657 verifySatelliteSupported(false, SATELLITE_RESULT_RADIO_NOT_AVAILABLE); 1658 verifySatelliteEnabled(false, SATELLITE_RESULT_INVALID_TELEPHONY_STATE); 1659 1660 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1661 setUpResponseForRequestIsSatelliteProvisioned(true, SATELLITE_RESULT_SUCCESS); 1662 setUpResponseForRequestSatelliteEnabled(false, false, false, SATELLITE_RESULT_SUCCESS); 1663 1664 setUpResponseForRequestIsSatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); 1665 mSatelliteControllerUT.onSatelliteServiceConnected(); 1666 processAllMessages(); 1667 1668 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1669 verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); 1670 verifySatelliteProvisioned(true, SATELLITE_RESULT_SUCCESS); 1671 } 1672 1673 @Test testRegisterForSatelliteModemStateChanged()1674 public void testRegisterForSatelliteModemStateChanged() { 1675 ISatelliteModemStateCallback callback = new ISatelliteModemStateCallback.Stub() { 1676 @Override 1677 public void onSatelliteModemStateChanged(int state) { 1678 logd("onSatelliteModemStateChanged: state=" + state); 1679 } 1680 1681 @Override 1682 public void onEmergencyModeChanged(boolean isEmergency) { 1683 logd("onEmergencyModeChanged: emergency=" + isEmergency); 1684 } 1685 1686 @Override 1687 public void onRegistrationFailure(int causeCode) { 1688 logd("onRegistrationFailure: causeCode=" + causeCode); 1689 } 1690 1691 @Override 1692 public void onTerrestrialNetworkAvailableChanged(boolean isAvailable) { 1693 logd("onTerrestrialNetworkAvailableChanged: isAvailable=" + isAvailable); 1694 } 1695 }; 1696 int errorCode = mSatelliteControllerUT.registerForSatelliteModemStateChanged(callback); 1697 assertEquals(SATELLITE_RESULT_INVALID_TELEPHONY_STATE, errorCode); 1698 verify(mMockSatelliteSessionController, never()) 1699 .registerForSatelliteModemStateChanged(callback); 1700 1701 resetSatelliteControllerUTToSupportedAndProvisionedState(); 1702 mSatelliteControllerUT.setSatelliteSessionController(mMockSatelliteSessionController); 1703 1704 errorCode = mSatelliteControllerUT.registerForSatelliteModemStateChanged(callback); 1705 assertEquals(SATELLITE_RESULT_SUCCESS, errorCode); 1706 verify(mMockSatelliteSessionController).registerForSatelliteModemStateChanged(callback); 1707 } 1708 1709 @Test testUnregisterForSatelliteModemStateChanged()1710 public void testUnregisterForSatelliteModemStateChanged() { 1711 ISatelliteModemStateCallback callback = new ISatelliteModemStateCallback.Stub() { 1712 @Override 1713 public void onSatelliteModemStateChanged(int state) { 1714 logd("onSatelliteModemStateChanged: state=" + state); 1715 } 1716 1717 @Override 1718 public void onEmergencyModeChanged(boolean isEmergency) { 1719 logd("onEmergencyModeChanged: emergency=" + isEmergency); 1720 } 1721 1722 @Override 1723 public void onRegistrationFailure(int causeCode) { 1724 logd("onRegistrationFailure: causeCode=" + causeCode); 1725 } 1726 1727 @Override 1728 public void onTerrestrialNetworkAvailableChanged(boolean isAvailable) { 1729 logd("onTerrestrialNetworkAvailableChanged: isAvailable=" + isAvailable); 1730 } 1731 }; 1732 mSatelliteControllerUT.unregisterForModemStateChanged(callback); 1733 verify(mMockSatelliteSessionController, never()) 1734 .unregisterForSatelliteModemStateChanged(callback); 1735 1736 resetSatelliteControllerUTToSupportedAndProvisionedState(); 1737 mSatelliteControllerUT.setSatelliteSessionController(mMockSatelliteSessionController); 1738 mSatelliteControllerUT.unregisterForModemStateChanged(callback); 1739 verify(mMockSatelliteSessionController).unregisterForSatelliteModemStateChanged(callback); 1740 } 1741 1742 @Test testRegisterForSatelliteProvisionStateChanged()1743 public void testRegisterForSatelliteProvisionStateChanged() { 1744 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 1745 Semaphore semaphore = new Semaphore(0); 1746 ISatelliteProvisionStateCallback callback = 1747 new ISatelliteProvisionStateCallback.Stub() { 1748 @Override 1749 public void onSatelliteProvisionStateChanged(boolean provisioned) { 1750 logd("onSatelliteProvisionStateChanged: provisioned=" + provisioned); 1751 try { 1752 semaphore.release(); 1753 } catch (Exception ex) { 1754 loge("onSatelliteProvisionStateChanged: Got exception in releasing " 1755 + "semaphore, ex=" + ex); 1756 } 1757 } 1758 1759 @Override 1760 public void onSatelliteSubscriptionProvisionStateChanged( 1761 List<SatelliteSubscriberProvisionStatus> status) { 1762 logd("onSatelliteSubscriptionProvisionStateChanged: " + status); 1763 } 1764 }; 1765 int errorCode = mSatelliteControllerUT.registerForSatelliteProvisionStateChanged(callback); 1766 assertEquals(SATELLITE_RESULT_SUCCESS, errorCode); 1767 1768 resetSatelliteControllerUT(); 1769 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1770 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1771 errorCode = mSatelliteControllerUT.registerForSatelliteProvisionStateChanged(callback); 1772 processAllMessages(); 1773 assertTrue(waitForForEvents( 1774 semaphore, 1, "testRegisterForSatelliteProvisionStateChanged")); 1775 assertEquals(SATELLITE_RESULT_SUCCESS, errorCode); 1776 1777 try { 1778 setSatelliteSubscriberTesting(true); 1779 } catch (Exception ex) { 1780 fail("provisionSatelliteService.setSatelliteSubscriberTesting: ex=" + ex); 1781 } 1782 doReturn(true).when(mMockSubscriptionManagerService).isSatelliteProvisionedForNonIpDatagram( 1783 anyInt()); 1784 1785 String mText = "This is test provision data."; 1786 byte[] testProvisionData = mText.getBytes(); 1787 CancellationSignal cancellationSignal = new CancellationSignal(); 1788 ICancellationSignal cancelRemote = null; 1789 mIIntegerConsumerResults.clear(); 1790 cancelRemote = mSatelliteControllerUT.provisionSatelliteService( 1791 TEST_SATELLITE_TOKEN, 1792 testProvisionData, mIIntegerConsumer); 1793 processAllMessages(); 1794 assertTrue(waitForForEvents( 1795 semaphore, 1, "testRegisterForSatelliteProvisionStateChanged")); 1796 mSatelliteControllerUT.unregisterForSatelliteProvisionStateChanged(callback); 1797 semaphore.drainPermits(); 1798 cancelRemote = mSatelliteControllerUT.provisionSatelliteService( 1799 TEST_SATELLITE_TOKEN, 1800 testProvisionData, mIIntegerConsumer); 1801 processAllMessages(); 1802 assertFalse(waitForForEvents( 1803 semaphore, 1, "testRegisterForSatelliteProvisionStateChanged")); 1804 } 1805 1806 @Test testRegisterForSatelliteDatagram()1807 public void testRegisterForSatelliteDatagram() { 1808 ISatelliteDatagramCallback callback = 1809 new ISatelliteDatagramCallback.Stub() { 1810 @Override 1811 public void onSatelliteDatagramReceived(long datagramId, 1812 @NonNull SatelliteDatagram datagram, int pendingCount, 1813 @NonNull IVoidConsumer internalAck) { 1814 logd("onSatelliteDatagramReceived"); 1815 } 1816 }; 1817 when(mMockDatagramController.registerForSatelliteDatagram(anyInt(), eq(callback))) 1818 .thenReturn(SATELLITE_RESULT_SUCCESS); 1819 int errorCode = mSatelliteControllerUT.registerForIncomingDatagram(callback); 1820 assertEquals(SATELLITE_RESULT_SUCCESS, errorCode); 1821 verify(mMockDatagramController).registerForSatelliteDatagram(anyInt(), eq(callback)); 1822 } 1823 1824 @Test testUnregisterForSatelliteDatagram()1825 public void testUnregisterForSatelliteDatagram() { 1826 ISatelliteDatagramCallback callback = 1827 new ISatelliteDatagramCallback.Stub() { 1828 @Override 1829 public void onSatelliteDatagramReceived(long datagramId, 1830 @NonNull SatelliteDatagram datagram, int pendingCount, 1831 @NonNull IVoidConsumer internalAck) { 1832 logd("onSatelliteDatagramReceived"); 1833 } 1834 }; 1835 doNothing().when(mMockDatagramController) 1836 .unregisterForSatelliteDatagram(anyInt(), eq(callback)); 1837 mSatelliteControllerUT.unregisterForIncomingDatagram(callback); 1838 verify(mMockDatagramController).unregisterForSatelliteDatagram(anyInt(), eq(callback)); 1839 } 1840 1841 @Test testSendSatelliteDatagram()1842 public void testSendSatelliteDatagram() { 1843 String mText = "This is a test datagram message from user"; 1844 SatelliteDatagram datagram = new SatelliteDatagram(mText.getBytes()); 1845 1846 int[] sosDatagramTypes = {SatelliteManager.DATAGRAM_TYPE_SOS_MESSAGE, 1847 SatelliteManager.DATAGRAM_TYPE_LAST_SOS_MESSAGE_STILL_NEED_HELP, 1848 SatelliteManager.DATAGRAM_TYPE_LAST_SOS_MESSAGE_NO_HELP_NEEDED}; 1849 for (int datagramType : sosDatagramTypes) { 1850 mSatelliteControllerUT = 1851 new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); 1852 mIIntegerConsumerSemaphore.drainPermits(); 1853 mIIntegerConsumerResults.clear(); 1854 clearInvocations(mMockDatagramController); 1855 clearInvocations(mMockPointingAppController); 1856 1857 mSatelliteControllerUT.sendDatagram(datagramType, datagram, true, 1858 mIIntegerConsumer); 1859 processAllMessages(); 1860 assertTrue(waitForIIntegerConsumerResult(1)); 1861 assertEquals(SATELLITE_RESULT_INVALID_TELEPHONY_STATE, 1862 (long) mIIntegerConsumerResults.get(0)); 1863 verify(mMockDatagramController, never()).sendSatelliteDatagram(anyInt(), 1864 eq(datagramType), eq(datagram), eq(true), any()); 1865 1866 mIIntegerConsumerResults.clear(); 1867 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1868 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1869 setProvisionedState(false); 1870 processAllMessages(); 1871 verifySatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 1872 mSatelliteControllerUT.sendDatagram(datagramType, datagram, true, 1873 mIIntegerConsumer); 1874 processAllMessages(); 1875 assertTrue(waitForIIntegerConsumerResult(1)); 1876 assertEquals(SATELLITE_RESULT_SERVICE_NOT_PROVISIONED, 1877 (long) mIIntegerConsumerResults.get(0)); 1878 verify(mMockDatagramController, never()).sendSatelliteDatagram(anyInt(), 1879 eq(datagramType), eq(datagram), eq(true), any()); 1880 1881 mIIntegerConsumerResults.clear(); 1882 setProvisionedState(true); 1883 processAllMessages(); 1884 verifySatelliteProvisioned(true, SATELLITE_RESULT_SUCCESS); 1885 mSatelliteControllerUT.sendDatagram(datagramType, datagram, true, 1886 mIIntegerConsumer); 1887 processAllMessages(); 1888 assertFalse(waitForIIntegerConsumerResult(1)); 1889 verify(mMockDatagramController, times(1)).sendSatelliteDatagram(anyInt(), 1890 eq(datagramType), eq(datagram), eq(true), any()); 1891 verify(mMockPointingAppController, times(1)).startPointingUI(eq(true), anyBoolean(), 1892 anyBoolean()); 1893 } 1894 } 1895 1896 @Test testPollPendingSatelliteDatagrams()1897 public void testPollPendingSatelliteDatagrams() { 1898 mIIntegerConsumerResults.clear(); 1899 mSatelliteControllerUT.pollPendingDatagrams(mIIntegerConsumer); 1900 processAllMessages(); 1901 assertTrue(waitForIIntegerConsumerResult(1)); 1902 assertEquals(SATELLITE_RESULT_INVALID_TELEPHONY_STATE, 1903 (long) mIIntegerConsumerResults.get(0)); 1904 verify(mMockDatagramController, never()).pollPendingSatelliteDatagrams(anyInt(), any()); 1905 1906 mIIntegerConsumerResults.clear(); 1907 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1908 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1909 setProvisionedState(false); 1910 processAllMessages(); 1911 verifySatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 1912 mSatelliteControllerUT.pollPendingDatagrams(mIIntegerConsumer); 1913 processAllMessages(); 1914 assertTrue(waitForIIntegerConsumerResult(1)); 1915 assertEquals(SATELLITE_RESULT_SERVICE_NOT_PROVISIONED, 1916 (long) mIIntegerConsumerResults.get(0)); 1917 verify(mMockDatagramController, never()).pollPendingSatelliteDatagrams(anyInt(), any()); 1918 1919 mIIntegerConsumerResults.clear(); 1920 setProvisionedState(true); 1921 processAllMessages(); 1922 verifySatelliteProvisioned(true, SATELLITE_RESULT_SUCCESS); 1923 mSatelliteControllerUT.pollPendingDatagrams(mIIntegerConsumer); 1924 processAllMessages(); 1925 assertFalse(waitForIIntegerConsumerResult(1)); 1926 verify(mMockDatagramController, times(1)).pollPendingSatelliteDatagrams(anyInt(), any()); 1927 } 1928 1929 @Test testProvisionSatelliteService()1930 public void testProvisionSatelliteService() { 1931 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(false); 1932 1933 String mText = "This is test provision data."; 1934 byte[] testProvisionData = mText.getBytes(); 1935 CancellationSignal cancellationSignal = new CancellationSignal(); 1936 ICancellationSignal cancelRemote = null; 1937 mIIntegerConsumerResults.clear(); 1938 cancelRemote = mSatelliteControllerUT.provisionSatelliteService( 1939 TEST_SATELLITE_TOKEN, 1940 testProvisionData, mIIntegerConsumer); 1941 processAllMessages(); 1942 assertTrue(waitForIIntegerConsumerResult(1)); 1943 assertEquals(SATELLITE_RESULT_INVALID_TELEPHONY_STATE, 1944 (long) mIIntegerConsumerResults.get(0)); 1945 assertNull(cancelRemote); 1946 1947 resetSatelliteControllerUT(); 1948 mIIntegerConsumerResults.clear(); 1949 setUpResponseForRequestIsSatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 1950 verifySatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 1951 cancelRemote = mSatelliteControllerUT.provisionSatelliteService( 1952 TEST_SATELLITE_TOKEN, 1953 testProvisionData, mIIntegerConsumer); 1954 processAllMessages(); 1955 assertTrue(waitForIIntegerConsumerResult(1)); 1956 assertEquals(SATELLITE_RESULT_NOT_SUPPORTED, (long) mIIntegerConsumerResults.get(0)); 1957 assertNull(cancelRemote); 1958 1959 resetSatelliteControllerUT(); 1960 mIIntegerConsumerResults.clear(); 1961 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1962 setUpResponseForRequestIsSatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 1963 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1964 verifySatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 1965 cancelRemote = mSatelliteControllerUT.provisionSatelliteService( 1966 TEST_SATELLITE_TOKEN, 1967 testProvisionData, mIIntegerConsumer); 1968 processAllMessages(); 1969 assertTrue(waitForIIntegerConsumerResult(1)); 1970 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 1971 assertNotNull(cancelRemote); 1972 verifySatelliteProvisioned(true, SATELLITE_RESULT_SUCCESS); 1973 1974 // Send provision request again after the device is successfully provisioned 1975 cancelRemote = mSatelliteControllerUT.provisionSatelliteService( 1976 TEST_SATELLITE_TOKEN, 1977 testProvisionData, mIIntegerConsumer); 1978 processAllMessages(); 1979 assertTrue(waitForIIntegerConsumerResult(1)); 1980 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 1981 assertNull(cancelRemote); 1982 1983 resetSatelliteControllerUT(); 1984 mIIntegerConsumerResults.clear(); 1985 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1986 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 1987 setUpResponseForRequestIsSatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 1988 verifySatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 1989 cancelRemote = mSatelliteControllerUT.provisionSatelliteService( 1990 TEST_NEXT_SATELLITE_TOKEN, testProvisionData, mIIntegerConsumer); 1991 cancellationSignal.setRemote(cancelRemote); 1992 cancellationSignal.cancel(); 1993 processAllMessages(); 1994 assertTrue(waitForIIntegerConsumerResult(1)); 1995 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 1996 1997 resetSatelliteControllerUT(); 1998 mIIntegerConsumerResults.clear(); 1999 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 2000 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 2001 setUpResponseForRequestIsSatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 2002 verifySatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 2003 cancelRemote = mSatelliteControllerUT.provisionSatelliteService( 2004 TEST_SATELLITE_TOKEN, 2005 testProvisionData, mIIntegerConsumer); 2006 cancelRemote = mSatelliteControllerUT.provisionSatelliteService( 2007 TEST_NEXT_SATELLITE_TOKEN, 2008 testProvisionData, mIIntegerConsumer); 2009 processAllMessages(); 2010 assertTrue(waitForIIntegerConsumerResult(1)); 2011 assertEquals(SATELLITE_RESULT_SERVICE_PROVISION_IN_PROGRESS, 2012 (long) mIIntegerConsumerResults.get(0)); 2013 } 2014 2015 @Test testDeprovisionSatelliteService()2016 public void testDeprovisionSatelliteService() { 2017 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(false); 2018 mIIntegerConsumerSemaphore.drainPermits(); 2019 mIIntegerConsumerResults.clear(); 2020 setUpResponseForRequestIsSatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 2021 verifySatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 2022 mSatelliteControllerUT.deprovisionSatelliteService( 2023 TEST_SATELLITE_TOKEN, mIIntegerConsumer); 2024 processAllMessages(); 2025 assertTrue(waitForIIntegerConsumerResult(1)); 2026 assertEquals(SATELLITE_RESULT_NOT_SUPPORTED, (long) mIIntegerConsumerResults.get(0)); 2027 2028 resetSatelliteControllerUT(); 2029 mIIntegerConsumerResults.clear(); 2030 mSatelliteControllerUT.deprovisionSatelliteService( 2031 TEST_SATELLITE_TOKEN, mIIntegerConsumer); 2032 processAllMessages(); 2033 assertTrue(waitForIIntegerConsumerResult(1)); 2034 assertEquals(SATELLITE_RESULT_INVALID_TELEPHONY_STATE, 2035 (long) mIIntegerConsumerResults.get(0)); 2036 2037 resetSatelliteControllerUT(); 2038 mIIntegerConsumerResults.clear(); 2039 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 2040 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 2041 mSatelliteControllerUT.deprovisionSatelliteService( 2042 TEST_SATELLITE_TOKEN, mIIntegerConsumer); 2043 processAllMessages(); 2044 assertTrue(waitForIIntegerConsumerResult(1)); 2045 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 2046 2047 resetSatelliteControllerUT(); 2048 mIIntegerConsumerResults.clear(); 2049 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 2050 setUpResponseForRequestIsSatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 2051 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 2052 verifySatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 2053 mSatelliteControllerUT.deprovisionSatelliteService( 2054 TEST_SATELLITE_TOKEN, mIIntegerConsumer); 2055 processAllMessages(); 2056 assertTrue(waitForIIntegerConsumerResult(1)); 2057 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 2058 2059 resetSatelliteControllerUT(); 2060 provisionSatelliteService(); 2061 mIIntegerConsumerResults.clear(); 2062 mSatelliteControllerUT.deprovisionSatelliteService( 2063 TEST_SATELLITE_TOKEN, mIIntegerConsumer); 2064 processAllMessages(); 2065 assertTrue(waitForIIntegerConsumerResult(1)); 2066 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 2067 verifySatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 2068 2069 resetSatelliteControllerUT(); 2070 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 2071 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 2072 setProvisionedState(null); 2073 mIIntegerConsumerResults.clear(); 2074 mSatelliteControllerUT.deprovisionSatelliteService( 2075 TEST_SATELLITE_TOKEN, mIIntegerConsumer); 2076 processAllMessages(); 2077 assertTrue(waitForIIntegerConsumerResult(1)); 2078 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 2079 verifySatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 2080 } 2081 2082 @Test testSupportedSatelliteServices()2083 public void testSupportedSatelliteServices() throws Exception { 2084 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(false); 2085 List<String> satellitePlmnList = mSatelliteControllerUT.getSatellitePlmnsForCarrier( 2086 SUB_ID); 2087 assertEquals(EMPTY_STRING_ARRAY.length, satellitePlmnList.size()); 2088 List<Integer> supportedSatelliteServices = 2089 mSatelliteControllerUT.getSupportedSatelliteServicesForPlmn(SUB_ID, "00101"); 2090 assertTrue(supportedSatelliteServices.isEmpty()); 2091 2092 String[] satelliteProviderStrArray = {"00101", "00102"}; 2093 mContextFixture.putStringArrayResource( 2094 R.array.config_satellite_providers, satelliteProviderStrArray); 2095 int[] expectedSupportedServices2 = {2}; 2096 int[] expectedSupportedServices3 = {1, 3}; 2097 int[] defaultSupportedServices = {5, 6}; 2098 PersistableBundle carrierSupportedSatelliteServicesPerProvider = new PersistableBundle(); 2099 carrierSupportedSatelliteServicesPerProvider.putIntArray( 2100 "00102", expectedSupportedServices2); 2101 carrierSupportedSatelliteServicesPerProvider.putIntArray( 2102 "00103", expectedSupportedServices3); 2103 String[] expectedSupportedSatellitePlmns = {"00102", "00103"}; 2104 mCarrierConfigBundle.putPersistableBundle(CarrierConfigManager 2105 .KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE, 2106 carrierSupportedSatelliteServicesPerProvider); 2107 mCarrierConfigBundle.putIntArray( 2108 CarrierConfigManager.KEY_CARRIER_ROAMING_SATELLITE_DEFAULT_SERVICES_INT_ARRAY, 2109 defaultSupportedServices); 2110 TestSatelliteController testSatelliteController = 2111 new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); 2112 2113 satellitePlmnList = testSatelliteController.getSatellitePlmnsForCarrier(SUB_ID); 2114 assertTrue(satellitePlmnList.isEmpty()); 2115 supportedSatelliteServices = 2116 testSatelliteController.getSupportedSatelliteServicesForPlmn(SUB_ID, "00101"); 2117 assertTrue(supportedSatelliteServices.isEmpty()); 2118 2119 // Add entitlement provided PLMNs. 2120 setEntitlementPlmnList(testSatelliteController, SUB_ID, 2121 Arrays.asList("00102", "00104", "00105")); 2122 // Carrier config changed with carrierEnabledSatelliteFlag disabled 2123 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 2124 : mCarrierConfigChangedListenerList) { 2125 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 2126 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 2127 ); 2128 } 2129 processAllMessages(); 2130 2131 supportedSatelliteServices = 2132 testSatelliteController.getSupportedSatelliteServicesForPlmn(SUB_ID, "00102"); 2133 assertTrue(supportedSatelliteServices.isEmpty()); 2134 supportedSatelliteServices = 2135 testSatelliteController.getSupportedSatelliteServicesForPlmn(SUB_ID, "00103"); 2136 assertTrue(supportedSatelliteServices.isEmpty()); 2137 supportedSatelliteServices = 2138 testSatelliteController.getSupportedSatelliteServicesForPlmn(SUB_ID, "00104"); 2139 assertTrue(supportedSatelliteServices.isEmpty()); 2140 supportedSatelliteServices = 2141 testSatelliteController.getSupportedSatelliteServicesForPlmn(SUB_ID, "00105"); 2142 assertTrue(supportedSatelliteServices.isEmpty()); 2143 2144 // Trigger carrier config changed with carrierEnabledSatelliteFlag enabled 2145 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 2146 mCarrierConfigBundle.putBoolean(CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, 2147 true); 2148 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 2149 : mCarrierConfigChangedListenerList) { 2150 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 2151 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 2152 ); 2153 } 2154 processAllMessages(); 2155 2156 satellitePlmnList = testSatelliteController.getSatellitePlmnsForCarrier(SUB_ID); 2157 assertTrue(Arrays.equals( 2158 expectedSupportedSatellitePlmns, satellitePlmnList.stream().toArray())); 2159 supportedSatelliteServices = 2160 mSatelliteControllerUT.getSupportedSatelliteServicesForPlmn(SUB_ID, "00102"); 2161 // "00101" should return carrier config assigned value, though it is in allowed list. 2162 assertTrue(Arrays.equals(expectedSupportedServices2, 2163 supportedSatelliteServices.stream() 2164 .mapToInt(Integer::intValue) 2165 .toArray())); 2166 supportedSatelliteServices = 2167 mSatelliteControllerUT.getSupportedSatelliteServicesForPlmn(SUB_ID, "00103"); 2168 assertTrue(Arrays.equals(expectedSupportedServices3, 2169 supportedSatelliteServices.stream() 2170 .mapToInt(Integer::intValue) 2171 .toArray())); 2172 // "00104", and "00105" should return default supported service. 2173 supportedSatelliteServices = 2174 testSatelliteController.getSupportedSatelliteServicesForPlmn(SUB_ID, "00104"); 2175 assertTrue(Arrays.equals(defaultSupportedServices, 2176 supportedSatelliteServices.stream() 2177 .mapToInt(Integer::intValue) 2178 .toArray())); 2179 supportedSatelliteServices = 2180 testSatelliteController.getSupportedSatelliteServicesForPlmn(SUB_ID, "00105"); 2181 assertTrue(Arrays.equals(defaultSupportedServices, 2182 supportedSatelliteServices.stream() 2183 .mapToInt(Integer::intValue) 2184 .toArray())); 2185 2186 // Subscriptions changed 2187 int[] newActiveSubIds = {SUB_ID1}; 2188 doReturn(newActiveSubIds).when(mMockSubscriptionManagerService).getActiveSubIdList(true); 2189 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 2190 : mCarrierConfigChangedListenerList) { 2191 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 2192 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 2193 ); 2194 } 2195 processAllMessages(); 2196 2197 satellitePlmnList = testSatelliteController.getSatellitePlmnsForCarrier(SUB_ID); 2198 assertTrue(satellitePlmnList.isEmpty()); 2199 // "00102" and "00103" should return default supported service for SUB_ID. 2200 supportedSatelliteServices = 2201 testSatelliteController.getSupportedSatelliteServicesForPlmn(SUB_ID, "00102"); 2202 assertTrue(Arrays.equals(defaultSupportedServices, 2203 supportedSatelliteServices.stream() 2204 .mapToInt(Integer::intValue) 2205 .toArray())); 2206 supportedSatelliteServices = 2207 testSatelliteController.getSupportedSatelliteServicesForPlmn(SUB_ID, "00103"); 2208 assertTrue(Arrays.equals(defaultSupportedServices, 2209 supportedSatelliteServices.stream() 2210 .mapToInt(Integer::intValue) 2211 .toArray())); 2212 // "00104", and "00105" should return default supported service for SUB_ID. 2213 supportedSatelliteServices = 2214 testSatelliteController.getSupportedSatelliteServicesForPlmn(SUB_ID, "00104"); 2215 assertTrue(Arrays.equals(defaultSupportedServices, 2216 supportedSatelliteServices.stream() 2217 .mapToInt(Integer::intValue) 2218 .toArray())); 2219 supportedSatelliteServices = 2220 testSatelliteController.getSupportedSatelliteServicesForPlmn(SUB_ID, "00105"); 2221 assertTrue(Arrays.equals(defaultSupportedServices, 2222 supportedSatelliteServices.stream() 2223 .mapToInt(Integer::intValue) 2224 .toArray())); 2225 2226 supportedSatelliteServices = 2227 testSatelliteController.getSupportedSatelliteServicesForPlmn(SUB_ID1, "00102"); 2228 assertNotNull(supportedSatelliteServices); 2229 assertTrue(Arrays.equals(expectedSupportedServices2, 2230 supportedSatelliteServices.stream() 2231 .mapToInt(Integer::intValue) 2232 .toArray())); 2233 2234 supportedSatelliteServices = 2235 testSatelliteController.getSupportedSatelliteServicesForPlmn(SUB_ID1, "00103"); 2236 assertTrue(Arrays.equals(expectedSupportedServices3, 2237 supportedSatelliteServices.stream() 2238 .mapToInt(Integer::intValue) 2239 .toArray())); 2240 /* "00104", and "00105" should return default supported service. */ 2241 supportedSatelliteServices = 2242 testSatelliteController.getSupportedSatelliteServicesForPlmn(SUB_ID1, "00104"); 2243 assertTrue(Arrays.equals(defaultSupportedServices, 2244 supportedSatelliteServices.stream() 2245 .mapToInt(Integer::intValue) 2246 .toArray())); 2247 supportedSatelliteServices = 2248 testSatelliteController.getSupportedSatelliteServicesForPlmn(SUB_ID1, "00105"); 2249 assertTrue(Arrays.equals(defaultSupportedServices, 2250 supportedSatelliteServices.stream() 2251 .mapToInt(Integer::intValue) 2252 .toArray())); 2253 } 2254 2255 @Test testConfigureSatellitePlmnOnCarrierConfigChanged()2256 public void testConfigureSatellitePlmnOnCarrierConfigChanged() { 2257 logd("testConfigureSatellitePlmnOnCarrierConfigChanged"); 2258 2259 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(false); 2260 String[] satelliteProviderStrArray = 2261 {"00101", "00102", "00103", "00104", "00105"}; 2262 List<String> satellitePlmnListFromOverlayConfig = 2263 Arrays.stream(satelliteProviderStrArray).toList(); 2264 mContextFixture.putStringArrayResource( 2265 R.array.config_satellite_providers, satelliteProviderStrArray); 2266 2267 /* Initially, the radio state is ON. In the constructor, satelliteController registers for 2268 the radio state changed events and immediately gets the radio state changed event as ON. */ 2269 doReturn(false).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2270 mCarrierConfigChangedListenerList.clear(); 2271 TestSatelliteController testSatelliteController = 2272 new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); 2273 processAllMessages(); 2274 List<String> carrierPlmnList = testSatelliteController.getSatellitePlmnsForCarrier( 2275 SUB_ID); 2276 verify(mMockSatelliteModemInterface, never()).setSatellitePlmn( 2277 anyInt(), anyList(), anyList(), any(Message.class)); 2278 assertTrue(carrierPlmnList.isEmpty()); 2279 reset(mMockSatelliteModemInterface); 2280 2281 // Test setSatellitePlmn() when Carrier Config change event triggered. 2282 mCarrierConfigBundle.putBoolean(CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, 2283 true); 2284 int[] supportedServices2 = {2}; 2285 int[] supportedServices3 = {1, 3}; 2286 PersistableBundle carrierSupportedSatelliteServicesPerProvider = new PersistableBundle(); 2287 carrierSupportedSatelliteServicesPerProvider.putIntArray( 2288 "00102", supportedServices2); 2289 carrierSupportedSatelliteServicesPerProvider.putIntArray( 2290 "00103", supportedServices3); 2291 List<String> expectedCarrierPlmnList = Arrays.asList("00102", "00103"); 2292 mCarrierConfigBundle.putPersistableBundle(CarrierConfigManager 2293 .KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE, 2294 carrierSupportedSatelliteServicesPerProvider); 2295 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 2296 : mCarrierConfigChangedListenerList) { 2297 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 2298 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 2299 ); 2300 } 2301 processAllMessages(); 2302 carrierPlmnList = testSatelliteController.getSatellitePlmnsForCarrier(SUB_ID); 2303 verify(mMockSatelliteModemInterface, never()).setSatellitePlmn( 2304 anyInt(), anyList(), anyList(), any(Message.class)); 2305 assertTrue(carrierPlmnList.isEmpty()); 2306 reset(mMockSatelliteModemInterface); 2307 2308 // Reset TestSatelliteController so that device satellite PLMNs is loaded when 2309 // carrierEnabledSatelliteFlag is enabled. 2310 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 2311 mCarrierConfigChangedListenerList.clear(); 2312 testSatelliteController = 2313 new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); 2314 2315 // Trigger carrier config changed with carrierEnabledSatelliteFlag enabled and empty 2316 // carrier supported satellite services. 2317 mCarrierConfigBundle.putPersistableBundle(CarrierConfigManager 2318 .KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE, 2319 new PersistableBundle()); 2320 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 2321 : mCarrierConfigChangedListenerList) { 2322 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 2323 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 2324 ); 2325 } 2326 processAllMessages(); 2327 2328 carrierPlmnList = testSatelliteController.getSatellitePlmnsForCarrier(SUB_ID); 2329 assertTrue(carrierPlmnList.isEmpty()); 2330 List<String> allSatellitePlmnList = SatelliteServiceUtils.mergeStrLists( 2331 carrierPlmnList, satellitePlmnListFromOverlayConfig); 2332 verify(mMockSatelliteModemInterface, times(1)).setSatellitePlmn(anyInt(), 2333 eq(EMPTY_STRING_LIST), eq(allSatellitePlmnList), any(Message.class)); 2334 reset(mMockSatelliteModemInterface); 2335 2336 // Trigger carrier config changed with carrierEnabledSatelliteFlag enabled and non-empty 2337 // carrier supported satellite services. 2338 mCarrierConfigBundle.putPersistableBundle(CarrierConfigManager 2339 .KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE, 2340 carrierSupportedSatelliteServicesPerProvider); 2341 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 2342 : mCarrierConfigChangedListenerList) { 2343 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 2344 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 2345 ); 2346 } 2347 processAllMessages(); 2348 carrierPlmnList = testSatelliteController.getSatellitePlmnsForCarrier(SUB_ID); 2349 allSatellitePlmnList = SatelliteServiceUtils.mergeStrLists( 2350 carrierPlmnList, satellitePlmnListFromOverlayConfig); 2351 assertEquals(expectedCarrierPlmnList, carrierPlmnList); 2352 verify(mMockSatelliteModemInterface, times(1)).setSatellitePlmn(anyInt(), 2353 eq(carrierPlmnList), eq(allSatellitePlmnList), any(Message.class)); 2354 reset(mMockSatelliteModemInterface); 2355 2356 /* setSatellitePlmn() is called regardless whether satellite attach for carrier is 2357 supported. */ 2358 mCarrierConfigBundle.putBoolean(CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, 2359 false); 2360 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 2361 : mCarrierConfigChangedListenerList) { 2362 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 2363 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 2364 ); 2365 } 2366 processAllMessages(); 2367 verify(mMockSatelliteModemInterface, times(1)).setSatellitePlmn(anyInt(), 2368 eq(carrierPlmnList), eq(allSatellitePlmnList), any(Message.class)); 2369 reset(mMockSatelliteModemInterface); 2370 2371 // Test empty config_satellite_providers and empty carrier PLMN list 2372 mCarrierConfigChangedListenerList.clear(); 2373 mContextFixture.putStringArrayResource( 2374 R.array.config_satellite_providers, EMPTY_STRING_ARRAY); 2375 testSatelliteController = 2376 new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); 2377 mCarrierConfigBundle.putPersistableBundle(CarrierConfigManager 2378 .KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE, 2379 new PersistableBundle()); 2380 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 2381 : mCarrierConfigChangedListenerList) { 2382 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 2383 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 2384 ); 2385 } 2386 processAllMessages(); 2387 carrierPlmnList = testSatelliteController.getSatellitePlmnsForCarrier(SUB_ID); 2388 assertTrue(carrierPlmnList.isEmpty()); 2389 verify(mMockSatelliteModemInterface, times(1)).setSatellitePlmn(anyInt(), 2390 eq(EMPTY_STRING_LIST), eq(EMPTY_STRING_LIST), any(Message.class)); 2391 reset(mMockSatelliteModemInterface); 2392 } 2393 2394 @Test testSatelliteCommunicationRestriction()2395 public void testSatelliteCommunicationRestriction() { 2396 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 2397 mCarrierConfigBundle.putBoolean( 2398 CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, true); 2399 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 2400 : mCarrierConfigChangedListenerList) { 2401 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 2402 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 2403 ); 2404 } 2405 processAllMessages(); 2406 2407 // Remove restriction reason if exist 2408 mIIntegerConsumerResults.clear(); 2409 reset(mMockSatelliteModemInterface); 2410 setUpResponseForRequestSetSatelliteEnabledForCarrier(true, SATELLITE_RESULT_SUCCESS); 2411 setUpResponseForRequestSetSatelliteEnabledForCarrier(false, SATELLITE_RESULT_SUCCESS); 2412 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2413 mSatelliteControllerUT.removeAttachRestrictionForCarrier(SUB_ID, 2414 SATELLITE_COMMUNICATION_RESTRICTION_REASON_USER, mIIntegerConsumer); 2415 mSatelliteControllerUT.removeAttachRestrictionForCarrier(SUB_ID, 2416 SATELLITE_COMMUNICATION_RESTRICTION_REASON_GEOLOCATION, mIIntegerConsumer); 2417 processAllMessages(); 2418 assertTrue(waitForIIntegerConsumerResult(2)); 2419 2420 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 2421 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(1)); 2422 2423 Set<Integer> restrictionSet = 2424 mSatelliteControllerUT.getAttachRestrictionReasonsForCarrier(SUB_ID); 2425 assertTrue(!restrictionSet.contains(SATELLITE_COMMUNICATION_RESTRICTION_REASON_USER)); 2426 assertTrue(!restrictionSet.contains( 2427 SATELLITE_COMMUNICATION_RESTRICTION_REASON_GEOLOCATION)); 2428 2429 // Add satellite attach restriction reason by user 2430 mIIntegerConsumerResults.clear(); 2431 reset(mMockSatelliteModemInterface); 2432 setUpResponseForRequestSetSatelliteEnabledForCarrier(false, SATELLITE_RESULT_SUCCESS); 2433 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2434 mSatelliteControllerUT.addAttachRestrictionForCarrier(SUB_ID, 2435 SATELLITE_COMMUNICATION_RESTRICTION_REASON_USER, mIIntegerConsumer); 2436 processAllMessages(); 2437 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 2438 verify(mMockSatelliteModemInterface, never()) 2439 .requestSetSatelliteEnabledForCarrier(anyInt(), anyBoolean(), any(Message.class)); 2440 assertTrue(waitForIIntegerConsumerResult(1)); 2441 restrictionSet = 2442 mSatelliteControllerUT.getAttachRestrictionReasonsForCarrier(SUB_ID); 2443 assertTrue(restrictionSet.contains(SATELLITE_COMMUNICATION_RESTRICTION_REASON_USER)); 2444 2445 // remove satellite restriction reason by user 2446 mIIntegerConsumerResults.clear(); 2447 reset(mMockSatelliteModemInterface); 2448 setUpResponseForRequestSetSatelliteEnabledForCarrier(true, SATELLITE_RESULT_SUCCESS); 2449 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2450 mSatelliteControllerUT.removeAttachRestrictionForCarrier(SUB_ID, 2451 SATELLITE_COMMUNICATION_RESTRICTION_REASON_USER, mIIntegerConsumer); 2452 processAllMessages(); 2453 assertTrue(waitForIIntegerConsumerResult(1)); 2454 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 2455 restrictionSet = 2456 mSatelliteControllerUT.getAttachRestrictionReasonsForCarrier(SUB_ID); 2457 assertTrue(!restrictionSet.contains(SATELLITE_COMMUNICATION_RESTRICTION_REASON_USER)); 2458 verify(mMockSatelliteModemInterface, times(1)) 2459 .requestSetSatelliteEnabledForCarrier(anyInt(), anyBoolean(), any(Message.class)); 2460 2461 // Add satellite attach restriction reason by user 2462 mIIntegerConsumerResults.clear(); 2463 reset(mMockSatelliteModemInterface); 2464 setUpResponseForRequestSetSatelliteEnabledForCarrier(false, SATELLITE_RESULT_SUCCESS); 2465 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2466 mSatelliteControllerUT.addAttachRestrictionForCarrier(SUB_ID, 2467 SATELLITE_COMMUNICATION_RESTRICTION_REASON_USER, mIIntegerConsumer); 2468 processAllMessages(); 2469 assertTrue(waitForIIntegerConsumerResult(1)); 2470 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 2471 restrictionSet = 2472 mSatelliteControllerUT.getAttachRestrictionReasonsForCarrier(SUB_ID); 2473 assertTrue(restrictionSet.contains(SATELLITE_COMMUNICATION_RESTRICTION_REASON_USER)); 2474 verify(mMockSatelliteModemInterface, times(1)) 2475 .requestSetSatelliteEnabledForCarrier(anyInt(), eq(false), any(Message.class)); 2476 2477 // add satellite attach restriction reason by geolocation 2478 mIIntegerConsumerResults.clear(); 2479 reset(mMockSatelliteModemInterface); 2480 setUpResponseForRequestSetSatelliteEnabledForCarrier(false, SATELLITE_RESULT_SUCCESS); 2481 mSatelliteControllerUT.addAttachRestrictionForCarrier(SUB_ID, 2482 SATELLITE_COMMUNICATION_RESTRICTION_REASON_GEOLOCATION, mIIntegerConsumer); 2483 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2484 processAllMessages(); 2485 assertTrue(waitForIIntegerConsumerResult(1)); 2486 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 2487 restrictionSet = 2488 mSatelliteControllerUT.getAttachRestrictionReasonsForCarrier(SUB_ID); 2489 assertTrue(restrictionSet.contains(SATELLITE_COMMUNICATION_RESTRICTION_REASON_GEOLOCATION)); 2490 verify(mMockSatelliteModemInterface, never()) 2491 .requestSetSatelliteEnabledForCarrier(anyInt(), anyBoolean(), any(Message.class)); 2492 2493 // remove satellite attach restriction reason by geolocation 2494 mIIntegerConsumerResults.clear(); 2495 reset(mMockSatelliteModemInterface); 2496 setUpResponseForRequestSetSatelliteEnabledForCarrier(true, SATELLITE_RESULT_SUCCESS); 2497 mSatelliteControllerUT.removeAttachRestrictionForCarrier(SUB_ID, 2498 SATELLITE_COMMUNICATION_RESTRICTION_REASON_GEOLOCATION, mIIntegerConsumer); 2499 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2500 processAllMessages(); 2501 assertTrue(waitForIIntegerConsumerResult(1)); 2502 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 2503 restrictionSet = 2504 mSatelliteControllerUT.getAttachRestrictionReasonsForCarrier(SUB_ID); 2505 assertTrue(!restrictionSet.contains( 2506 SATELLITE_COMMUNICATION_RESTRICTION_REASON_GEOLOCATION)); 2507 verify(mMockSatelliteModemInterface, never()) 2508 .requestSetSatelliteEnabledForCarrier(anyInt(), anyBoolean(), any(Message.class)); 2509 2510 // remove satellite restriction reason by user 2511 mIIntegerConsumerResults.clear(); 2512 reset(mMockSatelliteModemInterface); 2513 setUpResponseForRequestSetSatelliteEnabledForCarrier(true, SATELLITE_RESULT_SUCCESS); 2514 mSatelliteControllerUT.removeAttachRestrictionForCarrier(SUB_ID, 2515 SATELLITE_COMMUNICATION_RESTRICTION_REASON_USER, mIIntegerConsumer); 2516 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2517 processAllMessages(); 2518 assertTrue(waitForIIntegerConsumerResult(1)); 2519 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 2520 restrictionSet = 2521 mSatelliteControllerUT.getAttachRestrictionReasonsForCarrier(SUB_ID); 2522 assertTrue(!restrictionSet.contains(SATELLITE_COMMUNICATION_RESTRICTION_REASON_USER)); 2523 verify(mMockSatelliteModemInterface, times(1)) 2524 .requestSetSatelliteEnabledForCarrier(anyInt(), eq(true), any(Message.class)); 2525 reset(mMockSatelliteModemInterface); 2526 2527 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(false); 2528 2529 mIIntegerConsumerResults.clear(); 2530 mSatelliteControllerUT.removeAttachRestrictionForCarrier(SUB_ID, 2531 SATELLITE_COMMUNICATION_RESTRICTION_REASON_USER, mIIntegerConsumer); 2532 processAllMessages(); 2533 assertTrue(waitForIIntegerConsumerResult(1)); 2534 assertEquals( 2535 SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, (long) mIIntegerConsumerResults.get(0)); 2536 verifyZeroInteractions(mMockSatelliteModemInterface); 2537 2538 mIIntegerConsumerResults.clear(); 2539 mSatelliteControllerUT.addAttachRestrictionForCarrier(SUB_ID, 2540 SATELLITE_COMMUNICATION_RESTRICTION_REASON_USER, mIIntegerConsumer); 2541 processAllMessages(); 2542 assertTrue(waitForIIntegerConsumerResult(1)); 2543 assertEquals( 2544 SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, (long) mIIntegerConsumerResults.get(0)); 2545 verifyZeroInteractions(mMockSatelliteModemInterface); 2546 2547 Set<Integer> satelliteRestrictionReasons = 2548 mSatelliteControllerUT.getAttachRestrictionReasonsForCarrier(SUB_ID); 2549 assertTrue(satelliteRestrictionReasons.isEmpty()); 2550 } 2551 2552 @Test testIsSatelliteAttachRequired()2553 public void testIsSatelliteAttachRequired() { 2554 TestSatelliteController satelliteController = 2555 new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); 2556 mSatelliteCapabilitiesSemaphore.drainPermits(); 2557 satelliteController.requestSatelliteCapabilities(mSatelliteCapabilitiesReceiver); 2558 processAllMessages(); 2559 assertTrue(waitForRequestSatelliteCapabilitiesResult(1)); 2560 assertEquals( 2561 SATELLITE_RESULT_INVALID_TELEPHONY_STATE, mQueriedSatelliteCapabilitiesResultCode); 2562 assertFalse(satelliteController.isSatelliteAttachRequired()); 2563 2564 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 2565 setUpResponseForRequestSatelliteCapabilities( 2566 mEmptySatelliteCapabilities, SATELLITE_RESULT_SUCCESS); 2567 satelliteController = 2568 new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); 2569 verifySatelliteSupported(satelliteController, true, SATELLITE_RESULT_SUCCESS); 2570 mSatelliteCapabilitiesSemaphore.drainPermits(); 2571 satelliteController.requestSatelliteCapabilities(mSatelliteCapabilitiesReceiver); 2572 processAllMessages(); 2573 assertTrue(waitForRequestSatelliteCapabilitiesResult(1)); 2574 assertEquals(SATELLITE_RESULT_SUCCESS, mQueriedSatelliteCapabilitiesResultCode); 2575 assertEquals(mEmptySatelliteCapabilities, mQueriedSatelliteCapabilities); 2576 assertEquals(SatelliteManager.NT_RADIO_TECHNOLOGY_UNKNOWN, 2577 mSatelliteControllerUT.getSupportedNtnRadioTechnology()); 2578 2579 assertFalse(satelliteController.isSatelliteAttachRequired()); 2580 2581 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 2582 setUpResponseForRequestSatelliteCapabilities( 2583 mSatelliteCapabilities, SATELLITE_RESULT_SUCCESS); 2584 satelliteController = 2585 new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); 2586 verifySatelliteSupported(satelliteController, true, SATELLITE_RESULT_SUCCESS); 2587 mSatelliteCapabilitiesSemaphore.drainPermits(); 2588 satelliteController.requestSatelliteCapabilities(mSatelliteCapabilitiesReceiver); 2589 processAllMessages(); 2590 assertTrue(waitForRequestSatelliteCapabilitiesResult(1)); 2591 assertEquals(SATELLITE_RESULT_SUCCESS, mQueriedSatelliteCapabilitiesResultCode); 2592 assertEquals(mSatelliteCapabilities, mQueriedSatelliteCapabilities); 2593 assertTrue( 2594 mQueriedSatelliteCapabilities.getSupportedRadioTechnologies().contains( 2595 satelliteController.getSupportedNtnRadioTechnology())); 2596 assertEquals(mQueriedSatelliteCapabilities.getMaxBytesPerOutgoingDatagram(), 255); 2597 assertTrue(satelliteController.isSatelliteAttachRequired()); 2598 2599 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(false); 2600 assertFalse(satelliteController.isSatelliteAttachRequired()); 2601 } 2602 2603 @Test testSatelliteModemStateChanged()2604 public void testSatelliteModemStateChanged() { 2605 clearInvocations(mMockSatelliteSessionController); 2606 clearInvocations(mMockDatagramController); 2607 sendSatelliteModemStateChangedEvent(SATELLITE_MODEM_STATE_CONNECTED, null); 2608 processAllMessages(); 2609 verify(mMockSatelliteSessionController, times(0)).onSatelliteModemStateChanged( 2610 SATELLITE_MODEM_STATE_CONNECTED); 2611 2612 resetSatelliteControllerUTToSupportedAndProvisionedState(); 2613 mSatelliteControllerUT.setSatelliteSessionController(mMockSatelliteSessionController); 2614 clearInvocations(mMockSatelliteSessionController); 2615 clearInvocations(mMockDatagramController); 2616 sendSatelliteModemStateChangedEvent(SATELLITE_MODEM_STATE_UNAVAILABLE, null); 2617 processAllMessages(); 2618 verify(mMockSatelliteSessionController, times(1)).onSatelliteModemStateChanged( 2619 eq(SATELLITE_MODEM_STATE_OFF)); 2620 2621 clearInvocations(mMockSatelliteSessionController); 2622 clearInvocations(mMockDatagramController); 2623 mSatelliteControllerUT.isSatelliteBeingDisabled = true; 2624 sendSatelliteModemStateChangedEvent(SATELLITE_MODEM_STATE_NOT_CONNECTED, null); 2625 processAllMessages(); 2626 verify(mMockSatelliteSessionController, times(1)).onSatelliteModemStateChanged( 2627 SATELLITE_MODEM_STATE_NOT_CONNECTED); 2628 2629 clearInvocations(mMockSatelliteSessionController); 2630 mSatelliteControllerUT.isSatelliteBeingDisabled = false; 2631 sendSatelliteModemStateChangedEvent(SATELLITE_MODEM_STATE_NOT_CONNECTED, null); 2632 processAllMessages(); 2633 verify(mMockSatelliteSessionController, never()).onSatelliteModemStateChanged( 2634 SATELLITE_MODEM_STATE_NOT_CONNECTED); 2635 } 2636 2637 @Test testRequestNtnSignalStrengthWithFeatureFlagEnabled()2638 public void testRequestNtnSignalStrengthWithFeatureFlagEnabled() { 2639 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(true); 2640 resetSatelliteControllerUT(); 2641 2642 mRequestNtnSignalStrengthSemaphore.drainPermits(); 2643 setUpResponseForRequestIsSatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 2644 verifySatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 2645 2646 @NtnSignalStrength.NtnSignalStrengthLevel int expectedLevel = NTN_SIGNAL_STRENGTH_GREAT; 2647 setUpResponseForRequestNtnSignalStrength(expectedLevel, SATELLITE_RESULT_SUCCESS); 2648 /* In case request is not successful, result should be NTN_SIGNAL_STRENGTH_NONE */ 2649 verifyRequestNtnSignalStrength(NTN_SIGNAL_STRENGTH_NONE, SATELLITE_RESULT_NOT_SUPPORTED); 2650 2651 resetSatelliteControllerUT(); 2652 provisionSatelliteService(); 2653 2654 doReturn(false).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2655 setUpResponseForRequestNtnSignalStrength(expectedLevel, SATELLITE_RESULT_SUCCESS); 2656 verifyRequestNtnSignalStrength(NTN_SIGNAL_STRENGTH_NONE, 2657 SATELLITE_RESULT_REQUEST_NOT_SUPPORTED); 2658 2659 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2660 setUpResponseForRequestNtnSignalStrength(expectedLevel, SATELLITE_RESULT_SUCCESS); 2661 verifyRequestNtnSignalStrength(expectedLevel, SATELLITE_RESULT_SUCCESS); 2662 2663 resetSatelliteControllerUT(); 2664 provisionSatelliteService(); 2665 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2666 // reset cache to NTN_SIGNAL_STRENGTH_NONE 2667 sendNtnSignalStrengthChangedEvent(NTN_SIGNAL_STRENGTH_NONE, null); 2668 processAllMessages(); 2669 expectedLevel = NTN_SIGNAL_STRENGTH_POOR; 2670 setUpResponseForRequestNtnSignalStrength(expectedLevel, SATELLITE_RESULT_SUCCESS); 2671 verifyRequestNtnSignalStrength(expectedLevel, SATELLITE_RESULT_SUCCESS); 2672 } 2673 2674 @Test testRequestNtnSignalStrengthWithFeatureFlagDisabled()2675 public void testRequestNtnSignalStrengthWithFeatureFlagDisabled() { 2676 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(false); 2677 2678 resetSatelliteControllerUT(); 2679 mRequestNtnSignalStrengthSemaphore.drainPermits(); 2680 doReturn(false).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2681 2682 @NtnSignalStrength.NtnSignalStrengthLevel int expectedLevel = NTN_SIGNAL_STRENGTH_GREAT; 2683 setUpResponseForRequestNtnSignalStrength(expectedLevel, SATELLITE_RESULT_SUCCESS); 2684 verifyRequestNtnSignalStrength(NTN_SIGNAL_STRENGTH_NONE, 2685 SATELLITE_RESULT_REQUEST_NOT_SUPPORTED); 2686 2687 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2688 setUpResponseForRequestNtnSignalStrength(expectedLevel, SATELLITE_RESULT_SUCCESS); 2689 verifyRequestNtnSignalStrength(NTN_SIGNAL_STRENGTH_NONE, 2690 SATELLITE_RESULT_REQUEST_NOT_SUPPORTED); 2691 2692 expectedLevel = NTN_SIGNAL_STRENGTH_POOR; 2693 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2694 setUpResponseForRequestNtnSignalStrength(expectedLevel, SATELLITE_RESULT_SUCCESS); 2695 verifyRequestNtnSignalStrength(NTN_SIGNAL_STRENGTH_NONE, 2696 SATELLITE_RESULT_REQUEST_NOT_SUPPORTED); 2697 2698 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2699 setUpResponseForRequestNtnSignalStrength(expectedLevel, SATELLITE_RESULT_MODEM_ERROR); 2700 verifyRequestNtnSignalStrength(NTN_SIGNAL_STRENGTH_NONE, 2701 SATELLITE_RESULT_REQUEST_NOT_SUPPORTED); 2702 } 2703 2704 @Test testRegisterForNtnSignalStrengthChangedWithFeatureFlagEnabled()2705 public void testRegisterForNtnSignalStrengthChangedWithFeatureFlagEnabled() { 2706 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(true); 2707 2708 Semaphore semaphore = new Semaphore(0); 2709 final NtnSignalStrength[] signalStrength = new NtnSignalStrength[1]; 2710 INtnSignalStrengthCallback callback = 2711 new INtnSignalStrengthCallback.Stub() { 2712 @Override 2713 public void onNtnSignalStrengthChanged(NtnSignalStrength ntnSignalStrength) { 2714 logd("onNtnSignalStrengthChanged: ntnSignalStrength=" 2715 + ntnSignalStrength); 2716 try { 2717 signalStrength[0] = ntnSignalStrength; 2718 semaphore.release(); 2719 } catch (Exception ex) { 2720 loge("onNtnSignalStrengthChanged: Got exception in releasing " 2721 + "semaphore, ex=" + ex); 2722 } 2723 } 2724 }; 2725 2726 verifyRegisterForNtnSignalStrengthChanged(SUB_ID, callback, 2727 SATELLITE_RESULT_INVALID_TELEPHONY_STATE); 2728 2729 setUpResponseForRequestIsSatelliteSupported(false, 2730 SATELLITE_RESULT_SUCCESS); 2731 verifySatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 2732 verifyRegisterForNtnSignalStrengthChanged(SUB_ID, callback, 2733 SATELLITE_RESULT_NOT_SUPPORTED); 2734 2735 @NtnSignalStrength.NtnSignalStrengthLevel int expectedLevel = NTN_SIGNAL_STRENGTH_NONE; 2736 verifyRequestNtnSignalStrength(expectedLevel, SATELLITE_RESULT_NOT_SUPPORTED); 2737 2738 resetSatelliteControllerUT(); 2739 setUpResponseForRequestNtnSignalStrength(expectedLevel, SATELLITE_RESULT_SUCCESS); 2740 provisionSatelliteService(); 2741 verifyRegisterForNtnSignalStrengthChanged(SUB_ID, callback, 2742 SATELLITE_RESULT_SUCCESS); 2743 verifyRequestNtnSignalStrength(expectedLevel, SATELLITE_RESULT_SUCCESS); 2744 processAllMessages(); 2745 assertTrue(waitForForEvents( 2746 semaphore, 1, "testRegisterForNtnSignalStrengthChanged")); 2747 assertEquals(expectedLevel, signalStrength[0].getLevel()); 2748 2749 expectedLevel = NTN_SIGNAL_STRENGTH_GOOD; 2750 sendNtnSignalStrengthChangedEvent(expectedLevel, null); 2751 processAllMessages(); 2752 assertTrue(waitForForEvents( 2753 semaphore, 1, "testRegisterForNtnSignalStrengthChanged")); 2754 assertEquals(expectedLevel, signalStrength[0].getLevel()); 2755 verifyRequestNtnSignalStrength(NTN_SIGNAL_STRENGTH_GOOD, SATELLITE_RESULT_SUCCESS); 2756 2757 expectedLevel = NTN_SIGNAL_STRENGTH_POOR; 2758 sendNtnSignalStrengthChangedEvent(expectedLevel, null); 2759 processAllMessages(); 2760 assertTrue(waitForForEvents( 2761 semaphore, 1, "testRegisterForNtnSignalStrengthChanged")); 2762 assertEquals(expectedLevel, signalStrength[0].getLevel()); 2763 verifyRequestNtnSignalStrength(NTN_SIGNAL_STRENGTH_POOR, SATELLITE_RESULT_SUCCESS); 2764 2765 mSatelliteControllerUT.unregisterForNtnSignalStrengthChanged(callback); 2766 sendNtnSignalStrengthChangedEvent(NTN_SIGNAL_STRENGTH_GREAT, null); 2767 processAllMessages(); 2768 assertFalse(waitForForEvents( 2769 semaphore, 1, "testRegisterForNtnSignalStrengthChanged")); 2770 /* Even if all listeners are unregistered, the cache is updated with the latest value when a 2771 new value event occurs. */ 2772 verifyRequestNtnSignalStrength(NTN_SIGNAL_STRENGTH_GREAT, SATELLITE_RESULT_SUCCESS); 2773 } 2774 2775 @Test testRegisterForNtnSignalStrengthChangedWithFeatureFlagDisabled()2776 public void testRegisterForNtnSignalStrengthChangedWithFeatureFlagDisabled() { 2777 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(false); 2778 2779 Semaphore semaphore = new Semaphore(0); 2780 final NtnSignalStrength[] signalStrength = new NtnSignalStrength[1]; 2781 INtnSignalStrengthCallback callback = 2782 new INtnSignalStrengthCallback.Stub() { 2783 @Override 2784 public void onNtnSignalStrengthChanged(NtnSignalStrength ntnSignalStrength) { 2785 logd("onNtnSignalStrengthChanged: ntnSignalStrength=" 2786 + ntnSignalStrength); 2787 try { 2788 signalStrength[0] = ntnSignalStrength; 2789 semaphore.release(); 2790 } catch (Exception ex) { 2791 loge("onNtnSignalStrengthChanged: Got exception in releasing " 2792 + "semaphore, ex=" + ex); 2793 } 2794 } 2795 }; 2796 2797 verifyRegisterForNtnSignalStrengthChanged(SUB_ID, callback, 2798 SATELLITE_RESULT_REQUEST_NOT_SUPPORTED); 2799 2800 setUpResponseForRequestIsSatelliteSupported(false, 2801 SATELLITE_RESULT_SUCCESS); 2802 verifySatelliteSupported(false, SATELLITE_RESULT_NOT_SUPPORTED); 2803 verifyRegisterForNtnSignalStrengthChanged(SUB_ID, callback, 2804 SATELLITE_RESULT_REQUEST_NOT_SUPPORTED); 2805 setUpResponseForRequestNtnSignalStrength(NTN_SIGNAL_STRENGTH_NONE, 2806 SATELLITE_RESULT_SUCCESS); 2807 verifyRequestNtnSignalStrength(NTN_SIGNAL_STRENGTH_NONE, 2808 SATELLITE_RESULT_REQUEST_NOT_SUPPORTED); 2809 2810 resetSatelliteControllerUT(); 2811 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 2812 verifySatelliteSupported(false, SATELLITE_RESULT_NOT_SUPPORTED); 2813 verifyRegisterForNtnSignalStrengthChanged(SUB_ID, callback, 2814 SATELLITE_RESULT_REQUEST_NOT_SUPPORTED); 2815 verifyRequestNtnSignalStrength(NTN_SIGNAL_STRENGTH_NONE, 2816 SATELLITE_RESULT_REQUEST_NOT_SUPPORTED); 2817 2818 @NtnSignalStrength.NtnSignalStrengthLevel int expectedNtnSignalStrengthLevel = 2819 NTN_SIGNAL_STRENGTH_GOOD; 2820 sendNtnSignalStrengthChangedEvent(expectedNtnSignalStrengthLevel, null); 2821 processAllMessages(); 2822 assertTrue(waitForForEvents( 2823 semaphore, 0, "testRegisterForNtnSignalStrengthChanged")); 2824 } 2825 2826 @Test testSendingNtnSignalStrengthWithFeatureEnabled()2827 public void testSendingNtnSignalStrengthWithFeatureEnabled() { 2828 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(true); 2829 2830 int expectedResult = SATELLITE_RESULT_SUCCESS; 2831 // startSendingNtnSignalStrength() is requested when screen on event comes. 2832 reset(mMockSatelliteModemInterface); 2833 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2834 provisionSatelliteService(); 2835 setUpResponseForStartSendingNtnSignalStrength(expectedResult); 2836 2837 // but it is ignored because satellite is disabled 2838 setUpResponseForRequestIsSatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); 2839 verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); 2840 sendCmdStartSendingNtnSignalStrengthChangedEvent(true); 2841 processAllMessages(); 2842 verify(mMockSatelliteModemInterface, never()) 2843 .startSendingNtnSignalStrength(any(Message.class)); 2844 2845 // after satellite is enabled, startSendingNtnSignalStrength() is requested normally 2846 resetSatelliteControllerUT(); 2847 reset(mMockSatelliteModemInterface); 2848 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2849 provisionSatelliteService(); 2850 setUpResponseForStartSendingNtnSignalStrength(expectedResult); 2851 setUpResponseForRequestIsSatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); 2852 verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); 2853 processAllMessages(); 2854 sendCmdStartSendingNtnSignalStrengthChangedEvent(true); 2855 processAllMessages(); 2856 verify(mMockSatelliteModemInterface, times(1)) 2857 .startSendingNtnSignalStrength(any(Message.class)); 2858 2859 // requested again but ignored as expected and current state are matched. 2860 setUpResponseForStartSendingNtnSignalStrength(expectedResult); 2861 sendCmdStartSendingNtnSignalStrengthChangedEvent(true); 2862 processAllMessages(); 2863 verify(mMockSatelliteModemInterface, times(1)) 2864 .startSendingNtnSignalStrength(any(Message.class)); 2865 2866 // stopSendingNtnSignalStrength() is requested when screen off event comes. 2867 reset(mMockSatelliteModemInterface); 2868 setUpResponseForRequestIsSatelliteProvisioned(true, SATELLITE_RESULT_SUCCESS); 2869 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 2870 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2871 setUpResponseForStopSendingNtnSignalStrength(expectedResult); 2872 sendCmdStartSendingNtnSignalStrengthChangedEvent(false); 2873 processAllMessages(); 2874 verify(mMockSatelliteModemInterface, times(1)) 2875 .stopSendingNtnSignalStrength(any(Message.class)); 2876 2877 // requested again but ignored as expected and current state are matched. 2878 setUpResponseForStopSendingNtnSignalStrength(expectedResult); 2879 sendCmdStartSendingNtnSignalStrengthChangedEvent(false); 2880 processAllMessages(); 2881 verify(mMockSatelliteModemInterface, times(1)) 2882 .stopSendingNtnSignalStrength(any(Message.class)); 2883 2884 // startSendingNtnSignalStrength() is requested but received fail from the service. 2885 reset(mMockSatelliteModemInterface); 2886 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2887 setUpResponseForStartSendingNtnSignalStrength(SATELLITE_RESULT_INVALID_MODEM_STATE); 2888 sendCmdStartSendingNtnSignalStrengthChangedEvent(true); 2889 processAllMessages(); 2890 verify(mMockSatelliteModemInterface, times(1)) 2891 .startSendingNtnSignalStrength(any(Message.class)); 2892 2893 /* stopSendingNtnSignalStrength() is ignored because startSendingNtnSignalStrength has 2894 failed thus current state is stopSendingNtnSignalStrength */ 2895 reset(mMockSatelliteModemInterface); 2896 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2897 setUpResponseForStopSendingNtnSignalStrength(SATELLITE_RESULT_NO_RESOURCES); 2898 sendCmdStartSendingNtnSignalStrengthChangedEvent(false); 2899 processAllMessages(); 2900 verify(mMockSatelliteModemInterface, never()) 2901 .stopSendingNtnSignalStrength(any(Message.class)); 2902 2903 // startSendingNtnSignalStrength() is requested and modem state is changed 2904 reset(mMockSatelliteModemInterface); 2905 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2906 setUpResponseForStartSendingNtnSignalStrength(SATELLITE_RESULT_SUCCESS); 2907 sendCmdStartSendingNtnSignalStrengthChangedEvent(true); 2908 processAllMessages(); 2909 verify(mMockSatelliteModemInterface, times(1)) 2910 .startSendingNtnSignalStrength(any(Message.class)); 2911 2912 // stopSendingNtnSignalStrength() is failed as modem returns error 2913 reset(mMockSatelliteModemInterface); 2914 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2915 setUpResponseForStopSendingNtnSignalStrength(SATELLITE_RESULT_NO_RESOURCES); 2916 sendCmdStartSendingNtnSignalStrengthChangedEvent(false); 2917 processAllMessages(); 2918 verify(mMockSatelliteModemInterface, times(1)) 2919 .stopSendingNtnSignalStrength(any(Message.class)); 2920 2921 // request stopSendingNtnSignalStrength() again and returns success 2922 reset(mMockSatelliteModemInterface); 2923 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2924 setUpResponseForStopSendingNtnSignalStrength(SATELLITE_RESULT_SUCCESS); 2925 sendCmdStartSendingNtnSignalStrengthChangedEvent(false); 2926 processAllMessages(); 2927 verify(mMockSatelliteModemInterface, times(1)) 2928 .stopSendingNtnSignalStrength(any(Message.class)); 2929 } 2930 2931 @Test testSendingNtnSignalStrengthWithFeatureDisabled()2932 public void testSendingNtnSignalStrengthWithFeatureDisabled() { 2933 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(false); 2934 2935 int expectedResult = SATELLITE_RESULT_SUCCESS; 2936 // startSendingNtnSignalStrength() is requested when screen on event comes. 2937 reset(mMockSatelliteModemInterface); 2938 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2939 setUpResponseForRequestIsSatelliteSupported(true, expectedResult); 2940 setUpResponseForRequestIsSatelliteProvisioned(true, expectedResult); 2941 verifySatelliteSupported(false, SATELLITE_RESULT_NOT_SUPPORTED); 2942 verifySatelliteProvisioned(false, SATELLITE_RESULT_REQUEST_NOT_SUPPORTED); 2943 setUpResponseForStartSendingNtnSignalStrength(expectedResult); 2944 sendCmdStartSendingNtnSignalStrengthChangedEvent(true); 2945 processAllMessages(); 2946 verify(mMockSatelliteModemInterface, never()) 2947 .startSendingNtnSignalStrength(any(Message.class)); 2948 2949 // stopSendingNtnSignalStrength() is requested when screen off event comes. 2950 reset(mMockSatelliteModemInterface); 2951 setUpResponseForRequestIsSatelliteProvisioned(true, SATELLITE_RESULT_SUCCESS); 2952 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 2953 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 2954 setUpResponseForStopSendingNtnSignalStrength(expectedResult); 2955 sendCmdStartSendingNtnSignalStrengthChangedEvent(false); 2956 processAllMessages(); 2957 verify(mMockSatelliteModemInterface, never()) 2958 .stopSendingNtnSignalStrength(any(Message.class)); 2959 } 2960 2961 @Test testIsSatelliteSupportedViaCarrier()2962 public void testIsSatelliteSupportedViaCarrier() { 2963 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(false); 2964 assertFalse(mSatelliteControllerUT.isSatelliteSupportedViaCarrier()); 2965 2966 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 2967 assertFalse(mSatelliteControllerUT.isSatelliteSupportedViaCarrier()); 2968 2969 mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, true); 2970 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 2971 : mCarrierConfigChangedListenerList) { 2972 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 2973 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 2974 ); 2975 } 2976 processAllMessages(); 2977 assertTrue(mSatelliteControllerUT.isSatelliteSupportedViaCarrier()); 2978 } 2979 2980 @Test testCarrierEnabledSatelliteConnectionHysteresisTime()2981 public void testCarrierEnabledSatelliteConnectionHysteresisTime() throws Exception { 2982 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(false); 2983 assertFalse(mSatelliteControllerUT 2984 .isSatelliteConnectedViaCarrierWithinHysteresisTime().first); 2985 2986 when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); 2987 when(mServiceState2.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); 2988 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 2989 mCarrierConfigBundle.putInt(KEY_SATELLITE_CONNECTION_HYSTERESIS_SEC_INT, 1 * 60); 2990 mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, true); 2991 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 2992 : mCarrierConfigChangedListenerList) { 2993 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 2994 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 2995 ); 2996 } 2997 doReturn(mSignalStrength).when(mPhone).getSignalStrength(); 2998 doReturn(mSignalStrength).when(mPhone2).getSignalStrength(); 2999 List<CellSignalStrength> cellSignalStrengthList = new ArrayList<>(); 3000 cellSignalStrengthList.add(mCellSignalStrength); 3001 doReturn(cellSignalStrengthList).when(mSignalStrength).getCellSignalStrengths(); 3002 processAllMessages(); 3003 mSatelliteControllerUT.elapsedRealtime = 0; 3004 assertFalse(mSatelliteControllerUT 3005 .isSatelliteConnectedViaCarrierWithinHysteresisTime().first); 3006 assertFalse(mSatelliteControllerUT.isInSatelliteModeForCarrierRoaming(mPhone)); 3007 assertFalse(mSatelliteControllerUT.isInSatelliteModeForCarrierRoaming(mPhone2)); 3008 3009 when(mServiceState.isUsingNonTerrestrialNetwork()).thenReturn(false); 3010 when(mServiceState2.isUsingNonTerrestrialNetwork()).thenReturn(false); 3011 sendServiceStateChangedEvent(); 3012 processAllMessages(); 3013 assertFalse(mSatelliteControllerUT 3014 .isSatelliteConnectedViaCarrierWithinHysteresisTime().first); 3015 assertFalse(mSatelliteControllerUT.isInSatelliteModeForCarrierRoaming(mPhone)); 3016 assertFalse(mSatelliteControllerUT.isInSatelliteModeForCarrierRoaming(mPhone2)); 3017 verify(mPhone, times(1)).notifyCarrierRoamingNtnModeChanged(eq(false)); 3018 verify(mPhone2, times(1)).notifyCarrierRoamingNtnModeChanged(eq(false)); 3019 clearInvocations(mPhone); 3020 clearInvocations(mPhone2); 3021 3022 // Last satellite connected time of Phone2 should be 0 3023 when(mServiceState2.isUsingNonTerrestrialNetwork()).thenReturn(true); 3024 sendServiceStateChangedEvent(); 3025 processAllMessages(); 3026 // 2 minutes later and hysteresis timeout is 1 minute 3027 mSatelliteControllerUT.elapsedRealtime = 2 * 60 * 1000; 3028 // But Phone2 is connected to NTN right now 3029 assertTrue(mSatelliteControllerUT 3030 .isSatelliteConnectedViaCarrierWithinHysteresisTime().first); 3031 assertFalse(mSatelliteControllerUT.isInSatelliteModeForCarrierRoaming(mPhone)); 3032 assertTrue(mSatelliteControllerUT.isInSatelliteModeForCarrierRoaming(mPhone2)); 3033 verify(mPhone, times(0)).notifyCarrierRoamingNtnModeChanged(eq(false)); 3034 verify(mPhone2, times(1)).notifyCarrierRoamingNtnModeChanged(eq(true)); 3035 clearInvocations(mPhone); 3036 clearInvocations(mPhone2); 3037 3038 // Last satellite disconnected time of Phone2 should be 2 * 60 * 1000 3039 when(mServiceState2.isUsingNonTerrestrialNetwork()).thenReturn(false); 3040 sendServiceStateChangedEvent(); 3041 processAllMessages(); 3042 // Current time (2) - last disconnected time (2) < hysteresis timeout (1) 3043 assertTrue(mSatelliteControllerUT 3044 .isSatelliteConnectedViaCarrierWithinHysteresisTime().first); 3045 assertFalse(mSatelliteControllerUT.isInSatelliteModeForCarrierRoaming(mPhone)); 3046 assertTrue(mSatelliteControllerUT.isInSatelliteModeForCarrierRoaming(mPhone2)); 3047 verify(mPhone, times(0)).notifyCarrierRoamingNtnModeChanged(eq(false)); 3048 verify(mPhone2, times(0)).notifyCarrierRoamingNtnModeChanged(anyBoolean()); 3049 clearInvocations(mPhone); 3050 clearInvocations(mPhone2); 3051 3052 // Current time (4) - last disconnected time (2) > hysteresis timeout (1) 3053 mSatelliteControllerUT.elapsedRealtime = 4 * 60 * 1000; 3054 moveTimeForward(2 * 60 * 1000); 3055 processAllMessages(); 3056 assertFalse(mSatelliteControllerUT 3057 .isSatelliteConnectedViaCarrierWithinHysteresisTime().first); 3058 assertFalse(mSatelliteControllerUT.isInSatelliteModeForCarrierRoaming(mPhone)); 3059 assertFalse(mSatelliteControllerUT.isInSatelliteModeForCarrierRoaming(mPhone2)); 3060 verify(mPhone, times(0)).notifyCarrierRoamingNtnModeChanged(eq(false)); 3061 verify(mPhone2, times(1)).notifyCarrierRoamingNtnModeChanged(eq(false)); 3062 } 3063 3064 @Test testRegisterForSatelliteCapabilitiesChangedWithFeatureFlagEnabled()3065 public void testRegisterForSatelliteCapabilitiesChangedWithFeatureFlagEnabled() { 3066 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(true); 3067 3068 Semaphore semaphore = new Semaphore(0); 3069 final SatelliteCapabilities[] satelliteCapabilities = new SatelliteCapabilities[1]; 3070 ISatelliteCapabilitiesCallback callback = 3071 new ISatelliteCapabilitiesCallback.Stub() { 3072 @Override 3073 public void onSatelliteCapabilitiesChanged(SatelliteCapabilities capabilities) { 3074 logd("onSatelliteCapabilitiesChanged: " + capabilities); 3075 try { 3076 satelliteCapabilities[0] = capabilities; 3077 semaphore.release(); 3078 } catch (Exception ex) { 3079 loge("onSatelliteCapabilitiesChanged: Got exception in releasing " 3080 + "semaphore, ex=" + ex); 3081 } 3082 } 3083 }; 3084 3085 int errorCode = mSatelliteControllerUT.registerForCapabilitiesChanged(callback); 3086 assertEquals(SATELLITE_RESULT_INVALID_TELEPHONY_STATE, errorCode); 3087 3088 setUpResponseForRequestIsSatelliteSupported(false, 3089 SATELLITE_RESULT_SUCCESS); 3090 verifySatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 3091 errorCode = mSatelliteControllerUT.registerForCapabilitiesChanged(callback); 3092 assertEquals(SATELLITE_RESULT_NOT_SUPPORTED, errorCode); 3093 3094 resetSatelliteControllerUT(); 3095 provisionSatelliteService(); 3096 errorCode = mSatelliteControllerUT.registerForCapabilitiesChanged(callback); 3097 assertEquals(SATELLITE_RESULT_SUCCESS, errorCode); 3098 SatelliteCapabilities expectedCapabilities = mSatelliteCapabilities; 3099 sendSatelliteCapabilitiesChangedEvent(expectedCapabilities, null); 3100 processAllMessages(); 3101 assertTrue(waitForForEvents( 3102 semaphore, 1, "testRegisterForSatelliteCapabilitiesChanged")); 3103 assertTrue(expectedCapabilities.equals(satelliteCapabilities[0])); 3104 3105 expectedCapabilities = mEmptySatelliteCapabilities; 3106 sendSatelliteCapabilitiesChangedEvent(expectedCapabilities, null); 3107 processAllMessages(); 3108 assertTrue(waitForForEvents( 3109 semaphore, 1, "testRegisterForSatelliteCapabilitiesChanged")); 3110 assertTrue(expectedCapabilities.equals(satelliteCapabilities[0])); 3111 3112 mSatelliteControllerUT.unregisterForCapabilitiesChanged(callback); 3113 expectedCapabilities = mSatelliteCapabilities; 3114 sendSatelliteCapabilitiesChangedEvent(expectedCapabilities, null); 3115 processAllMessages(); 3116 assertTrue(waitForForEvents( 3117 semaphore, 0, "testRegisterForSatelliteCapabilitiesChanged")); 3118 } 3119 3120 @Test testRegisterForSatelliteCapabilitiesChangedWithFeatureFlagDisabled()3121 public void testRegisterForSatelliteCapabilitiesChangedWithFeatureFlagDisabled() { 3122 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(false); 3123 3124 Semaphore semaphore = new Semaphore(0); 3125 final SatelliteCapabilities[] satelliteCapabilities = new SatelliteCapabilities[1]; 3126 ISatelliteCapabilitiesCallback callback = 3127 new ISatelliteCapabilitiesCallback.Stub() { 3128 @Override 3129 public void onSatelliteCapabilitiesChanged(SatelliteCapabilities capabilities) { 3130 logd("onSatelliteCapabilitiesChanged: " + capabilities); 3131 try { 3132 satelliteCapabilities[0] = capabilities; 3133 semaphore.release(); 3134 } catch (Exception ex) { 3135 loge("onSatelliteCapabilitiesChanged: Got exception in releasing " 3136 + "semaphore, ex=" + ex); 3137 } 3138 } 3139 }; 3140 3141 int errorCode = mSatelliteControllerUT.registerForCapabilitiesChanged(callback); 3142 assertEquals(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, errorCode); 3143 3144 setUpResponseForRequestIsSatelliteSupported(false, 3145 SATELLITE_RESULT_SUCCESS); 3146 verifySatelliteSupported(false, SATELLITE_RESULT_NOT_SUPPORTED); 3147 errorCode = mSatelliteControllerUT.registerForCapabilitiesChanged(callback); 3148 assertEquals(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, errorCode); 3149 3150 resetSatelliteControllerUT(); 3151 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 3152 verifySatelliteSupported(false, SATELLITE_RESULT_NOT_SUPPORTED); 3153 errorCode = mSatelliteControllerUT.registerForCapabilitiesChanged(callback); 3154 assertEquals(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, errorCode); 3155 3156 SatelliteCapabilities expectedCapabilities = mSatelliteCapabilities; 3157 sendSatelliteCapabilitiesChangedEvent(expectedCapabilities, null); 3158 processAllMessages(); 3159 assertTrue(waitForForEvents( 3160 semaphore, 0, "testRegisterForSatelliteCapabilitiesChanged")); 3161 } 3162 3163 @Test testSatelliteCommunicationRestrictionForEntitlement()3164 public void testSatelliteCommunicationRestrictionForEntitlement() throws Exception { 3165 logd("testSatelliteCommunicationRestrictionForEntitlement"); 3166 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 3167 3168 mCarrierConfigBundle.putBoolean(CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, 3169 true); 3170 SparseBooleanArray satelliteEnabledPerCarrier = new SparseBooleanArray(); 3171 replaceInstance(SatelliteController.class, "mSatelliteEntitlementStatusPerCarrier", 3172 mSatelliteControllerUT, satelliteEnabledPerCarrier); 3173 3174 mIIntegerConsumerResults.clear(); 3175 reset(mMockSatelliteModemInterface); 3176 setUpResponseForRequestSetSatelliteEnabledForCarrier(true, SATELLITE_RESULT_SUCCESS); 3177 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 3178 Map<Integer, Set<Integer>> satelliteAttachRestrictionForCarrierArray = new HashMap<>(); 3179 satelliteAttachRestrictionForCarrierArray.put(SUB_ID, new HashSet<>()); 3180 satelliteAttachRestrictionForCarrierArray.get(SUB_ID).add( 3181 SATELLITE_COMMUNICATION_RESTRICTION_REASON_ENTITLEMENT); 3182 replaceInstance(SatelliteController.class, "mSatelliteAttachRestrictionForCarrierArray", 3183 mSatelliteControllerUT, satelliteAttachRestrictionForCarrierArray); 3184 3185 // Verify call the requestSetSatelliteEnabledForCarrier to enable the satellite when 3186 // satellite service is enabled by entitlement server. 3187 mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, true, new ArrayList<>(), 3188 new ArrayList<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), 3189 new HashMap<>(), mIIntegerConsumer); 3190 processAllMessages(); 3191 3192 assertTrue(waitForIIntegerConsumerResult(1)); 3193 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 3194 verify(mMockSatelliteModemInterface, times(1)) 3195 .requestSetSatelliteEnabledForCarrier(anyInt(), eq(true), any(Message.class)); 3196 3197 // Verify call the requestSetSatelliteEnabledForCarrier to disable the satellite when 3198 // satellite service is disabled by entitlement server. 3199 mIIntegerConsumerResults.clear(); 3200 reset(mMockSatelliteModemInterface); 3201 Map<Integer, Boolean> enabledForCarrierArrayPerSub = new HashMap<>(); 3202 enabledForCarrierArrayPerSub.put(SUB_ID, true); 3203 replaceInstance(SatelliteController.class, "mIsSatelliteAttachEnabledForCarrierArrayPerSub", 3204 mSatelliteControllerUT, enabledForCarrierArrayPerSub); 3205 doReturn(mIsSatelliteServiceSupported) 3206 .when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 3207 setUpResponseForRequestSetSatelliteEnabledForCarrier(false, SATELLITE_RESULT_SUCCESS); 3208 mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, false, new ArrayList<>(), 3209 new ArrayList<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), 3210 new HashMap<>(), mIIntegerConsumer); 3211 processAllMessages(); 3212 3213 assertTrue(waitForIIntegerConsumerResult(1)); 3214 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 3215 verify(mMockSatelliteModemInterface, times(1)) 3216 .requestSetSatelliteEnabledForCarrier(anyInt(), eq(false), any(Message.class)); 3217 } 3218 3219 @Test testPassSatellitePlmnToModemAfterUpdateSatelliteEntitlementStatus()3220 public void testPassSatellitePlmnToModemAfterUpdateSatelliteEntitlementStatus() 3221 throws Exception { 3222 logd("testPassSatellitePlmnToModemAfterUpdateSatelliteEntitlementStatus"); 3223 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 3224 3225 replaceInstance(SatelliteController.class, "mMergedPlmnListPerCarrier", 3226 mSatelliteControllerUT, new SparseArray<>()); 3227 List<String> overlayConfigPlmnList = new ArrayList<>(); 3228 replaceInstance(SatelliteController.class, "mSatellitePlmnListFromOverlayConfig", 3229 mSatelliteControllerUT, overlayConfigPlmnList); 3230 mCarrierConfigBundle.putBoolean( 3231 CarrierConfigManager.KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true); 3232 mCarrierConfigBundle.putBoolean(CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, 3233 true); 3234 3235 // If the entitlement plmn list, the carrier plmn list, the overlay config plmn list and 3236 // the barred plmn list are empty, verify not passing to the modem. 3237 reset(mMockSatelliteModemInterface); 3238 List<String> entitlementPlmnList = new ArrayList<>(); 3239 List<String> barredPlmnList = new ArrayList<>(); 3240 mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, false, 3241 entitlementPlmnList, barredPlmnList, new HashMap<>(), new HashMap<>(), 3242 new HashMap<>(), new HashMap<>(), mIIntegerConsumer); 3243 verify(mMockSatelliteModemInterface, never()).requestSatelliteEnabled( 3244 any(SatelliteModemEnableRequestAttributes.class), any(Message.class)); 3245 3246 // If the entitlement plmn list and the overlay config plmn list are available and the 3247 // carrier plmn list and the barred plmn list are empty, verify passing to the modem. 3248 reset(mMockSatelliteModemInterface); 3249 entitlementPlmnList = Arrays.stream(new String[]{"00101", "00102", "00103"}).toList(); 3250 List<String> mergedPlmnList = entitlementPlmnList; 3251 overlayConfigPlmnList = 3252 Arrays.stream(new String[]{"00101", "00102", "00104"}).toList(); 3253 replaceInstance(SatelliteController.class, "mSatellitePlmnListFromOverlayConfig", 3254 mSatelliteControllerUT, overlayConfigPlmnList); 3255 verifyPassingToModemAfterQueryCompleted(entitlementPlmnList, mergedPlmnList, 3256 overlayConfigPlmnList, barredPlmnList); 3257 3258 // If the entitlement plmn list, the overlay config plmn list and the carrier plmn list 3259 // are available and the barred plmn list is empty, verify passing to the modem. 3260 reset(mMockSatelliteModemInterface); 3261 Map<Integer, Map<String, Set<Integer>>> 3262 satelliteServicesSupportedByCarriers = new HashMap<>(); 3263 List<String> carrierConfigPlmnList = Arrays.stream(new String[]{"00105", "00106"}).toList(); 3264 Map<String, Set<Integer>> plmnAndService = new HashMap<>(); 3265 plmnAndService.put(carrierConfigPlmnList.get(0), new HashSet<>(Arrays.asList(3, 5))); 3266 plmnAndService.put(carrierConfigPlmnList.get(1), new HashSet<>(Arrays.asList(3))); 3267 satelliteServicesSupportedByCarriers.put(SUB_ID, plmnAndService); 3268 replaceInstance(SatelliteController.class, "mSatelliteServicesSupportedByCarriers", 3269 mSatelliteControllerUT, satelliteServicesSupportedByCarriers); 3270 verifyPassingToModemAfterQueryCompleted(entitlementPlmnList, mergedPlmnList, 3271 overlayConfigPlmnList, barredPlmnList); 3272 3273 // If the entitlement plmn list is empty and the overlay config plmn list and the carrier 3274 // plmn list are available, verify passing to the modem. 3275 reset(mMockSatelliteModemInterface); 3276 entitlementPlmnList = new ArrayList<>(); 3277 mergedPlmnList = carrierConfigPlmnList; 3278 verifyPassingToModemAfterQueryCompleted(entitlementPlmnList, mergedPlmnList, 3279 overlayConfigPlmnList, barredPlmnList); 3280 3281 // If the entitlement plmn list is empty and the overlay config plmn list, the carrier 3282 // plmn list and the barred plmn list are available, verify passing to the modem. 3283 reset(mMockSatelliteModemInterface); 3284 barredPlmnList = Arrays.stream(new String[]{"00105", "00107"}).toList(); 3285 verifyPassingToModemAfterQueryCompleted(entitlementPlmnList, mergedPlmnList, 3286 overlayConfigPlmnList, barredPlmnList); 3287 3288 // If the entitlement plmn list is null and the overlay config plmn list and the carrier 3289 // plmn list are available, verify passing to the modem. 3290 reset(mMockSatelliteModemInterface); 3291 entitlementPlmnList = null; 3292 mergedPlmnList = carrierConfigPlmnList; 3293 verifyPassingToModemAfterQueryCompleted(entitlementPlmnList, mergedPlmnList, 3294 overlayConfigPlmnList, barredPlmnList); 3295 3296 // If the entitlement plmn list is invalid, verify not passing to the modem. 3297 reset(mMockSatelliteModemInterface); 3298 entitlementPlmnList = Arrays.stream(new String[]{"00101", "00102", ""}).toList(); 3299 mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, false, 3300 entitlementPlmnList, barredPlmnList, new HashMap<>(), new HashMap<>(), 3301 new HashMap<>(), new HashMap<>(), mIIntegerConsumer); 3302 verify(mMockSatelliteModemInterface, never()).requestSatelliteEnabled( 3303 any(SatelliteModemEnableRequestAttributes.class), any(Message.class)); 3304 3305 // If the entitlement plmn list is invalid, verify not passing to the modem. 3306 reset(mMockSatelliteModemInterface); 3307 entitlementPlmnList = Arrays.stream(new String[]{"00101", "00102", "123456789"}).toList(); 3308 mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, false, 3309 entitlementPlmnList, barredPlmnList, new HashMap<>(), new HashMap<>(), 3310 new HashMap<>(), new HashMap<>(), mIIntegerConsumer); 3311 verify(mMockSatelliteModemInterface, never()).requestSatelliteEnabled( 3312 any(SatelliteModemEnableRequestAttributes.class), any(Message.class)); 3313 3314 // If the entitlement plmn list is invalid, verify not passing to the modem. 3315 reset(mMockSatelliteModemInterface); 3316 entitlementPlmnList = Arrays.stream(new String[]{"00101", "00102", "12"}).toList(); 3317 mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, false, 3318 entitlementPlmnList, barredPlmnList, new HashMap<>(), new HashMap<>(), 3319 new HashMap<>(), new HashMap<>(), mIIntegerConsumer); 3320 verify(mMockSatelliteModemInterface, never()).requestSatelliteEnabled( 3321 any(SatelliteModemEnableRequestAttributes.class), any(Message.class)); 3322 3323 // If the entitlement plmn list is invalid, verify not passing to the modem. 3324 reset(mMockSatelliteModemInterface); 3325 entitlementPlmnList = Arrays.stream(new String[]{"00101", "00102", "1234"}).toList(); 3326 mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, false, 3327 entitlementPlmnList, barredPlmnList, new HashMap<>(), new HashMap<>(), 3328 new HashMap<>(), new HashMap<>(), mIIntegerConsumer); 3329 verify(mMockSatelliteModemInterface, never()).requestSatelliteEnabled( 3330 any(SatelliteModemEnableRequestAttributes.class), any(Message.class)); 3331 } 3332 verifyPassingToModemAfterQueryCompleted(List<String> entitlementPlmnList, List<String> mergedPlmnList, List<String> overlayConfigPlmnList, List<String> barredPlmnList)3333 private void verifyPassingToModemAfterQueryCompleted(List<String> entitlementPlmnList, 3334 List<String> mergedPlmnList, List<String> overlayConfigPlmnList, 3335 List<String> barredPlmnList) { 3336 mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, false, 3337 entitlementPlmnList, barredPlmnList, new HashMap<>(), new HashMap<>(), 3338 new HashMap<>(), new HashMap<>(), mIIntegerConsumer); 3339 3340 List<String> plmnListPerCarrier = mSatelliteControllerUT.getSatellitePlmnsForCarrier( 3341 SUB_ID); 3342 List<String> allSatellitePlmnList = SatelliteServiceUtils.mergeStrLists( 3343 plmnListPerCarrier, overlayConfigPlmnList, barredPlmnList); 3344 3345 assertEquals(mergedPlmnList, plmnListPerCarrier); 3346 if (overlayConfigPlmnList.isEmpty()) { 3347 assertEquals(plmnListPerCarrier, allSatellitePlmnList); 3348 } 3349 verify(mMockSatelliteModemInterface, times(1)).setSatellitePlmn(anyInt(), 3350 eq(plmnListPerCarrier), eq(allSatellitePlmnList), any(Message.class)); 3351 } 3352 setConfigData(List<String> plmnList)3353 private void setConfigData(List<String> plmnList) { 3354 doReturn(plmnList).when(mMockConfig).getAllSatellitePlmnsForCarrier(anyInt()); 3355 doReturn(mMockConfig).when(mMockConfigParser).getConfig(); 3356 3357 Map<String, List<Integer>> servicePerPlmn = new HashMap<>(); 3358 List<List<Integer>> serviceLists = Arrays.asList( 3359 Arrays.asList(1), 3360 Arrays.asList(3), 3361 Arrays.asList(5) 3362 ); 3363 for (int i = 0; i < plmnList.size(); i++) { 3364 servicePerPlmn.put(plmnList.get(i), serviceLists.get(i)); 3365 } 3366 doReturn(servicePerPlmn).when(mMockConfig).getSupportedSatelliteServices(anyInt()); 3367 doReturn(mMockConfig).when(mMockConfigParser).getConfig(); 3368 } 3369 3370 @Test testUpdateSupportedSatelliteServices()3371 public void testUpdateSupportedSatelliteServices() throws Exception { 3372 logd("testUpdateSupportedSatelliteServices"); 3373 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 3374 replaceInstance(SatelliteController.class, "mMergedPlmnListPerCarrier", 3375 mSatelliteControllerUT, new SparseArray<>()); 3376 replaceInstance(SatelliteController.class, "mSatelliteServicesSupportedByCarriers", 3377 mSatelliteControllerUT, new HashMap<>()); 3378 List<Integer> servicesPerPlmn; 3379 3380 // verify whether an empty list is returned with conditions below 3381 // the config data plmn list : empty 3382 // the carrier config plmn list : empty 3383 setConfigData(new ArrayList<>()); 3384 setCarrierConfigDataPlmnList(new ArrayList<>()); 3385 invokeCarrierConfigChanged(); 3386 servicesPerPlmn = mSatelliteControllerUT.getSupportedSatelliteServicesForPlmn( 3387 SUB_ID, "31016"); 3388 assertEquals(new ArrayList<>(), servicesPerPlmn); 3389 3390 // Verify whether the carrier config plmn list is returned with conditions below 3391 // the config data plmn list : empty 3392 // the carrier config plmn list : exist with services {{2}, {1, 3}, {2}} 3393 setConfigData(new ArrayList<>()); 3394 setCarrierConfigDataPlmnList(Arrays.asList("00101", "00102", "00104")); 3395 invokeCarrierConfigChanged(); 3396 servicesPerPlmn = mSatelliteControllerUT.getSupportedSatelliteServicesForPlmn( 3397 SUB_ID, "00101"); 3398 assertEquals(Arrays.asList(2).stream().sorted().toList(), 3399 servicesPerPlmn.stream().sorted().toList()); 3400 servicesPerPlmn = mSatelliteControllerUT.getSupportedSatelliteServicesForPlmn( 3401 SUB_ID, "00102"); 3402 assertEquals(Arrays.asList(1, 3).stream().sorted().toList(), 3403 servicesPerPlmn.stream().sorted().toList()); 3404 servicesPerPlmn = mSatelliteControllerUT.getSupportedSatelliteServicesForPlmn( 3405 SUB_ID, "00104"); 3406 assertEquals(Arrays.asList(2).stream().sorted().toList(), 3407 servicesPerPlmn.stream().sorted().toList()); 3408 3409 // Verify whether the carrier config plmn list is returned with conditions below 3410 // the config data plmn list : exist with services {{1}, {3}, {5}} 3411 // the carrier config plmn list : exist with services {{2}, {1, 3}, {2}} 3412 setConfigData(Arrays.asList("00101", "00102", "31024")); 3413 setCarrierConfigDataPlmnList(Arrays.asList("00101", "00102", "00104")); 3414 invokeCarrierConfigChanged(); 3415 servicesPerPlmn = mSatelliteControllerUT.getSupportedSatelliteServicesForPlmn( 3416 SUB_ID, "00101"); 3417 assertEquals(Arrays.asList(1).stream().sorted().toList(), 3418 servicesPerPlmn.stream().sorted().toList()); 3419 servicesPerPlmn = mSatelliteControllerUT.getSupportedSatelliteServicesForPlmn( 3420 SUB_ID, "00102"); 3421 assertEquals(Arrays.asList(3).stream().sorted().toList(), 3422 servicesPerPlmn.stream().sorted().toList()); 3423 servicesPerPlmn = mSatelliteControllerUT.getSupportedSatelliteServicesForPlmn( 3424 SUB_ID, "00104"); 3425 assertEquals(new ArrayList<>(), servicesPerPlmn.stream().sorted().toList()); 3426 servicesPerPlmn = mSatelliteControllerUT.getSupportedSatelliteServicesForPlmn( 3427 SUB_ID, "31024"); 3428 assertEquals(Arrays.asList(5).stream().sorted().toList(), 3429 servicesPerPlmn.stream().sorted().toList()); 3430 } setEntitlementPlmnList(List<String> plmnList)3431 private void setEntitlementPlmnList(List<String> plmnList) throws Exception { 3432 SparseArray<List<String>> entitlementPlmnListPerCarrier = new SparseArray<>(); 3433 if (!plmnList.isEmpty()) { 3434 entitlementPlmnListPerCarrier.clear(); 3435 entitlementPlmnListPerCarrier.put(SUB_ID, plmnList); 3436 } 3437 replaceInstance(SatelliteController.class, "mEntitlementPlmnListPerCarrier", 3438 mSatelliteControllerUT, entitlementPlmnListPerCarrier); 3439 } 3440 setEntitlementPlmnList(SatelliteController targetClass, int subId, List<String> plmnList)3441 private void setEntitlementPlmnList(SatelliteController targetClass, int subId, 3442 List<String> plmnList) throws Exception { 3443 SparseArray<List<String>> entitlementPlmnListPerCarrier = new SparseArray<>(); 3444 if (!plmnList.isEmpty()) { 3445 entitlementPlmnListPerCarrier.clear(); 3446 entitlementPlmnListPerCarrier.put(subId, plmnList); 3447 } 3448 replaceInstance(SatelliteController.class, "mEntitlementPlmnListPerCarrier", 3449 targetClass, entitlementPlmnListPerCarrier); 3450 } 3451 setConfigDataPlmnList(List<String> plmnList)3452 private void setConfigDataPlmnList(List<String> plmnList) { 3453 doReturn(plmnList).when(mMockConfig).getAllSatellitePlmnsForCarrier(anyInt()); 3454 doReturn(mMockConfig).when(mMockConfigParser).getConfig(); 3455 } 3456 setCarrierConfigDataPlmnList(List<String> plmnList)3457 private void setCarrierConfigDataPlmnList(List<String> plmnList) { 3458 if (!plmnList.isEmpty()) { 3459 mCarrierConfigBundle.putBoolean( 3460 CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, 3461 true); 3462 PersistableBundle carrierSupportedSatelliteServicesPerProvider = 3463 new PersistableBundle(); 3464 List<String> carrierConfigPlmnList = plmnList; 3465 carrierSupportedSatelliteServicesPerProvider.putIntArray( 3466 carrierConfigPlmnList.get(0), new int[]{2}); 3467 carrierSupportedSatelliteServicesPerProvider.putIntArray( 3468 carrierConfigPlmnList.get(1), new int[]{1, 3}); 3469 carrierSupportedSatelliteServicesPerProvider.putIntArray( 3470 carrierConfigPlmnList.get(2), new int[]{2}); 3471 mCarrierConfigBundle.putPersistableBundle(CarrierConfigManager 3472 .KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE, 3473 carrierSupportedSatelliteServicesPerProvider); 3474 } else { 3475 mCarrierConfigBundle.putPersistableBundle(CarrierConfigManager 3476 .KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE, 3477 new PersistableBundle()); 3478 } 3479 } 3480 invokeCarrierConfigChanged()3481 private void invokeCarrierConfigChanged() { 3482 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 3483 : mCarrierConfigChangedListenerList) { 3484 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 3485 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 3486 ); 3487 } 3488 processAllMessages(); 3489 } 3490 3491 @Test testUpdatePlmnListPerCarrier()3492 public void testUpdatePlmnListPerCarrier() throws Exception { 3493 logd("testUpdatePlmnListPerCarrier"); 3494 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 3495 3496 replaceInstance(SatelliteController.class, "mMergedPlmnListPerCarrier", 3497 mSatelliteControllerUT, new SparseArray<>()); 3498 mCarrierConfigBundle.putBoolean( 3499 CarrierConfigManager.KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true); 3500 List<String> plmnListPerCarrier; 3501 3502 // verify whether an empty list is returned with conditions below 3503 // the entitlement plmn list : empty 3504 // the config data plmn list : empty 3505 // the carrier config plmn list : empty 3506 setEntitlementPlmnList(new ArrayList<>()); 3507 setConfigDataPlmnList(new ArrayList<>()); 3508 setCarrierConfigDataPlmnList(new ArrayList<>()); 3509 invokeCarrierConfigChanged(); 3510 plmnListPerCarrier = mSatelliteControllerUT.getSatellitePlmnsForCarrier(SUB_ID); 3511 assertEquals(new ArrayList<>(), plmnListPerCarrier.stream().sorted().toList()); 3512 3513 // Verify whether the carrier config plmn list is returned with conditions below 3514 // the entitlement plmn list : empty 3515 // the config data plmn list : empty 3516 // the carrier config plmn list : exist 3517 setEntitlementPlmnList(new ArrayList<>()); 3518 setConfigDataPlmnList(new ArrayList<>()); 3519 setCarrierConfigDataPlmnList(Arrays.asList("00101", "00102", "00104")); 3520 invokeCarrierConfigChanged(); 3521 plmnListPerCarrier = mSatelliteControllerUT.getSatellitePlmnsForCarrier(SUB_ID); 3522 assertEquals(Arrays.asList("00101", "00102", "00104").stream().sorted().toList(), 3523 plmnListPerCarrier.stream().sorted().toList()); 3524 3525 // Verify whether config data plmn list is returned with conditions below 3526 // the entitlement plmn list : empty 3527 // the config data plmn list : exist 3528 // the carrier config plmn list : exist 3529 setEntitlementPlmnList(new ArrayList<>()); 3530 setConfigDataPlmnList(Arrays.asList("11111", "22222", "33333")); 3531 setCarrierConfigDataPlmnList(Arrays.asList("00101", "00102", "00104")); 3532 invokeCarrierConfigChanged(); 3533 plmnListPerCarrier = mSatelliteControllerUT.getSatellitePlmnsForCarrier(SUB_ID); 3534 assertEquals(Arrays.asList("11111", "22222", "33333").stream().sorted().toList(), 3535 plmnListPerCarrier.stream().sorted().toList()); 3536 3537 // Verify whether the entitlement plmn list is returned with conditions below 3538 // the entitlement plmn list : exist 3539 // the config data plmn list : exist 3540 // the carrier config plmn list : exist 3541 setEntitlementPlmnList(Arrays.asList("99090", "88080", "77070")); 3542 setConfigDataPlmnList(Arrays.asList("11111", "22222", "33333")); 3543 setCarrierConfigDataPlmnList(Arrays.asList("00101", "00102", "00104")); 3544 invokeCarrierConfigChanged(); 3545 plmnListPerCarrier = mSatelliteControllerUT.getSatellitePlmnsForCarrier(SUB_ID); 3546 assertEquals(Arrays.asList("99090", "88080", "77070").stream().sorted().toList(), 3547 plmnListPerCarrier.stream().sorted().toList()); 3548 } 3549 3550 @Test testEntitlementStatus()3551 public void testEntitlementStatus() throws Exception { 3552 logd("testEntitlementStatus"); 3553 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 3554 SparseBooleanArray satelliteEnabledPerCarrier = new SparseBooleanArray(); 3555 replaceInstance(SatelliteController.class, "mSatelliteEntitlementStatusPerCarrier", 3556 mSatelliteControllerUT, satelliteEnabledPerCarrier); 3557 3558 // Change SUB_ID's EntitlementStatus to true 3559 mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, true, new ArrayList<>(), 3560 new ArrayList<>(), new HashMap<>(), new HashMap<>(), 3561 new HashMap<>(), new HashMap<>(), mIIntegerConsumer); 3562 3563 assertEquals(true, satelliteEnabledPerCarrier.get(SUB_ID)); 3564 assertEquals(false, satelliteEnabledPerCarrier.get(SUB_ID1)); 3565 3566 // Change SUB_ID1's EntitlementStatus to true 3567 mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID1, true, new ArrayList<>(), 3568 new ArrayList<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), 3569 new HashMap<>(), mIIntegerConsumer); 3570 3571 assertEquals(true, satelliteEnabledPerCarrier.get(SUB_ID)); 3572 assertEquals(true, satelliteEnabledPerCarrier.get(SUB_ID1)); 3573 3574 // Change SUB_ID's EntitlementStatus to false 3575 mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, false, new ArrayList<>(), 3576 new ArrayList<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), 3577 new HashMap<>(), mIIntegerConsumer); 3578 3579 assertEquals(false, satelliteEnabledPerCarrier.get(SUB_ID)); 3580 assertEquals(true, satelliteEnabledPerCarrier.get(SUB_ID1)); 3581 } 3582 3583 @Test testUpdateRestrictReasonForEntitlementPerCarrier()3584 public void testUpdateRestrictReasonForEntitlementPerCarrier() throws Exception { 3585 logd("testUpdateRestrictReasonForEntitlementPerCarrier"); 3586 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 3587 3588 // Verify that the entitlement restriction reason is added before the entitlement query, 3589 // When the Satellite entitlement status value read from DB is disabled. 3590 doReturn("").when(mContext).getOpPackageName(); 3591 doReturn("").when(mContext).getAttributionTag(); 3592 doReturn("0").when(mMockSubscriptionManagerService).getSubscriptionProperty(anyInt(), 3593 eq(SATELLITE_ENTITLEMENT_STATUS), anyString(), anyString()); 3594 doReturn(new ArrayList<>()).when( 3595 mMockSubscriptionManagerService).getSatelliteEntitlementPlmnList(anyInt()); 3596 mCarrierConfigBundle.putBoolean(CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, 3597 true); 3598 mCarrierConfigBundle.putBoolean( 3599 CarrierConfigManager.KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true); 3600 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 3601 : mCarrierConfigChangedListenerList) { 3602 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 3603 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 3604 ); 3605 } 3606 processAllMessages(); 3607 Set<Integer> restrictionSet = 3608 mSatelliteControllerUT.getAttachRestrictionReasonsForCarrier(SUB_ID); 3609 assertEquals(1, restrictionSet.size()); 3610 assertTrue(restrictionSet.contains(SATELLITE_COMMUNICATION_RESTRICTION_REASON_ENTITLEMENT)); 3611 } 3612 3613 @Test testUpdateEntitlementPlmnListPerCarrier()3614 public void testUpdateEntitlementPlmnListPerCarrier() throws Exception { 3615 logd("testUpdateEntitlementPlmnListPerCarrier"); 3616 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 3617 3618 // If the Satellite entitlement plmn list read from the DB is empty list and carrier 3619 // config plmn list also is empty , check whether an empty list is returned when calling 3620 // getSatellitePlmnsForCarrier before the entitlement query. 3621 doReturn(new ArrayList<>()).when( 3622 mMockSubscriptionManagerService).getSatelliteEntitlementPlmnList(anyInt()); 3623 replaceInstance(SatelliteController.class, "mEntitlementPlmnListPerCarrier", 3624 mSatelliteControllerUT, new SparseArray<>()); 3625 replaceInstance(SatelliteController.class, "mSatelliteServicesSupportedByCarriers", 3626 mSatelliteControllerUT, new HashMap<>()); 3627 mCarrierConfigBundle.putBoolean(CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, 3628 true); 3629 mCarrierConfigBundle.putBoolean( 3630 CarrierConfigManager.KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true); 3631 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 3632 : mCarrierConfigChangedListenerList) { 3633 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 3634 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 3635 ); 3636 } 3637 processAllMessages(); 3638 3639 assertEquals(new ArrayList<>(), mSatelliteControllerUT.getSatellitePlmnsForCarrier(SUB_ID)); 3640 3641 // If the Satellite entitlement plmn list read from the DB is valid and carrier config 3642 // plmn list is empty, check whether valid entitlement plmn list is returned 3643 // when calling getSatellitePlmnsForCarrier before the entitlement query. 3644 replaceInstance(SatelliteController.class, "mEntitlementPlmnListPerCarrier", 3645 mSatelliteControllerUT, new SparseArray<>()); 3646 List<String> expectedSatelliteEntitlementPlmnList = Arrays.asList("123456,12560"); 3647 doReturn(expectedSatelliteEntitlementPlmnList).when( 3648 mMockSubscriptionManagerService).getSatelliteEntitlementPlmnList(anyInt()); 3649 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 3650 : mCarrierConfigChangedListenerList) { 3651 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 3652 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 3653 ); 3654 } 3655 processAllMessages(); 3656 3657 assertEquals(expectedSatelliteEntitlementPlmnList, 3658 mSatelliteControllerUT.getSatellitePlmnsForCarrier(SUB_ID)); 3659 3660 // If the Satellite entitlement plmn list read from the DB is valid and carrier config 3661 // plmn list is valid, check whether valid entitlement plmn list is returned when 3662 // calling getSatellitePlmnsForCarrier before the entitlement query. 3663 replaceInstance(SatelliteController.class, "mEntitlementPlmnListPerCarrier", 3664 mSatelliteControllerUT, new SparseArray<>()); 3665 PersistableBundle carrierSupportedSatelliteServicesPerProvider = new PersistableBundle(); 3666 List<String> carrierConfigPlmnList = Arrays.asList("00102", "00103", "00105"); 3667 carrierSupportedSatelliteServicesPerProvider.putIntArray( 3668 carrierConfigPlmnList.get(0), new int[]{2}); 3669 carrierSupportedSatelliteServicesPerProvider.putIntArray( 3670 carrierConfigPlmnList.get(1), new int[]{1, 3}); 3671 carrierSupportedSatelliteServicesPerProvider.putIntArray( 3672 carrierConfigPlmnList.get(2), new int[]{2}); 3673 mCarrierConfigBundle.putPersistableBundle(CarrierConfigManager 3674 .KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE, 3675 carrierSupportedSatelliteServicesPerProvider); 3676 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 3677 : mCarrierConfigChangedListenerList) { 3678 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 3679 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 3680 ); 3681 } 3682 processAllMessages(); 3683 3684 assertEquals(expectedSatelliteEntitlementPlmnList, 3685 mSatelliteControllerUT.getSatellitePlmnsForCarrier(SUB_ID)); 3686 3687 // If the Satellite entitlement plmn list read from the DB is empty and carrier config 3688 // plmn list is valid, check whether valid carrier config plmn list is returned when 3689 // calling getSatellitePlmnsForCarrier before the entitlement query. 3690 replaceInstance(SatelliteController.class, "mEntitlementPlmnListPerCarrier", 3691 mSatelliteControllerUT, new SparseArray<>()); 3692 doReturn(new ArrayList<>()).when( 3693 mMockSubscriptionManagerService).getSatelliteEntitlementPlmnList(anyInt()); 3694 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 3695 : mCarrierConfigChangedListenerList) { 3696 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 3697 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 3698 ); 3699 } 3700 processAllMessages(); 3701 3702 assertEquals(carrierConfigPlmnList.stream().sorted().toList(), 3703 mSatelliteControllerUT.getSatellitePlmnsForCarrier( 3704 SUB_ID).stream().sorted().toList()); 3705 } 3706 3707 @Test testHandleEventServiceStateChanged()3708 public void testHandleEventServiceStateChanged() { 3709 mContextFixture.putBooleanResource( 3710 R.bool.config_satellite_should_notify_availability, true); 3711 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 3712 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 3713 mCarrierConfigBundle.putInt(KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT, 3714 CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC); 3715 invokeCarrierConfigChanged(); 3716 3717 // Do nothing when the satellite is not connected 3718 doReturn(false).when(mServiceState).isUsingNonTerrestrialNetwork(); 3719 sendServiceStateChangedEvent(); 3720 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 3721 processAllMessages(); 3722 assertFalse(mSharedPreferences.getBoolean(SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY, false)); 3723 verify(mMockNotificationManager, never()).notifyAsUser(anyString(), anyInt(), any(), any()); 3724 3725 // Check sending a system notification when the satellite is connected 3726 doReturn(true).when(mServiceState).isUsingNonTerrestrialNetwork(); 3727 sendServiceStateChangedEvent(); 3728 processAllMessages(); 3729 verify(mMockNotificationManager, times(1)).notifyAsUser(anyString(), anyInt(), any(), 3730 any()); 3731 // Just by showing notification we do not update the pref file , only once user interact 3732 // only we will update the pref value to true. 3733 assertFalse(mSharedPreferences.getBoolean(SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY, false)); 3734 3735 // Check don't display again after displayed already a system notification. 3736 sendServiceStateChangedEvent(); 3737 processAllMessages(); 3738 verify(mMockNotificationManager, times(2)).notifyAsUser(anyString(), anyInt(), any(), 3739 any()); 3740 } 3741 3742 @Test testRequestSatelliteEnabled_timeout()3743 public void testRequestSatelliteEnabled_timeout() { 3744 mIsSatelliteEnabledSemaphore.drainPermits(); 3745 mIIntegerConsumerResults.clear(); 3746 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 3747 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 3748 setProvisionedState(true); 3749 processAllMessages(); 3750 verifySatelliteProvisioned(true, SATELLITE_RESULT_SUCCESS); 3751 3752 // Successfully disable satellite 3753 mIIntegerConsumerResults.clear(); 3754 setUpResponseForRequestSatelliteEnabled(false, false, false, SATELLITE_RESULT_SUCCESS); 3755 mSatelliteControllerUT.requestSatelliteEnabled(false, false, false, mIIntegerConsumer); 3756 processAllMessages(); 3757 assertTrue(waitForIIntegerConsumerResult(1)); 3758 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 3759 verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); 3760 3761 // Time out to enable satellite 3762 ArgumentCaptor<SatelliteModemEnableRequestAttributes> enableSatelliteRequest = 3763 ArgumentCaptor.forClass(SatelliteModemEnableRequestAttributes.class); 3764 ArgumentCaptor<Message> enableSatelliteResponse = ArgumentCaptor.forClass(Message.class); 3765 mIIntegerConsumerResults.clear(); 3766 setUpNoResponseForRequestSatelliteEnabled(true, false, false); 3767 clearInvocations(mMockSatelliteModemInterface); 3768 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 3769 processAllMessages(); 3770 assertFalse(waitForIIntegerConsumerResult(1)); 3771 verify(mMockSatelliteModemInterface).requestSatelliteEnabled( 3772 enableSatelliteRequest.capture(), 3773 enableSatelliteResponse.capture()); 3774 SatelliteModemEnableRequestAttributes request = enableSatelliteRequest.getValue(); 3775 assertTrue(request.isEnabled()); 3776 assertFalse(request.isDemoMode()); 3777 assertFalse(request.isEmergencyMode()); 3778 3779 clearInvocations(mMockSatelliteModemInterface); 3780 moveTimeForward(TEST_WAIT_FOR_SATELLITE_ENABLING_RESPONSE_TIMEOUT_MILLIS); 3781 processAllMessages(); 3782 assertTrue(waitForIIntegerConsumerResult(1)); 3783 assertEquals(SATELLITE_RESULT_MODEM_TIMEOUT, (long) mIIntegerConsumerResults.get(0)); 3784 verify(mMockSatelliteModemInterface).requestSatelliteEnabled( 3785 any(SatelliteModemEnableRequestAttributes.class), any(Message.class)); 3786 verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); 3787 3788 // Send the response for the above request to enable satellite. SatelliteController should 3789 // ignore the event 3790 Message response = enableSatelliteResponse.getValue(); 3791 AsyncResult.forMessage(response, null, null); 3792 response.sendToTarget(); 3793 processAllMessages(); 3794 verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); 3795 3796 // Successfully enable satellite 3797 mIIntegerConsumerResults.clear(); 3798 setUpResponseForRequestSatelliteEnabled(true, false, false, SATELLITE_RESULT_SUCCESS); 3799 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 3800 processAllMessages(); 3801 assertTrue(waitForIIntegerConsumerResult(1)); 3802 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 3803 verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); 3804 3805 // Time out to disable satellite 3806 ArgumentCaptor<Message> disableSatelliteResponse = ArgumentCaptor.forClass(Message.class); 3807 mIIntegerConsumerResults.clear(); 3808 clearInvocations(mMockSatelliteModemInterface); 3809 setUpNoResponseForRequestSatelliteEnabled(false, false, false); 3810 mSatelliteControllerUT.requestSatelliteEnabled(false, false, false, mIIntegerConsumer); 3811 processAllMessages(); 3812 assertFalse(waitForIIntegerConsumerResult(1)); 3813 verify(mMockSatelliteModemInterface).requestSatelliteEnabled( 3814 any(SatelliteModemEnableRequestAttributes.class), 3815 disableSatelliteResponse.capture()); 3816 3817 clearInvocations(mMockSatelliteModemInterface); 3818 moveTimeForward(TEST_WAIT_FOR_SATELLITE_ENABLING_RESPONSE_TIMEOUT_MILLIS); 3819 processAllMessages(); 3820 assertTrue(waitForIIntegerConsumerResult(1)); 3821 assertEquals(SATELLITE_RESULT_MODEM_TIMEOUT, (long) mIIntegerConsumerResults.get(0)); 3822 verify(mMockSatelliteModemInterface, never()).requestSatelliteEnabled( 3823 any(SatelliteModemEnableRequestAttributes.class), any(Message.class)); 3824 // Satellite should state at enabled state since satellite disable request failed 3825 verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); 3826 3827 // Send the response for the above request to disable satellite. SatelliteController should 3828 // ignore the event 3829 response = disableSatelliteResponse.getValue(); 3830 AsyncResult.forMessage(response, null, null); 3831 response.sendToTarget(); 3832 processAllMessages(); 3833 verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); 3834 } 3835 3836 @Test testUpdateNtnSignalStrentghReportWithFeatureFlagEnabled()3837 public void testUpdateNtnSignalStrentghReportWithFeatureFlagEnabled() { 3838 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(true); 3839 3840 mIsSatelliteEnabledSemaphore.drainPermits(); 3841 mIIntegerConsumerResults.clear(); 3842 resetSatelliteControllerUT(); 3843 3844 // Successfully provisioned 3845 reset(mMockSatelliteModemInterface); 3846 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 3847 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 3848 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 3849 setProvisionedState(true); 3850 setUpResponseForRequestIsSatelliteProvisioned(true, SATELLITE_RESULT_SUCCESS); 3851 setProvisionedState(true); 3852 processAllMessages(); 3853 verifySatelliteProvisioned(true, SATELLITE_RESULT_SUCCESS); 3854 3855 // startSendingNtnSignalStrength should be invoked when satellite is enabled 3856 mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled = false; 3857 mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled = false; 3858 setUpResponseForRequestSatelliteEnabled(true, false, false, SATELLITE_RESULT_SUCCESS); 3859 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 3860 processAllMessages(); 3861 assertTrue(waitForIIntegerConsumerResult(1)); 3862 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 3863 verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); 3864 assertTrue(mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled); 3865 assertTrue(mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled); 3866 assertEquals( 3867 SATELLITE_MODE_ENABLED_TRUE, mSatelliteControllerUT.satelliteModeSettingValue); 3868 verify(mMockSatelliteModemInterface, times(1)).startSendingNtnSignalStrength( 3869 any(Message.class)); 3870 3871 // Ignore request ntn signal strength for redundant enable request 3872 reset(mMockSatelliteModemInterface); 3873 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 3874 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 3875 processAllMessages(); 3876 assertTrue(waitForIIntegerConsumerResult(1)); 3877 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 3878 verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); 3879 verify(mMockSatelliteModemInterface, never()).startSendingNtnSignalStrength( 3880 any(Message.class)); 3881 3882 // stopSendingNtnSignalStrength should be invoked when satellite is successfully off. 3883 mIIntegerConsumerResults.clear(); 3884 reset(mMockSatelliteModemInterface); 3885 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 3886 setUpResponseForRequestSatelliteEnabled(false, false, false, SATELLITE_RESULT_SUCCESS); 3887 mSatelliteControllerUT.requestSatelliteEnabled(false, false, false, mIIntegerConsumer); 3888 processAllMessages(); 3889 assertTrue(waitForIIntegerConsumerResult(1)); 3890 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 3891 verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); 3892 verify(mMockSatelliteModemInterface, times(1)).stopSendingNtnSignalStrength( 3893 any(Message.class)); 3894 3895 // Ignore redundant request for stop reporting ntn signal strength. 3896 mIIntegerConsumerResults.clear(); 3897 reset(mMockSatelliteModemInterface); 3898 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 3899 mIIntegerConsumerResults.clear(); 3900 setUpResponseForRequestSatelliteEnabled(false, false, false, SATELLITE_RESULT_SUCCESS); 3901 mSatelliteControllerUT.requestSatelliteEnabled(false, false, false, mIIntegerConsumer); 3902 processAllMessages(); 3903 assertTrue(waitForIIntegerConsumerResult(1)); 3904 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 3905 verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); 3906 verify(mMockSatelliteModemInterface, never()).stopSendingNtnSignalStrength( 3907 any(Message.class)); 3908 3909 // startSendingNtnSignalStrength is invoked when satellite is enabled again. 3910 mIIntegerConsumerResults.clear(); 3911 reset(mMockSatelliteModemInterface); 3912 doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported(); 3913 mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled = false; 3914 mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled = false; 3915 setUpResponseForRequestSatelliteEnabled(true, false, false, SATELLITE_RESULT_SUCCESS); 3916 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 3917 processAllMessages(); 3918 assertTrue(waitForIIntegerConsumerResult(1)); 3919 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 3920 verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); 3921 assertTrue(mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled); 3922 assertTrue(mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled); 3923 assertEquals( 3924 SATELLITE_MODE_ENABLED_TRUE, mSatelliteControllerUT.satelliteModeSettingValue); 3925 verify(mMockSatelliteModemInterface, times(1)).startSendingNtnSignalStrength( 3926 any(Message.class)); 3927 } 3928 3929 @Test testRegisterForSatelliteSupportedStateChanged_WithFeatureFlagEnabled()3930 public void testRegisterForSatelliteSupportedStateChanged_WithFeatureFlagEnabled() { 3931 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(true); 3932 3933 Semaphore semaphore = new Semaphore(0); 3934 final boolean[] isSupported = new boolean[1]; 3935 ISatelliteSupportedStateCallback callback = 3936 new ISatelliteSupportedStateCallback.Stub() { 3937 @Override 3938 public void onSatelliteSupportedStateChanged(boolean supported) { 3939 logd("onSatelliteSupportedStateChanged: supported=" + supported); 3940 isSupported[0] = supported; 3941 try { 3942 semaphore.release(); 3943 } catch (Exception ex) { 3944 loge("onSatelliteSupportedStateChanged: Got exception in releasing " 3945 + "semaphore, ex=" + ex); 3946 } 3947 } 3948 }; 3949 3950 resetSatelliteControllerUT(); 3951 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 3952 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 3953 int errorCode = mSatelliteControllerUT.registerForSatelliteSupportedStateChanged(callback); 3954 assertEquals(SATELLITE_RESULT_SUCCESS, errorCode); 3955 3956 sendSatelliteSupportedStateChangedEvent(true, null); 3957 processAllMessages(); 3958 // Verify redundant report is ignored 3959 assertFalse(waitForForEvents( 3960 semaphore, 1, "testRegisterForSatelliteSupportedStateChanged")); 3961 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 3962 3963 // Verify updated state is reported 3964 sendSatelliteSupportedStateChangedEvent(false, null); 3965 processAllMessages(); 3966 assertTrue(waitForForEvents( 3967 semaphore, 1, "testRegisterForSatelliteSupportedStateChanged")); 3968 assertEquals(false, isSupported[0]); 3969 verifySatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 3970 3971 // Verify redundant report is ignored 3972 sendSatelliteSupportedStateChangedEvent(false, null); 3973 processAllMessages(); 3974 assertFalse(waitForForEvents( 3975 semaphore, 1, "testRegisterForSatelliteSupportedStateChanged")); 3976 verifySatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 3977 3978 // Verify updated state is reported 3979 sendSatelliteSupportedStateChangedEvent(true, null); 3980 processAllMessages(); 3981 assertTrue(waitForForEvents( 3982 semaphore, 1, "testRegisterForSatelliteSupportedStateChanged")); 3983 assertEquals(true, isSupported[0]); 3984 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 3985 3986 // Successfully enable satellite 3987 setProvisionedState(true); 3988 processAllMessages(); 3989 verifySatelliteProvisioned(true, SATELLITE_RESULT_SUCCESS); 3990 mIIntegerConsumerResults.clear(); 3991 setUpResponseForRequestSatelliteEnabled(true, false, false, SATELLITE_RESULT_SUCCESS); 3992 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 3993 processAllMessages(); 3994 assertTrue(waitForIIntegerConsumerResult(1)); 3995 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 3996 verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); 3997 3998 // Send satellite is not supported state from modem to disable satellite 3999 setUpResponseForRequestSatelliteEnabled(false, false, false, SATELLITE_RESULT_SUCCESS); 4000 sendSatelliteSupportedStateChangedEvent(false, null); 4001 processAllMessages(); 4002 assertTrue(waitForForEvents( 4003 semaphore, 1, "testRegisterForSatelliteSupportedStateChanged")); 4004 assertEquals(false, isSupported[0]); 4005 4006 // It is needed to set satellite as support to check whether satellite is enabled or not 4007 sendSatelliteSupportedStateChangedEvent(true, null); 4008 processAllMessages(); 4009 assertTrue(waitForForEvents( 4010 semaphore, 1, "testRegisterForSatelliteSupportedStateChanged")); 4011 assertEquals(true, isSupported[0]); 4012 // Verify satellite was disabled 4013 verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); 4014 4015 mSatelliteControllerUT.unregisterForSatelliteSupportedStateChanged(callback); 4016 sendSatelliteSupportedStateChangedEvent(true, null); 4017 processAllMessages(); 4018 assertFalse(waitForForEvents( 4019 semaphore, 1, "testRegisterForSatelliteSupportedStateChanged")); 4020 } 4021 4022 @Test testRegisterForSatelliteSupportedStateChanged_WithFeatureFlagDisabled()4023 public void testRegisterForSatelliteSupportedStateChanged_WithFeatureFlagDisabled() { 4024 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(false); 4025 4026 Semaphore semaphore = new Semaphore(0); 4027 ISatelliteSupportedStateCallback callback = 4028 new ISatelliteSupportedStateCallback.Stub() { 4029 @Override 4030 public void onSatelliteSupportedStateChanged(boolean supported) { 4031 logd("onSatelliteSupportedStateChanged: supported=" + supported); 4032 try { 4033 semaphore.release(); 4034 } catch (Exception ex) { 4035 loge("onSatelliteSupportedStateChanged: Got exception in releasing " 4036 + "semaphore, ex=" + ex); 4037 } 4038 } 4039 }; 4040 int errorCode = mSatelliteControllerUT.registerForSatelliteSupportedStateChanged( 4041 callback); 4042 assertEquals(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, errorCode); 4043 } 4044 4045 @Test testRegisterForSelectedNbIotSatelliteSubscriptionChanged_WithFeatureFlagEnabled()4046 public void testRegisterForSelectedNbIotSatelliteSubscriptionChanged_WithFeatureFlagEnabled() { 4047 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 4048 4049 Semaphore semaphore = new Semaphore(0); 4050 final int[] selectedSubIds = new int[1]; 4051 ISelectedNbIotSatelliteSubscriptionCallback callback = 4052 new ISelectedNbIotSatelliteSubscriptionCallback.Stub() { 4053 @Override 4054 public void onSelectedNbIotSatelliteSubscriptionChanged(int selectedSubId) { 4055 logd("onSelectedNbIotSatelliteSubscriptionChanged: selectedSubId=" 4056 + selectedSubId); 4057 try { 4058 selectedSubIds[0] = selectedSubId; 4059 semaphore.release(); 4060 } catch (Exception ex) { 4061 loge("onSelectedNbIotSatelliteSubscriptionChanged: Got exception in " 4062 + "releasing semaphore, ex=" + ex); 4063 } 4064 } 4065 }; 4066 4067 int errorCode = mSatelliteControllerUT.registerForSelectedNbIotSatelliteSubscriptionChanged( 4068 callback); 4069 assertEquals(SATELLITE_RESULT_INVALID_TELEPHONY_STATE, errorCode); 4070 4071 setUpResponseForRequestIsSatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 4072 verifySatelliteSupported(false, SATELLITE_RESULT_SUCCESS); 4073 errorCode = mSatelliteControllerUT.registerForSelectedNbIotSatelliteSubscriptionChanged( 4074 callback); 4075 assertEquals(SATELLITE_RESULT_NOT_SUPPORTED, errorCode); 4076 4077 // Register the callback and verify that the event is reported. 4078 resetSatelliteControllerUT(); 4079 setUpResponseForRequestIsSatelliteProvisioned(true,SATELLITE_RESULT_SUCCESS); 4080 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 4081 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 4082 errorCode = mSatelliteControllerUT.registerForSelectedNbIotSatelliteSubscriptionChanged( 4083 callback); 4084 assertEquals(SATELLITE_RESULT_SUCCESS, errorCode); 4085 int expectedSubId = 1; 4086 sendSelectedNbIotSatelliteSubscriptionChangedEvent(expectedSubId, null); 4087 processAllMessages(); 4088 assertTrue(waitForForEvents( 4089 semaphore, 1, "testRegisterForSelectedNbIotSatelliteSubscriptionChanged")); 4090 assertEquals(expectedSubId, selectedSubIds[0]); 4091 4092 // Unregister the callback and verify that the event is not reported. 4093 mSatelliteControllerUT.unregisterForSelectedNbIotSatelliteSubscriptionChanged(callback); 4094 sendSelectedNbIotSatelliteSubscriptionChangedEvent(2, null); 4095 processAllMessages(); 4096 assertTrue(waitForForEvents( 4097 semaphore, 0, "testRegisterForSelectedNbIotSatelliteSubscriptionChanged")); 4098 } 4099 4100 @Test testRegisterForSelectedNbIotSatelliteSubscriptionChanged_WithFeatureFlagDisabled()4101 public void testRegisterForSelectedNbIotSatelliteSubscriptionChanged_WithFeatureFlagDisabled() { 4102 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(false); 4103 4104 Semaphore semaphore = new Semaphore(0); 4105 final int[] selectedSubIds = new int[1]; 4106 ISelectedNbIotSatelliteSubscriptionCallback callback = 4107 new ISelectedNbIotSatelliteSubscriptionCallback.Stub() { 4108 @Override 4109 public void onSelectedNbIotSatelliteSubscriptionChanged(int selectedSubId) { 4110 logd("onSelectedNbIotSatelliteSubscriptionChanged: selectedSubId=" 4111 + selectedSubId); 4112 try { 4113 selectedSubIds[0] = selectedSubId; 4114 semaphore.release(); 4115 } catch (Exception ex) { 4116 loge("onSelectedNbIotSatelliteSubscriptionChanged: Got exception in " 4117 + "releasing semaphore, ex=" + ex); 4118 } 4119 } 4120 }; 4121 4122 int errorCode = mSatelliteControllerUT.registerForSelectedNbIotSatelliteSubscriptionChanged( 4123 callback); 4124 assertEquals(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, errorCode); 4125 4126 // Verify that the event is not reported. 4127 sendSelectedNbIotSatelliteSubscriptionChangedEvent(1, null); 4128 processAllMessages(); 4129 assertTrue(waitForForEvents( 4130 semaphore, 0, "testRegisterForSelectedNbIotSatelliteSubscriptionChanged")); 4131 4132 4133 } 4134 4135 @Test testIsSatelliteEmergencyMessagingSupportedViaCarrier()4136 public void testIsSatelliteEmergencyMessagingSupportedViaCarrier() { 4137 // Carrier-enabled flag is off 4138 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(false); 4139 assertFalse(mSatelliteControllerUT.isSatelliteEmergencyMessagingSupportedViaCarrier()); 4140 4141 // Carrier-enabled flag is on and satellite attach is not supported 4142 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 4143 assertFalse(mSatelliteControllerUT.isSatelliteEmergencyMessagingSupportedViaCarrier()); 4144 4145 // Trigger carrier config changed to enable satellite attach 4146 mCarrierConfigBundle.putBoolean( 4147 CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, true); 4148 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 4149 : mCarrierConfigChangedListenerList) { 4150 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 4151 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 4152 ); 4153 } 4154 processAllMessages(); 4155 assertFalse(mSatelliteControllerUT.isSatelliteEmergencyMessagingSupportedViaCarrier()); 4156 4157 // Trigger carrier config changed to enable satellite attach & emergency messaging 4158 mCarrierConfigBundle.putBoolean( 4159 CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, true); 4160 mCarrierConfigBundle.putBoolean( 4161 CarrierConfigManager.KEY_EMERGENCY_MESSAGING_SUPPORTED_BOOL, true); 4162 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 4163 : mCarrierConfigChangedListenerList) { 4164 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 4165 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 4166 ); 4167 } 4168 processAllMessages(); 4169 assertTrue(mSatelliteControllerUT.isSatelliteEmergencyMessagingSupportedViaCarrier()); 4170 } 4171 4172 @Test testGetCarrierEmergencyCallWaitForConnectionTimeoutMillis()4173 public void testGetCarrierEmergencyCallWaitForConnectionTimeoutMillis() { 4174 // Carrier-enabled flag is off 4175 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(false); 4176 assertEquals(DEFAULT_CARRIER_EMERGENCY_CALL_WAIT_FOR_CONNECTION_TIMEOUT_MILLIS, 4177 mSatelliteControllerUT.getCarrierEmergencyCallWaitForConnectionTimeoutMillis()); 4178 4179 // Carrier-enabled flag is on 4180 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 4181 assertEquals(DEFAULT_CARRIER_EMERGENCY_CALL_WAIT_FOR_CONNECTION_TIMEOUT_MILLIS, 4182 mSatelliteControllerUT.getCarrierEmergencyCallWaitForConnectionTimeoutMillis()); 4183 4184 // Trigger carrier config changed to enable satellite attach 4185 int timeoutMillisForCarrier1 = 1000; 4186 PersistableBundle carrierConfigBundle1 = new PersistableBundle(); 4187 carrierConfigBundle1.putBoolean( 4188 CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, true); 4189 carrierConfigBundle1.putBoolean( 4190 CarrierConfigManager.KEY_EMERGENCY_MESSAGING_SUPPORTED_BOOL, true); 4191 carrierConfigBundle1.putInt( 4192 KEY_EMERGENCY_CALL_TO_SATELLITE_T911_HANDOVER_TIMEOUT_MILLIS_INT, 4193 timeoutMillisForCarrier1); 4194 doReturn(carrierConfigBundle1) 4195 .when(mCarrierConfigManager).getConfigForSubId(eq(SUB_ID), anyVararg()); 4196 4197 int timeoutMillisForCarrier2 = 2000; 4198 PersistableBundle carrierConfigBundle2 = new PersistableBundle(); 4199 carrierConfigBundle2.putBoolean( 4200 CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, true); 4201 carrierConfigBundle2.putBoolean( 4202 CarrierConfigManager.KEY_EMERGENCY_MESSAGING_SUPPORTED_BOOL, true); 4203 carrierConfigBundle2.putInt( 4204 KEY_EMERGENCY_CALL_TO_SATELLITE_T911_HANDOVER_TIMEOUT_MILLIS_INT, 4205 timeoutMillisForCarrier2); 4206 doReturn(carrierConfigBundle2) 4207 .when(mCarrierConfigManager).getConfigForSubId(eq(SUB_ID1), anyVararg()); 4208 4209 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 4210 : mCarrierConfigChangedListenerList) { 4211 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 4212 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 4213 ); 4214 } 4215 processAllMessages(); 4216 4217 // Both phones are not in satellite mode for carrier roaming, and thus the max timeout 4218 // duration - timeoutMillisForCarrier2 - is used 4219 assertEquals(timeoutMillisForCarrier2, 4220 mSatelliteControllerUT.getCarrierEmergencyCallWaitForConnectionTimeoutMillis()); 4221 4222 // Phone 1 is in satellite mode for carrier roaming 4223 when(mServiceState.isUsingNonTerrestrialNetwork()).thenReturn(true); 4224 assertEquals(timeoutMillisForCarrier1, 4225 mSatelliteControllerUT.getCarrierEmergencyCallWaitForConnectionTimeoutMillis()); 4226 4227 // Both phones are in satellite mode for carrier roaming. The timeout duration of the first 4228 // phone will be selected 4229 when(mServiceState2.isUsingNonTerrestrialNetwork()).thenReturn(true); 4230 assertEquals(timeoutMillisForCarrier1, 4231 mSatelliteControllerUT.getCarrierEmergencyCallWaitForConnectionTimeoutMillis()); 4232 } 4233 4234 @Test testIsCarrierRoamingNtnEligible()4235 public void testIsCarrierRoamingNtnEligible() { 4236 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(false); 4237 assertFalse(mSatelliteControllerUT.isCarrierRoamingNtnEligible(null)); 4238 4239 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 4240 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 4241 when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); 4242 when(mServiceState2.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); 4243 mSatelliteControllerUT.mIsApplicationSupportsP2P = true; 4244 mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, true); 4245 mCarrierConfigBundle.putInt(KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT, 1); 4246 mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ROAMING_P2P_SMS_SUPPORTED_BOOL, true); 4247 int[] supportedServices2 = {2}; 4248 int[] supportedServices3 = {1, 3}; 4249 PersistableBundle carrierSupportedSatelliteServicesPerProvider = new PersistableBundle(); 4250 carrierSupportedSatelliteServicesPerProvider.putIntArray( 4251 "00102", supportedServices2); 4252 carrierSupportedSatelliteServicesPerProvider.putIntArray( 4253 "00103", supportedServices3); 4254 mCarrierConfigBundle.putPersistableBundle(CarrierConfigManager 4255 .KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE, 4256 carrierSupportedSatelliteServicesPerProvider); 4257 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 4258 : mCarrierConfigChangedListenerList) { 4259 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 4260 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 4261 ); 4262 } 4263 mSatelliteControllerUT.setSatellitePhone(1); 4264 mSatelliteControllerUT.setSelectedSatelliteSubId(SUB_ID); 4265 mSatelliteControllerUT.isSatelliteProvisioned = true; 4266 mSatelliteControllerUT.setIsSatelliteAllowedState(true); 4267 processAllMessages(); 4268 4269 assertTrue(mSatelliteControllerUT.isCarrierRoamingNtnEligible(mPhone)); 4270 4271 when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE); 4272 when(mServiceState2.getState()).thenReturn(ServiceState.STATE_IN_SERVICE); 4273 processAllMessages(); 4274 assertFalse(mSatelliteControllerUT.isCarrierRoamingNtnEligible(mPhone)); 4275 4276 when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE); 4277 when(mServiceState2.getState()).thenReturn(ServiceState.STATE_IN_SERVICE); 4278 mSatelliteControllerUT.overrideCarrierRoamingNtnEligibilityChanged(true, false); 4279 processAllMessages(); 4280 assertTrue(mSatelliteControllerUT.isCarrierRoamingNtnEligible(mPhone)); 4281 } 4282 4283 @Test testOverrideCarrierRoamingNtNEligibilityChange()4284 public void testOverrideCarrierRoamingNtNEligibilityChange() { 4285 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 4286 mSatelliteControllerUT.overrideCarrierRoamingNtnEligibilityChanged(true, false); 4287 verify(mPhone, times(1)).notifyCarrierRoamingNtnEligibleStateChanged(eq(true)); 4288 clearInvocations(mPhone); 4289 4290 mSatelliteControllerUT.overrideCarrierRoamingNtnEligibilityChanged(false, false); 4291 verify(mPhone, times(1)).notifyCarrierRoamingNtnEligibleStateChanged(eq(false)); 4292 clearInvocations(mPhone); 4293 4294 mSatelliteControllerUT.overrideCarrierRoamingNtnEligibilityChanged(false, true); 4295 verify(mPhone, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(eq(true)); 4296 clearInvocations(mPhone); 4297 } 4298 4299 @Test testNotifyNtnEligibilityHysteresisTimedOut()4300 public void testNotifyNtnEligibilityHysteresisTimedOut() { 4301 mContextFixture.putBooleanResource( 4302 R.bool.config_satellite_should_notify_availability, true); 4303 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 4304 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 4305 when(mServiceState2.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); 4306 when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); 4307 mSatelliteControllerUT.mIsApplicationSupportsP2P = true; 4308 mSatelliteControllerUT.setIsSatelliteSupported(true); 4309 mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, true); 4310 mCarrierConfigBundle.putInt(KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT, 4311 CARRIER_ROAMING_NTN_CONNECT_MANUAL); 4312 mCarrierConfigBundle.putInt( 4313 KEY_CARRIER_SUPPORTED_SATELLITE_NOTIFICATION_HYSTERESIS_SEC_INT, 1 * 60); 4314 mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ROAMING_P2P_SMS_SUPPORTED_BOOL, true); 4315 int[] supportedServices2 = {2}; 4316 int[] supportedServices3 = {1, 3}; 4317 PersistableBundle carrierSupportedSatelliteServicesPerProvider = new PersistableBundle(); 4318 carrierSupportedSatelliteServicesPerProvider.putIntArray( 4319 "00102", supportedServices2); 4320 carrierSupportedSatelliteServicesPerProvider.putIntArray( 4321 "00103", supportedServices3); 4322 mCarrierConfigBundle.putPersistableBundle(CarrierConfigManager 4323 .KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE, 4324 carrierSupportedSatelliteServicesPerProvider); 4325 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 4326 : mCarrierConfigChangedListenerList) { 4327 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 4328 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 4329 ); 4330 } 4331 mSatelliteControllerUT.setSatellitePhone(1); 4332 mSatelliteControllerUT.setSelectedSatelliteSubId(SUB_ID); 4333 mSatelliteControllerUT.isSatelliteProvisioned = true; 4334 mSatelliteControllerUT.isSatelliteAllowedCallback = null; 4335 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 4336 mSatelliteControllerUT.setIsSatelliteAllowedState(true); 4337 processAllMessages(); 4338 mSatelliteControllerUT.elapsedRealtime = 0; 4339 assertTrue(mSatelliteControllerUT.isCarrierRoamingNtnEligible(mPhone)); 4340 verify(mPhone, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(eq(true)); 4341 verify(mPhone2, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(anyBoolean()); 4342 clearInvocations(mPhone); 4343 4344 // 2 minutes later and hysteresis timeout is 1 minute 4345 mSatelliteControllerUT.elapsedRealtime = 2 * 60 * 1000; 4346 moveTimeForward(2 * 60 * 1000); 4347 processAllMessages(); 4348 assertTrue(mSatelliteControllerUT.isCarrierRoamingNtnEligible(mPhone)); 4349 verify(mPhone, times(1)).notifyCarrierRoamingNtnEligibleStateChanged(eq(true)); 4350 verify(mPhone2, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(anyBoolean()); 4351 verify(mMockNotificationManager, times(1)).notifyAsUser(anyString(), anyInt(), any(), 4352 any()); 4353 clearInvocations(mPhone); 4354 4355 when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE); 4356 sendServiceStateChangedEvent(); 4357 processAllMessages(); 4358 assertFalse(mSatelliteControllerUT.isCarrierRoamingNtnEligible(mPhone)); 4359 verify(mPhone, times(1)).notifyCarrierRoamingNtnEligibleStateChanged(eq(false)); 4360 verify(mPhone2, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(anyBoolean()); 4361 } 4362 4363 @Test testNotifyCarrierRoamingNtnSignalStrengthChanged()4364 public void testNotifyCarrierRoamingNtnSignalStrengthChanged() { 4365 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 4366 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 4367 4368 sendSignalStrengthChangedEvent(mPhone.getPhoneId()); 4369 processAllMessages(); 4370 ArgumentCaptor<NtnSignalStrength> captor = ArgumentCaptor.forClass(NtnSignalStrength.class); 4371 verify(mPhone, times(1)).notifyCarrierRoamingNtnSignalStrengthChanged( 4372 captor.capture()); 4373 NtnSignalStrength actualSignalStrength = captor.getValue(); 4374 assertEquals(NTN_SIGNAL_STRENGTH_NONE, actualSignalStrength.getLevel()); 4375 clearInvocations(mPhone); 4376 4377 when(mSignalStrength.getLevel()).thenReturn(SignalStrength.SIGNAL_STRENGTH_GOOD); 4378 when(mPhone.getSignalStrength()).thenReturn(mSignalStrength); 4379 mCarrierConfigBundle.putInt(KEY_SATELLITE_CONNECTION_HYSTERESIS_SEC_INT, 1 * 60); 4380 mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, true); 4381 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 4382 : mCarrierConfigChangedListenerList) { 4383 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 4384 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 4385 ); 4386 } 4387 processAllMessages(); 4388 when(mServiceState.isUsingNonTerrestrialNetwork()).thenReturn(true); 4389 when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE); 4390 sendServiceStateChangedEvent(); 4391 processAllMessages(); 4392 captor = ArgumentCaptor.forClass(NtnSignalStrength.class); 4393 verify(mPhone, times(1)).notifyCarrierRoamingNtnSignalStrengthChanged( 4394 captor.capture()); 4395 actualSignalStrength = captor.getValue(); 4396 assertEquals(NTN_SIGNAL_STRENGTH_GOOD, actualSignalStrength.getLevel()); 4397 clearInvocations(mPhone); 4398 } 4399 4400 @Test testGetWwanIsInService()4401 public void testGetWwanIsInService() { 4402 when(mServiceState.getNetworkRegistrationInfoListForTransportType( 4403 eq(AccessNetworkConstants.TRANSPORT_TYPE_WWAN))) 4404 .thenReturn(new ArrayList<>()); 4405 assertFalse(mSatelliteControllerUT.getWwanIsInService(mServiceState)); 4406 4407 NetworkRegistrationInfo nri = new NetworkRegistrationInfo.Builder() 4408 .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME) 4409 .build(); 4410 when(mServiceState.getNetworkRegistrationInfoListForTransportType( 4411 eq(AccessNetworkConstants.TRANSPORT_TYPE_WWAN))) 4412 .thenReturn(List.of(nri)); 4413 assertTrue(mSatelliteControllerUT.getWwanIsInService(mServiceState)); 4414 4415 nri = new NetworkRegistrationInfo.Builder() 4416 .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING) 4417 .build(); 4418 when(mServiceState.getNetworkRegistrationInfoListForTransportType( 4419 eq(AccessNetworkConstants.TRANSPORT_TYPE_WWAN))) 4420 .thenReturn(List.of(nri)); 4421 assertTrue(mSatelliteControllerUT.getWwanIsInService(mServiceState)); 4422 4423 nri = new NetworkRegistrationInfo.Builder().setRegistrationState( 4424 NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING) 4425 .build(); 4426 when(mServiceState.getNetworkRegistrationInfoListForTransportType( 4427 eq(AccessNetworkConstants.TRANSPORT_TYPE_WWAN))) 4428 .thenReturn(List.of(nri)); 4429 assertFalse(mSatelliteControllerUT.getWwanIsInService(mServiceState)); 4430 } 4431 4432 @Test testRegistrationFailureCallback()4433 public void testRegistrationFailureCallback() { 4434 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 4435 Semaphore semaphore = new Semaphore(0); 4436 final int[] resultErrorCode = new int[1]; 4437 ISatelliteModemStateCallback callback = new ISatelliteModemStateCallback.Stub() { 4438 @Override 4439 public void onSatelliteModemStateChanged(int state) { 4440 logd("onSatelliteModemStateChanged: state=" + state); 4441 } 4442 4443 @Override 4444 public void onEmergencyModeChanged(boolean isEmergency) { 4445 logd("onEmergencyModeChanged: emergency=" + isEmergency); 4446 } 4447 4448 @Override 4449 public void onRegistrationFailure(int causeCode) { 4450 logd("onRegistrationFailure: causeCode=" + causeCode); 4451 resultErrorCode[0] = causeCode; 4452 semaphore.release(); 4453 } 4454 4455 @Override 4456 public void onTerrestrialNetworkAvailableChanged(boolean isAvailable) { 4457 logd("onTerrestrialNetworkAvailableChanged: isAvailable=" + isAvailable); 4458 } 4459 }; 4460 resetSatelliteControllerUTToSupportedAndProvisionedState(); 4461 mSatelliteControllerUT.setSatelliteSessionController(mMockSatelliteSessionController); 4462 4463 int RegisterErrorCode = mSatelliteControllerUT.registerForSatelliteModemStateChanged( 4464 callback); 4465 assertEquals(SATELLITE_RESULT_SUCCESS, RegisterErrorCode); 4466 verify(mMockSatelliteSessionController).registerForSatelliteModemStateChanged(callback); 4467 4468 int expectedErrorCode = 100; 4469 mIIntegerConsumerResults.clear(); 4470 sendSatelliteRegistrationFailureEvent(100, null); 4471 processAllMessages(); 4472 assertTrue(waitForForEvents( 4473 semaphore, 1, "testRegistrationFailureCallback")); 4474 assertEquals(expectedErrorCode, resultErrorCode[0]); 4475 } 4476 4477 @RequiresFlagsDisabled(FLAG_DEVICE_STATE_PROPERTY_MIGRATION) 4478 @Test testDetermineIsFoldable_overlayConfigurationValues()4479 public void testDetermineIsFoldable_overlayConfigurationValues() { 4480 // isFoldable should return false with the base configuration. 4481 assertFalse(mSatelliteControllerUT.isFoldable(mContext, 4482 mSatelliteControllerUT.getSupportedDeviceStates())); 4483 4484 mContextFixture.putIntArrayResource(R.array.config_foldedDeviceStates, new int[2]); 4485 assertTrue(mSatelliteControllerUT.isFoldable(mContext, 4486 mSatelliteControllerUT.getSupportedDeviceStates())); 4487 } 4488 4489 @RequiresFlagsEnabled(FLAG_DEVICE_STATE_PROPERTY_MIGRATION) 4490 @Test testDetermineIsFoldable_deviceStateManager()4491 public void testDetermineIsFoldable_deviceStateManager() { 4492 // isFoldable should return false with the base configuration. 4493 assertFalse(mSatelliteControllerUT.isFoldable(mContext, 4494 mSatelliteControllerUT.getSupportedDeviceStates())); 4495 4496 DeviceState foldedDeviceState = new DeviceState(new DeviceState.Configuration.Builder( 4497 0 /* identifier */, "FOLDED") 4498 .setSystemProperties(Set.of(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY)) 4499 .setPhysicalProperties( 4500 Set.of(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED)) 4501 .build()); 4502 DeviceState unfoldedDeviceState = new DeviceState(new DeviceState.Configuration.Builder( 4503 1 /* identifier */, "UNFOLDED") 4504 .setSystemProperties(Set.of(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY)) 4505 .setPhysicalProperties( 4506 Set.of(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_OPEN)) 4507 .build()); 4508 List<DeviceState> foldableDeviceStateList = List.of(foldedDeviceState, unfoldedDeviceState); 4509 assertTrue(mSatelliteControllerUT.isFoldable(mContext, foldableDeviceStateList)); 4510 } 4511 4512 @Test testTerrestrialNetworkAvailableChangedCallback()4513 public void testTerrestrialNetworkAvailableChangedCallback() { 4514 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 4515 Semaphore semaphore = new Semaphore(0); 4516 final int[] receivedScanResult = new int[1]; 4517 ISatelliteModemStateCallback callback = new ISatelliteModemStateCallback.Stub() { 4518 @Override 4519 public void onSatelliteModemStateChanged(int state) { 4520 logd("onSatelliteModemStateChanged: state=" + state); 4521 } 4522 4523 @Override 4524 public void onEmergencyModeChanged(boolean isEmergency) { 4525 logd("onEmergencyModeChanged: emergency=" + isEmergency); 4526 } 4527 4528 @Override 4529 public void onRegistrationFailure(int causeCode) { 4530 logd("onRegistrationFailure: causeCode=" + causeCode); 4531 } 4532 4533 @Override 4534 public void onTerrestrialNetworkAvailableChanged(boolean isAvailable) { 4535 logd("onTerrestrialNetworkAvailableChanged: isAvailable=" + isAvailable); 4536 receivedScanResult[0] = isAvailable ? 1 : 0; 4537 semaphore.release(); 4538 } 4539 }; 4540 resetSatelliteControllerUTToSupportedAndProvisionedState(); 4541 mSatelliteControllerUT.setSatelliteSessionController(mMockSatelliteSessionController); 4542 4543 int RegisterErrorCode = mSatelliteControllerUT.registerForSatelliteModemStateChanged( 4544 callback); 4545 assertEquals(SATELLITE_RESULT_SUCCESS, RegisterErrorCode); 4546 verify(mMockSatelliteSessionController).registerForSatelliteModemStateChanged(callback); 4547 4548 int expectedErrorCode = 1; 4549 mIIntegerConsumerResults.clear(); 4550 sendTerrestrialNetworkAvailableChangedEvent(true, null); 4551 processAllMessages(); 4552 assertTrue(waitForForEvents( 4553 semaphore, 1, "testRegistrationFailureCallback")); 4554 assertEquals(expectedErrorCode, receivedScanResult[0]); 4555 } 4556 4557 private boolean mProvisionState = false; 4558 private int mProvisionSateResultCode = -1; 4559 private Semaphore mProvisionSateSemaphore = new Semaphore(0); 4560 private ResultReceiver mProvisionSatelliteReceiver = new ResultReceiver(null) { 4561 @Override 4562 protected void onReceiveResult(int resultCode, Bundle resultData) { 4563 mProvisionSateResultCode = resultCode; 4564 logd("mProvisionSatelliteReceiver: resultCode=" + resultCode); 4565 if (resultCode == SATELLITE_RESULT_SUCCESS) { 4566 if (resultData.containsKey(KEY_PROVISION_SATELLITE_TOKENS)) { 4567 mProvisionState = resultData.getBoolean(KEY_PROVISION_SATELLITE_TOKENS); 4568 logd("mProvisionSatelliteReceiver: mProvisionState=" + mProvisionState); 4569 } else { 4570 loge("KEY_PROVISION_SATELLITE_TOKENS does not exist."); 4571 mProvisionState = false; 4572 } 4573 } else { 4574 mProvisionState = false; 4575 } 4576 try { 4577 mProvisionSateSemaphore.release(); 4578 } catch (Exception ex) { 4579 loge("mProvisionSatelliteReceiver: Got exception in releasing semaphore, ex=" + ex); 4580 } 4581 } 4582 }; 4583 4584 private List<SatelliteSubscriberProvisionStatus> 4585 mRequestSatelliteSubscriberProvisionStatusResultList = new ArrayList<>(); 4586 private int mRequestSatelliteSubscriberProvisionStatusResultCode = SATELLITE_RESULT_SUCCESS; 4587 private Semaphore mRequestSatelliteSubscriberProvisionStatusSemaphore = new Semaphore(0); 4588 private ResultReceiver mRequestSatelliteSubscriberProvisionStatusReceiver = new ResultReceiver( 4589 null) { 4590 @Override 4591 protected void onReceiveResult(int resultCode, Bundle resultData) { 4592 mRequestSatelliteSubscriberProvisionStatusResultCode = resultCode; 4593 logd("mRequestSatelliteSubscriberProvisionStatusReceiver: resultCode=" + resultCode); 4594 if (resultCode == SATELLITE_RESULT_SUCCESS) { 4595 if (resultData.containsKey(KEY_REQUEST_PROVISION_SUBSCRIBER_ID_TOKEN)) { 4596 mRequestSatelliteSubscriberProvisionStatusResultList = 4597 resultData.getParcelableArrayList( 4598 KEY_REQUEST_PROVISION_SUBSCRIBER_ID_TOKEN, 4599 SatelliteSubscriberProvisionStatus.class); 4600 } else { 4601 loge("KEY_REQUEST_PROVISION_SUBSCRIBER_ID_TOKEN does not exist."); 4602 mRequestSatelliteSubscriberProvisionStatusResultList = new ArrayList<>(); 4603 } 4604 } else { 4605 mRequestSatelliteSubscriberProvisionStatusResultList = new ArrayList<>(); 4606 } 4607 try { 4608 mRequestSatelliteSubscriberProvisionStatusSemaphore.release(); 4609 } catch (Exception ex) { 4610 loge("mRequestSatelliteSubscriberProvisionStatusReceiver: Got exception in " 4611 + "releasing " 4612 + "semaphore, ex=" + ex); 4613 } 4614 } 4615 }; 4616 4617 @Test testRequestSatelliteSubscriberProvisionStatus()4618 public void testRequestSatelliteSubscriberProvisionStatus() throws Exception { 4619 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 4620 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(true); 4621 verifyRequestSatelliteSubscriberProvisionStatus(); 4622 } 4623 verifyRequestSatelliteSubscriberProvisionStatus()4624 private void verifyRequestSatelliteSubscriberProvisionStatus() throws Exception { 4625 setSatelliteSubscriberTesting(true); 4626 List<SatelliteSubscriberInfo> list = getExpectedSatelliteSubscriberInfoList(); 4627 mCarrierConfigBundle.putBoolean(KEY_CARRIER_CONFIG_APPLIED_BOOL, true); 4628 mCarrierConfigBundle.putString(KEY_SATELLITE_NIDD_APN_NAME_STRING, mNiddApn); 4629 mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ESOS_SUPPORTED_BOOL, true); 4630 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 4631 : mCarrierConfigChangedListenerList) { 4632 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 4633 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 4634 ); 4635 } 4636 moveTimeForward(TimeUnit.MINUTES.toMillis(1)); 4637 processAllMessages(); 4638 4639 // Verify that calling requestSatelliteSubscriberProvisionStatus returns the expected 4640 // list of SatelliteSubscriberProvisionStatus. 4641 mSatelliteControllerUT.requestSatelliteSubscriberProvisionStatus( 4642 mRequestSatelliteSubscriberProvisionStatusReceiver); 4643 moveTimeForward(TimeUnit.MINUTES.toMillis(1)); 4644 processAllMessages(); 4645 assertEquals(SATELLITE_RESULT_SUCCESS, 4646 mRequestSatelliteSubscriberProvisionStatusResultCode); 4647 assertEquals(list.get(0), mRequestSatelliteSubscriberProvisionStatusResultList.get( 4648 0).getSatelliteSubscriberInfo()); 4649 } 4650 4651 @Test testProvisionSatellite()4652 public void testProvisionSatellite() throws Exception { 4653 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 4654 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(true); 4655 verifyRequestSatelliteSubscriberProvisionStatus(); 4656 List<SatelliteSubscriberInfo> inputList = getExpectedSatelliteSubscriberInfoList(); 4657 verifyProvisionSatellite(inputList); 4658 } 4659 verifyProvisionSatellite(List<SatelliteSubscriberInfo> inputList)4660 private void verifyProvisionSatellite(List<SatelliteSubscriberInfo> inputList) { 4661 doAnswer(invocation -> { 4662 Message message = (Message) invocation.getArguments()[1]; 4663 AsyncResult.forMessage(message, null, new SatelliteException(SATELLITE_RESULT_SUCCESS)); 4664 message.sendToTarget(); 4665 return null; 4666 }).when(mMockSatelliteModemInterface).updateSatelliteSubscription(anyString(), any()); 4667 4668 mSatelliteControllerUT.provisionSatellite(inputList, mProvisionSatelliteReceiver); 4669 processAllMessages(); 4670 assertEquals(SATELLITE_RESULT_SUCCESS, mProvisionSateResultCode); 4671 assertTrue(mProvisionState); 4672 } 4673 4674 @Test testRegisterForSatelliteSubscriptionProvisionStateChanged()4675 public void testRegisterForSatelliteSubscriptionProvisionStateChanged() throws Exception { 4676 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 4677 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(true); 4678 4679 Semaphore semaphore = new Semaphore(0); 4680 SatelliteSubscriberProvisionStatus[] resultArray = 4681 new SatelliteSubscriberProvisionStatus[2]; 4682 ISatelliteProvisionStateCallback callback = new ISatelliteProvisionStateCallback.Stub() { 4683 @Override 4684 public void onSatelliteProvisionStateChanged(boolean provisioned) { 4685 logd("onSatelliteProvisionStateChanged: provisioned=" + provisioned); 4686 } 4687 4688 @Override 4689 public void onSatelliteSubscriptionProvisionStateChanged( 4690 List<SatelliteSubscriberProvisionStatus> satelliteSubscriberProvisionStatus) { 4691 logd("onSatelliteSubscriptionProvisionStateChanged: " 4692 + satelliteSubscriberProvisionStatus); 4693 for (int i = 0; i < satelliteSubscriberProvisionStatus.size(); i++) { 4694 resultArray[i] = satelliteSubscriberProvisionStatus.get(i); 4695 } 4696 try { 4697 semaphore.release(); 4698 } catch (Exception ex) { 4699 loge("onSatelliteSubscriptionProvisionStateChanged: Got exception in releasing " 4700 + "semaphore, ex=" + ex); 4701 } 4702 } 4703 }; 4704 4705 TestSubscriptionManager testSubscriptionManager = new TestSubscriptionManager(); 4706 doAnswer(invocation -> { 4707 testSubscriptionManager.setIsSatelliteProvisionedForNonIpDatagram( 4708 invocation.getArgument(0), invocation.getArgument(1)); 4709 return null; 4710 }).when(mMockSubscriptionManagerService).setIsSatelliteProvisionedForNonIpDatagram(anyInt(), 4711 anyBoolean()); 4712 doAnswer(invocation -> testSubscriptionManager.isSatelliteProvisionedForNonIpDatagram( 4713 invocation.getArgument(0))).when( 4714 mMockSubscriptionManagerService).isSatelliteProvisionedForNonIpDatagram(anyInt()); 4715 4716 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 4717 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 4718 int errorCode = mSatelliteControllerUT.registerForSatelliteProvisionStateChanged(callback); 4719 processAllMessages(); 4720 assertEquals(SATELLITE_RESULT_SUCCESS, errorCode); 4721 4722 verifyRequestSatelliteSubscriberProvisionStatus(); 4723 4724 // Verify that onSatelliteSubscriptionProvisionStateChanged is called when requesting 4725 // provisioning for the first time. 4726 List<SatelliteSubscriberInfo> list = getExpectedSatelliteSubscriberInfoList(); 4727 List<SatelliteSubscriberInfo> inputList = new ArrayList<>(); 4728 inputList.add(list.get(0)); 4729 verifyProvisionSatellite(inputList); 4730 4731 verify(mMockSatelliteModemInterface, times(1)).updateSatelliteSubscription(anyString(), 4732 any()); 4733 assertTrue(waitForForEvents( 4734 semaphore, 1, "testRegisterForSatelliteSubscriptionProvisionStateChanged")); 4735 assertTrue(resultArray[0].isProvisioned()); 4736 assertEquals(mSubscriberId, resultArray[0].getSatelliteSubscriberInfo().getSubscriberId()); 4737 4738 // Request provisioning with SatelliteSubscriberInfo that has not been provisioned 4739 // before, and verify that onSatelliteSubscriptionProvisionStateChanged is called. 4740 inputList = new ArrayList<>(); 4741 inputList.add(list.get(1)); 4742 verifyProvisionSatellite(inputList); 4743 4744 assertTrue(waitForForEvents( 4745 semaphore, 1, "testRegisterForSatelliteSubscriptionProvisionStateChanged")); 4746 assertTrue(resultArray[1].isProvisioned()); 4747 assertEquals(mSubscriberId2, resultArray[1].getSatelliteSubscriberInfo().getSubscriberId()); 4748 4749 // Request provisioning with the same SatelliteSubscriberInfo that was previously 4750 // requested, and verify that onSatelliteSubscriptionProvisionStateChanged is not called. 4751 verifyProvisionSatellite(inputList); 4752 4753 assertFalse(waitForForEvents( 4754 semaphore, 1, "testRegisterForSatelliteSubscriptionProvisionStateChanged")); 4755 4756 // Request deprovision for subscriberID 2, verify that subscriberID 2 is set to 4757 // deprovision and that subscriberID 1 is set to provision. 4758 verifyDeprovisionSatellite(inputList); 4759 assertTrue(waitForForEvents( 4760 semaphore, 1, "testRegisterForSatelliteSubscriptionProvisionStateChanged")); 4761 assertFalse(resultArray[1].isProvisioned()); 4762 assertEquals(mSubscriberId2, resultArray[1].getSatelliteSubscriberInfo().getSubscriberId()); 4763 assertTrue(resultArray[0].isProvisioned()); 4764 assertEquals(mSubscriberId, resultArray[0].getSatelliteSubscriberInfo().getSubscriberId()); 4765 4766 // Request deprovision for subscriberID 1, verify that subscriberID 1 is set to deprovision. 4767 inputList = new ArrayList<>(); 4768 inputList.add(list.get(0)); 4769 verifyDeprovisionSatellite(inputList); 4770 assertTrue(waitForForEvents( 4771 semaphore, 1, "testRegisterForSatelliteSubscriptionProvisionStateChanged")); 4772 assertFalse(resultArray[1].isProvisioned()); 4773 assertEquals(mSubscriberId2, resultArray[1].getSatelliteSubscriberInfo().getSubscriberId()); 4774 assertFalse(resultArray[0].isProvisioned()); 4775 assertEquals(mSubscriberId, resultArray[0].getSatelliteSubscriberInfo().getSubscriberId()); 4776 4777 // Request provision for subscriberID 2, verify that subscriberID 2 is set to provision. 4778 inputList = new ArrayList<>(); 4779 inputList.add(list.get(1)); 4780 verifyProvisionSatellite(inputList); 4781 4782 assertTrue(waitForForEvents( 4783 semaphore, 1, "testRegisterForSatelliteSubscriptionProvisionStateChanged")); 4784 assertTrue(resultArray[1].isProvisioned()); 4785 assertEquals(mSubscriberId2, resultArray[1].getSatelliteSubscriberInfo().getSubscriberId()); 4786 assertFalse(resultArray[0].isProvisioned()); 4787 assertEquals(mSubscriberId, resultArray[0].getSatelliteSubscriberInfo().getSubscriberId()); 4788 } 4789 4790 private boolean mDeprovisionDone = false; 4791 private int mDeprovisionSateResultCode = -1; 4792 private Semaphore mDeprovisionSateSemaphore = new Semaphore(0); 4793 private ResultReceiver mDeprovisionSatelliteReceiver = new ResultReceiver(null) { 4794 @Override 4795 protected void onReceiveResult(int resultCode, Bundle resultData) { 4796 mDeprovisionSateResultCode = resultCode; 4797 logd("DeprovisionSatelliteReceiver: resultCode=" + resultCode); 4798 if (resultCode == SATELLITE_RESULT_SUCCESS) { 4799 if (resultData.containsKey(KEY_DEPROVISION_SATELLITE_TOKENS)) { 4800 mDeprovisionDone = resultData.getBoolean(KEY_DEPROVISION_SATELLITE_TOKENS); 4801 logd("DeprovisionSatelliteReceiver: deprovision=" + mDeprovisionDone); 4802 } else { 4803 loge("KEY_DEPROVISION_SATELLITE_TOKENS does not exist."); 4804 mDeprovisionDone = false; 4805 } 4806 } else { 4807 mDeprovisionDone = false; 4808 } 4809 try { 4810 mDeprovisionSateSemaphore.release(); 4811 } catch (Exception ex) { 4812 loge("DeprovisionSatelliteReceiver: Got exception in releasing semaphore " + ex); 4813 } 4814 } 4815 }; 4816 4817 @Test testDeprovisionSatellite()4818 public void testDeprovisionSatellite() throws Exception { 4819 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 4820 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(true); 4821 verifyRequestSatelliteSubscriberProvisionStatus(); 4822 List<SatelliteSubscriberInfo> inputList = getExpectedSatelliteSubscriberInfoList(); 4823 verifyProvisionSatellite(inputList); 4824 verifyDeprovisionSatellite(inputList); 4825 } 4826 verifyDeprovisionSatellite(List<SatelliteSubscriberInfo> inputList)4827 private void verifyDeprovisionSatellite(List<SatelliteSubscriberInfo> inputList) { 4828 doAnswer(invocation -> { 4829 Message message = (Message) invocation.getArguments()[1]; 4830 AsyncResult.forMessage(message, null, new SatelliteException(SATELLITE_RESULT_SUCCESS)); 4831 message.sendToTarget(); 4832 return null; 4833 }).when(mMockSatelliteModemInterface).updateSatelliteSubscription(anyString(), any()); 4834 4835 mSatelliteControllerUT.deprovisionSatellite(inputList, mDeprovisionSatelliteReceiver); 4836 processAllMessages(); 4837 assertEquals(SATELLITE_RESULT_SUCCESS, mDeprovisionSateResultCode); 4838 assertTrue(mDeprovisionDone); 4839 } 4840 setSatelliteSubscriberTesting(boolean sameCarrier)4841 private void setSatelliteSubscriberTesting(boolean sameCarrier) throws Exception { 4842 doReturn("123").when(mContext).getAttributionTag(); 4843 final int carrierId_subID = 0; 4844 final int carrierId_subID1 = sameCarrier ? 0 : 1; 4845 SubscriptionInfo subscriptionInfo = new SubscriptionInfo.Builder() 4846 .setId(SUB_ID).setIccId(mIccId).setSimSlotIndex(0).setOnlyNonTerrestrialNetwork( 4847 false).setSatelliteESOSSupported(true).setCarrierId( 4848 carrierId_subID).build(); 4849 SubscriptionInfo subscriptionInfo2 = new SubscriptionInfo.Builder() 4850 .setId(SUB_ID1).setIccId(mIccId2).setSimSlotIndex(1).setOnlyNonTerrestrialNetwork( 4851 true).setSatelliteESOSSupported(false).setCarrierId( 4852 carrierId_subID1).build(); 4853 List<SubscriptionInfo> allSubInfos = new ArrayList<>(); 4854 allSubInfos.add(subscriptionInfo); 4855 allSubInfos.add(subscriptionInfo2); 4856 testSubscriptionInfo = subscriptionInfo; 4857 testSubscriptionInfo2 = subscriptionInfo2; 4858 doReturn(allSubInfos).when(mMockSubscriptionManagerService).getAllSubInfoList( 4859 anyString(), anyString()); 4860 SubscriptionInfoInternal subInfoInternal = 4861 new SubscriptionInfoInternal.Builder().setCarrierId( 4862 carrierId_subID).setImsi(mImsi).setIccId(mIccId).build(); 4863 SubscriptionInfoInternal subInfoInternal2 = 4864 new SubscriptionInfoInternal.Builder().setCarrierId( 4865 carrierId_subID1).setImsi(mImsi2).setIccId(mIccId2).build(); 4866 doReturn(subscriptionInfo).when(mMockSubscriptionManagerService).getSubscriptionInfo( 4867 eq(SUB_ID)); 4868 doReturn(subscriptionInfo2).when(mMockSubscriptionManagerService).getSubscriptionInfo( 4869 eq(SUB_ID1)); 4870 Field field = SatelliteController.class.getDeclaredField("mInjectSubscriptionManager"); 4871 field.setAccessible(true); 4872 field.set(mSatelliteControllerUT, mSubscriptionManager); 4873 doReturn(mMsisdn).when(mSubscriptionManager).getPhoneNumber(eq(SUB_ID)); 4874 doReturn(mMsisdn2).when(mSubscriptionManager).getPhoneNumber(eq(SUB_ID1)); 4875 Field provisionedSubscriberIdField = SatelliteController.class.getDeclaredField( 4876 "mProvisionedSubscriberId"); 4877 provisionedSubscriberIdField.setAccessible(true); 4878 provisionedSubscriberIdField.set(mSatelliteControllerUT, new HashMap<>()); 4879 Field subscriberIdPerSubField = SatelliteController.class.getDeclaredField( 4880 "mSubscriberIdPerSub"); 4881 subscriberIdPerSubField.setAccessible(true); 4882 subscriberIdPerSubField.set(mSatelliteControllerUT, new HashMap<>()); 4883 Field lastConfiguredIccIdField = SatelliteController.class.getDeclaredField( 4884 "mLastConfiguredIccId"); 4885 lastConfiguredIccIdField.setAccessible(true); 4886 lastConfiguredIccIdField.set(mSatelliteControllerUT, null); 4887 doReturn(subInfoInternal).when(mMockSubscriptionManagerService).getSubscriptionInfoInternal( 4888 eq(SUB_ID)); 4889 doReturn(subInfoInternal2).when( 4890 mMockSubscriptionManagerService).getSubscriptionInfoInternal(eq(SUB_ID1)); 4891 doReturn(mResources).when(mContext).getResources(); 4892 doReturn("package").when(mResources).getString( 4893 eq(R.string.config_satellite_gateway_service_package)); 4894 doReturn("className").when(mResources).getString( 4895 eq(R.string.config_satellite_carrier_roaming_esos_provisioned_class)); 4896 } 4897 getExpectedSatelliteSubscriberInfoList()4898 private List<SatelliteSubscriberInfo> getExpectedSatelliteSubscriberInfoList() { 4899 List<SatelliteSubscriberInfo> list = new ArrayList<>(); 4900 list.add(new SatelliteSubscriberInfo.Builder().setSubscriberId(mSubscriberId).setCarrierId( 4901 mCarrierId).setNiddApn(mNiddApn).setSubId(SUB_ID).setSubscriberIdType( 4902 SatelliteSubscriberInfo.IMSI_MSISDN).build()); 4903 list.add(new SatelliteSubscriberInfo.Builder().setSubscriberId(mSubscriberId2).setCarrierId( 4904 mCarrierId).setNiddApn(mNiddApn).setSubId(SUB_ID1).setSubscriberIdType( 4905 SatelliteSubscriberInfo.ICCID).build()); 4906 return list; 4907 } 4908 4909 @Test testCheckForSubscriberIdChange_noChanged()4910 public void testCheckForSubscriberIdChange_noChanged() { 4911 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 4912 4913 String imsi = "012345"; 4914 String oldMsisdn = "1234567890"; 4915 String newMsisdn = "1234567890"; 4916 List<SubscriptionInfo> allSubInfos = new ArrayList<>(); 4917 Optional<String> getSubscriberId; 4918 SubscriptionInfoInternal subInfoInternal = 4919 new SubscriptionInfoInternal.Builder().setCarrierId(0) 4920 .setImsi(imsi).build(); 4921 4922 when(mSubscriptionInfo.getSubscriptionId()).thenReturn(SUB_ID); 4923 allSubInfos.add(mSubscriptionInfo); 4924 doReturn(" ").when(mContext).getOpPackageName(); 4925 doReturn(" ").when(mContext).getAttributionTag(); 4926 when(mMockSubscriptionManagerService.getAllSubInfoList(anyString(), anyString())) 4927 .thenReturn(allSubInfos); 4928 when(mSubscriptionInfo.isSatelliteESOSSupported()).thenReturn(true); 4929 when(mMockSubscriptionManagerService.getSubscriptionInfoInternal(SUB_ID)) 4930 .thenReturn(subInfoInternal); 4931 4932 try { 4933 Field field = SatelliteController.class.getDeclaredField("mInjectSubscriptionManager"); 4934 field.setAccessible(true); 4935 field.set(mSatelliteControllerUT, mSubscriptionManager); 4936 } catch (Exception e) { 4937 loge("Exception InjectSubscriptionManager e: " + e); 4938 } 4939 when(mSubscriptionManager.getPhoneNumber(SUB_ID)).thenReturn(newMsisdn); 4940 when(mSubscriptionInfo.isOnlyNonTerrestrialNetwork()).thenReturn(false); 4941 mSatelliteControllerUT.subscriberIdPerSub().put(imsi + oldMsisdn, SUB_ID); 4942 4943 getSubscriberId = mSatelliteControllerUT.subscriberIdPerSub().entrySet().stream() 4944 .filter(entry -> entry.getValue().equals(SUB_ID)) 4945 .map(Map.Entry::getKey).findFirst(); 4946 assertEquals(imsi + newMsisdn, getSubscriberId.get()); 4947 4948 setComponentName(); 4949 mSatelliteControllerUT.subsInfoListPerPriority().computeIfAbsent( 4950 getKeyPriority(mSubscriptionInfo), k -> new ArrayList<>()) 4951 .add(mSubscriptionInfo); 4952 mSatelliteControllerUT.evaluateESOSProfilesPrioritizationTest(); 4953 // Verify that broadcast has not been sent. 4954 verify(mContext, times(0)).sendBroadcast(any(Intent.class)); 4955 } 4956 4957 @Test testCheckForSubscriberIdChange_changed()4958 public void testCheckForSubscriberIdChange_changed() { 4959 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 4960 mCarrierConfigBundle.putBoolean(KEY_CARRIER_CONFIG_APPLIED_BOOL, true); 4961 List<SubscriptionInfo> allSubInfos = new ArrayList<>(); 4962 4963 String imsi = "012345"; 4964 String oldMsisdn = "1234567890"; 4965 String newMsisdn = "4567891234"; 4966 4967 Optional<String> getSubscriberId; 4968 SubscriptionInfoInternal subInfoInternal = 4969 new SubscriptionInfoInternal.Builder().setCarrierId(0).setImsi(imsi).build(); 4970 4971 when(mSubscriptionInfo.getSubscriptionId()).thenReturn(SUB_ID); 4972 allSubInfos.add(mSubscriptionInfo); 4973 doReturn(" ").when(mContext).getOpPackageName(); 4974 doReturn(" ").when(mContext).getAttributionTag(); 4975 when(mMockSubscriptionManagerService.getAllSubInfoList(anyString(), anyString())) 4976 .thenReturn(allSubInfos); 4977 4978 when(mSubscriptionInfo.isSatelliteESOSSupported()).thenReturn(true); 4979 when(mSubscriptionInfo.isActive()).thenReturn(true); 4980 when(mMockSubscriptionManagerService.getSubscriptionInfoInternal(SUB_ID)) 4981 .thenReturn(subInfoInternal); 4982 4983 try { 4984 Field field = SatelliteController.class.getDeclaredField("mInjectSubscriptionManager"); 4985 field.setAccessible(true); 4986 field.set(mSatelliteControllerUT, mSubscriptionManager); 4987 } catch (Exception e) { 4988 loge("Exception InjectSubscriptionManager e: " + e); 4989 } 4990 when(mSubscriptionManager.getPhoneNumber(SUB_ID)).thenReturn(newMsisdn); 4991 when(mSubscriptionInfo.isOnlyNonTerrestrialNetwork()).thenReturn(false); 4992 mSatelliteControllerUT.subscriberIdPerSub().put(imsi + oldMsisdn, SUB_ID); 4993 4994 getSubscriberId = mSatelliteControllerUT.subscriberIdPerSub().entrySet().stream() 4995 .filter(entry -> entry.getValue().equals(SUB_ID)) 4996 .map(Map.Entry::getKey).findFirst(); 4997 assertNotEquals(imsi + newMsisdn, getSubscriberId.get()); 4998 4999 setComponentName(); 5000 mSatelliteControllerUT.subsInfoListPerPriority().computeIfAbsent( 5001 getKeyPriority(mSubscriptionInfo), k -> new ArrayList<>()) 5002 .add(mSubscriptionInfo); 5003 mSatelliteControllerUT.evaluateESOSProfilesPrioritizationTest(); 5004 // Verify that broadcast has been sent. 5005 verify(mContext, times(1)).sendBroadcast(any(Intent.class)); 5006 } 5007 5008 @Test testRegisterForSatelliteCommunicationAllowedStateChanged()5009 public void testRegisterForSatelliteCommunicationAllowedStateChanged() throws Exception { 5010 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 5011 mContextFixture.putIntArrayResource( 5012 R.array.config_verizon_satellite_enabled_tagids, 5013 new int[]{1001}); 5014 when(mContext.getResources()).thenReturn(mResources); 5015 when(mResources.getIntArray( 5016 R.array.config_verizon_satellite_enabled_tagids)).thenReturn(new int[]{1001}); 5017 // carrierID is same as SUBID for this test 5018 final int carrierSubId = SUB_ID; 5019 final int oemSubId = SUB_ID1; 5020 final String carrierSubscriberId = mSubscriberId; 5021 final String oemSubscriberId = mSubscriberId2; 5022 mCarrierConfigBundle.putBoolean(KEY_CARRIER_CONFIG_APPLIED_BOOL, true); 5023 setSatelliteSubscriberTesting(false); 5024 invokeCarrierConfigChanged(); 5025 5026 Field provisionedSubscriberIdField = SatelliteController.class.getDeclaredField( 5027 "mProvisionedSubscriberId"); 5028 provisionedSubscriberIdField.setAccessible(true); 5029 Map<String, Boolean> testProvisionedSubscriberId = new HashMap<>();; 5030 testProvisionedSubscriberId.put(carrierSubscriberId, true); 5031 testProvisionedSubscriberId.put(oemSubscriberId, true); 5032 provisionedSubscriberIdField.set(mSatelliteControllerUT, testProvisionedSubscriberId); 5033 5034 Field currentLocationTagIdsField = SatelliteController.class.getDeclaredField( 5035 "mCurrentLocationTagIds"); 5036 currentLocationTagIdsField.setAccessible(true); 5037 5038 setComponentName(); 5039 mSatelliteControllerUT.setIsSatelliteAllowedState(true); 5040 5041 mSatelliteControllerUT.registerForSatelliteCommunicationAllowedStateChanged(); 5042 5043 // Test satelliteAccessConfigCallback.onSuccess 5044 // with current location NOT supporting carrier satellite 5045 // OEM satellite subscription should be selected 5046 currentLocationTagIdsField.set(mSatelliteControllerUT, Arrays.asList(100)); 5047 5048 mSatelliteControllerUT.subsInfoListPerPriority().computeIfAbsent( 5049 getKeyPriority(testSubscriptionInfo), k -> new ArrayList<>()) 5050 .add(testSubscriptionInfo); 5051 mSatelliteControllerUT.subsInfoListPerPriority().computeIfAbsent( 5052 getKeyPriority(testSubscriptionInfo2), k -> new ArrayList<>()) 5053 .add(testSubscriptionInfo2); 5054 5055 mSatelliteControllerUT.evaluateESOSProfilesPrioritizationTest(); 5056 processAllMessages(); 5057 assertEquals(oemSubId, mSatelliteControllerUT.getSelectedSatelliteSubId()); 5058 5059 // Test satelliteAccessConfigCallback.onSuccess 5060 // with current location supporting carrier satellite 5061 // Carrier satellite subscription should be selected 5062 currentLocationTagIdsField.set(mSatelliteControllerUT, Arrays.asList(1001, 100)); 5063 5064 mSatelliteControllerUT.subsInfoListPerPriority().computeIfAbsent( 5065 getKeyPriority(testSubscriptionInfo), k -> new ArrayList<>()) 5066 .add(testSubscriptionInfo); 5067 mSatelliteControllerUT.subsInfoListPerPriority().computeIfAbsent( 5068 getKeyPriority(testSubscriptionInfo2), k -> new ArrayList<>()) 5069 .add(testSubscriptionInfo2); 5070 5071 mSatelliteControllerUT.evaluateESOSProfilesPrioritizationTest(); 5072 processAllMessages(); 5073 assertEquals(carrierSubId, mSatelliteControllerUT.getSelectedSatelliteSubId()); 5074 } 5075 5076 5077 @Test testProvisionStatusPerSubscriberIdGetFromDb()5078 public void testProvisionStatusPerSubscriberIdGetFromDb() throws Exception { 5079 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 5080 5081 setSatelliteSubscriberTesting(true); 5082 // Check if the cache is not updated when the value read from the database is false. 5083 verifyProvisionStatusPerSubscriberIdGetFromDb(false); 5084 5085 // Check if the cache is updated when the value read from the database is true. 5086 verifyProvisionStatusPerSubscriberIdGetFromDb(true); 5087 } 5088 5089 @Test testProvisionStatusPerSubscriberIdStoreToDb()5090 public void testProvisionStatusPerSubscriberIdStoreToDb() throws Exception { 5091 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 5092 5093 setSatelliteSubscriberTesting(true); 5094 // Check if the cache is not updated when the value read from the database is false. 5095 verifyProvisionStatusPerSubscriberIdGetFromDb(false); 5096 5097 List<SatelliteSubscriberInfo> inputList = getExpectedSatelliteSubscriberInfoList(); 5098 verifyProvisionSatellite(inputList); 5099 verify(mMockSubscriptionManagerService).setIsSatelliteProvisionedForNonIpDatagram( 5100 eq(SUB_ID), eq(true)); 5101 } 5102 5103 @Test testIsCarrierRoamingNtnAvailableServicesForManualConnect()5104 public void testIsCarrierRoamingNtnAvailableServicesForManualConnect() { 5105 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 5106 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 5107 mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, true); 5108 // CARRIER_ROAMING_NTN_CONNECT_MANUAL: 1 5109 mCarrierConfigBundle.putInt(KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT, 1); 5110 5111 mSatelliteControllerUT.setSatellitePhone(1); 5112 processAllMessages(); 5113 when(mContext.getPackageManager()).thenReturn(mMockPManager); 5114 try { 5115 when(mMockPManager.getApplicationInfo(anyString(), 5116 anyInt())).thenReturn(getApplicationInfo()); 5117 } catch (PackageManager.NameNotFoundException e) { 5118 logd("NameNotFoundException"); 5119 } 5120 assertTrue(mSatelliteControllerUT 5121 .isP2PSmsDisallowedOnCarrierRoamingNtn(/*subId*/ SUB_ID)); 5122 } 5123 5124 @Test testIsCarrierRoamingNtnAvailableServicesForAutomaticConnect()5125 public void testIsCarrierRoamingNtnAvailableServicesForAutomaticConnect() { 5126 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 5127 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 5128 mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, true); 5129 // CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC: 0 5130 mCarrierConfigBundle.putInt(KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT, 0); 5131 5132 mSatelliteControllerUT.setSatellitePhone(1); 5133 processAllMessages(); 5134 when(mContext.getPackageManager()).thenReturn(mMockPManager); 5135 try { 5136 when(mMockPManager.getApplicationInfo(anyString(), 5137 anyInt())).thenReturn(getApplicationInfo()); 5138 } catch (PackageManager.NameNotFoundException e) { 5139 logd("NameNotFoundException"); 5140 } 5141 // If it is automatic connection case, it is not support the callback. 5142 assertFalse(mSatelliteControllerUT 5143 .isP2PSmsDisallowedOnCarrierRoamingNtn(/*subId*/ SUB_ID)); 5144 } 5145 getApplicationInfo()5146 ApplicationInfo getApplicationInfo() { 5147 ApplicationInfo applicationInfo = new ApplicationInfo(); 5148 applicationInfo.metaData = new Bundle(); 5149 applicationInfo.metaData.putBoolean( 5150 METADATA_SATELLITE_MANUAL_CONNECT_P2P_SUPPORT, true); 5151 return applicationInfo; 5152 } 5153 5154 @Test testRegisterApplicationStateChanged()5155 public void testRegisterApplicationStateChanged() { 5156 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 5157 mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, false); 5158 when(mMockSubscriptionManagerService.getActiveSubIdList(true)) 5159 .thenReturn(new int[]{SUB_ID1}); 5160 5161 ArgumentCaptor<IntentFilter> intentFilterCaptor = 5162 ArgumentCaptor.forClass(IntentFilter.class); 5163 ArgumentCaptor<BroadcastReceiver> receiverCaptor = 5164 ArgumentCaptor.forClass(BroadcastReceiver.class); 5165 verify(mContext).registerReceiver(receiverCaptor.capture(), intentFilterCaptor.capture(), 5166 anyInt()); 5167 5168 BroadcastReceiver receiver = receiverCaptor.getValue(); 5169 mSatelliteControllerUT = 5170 new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); 5171 assertFalse(mSatelliteControllerUT.isApplicationUpdated); 5172 Intent intent = new Intent(Intent.ACTION_PACKAGE_ADDED); 5173 intent.setData(Uri.parse("com.example.app")); 5174 receiver.onReceive(mContext, intent); 5175 CountDownLatch latch1 = new CountDownLatch(1); 5176 new Handler(Looper.getMainLooper()).postDelayed(() -> { 5177 latch1.countDown(); 5178 }, 100); 5179 try { 5180 latch1.await(); 5181 } catch (InterruptedException e) { 5182 } 5183 assertTrue(mSatelliteControllerUT.isApplicationUpdated); 5184 mSatelliteControllerUT = 5185 new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); 5186 assertFalse(mSatelliteControllerUT.isApplicationUpdated); 5187 intent = new Intent(Intent.ACTION_PACKAGE_REPLACED); 5188 intent.setData(Uri.parse("com.example.app")); 5189 receiver.onReceive(mContext, intent); 5190 CountDownLatch latch2 = new CountDownLatch(1); 5191 new Handler(Looper.getMainLooper()).postDelayed(() -> { 5192 latch2.countDown(); 5193 }, 100); 5194 try { 5195 latch2.await(); 5196 } catch (InterruptedException e) { 5197 } 5198 assertTrue(mSatelliteControllerUT.isApplicationUpdated); 5199 mSatelliteControllerUT = 5200 new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); 5201 assertFalse(mSatelliteControllerUT.isApplicationUpdated); 5202 intent = new Intent(Intent.ACTION_PACKAGE_REMOVED); 5203 intent.setData(Uri.parse("com.example.app")); 5204 receiver.onReceive(mContext, intent); 5205 CountDownLatch latch3 = new CountDownLatch(1); 5206 new Handler(Looper.getMainLooper()).postDelayed(() -> { 5207 latch3.countDown(); 5208 }, 100); 5209 try { 5210 latch3.await(); 5211 } catch (InterruptedException e) { 5212 } 5213 assertTrue(mSatelliteControllerUT.isApplicationUpdated); 5214 mSatelliteControllerUT = 5215 new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); 5216 assertFalse(mSatelliteControllerUT.isApplicationUpdated); 5217 intent = new Intent(Intent.ACTION_PACKAGE_ADDED); 5218 intent.setData(Uri.parse("com.example.different")); 5219 receiver.onReceive(mContext, intent); 5220 CountDownLatch latch4 = new CountDownLatch(1); 5221 new Handler(Looper.getMainLooper()).postDelayed(() -> { 5222 latch4.countDown(); 5223 }, 100); 5224 try { 5225 latch4.await(); 5226 } catch (InterruptedException e) { 5227 } 5228 assertFalse(mSatelliteControllerUT.isApplicationUpdated); 5229 } 5230 5231 @Test testUpdateSystemSelectionChannels()5232 public void testUpdateSystemSelectionChannels() { 5233 when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(true); 5234 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 5235 5236 String mccmnc = "123455"; 5237 int[] bands1 = {200, 201, 202}; 5238 IntArray intArraybands1 = new IntArray(3); 5239 intArraybands1.addAll(bands1); 5240 int[] earfcns1 = {300, 301, 310, 311}; 5241 IntArray intArrayEarfcns1 = new IntArray(4); 5242 intArrayEarfcns1.addAll(earfcns1); 5243 String seed1 = "test-seed-satellite1"; 5244 UUID uuid1 = UUID.nameUUIDFromBytes(seed1.getBytes()); 5245 SatellitePosition satellitePosition1 = new SatellitePosition(0, 35876); 5246 EarfcnRange earfcnRange1 = new EarfcnRange(301, 300); 5247 EarfcnRange earfcnRange2 = new EarfcnRange(311, 310); 5248 List<EarfcnRange> earfcnRangeList1 = new ArrayList<>( 5249 Arrays.asList(earfcnRange1, earfcnRange2)); 5250 SatelliteInfo satelliteInfo1 = new SatelliteInfo(uuid1, satellitePosition1, Arrays.stream( 5251 bands1).boxed().collect(Collectors.toList()), earfcnRangeList1); 5252 int[] tagIds = {1, 2, 3}; 5253 IntArray intArrayTagIds = new IntArray(3); 5254 intArrayTagIds.addAll(tagIds); 5255 SystemSelectionSpecifier systemSelectionSpecifier1 = new SystemSelectionSpecifier(mccmnc, 5256 intArraybands1, intArrayEarfcns1, new SatelliteInfo[]{satelliteInfo1}, 5257 intArrayTagIds); 5258 5259 setUpResponseForUpdateSystemSelectionChannels(SATELLITE_RESULT_ERROR); 5260 mSatelliteControllerUT.updateSystemSelectionChannels( 5261 new ArrayList<>(List.of(systemSelectionSpecifier1)), 5262 mSystemSelectionChannelUpdatedReceiver); 5263 processAllMessages(); 5264 assertTrue(waitForRequestUpdateSystemSelectionChannelResult(1)); 5265 assertEquals(SATELLITE_RESULT_ERROR, mQueriedSystemSelectionChannelUpdatedResultCode); 5266 5267 // Verify whether callback receives expected result 5268 setUpResponseForUpdateSystemSelectionChannels(SATELLITE_RESULT_SUCCESS); 5269 mSatelliteControllerUT.updateSystemSelectionChannels( 5270 new ArrayList<>(List.of(systemSelectionSpecifier1)), 5271 mSystemSelectionChannelUpdatedReceiver); 5272 processAllMessages(); 5273 assertTrue(waitForRequestUpdateSystemSelectionChannelResult(1)); 5274 assertEquals(SATELLITE_RESULT_SUCCESS, mQueriedSystemSelectionChannelUpdatedResultCode); 5275 5276 // Verify whether SatelliteModemInterface API was invoked and data is valid, when single 5277 // data was provided. 5278 ArgumentCaptor<List<SystemSelectionSpecifier>> systemSelectionSpecifierListCaptor = 5279 ArgumentCaptor.forClass(List.class); 5280 verify(mMockSatelliteModemInterface, times(2)).updateSystemSelectionChannels( 5281 systemSelectionSpecifierListCaptor.capture(), any(Message.class)); 5282 List<SystemSelectionSpecifier> capturedList = systemSelectionSpecifierListCaptor.getValue(); 5283 SystemSelectionSpecifier systemSelectionSpecifier = capturedList.getFirst(); 5284 5285 assertEquals(mccmnc, systemSelectionSpecifier.getMccMnc()); 5286 int[] actualBandsArray = systemSelectionSpecifier.getBands(); 5287 assertArrayEquals(bands1, actualBandsArray); 5288 int[] actualEarfcnsArray = systemSelectionSpecifier.getEarfcns(); 5289 assertArrayEquals(earfcns1, actualEarfcnsArray); 5290 assertArrayEquals(new SatelliteInfo[]{satelliteInfo1}, 5291 systemSelectionSpecifier.getSatelliteInfos().toArray(new SatelliteInfo[0])); 5292 int[] actualTagIdArray = systemSelectionSpecifier.getTagIds(); 5293 assertArrayEquals(tagIds, actualTagIdArray); 5294 5295 // Verify whether SatelliteModemInterface API was invoked and data is valid, when list 5296 // of data was provided. 5297 int[] bands2 = {210, 211, 212}; 5298 IntArray intArraybands2 = new IntArray(3); 5299 intArraybands2.addAll(bands2); 5300 int[] earfcns2 = {320, 321, 330, 331}; 5301 IntArray intArrayEarfcns2 = new IntArray(4); 5302 intArrayEarfcns2.addAll(earfcns2); 5303 String seed2 = "test-seed-satellite2"; 5304 UUID uuid2 = UUID.nameUUIDFromBytes(seed2.getBytes()); 5305 SatellitePosition satellitePosition2 = new SatellitePosition(120, 35876); 5306 EarfcnRange earfcnRange3 = new EarfcnRange(321, 320); 5307 EarfcnRange earfcnRange4 = new EarfcnRange(331, 330); 5308 List<EarfcnRange> earfcnRangeList2 = new ArrayList<>( 5309 Arrays.asList(earfcnRange3, earfcnRange4)); 5310 SatelliteInfo satelliteInfo2 = new SatelliteInfo(uuid2, satellitePosition2, Arrays.stream( 5311 bands1).boxed().collect(Collectors.toList()), earfcnRangeList2); 5312 SystemSelectionSpecifier systemSelectionSpecifier2 = new SystemSelectionSpecifier(mccmnc, 5313 intArraybands2, intArrayEarfcns2, new SatelliteInfo[]{satelliteInfo2}, 5314 intArrayTagIds); 5315 5316 // Verify whether callback receives expected result 5317 setUpResponseForUpdateSystemSelectionChannels(SATELLITE_RESULT_SUCCESS); 5318 mSatelliteControllerUT.updateSystemSelectionChannels( 5319 new ArrayList<>(List.of(systemSelectionSpecifier1, systemSelectionSpecifier2)), 5320 mSystemSelectionChannelUpdatedReceiver); 5321 processAllMessages(); 5322 assertTrue(waitForRequestUpdateSystemSelectionChannelResult(1)); 5323 assertEquals(SATELLITE_RESULT_SUCCESS, mQueriedSystemSelectionChannelUpdatedResultCode); 5324 5325 // Verify whether SatelliteModemInterface API was invoked and data is valid, 5326 verify(mMockSatelliteModemInterface, times(3)).updateSystemSelectionChannels( 5327 systemSelectionSpecifierListCaptor.capture(), any(Message.class)); 5328 capturedList = systemSelectionSpecifierListCaptor.getValue(); 5329 SystemSelectionSpecifier capturedSystemSelectionSpecifier1 = capturedList.getFirst(); 5330 SystemSelectionSpecifier capturedSystemSelectionSpecifier2 = capturedList.get(1); 5331 5332 // Verify first SystemSelectionSpecifier 5333 assertEquals(mccmnc, systemSelectionSpecifier.getMccMnc()); 5334 actualBandsArray = capturedSystemSelectionSpecifier1.getBands(); 5335 assertArrayEquals(bands1, actualBandsArray); 5336 actualEarfcnsArray = capturedSystemSelectionSpecifier1.getEarfcns(); 5337 assertArrayEquals(earfcns1, actualEarfcnsArray); 5338 assertArrayEquals(new SatelliteInfo[]{satelliteInfo1}, 5339 capturedSystemSelectionSpecifier1.getSatelliteInfos().toArray( 5340 new SatelliteInfo[0])); 5341 actualTagIdArray = capturedSystemSelectionSpecifier1.getTagIds(); 5342 assertArrayEquals(tagIds, actualTagIdArray); 5343 5344 // Verify second SystemSelectionSpecifier 5345 assertEquals(mccmnc, systemSelectionSpecifier.getMccMnc()); 5346 actualBandsArray = capturedSystemSelectionSpecifier2.getBands(); 5347 assertArrayEquals(bands2, actualBandsArray); 5348 actualEarfcnsArray = capturedSystemSelectionSpecifier2.getEarfcns(); 5349 assertArrayEquals(earfcns2, actualEarfcnsArray); 5350 assertArrayEquals(new SatelliteInfo[]{satelliteInfo2}, 5351 capturedSystemSelectionSpecifier2.getSatelliteInfos().toArray( 5352 new SatelliteInfo[0])); 5353 actualTagIdArray = capturedSystemSelectionSpecifier2.getTagIds(); 5354 assertArrayEquals(tagIds, actualTagIdArray); 5355 } 5356 verifyProvisionStatusPerSubscriberIdGetFromDb(boolean provision)5357 private void verifyProvisionStatusPerSubscriberIdGetFromDb(boolean provision) { 5358 doReturn(provision).when( 5359 mMockSubscriptionManagerService).isSatelliteProvisionedForNonIpDatagram(anyInt()); 5360 mCarrierConfigBundle.putString(KEY_SATELLITE_NIDD_APN_NAME_STRING, mNiddApn); 5361 mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ESOS_SUPPORTED_BOOL, true); 5362 for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair 5363 : mCarrierConfigChangedListenerList) { 5364 pair.first.execute(() -> pair.second.onCarrierConfigChanged( 5365 /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) 5366 ); 5367 } 5368 moveTimeForward(TimeUnit.MINUTES.toMillis(1)); 5369 processAllMessages(); 5370 mSatelliteControllerUT.requestSatelliteSubscriberProvisionStatus( 5371 mRequestSatelliteSubscriberProvisionStatusReceiver); 5372 moveTimeForward(TimeUnit.MINUTES.toMillis(1)); 5373 processAllMessages(); 5374 assertEquals(SATELLITE_RESULT_SUCCESS, 5375 mRequestSatelliteSubscriberProvisionStatusResultCode); 5376 assertEquals(provision, 5377 mRequestSatelliteSubscriberProvisionStatusResultList.get(0).isProvisioned()); 5378 } 5379 setComponentName()5380 private void setComponentName() { 5381 when(mSatelliteControllerUT.getStringFromOverlayConfigTest( 5382 R.string.config_satellite_gateway_service_package)) 5383 .thenReturn("com.example.package"); 5384 when(mSatelliteControllerUT.getStringFromOverlayConfigTest( 5385 R.string.config_satellite_carrier_roaming_esos_provisioned_class)) 5386 .thenReturn("com.example.class"); 5387 } 5388 getKeyPriority(SubscriptionInfo subscriptionInfo)5389 private int getKeyPriority(SubscriptionInfo subscriptionInfo) { 5390 boolean isActive = subscriptionInfo.isActive(); 5391 boolean isNtnOnly = subscriptionInfo.isOnlyNonTerrestrialNetwork(); 5392 boolean isESOSSupported = subscriptionInfo.isSatelliteESOSSupported(); 5393 boolean isCarrierSatelliteHigherPriority = 5394 mSatelliteControllerUT.isCarrierSatelliteHigherPriorityTest( 5395 subscriptionInfo); 5396 5397 int keyPriority; 5398 if (isESOSSupported && isActive && isCarrierSatelliteHigherPriority) { 5399 keyPriority = 1; 5400 } else if (isNtnOnly) { 5401 keyPriority = 2; 5402 } else if (isESOSSupported) { 5403 keyPriority = 3; 5404 } else { 5405 keyPriority = -1; 5406 } 5407 return keyPriority; 5408 } 5409 resetSatelliteControllerUTEnabledState()5410 private void resetSatelliteControllerUTEnabledState() { 5411 logd("resetSatelliteControllerUTEnabledState"); 5412 setUpResponseForRequestIsSatelliteSupported(false, SATELLITE_RESULT_RADIO_NOT_AVAILABLE); 5413 doNothing().when(mMockSatelliteModemInterface) 5414 .setSatelliteServicePackageName(anyString()); 5415 mSatelliteControllerUT.setSatelliteServicePackageName("TestSatelliteService", null); 5416 processAllMessages(); 5417 5418 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 5419 setProvisionedState(false); 5420 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 5421 setProvisionedState(true); 5422 processAllMessages(); 5423 verifySatelliteProvisioned(true, SATELLITE_RESULT_SUCCESS); 5424 } 5425 resetSatelliteControllerUT()5426 private void resetSatelliteControllerUT() { 5427 logd("resetSatelliteControllerUT"); 5428 // Trigger cleanUpResources 5429 sendSatelliteModemStateChangedEvent(SATELLITE_MODEM_STATE_UNAVAILABLE, null); 5430 processAllMessages(); 5431 5432 // Reset all cached states 5433 setUpResponseForRequestIsSatelliteSupported(false, SATELLITE_RESULT_RADIO_NOT_AVAILABLE); 5434 doNothing().when(mMockSatelliteModemInterface) 5435 .setSatelliteServicePackageName(anyString()); 5436 mSatelliteControllerUT.setSatelliteServicePackageName("TestSatelliteService", null); 5437 processAllMessages(); 5438 } 5439 resetSatelliteControllerUTToSupportedAndProvisionedState()5440 private void resetSatelliteControllerUTToSupportedAndProvisionedState() { 5441 resetSatelliteControllerUT(); 5442 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 5443 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 5444 setProvisionedState(true); 5445 processAllMessages(); 5446 verifySatelliteProvisioned(true, SATELLITE_RESULT_SUCCESS); 5447 } 5448 resetSatelliteControllerUTToOffAndProvisionedState()5449 private void resetSatelliteControllerUTToOffAndProvisionedState() { 5450 resetSatelliteControllerUTToSupportedAndProvisionedState(); 5451 // Clean up pending resources and move satellite controller to OFF state. 5452 sendSatelliteModemStateChangedEvent(SATELLITE_MODEM_STATE_UNAVAILABLE, null); 5453 mSatelliteControllerUT.moveSatelliteToOffStateAndCleanUpResources( 5454 SATELLITE_RESULT_REQUEST_ABORTED); 5455 processAllMessages(); 5456 verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); 5457 } 5458 resetSatelliteControllerUTToOnAndProvisionedState()5459 private void resetSatelliteControllerUTToOnAndProvisionedState() { 5460 resetSatelliteControllerUTToOffAndProvisionedState(); 5461 setRadioPower(true); 5462 processAllMessages(); 5463 5464 mIIntegerConsumerResults.clear(); 5465 setUpResponseForRequestSatelliteEnabled(true, false, false, SATELLITE_RESULT_SUCCESS); 5466 mSatelliteControllerUT.requestSatelliteEnabled(true, false, false, mIIntegerConsumer); 5467 processAllMessages(); 5468 assertTrue(waitForIIntegerConsumerResult(1)); 5469 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 5470 verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); 5471 } 5472 setUpResponseForRequestIsSatelliteEnabled(boolean isSatelliteEnabled, @SatelliteManager.SatelliteResult int error)5473 private void setUpResponseForRequestIsSatelliteEnabled(boolean isSatelliteEnabled, 5474 @SatelliteManager.SatelliteResult int error) { 5475 SatelliteException exception = (error == SATELLITE_RESULT_SUCCESS) 5476 ? null : new SatelliteException(error); 5477 doAnswer(invocation -> { 5478 Message message = (Message) invocation.getArguments()[0]; 5479 int[] enabled = new int[] {isSatelliteEnabled ? 1 : 0}; 5480 AsyncResult.forMessage(message, enabled, exception); 5481 message.sendToTarget(); 5482 return null; 5483 }).when(mMockSatelliteModemInterface).requestIsSatelliteEnabled(any(Message.class)); 5484 mSatelliteControllerUT.isSatelliteEnabledOrBeingEnabled = isSatelliteEnabled; 5485 } 5486 setUpResponseForRequestIsSatelliteSupported( boolean isSatelliteSupported, @SatelliteManager.SatelliteResult int error)5487 private void setUpResponseForRequestIsSatelliteSupported( 5488 boolean isSatelliteSupported, @SatelliteManager.SatelliteResult int error) { 5489 SatelliteException exception = (error == SATELLITE_RESULT_SUCCESS) 5490 ? null : new SatelliteException(error); 5491 doAnswer(invocation -> { 5492 Message message = (Message) invocation.getArguments()[0]; 5493 AsyncResult.forMessage(message, isSatelliteSupported, exception); 5494 message.sendToTarget(); 5495 return null; 5496 }).when(mMockSatelliteModemInterface).requestIsSatelliteSupported(any(Message.class)); 5497 } 5498 setUpResponseForRequestTimeForNextSatelliteVisibility( int satelliteVisibilityTime, @SatelliteManager.SatelliteResult int error)5499 private void setUpResponseForRequestTimeForNextSatelliteVisibility( 5500 int satelliteVisibilityTime, @SatelliteManager.SatelliteResult int error) { 5501 SatelliteException exception = (error == SATELLITE_RESULT_SUCCESS) 5502 ? null : new SatelliteException(error); 5503 int[] visibilityTime = new int[]{satelliteVisibilityTime}; 5504 doAnswer(invocation -> { 5505 Message message = (Message) invocation.getArguments()[0]; 5506 AsyncResult.forMessage(message, visibilityTime, exception); 5507 message.sendToTarget(); 5508 return null; 5509 }).when(mMockSatelliteModemInterface) 5510 .requestTimeForNextSatelliteVisibility(any(Message.class)); 5511 } 5512 setUpNullResponseForRequestTimeForNextSatelliteVisibility( @atelliteManager.SatelliteResult int error)5513 private void setUpNullResponseForRequestTimeForNextSatelliteVisibility( 5514 @SatelliteManager.SatelliteResult int error) { 5515 SatelliteException exception = (error == SATELLITE_RESULT_SUCCESS) 5516 ? null : new SatelliteException(error); 5517 doAnswer(invocation -> { 5518 Message message = (Message) invocation.getArguments()[0]; 5519 AsyncResult.forMessage(message, null, exception); 5520 message.sendToTarget(); 5521 return null; 5522 }).when(mMockSatelliteModemInterface) 5523 .requestTimeForNextSatelliteVisibility(any(Message.class)); 5524 } 5525 setUpResponseForRequestIsSatelliteProvisioned( boolean isSatelliteProvisioned, @SatelliteManager.SatelliteResult int error)5526 private void setUpResponseForRequestIsSatelliteProvisioned( 5527 boolean isSatelliteProvisioned, @SatelliteManager.SatelliteResult int error) { 5528 mSatelliteControllerUT.setSatelliteProvisioned(isSatelliteProvisioned); 5529 } 5530 setUpResponseForRequestSatelliteEnabled( boolean enabled, boolean demoMode, boolean emergency, @SatelliteManager.SatelliteResult int error)5531 private void setUpResponseForRequestSatelliteEnabled( 5532 boolean enabled, boolean demoMode, boolean emergency, 5533 @SatelliteManager.SatelliteResult int error) { 5534 SatelliteException exception = (error == SATELLITE_RESULT_SUCCESS) 5535 ? null : new SatelliteException(error); 5536 doAnswer(invocation -> { 5537 if (exception == null && !enabled) { 5538 sendSatelliteModemStateChangedEvent(SATELLITE_MODEM_STATE_OFF, null); 5539 } 5540 Message message = (Message) invocation.getArguments()[1]; 5541 AsyncResult.forMessage(message, null, exception); 5542 message.sendToTarget(); 5543 return null; 5544 }).when(mMockSatelliteModemInterface) 5545 .requestSatelliteEnabled(any(SatelliteModemEnableRequestAttributes.class), 5546 any(Message.class)); 5547 } 5548 setUpResponseForRequestSetSatelliteEnabledForCarrier( boolean enabled, @SatelliteManager.SatelliteResult int error)5549 private void setUpResponseForRequestSetSatelliteEnabledForCarrier( 5550 boolean enabled, @SatelliteManager.SatelliteResult int error) { 5551 SatelliteException exception = (error == SATELLITE_RESULT_SUCCESS) 5552 ? null : new SatelliteException(error); 5553 doAnswer(invocation -> { 5554 Message message = (Message) invocation.getArguments()[2]; 5555 AsyncResult.forMessage(message, null, exception); 5556 message.sendToTarget(); 5557 return null; 5558 }).when(mMockSatelliteModemInterface) 5559 .requestSetSatelliteEnabledForCarrier(anyInt(), eq(enabled), any(Message.class)); 5560 } 5561 setUpNoResponseForRequestSatelliteEnabled(boolean enabled, boolean demoMode, boolean emergency)5562 private void setUpNoResponseForRequestSatelliteEnabled(boolean enabled, boolean demoMode, 5563 boolean emergency) { 5564 doNothing().when(mMockSatelliteModemInterface) 5565 .requestSatelliteEnabled(eq(new SatelliteModemEnableRequestAttributes( 5566 enabled, demoMode, emergency, 5567 new SatelliteSubscriptionInfo("", "") 5568 )), 5569 any(Message.class)); 5570 } 5571 setUpResponseForRequestSatelliteCapabilities( SatelliteCapabilities satelliteCapabilities, @SatelliteManager.SatelliteResult int error)5572 private void setUpResponseForRequestSatelliteCapabilities( 5573 SatelliteCapabilities satelliteCapabilities, 5574 @SatelliteManager.SatelliteResult int error) { 5575 SatelliteException exception = (error == SATELLITE_RESULT_SUCCESS) 5576 ? null : new SatelliteException(error); 5577 doAnswer(invocation -> { 5578 Message message = (Message) invocation.getArguments()[0]; 5579 AsyncResult.forMessage(message, satelliteCapabilities, exception); 5580 message.sendToTarget(); 5581 return null; 5582 }).when(mMockSatelliteModemInterface).requestSatelliteCapabilities(any(Message.class)); 5583 } 5584 setUpResponseForRequestNtnSignalStrength( @tnSignalStrength.NtnSignalStrengthLevel int ntnSignalStrengthLevel, @SatelliteManager.SatelliteResult int error)5585 private void setUpResponseForRequestNtnSignalStrength( 5586 @NtnSignalStrength.NtnSignalStrengthLevel int ntnSignalStrengthLevel, 5587 @SatelliteManager.SatelliteResult int error) { 5588 SatelliteException exception = (error == SATELLITE_RESULT_SUCCESS) 5589 ? null : new SatelliteException(error); 5590 doAnswer(invocation -> { 5591 Message message = (Message) invocation.getArguments()[0]; 5592 AsyncResult.forMessage(message, new NtnSignalStrength(ntnSignalStrengthLevel), 5593 exception); 5594 message.sendToTarget(); 5595 return null; 5596 }).when(mMockSatelliteModemInterface).requestNtnSignalStrength(any(Message.class)); 5597 } 5598 waitForForEvents( Semaphore semaphore, int expectedNumberOfEvents, String caller)5599 private boolean waitForForEvents( 5600 Semaphore semaphore, int expectedNumberOfEvents, String caller) { 5601 for (int i = 0; i < expectedNumberOfEvents; i++) { 5602 try { 5603 if (!semaphore.tryAcquire(TIMEOUT, TimeUnit.MILLISECONDS)) { 5604 loge(caller + ": Timeout to receive the expected event"); 5605 return false; 5606 } 5607 } catch (Exception ex) { 5608 loge(caller + ": Got exception=" + ex); 5609 return false; 5610 } 5611 } 5612 return true; 5613 } 5614 setUpNullResponseForRequestSatelliteCapabilities( @atelliteManager.SatelliteResult int error)5615 private void setUpNullResponseForRequestSatelliteCapabilities( 5616 @SatelliteManager.SatelliteResult int error) { 5617 SatelliteException exception = (error == SATELLITE_RESULT_SUCCESS) 5618 ? null : new SatelliteException(error); 5619 doAnswer(invocation -> { 5620 Message message = (Message) invocation.getArguments()[0]; 5621 AsyncResult.forMessage(message, null, exception); 5622 message.sendToTarget(); 5623 return null; 5624 }).when(mMockSatelliteModemInterface).requestSatelliteCapabilities(any(Message.class)); 5625 } 5626 setUpResponseForStartSatelliteTransmissionUpdates( @atelliteManager.SatelliteResult int error)5627 private void setUpResponseForStartSatelliteTransmissionUpdates( 5628 @SatelliteManager.SatelliteResult int error) { 5629 SatelliteException exception = (error == SATELLITE_RESULT_SUCCESS) 5630 ? null : new SatelliteException(error); 5631 doAnswer(invocation -> { 5632 Message message = (Message) invocation.getArguments()[0]; 5633 AsyncResult.forMessage(message, null, exception); 5634 message.sendToTarget(); 5635 return null; 5636 }).when(mMockPointingAppController).startSatelliteTransmissionUpdates(any(Message.class)); 5637 } 5638 setUpResponseForStopSatelliteTransmissionUpdates( @atelliteManager.SatelliteResult int error)5639 private void setUpResponseForStopSatelliteTransmissionUpdates( 5640 @SatelliteManager.SatelliteResult int error) { 5641 SatelliteException exception = (error == SATELLITE_RESULT_SUCCESS) 5642 ? null : new SatelliteException(error); 5643 doAnswer(invocation -> { 5644 Message message = (Message) invocation.getArguments()[0]; 5645 AsyncResult.forMessage(message, null, exception); 5646 message.sendToTarget(); 5647 return null; 5648 }).when(mMockPointingAppController).stopSatelliteTransmissionUpdates(any(Message.class)); 5649 } 5650 setUpResponseForStartSendingNtnSignalStrength( @atelliteManager.SatelliteResult int error)5651 private void setUpResponseForStartSendingNtnSignalStrength( 5652 @SatelliteManager.SatelliteResult int error) { 5653 SatelliteException exception = (error == SATELLITE_RESULT_SUCCESS) 5654 ? null : new SatelliteException(error); 5655 doAnswer(invocation -> { 5656 Message message = (Message) invocation.getArguments()[0]; 5657 AsyncResult.forMessage(message, null, exception); 5658 message.sendToTarget(); 5659 return null; 5660 }).when(mMockSatelliteModemInterface).startSendingNtnSignalStrength(any(Message.class)); 5661 } 5662 setUpResponseForStopSendingNtnSignalStrength( @atelliteManager.SatelliteResult int error)5663 private void setUpResponseForStopSendingNtnSignalStrength( 5664 @SatelliteManager.SatelliteResult int error) { 5665 SatelliteException exception = (error == SATELLITE_RESULT_SUCCESS) 5666 ? null : new SatelliteException(error); 5667 doAnswer(invocation -> { 5668 Message message = (Message) invocation.getArguments()[0]; 5669 AsyncResult.forMessage(message, null, exception); 5670 message.sendToTarget(); 5671 return null; 5672 }).when(mMockSatelliteModemInterface).stopSendingNtnSignalStrength(any(Message.class)); 5673 } 5674 setUpResponseForUpdateSystemSelectionChannels( @atelliteManager.SatelliteResult int error)5675 private void setUpResponseForUpdateSystemSelectionChannels( 5676 @SatelliteManager.SatelliteResult int error) { 5677 SatelliteException exception = (error == SATELLITE_RESULT_SUCCESS) 5678 ? null : new SatelliteException(error); 5679 doAnswer(invocation -> { 5680 Message message = (Message) invocation.getArguments()[1]; 5681 AsyncResult.forMessage(message, null, exception); 5682 message.sendToTarget(); 5683 return null; 5684 }).when(mMockSatelliteModemInterface).updateSystemSelectionChannels(anyList(), 5685 any(Message.class)); 5686 } 5687 waitForRequestIsSatelliteSupportedResult(int expectedNumberOfEvents)5688 private boolean waitForRequestIsSatelliteSupportedResult(int expectedNumberOfEvents) { 5689 for (int i = 0; i < expectedNumberOfEvents; i++) { 5690 try { 5691 if (!mSatelliteSupportSemaphore.tryAcquire(TIMEOUT, TimeUnit.MILLISECONDS)) { 5692 loge("Timeout to receive requestIsSatelliteSupported() callback"); 5693 return false; 5694 } 5695 } catch (Exception ex) { 5696 loge("waitForRequestIsSatelliteSupportedResult: Got exception=" + ex); 5697 return false; 5698 } 5699 } 5700 return true; 5701 } 5702 waitForRequestTimeForNextSatelliteVisibilityResult( int expectedNumberOfEvents)5703 private boolean waitForRequestTimeForNextSatelliteVisibilityResult( 5704 int expectedNumberOfEvents) { 5705 for (int i = 0; i < expectedNumberOfEvents; i++) { 5706 try { 5707 if (!mSatelliteVisibilityTimeSemaphore.tryAcquire(TIMEOUT, TimeUnit.MILLISECONDS)) { 5708 loge("Timeout to receive " 5709 + "requestTimeForNextSatelliteVisibility() callback"); 5710 return false; 5711 } 5712 } catch (Exception ex) { 5713 loge("waitForRequestTimeForNextSatelliteVisibilityResult: Got exception=" + ex); 5714 return false; 5715 } 5716 } 5717 return true; 5718 } 5719 waitForRequestIsSatelliteEnabledResult(int expectedNumberOfEvents)5720 private boolean waitForRequestIsSatelliteEnabledResult(int expectedNumberOfEvents) { 5721 for (int i = 0; i < expectedNumberOfEvents; i++) { 5722 try { 5723 if (!mIsSatelliteEnabledSemaphore.tryAcquire(TIMEOUT, TimeUnit.MILLISECONDS)) { 5724 loge("Timeout to receive requestIsSatelliteEnabled() callback"); 5725 return false; 5726 } 5727 } catch (Exception ex) { 5728 loge("waitForRequestIsSatelliteEnabledResult: Got exception=" + ex); 5729 return false; 5730 } 5731 } 5732 return true; 5733 } 5734 waitForRequestIsSatelliteProvisionedResult(int expectedNumberOfEvents)5735 private boolean waitForRequestIsSatelliteProvisionedResult(int expectedNumberOfEvents) { 5736 for (int i = 0; i < expectedNumberOfEvents; i++) { 5737 try { 5738 if (!mIsSatelliteProvisionedSemaphore.tryAcquire(TIMEOUT, TimeUnit.MILLISECONDS)) { 5739 loge("Timeout to receive requestIsSatelliteProvisioned() callback"); 5740 return false; 5741 } 5742 } catch (Exception ex) { 5743 loge("waitForRequestIsSatelliteProvisionedResult: Got exception=" + ex); 5744 return false; 5745 } 5746 } 5747 return true; 5748 } 5749 waitForRequestSatelliteCapabilitiesResult(int expectedNumberOfEvents)5750 private boolean waitForRequestSatelliteCapabilitiesResult(int expectedNumberOfEvents) { 5751 for (int i = 0; i < expectedNumberOfEvents; i++) { 5752 try { 5753 if (!mSatelliteCapabilitiesSemaphore.tryAcquire(TIMEOUT, TimeUnit.MILLISECONDS)) { 5754 loge("Timeout to receive requestSatelliteCapabilities() callback"); 5755 return false; 5756 } 5757 } catch (Exception ex) { 5758 loge("waitForRequestSatelliteCapabilitiesResult: Got exception=" + ex); 5759 return false; 5760 } 5761 } 5762 return true; 5763 } 5764 waitForRequestIsDemoModeEnabledResult(int expectedNumberOfEvents)5765 private boolean waitForRequestIsDemoModeEnabledResult(int expectedNumberOfEvents) { 5766 for (int i = 0; i < expectedNumberOfEvents; i++) { 5767 try { 5768 if (!mIsDemoModeEnabledSemaphore.tryAcquire(TIMEOUT, TimeUnit.MILLISECONDS)) { 5769 loge("Timeout to receive requestIsDemoModeEnabled() callback"); 5770 return false; 5771 } 5772 } catch (Exception ex) { 5773 loge("waitForRequestIsDemoModeEnabled: Got exception=" + ex); 5774 return false; 5775 } 5776 } 5777 return true; 5778 } 5779 waitForRequestNtnSignalStrengthResult(int expectedNumberOfEvents)5780 private boolean waitForRequestNtnSignalStrengthResult(int expectedNumberOfEvents) { 5781 for (int i = 0; i < expectedNumberOfEvents; i++) { 5782 try { 5783 if (!mRequestNtnSignalStrengthSemaphore.tryAcquire(TIMEOUT, 5784 TimeUnit.MILLISECONDS)) { 5785 loge("Timeout to receive requestNtnSignalStrength() callback"); 5786 return false; 5787 } 5788 } catch (Exception ex) { 5789 loge("requestNtnSignalStrength: Got exception=" + ex); 5790 return false; 5791 } 5792 } 5793 return true; 5794 } 5795 waitForIIntegerConsumerResult(int expectedNumberOfEvents)5796 private boolean waitForIIntegerConsumerResult(int expectedNumberOfEvents) { 5797 for (int i = 0; i < expectedNumberOfEvents; i++) { 5798 try { 5799 if (!mIIntegerConsumerSemaphore.tryAcquire(TIMEOUT, TimeUnit.MILLISECONDS)) { 5800 loge("Timeout to receive IIntegerConsumer() callback"); 5801 return false; 5802 } 5803 } catch (Exception ex) { 5804 loge("waitForIIntegerConsumerResult: Got exception=" + ex); 5805 return false; 5806 } 5807 } 5808 return true; 5809 } 5810 waitForRequestUpdateSystemSelectionChannelResult(int expectedNumberOfEvents)5811 private boolean waitForRequestUpdateSystemSelectionChannelResult(int expectedNumberOfEvents) { 5812 for (int i = 0; i < expectedNumberOfEvents; i++) { 5813 try { 5814 if (!mSystemSelectionChannelUpdatedSemaphore.tryAcquire(TIMEOUT, 5815 TimeUnit.MILLISECONDS)) { 5816 logd("Timeout to receive " 5817 + "updateSystemSelectionChannel()" 5818 + " callback"); 5819 return false; 5820 } 5821 } catch (Exception ex) { 5822 logd("updateSystemSelectionChannel: Got exception=" + ex); 5823 return false; 5824 } 5825 } 5826 return true; 5827 } 5828 verifySatelliteSupported(boolean supported, int expectedErrorCode)5829 private void verifySatelliteSupported(boolean supported, int expectedErrorCode) { 5830 mSatelliteSupportSemaphore.drainPermits(); 5831 mSatelliteControllerUT.requestIsSatelliteSupported(mSatelliteSupportReceiver); 5832 processAllMessages(); 5833 assertTrue(waitForRequestIsSatelliteSupportedResult(1)); 5834 assertEquals(expectedErrorCode, mQueriedSatelliteSupportedResultCode); 5835 assertEquals(supported, mQueriedSatelliteSupported); 5836 } 5837 verifySatelliteSupported(TestSatelliteController satelliteController, boolean supported, int expectedErrorCode)5838 private void verifySatelliteSupported(TestSatelliteController satelliteController, 5839 boolean supported, int expectedErrorCode) { 5840 mSatelliteSupportSemaphore.drainPermits(); 5841 satelliteController.requestIsSatelliteSupported(mSatelliteSupportReceiver); 5842 processAllMessages(); 5843 assertTrue(waitForRequestIsSatelliteSupportedResult(1)); 5844 assertEquals(expectedErrorCode, mQueriedSatelliteSupportedResultCode); 5845 assertEquals(supported, mQueriedSatelliteSupported); 5846 } 5847 verifySatelliteEnabled(boolean enabled, int expectedErrorCode)5848 private void verifySatelliteEnabled(boolean enabled, int expectedErrorCode) { 5849 mIsSatelliteEnabledSemaphore.drainPermits(); 5850 mSatelliteControllerUT.requestIsSatelliteEnabled(mIsSatelliteEnabledReceiver); 5851 processAllMessages(); 5852 assertTrue(waitForRequestIsSatelliteEnabledResult(1)); 5853 assertEquals(expectedErrorCode, mQueriedIsSatelliteEnabledResultCode); 5854 assertEquals(enabled, mQueriedIsSatelliteEnabled); 5855 } 5856 verifySatelliteProvisioned(boolean provisioned, int expectedErrorCode)5857 private void verifySatelliteProvisioned(boolean provisioned, int expectedErrorCode) { 5858 mIsSatelliteProvisionedSemaphore.drainPermits(); 5859 mSatelliteControllerUT.requestIsSatelliteProvisioned(mIsSatelliteProvisionedReceiver); 5860 processAllMessages(); 5861 assertTrue(waitForRequestIsSatelliteProvisionedResult(1)); 5862 assertEquals(expectedErrorCode, mQueriedIsSatelliteProvisionedResultCode); 5863 assertEquals(provisioned, mQueriedIsSatelliteProvisioned); 5864 } 5865 verifyRequestNtnSignalStrength( @tnSignalStrength.NtnSignalStrengthLevel int signalStrengthLevel, int expectedErrorCode)5866 private void verifyRequestNtnSignalStrength( 5867 @NtnSignalStrength.NtnSignalStrengthLevel int signalStrengthLevel, 5868 int expectedErrorCode) { 5869 mRequestNtnSignalStrengthSemaphore.drainPermits(); 5870 mSatelliteControllerUT.requestNtnSignalStrength(mRequestNtnSignalStrengthReceiver); 5871 processAllMessages(); 5872 assertTrue(waitForRequestNtnSignalStrengthResult(1)); 5873 assertEquals(expectedErrorCode, mQueriedNtnSignalStrengthResultCode); 5874 assertEquals(signalStrengthLevel, mQueriedNtnSignalStrengthLevel); 5875 } 5876 setProvisionedState(@ullable Boolean provisioned)5877 private void setProvisionedState(@Nullable Boolean provisioned) { 5878 mSatelliteControllerUT.setSatelliteProvisioned(provisioned); 5879 } 5880 sendSatelliteModemStateChangedEvent(int state, Throwable exception)5881 private void sendSatelliteModemStateChangedEvent(int state, Throwable exception) { 5882 Message msg = mSatelliteControllerUT.obtainMessage( 5883 28 /* EVENT_SATELLITE_MODEM_STATE_CHANGED */); 5884 msg.obj = new AsyncResult(null, state, exception); 5885 msg.sendToTarget(); 5886 } 5887 sendNtnSignalStrengthChangedEvent( @tnSignalStrength.NtnSignalStrengthLevel int ntnSignalStrengthLevel, Throwable exception)5888 private void sendNtnSignalStrengthChangedEvent( 5889 @NtnSignalStrength.NtnSignalStrengthLevel int ntnSignalStrengthLevel, 5890 Throwable exception) { 5891 Message msg = mSatelliteControllerUT.obtainMessage( 5892 34 /* EVENT_NTN_SIGNAL_STRENGTH_CHANGED */); 5893 msg.obj = new AsyncResult(null, new NtnSignalStrength(ntnSignalStrengthLevel), 5894 exception); 5895 msg.sendToTarget(); 5896 } 5897 sendSignalStrengthChangedEvent(int phoneId)5898 private void sendSignalStrengthChangedEvent(int phoneId) { 5899 Message msg = mSatelliteControllerUT.obtainMessage( 5900 57 /* EVENT_SIGNAL_STRENGTH_CHANGED */); 5901 msg.obj = new AsyncResult(phoneId, null, null); 5902 msg.sendToTarget(); 5903 } 5904 sendCmdStartSendingNtnSignalStrengthChangedEvent(boolean shouldReport)5905 private void sendCmdStartSendingNtnSignalStrengthChangedEvent(boolean shouldReport) { 5906 Message msg = mSatelliteControllerUT.obtainMessage( 5907 35 /* CMD_UPDATE_NTN_SIGNAL_STRENGTH_REPORTING */); 5908 msg.obj = new AsyncResult(null, shouldReport, null); 5909 msg.sendToTarget(); 5910 } 5911 sendStartSendingNtnSignalStrengthChangedEvent( @tnSignalStrength.NtnSignalStrengthLevel int ntnSignalStrengthLevel, Throwable exception)5912 private void sendStartSendingNtnSignalStrengthChangedEvent( 5913 @NtnSignalStrength.NtnSignalStrengthLevel int ntnSignalStrengthLevel, 5914 Throwable exception) { 5915 Message msg = mSatelliteControllerUT.obtainMessage( 5916 36 /* EVENT_UPDATE_NTN_SIGNAL_STRENGTH_REPORTING_DONE */); 5917 msg.obj = new AsyncResult(null, new NtnSignalStrength(ntnSignalStrengthLevel), 5918 exception); 5919 msg.sendToTarget(); 5920 } 5921 sendServiceStateChangedEvent()5922 private void sendServiceStateChangedEvent() { 5923 mSatelliteControllerUT.obtainMessage(37 /* EVENT_SERVICE_STATE_CHANGED */).sendToTarget(); 5924 } 5925 sendSatelliteCapabilitiesChangedEvent(SatelliteCapabilities capabilities, Throwable exception)5926 private void sendSatelliteCapabilitiesChangedEvent(SatelliteCapabilities capabilities, 5927 Throwable exception) { 5928 Message msg = mSatelliteControllerUT.obtainMessage( 5929 38 /* EVENT_SATELLITE_CAPABILITIES_CHANGED */); 5930 msg.obj = new AsyncResult(null, capabilities, exception); 5931 msg.sendToTarget(); 5932 } 5933 sendSatelliteSupportedStateChangedEvent(boolean supported, Throwable exception)5934 private void sendSatelliteSupportedStateChangedEvent(boolean supported, Throwable exception) { 5935 Message msg = mSatelliteControllerUT.obtainMessage( 5936 41 /* EVENT_SATELLITE_SUPPORTED_STATE_CHANGED */); 5937 msg.obj = new AsyncResult(null, supported, exception); 5938 msg.sendToTarget(); 5939 } 5940 sendSatelliteRegistrationFailureEvent(int errorCode, Throwable exception)5941 private void sendSatelliteRegistrationFailureEvent(int errorCode, Throwable exception) { 5942 Message msg = mSatelliteControllerUT.obtainMessage( 5943 54 /* EVENT_SATELLITE_REGISTRATION_FAILURE */); 5944 msg.obj = new AsyncResult(null, errorCode, exception); 5945 msg.sendToTarget(); 5946 } 5947 sendTerrestrialNetworkAvailableChangedEvent(boolean isAvailable, Throwable exception)5948 private void sendTerrestrialNetworkAvailableChangedEvent(boolean isAvailable, 5949 Throwable exception) { 5950 Message msg = mSatelliteControllerUT.obtainMessage( 5951 55 /* EVENT_TERRESTRIAL_NETWORK_AVAILABLE_CHANGED */); 5952 msg.obj = new AsyncResult(null, isAvailable, exception); 5953 msg.sendToTarget(); 5954 } 5955 sendSelectedNbIotSatelliteSubscriptionChangedEvent(int selectedSubId, Throwable exception)5956 private void sendSelectedNbIotSatelliteSubscriptionChangedEvent(int selectedSubId, 5957 Throwable exception) { 5958 Message msg = mSatelliteControllerUT.obtainMessage( 5959 60 /* EVENT_SELECTED_NB_IOT_SATELLITE_SUBSCRIPTION_CHANGED */); 5960 msg.obj = new AsyncResult(null, selectedSubId, exception); 5961 msg.sendToTarget(); 5962 } 5963 sendCmdEvaluateCarrierRoamingNtnEligibilityChange()5964 private void sendCmdEvaluateCarrierRoamingNtnEligibilityChange() { 5965 mSatelliteControllerUT.obtainMessage( 5966 61 /* CMD_EVALUATE_CARRIER_ROAMING_NTN_ELIGIBILITY_CHANGE */).sendToTarget(); 5967 } 5968 setRadioPower(boolean on)5969 private void setRadioPower(boolean on) { 5970 mSimulatedCommands.setRadioPower(on, false, false, null); 5971 } 5972 verifyRegisterForNtnSignalStrengthChanged(int subId, INtnSignalStrengthCallback callback, int expectedError)5973 private void verifyRegisterForNtnSignalStrengthChanged(int subId, 5974 INtnSignalStrengthCallback callback, int expectedError) { 5975 if (expectedError == SATELLITE_RESULT_SUCCESS) { 5976 try { 5977 mSatelliteControllerUT.registerForNtnSignalStrengthChanged(callback); 5978 } catch (RemoteException ex) { 5979 throw new AssertionError(); 5980 } 5981 } else { 5982 RemoteException ex = assertThrows(RemoteException.class, 5983 () -> mSatelliteControllerUT.registerForNtnSignalStrengthChanged(callback)); 5984 assertTrue("The cause is not IllegalStateException", 5985 ex.getCause() instanceof IllegalStateException); 5986 } 5987 } 5988 provisionSatelliteService()5989 private void provisionSatelliteService() { 5990 String mText = "This is test provision data."; 5991 byte[] testProvisionData = mText.getBytes(); 5992 ICancellationSignal cancelRemote; 5993 mIIntegerConsumerResults.clear(); 5994 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 5995 setUpResponseForRequestIsSatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 5996 verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 5997 verifySatelliteProvisioned(false, SATELLITE_RESULT_SUCCESS); 5998 5999 try { 6000 setSatelliteSubscriberTesting(true); 6001 } catch (Exception ex) { 6002 fail("provisionSatelliteService.setSatelliteSubscriberTesting: ex=" + ex); 6003 } 6004 doReturn(true).when(mMockSubscriptionManagerService).isSatelliteProvisionedForNonIpDatagram( 6005 anyInt()); 6006 6007 cancelRemote = mSatelliteControllerUT.provisionSatelliteService( 6008 TEST_SATELLITE_TOKEN, 6009 testProvisionData, mIIntegerConsumer); 6010 processAllMessages(); 6011 assertTrue(waitForIIntegerConsumerResult(1)); 6012 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 6013 assertNotNull(cancelRemote); 6014 verifySatelliteProvisioned(true, SATELLITE_RESULT_SUCCESS); 6015 } 6016 deprovisionSatelliteService()6017 private void deprovisionSatelliteService() { 6018 mIIntegerConsumerResults.clear(); 6019 mSatelliteControllerUT.deprovisionSatelliteService( 6020 TEST_SATELLITE_TOKEN, mIIntegerConsumer); 6021 processAllMessages(); 6022 assertTrue(waitForIIntegerConsumerResult(1)); 6023 assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); 6024 } 6025 loge(String message)6026 private static void loge(String message) { 6027 Rlog.e(TAG, message); 6028 } 6029 6030 private static class TestSharedPreferences 6031 implements SharedPreferences, SharedPreferences.Editor { 6032 private HashMap<String, Object> mValues = new HashMap<String, Object>(); 6033 getValueCount()6034 public int getValueCount() { 6035 return mValues.size(); 6036 } 6037 6038 @Override edit()6039 public Editor edit() { 6040 return this; 6041 } 6042 6043 @Override contains(String key)6044 public boolean contains(String key) { 6045 return mValues.containsKey(key); 6046 } 6047 6048 @Override getAll()6049 public Map<String, ?> getAll() { 6050 return new HashMap<String, Object>(mValues); 6051 } 6052 6053 @Override getBoolean(String key, boolean defValue)6054 public boolean getBoolean(String key, boolean defValue) { 6055 if (mValues.containsKey(key)) { 6056 return ((Boolean) mValues.get(key)).booleanValue(); 6057 } 6058 return defValue; 6059 } 6060 6061 @Override getFloat(String key, float defValue)6062 public float getFloat(String key, float defValue) { 6063 if (mValues.containsKey(key)) { 6064 return ((Float) mValues.get(key)).floatValue(); 6065 } 6066 return defValue; 6067 } 6068 6069 @Override getInt(String key, int defValue)6070 public int getInt(String key, int defValue) { 6071 if (mValues.containsKey(key)) { 6072 return ((Integer) mValues.get(key)).intValue(); 6073 } 6074 return defValue; 6075 } 6076 6077 @Override getLong(String key, long defValue)6078 public long getLong(String key, long defValue) { 6079 if (mValues.containsKey(key)) { 6080 return ((Long) mValues.get(key)).longValue(); 6081 } 6082 return defValue; 6083 } 6084 6085 @Override getString(String key, String defValue)6086 public String getString(String key, String defValue) { 6087 if (mValues.containsKey(key)) return (String) mValues.get(key); 6088 else return defValue; 6089 } 6090 6091 @SuppressWarnings("unchecked") 6092 @Override getStringSet(String key, Set<String> defValues)6093 public Set<String> getStringSet(String key, Set<String> defValues) { 6094 if (mValues.containsKey(key)) { 6095 return (Set<String>) mValues.get(key); 6096 } 6097 return defValues; 6098 } 6099 6100 @Override registerOnSharedPreferenceChangeListener( OnSharedPreferenceChangeListener listener)6101 public void registerOnSharedPreferenceChangeListener( 6102 OnSharedPreferenceChangeListener listener) { 6103 throw new UnsupportedOperationException(); 6104 } 6105 6106 @Override unregisterOnSharedPreferenceChangeListener( OnSharedPreferenceChangeListener listener)6107 public void unregisterOnSharedPreferenceChangeListener( 6108 OnSharedPreferenceChangeListener listener) { 6109 throw new UnsupportedOperationException(); 6110 } 6111 6112 @Override putBoolean(String key, boolean value)6113 public Editor putBoolean(String key, boolean value) { 6114 mValues.put(key, Boolean.valueOf(value)); 6115 return this; 6116 } 6117 6118 @Override putFloat(String key, float value)6119 public Editor putFloat(String key, float value) { 6120 mValues.put(key, value); 6121 return this; 6122 } 6123 6124 @Override putInt(String key, int value)6125 public Editor putInt(String key, int value) { 6126 mValues.put(key, value); 6127 return this; 6128 } 6129 6130 @Override putLong(String key, long value)6131 public Editor putLong(String key, long value) { 6132 mValues.put(key, value); 6133 return this; 6134 } 6135 6136 @Override putString(String key, String value)6137 public Editor putString(String key, String value) { 6138 mValues.put(key, value); 6139 return this; 6140 } 6141 6142 @Override putStringSet(String key, Set<String> values)6143 public Editor putStringSet(String key, Set<String> values) { 6144 mValues.put(key, values); 6145 return this; 6146 } 6147 6148 @Override remove(String key)6149 public Editor remove(String key) { 6150 mValues.remove(key); 6151 return this; 6152 } 6153 6154 @Override clear()6155 public Editor clear() { 6156 mValues.clear(); 6157 return this; 6158 } 6159 6160 @Override commit()6161 public boolean commit() { 6162 return true; 6163 } 6164 6165 @Override apply()6166 public void apply() { 6167 commit(); 6168 } 6169 } 6170 6171 private class TestSatelliteController extends SatelliteController { 6172 public boolean setSettingsKeyForSatelliteModeCalled = false; 6173 public boolean allRadiosDisabled = true; 6174 public long elapsedRealtime = 0; 6175 public int satelliteModeSettingValue = SATELLITE_MODE_ENABLED_FALSE; 6176 public boolean setSettingsKeyToAllowDeviceRotationCalled = false; 6177 public OutcomeReceiver<Boolean, SatelliteException> isSatelliteAllowedCallback = null; 6178 public static boolean isApplicationUpdated; 6179 public String packageName = "com.example.app"; 6180 public boolean isSatelliteBeingDisabled = false; 6181 public boolean mIsApplicationSupportsP2P = false; 6182 public int selectedSatelliteSubId = -1; 6183 public boolean isSatelliteProvisioned; 6184 public boolean isSatelliteEnabledOrBeingEnabled = false; 6185 TestSatelliteController( Context context, Looper looper, @NonNull FeatureFlags featureFlags)6186 TestSatelliteController( 6187 Context context, Looper looper, @NonNull FeatureFlags featureFlags) { 6188 super(context, looper, featureFlags); 6189 logd("Constructing TestSatelliteController"); 6190 isApplicationUpdated = false; 6191 } 6192 6193 @Override initializeSatelliteModeRadios()6194 protected void initializeSatelliteModeRadios() { 6195 logd("initializeSatelliteModeRadios"); 6196 } 6197 6198 @Override setSettingsKeyForSatelliteMode(int val)6199 protected void setSettingsKeyForSatelliteMode(int val) { 6200 logd("setSettingsKeyForSatelliteMode: val=" + val); 6201 satelliteModeSettingValue = val; 6202 setSettingsKeyForSatelliteModeCalled = true; 6203 } 6204 6205 @Override setSettingsKeyToAllowDeviceRotation(int val)6206 protected void setSettingsKeyToAllowDeviceRotation(int val) { 6207 logd("setSettingsKeyToAllowDeviceRotation: val=" + val); 6208 setSettingsKeyToAllowDeviceRotationCalled = true; 6209 } 6210 6211 @Override areAllRadiosDisabled()6212 protected boolean areAllRadiosDisabled() { 6213 logd("areAllRadiosDisabled: " + allRadiosDisabled); 6214 return allRadiosDisabled; 6215 } 6216 6217 @Override getSupportedNtnRadioTechnology()6218 protected int getSupportedNtnRadioTechnology() { 6219 int ntRadioTechnology = super.getSupportedNtnRadioTechnology(); 6220 logd("getCurrentNtnRadioTechnology: val=" + ntRadioTechnology); 6221 return ntRadioTechnology; 6222 } 6223 6224 @Override getElapsedRealtime()6225 protected long getElapsedRealtime() { 6226 return elapsedRealtime; 6227 } 6228 6229 @Override registerForSatelliteCommunicationAllowedStateChanged()6230 protected void registerForSatelliteCommunicationAllowedStateChanged() { 6231 logd("registerForSatelliteCommunicationAllowedStateChanged"); 6232 } 6233 setSatelliteSessionController(SatelliteSessionController satelliteSessionController)6234 void setSatelliteSessionController(SatelliteSessionController satelliteSessionController) { 6235 mSatelliteSessionController = satelliteSessionController; 6236 } 6237 6238 @Override setSatellitePhone(int subId)6239 protected void setSatellitePhone(int subId) { 6240 logd("setSatellitePhone"); 6241 synchronized (mSatellitePhoneLock) { 6242 mSatellitePhone = mPhone; 6243 } 6244 } 6245 6246 @Override setSelectedSatelliteSubId(int subId)6247 protected void setSelectedSatelliteSubId(int subId) { 6248 logd("setSelectedSatelliteSubId: subId=" + subId); 6249 synchronized (mSatelliteTokenProvisionedLock) { 6250 mSelectedSatelliteSubId = subId; 6251 } 6252 } 6253 6254 @Override isSubscriptionProvisioned(int subId)6255 protected boolean isSubscriptionProvisioned(int subId) { 6256 return isSatelliteProvisioned; 6257 } 6258 6259 @Override getSupportedDeviceStates()6260 protected List<DeviceState> getSupportedDeviceStates() { 6261 return List.of(new DeviceState(new DeviceState.Configuration.Builder(0 /* identifier */, 6262 "DEFAULT" /* name */).build())); 6263 } 6264 6265 @Override isSatelliteBeingDisabled()6266 public boolean isSatelliteBeingDisabled() { 6267 return isSatelliteBeingDisabled; 6268 } 6269 6270 @Override isSatelliteEnabledOrBeingEnabled()6271 public boolean isSatelliteEnabledOrBeingEnabled() { 6272 return isSatelliteEnabledOrBeingEnabled; 6273 } 6274 getConfigSatelliteGatewayServicePackage()6275 protected String getConfigSatelliteGatewayServicePackage() { 6276 String packageName = "com.example.app"; 6277 return packageName; 6278 } 6279 6280 @Override handleCarrierRoamingNtnAvailableServicesChanged(int subId)6281 protected void handleCarrierRoamingNtnAvailableServicesChanged(int subId) { 6282 isApplicationUpdated = true; 6283 } 6284 6285 @Override isApplicationSupportsP2P(String packageName)6286 public boolean isApplicationSupportsP2P(String packageName) { 6287 return mIsApplicationSupportsP2P; 6288 } 6289 6290 @Override getSupportedServicesOnCarrierRoamingNtn(int subId)6291 public int[] getSupportedServicesOnCarrierRoamingNtn(int subId) { 6292 return new int[]{3, 5}; 6293 } 6294 6295 setSatelliteProvisioned(@ullable Boolean isProvisioned)6296 void setSatelliteProvisioned(@Nullable Boolean isProvisioned) { 6297 synchronized (mDeviceProvisionLock) { 6298 mIsDeviceProvisioned = isProvisioned; 6299 } 6300 } 6301 setIsSatelliteSupported(@ullable Boolean isSatelliteSupported)6302 void setIsSatelliteSupported(@Nullable Boolean isSatelliteSupported) { 6303 synchronized (mIsSatelliteSupportedLock) { 6304 mIsSatelliteSupported = isSatelliteSupported; 6305 } 6306 } 6307 isRadioOn()6308 public boolean isRadioOn() { 6309 synchronized (mIsRadioOnLock) { 6310 return mIsRadioOn; 6311 } 6312 } 6313 isRadioOffRequested()6314 public boolean isRadioOffRequested() { 6315 synchronized (mIsRadioOnLock) { 6316 return mRadioOffRequested; 6317 } 6318 } 6319 isWaitForCellularModemOffTimerStarted()6320 public boolean isWaitForCellularModemOffTimerStarted() { 6321 return hasMessages(EVENT_WAIT_FOR_CELLULAR_MODEM_OFF_TIMED_OUT); 6322 } 6323 subscriberIdPerSub()6324 public Map<String, Integer> subscriberIdPerSub() { 6325 synchronized (mSatelliteTokenProvisionedLock) { 6326 return mSubscriberIdPerSub; 6327 } 6328 } 6329 subsInfoListPerPriority()6330 public Map<Integer, List<SubscriptionInfo>> subsInfoListPerPriority() { 6331 synchronized (mSatelliteTokenProvisionedLock) { 6332 return mSubsInfoListPerPriority; 6333 } 6334 } 6335 evaluateESOSProfilesPrioritizationTest()6336 public void evaluateESOSProfilesPrioritizationTest() { 6337 evaluateESOSProfilesPrioritization(); 6338 } 6339 isCarrierSatelliteHigherPriorityTest(SubscriptionInfo info)6340 public boolean isCarrierSatelliteHigherPriorityTest(SubscriptionInfo info) { 6341 return isCarrierSatelliteHigherPriority(info); 6342 } 6343 getStringFromOverlayConfigTest(int resourceId)6344 public String getStringFromOverlayConfigTest(int resourceId) { 6345 return getStringFromOverlayConfig(resourceId); 6346 } 6347 isAnyWaitForSatelliteEnablingResponseTimerStarted()6348 public boolean isAnyWaitForSatelliteEnablingResponseTimerStarted() { 6349 return hasMessages(EVENT_WAIT_FOR_SATELLITE_ENABLING_RESPONSE_TIMED_OUT); 6350 } 6351 getResultReceiverTotalCount()6352 public int getResultReceiverTotalCount() { 6353 synchronized (mResultReceiverTotalCountLock) { 6354 return mResultReceiverTotalCount; 6355 } 6356 } 6357 getResultReceiverCountPerMethodMap()6358 public HashMap<String, Integer> getResultReceiverCountPerMethodMap() { 6359 synchronized (mResultReceiverTotalCountLock) { 6360 return mResultReceiverCountPerMethodMap; 6361 } 6362 } 6363 setIsSatelliteAllowedState(boolean isAllowed)6364 public void setIsSatelliteAllowedState(boolean isAllowed) { 6365 synchronized(mSatelliteAccessConfigLock) { 6366 mSatelliteAccessAllowed = isAllowed; 6367 } 6368 } 6369 } 6370 6371 @Test testLoggingCodeForResultReceiverCount()6372 public void testLoggingCodeForResultReceiverCount() throws Exception { 6373 final String callerSC = "SC:ResultReceiver"; 6374 final String callerSAC = "SAC:ResultReceiver"; 6375 6376 doReturn(false).when(mFeatureFlags).carrierRoamingNbIotNtn(); 6377 6378 mSatelliteControllerUT.incrementResultReceiverCount(callerSC); 6379 assertEquals(0, mSatelliteControllerUT.getResultReceiverTotalCount()); 6380 mSatelliteControllerUT.decrementResultReceiverCount(callerSC); 6381 assertEquals(0, mSatelliteControllerUT.getResultReceiverTotalCount()); 6382 6383 doReturn(true).when(mFeatureFlags).carrierRoamingNbIotNtn(); 6384 6385 mSatelliteControllerUT.incrementResultReceiverCount(callerSC); 6386 assertEquals(1, mSatelliteControllerUT.getResultReceiverTotalCount()); 6387 assertEquals(1, mSatelliteControllerUT.getResultReceiverCountPerMethodMap().size()); 6388 assertEquals(1, (int) Optional.ofNullable(mSatelliteControllerUT 6389 .getResultReceiverCountPerMethodMap().get(callerSC)).orElse(0)); 6390 assertEquals(0, (int) Optional.ofNullable(mSatelliteControllerUT 6391 .getResultReceiverCountPerMethodMap().get(callerSAC)).orElse(0)); 6392 6393 mSatelliteControllerUT.incrementResultReceiverCount(callerSC); 6394 assertEquals(2, mSatelliteControllerUT.getResultReceiverTotalCount()); 6395 assertEquals(1, mSatelliteControllerUT.getResultReceiverCountPerMethodMap().size()); 6396 assertEquals(2, (int) Optional.ofNullable(mSatelliteControllerUT 6397 .getResultReceiverCountPerMethodMap().get(callerSC)).orElse(0)); 6398 assertEquals(0, (int) Optional.ofNullable(mSatelliteControllerUT 6399 .getResultReceiverCountPerMethodMap().get(callerSAC)).orElse(0)); 6400 6401 mSatelliteControllerUT.incrementResultReceiverCount(callerSAC); 6402 assertEquals(3, mSatelliteControllerUT.getResultReceiverTotalCount()); 6403 assertEquals(2, mSatelliteControllerUT.getResultReceiverCountPerMethodMap().size()); 6404 assertEquals(2, (int) Optional.ofNullable(mSatelliteControllerUT 6405 .getResultReceiverCountPerMethodMap().get(callerSC)).orElse(0)); 6406 assertEquals(1, (int) Optional.ofNullable(mSatelliteControllerUT 6407 .getResultReceiverCountPerMethodMap().get(callerSAC)).orElse(0)); 6408 6409 mSatelliteControllerUT.decrementResultReceiverCount(callerSC); 6410 assertEquals(2, mSatelliteControllerUT.getResultReceiverTotalCount()); 6411 assertEquals(2, mSatelliteControllerUT.getResultReceiverCountPerMethodMap().size()); 6412 assertEquals(1, (int) Optional.ofNullable(mSatelliteControllerUT 6413 .getResultReceiverCountPerMethodMap().get(callerSC)).orElse(0)); 6414 assertEquals(1, (int) Optional.ofNullable(mSatelliteControllerUT 6415 .getResultReceiverCountPerMethodMap().get(callerSAC)).orElse(0)); 6416 6417 mSatelliteControllerUT.decrementResultReceiverCount(callerSC); 6418 assertEquals(1, mSatelliteControllerUT.getResultReceiverTotalCount()); 6419 assertEquals(2, mSatelliteControllerUT.getResultReceiverCountPerMethodMap().size()); 6420 assertEquals(0, (int) Optional.ofNullable(mSatelliteControllerUT 6421 .getResultReceiverCountPerMethodMap().get(callerSC)).orElse(0)); 6422 assertEquals(1, (int) Optional.ofNullable(mSatelliteControllerUT 6423 .getResultReceiverCountPerMethodMap().get(callerSAC)).orElse(0)); 6424 6425 mSatelliteControllerUT.decrementResultReceiverCount(callerSAC); 6426 assertEquals(0, mSatelliteControllerUT.getResultReceiverTotalCount()); 6427 assertEquals(2, mSatelliteControllerUT.getResultReceiverCountPerMethodMap().size()); 6428 assertEquals(0, (int) Optional.ofNullable(mSatelliteControllerUT 6429 .getResultReceiverCountPerMethodMap().get(callerSC)).orElse(0)); 6430 assertEquals(0, (int) Optional.ofNullable(mSatelliteControllerUT 6431 .getResultReceiverCountPerMethodMap().get(callerSAC)).orElse(0)); 6432 } 6433 6434 @Test testSetNtnSmsSupportedByMessagesApp()6435 public void testSetNtnSmsSupportedByMessagesApp() { 6436 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 6437 mSatelliteControllerUT.setNtnSmsSupportedByMessagesApp(true); 6438 assertTrue(mSharedPreferences.getBoolean( 6439 SatelliteController.NTN_SMS_SUPPORTED_BY_MESSAGES_APP_KEY, false)); 6440 } 6441 6442 private static class TestSubscriptionManager { 6443 public Map<Integer, Boolean> mSatelliteProvisionedForNonIpDatagram = new HashMap<>(); 6444 resetProvisionMapForNonIpDatagram()6445 public void resetProvisionMapForNonIpDatagram() { 6446 mSatelliteProvisionedForNonIpDatagram.clear(); 6447 } 6448 setIsSatelliteProvisionedForNonIpDatagram(int subId, boolean provisioned)6449 public void setIsSatelliteProvisionedForNonIpDatagram(int subId, boolean provisioned) { 6450 mSatelliteProvisionedForNonIpDatagram.put(subId, provisioned); 6451 } 6452 isSatelliteProvisionedForNonIpDatagram(int subId)6453 public boolean isSatelliteProvisionedForNonIpDatagram(int subId) { 6454 Boolean isProvisioned = mSatelliteProvisionedForNonIpDatagram.get(subId); 6455 return isProvisioned != null ? isProvisioned : false; 6456 } 6457 } 6458 6459 @Test testGetSatelliteDataPlanForPlmn_WithEntitlement()6460 public void testGetSatelliteDataPlanForPlmn_WithEntitlement() throws Exception { 6461 logd("testGetSatelliteDataPlanForPlmn_WithEntitlement"); 6462 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 6463 6464 replaceInstance(SatelliteController.class, "mMergedPlmnListPerCarrier", 6465 mSatelliteControllerUT, new SparseArray<>()); 6466 List<String> overlayConfigPlmnList = new ArrayList<>(); 6467 replaceInstance(SatelliteController.class, "mSatellitePlmnListFromOverlayConfig", 6468 mSatelliteControllerUT, overlayConfigPlmnList); 6469 mCarrierConfigBundle.putBoolean( 6470 CarrierConfigManager.KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true); 6471 mCarrierConfigBundle.putBoolean(CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, 6472 true); 6473 6474 List<String> entitlementPlmnList = 6475 Arrays.stream(new String[]{"00101", "00102", "00103", "00104"}) 6476 .toList(); 6477 List<String> barredPlmnList = new ArrayList<>(); 6478 Map<String, Integer> dataPlanListMap = Map.of( 6479 "00101", SATELLITE_DATA_PLAN_METERED, 6480 "00103", SATELLITE_DATA_PLAN_UNMETERED); 6481 mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, false, 6482 entitlementPlmnList, barredPlmnList, dataPlanListMap, new HashMap<>(), 6483 new HashMap<>(), new HashMap<>(), mIIntegerConsumer); 6484 6485 int dataPlanForPlmn; 6486 dataPlanForPlmn = mSatelliteControllerUT.getSatelliteDataPlanForPlmn(SUB_ID, "00101"); 6487 assertEquals(SATELLITE_DATA_PLAN_METERED, dataPlanForPlmn); 6488 6489 dataPlanForPlmn = mSatelliteControllerUT.getSatelliteDataPlanForPlmn(SUB_ID, "00103"); 6490 assertEquals(SATELLITE_DATA_PLAN_UNMETERED, dataPlanForPlmn); 6491 } 6492 6493 @Test testGetSatelliteDataPlanForPlmn_WithoutEntitlement()6494 public void testGetSatelliteDataPlanForPlmn_WithoutEntitlement() throws Exception { 6495 logd("testGetSatelliteDataPlanForPlmn_WithoutEntitlement"); 6496 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 6497 6498 replaceInstance(SatelliteController.class, "mMergedPlmnListPerCarrier", 6499 mSatelliteControllerUT, new SparseArray<>()); 6500 List<String> overlayConfigPlmnList = new ArrayList<>(); 6501 replaceInstance(SatelliteController.class, "mSatellitePlmnListFromOverlayConfig", 6502 mSatelliteControllerUT, overlayConfigPlmnList); 6503 mCarrierConfigBundle.putBoolean( 6504 CarrierConfigManager.KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true); 6505 mCarrierConfigBundle.putBoolean(CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, 6506 true); 6507 6508 List<String> entitlementPlmnList = 6509 Arrays.stream(new String[]{"00101", "00102", "00103", "00104"}) 6510 .toList(); 6511 List<String> barredPlmnList = new ArrayList<>(); 6512 Map<String, Integer> dataPlanListMap = new HashMap<>(); 6513 mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, false, 6514 entitlementPlmnList, barredPlmnList, dataPlanListMap, new HashMap<>(), 6515 new HashMap<>(), new HashMap<>(), mIIntegerConsumer); 6516 6517 int dataPlanForPlmn = mSatelliteControllerUT.getSatelliteDataPlanForPlmn(SUB_ID, "00101"); 6518 assertEquals(SATELLITE_DATA_PLAN_METERED, dataPlanForPlmn); 6519 } 6520 6521 @Test TestGetSupportedSatelliteServicesForPlmn_WithEntitlement()6522 public void TestGetSupportedSatelliteServicesForPlmn_WithEntitlement() throws Exception { 6523 logd("TestGetSupportedSatelliteServicesForPlmn_WithEntitlement"); 6524 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 6525 6526 replaceInstance(SatelliteController.class, "mMergedPlmnListPerCarrier", 6527 mSatelliteControllerUT, new SparseArray<>()); 6528 List<String> overlayConfigPlmnList = new ArrayList<>(); 6529 replaceInstance(SatelliteController.class, "mSatellitePlmnListFromOverlayConfig", 6530 mSatelliteControllerUT, overlayConfigPlmnList); 6531 mCarrierConfigBundle.putBoolean( 6532 CarrierConfigManager.KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true); 6533 mCarrierConfigBundle.putBoolean(CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, 6534 true); 6535 6536 List<String> entitlementPlmnList = 6537 Arrays.stream(new String[]{"00101", "00102", "00103", "00104"}) 6538 .toList(); 6539 List<String> barredPlmnList = new ArrayList<>(); 6540 Map<String, List<Integer>> serviceTypeListMap = Map.of( 6541 "00101", List.of(SERVICE_TYPE_DATA, SERVICE_TYPE_SMS), 6542 "00102", List.of(SERVICE_TYPE_VOICE, SERVICE_TYPE_SMS), 6543 "00103", List.of(SERVICE_TYPE_DATA, SERVICE_TYPE_VOICE, SERVICE_TYPE_SMS)); 6544 mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, false, 6545 entitlementPlmnList, barredPlmnList, new HashMap<>(), serviceTypeListMap, 6546 new HashMap<>(), new HashMap<>(), mIIntegerConsumer); 6547 6548 List<Integer> allowedServiceForPlmn; 6549 allowedServiceForPlmn = mSatelliteControllerUT 6550 .getSupportedSatelliteServicesForPlmn(SUB_ID, "00101"); 6551 assertEquals(List.of(SERVICE_TYPE_DATA, SERVICE_TYPE_SMS), allowedServiceForPlmn); 6552 6553 allowedServiceForPlmn = mSatelliteControllerUT 6554 .getSupportedSatelliteServicesForPlmn(SUB_ID, "00102"); 6555 assertEquals(List.of(SERVICE_TYPE_VOICE, SERVICE_TYPE_SMS), allowedServiceForPlmn); 6556 6557 allowedServiceForPlmn = mSatelliteControllerUT 6558 .getSupportedSatelliteServicesForPlmn(SUB_ID, "00103"); 6559 assertEquals(List.of(SERVICE_TYPE_DATA, SERVICE_TYPE_VOICE, SERVICE_TYPE_SMS), 6560 allowedServiceForPlmn); 6561 } 6562 6563 @Test TestGetSupportedSatelliteServicesForPlmn_WithoutEntitlement()6564 public void TestGetSupportedSatelliteServicesForPlmn_WithoutEntitlement() throws Exception { 6565 logd("TestGetSupportedSatelliteServicesForPlmn_WithoutAllowedServices"); 6566 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 6567 6568 replaceInstance(SatelliteController.class, "mMergedPlmnListPerCarrier", 6569 mSatelliteControllerUT, new SparseArray<>()); 6570 List<String> overlayConfigPlmnList = new ArrayList<>(); 6571 replaceInstance(SatelliteController.class, "mSatellitePlmnListFromOverlayConfig", 6572 mSatelliteControllerUT, overlayConfigPlmnList); 6573 mCarrierConfigBundle.putBoolean( 6574 CarrierConfigManager.KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true); 6575 mCarrierConfigBundle.putBoolean(CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, 6576 true); 6577 6578 List<String> entitlementPlmnList = 6579 Arrays.stream(new String[]{"00101", "00102", "00103", "00104"}) 6580 .toList(); 6581 List<String> barredPlmnList = new ArrayList<>(); 6582 Map<String, Integer> dataPlanListMap = new HashMap<>(); 6583 Map<String, List<Integer>> allowedServiceListMap = new HashMap<>(); 6584 mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, false, 6585 entitlementPlmnList, barredPlmnList, dataPlanListMap, allowedServiceListMap, 6586 new HashMap<>(), new HashMap<>(), mIIntegerConsumer); 6587 6588 // Verify whether the carrier config plmn list is returned with conditions below 6589 // the config data plmn list : empty 6590 // the carrier config plmn list : exist with services {{2}} 6591 setConfigData(new ArrayList<>()); 6592 mCarrierConfigBundle.putBoolean(CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, 6593 true); 6594 PersistableBundle carrierSupportedSatelliteServicesPerProvider = 6595 new PersistableBundle(); 6596 List<String> carrierConfigPlmnList = List.of("00101"); 6597 carrierSupportedSatelliteServicesPerProvider.putIntArray( 6598 carrierConfigPlmnList.get(0), new int[]{2}); 6599 mCarrierConfigBundle.putPersistableBundle(CarrierConfigManager 6600 .KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE, 6601 carrierSupportedSatelliteServicesPerProvider); 6602 invokeCarrierConfigChanged(); 6603 6604 List<Integer> servicesPerPlmn; 6605 servicesPerPlmn = mSatelliteControllerUT.getSupportedSatelliteServicesForPlmn( 6606 SUB_ID, "00101"); 6607 assertEquals(Arrays.asList(2).stream().sorted().toList(), 6608 servicesPerPlmn.stream().sorted().toList()); 6609 } 6610 6611 @Test testGetSupportedSatelliteDataModeForPlmn_WithEntitlement()6612 public void testGetSupportedSatelliteDataModeForPlmn_WithEntitlement() throws Exception { 6613 logd("testGetSupportedSatelliteDataModeForPlmn_WithEntitlement"); 6614 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 6615 6616 replaceInstance(SatelliteController.class, "mMergedPlmnListPerCarrier", 6617 mSatelliteControllerUT, new SparseArray<>()); 6618 List<String> overlayConfigPlmnList = new ArrayList<>(); 6619 replaceInstance(SatelliteController.class, "mSatellitePlmnListFromOverlayConfig", 6620 mSatelliteControllerUT, overlayConfigPlmnList); 6621 mCarrierConfigBundle.putBoolean( 6622 CarrierConfigManager.KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true); 6623 mCarrierConfigBundle.putBoolean(CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, 6624 true); 6625 6626 List<String> entitlementPlmnList = 6627 Arrays.stream(new String[]{"00101", "00102", "00103", "00104"}) 6628 .toList(); 6629 List<String> barredPlmnList = new ArrayList<>(); 6630 Map<String, Integer> dataServicePolicyMap = Map.of( 6631 "00101", SATELLITE_DATA_SUPPORT_BANDWIDTH_CONSTRAINED, 6632 "00102", SATELLITE_DATA_SUPPORT_ALL 6633 ); 6634 mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, false, 6635 entitlementPlmnList, barredPlmnList, new HashMap<>(), new HashMap<>(), 6636 dataServicePolicyMap, new HashMap<>(), mIIntegerConsumer); 6637 6638 int dataSupportModeForPlmn; 6639 dataSupportModeForPlmn = mSatelliteControllerUT 6640 .getSatelliteDataServicePolicyForPlmn(SUB_ID, "00101"); 6641 assertEquals(SATELLITE_DATA_SUPPORT_BANDWIDTH_CONSTRAINED, dataSupportModeForPlmn); 6642 6643 dataSupportModeForPlmn = mSatelliteControllerUT 6644 .getSatelliteDataServicePolicyForPlmn(SUB_ID, "00102"); 6645 assertEquals(SATELLITE_DATA_SUPPORT_ALL, dataSupportModeForPlmn); 6646 6647 } 6648 6649 @Test testGetSupportedSatelliteDataModeForPlmn_WithoutEntitlement()6650 public void testGetSupportedSatelliteDataModeForPlmn_WithoutEntitlement() throws Exception { 6651 logd("testGetSupportedSatelliteDataModeForPlmn_WithoutEntitlement"); 6652 when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); 6653 6654 replaceInstance(SatelliteController.class, "mMergedPlmnListPerCarrier", 6655 mSatelliteControllerUT, new SparseArray<>()); 6656 List<String> overlayConfigPlmnList = new ArrayList<>(); 6657 replaceInstance(SatelliteController.class, "mSatellitePlmnListFromOverlayConfig", 6658 mSatelliteControllerUT, overlayConfigPlmnList); 6659 mCarrierConfigBundle.putBoolean( 6660 CarrierConfigManager.KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true); 6661 mCarrierConfigBundle.putBoolean(CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, 6662 true); 6663 6664 List<String> entitlementPlmnList = 6665 Arrays.stream(new String[]{"00101", "00102", "00103", "00104"}) 6666 .toList(); 6667 List<String> barredPlmnList = new ArrayList<>(); 6668 Map<String, Integer> dataServicePolicyMap = new HashMap<>(); 6669 mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, false, 6670 entitlementPlmnList, barredPlmnList, new HashMap<>(), new HashMap<>(), 6671 dataServicePolicyMap, new HashMap<>(), mIIntegerConsumer); 6672 6673 mCarrierConfigBundle.putInt( 6674 CarrierConfigManager.KEY_SATELLITE_DATA_SUPPORT_MODE_INT, 6675 SATELLITE_DATA_SUPPORT_BANDWIDTH_CONSTRAINED); 6676 int dataSupportModeForPlmn = mSatelliteControllerUT 6677 .getSatelliteDataServicePolicyForPlmn(SUB_ID, "00101"); 6678 assertEquals(SATELLITE_DATA_SUPPORT_BANDWIDTH_CONSTRAINED, dataSupportModeForPlmn); 6679 } 6680 6681 @Test testEvaluateCarrierRoamingNtnEligibilityChange_inSatelliteMode()6682 public void testEvaluateCarrierRoamingNtnEligibilityChange_inSatelliteMode() { 6683 when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); 6684 6685 mSatelliteControllerUT.isSatelliteEnabledOrBeingEnabled = true; 6686 mSatelliteControllerUT.setSatellitePhone(1); 6687 mSatelliteControllerUT.setSelectedSatelliteSubId(SUB_ID); 6688 mSatelliteControllerUT.isSatelliteProvisioned = true; 6689 mSatelliteControllerUT.isSatelliteAllowedCallback = null; 6690 setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS); 6691 mSatelliteControllerUT.setIsSatelliteAllowedState(true); 6692 sendCmdEvaluateCarrierRoamingNtnEligibilityChange(); 6693 processAllMessages(); 6694 verify(mPhone, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(anyBoolean()); 6695 } 6696 } 6697