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 android.telephony.satellite.cts; 18 19 20 import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_GONE; 21 22 import android.annotation.NonNull; 23 import android.annotation.Nullable; 24 import android.app.ActivityManager; 25 import android.app.Instrumentation; 26 import android.content.BroadcastReceiver; 27 import android.content.ComponentName; 28 import android.content.Context; 29 import android.content.Intent; 30 import android.content.IntentFilter; 31 import android.content.ServiceConnection; 32 import android.content.pm.PackageManager; 33 import android.content.res.Resources; 34 import android.os.IBinder; 35 import android.os.RemoteException; 36 import android.telephony.cts.externalpointingui.ExternalMockPointingUi; 37 import android.telephony.cts.externalsatellitegatewayservice.ExternalMockSatelliteGatewayService; 38 import android.telephony.cts.externalsatellitegatewayservice.IExternalMockSatelliteGatewayService; 39 import android.telephony.cts.externalsatellitegatewayservice.IExternalSatelliteGatewayListener; 40 import android.telephony.cts.externalsatelliteservice.ExternalMockSatelliteService; 41 import android.telephony.cts.externalsatelliteservice.IExternalMockSatelliteService; 42 import android.telephony.cts.externalsatelliteservice.IExternalSatelliteListener; 43 import android.telephony.cts.util.TelephonyUtils; 44 import android.telephony.satellite.EarfcnRange; 45 import android.telephony.satellite.SatelliteInfo; 46 import android.telephony.satellite.SatellitePosition; 47 import android.telephony.satellite.SystemSelectionSpecifier; 48 import android.telephony.satellite.stub.PointingInfo; 49 import android.telephony.satellite.stub.SatelliteDatagram; 50 import android.text.TextUtils; 51 import android.util.IntArray; 52 import android.util.Log; 53 54 import com.android.internal.R; 55 56 import java.util.ArrayList; 57 import java.util.Arrays; 58 import java.util.List; 59 import java.util.UUID; 60 import java.util.concurrent.CountDownLatch; 61 import java.util.concurrent.Semaphore; 62 import java.util.concurrent.TimeUnit; 63 import java.util.stream.Collectors; 64 65 /** 66 * This class is responsible for connecting Telephony framework and CTS to the MockSatelliteService. 67 */ 68 class MockSatelliteServiceManager { 69 private static final String TAG = "MockSatelliteServiceManager"; 70 private static final String PACKAGE = "android.telephony.cts"; 71 private static final String EXTERNAL_SATELLITE_GATEWAY_PACKAGE = 72 ExternalMockSatelliteGatewayService.class.getPackage().getName(); 73 private static final String EXTERNAL_SATELLITE_PACKAGE = 74 ExternalMockSatelliteService.class.getPackage().getName(); 75 private static final String EXTERNAL_POINTING_UI_PACKAGE = 76 ExternalMockPointingUi.class.getPackage().getName(); 77 private static final String SET_SATELLITE_SERVICE_PACKAGE_NAME_CMD = 78 "cmd phone set-satellite-service-package-name -s "; 79 private static final String SET_SATELLITE_GATEWAY_SERVICE_PACKAGE_NAME_CMD = 80 "cmd phone set-satellite-gateway-service-package-name -s "; 81 private static final String SET_SATELLITE_LISTENING_TIMEOUT_DURATION_CMD = 82 "cmd phone set-satellite-listening-timeout-duration -t "; 83 private static final String SET_SATELLITE_IGNORE_CELLULAR_SERVICE_STATE_CMD = 84 "cmd phone set-satellite-ignore-cellular-service-state -d "; 85 private static final String SET_SATELLITE_POINTING_UI_CLASS_NAME_CMD = 86 "cmd phone set-satellite-pointing-ui-class-name"; 87 private static final String SET_DATAGRAM_CONTROLLER_TIMEOUT_DURATION_CMD = 88 "cmd phone set-datagram-controller-timeout-duration "; 89 90 private static final String SET_DATAGRAM_CONTROLLER_BOOLEAN_CONFIG_CMD = 91 "cmd phone set-datagram-controller-boolean-config "; 92 93 private static final String SET_SATELLITE_CONTROLLER_TIMEOUT_DURATION_CMD = 94 "cmd phone set-satellite-controller-timeout-duration "; 95 private static final String SET_SHOULD_SEND_DATAGRAM_TO_MODEM_IN_DEMO_MODE = 96 "cmd phone set-should-send-datagram-to-modem-in-demo-mode "; 97 private static final String SET_COUNTRY_CODES = "cmd phone set-country-codes"; 98 private static final String SET_SATELLITE_ACCESS_CONTROL_OVERLAY_CONFIGS = 99 "cmd phone set-satellite-access-control-overlay-configs"; 100 private static final String SET_IS_SATELLITE_COMMUNICATION_ALLOWED_FOR_CURRENT_LOCATION_CACHE = 101 "cmd phone set-is-satellite-communication-allowed-for-current-location-cache "; 102 private static final String SET_SATELLITE_SUBSCRIBERID_LIST_CHANGED_INTENT_COMPONENT = 103 "cmd phone set-satellite-subscriberid-list-changed-intent-component "; 104 private static final String SET_SATELLITE_ACCESS_ALLOWED_FOR_SUBSCRIPTIONS_CMD = 105 "cmd phone set-satellite-access-allowed-for-subscriptions"; 106 private static final String SET_SATELLITE_TN_SCANNING_SUPPORT_CMD = 107 "cmd phone set-satellite-tn-scanning-support "; 108 private static final String SET_SUPPORT_DISABLE_SATELLITE_WHILE_ENABLE_IN_PROGRESS_CMD = 109 "cmd phone set-support-disable-satellite-while-enable-in-progress "; 110 private static final String OVERRIDE_CONFIG_DATA_VERSION = 111 "cmd phone override-config-data-version"; 112 private static final String UPDATE_TELEPHONY_CONFIG_INTENT = 113 "com.google.android.configupdater.TelephonyConfigUpdate.UPDATE_CONFIG"; 114 private static final String CONFIG_UPDATER_PACKAGE = "com.google.android.configupdater"; 115 private static final String SET_SATELLITE_IGNORE_PLMN_LIST_FROM_STORAGE = 116 "cmd phone set-satellite-ignore-plmn-list-from-storage -d "; 117 118 private static final long TIMEOUT = 5000; 119 @NonNull private ActivityManager mActivityManager; 120 @NonNull private UidImportanceListener mUidImportanceListener = new UidImportanceListener(); 121 122 private MockSatelliteService mSatelliteService; 123 private TestSatelliteServiceConnection mSatelliteServiceConn; 124 private IExternalMockSatelliteService mExternalSatelliteService; 125 private ExternalSatelliteServiceConnection mExternalSatelliteServiceConn; 126 private final Semaphore mRemoteServiceConnectedSemaphore = new Semaphore(0); 127 private final Semaphore mExternalServiceDisconnectedSemaphore = new Semaphore(0); 128 private MockSatelliteGatewayService mSatelliteGatewayService; 129 private TestSatelliteGatewayServiceConnection mSatelliteGatewayServiceConn; 130 private IExternalMockSatelliteGatewayService mExternalSatelliteGatewayService; 131 private ExternalSatelliteGatewayServiceConnection mExternalSatelliteGatewayServiceConn; 132 private final Semaphore mRemoteGatewayServiceConnectedSemaphore = new Semaphore(0); 133 private final Semaphore mRemoteGatewayServiceDisconnectedSemaphore = new Semaphore(0); 134 private final Semaphore mExternalGatewayServiceDisconnectedSemaphore = new Semaphore(0); 135 private Instrumentation mInstrumentation; 136 private final Semaphore mStartSendingPointingInfoSemaphore = new Semaphore(0); 137 private final Semaphore mStopSendingPointingInfoSemaphore = new Semaphore(0); 138 private final Semaphore mPollPendingDatagramsSemaphore = new Semaphore(0); 139 private final Semaphore mStopPointingUiSemaphore = new Semaphore(0); 140 private final Semaphore mSendDatagramsSemaphore = new Semaphore(0); 141 private final Semaphore mRequestSatelliteEnabledSemaphore = new Semaphore(0); 142 private final Object mRequestSatelliteEnabledLock = new Object(); 143 private List<SatelliteDatagram> mSentSatelliteDatagrams = new ArrayList<>(); 144 private List<Boolean> mSentIsEmergencyList = new ArrayList<>(); 145 private final Object mSendDatagramLock = new Object(); 146 private final Semaphore mListeningEnabledSemaphore = new Semaphore(0); 147 private List<Boolean> mListeningEnabledList = new ArrayList<>(); 148 private final Object mListeningEnabledLock = new Object(); 149 private final Semaphore mMockPointingUiActivitySemaphore = new Semaphore(0); 150 private final MockPointingUiActivityStatusReceiver mMockPointingUiActivityStatusReceiver = 151 new MockPointingUiActivityStatusReceiver(mMockPointingUiActivitySemaphore); 152 private final boolean mIsSatelliteServicePackageConfigured; 153 boolean mIsPointingUiOverridden = false; 154 private final Semaphore mSetSatellitePlmnSemaphore = new Semaphore(0); 155 156 @NonNull 157 private final ILocalSatelliteListener mSatelliteListener = 158 new ILocalSatelliteListener.Stub() { 159 @Override 160 public void onRemoteServiceConnected() { 161 logd("onRemoteServiceConnected"); 162 mRemoteServiceConnectedSemaphore.release(); 163 } 164 165 @Override 166 public void onStartSendingSatellitePointingInfo() { 167 logd("onStartSendingSatellitePointingInfo"); 168 try { 169 mStartSendingPointingInfoSemaphore.release(); 170 } catch (Exception ex) { 171 logd("onStartSendingSatellitePointingInfo: Got exception, ex=" + ex); 172 } 173 } 174 175 @Override 176 public void onStopSendingSatellitePointingInfo() { 177 logd("onStopSendingSatellitePointingInfo"); 178 try { 179 mStopSendingPointingInfoSemaphore.release(); 180 } catch (Exception ex) { 181 logd("onStopSendingSatellitePointingInfo: Got exception, ex=" + ex); 182 } 183 } 184 185 @Override 186 public void onPollPendingSatelliteDatagrams() { 187 logd("onPollPendingSatelliteDatagrams"); 188 try { 189 mPollPendingDatagramsSemaphore.release(); 190 } catch (Exception ex) { 191 logd("onPollPendingSatelliteDatagrams: Got exception, ex=" + ex); 192 } 193 } 194 195 @Override 196 public void onSendSatelliteDatagram( 197 SatelliteDatagram datagram, boolean isEmergency) { 198 logd("onSendSatelliteDatagram"); 199 synchronized (mSendDatagramLock) { 200 mSentSatelliteDatagrams.add(datagram); 201 mSentIsEmergencyList.add(isEmergency); 202 } 203 try { 204 mSendDatagramsSemaphore.release(); 205 } catch (Exception ex) { 206 logd("onSendSatelliteDatagram: Got exception, ex=" + ex); 207 } 208 } 209 210 @Override 211 public void onSatelliteListeningEnabled(boolean enabled) { 212 logd("onSatelliteListeningEnabled: enabled=" + enabled); 213 synchronized (mListeningEnabledLock) { 214 mListeningEnabledList.add(enabled); 215 } 216 try { 217 mListeningEnabledSemaphore.release(); 218 } catch (Exception ex) { 219 logd("onSatelliteListeningEnabled: Got exception, ex=" + ex); 220 } 221 } 222 223 @Override 224 public void onSetSatellitePlmn() { 225 logd("onSetSatellitePlmn()"); 226 try { 227 mSetSatellitePlmnSemaphore.release(); 228 } catch (Exception ex) { 229 logd("onSetSatellitePlmn: Got exception, ex=" + ex); 230 } 231 } 232 233 @Override 234 public void onRequestSatelliteEnabled(boolean enableSatellite) { 235 logd("onRequestSatelliteEnabled: enableSatellite=" + enableSatellite); 236 try { 237 mRequestSatelliteEnabledSemaphore.release(); 238 } catch (Exception ex) { 239 logd("onRequestSatelliteEnabled: Got exception, ex=" + ex); 240 } 241 } 242 }; 243 244 @NonNull 245 private final ILocalSatelliteGatewayListener mSatelliteGatewayListener = 246 new ILocalSatelliteGatewayListener.Stub() { 247 @Override 248 public void onRemoteServiceConnected() { 249 logd("ILocalSatelliteGatewayListener: onRemoteServiceConnected"); 250 mRemoteGatewayServiceConnectedSemaphore.release(); 251 } 252 253 @Override 254 public void onRemoteServiceDisconnected() { 255 logd("ILocalSatelliteGatewayListener: onRemoteServiceDisconnected"); 256 mRemoteGatewayServiceDisconnectedSemaphore.release(); 257 } 258 }; 259 260 private class TestSatelliteServiceConnection implements ServiceConnection { 261 private final CountDownLatch mLatch; 262 TestSatelliteServiceConnection(CountDownLatch latch)263 TestSatelliteServiceConnection(CountDownLatch latch) { 264 mLatch = latch; 265 } 266 267 @Override onServiceConnected(ComponentName name, IBinder service)268 public void onServiceConnected(ComponentName name, IBinder service) { 269 logd("onServiceConnected"); 270 mSatelliteService = ((MockSatelliteService.LocalBinder) service).getService(); 271 mSatelliteService.setLocalSatelliteListener(mSatelliteListener); 272 mLatch.countDown(); 273 } 274 275 @Override onServiceDisconnected(ComponentName name)276 public void onServiceDisconnected(ComponentName name) { 277 logd("onServiceDisconnected"); 278 mSatelliteService = null; 279 } 280 } 281 282 private class ExternalSatelliteServiceConnection implements ServiceConnection { 283 private final CountDownLatch mLatch; 284 ExternalSatelliteServiceConnection(CountDownLatch latch)285 ExternalSatelliteServiceConnection(CountDownLatch latch) { 286 mLatch = latch; 287 } 288 289 @Override onServiceConnected(ComponentName name, IBinder service)290 public void onServiceConnected(ComponentName name, IBinder service) { 291 logd("ExternalSatelliteService: onServiceConnected"); 292 mExternalSatelliteService = 293 IExternalMockSatelliteService.Stub.asInterface(service); 294 try { 295 mExternalSatelliteService.setExternalSatelliteListener( 296 mExternalSatelliteListener); 297 mLatch.countDown(); 298 } catch (RemoteException ex) { 299 loge("ExternalSatelliteService: setExternalSatelliteListener ex=" + ex); 300 } 301 } 302 303 @Override onServiceDisconnected(ComponentName name)304 public void onServiceDisconnected(ComponentName name) { 305 logd("ExternalSatelliteService: onServiceDisconnected"); 306 mExternalSatelliteService = null; 307 try { 308 mExternalServiceDisconnectedSemaphore.release(); 309 } catch (Exception ex) { 310 loge("ExternalSatelliteService: ex=" + ex); 311 } 312 } 313 } 314 315 private class UidImportanceListener implements ActivityManager.OnUidImportanceListener { 316 @Override onUidImportance(int uid, int importance)317 public void onUidImportance(int uid, int importance) { 318 if (importance != IMPORTANCE_GONE) return; 319 final PackageManager pm = mInstrumentation.getContext().getPackageManager(); 320 final String[] callerPackages = pm.getPackagesForUid(uid); 321 if (callerPackages != null) { 322 if (Arrays.stream(callerPackages) 323 .anyMatch(EXTERNAL_POINTING_UI_PACKAGE::contains)) { 324 mStopPointingUiSemaphore.release(); 325 } 326 } 327 } 328 } 329 330 @NonNull 331 private final IExternalSatelliteListener mExternalSatelliteListener = 332 new IExternalSatelliteListener.Stub() { 333 @Override 334 public void onRemoteServiceConnected() { 335 logd("IExternalSatelliteListener: onRemoteServiceConnected"); 336 mRemoteServiceConnectedSemaphore.release(); 337 } 338 }; 339 340 private class TestSatelliteGatewayServiceConnection implements ServiceConnection { 341 private final CountDownLatch mLatch; 342 TestSatelliteGatewayServiceConnection(CountDownLatch latch)343 TestSatelliteGatewayServiceConnection(CountDownLatch latch) { 344 mLatch = latch; 345 } 346 347 @Override onServiceConnected(ComponentName name, IBinder service)348 public void onServiceConnected(ComponentName name, IBinder service) { 349 logd("GatewayService: onServiceConnected"); 350 mSatelliteGatewayService = 351 ((MockSatelliteGatewayService.LocalBinder) service).getService(); 352 mSatelliteGatewayService.setLocalSatelliteListener(mSatelliteGatewayListener); 353 mLatch.countDown(); 354 } 355 356 @Override onServiceDisconnected(ComponentName name)357 public void onServiceDisconnected(ComponentName name) { 358 logd("GatewayService: onServiceDisconnected"); 359 mSatelliteGatewayService = null; 360 } 361 } 362 363 @NonNull 364 private final IExternalSatelliteGatewayListener mExternalSatelliteGatewayListener = 365 new IExternalSatelliteGatewayListener.Stub() { 366 @Override 367 public void onRemoteServiceConnected() { 368 logd("IExternalSatelliteGatewayListener: onRemoteServiceConnected"); 369 mRemoteGatewayServiceConnectedSemaphore.release(); 370 } 371 }; 372 373 private class ExternalSatelliteGatewayServiceConnection implements ServiceConnection { 374 private final CountDownLatch mLatch; 375 ExternalSatelliteGatewayServiceConnection(CountDownLatch latch)376 ExternalSatelliteGatewayServiceConnection(CountDownLatch latch) { 377 mLatch = latch; 378 } 379 380 @Override onServiceConnected(ComponentName name, IBinder service)381 public void onServiceConnected(ComponentName name, IBinder service) { 382 logd("ExternalGatewayService: onServiceConnected"); 383 mExternalSatelliteGatewayService = 384 IExternalMockSatelliteGatewayService.Stub.asInterface(service); 385 try { 386 mExternalSatelliteGatewayService.setExternalSatelliteGatewayListener( 387 mExternalSatelliteGatewayListener); 388 mLatch.countDown(); 389 } catch (RemoteException ex) { 390 loge("ExternalGatewayService: setExternalSatelliteGatewayListener ex=" + ex); 391 } 392 } 393 394 @Override onServiceDisconnected(ComponentName name)395 public void onServiceDisconnected(ComponentName name) { 396 logd("ExternalGatewayService: onServiceDisconnected"); 397 mExternalSatelliteGatewayService = null; 398 try { 399 mExternalGatewayServiceDisconnectedSemaphore.release(); 400 } catch (Exception ex) { 401 loge("ExternalGatewayService: ex=" + ex); 402 } 403 } 404 } 405 MockSatelliteServiceManager(Instrumentation instrumentation)406 MockSatelliteServiceManager(Instrumentation instrumentation) { 407 mInstrumentation = instrumentation; 408 mIsSatelliteServicePackageConfigured = !TextUtils.isEmpty(getSatelliteServicePackageName()); 409 } 410 connectSatelliteService()411 boolean connectSatelliteService() { 412 logd("connectSatelliteService starting ..."); 413 if (!setupLocalSatelliteService()) { 414 loge("Failed to set up local satellite service"); 415 return false; 416 } 417 418 try { 419 if (!setSatelliteServicePackageName(PACKAGE, true)) { 420 loge("Failed to set satellite service package name"); 421 return false; 422 } 423 } catch (Exception ex) { 424 loge("connectSatelliteService: Got exception with setSatelliteServicePackageName " 425 + "ex=" + ex); 426 return false; 427 } 428 429 // Wait for SatelliteModemInterface connecting to MockSatelliteService. 430 return waitForRemoteSatelliteServiceConnected(1); 431 } 432 connectExternalSatelliteService()433 boolean connectExternalSatelliteService() { 434 logd("connectExternalSatelliteService starting ..."); 435 if (!setupExternalSatelliteService()) { 436 loge("Failed to set up external satellite service"); 437 return false; 438 } 439 440 try { 441 if (!setSatelliteServicePackageName(EXTERNAL_SATELLITE_PACKAGE, null)) { 442 loge("Failed to set satellite service package name"); 443 return false; 444 } 445 } catch (Exception ex) { 446 loge("connectExternalSatelliteService: Got exception with " 447 + "setSatelliteServicePackageName, ex=" + ex); 448 return false; 449 } 450 return true; 451 } 452 setupExternalSatelliteService()453 boolean setupExternalSatelliteService() { 454 logd("setupExternalSatelliteService start"); 455 if (mExternalSatelliteService != null) { 456 logd("setupExternalSatelliteService: external service is already set up"); 457 return true; 458 } 459 CountDownLatch latch = new CountDownLatch(1); 460 mExternalSatelliteServiceConn = new ExternalSatelliteServiceConnection(latch); 461 Intent intent = new Intent(); 462 intent.setComponent(new ComponentName(EXTERNAL_SATELLITE_PACKAGE, 463 ExternalMockSatelliteService.class.getName())); 464 mInstrumentation.getContext().bindService(intent, mExternalSatelliteServiceConn, 465 Context.BIND_AUTO_CREATE); 466 try { 467 return latch.await(TIMEOUT, TimeUnit.MILLISECONDS); 468 } catch (InterruptedException e) { 469 loge("setupExternalSatelliteService: Got InterruptedException e=" + e); 470 return false; 471 } 472 } 473 connectSatelliteGatewayService()474 boolean connectSatelliteGatewayService() { 475 logd("connectSatelliteGatewayService starting ..."); 476 if (!setupLocalSatelliteGatewayService()) { 477 loge("Failed to set up local satellite gateway service"); 478 return false; 479 } 480 481 try { 482 if (!setSatelliteGatewayServicePackageName(PACKAGE)) { 483 loge("Failed to set satellite gateway service package name"); 484 return false; 485 } 486 } catch (Exception ex) { 487 loge("connectSatelliteGatewayService: Got exception with " 488 + "setSatelliteGatewayServicePackageName, ex=" + ex); 489 return false; 490 } 491 return true; 492 } 493 connectExternalSatelliteGatewayService()494 boolean connectExternalSatelliteGatewayService() { 495 logd("connectExternalSatelliteGatewayService starting ..."); 496 if (!setupExternalSatelliteGatewayService()) { 497 loge("Failed to set up external satellite gateway service"); 498 return false; 499 } 500 501 try { 502 if (!setSatelliteGatewayServicePackageName(EXTERNAL_SATELLITE_GATEWAY_PACKAGE)) { 503 loge("Failed to set satellite gateway service package name"); 504 return false; 505 } 506 } catch (Exception ex) { 507 loge("connectExternalSatelliteGatewayService: Got exception with " 508 + "setSatelliteGatewayServicePackageName, ex=" + ex); 509 return false; 510 } 511 return true; 512 } 513 setupExternalSatelliteGatewayService()514 boolean setupExternalSatelliteGatewayService() { 515 logd("setupExternalSatelliteGatewayService start"); 516 if (mExternalSatelliteGatewayService != null) { 517 logd("setupExternalSatelliteGatewayService: external service is already set up"); 518 return true; 519 } 520 CountDownLatch latch = new CountDownLatch(1); 521 mExternalSatelliteGatewayServiceConn = new ExternalSatelliteGatewayServiceConnection(latch); 522 Intent intent = new Intent(); 523 intent.setComponent(new ComponentName(EXTERNAL_SATELLITE_GATEWAY_PACKAGE, 524 ExternalMockSatelliteGatewayService.class.getName())); 525 mInstrumentation.getContext().bindService(intent, mExternalSatelliteGatewayServiceConn, 526 Context.BIND_AUTO_CREATE); 527 try { 528 return latch.await(TIMEOUT, TimeUnit.MILLISECONDS); 529 } catch (InterruptedException e) { 530 loge("setupExternalSatelliteGatewayService: Got InterruptedException e=" + e); 531 return false; 532 } 533 } 534 restoreSatelliteServicePackageName()535 boolean restoreSatelliteServicePackageName() { 536 logd("restoreSatelliteServicePackageName"); 537 try { 538 if (!setSatelliteServicePackageName(null, null)) { 539 loge("Failed to restore satellite service package name"); 540 return false; 541 } 542 } catch (Exception ex) { 543 loge("restoreSatelliteServicePackageName: Got exception with " 544 + "setSatelliteServicePackageName ex=" + ex); 545 return false; 546 } 547 return true; 548 } 549 restoreSatelliteGatewayServicePackageName()550 boolean restoreSatelliteGatewayServicePackageName() { 551 logd("restoreSatelliteGatewayServicePackageName"); 552 if (mSatelliteGatewayServiceConn != null) { 553 mInstrumentation.getContext().unbindService(mSatelliteGatewayServiceConn); 554 } 555 mSatelliteGatewayServiceConn = null; 556 mSatelliteGatewayService = null; 557 try { 558 if (!setSatelliteGatewayServicePackageName(null)) { 559 loge("Failed to restore satellite gateway service package name"); 560 return false; 561 } 562 } catch (Exception ex) { 563 loge("restoreSatelliteGatewayServicePackageName: Got exception with " 564 + "setSatelliteGatewayServicePackageName ex=" + ex); 565 return false; 566 } 567 return true; 568 } 569 overrideSatellitePointingUiClassName()570 boolean overrideSatellitePointingUiClassName() { 571 logd("overrideSatellitePointingUiClassName"); 572 try { 573 if (!setSatellitePointingUiClassName( 574 PACKAGE, MockPointingUiActivity.class.getName())) { 575 loge("Failed to override satellite pointing UI package and class names"); 576 return false; 577 } 578 } catch (Exception ex) { 579 loge("overrideSatellitePointingUiClassName: Got exception with " 580 + "setSatellitePointingUiClassName ex=" + ex); 581 return false; 582 } 583 registerForMockPointingUiActivityStatus(); 584 mIsPointingUiOverridden = true; 585 return true; 586 } 587 overrideExternalSatellitePointingUiClassName()588 boolean overrideExternalSatellitePointingUiClassName() { 589 logd("overrideExternalSatellitePointingUiClassName"); 590 try { 591 mActivityManager = mInstrumentation.getContext() 592 .getSystemService(ActivityManager.class); 593 mActivityManager.addOnUidImportanceListener(mUidImportanceListener, IMPORTANCE_GONE); 594 if (!setSatellitePointingUiClassName( 595 EXTERNAL_POINTING_UI_PACKAGE, ExternalMockPointingUi.class.getName())) { 596 loge("Failed to override external satellite pointing UI package and class names"); 597 return false; 598 } 599 } catch (Exception ex) { 600 loge("overrideExternalSatellitePointingUiClassName: Got exception with " 601 + "setSatellitePointingUiClassName ex=" + ex); 602 return false; 603 } 604 registerForExternalMockPointingUiActivityStatus(); 605 mIsPointingUiOverridden = true; 606 return true; 607 } restoreSatellitePointingUiClassName()608 boolean restoreSatellitePointingUiClassName() { 609 logd("restoreSatellitePointingUiClassName"); 610 if (!mIsPointingUiOverridden) { 611 return true; 612 } 613 try { 614 if (!setSatellitePointingUiClassName(null, null)) { 615 loge("Failed to restore satellite pointing UI package and class names"); 616 return false; 617 } 618 } catch (Exception ex) { 619 loge("restoreSatellitePointingUiClassName: Got exception with " 620 + "setSatellitePointingUiClassName ex=" + ex); 621 return false; 622 } 623 unregisterForMockPointingUiActivityStatus(); 624 mIsPointingUiOverridden = false; 625 return true; 626 } 627 isSatelliteServicePackageConfigured()628 boolean isSatelliteServicePackageConfigured() { 629 return mIsSatelliteServicePackageConfigured; 630 } 631 getSentIsEmergency(int index)632 Boolean getSentIsEmergency(int index) { 633 synchronized (mSendDatagramLock) { 634 if (index >= mSentIsEmergencyList.size()) return null; 635 return mSentIsEmergencyList.get(index); 636 } 637 } 638 getSentSatelliteDatagram(int index)639 SatelliteDatagram getSentSatelliteDatagram(int index) { 640 synchronized (mSendDatagramLock) { 641 if (index >= mSentSatelliteDatagrams.size()) return null; 642 return mSentSatelliteDatagrams.get(index); 643 } 644 } 645 clearSentSatelliteDatagramInfo()646 void clearSentSatelliteDatagramInfo() { 647 synchronized (mSendDatagramLock) { 648 mSentSatelliteDatagrams.clear(); 649 mSentIsEmergencyList.clear(); 650 mSendDatagramsSemaphore.drainPermits(); 651 } 652 } 653 clearRequestSatelliteEnabledPermits()654 void clearRequestSatelliteEnabledPermits() { 655 synchronized (mRequestSatelliteEnabledLock) { 656 mRequestSatelliteEnabledSemaphore.drainPermits(); 657 } 658 } 659 getTotalCountOfSentSatelliteDatagrams()660 int getTotalCountOfSentSatelliteDatagrams() { 661 synchronized (mSendDatagramLock) { 662 return mSentSatelliteDatagrams.size(); 663 } 664 } 665 getListeningEnabled(int index)666 Boolean getListeningEnabled(int index) { 667 synchronized (mListeningEnabledLock) { 668 if (index >= mListeningEnabledList.size()) return null; 669 return mListeningEnabledList.get(index); 670 } 671 } 672 getTotalCountOfListeningEnabledList()673 int getTotalCountOfListeningEnabledList() { 674 synchronized (mListeningEnabledLock) { 675 return mListeningEnabledList.size(); 676 } 677 } 678 clearListeningEnabledList()679 void clearListeningEnabledList() { 680 synchronized (mListeningEnabledLock) { 681 mListeningEnabledList.clear(); 682 mListeningEnabledSemaphore.drainPermits(); 683 } 684 } 685 clearMockPointingUiActivityStatusChanges()686 void clearMockPointingUiActivityStatusChanges() { 687 mMockPointingUiActivitySemaphore.drainPermits(); 688 } 689 clearRemoteGatewayServiceConnectedStatusChanges()690 void clearRemoteGatewayServiceConnectedStatusChanges() { 691 mRemoteGatewayServiceConnectedSemaphore.drainPermits(); 692 } 693 clearRemoteGatewayServiceDisconnectedStatusChanges()694 void clearRemoteGatewayServiceDisconnectedStatusChanges() { 695 mRemoteGatewayServiceDisconnectedSemaphore.drainPermits(); 696 } 697 clearStopPointingUiActivity()698 void clearStopPointingUiActivity() { 699 mStopPointingUiSemaphore.drainPermits(); 700 } 701 waitForEventOnStartSendingSatellitePointingInfo(int expectedNumberOfEvents)702 boolean waitForEventOnStartSendingSatellitePointingInfo(int expectedNumberOfEvents) { 703 for (int i = 0; i < expectedNumberOfEvents; i++) { 704 try { 705 if (!mStartSendingPointingInfoSemaphore.tryAcquire( 706 TIMEOUT, TimeUnit.MILLISECONDS)) { 707 loge("Timeout to receive onStartSendingSatellitePointingInfo"); 708 return false; 709 } 710 } catch (Exception ex) { 711 loge("onStartSendingSatellitePointingInfo: Got exception=" + ex); 712 return false; 713 } 714 } 715 return true; 716 } 717 waitForEventOnStopSendingSatellitePointingInfo(int expectedNumberOfEvents)718 boolean waitForEventOnStopSendingSatellitePointingInfo(int expectedNumberOfEvents) { 719 for (int i = 0; i < expectedNumberOfEvents; i++) { 720 try { 721 if (!mStopSendingPointingInfoSemaphore.tryAcquire( 722 TIMEOUT, TimeUnit.MILLISECONDS)) { 723 loge("Timeout to receive onStopSendingSatellitePointingInfo"); 724 return false; 725 } 726 } catch (Exception ex) { 727 loge("onStopSendingSatellitePointingInfo: Got exception=" + ex); 728 return false; 729 } 730 } 731 return true; 732 } 733 waitForEventOnPollPendingSatelliteDatagrams(int expectedNumberOfEvents)734 boolean waitForEventOnPollPendingSatelliteDatagrams(int expectedNumberOfEvents) { 735 for (int i = 0; i < expectedNumberOfEvents; i++) { 736 try { 737 if (!mPollPendingDatagramsSemaphore.tryAcquire( 738 TIMEOUT, TimeUnit.MILLISECONDS)) { 739 loge("Timeout to receive onPollPendingSatelliteDatagrams"); 740 return false; 741 } 742 } catch (Exception ex) { 743 loge("onPollPendingSatelliteDatagrams: Got exception=" + ex); 744 return false; 745 } 746 } 747 return true; 748 } 749 clearPollPendingDatagramPermits()750 void clearPollPendingDatagramPermits() { 751 mPollPendingDatagramsSemaphore.drainPermits(); 752 } 753 waitForEventOnSendSatelliteDatagram(int expectedNumberOfEvents)754 boolean waitForEventOnSendSatelliteDatagram(int expectedNumberOfEvents) { 755 for (int i = 0; i < expectedNumberOfEvents; i++) { 756 try { 757 if (!mSendDatagramsSemaphore.tryAcquire( 758 TIMEOUT, TimeUnit.MILLISECONDS)) { 759 loge("Timeout to receive onSendSatelliteDatagram"); 760 return false; 761 } 762 } catch (Exception ex) { 763 loge("onSendSatelliteDatagram: Got exception=" + ex); 764 return false; 765 } 766 } 767 return true; 768 } 769 waitForEventOnRequestSatelliteEnabled(int expectedNumberOfEvents)770 boolean waitForEventOnRequestSatelliteEnabled(int expectedNumberOfEvents) { 771 for (int i = 0; i < expectedNumberOfEvents; i++) { 772 try { 773 if (!mRequestSatelliteEnabledSemaphore.tryAcquire( 774 TIMEOUT, TimeUnit.MILLISECONDS)) { 775 loge("Timeout to receive OnRequestSatelliteEnabled"); 776 return false; 777 } 778 } catch (Exception ex) { 779 loge("OnRequestSatelliteEnabled: Got exception=" + ex); 780 return false; 781 } 782 } 783 return true; 784 } 785 waitForEventOnSatelliteListeningEnabled(int expectedNumberOfEvents)786 boolean waitForEventOnSatelliteListeningEnabled(int expectedNumberOfEvents) { 787 for (int i = 0; i < expectedNumberOfEvents; i++) { 788 try { 789 if (!mListeningEnabledSemaphore.tryAcquire( 790 TIMEOUT, TimeUnit.MILLISECONDS)) { 791 loge("Timeout to receive onSatelliteListeningEnabled"); 792 return false; 793 } 794 } catch (Exception ex) { 795 loge("onSatelliteListeningEnabled: Got exception=" + ex); 796 return false; 797 } 798 } 799 return true; 800 } 801 waitForRemoteSatelliteServiceConnected(int expectedNumberOfEvents)802 boolean waitForRemoteSatelliteServiceConnected(int expectedNumberOfEvents) { 803 for (int i = 0; i < expectedNumberOfEvents; i++) { 804 try { 805 if (!mRemoteServiceConnectedSemaphore.tryAcquire( 806 TIMEOUT, TimeUnit.MILLISECONDS)) { 807 loge("Timeout to receive RemoteSatelliteServiceConnected"); 808 return false; 809 } 810 } catch (Exception ex) { 811 loge("RemoteSatelliteServiceConnected: Got exception=" + ex); 812 return false; 813 } 814 } 815 return true; 816 } 817 waitForRemoteSatelliteGatewayServiceConnected(int expectedNumberOfEvents)818 boolean waitForRemoteSatelliteGatewayServiceConnected(int expectedNumberOfEvents) { 819 for (int i = 0; i < expectedNumberOfEvents; i++) { 820 try { 821 if (!mRemoteGatewayServiceConnectedSemaphore.tryAcquire( 822 TIMEOUT, TimeUnit.MILLISECONDS)) { 823 loge("Timeout to receive RemoteSatelliteGatewayServiceConnected"); 824 return false; 825 } 826 } catch (Exception ex) { 827 loge("RemoteSatelliteGatewayServiceConnected: Got exception=" + ex); 828 return false; 829 } 830 } 831 return true; 832 } 833 waitForRemoteSatelliteGatewayServiceDisconnected(int expectedNumberOfEvents)834 boolean waitForRemoteSatelliteGatewayServiceDisconnected(int expectedNumberOfEvents) { 835 for (int i = 0; i < expectedNumberOfEvents; i++) { 836 try { 837 if (!mRemoteGatewayServiceDisconnectedSemaphore.tryAcquire( 838 TIMEOUT, TimeUnit.MILLISECONDS)) { 839 loge("Timeout to receive RemoteGatewayServiceDisconnected"); 840 return false; 841 } 842 } catch (Exception ex) { 843 loge("RemoteGatewayServiceDisconnected: Got exception=" + ex); 844 return false; 845 } 846 } 847 return true; 848 } 849 waitForExternalSatelliteServiceDisconnected(int expectedNumberOfEvents)850 boolean waitForExternalSatelliteServiceDisconnected(int expectedNumberOfEvents) { 851 for (int i = 0; i < expectedNumberOfEvents; i++) { 852 try { 853 if (!mExternalServiceDisconnectedSemaphore.tryAcquire( 854 TIMEOUT, TimeUnit.MILLISECONDS)) { 855 loge("Timeout to receive ExternalServiceDisconnected"); 856 return false; 857 } 858 } catch (Exception ex) { 859 loge("ExternalServiceDisconnected: Got exception=" + ex); 860 return false; 861 } 862 } 863 return true; 864 } 865 waitForExternalSatelliteGatewayServiceDisconnected(int expectedNumberOfEvents)866 boolean waitForExternalSatelliteGatewayServiceDisconnected(int expectedNumberOfEvents) { 867 for (int i = 0; i < expectedNumberOfEvents; i++) { 868 try { 869 if (!mExternalGatewayServiceDisconnectedSemaphore.tryAcquire( 870 TIMEOUT, TimeUnit.MILLISECONDS)) { 871 loge("Timeout to receive ExternalGatewayServiceDisconnected"); 872 return false; 873 } 874 } catch (Exception ex) { 875 loge("ExternalGatewayServiceDisconnected: Got exception=" + ex); 876 return false; 877 } 878 } 879 return true; 880 } 881 waitForEventMockPointingUiActivityStarted(int expectedNumberOfEvents)882 boolean waitForEventMockPointingUiActivityStarted(int expectedNumberOfEvents) { 883 for (int i = 0; i < expectedNumberOfEvents; i++) { 884 try { 885 if (!mMockPointingUiActivitySemaphore.tryAcquire( 886 TIMEOUT, TimeUnit.MILLISECONDS)) { 887 loge("Timeout to receive MockPointingUiActivityStarted"); 888 return false; 889 } 890 } catch (Exception ex) { 891 loge("MockPointingUiActivityStarted: Got exception=" + ex); 892 return false; 893 } 894 } 895 return true; 896 } 897 waitForEventMockPointingUiActivityStopped(int expectedNumberOfEvents)898 boolean waitForEventMockPointingUiActivityStopped(int expectedNumberOfEvents) { 899 for (int i = 0; i < expectedNumberOfEvents; i++) { 900 try { 901 if (!mStopPointingUiSemaphore.tryAcquire( 902 TIMEOUT, TimeUnit.MILLISECONDS)) { 903 loge("Timeout to receive StopPointingUiSemaphore"); 904 return false; 905 } 906 } catch (Exception ex) { 907 loge("StopPointingUiSemaphore: Got exception=" + ex); 908 return false; 909 } 910 } 911 return true; 912 } 913 waitForEventOnSetSatellitePlmn(int expectedNumberOfEvents)914 boolean waitForEventOnSetSatellitePlmn(int expectedNumberOfEvents) { 915 for (int i = 0; i < expectedNumberOfEvents; i++) { 916 try { 917 if (!mSetSatellitePlmnSemaphore.tryAcquire( 918 TIMEOUT, TimeUnit.MILLISECONDS)) { 919 loge("Timeout to receive onSetSatellitePlmn"); 920 return false; 921 } 922 } catch (Exception ex) { 923 loge("onSetSatellitePlmn: Got exception=" + ex); 924 return false; 925 } 926 } 927 return true; 928 } 929 setErrorCode(int errorCode)930 void setErrorCode(int errorCode) { 931 logd("setErrorCode: errorCode=" + errorCode); 932 if (mSatelliteService == null) { 933 loge("setErrorCode: mSatelliteService is null"); 934 return; 935 } 936 mSatelliteService.setErrorCode(errorCode); 937 } 938 setEnableCellularScanningErrorCode(int errorCode)939 void setEnableCellularScanningErrorCode(int errorCode) { 940 logd("setEnableCellularScanningErrorCode: errorCode=" + errorCode); 941 if (mSatelliteService == null) { 942 loge("setEnableCellularScanningErrorCode: mSatelliteService is null"); 943 return; 944 } 945 mSatelliteService.setEnableCellularScanningErrorCode(errorCode); 946 } 947 setSupportedRadioTechnologies(@onNull int[] supportedRadioTechnologies)948 void setSupportedRadioTechnologies(@NonNull int[] supportedRadioTechnologies) { 949 logd("setSupportedRadioTechnologies: " + supportedRadioTechnologies[0]); 950 if (mSatelliteService == null) { 951 loge("setSupportedRadioTechnologies: mSatelliteService is null"); 952 return; 953 } 954 mSatelliteService.setSupportedRadioTechnologies(supportedRadioTechnologies); 955 } 956 setSatelliteSupport(boolean supported)957 void setSatelliteSupport(boolean supported) { 958 logd("setSatelliteSupport: supported=" + supported); 959 if (mSatelliteService == null) { 960 loge("setErrorCode: mSatelliteService is null"); 961 return; 962 } 963 mSatelliteService.setSatelliteSupport(supported); 964 } 965 setShouldRespondTelephony(boolean shouldRespondTelephony)966 public void setShouldRespondTelephony(boolean shouldRespondTelephony) { 967 logd("setShouldRespondTelephony: shouldRespondTelephony=" + shouldRespondTelephony); 968 if (mSatelliteService == null) { 969 loge("setShouldRespondTelephony: mSatelliteService is null"); 970 return; 971 } 972 mSatelliteService.setShouldRespondTelephony(shouldRespondTelephony); 973 } 974 setShouldRespondEnableRequest(boolean shouldRespond)975 public void setShouldRespondEnableRequest(boolean shouldRespond) { 976 logd("setShouldRespondEnableRequest: shouldRespond=" + shouldRespond); 977 if (mSatelliteService == null) { 978 loge("setShouldRespondEnableRequest: mSatelliteService is null"); 979 return; 980 } 981 mSatelliteService.setShouldRespondEnableRequest(shouldRespond); 982 } 983 setNtnSignalStrength( android.telephony.satellite.stub.NtnSignalStrength ntnSignalStrength)984 void setNtnSignalStrength( 985 android.telephony.satellite.stub.NtnSignalStrength ntnSignalStrength) { 986 if (mSatelliteService == null) { 987 loge("setNtnSignalStrength: mSatelliteService is null"); 988 return; 989 } 990 mSatelliteService.setNtnSignalStrength(ntnSignalStrength); 991 } 992 sendOnSatelliteDatagramReceived(SatelliteDatagram datagram, int pendingCount)993 void sendOnSatelliteDatagramReceived(SatelliteDatagram datagram, int pendingCount) { 994 logd("sendOnSatelliteDatagramReceived"); 995 if (mSatelliteService == null) { 996 loge("setErrorCode: mSatelliteService is null"); 997 return; 998 } 999 mSatelliteService.sendOnSatelliteDatagramReceived(datagram, pendingCount); 1000 } 1001 sendOnPendingDatagrams()1002 void sendOnPendingDatagrams() { 1003 logd("sendOnPendingDatagrams"); 1004 if (mSatelliteService == null) { 1005 loge("setErrorCode: mSatelliteService is null"); 1006 return; 1007 } 1008 mSatelliteService.sendOnPendingDatagrams(); 1009 } 1010 sendOnSatellitePositionChanged(PointingInfo pointingInfo)1011 void sendOnSatellitePositionChanged(PointingInfo pointingInfo) { 1012 logd("sendOnSatellitePositionChanged"); 1013 mSatelliteService.sendOnSatellitePositionChanged(pointingInfo); 1014 } 1015 sendOnSatelliteModemStateChanged(int modemState)1016 void sendOnSatelliteModemStateChanged(int modemState) { 1017 logd("sendOnSatelliteModemStateChanged: " + modemState); 1018 if (mSatelliteService == null) { 1019 loge("sendOnSatelliteModemStateChanged: mSatelliteService is null"); 1020 return; 1021 } 1022 mSatelliteService.sendOnSatelliteModemStateChanged(modemState); 1023 } 1024 sendOnNtnSignalStrengthChanged( android.telephony.satellite.stub.NtnSignalStrength ntnSignalStrength)1025 void sendOnNtnSignalStrengthChanged( 1026 android.telephony.satellite.stub.NtnSignalStrength ntnSignalStrength) { 1027 logd("sendOnNtnSignalStrengthChanged: " + ntnSignalStrength.signalStrengthLevel); 1028 if (mSatelliteService == null) { 1029 loge("sendOnNtnSignalStrengthChanged: mSatelliteService is null"); 1030 return; 1031 } 1032 mSatelliteService.sendOnNtnSignalStrengthChanged(ntnSignalStrength); 1033 } 1034 sendOnSatelliteCapabilitiesChanged( android.telephony.satellite.stub.SatelliteCapabilities satelliteCapabilities)1035 void sendOnSatelliteCapabilitiesChanged( 1036 android.telephony.satellite.stub.SatelliteCapabilities satelliteCapabilities) { 1037 logd("sendOnSatelliteCapabilitiesChanged: " + satelliteCapabilities); 1038 if (mSatelliteService == null) { 1039 loge("sendOnSatelliteCapabilitiesChanged: mSatelliteService is null"); 1040 return; 1041 } 1042 mSatelliteService.sendOnSatelliteCapabilitiesChanged(satelliteCapabilities); 1043 } 1044 sendOnSatelliteSupportedStateChanged(boolean supported)1045 void sendOnSatelliteSupportedStateChanged(boolean supported) { 1046 logd("sendOnSatelliteSupportedStateChanged: " + supported); 1047 if (mSatelliteService == null) { 1048 loge("sendOnSatelliteSupportedStateChanged: mSatelliteService is null"); 1049 return; 1050 } 1051 mSatelliteService.sendOnSatelliteSupportedStateChanged(supported); 1052 } 1053 setSatelliteListeningTimeoutDuration(long timeoutMillis)1054 boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { 1055 try { 1056 String result = 1057 TelephonyUtils.executeShellCommand(mInstrumentation, 1058 SET_SATELLITE_LISTENING_TIMEOUT_DURATION_CMD + timeoutMillis); 1059 logd("setSatelliteListeningTimeoutDuration: result = " + result); 1060 return "true".equals(result); 1061 } catch (Exception e) { 1062 loge("setSatelliteListeningTimeoutDuration: e=" + e); 1063 return false; 1064 } 1065 } 1066 setSatelliteIgnoreCellularServiceState(boolean enabled)1067 boolean setSatelliteIgnoreCellularServiceState(boolean enabled) { 1068 try { 1069 String result = 1070 TelephonyUtils.executeShellCommand(mInstrumentation, 1071 SET_SATELLITE_IGNORE_CELLULAR_SERVICE_STATE_CMD + enabled); 1072 logd("setSatelliteIgnoreCellularServiceState: result = " + result); 1073 return "true".equals(result); 1074 } catch (Exception e) { 1075 loge("setSatelliteIgnoreCellularServiceState: e=" + e); 1076 return false; 1077 } 1078 } 1079 setDatagramControllerTimeoutDuration( boolean reset, int timeoutType, long timeoutMillis)1080 boolean setDatagramControllerTimeoutDuration( 1081 boolean reset, int timeoutType, long timeoutMillis) { 1082 StringBuilder command = new StringBuilder(); 1083 command.append(SET_DATAGRAM_CONTROLLER_TIMEOUT_DURATION_CMD); 1084 if (reset) { 1085 command.append("-r"); 1086 } 1087 command.append(" -t " + timeoutType); 1088 command.append(" -d " + timeoutMillis); 1089 1090 try { 1091 String result = 1092 TelephonyUtils.executeShellCommand(mInstrumentation, command.toString()); 1093 logd("setDatagramControllerTimeoutDuration: result = " + result); 1094 return "true".equals(result); 1095 } catch (Exception e) { 1096 loge("setDatagramControllerTimeoutDuration: e=" + e); 1097 return false; 1098 } 1099 } 1100 setDatagramControllerBooleanConfig( boolean reset, int booleanType, boolean enable)1101 boolean setDatagramControllerBooleanConfig( 1102 boolean reset, int booleanType, boolean enable) { 1103 StringBuilder command = new StringBuilder(); 1104 command.append(SET_DATAGRAM_CONTROLLER_BOOLEAN_CONFIG_CMD); 1105 if (reset) { 1106 command.append("-r"); 1107 } 1108 command.append(" -t " + booleanType); 1109 command.append(" -d " + enable); 1110 1111 try { 1112 String result = 1113 TelephonyUtils.executeShellCommand(mInstrumentation, command.toString()); 1114 logd("setDatagramControllerBooleanConfig: result = " + result); 1115 return "true".equals(result); 1116 } catch (Exception e) { 1117 loge("setDatagramControllerBooleanConfig: e=" + e); 1118 return false; 1119 } 1120 } 1121 setSatelliteControllerTimeoutDuration( boolean reset, int timeoutType, long timeoutMillis)1122 boolean setSatelliteControllerTimeoutDuration( 1123 boolean reset, int timeoutType, long timeoutMillis) { 1124 StringBuilder command = new StringBuilder(); 1125 command.append(SET_SATELLITE_CONTROLLER_TIMEOUT_DURATION_CMD); 1126 if (reset) { 1127 command.append("-r"); 1128 } 1129 command.append(" -t " + timeoutType); 1130 command.append(" -d " + timeoutMillis); 1131 1132 try { 1133 String result = 1134 TelephonyUtils.executeShellCommand(mInstrumentation, command.toString()); 1135 logd("setSatelliteControllerTimeoutDuration: result = " + result); 1136 return "true".equals(result); 1137 } catch (Exception e) { 1138 loge("setSatelliteControllerTimeoutDuration: e=" + e); 1139 return false; 1140 } 1141 } 1142 setShouldSendDatagramToModemInDemoMode(boolean shouldSendToDemoMode)1143 boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToDemoMode) { 1144 try { 1145 String result = TelephonyUtils.executeShellCommand(mInstrumentation, 1146 SET_SHOULD_SEND_DATAGRAM_TO_MODEM_IN_DEMO_MODE 1147 + (shouldSendToDemoMode ? "true" : "false")); 1148 logd("setShouldSendDatagramToModemInDemoMode(" + shouldSendToDemoMode + "): result = " 1149 + result); 1150 return true; 1151 } catch (Exception e) { 1152 loge("setShouldSendDatagramToModemInDemoMode: e=" + e); 1153 return false; 1154 } 1155 } 1156 setWaitToSend(boolean wait)1157 void setWaitToSend(boolean wait) { 1158 logd("setWaitToSend: wait= " + wait); 1159 if (mSatelliteService == null) { 1160 loge("setWaitToSend: mSatelliteService is null"); 1161 return; 1162 } 1163 mSatelliteService.setWaitToSend(wait); 1164 } 1165 sendSavedDatagram()1166 boolean sendSavedDatagram() { 1167 logd("sendSavedDatagram"); 1168 if (mSatelliteService == null) { 1169 loge("sendSavedDatagram: mSatelliteService is null"); 1170 return false; 1171 } 1172 return mSatelliteService.sendSavedDatagram(); 1173 } 1174 respondToRequestSatelliteEnabled(boolean isEnabled, int modemState)1175 boolean respondToRequestSatelliteEnabled(boolean isEnabled, int modemState) { 1176 logd("respondToRequestSatelliteEnabled, isEnabled=" + isEnabled 1177 + ", modemState=" + modemState); 1178 if (mSatelliteService == null) { 1179 loge("respondToRequestSatelliteEnabled: mSatelliteService is null"); 1180 return false; 1181 } 1182 return mSatelliteService.respondToRequestSatelliteEnabled(isEnabled, modemState); 1183 } 1184 clearSatelliteEnableRequestQueues()1185 void clearSatelliteEnableRequestQueues() { 1186 logd("clearSatelliteEnableRequestQueues"); 1187 if (mSatelliteService == null) { 1188 loge("clearSatelliteEnableRequestQueues: mSatelliteService is null"); 1189 return; 1190 } 1191 mSatelliteService.clearSatelliteEnableRequestQueues(); 1192 } 1193 stopExternalSatelliteService()1194 boolean stopExternalSatelliteService() { 1195 logd("stopExternalSatelliteService"); 1196 try { 1197 TelephonyUtils.executeShellCommand(mInstrumentation, 1198 "am force-stop " + EXTERNAL_SATELLITE_PACKAGE); 1199 return true; 1200 } catch (Exception ex) { 1201 loge("stopExternalSatelliteService: ex=" + ex); 1202 return false; 1203 } 1204 } 1205 stopExternalSatelliteGatewayService()1206 boolean stopExternalSatelliteGatewayService() { 1207 logd("stopExternalSatelliteGatewayService"); 1208 try { 1209 TelephonyUtils.executeShellCommand(mInstrumentation, 1210 "am force-stop " + EXTERNAL_SATELLITE_GATEWAY_PACKAGE); 1211 return true; 1212 } catch (Exception ex) { 1213 loge("stopExternalSatelliteGatewayService: ex=" + ex); 1214 return false; 1215 } 1216 } 1217 resetSatelliteService()1218 void resetSatelliteService() { 1219 mSatelliteService = null; 1220 } 1221 stopExternalMockPointingUi()1222 boolean stopExternalMockPointingUi() { 1223 logd("stopExternalMockPointingUi"); 1224 try { 1225 TelephonyUtils.executeShellCommand(mInstrumentation, 1226 "am force-stop " + EXTERNAL_POINTING_UI_PACKAGE); 1227 return true; 1228 } catch (Exception ex) { 1229 loge("stopExternalMockPointingUi: ex=" + ex); 1230 return false; 1231 } 1232 } 1233 getCarrierPlmnList()1234 @Nullable List<String> getCarrierPlmnList() { 1235 if (mSatelliteService == null) { 1236 loge("getCarrierPlmnList: mSatelliteService is null"); 1237 return null; 1238 } 1239 return mSatelliteService.getCarrierPlmnList(); 1240 } 1241 getAllSatellitePlmnList()1242 @Nullable List<String> getAllSatellitePlmnList() { 1243 if (mSatelliteService == null) { 1244 loge("getAllSatellitePlmnList: mSatelliteService is null"); 1245 return null; 1246 } 1247 return mSatelliteService.getAllSatellitePlmnList(); 1248 } 1249 getIsSatelliteEnabledForCarrier()1250 @Nullable Boolean getIsSatelliteEnabledForCarrier() { 1251 if (mSatelliteService == null) { 1252 loge("getIsSatelliteEnabledForCarrier: mSatelliteService is null"); 1253 return null; 1254 } 1255 return mSatelliteService.getIsSatelliteEnabledForCarrier(); 1256 } 1257 clearSatelliteEnabledForCarrier()1258 void clearSatelliteEnabledForCarrier() { 1259 if (mSatelliteService == null) { 1260 loge("clearSatelliteEnabledForCarrier: mSatelliteService is null"); 1261 return; 1262 } 1263 mSatelliteService.clearSatelliteEnabledForCarrier(); 1264 } 1265 getPlmnListFromOverlayConfig()1266 @NonNull List<String> getPlmnListFromOverlayConfig() { 1267 String[] plmnArr = readStringArrayFromOverlayConfig("config_satellite_providers"); 1268 return Arrays.stream(plmnArr).toList(); 1269 } 1270 getIsEmergency()1271 @Nullable Boolean getIsEmergency() { 1272 if (mSatelliteService == null) { 1273 loge("getIsEmergency: mSatelliteService is null"); 1274 return null; 1275 } 1276 return mSatelliteService.getIsEmergency(); 1277 } 1278 1279 @Nullable getSystemSelectionChannels()1280 public List<SystemSelectionSpecifier> getSystemSelectionChannels() { 1281 if (mSatelliteService == null) { 1282 loge("getSystemSelectionChannels: mSatelliteService is null"); 1283 return null; 1284 } 1285 List<SystemSelectionSpecifier> converted = new ArrayList<>(); 1286 List<android.telephony.satellite.stub.SystemSelectionSpecifier> 1287 halSystemSelectionSpecifierList = mSatelliteService.getSystemSelectionChannels(); 1288 1289 if (!halSystemSelectionSpecifierList.isEmpty()) { 1290 for (android.telephony.satellite.stub.SystemSelectionSpecifier 1291 systemSelectionSpecifier : halSystemSelectionSpecifierList) { 1292 converted.add( 1293 covertSystemSelectionSpecifierFromHALFormat(systemSelectionSpecifier)); 1294 } 1295 } 1296 1297 return converted; 1298 } 1299 covertSystemSelectionSpecifierFromHALFormat( android.telephony.satellite.stub.SystemSelectionSpecifier systemSelectionSpecifier)1300 private SystemSelectionSpecifier covertSystemSelectionSpecifierFromHALFormat( 1301 android.telephony.satellite.stub.SystemSelectionSpecifier systemSelectionSpecifier) { 1302 String mccmnc = systemSelectionSpecifier.mMccMnc; 1303 1304 IntArray bands = new IntArray(systemSelectionSpecifier.mBands.length); 1305 bands.addAll(systemSelectionSpecifier.mBands); 1306 1307 IntArray earfcns = new IntArray(systemSelectionSpecifier.mEarfcs.length); 1308 earfcns.addAll(systemSelectionSpecifier.mEarfcs); 1309 1310 SatelliteInfo[] satelliteInfoArray = 1311 new SatelliteInfo[systemSelectionSpecifier.satelliteInfos.length]; 1312 android.telephony.satellite.stub.SatelliteInfo[] halSatelliteInfos = 1313 systemSelectionSpecifier.satelliteInfos; 1314 for (int i = 0; i < halSatelliteInfos.length; i++) { 1315 android.telephony.satellite.stub.SatelliteInfo halSatelliteInfo = halSatelliteInfos[i]; 1316 1317 long mostSigBits = halSatelliteInfo.id.mostSigBits; 1318 long leastSigBits = halSatelliteInfo.id.leastSigBits; 1319 UUID uuid = new UUID(mostSigBits, leastSigBits); 1320 1321 SatellitePosition satellitePosition; 1322 double longitudeDegree = halSatelliteInfo.position.longitudeDegree; 1323 double altitudeDegree = halSatelliteInfo.position.altitudeKm; 1324 if (longitudeDegree == 0 && altitudeDegree == 0) { 1325 satellitePosition = null; 1326 } else { 1327 satellitePosition = new SatellitePosition(longitudeDegree, altitudeDegree); 1328 } 1329 1330 List<Integer> bandList = Arrays.stream(halSatelliteInfo.bands).boxed().collect( 1331 Collectors.toList()); 1332 1333 List<EarfcnRange> earfcnRangeList = new ArrayList<>(); 1334 for (int j = 0; j < halSatelliteInfo.earfcnRanges.length; j++) { 1335 int startEarfcn = halSatelliteInfo.earfcnRanges[j].startEarfcn; 1336 int endEarfcn = halSatelliteInfo.earfcnRanges[j].endEarfcn; 1337 earfcnRangeList.add(new EarfcnRange(startEarfcn, endEarfcn)); 1338 } 1339 1340 satelliteInfoArray[i] = new SatelliteInfo(uuid, satellitePosition, bandList, 1341 earfcnRangeList); 1342 } 1343 1344 IntArray tagIds = new IntArray(systemSelectionSpecifier.tagIds.length); 1345 tagIds.addAll(systemSelectionSpecifier.tagIds); 1346 1347 return new SystemSelectionSpecifier(mccmnc, bands, earfcns, satelliteInfoArray, tagIds); 1348 } 1349 1350 /** Set telephony country codes */ setCountryCodes(boolean reset, @Nullable String currentNetworkCountryCodes, @Nullable String cachedNetworkCountryCodes, @Nullable String locationCountryCode, long locationCountryCodeTimestampNanos)1351 boolean setCountryCodes(boolean reset, @Nullable String currentNetworkCountryCodes, 1352 @Nullable String cachedNetworkCountryCodes, @Nullable String locationCountryCode, 1353 long locationCountryCodeTimestampNanos) { 1354 logd("setCountryCodes: reset= " + reset + ", currentNetworkCountryCodes=" 1355 + currentNetworkCountryCodes + ", cachedNetworkCountryCodes=" 1356 + cachedNetworkCountryCodes + ", locationCountryCode=" + locationCountryCode 1357 + ", locationCountryCodeTimestampNanos=" + locationCountryCodeTimestampNanos); 1358 try { 1359 StringBuilder command = new StringBuilder(); 1360 command.append(SET_COUNTRY_CODES); 1361 if (reset) { 1362 command.append(" -r"); 1363 } 1364 if (!TextUtils.isEmpty(currentNetworkCountryCodes)) { 1365 command.append(" -n "); 1366 command.append(currentNetworkCountryCodes); 1367 } 1368 if (!TextUtils.isEmpty(cachedNetworkCountryCodes)) { 1369 command.append(" -c "); 1370 command.append(cachedNetworkCountryCodes); 1371 } 1372 if (!TextUtils.isEmpty(locationCountryCode)) { 1373 command.append(" -l "); 1374 command.append(locationCountryCode); 1375 command.append(" -t "); 1376 command.append(locationCountryCodeTimestampNanos); 1377 } 1378 TelephonyUtils.executeShellCommand(mInstrumentation, command.toString()); 1379 return true; 1380 } catch (Exception ex) { 1381 loge("setCountryCodes: ex= " + ex); 1382 return false; 1383 } 1384 } 1385 1386 /** Set overlay configs for satellite access controller */ setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed, @Nullable String s2CellFile, long locationFreshDurationNanos, @Nullable String satelliteCountryCodes, @Nullable String satelliteAccessConfigurationFile)1387 boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed, 1388 @Nullable String s2CellFile, long locationFreshDurationNanos, 1389 @Nullable String satelliteCountryCodes, 1390 @Nullable String satelliteAccessConfigurationFile) { 1391 logd("setSatelliteAccessControlOverlayConfigs"); 1392 try { 1393 StringBuilder command = new StringBuilder(); 1394 command.append(SET_SATELLITE_ACCESS_CONTROL_OVERLAY_CONFIGS); 1395 if (reset) { 1396 command.append(" -r"); 1397 } else { 1398 if (isAllowed) { 1399 command.append(" -a"); 1400 } 1401 if (!TextUtils.isEmpty(s2CellFile)) { 1402 command.append(" -f "); 1403 command.append(s2CellFile); 1404 } 1405 command.append(" -d "); 1406 command.append(locationFreshDurationNanos); 1407 if (!TextUtils.isEmpty(satelliteCountryCodes)) { 1408 command.append(" -c "); 1409 command.append(satelliteCountryCodes); 1410 } 1411 if (!TextUtils.isEmpty(satelliteAccessConfigurationFile)) { 1412 command.append(" -g "); 1413 command.append(satelliteAccessConfigurationFile); 1414 } 1415 } 1416 logd("command=" + command); 1417 TelephonyUtils.executeShellCommand(mInstrumentation, command.toString()); 1418 return true; 1419 } catch (Exception ex) { 1420 loge("setSatelliteAccessControlOverlayConfigs: ex= " + ex); 1421 return false; 1422 } 1423 } 1424 overrideConfigDataVersion(boolean reset, int version)1425 boolean overrideConfigDataVersion(boolean reset, int version) { 1426 logd("overrideConfigDataVersion: reset=" + reset + ", version=" + version); 1427 try { 1428 StringBuilder command = new StringBuilder(); 1429 command.append(OVERRIDE_CONFIG_DATA_VERSION); 1430 if (reset) { 1431 command.append(" -r"); 1432 } else { 1433 command.append(" -v "); 1434 command.append(version); 1435 } 1436 logd("command=" + command); 1437 TelephonyUtils.executeShellCommand(mInstrumentation, command.toString()); 1438 return true; 1439 } catch (Exception ex) { 1440 loge("overrideConfigDataVersion: ex= " + ex); 1441 return false; 1442 } 1443 } 1444 updateTelephonyConfig(@onNull String contentUrl, @NonNull String metaDataUrl)1445 boolean updateTelephonyConfig(@NonNull String contentUrl, @NonNull String metaDataUrl) { 1446 logd("updateTelephonyConfig"); 1447 try { 1448 StringBuilder commandStringBuilder = new StringBuilder(); 1449 commandStringBuilder.append("am broadcast -a "); 1450 commandStringBuilder.append(UPDATE_TELEPHONY_CONFIG_INTENT); 1451 commandStringBuilder.append(" --es CONTENT_URL "); 1452 commandStringBuilder.append(contentUrl); 1453 commandStringBuilder.append(" --es METADATA_URL "); 1454 commandStringBuilder.append(metaDataUrl); 1455 commandStringBuilder.append(" -p "); 1456 commandStringBuilder.append(CONFIG_UPDATER_PACKAGE); 1457 TelephonyUtils.executeShellCommand(mInstrumentation, commandStringBuilder.toString()); 1458 logd("updateTelephonyConfig: " + commandStringBuilder.toString()); 1459 return true; 1460 } catch (Exception ex) { 1461 loge("updateTelephonyConfig: ex=" + ex); 1462 return false; 1463 } 1464 } 1465 readStringArrayFromOverlayConfig(@onNull String resourceName)1466 @NonNull private String[] readStringArrayFromOverlayConfig(@NonNull String resourceName) { 1467 String[] strArray = null; 1468 try { 1469 strArray = mInstrumentation.getContext().getResources().getStringArray( 1470 Resources.getSystem().getIdentifier(resourceName, "array", "android")); 1471 } catch (Resources.NotFoundException ex) { 1472 loge("readStringArrayFromOverlayConfig: resourceName = " 1473 + resourceName + ", ex = " + ex); 1474 } 1475 if (strArray == null) { 1476 strArray = new String[0]; 1477 } 1478 return strArray; 1479 } 1480 setupLocalSatelliteService()1481 private boolean setupLocalSatelliteService() { 1482 if (mSatelliteService != null) { 1483 logd("setupLocalSatelliteService: local service is already set up"); 1484 return true; 1485 } 1486 CountDownLatch latch = new CountDownLatch(1); 1487 mSatelliteServiceConn = new TestSatelliteServiceConnection(latch); 1488 mInstrumentation.getContext().bindService(new Intent(mInstrumentation.getContext(), 1489 MockSatelliteService.class), mSatelliteServiceConn, Context.BIND_AUTO_CREATE); 1490 try { 1491 return latch.await(TIMEOUT, TimeUnit.MILLISECONDS); 1492 } catch (InterruptedException e) { 1493 loge("setupLocalSatelliteService: Got InterruptedException e=" + e); 1494 return false; 1495 } 1496 } 1497 setupLocalSatelliteGatewayService()1498 private boolean setupLocalSatelliteGatewayService() { 1499 if (mSatelliteGatewayService != null) { 1500 logd("setupLocalSatelliteGatewayService: local service is already set up"); 1501 return true; 1502 } 1503 CountDownLatch latch = new CountDownLatch(1); 1504 mSatelliteGatewayServiceConn = new TestSatelliteGatewayServiceConnection(latch); 1505 mInstrumentation.getContext().bindService(new Intent(mInstrumentation.getContext(), 1506 MockSatelliteGatewayService.class), mSatelliteGatewayServiceConn, 1507 Context.BIND_AUTO_CREATE); 1508 try { 1509 return latch.await(TIMEOUT, TimeUnit.MILLISECONDS); 1510 } catch (InterruptedException e) { 1511 loge("setupLocalSatelliteGatewayService: Got InterruptedException e=" + e); 1512 return false; 1513 } 1514 } 1515 setSatelliteServicePackageName(@ullable String packageName, @Nullable Boolean provisioned)1516 private boolean setSatelliteServicePackageName(@Nullable String packageName, 1517 @Nullable Boolean provisioned) { 1518 String option = packageName; 1519 1520 if (provisioned != null) { 1521 option = option + " -p " + (provisioned ? "true" : "false"); 1522 } 1523 1524 try { 1525 TelephonyUtils.executeShellCommand(mInstrumentation, 1526 SET_SATELLITE_SERVICE_PACKAGE_NAME_CMD + option); 1527 return true; 1528 } catch (Exception ex) { 1529 loge("setSatelliteServicePackageName: ex= " + ex); 1530 return false; 1531 } 1532 } 1533 setSatelliteGatewayServicePackageName( @ullable String packageName)1534 private boolean setSatelliteGatewayServicePackageName( 1535 @Nullable String packageName) throws Exception { 1536 try { 1537 TelephonyUtils.executeShellCommand(mInstrumentation, 1538 SET_SATELLITE_GATEWAY_SERVICE_PACKAGE_NAME_CMD + packageName); 1539 return true; 1540 } catch (Exception ex) { 1541 loge("setSatelliteGatewayServicePackageName: ex=" + ex); 1542 return false; 1543 } 1544 } 1545 setSatellitePointingUiClassName( @ullable String packageName, @Nullable String className)1546 private boolean setSatellitePointingUiClassName( 1547 @Nullable String packageName, @Nullable String className) { 1548 try { 1549 TelephonyUtils.executeShellCommand(mInstrumentation, 1550 SET_SATELLITE_POINTING_UI_CLASS_NAME_CMD + " -p " + packageName 1551 + " -c " + className); 1552 return true; 1553 } catch (Exception ex) { 1554 loge("setSatellitePointingUiClassName: ex = " + ex); 1555 return false; 1556 } 1557 } 1558 setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state)1559 boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) { 1560 String option; 1561 if ("cache_allowed".equalsIgnoreCase(state)) { 1562 option = "-a"; 1563 } else if ("cache_clear_and_not_allowed".equalsIgnoreCase(state)) { 1564 option = "-n"; 1565 } else if ("clear_cache_only".equalsIgnoreCase(state)) { 1566 option = "-c"; 1567 } else { 1568 return false; 1569 } 1570 1571 try { 1572 String result = TelephonyUtils.executeShellCommand(mInstrumentation, 1573 SET_IS_SATELLITE_COMMUNICATION_ALLOWED_FOR_CURRENT_LOCATION_CACHE 1574 + option); 1575 logd("setIsSatelliteCommunicationAllowedForCurrentLocationCache(" + option 1576 + "): result = " + result); 1577 return true; 1578 } catch (Exception e) { 1579 loge("setIsSatelliteCommunicationAllowedForCurrentLocationCache: e=" + e); 1580 return false; 1581 } 1582 } 1583 setSatelliteAccessAllowedForSubscriptions(@ullable String subIdListStr)1584 boolean setSatelliteAccessAllowedForSubscriptions(@Nullable String subIdListStr) { 1585 String args = ""; 1586 if (!TextUtils.isEmpty(subIdListStr)) { 1587 args = " -s " + subIdListStr; 1588 } 1589 1590 try { 1591 String result = TelephonyUtils.executeShellCommand(mInstrumentation, 1592 SET_SATELLITE_ACCESS_ALLOWED_FOR_SUBSCRIPTIONS_CMD + args); 1593 logd("setSatelliteAccessAllowedForSubscriptions(" + args 1594 + "): result = " + result); 1595 return true; 1596 } catch (Exception e) { 1597 loge("setSatelliteAccessAllowedForSubscriptions: e=" + e); 1598 return false; 1599 } 1600 } 1601 setSatelliteTnScanningSupport(boolean reset, boolean concurrentTnScanningSupported, boolean tnScanningDuringSatelliteSessionAllowed)1602 boolean setSatelliteTnScanningSupport(boolean reset, boolean concurrentTnScanningSupported, 1603 boolean tnScanningDuringSatelliteSessionAllowed) { 1604 StringBuilder command = new StringBuilder(); 1605 command.append(SET_SATELLITE_TN_SCANNING_SUPPORT_CMD); 1606 if (reset) { 1607 command.append(" -r"); 1608 } else { 1609 command.append(" -s "); 1610 command.append(concurrentTnScanningSupported); 1611 command.append(" -a "); 1612 command.append(tnScanningDuringSatelliteSessionAllowed); 1613 } 1614 1615 try { 1616 String result = TelephonyUtils.executeShellCommand(mInstrumentation, 1617 command.toString()); 1618 logd("setSatelliteTnScanningSupport(" + command.toString() 1619 + "): result = " + result); 1620 return true; 1621 } catch (Exception e) { 1622 loge("setSatelliteTnScanningSupport: e=" + e); 1623 return false; 1624 } 1625 } 1626 setSupportDisableSatelliteWhileEnableInProgress(boolean reset, boolean supported)1627 boolean setSupportDisableSatelliteWhileEnableInProgress(boolean reset, boolean supported) { 1628 StringBuilder command = new StringBuilder(); 1629 command.append(SET_SUPPORT_DISABLE_SATELLITE_WHILE_ENABLE_IN_PROGRESS_CMD); 1630 if (reset) { 1631 command.append(" -r"); 1632 } else { 1633 command.append(" -s "); 1634 command.append(supported); 1635 } 1636 1637 try { 1638 String result = TelephonyUtils.executeShellCommand(mInstrumentation, 1639 command.toString()); 1640 logd("setSupportDisableSatelliteWhileEnableInProgress(" + command.toString() 1641 + "): result = " + result); 1642 return true; 1643 } catch (Exception e) { 1644 loge("setSupportDisableSatelliteWhileEnableInProgress: e=" + e); 1645 return false; 1646 } 1647 } 1648 setSatelliteSubscriberIdListChangedIntentComponent(String name)1649 boolean setSatelliteSubscriberIdListChangedIntentComponent(String name) { 1650 String option; 1651 if ("package".equalsIgnoreCase(name)) { 1652 option = "-p"; 1653 } else if ("class".equalsIgnoreCase(name)) { 1654 option = "-c"; 1655 } else if ("reset".equalsIgnoreCase(name)) { 1656 option = "-r"; 1657 } else { 1658 return false; 1659 } 1660 1661 try { 1662 String result = TelephonyUtils.executeShellCommand(mInstrumentation, 1663 SET_SATELLITE_SUBSCRIBERID_LIST_CHANGED_INTENT_COMPONENT + option); 1664 logd("setSatelliteSubscriberIdListChangedIntentComponent(" + option + "): result = " 1665 + result); 1666 return true; 1667 } catch (Exception e) { 1668 loge("setSatelliteSubscriberIdListChangedIntentComponent: e=" + e); 1669 return false; 1670 } 1671 } 1672 setSatelliteIgnorePlmnListFromStorage(boolean enabled)1673 boolean setSatelliteIgnorePlmnListFromStorage(boolean enabled) { 1674 try { 1675 String result = 1676 TelephonyUtils.executeShellCommand( 1677 mInstrumentation, 1678 SET_SATELLITE_IGNORE_PLMN_LIST_FROM_STORAGE + enabled); 1679 logd("setSatelliteIgnorePlmnListFromStorage: result = " + result); 1680 return "true".equals(result); 1681 } catch (Exception e) { 1682 loge("setSatelliteIgnorePlmnListFromStorage: e=" + e); 1683 return false; 1684 } 1685 } 1686 registerForMockPointingUiActivityStatus()1687 private void registerForMockPointingUiActivityStatus() { 1688 IntentFilter intentFilter = new IntentFilter( 1689 MockPointingUiActivity.ACTION_MOCK_POINTING_UI_ACTIVITY_STARTED); 1690 mInstrumentation.getContext().registerReceiver( 1691 mMockPointingUiActivityStatusReceiver, intentFilter, Context.RECEIVER_EXPORTED); 1692 } 1693 registerForExternalMockPointingUiActivityStatus()1694 private void registerForExternalMockPointingUiActivityStatus() { 1695 logd("registerForExternalMockPointingUiActivityStatus"); 1696 IntentFilter intentFilter = new IntentFilter( 1697 ExternalMockPointingUi.ACTION_MOCK_POINTING_UI_ACTIVITY_STARTED); 1698 mInstrumentation.getContext().registerReceiver( 1699 mMockPointingUiActivityStatusReceiver, intentFilter, Context.RECEIVER_EXPORTED); 1700 } 1701 unregisterForMockPointingUiActivityStatus()1702 private void unregisterForMockPointingUiActivityStatus() { 1703 mInstrumentation.getContext().unregisterReceiver(mMockPointingUiActivityStatusReceiver); 1704 } 1705 logd(@onNull String log)1706 private static void logd(@NonNull String log) { 1707 Log.d(TAG, log); 1708 } 1709 loge(@onNull String log)1710 private static void loge(@NonNull String log) { 1711 Log.e(TAG, log); 1712 } 1713 1714 private static class MockPointingUiActivityStatusReceiver extends BroadcastReceiver { 1715 private Semaphore mSemaphore; 1716 MockPointingUiActivityStatusReceiver(Semaphore semaphore)1717 MockPointingUiActivityStatusReceiver(Semaphore semaphore) { 1718 mSemaphore = semaphore; 1719 } 1720 1721 @Override onReceive(Context context, Intent intent)1722 public void onReceive(Context context, Intent intent) { 1723 logd("MockPointingUiActivityStatusReceiver: onReceive " + intent.getAction()); 1724 if ((MockPointingUiActivity.ACTION_MOCK_POINTING_UI_ACTIVITY_STARTED.equals( 1725 intent.getAction())) 1726 || (ExternalMockPointingUi.ACTION_MOCK_POINTING_UI_ACTIVITY_STARTED.equals( 1727 intent.getAction()))) { 1728 logd("MockPointingUiActivityStatusReceiver: onReceive"); 1729 try { 1730 mSemaphore.release(); 1731 } catch (Exception ex) { 1732 loge("MockPointingUiActivityStatusReceiver: Got exception, ex=" + ex); 1733 } 1734 } 1735 } 1736 } 1737 getSatelliteServicePackageName()1738 private String getSatelliteServicePackageName() { 1739 return TextUtils.emptyIfNull(mInstrumentation.getContext().getResources().getString( 1740 R.string.config_satellite_service_package)); 1741 } 1742 } 1743