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.phone.testapps.satellitetestapp; 18 19 import android.annotation.NonNull; 20 import android.app.Activity; 21 import android.content.Intent; 22 import android.os.Bundle; 23 import android.os.OutcomeReceiver; 24 import android.telephony.SubscriptionInfo; 25 import android.telephony.SubscriptionManager; 26 import android.telephony.satellite.wrapper.CarrierRoamingNtnModeListenerWrapper2; 27 import android.telephony.satellite.wrapper.NtnSignalStrengthCallbackWrapper; 28 import android.telephony.satellite.wrapper.NtnSignalStrengthWrapper; 29 import android.telephony.satellite.wrapper.SatelliteAccessConfigurationWrapper; 30 import android.telephony.satellite.wrapper.SatelliteCapabilitiesCallbackWrapper; 31 import android.telephony.satellite.wrapper.SatelliteCommunicationAllowedStateCallbackWrapper; 32 import android.telephony.satellite.wrapper.SatelliteManagerWrapper; 33 import android.telephony.satellite.wrapper.SatelliteModemStateCallbackWrapper2; 34 import android.telephony.satellite.wrapper.SatelliteSubscriberInfoWrapper; 35 import android.telephony.satellite.wrapper.SatelliteSubscriberProvisionStatusWrapper; 36 import android.util.Log; 37 import android.view.View; 38 import android.view.View.OnClickListener; 39 import android.widget.ArrayAdapter; 40 import android.widget.ListView; 41 42 import java.util.ArrayList; 43 import java.util.List; 44 import java.util.Map; 45 import java.util.Set; 46 import java.util.concurrent.ExecutorService; 47 import java.util.concurrent.Executors; 48 import java.util.function.Consumer; 49 import java.util.stream.Collectors; 50 51 /** 52 * Activity related to SatelliteControl APIs for satellite. 53 */ 54 public class TestSatelliteWrapper extends Activity { 55 private static final String TAG = "TestSatelliteWrapper"; 56 ArrayList<String> mLogMessages = new ArrayList<>(); 57 ArrayAdapter<String> mAdapter; 58 59 private final ExecutorService mExecutor = Executors.newSingleThreadExecutor(); 60 private SatelliteManagerWrapper mSatelliteManagerWrapper; 61 private NtnSignalStrengthCallback mNtnSignalStrengthCallback = null; 62 private SatelliteModemStateCallback mModemStateCallback = null; 63 private CarrierRoamingNtnModeListener mCarrierRoamingNtnModeListener = null; 64 private SatelliteCommunicationAllowedStateCallback mSatelliteCommunicationAllowedStateCallback; 65 private SatelliteCapabilitiesCallbackWrapper mSatelliteCapabilitiesCallback; 66 private SubscriptionManager mSubscriptionManager; 67 private int mSubId; 68 private List<SatelliteSubscriberProvisionStatusWrapper> mSatelliteSubscriberProvisionStatuses = 69 new ArrayList<>(); 70 71 private ListView mLogListView; 72 73 @Override onCreate(Bundle savedInstanceState)74 public void onCreate(Bundle savedInstanceState) { 75 super.onCreate(savedInstanceState); 76 mSatelliteManagerWrapper = SatelliteManagerWrapper.getInstance(this); 77 mSubscriptionManager = getSystemService(SubscriptionManager.class); 78 mSubId = getActiveSubId(); 79 80 setContentView(R.layout.activity_TestSatelliteWrapper); 81 findViewById(R.id.requestNtnSignalStrength) 82 .setOnClickListener(this::requestNtnSignalStrength); 83 findViewById(R.id.registerForNtnSignalStrengthChanged) 84 .setOnClickListener(this::registerForNtnSignalStrengthChanged); 85 findViewById(R.id.unregisterForNtnSignalStrengthChanged) 86 .setOnClickListener(this::unregisterForNtnSignalStrengthChanged); 87 findViewById(R.id.isOnlyNonTerrestrialNetworkSubscription) 88 .setOnClickListener(this::isOnlyNonTerrestrialNetworkSubscription); 89 findViewById(R.id.registerForSatelliteCapabilitiesChanged) 90 .setOnClickListener(this::registerForCapabilitiesChanged); 91 findViewById(R.id.unregisterForSatelliteCapabilitiesChanged) 92 .setOnClickListener(this::unregisterForCapabilitiesChanged); 93 findViewById(R.id.isNonTerrestrialNetwork) 94 .setOnClickListener(this::isNonTerrestrialNetwork); 95 findViewById(R.id.getAvailableServices) 96 .setOnClickListener(this::getAvailableServices); 97 findViewById(R.id.isUsingNonTerrestrialNetwork) 98 .setOnClickListener(this::isUsingNonTerrestrialNetwork); 99 findViewById(R.id.requestAttachEnabledForCarrier_enable) 100 .setOnClickListener(this::requestAttachEnabledForCarrier_enable); 101 findViewById(R.id.requestAttachEnabledForCarrier_disable) 102 .setOnClickListener(this::requestAttachEnabledForCarrier_disable); 103 findViewById(R.id.requestIsAttachEnabledForCarrier) 104 .setOnClickListener(this::requestIsAttachEnabledForCarrier); 105 findViewById(R.id.addAttachRestrictionForCarrier) 106 .setOnClickListener(this::addAttachRestrictionForCarrier); 107 findViewById(R.id.removeAttachRestrictionForCarrier) 108 .setOnClickListener(this::removeAttachRestrictionForCarrier); 109 findViewById(R.id.getAttachRestrictionReasonsForCarrier) 110 .setOnClickListener(this::getAttachRestrictionReasonsForCarrier); 111 findViewById(R.id.getSatellitePlmnsForCarrier) 112 .setOnClickListener(this::getSatellitePlmnsForCarrier); 113 findViewById(R.id.registerForCarrierRoamingNtnModeChanged) 114 .setOnClickListener(this::registerForCarrierRoamingNtnModeChanged); 115 findViewById(R.id.unregisterForCarrierRoamingNtnModeChanged) 116 .setOnClickListener(this::unregisterForCarrierRoamingNtnModeChanged); 117 findViewById(R.id.registerForCommunicationAllowedStateChanged) 118 .setOnClickListener(this::registerForCommunicationAllowedStateChanged); 119 findViewById(R.id.unregisterForCommunicationAllowedStateChanged) 120 .setOnClickListener(this::unregisterForCommunicationAllowedStateChanged); 121 findViewById(R.id.registerForModemStateChanged) 122 .setOnClickListener(this::registerForModemStateChanged); 123 findViewById(R.id.unregisterForModemStateChanged) 124 .setOnClickListener(this::unregisterForModemStateChanged); 125 findViewById(R.id.requestSatelliteSubscriberProvisionStatusWrapper) 126 .setOnClickListener(this::requestSatelliteSubscriberProvisionStatus); 127 findViewById(R.id.provisionSatelliteWrapper) 128 .setOnClickListener(this::provisionSatellite); 129 findViewById(R.id.deprovisionSatelliteWrapper) 130 .setOnClickListener(this::deprovisionSatellite); 131 findViewById(R.id.setNtnSmsSupportedTrue) 132 .setOnClickListener(this::setNtnSmsSupportedTrue); 133 findViewById(R.id.setNtnSmsSupportedFalse) 134 .setOnClickListener(this::setNtnSmsSupportedFalse); 135 findViewById(R.id.requestSatelliteAccessConfigurationForCurrentLocation) 136 .setOnClickListener(this::requestSatelliteAccessConfigurationForCurrentLocation); 137 138 139 140 findViewById(R.id.Back).setOnClickListener(new OnClickListener() { 141 @Override 142 public void onClick(View view) { 143 startActivity(new Intent(TestSatelliteWrapper.this, SatelliteTestApp.class)); 144 } 145 }); 146 findViewById(R.id.ClearLog).setOnClickListener(new OnClickListener() { 147 @Override 148 public void onClick(View v) { 149 clearListView(); 150 } 151 }); 152 153 mLogListView = findViewById(R.id.logListView); 154 mAdapter = new ArrayAdapter<>(this, R.layout.log_textview, mLogMessages); 155 mLogListView.setAdapter(mAdapter); 156 157 addLogMessage("TestSatelliteWrapper.onCreate()"); 158 } 159 160 clearListView()161 private void clearListView() { 162 mLogMessages.clear(); 163 mAdapter.notifyDataSetChanged(); 164 } 165 166 @Override onDestroy()167 protected void onDestroy() { 168 super.onDestroy(); 169 170 if (mSatelliteManagerWrapper != null) { 171 if (mNtnSignalStrengthCallback != null) { 172 logd("unregisterForNtnSignalStrengthChanged()"); 173 mSatelliteManagerWrapper.unregisterForNtnSignalStrengthChanged( 174 mNtnSignalStrengthCallback); 175 } 176 if (mSatelliteCapabilitiesCallback != null) { 177 logd("unregisterForCapabilitiesChanged()"); 178 mSatelliteManagerWrapper.unregisterForCapabilitiesChanged( 179 mSatelliteCapabilitiesCallback); 180 } 181 } 182 mSubscriptionManager = null; 183 mSatelliteManagerWrapper = null; 184 mExecutor.shutdown(); 185 } 186 requestNtnSignalStrength(View view)187 private void requestNtnSignalStrength(View view) { 188 addLogMessage("requestNtnSignalStrength"); 189 logd("requestNtnSignalStrength"); 190 OutcomeReceiver<NtnSignalStrengthWrapper, 191 SatelliteManagerWrapper.SatelliteExceptionWrapper> receiver = 192 new OutcomeReceiver<>() { 193 @Override 194 public void onResult(NtnSignalStrengthWrapper level) { 195 if (level != null) { 196 addLogMessage("requestNtnSignalStrength level is " + level.getLevel()); 197 } 198 } 199 200 @Override 201 public void onError( 202 SatelliteManagerWrapper.SatelliteExceptionWrapper exception) { 203 if (exception != null) { 204 String onError = "requestNtnSignalStrength exception: " 205 + translateResultCodeToString(exception.getErrorCode()); 206 logd(onError); 207 addLogMessage(onError); 208 } 209 } 210 }; 211 212 try { 213 mSatelliteManagerWrapper.requestNtnSignalStrength(mExecutor, receiver); 214 } catch (SecurityException ex) { 215 String errorMessage = "requestNtnSignalStrength: " + ex.getMessage(); 216 logd(errorMessage); 217 addLogMessage(errorMessage); 218 } 219 } 220 registerForCarrierRoamingNtnModeChanged(View view)221 private void registerForCarrierRoamingNtnModeChanged(View view) { 222 addLogMessage("registerForCarrierRoamingNtnModeChanged"); 223 logd("registerForCarrierRoamingNtnModeChanged()"); 224 if (mCarrierRoamingNtnModeListener == null) { 225 logd("Creating new CarrierRoamingNtnModeListener instance."); 226 mCarrierRoamingNtnModeListener = new CarrierRoamingNtnModeListener(); 227 } 228 229 try { 230 mSatelliteManagerWrapper.registerForCarrierRoamingNtnModeChanged(mSubId, mExecutor, 231 mCarrierRoamingNtnModeListener); 232 } catch (Exception ex) { 233 String errorMessage = "registerForCarrierRoamingNtnModeChanged: " + ex.getMessage(); 234 logd(errorMessage); 235 addLogMessage(errorMessage); 236 mCarrierRoamingNtnModeListener = null; 237 } 238 } 239 unregisterForCarrierRoamingNtnModeChanged(View view)240 private void unregisterForCarrierRoamingNtnModeChanged(View view) { 241 addLogMessage("unregisterForCarrierRoamingNtnModeChanged"); 242 logd("unregisterForCarrierRoamingNtnModeChanged()"); 243 if (mCarrierRoamingNtnModeListener != null) { 244 mSatelliteManagerWrapper.unregisterForCarrierRoamingNtnModeChanged(mSubId, 245 mCarrierRoamingNtnModeListener); 246 mCarrierRoamingNtnModeListener = null; 247 addLogMessage("mCarrierRoamingNtnModeListener was unregistered"); 248 } else { 249 addLogMessage("mCarrierRoamingNtnModeListener is null, ignored."); 250 } 251 } 252 registerForCommunicationAllowedStateChanged(View view)253 private void registerForCommunicationAllowedStateChanged(View view) { 254 addLogMessage("registerForCommunicationAllowedStateChanged"); 255 logd("registerForCommunicationAllowedStateChanged()"); 256 if (mSatelliteCommunicationAllowedStateCallback == null) { 257 logd("Creating new CarrierRoamingNtnModeListener instance."); 258 mSatelliteCommunicationAllowedStateCallback = 259 new SatelliteCommunicationAllowedStateCallback(); 260 } 261 262 try { 263 mSatelliteManagerWrapper.registerForCommunicationAllowedStateChanged(mExecutor, 264 mSatelliteCommunicationAllowedStateCallback); 265 } catch (Exception ex) { 266 String errorMessage = "registerForCommunicationAllowedStateChanged: " + ex.getMessage(); 267 logd(errorMessage); 268 addLogMessage(errorMessage); 269 mSatelliteCommunicationAllowedStateCallback = null; 270 } 271 } 272 unregisterForCommunicationAllowedStateChanged(View view)273 private void unregisterForCommunicationAllowedStateChanged(View view) { 274 addLogMessage("unregisterForCommunicationAllowedStateChanged"); 275 logd("unregisterForCommunicationAllowedStateChanged()"); 276 if (mSatelliteCommunicationAllowedStateCallback != null) { 277 mSatelliteManagerWrapper.unregisterForCommunicationAllowedStateChanged( 278 mSatelliteCommunicationAllowedStateCallback); 279 mSatelliteCommunicationAllowedStateCallback = null; 280 addLogMessage("mSatelliteCommunicationAllowedStateCallback was unregistered"); 281 } else { 282 addLogMessage("mSatelliteCommunicationAllowedStateCallback is null, ignored."); 283 } 284 } 285 registerForNtnSignalStrengthChanged(View view)286 private void registerForNtnSignalStrengthChanged(View view) { 287 addLogMessage("registerForNtnSignalStrengthChanged"); 288 logd("registerForNtnSignalStrengthChanged()"); 289 if (mNtnSignalStrengthCallback == null) { 290 logd("create new NtnSignalStrengthCallback instance."); 291 mNtnSignalStrengthCallback = new NtnSignalStrengthCallback(); 292 } 293 294 try { 295 mSatelliteManagerWrapper.registerForNtnSignalStrengthChanged(mExecutor, 296 mNtnSignalStrengthCallback); 297 } catch (Exception ex) { 298 String errorMessage = "registerForNtnSignalStrengthChanged: " + ex.getMessage(); 299 logd(errorMessage); 300 addLogMessage(errorMessage); 301 mNtnSignalStrengthCallback = null; 302 } 303 } 304 unregisterForNtnSignalStrengthChanged(View view)305 private void unregisterForNtnSignalStrengthChanged(View view) { 306 addLogMessage("unregisterForNtnSignalStrengthChanged"); 307 logd("unregisterForNtnSignalStrengthChanged()"); 308 if (mNtnSignalStrengthCallback != null) { 309 mSatelliteManagerWrapper.unregisterForNtnSignalStrengthChanged( 310 mNtnSignalStrengthCallback); 311 mNtnSignalStrengthCallback = null; 312 addLogMessage("mNtnSignalStrengthCallback was unregistered"); 313 } else { 314 addLogMessage("mNtnSignalStrengthCallback is null, ignored."); 315 } 316 } 317 isOnlyNonTerrestrialNetworkSubscription(View view)318 private void isOnlyNonTerrestrialNetworkSubscription(View view) { 319 addLogMessage("isOnlyNonTerrestrialNetworkSubscription"); 320 logd("isOnlyNonTerrestrialNetworkSubscription()"); 321 List<SubscriptionInfo> infoList = mSubscriptionManager.getAvailableSubscriptionInfoList(); 322 List<Integer> subIdList = infoList.stream() 323 .map(SubscriptionInfo::getSubscriptionId) 324 .toList(); 325 326 Map<Integer, Boolean> resultMap = subIdList.stream().collect( 327 Collectors.toMap( 328 id -> id, 329 id -> { 330 boolean result = mSatelliteManagerWrapper 331 .isOnlyNonTerrestrialNetworkSubscription(id); 332 addLogMessage("SatelliteManagerWrapper" 333 + ".isOnlyNonTerrestrialNetworkSubscription(" + id + ")"); 334 return result; 335 } 336 )); 337 338 for (Map.Entry<Integer, Boolean> entry : resultMap.entrySet()) { 339 int subId = entry.getKey(); 340 boolean result = entry.getValue(); 341 addLogMessage("Subscription ID: " + subId + ", Result: " + result); 342 } 343 } 344 registerForCapabilitiesChanged(View view)345 private void registerForCapabilitiesChanged(View view) { 346 addLogMessage("registerForCapabilitiesChanged"); 347 logd("registerForCapabilitiesChanged()"); 348 if (mSatelliteCapabilitiesCallback == null) { 349 mSatelliteCapabilitiesCallback = 350 SatelliteCapabilities -> { 351 String message = "Received SatelliteCapabillities : " 352 + SatelliteCapabilities; 353 logd(message); 354 addLogMessage(message); 355 }; 356 } 357 358 int result = mSatelliteManagerWrapper.registerForCapabilitiesChanged(mExecutor, 359 mSatelliteCapabilitiesCallback); 360 if (result != SatelliteManagerWrapper.SATELLITE_RESULT_SUCCESS) { 361 String onError = translateResultCodeToString(result); 362 logd(onError); 363 addLogMessage(onError); 364 mSatelliteCapabilitiesCallback = null; 365 } 366 } 367 unregisterForCapabilitiesChanged(View view)368 private void unregisterForCapabilitiesChanged(View view) { 369 addLogMessage("unregisterForCapabilitiesChanged"); 370 logd("unregisterForCapabilitiesChanged()"); 371 if (mSatelliteCapabilitiesCallback != null) { 372 mSatelliteManagerWrapper.unregisterForCapabilitiesChanged( 373 mSatelliteCapabilitiesCallback); 374 mSatelliteCapabilitiesCallback = null; 375 addLogMessage("mSatelliteCapabilitiesCallback was unregistered"); 376 } else { 377 addLogMessage("mSatelliteCapabilitiesCallback is null, ignored."); 378 } 379 } 380 registerForModemStateChanged(View view)381 private void registerForModemStateChanged(View view) { 382 addLogMessage("registerForModemStateChanged"); 383 logd("registerForSatelliteModemStateChanged()"); 384 if (mModemStateCallback == null) { 385 logd("create new ModemStateCallback instance."); 386 mModemStateCallback = new SatelliteModemStateCallback(); 387 } 388 389 try { 390 mSatelliteManagerWrapper.registerForModemStateChanged(mExecutor, mModemStateCallback); 391 } catch (Exception ex) { 392 String errorMessage = "registerForModemStateChanged: " + ex.getMessage(); 393 logd(errorMessage); 394 addLogMessage(errorMessage); 395 mModemStateCallback = null; 396 } 397 } 398 unregisterForModemStateChanged(View view)399 private void unregisterForModemStateChanged(View view) { 400 addLogMessage("unregisterForModemStateChanged"); 401 logd("unregisterForModemStateChanged()"); 402 if (mModemStateCallback != null) { 403 mSatelliteManagerWrapper.unregisterForModemStateChanged(mModemStateCallback); 404 mModemStateCallback = null; 405 addLogMessage("mModemStateCallback was unregistered"); 406 } else { 407 addLogMessage("mModemStateCallback is null, ignored."); 408 } 409 } 410 requestSatelliteSubscriberProvisionStatus(View view)411 private void requestSatelliteSubscriberProvisionStatus(View view) { 412 addLogMessage("requestSatelliteSubscriberProvisionStatus"); 413 logd("requestSatelliteSubscriberProvisionStatus"); 414 415 if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { 416 addLogMessage("requestSatelliteSubscriberProvisionStatus: Subscription ID is invalid"); 417 logd("requestSatelliteSubscriberProvisionStatus: Subscription ID is invalid"); 418 return; 419 } 420 421 OutcomeReceiver<List<SatelliteSubscriberProvisionStatusWrapper>, 422 SatelliteManagerWrapper.SatelliteExceptionWrapper> receiver = 423 new OutcomeReceiver<>() { 424 @Override 425 public void onResult(List<SatelliteSubscriberProvisionStatusWrapper> result) { 426 mSatelliteSubscriberProvisionStatuses = result; 427 logd("requestSatelliteSubscriberProvisionStatus: onResult=" + result); 428 addLogMessage( 429 "requestSatelliteSubscriberProvisionStatus: onResult=" + result); 430 } 431 432 @Override 433 public void onError( 434 SatelliteManagerWrapper.SatelliteExceptionWrapper exception) { 435 if (exception != null) { 436 String onError = "requestSatelliteSubscriberProvisionStatus exception: " 437 + translateResultCodeToString(exception.getErrorCode()); 438 logd(onError); 439 addLogMessage(onError); 440 } 441 } 442 }; 443 444 try { 445 mSatelliteManagerWrapper.requestSatelliteSubscriberProvisionStatus(mExecutor, receiver); 446 } catch (SecurityException | IllegalArgumentException ex) { 447 String errorMessage = "requestSatelliteSubscriberProvisionStatus: " + ex.getMessage(); 448 logd(errorMessage); 449 addLogMessage(errorMessage); 450 } 451 } 452 provisionSatellite(View view)453 private void provisionSatellite(View view) { 454 addLogMessage("provisionSatellite"); 455 logd("provisionSatellite"); 456 457 if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { 458 addLogMessage("provisionSatellite: Subscription ID is invalid"); 459 logd("provisionSatellite: Subscription ID is invalid"); 460 return; 461 } 462 463 OutcomeReceiver<Boolean, 464 SatelliteManagerWrapper.SatelliteExceptionWrapper> receiver = 465 new OutcomeReceiver<>() { 466 @Override 467 public void onResult(Boolean result) { 468 logd("provisionSatellite: onResult=" + result); 469 addLogMessage("provisionSatellite: onResult=" + result); 470 } 471 472 @Override 473 public void onError( 474 SatelliteManagerWrapper.SatelliteExceptionWrapper exception) { 475 if (exception != null) { 476 String onError = "provisionSatellite exception: " 477 + translateResultCodeToString(exception.getErrorCode()); 478 logd(onError); 479 addLogMessage(onError); 480 } 481 } 482 }; 483 484 List<SatelliteSubscriberInfoWrapper> list = new ArrayList<>(); 485 for (SatelliteSubscriberProvisionStatusWrapper status : 486 mSatelliteSubscriberProvisionStatuses) { 487 list.add(status.getSatelliteSubscriberInfo()); 488 } 489 try { 490 mSatelliteManagerWrapper.provisionSatellite(list, mExecutor, receiver); 491 } catch (SecurityException | IllegalArgumentException ex) { 492 String errorMessage = "provisionSatellite: " + ex.getMessage(); 493 logd(errorMessage); 494 addLogMessage(errorMessage); 495 } 496 } 497 deprovisionSatellite(View view)498 private void deprovisionSatellite(View view) { 499 addLogMessage("deprovisionSatellite"); 500 logd("deprovisionSatellite"); 501 502 if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { 503 addLogMessage("deprovisionSatellite: Subscription ID is invalid"); 504 logd("deprovisionSatellite: Subscription ID is invalid"); 505 return; 506 } 507 508 OutcomeReceiver<Boolean, 509 SatelliteManagerWrapper.SatelliteExceptionWrapper> receiver = 510 new OutcomeReceiver<>() { 511 @Override 512 public void onResult(Boolean result) { 513 logd("deprovisionSatellite: onResult=" + result); 514 addLogMessage("deprovisionSatellite: onResult=" + result); 515 } 516 517 @Override 518 public void onError( 519 SatelliteManagerWrapper.SatelliteExceptionWrapper exception) { 520 if (exception != null) { 521 String onError = "deprovisionSatellite exception: " 522 + translateResultCodeToString(exception.getErrorCode()); 523 logd(onError); 524 addLogMessage(onError); 525 } 526 } 527 }; 528 529 List<SatelliteSubscriberInfoWrapper> list = new ArrayList<>(); 530 for (SatelliteSubscriberProvisionStatusWrapper status : 531 mSatelliteSubscriberProvisionStatuses) { 532 list.add(status.getSatelliteSubscriberInfo()); 533 } 534 try { 535 mSatelliteManagerWrapper.deprovisionSatellite(list, mExecutor, receiver); 536 } catch (SecurityException | IllegalArgumentException ex) { 537 String errorMessage = "deprovisionSatellite: " + ex.getMessage(); 538 logd(errorMessage); 539 addLogMessage(errorMessage); 540 } 541 } 542 543 public class NtnSignalStrengthCallback implements NtnSignalStrengthCallbackWrapper { 544 @Override onNtnSignalStrengthChanged( @onNull NtnSignalStrengthWrapper ntnSignalStrength)545 public void onNtnSignalStrengthChanged( 546 @NonNull NtnSignalStrengthWrapper ntnSignalStrength) { 547 String message = "Received NTN SignalStrength : " + ntnSignalStrength.getLevel(); 548 logd(message); 549 addLogMessage(message); 550 } 551 } 552 553 private class CarrierRoamingNtnModeListener implements CarrierRoamingNtnModeListenerWrapper2 { 554 555 @Override onCarrierRoamingNtnModeChanged(boolean active)556 public void onCarrierRoamingNtnModeChanged(boolean active) { 557 String message = "Received onCarrierRoamingNtnModeChanged active: " + active; 558 logd(message); 559 addLogMessage(message); 560 } 561 562 @Override onCarrierRoamingNtnEligibleStateChanged(boolean eligible)563 public void onCarrierRoamingNtnEligibleStateChanged(boolean eligible) { 564 String message = "Received onCarrierRoamingNtnEligibleStateChanged " 565 + "eligible: " + eligible; 566 logd(message); 567 addLogMessage(message); 568 } 569 } 570 571 private class SatelliteCommunicationAllowedStateCallback implements 572 SatelliteCommunicationAllowedStateCallbackWrapper { 573 574 @Override onSatelliteCommunicationAllowedStateChanged(boolean isAllowed)575 public void onSatelliteCommunicationAllowedStateChanged(boolean isAllowed) { 576 String message = 577 "Received onSatelliteCommunicationAllowedStateChanged isAllowed: " + isAllowed; 578 logd(message); 579 addLogMessage(message); 580 } 581 } 582 583 private class SatelliteModemStateCallback implements SatelliteModemStateCallbackWrapper2 { 584 @Override onSatelliteModemStateChanged(int state)585 public void onSatelliteModemStateChanged(int state) { 586 String message = "Received onSatelliteModemStateChanged state: " + state; 587 logd(message); 588 addLogMessage(message); 589 } 590 591 @Override onEmergencyModeChanged(boolean isEmergency)592 public void onEmergencyModeChanged(boolean isEmergency) { 593 String message = "Received onEmergencyModeChanged isEmergency: " + isEmergency; 594 logd(message); 595 addLogMessage(message); 596 } 597 } 598 isNonTerrestrialNetwork(View view)599 private void isNonTerrestrialNetwork(View view) { 600 boolean isNonTerrestrialNetwork = mSatelliteManagerWrapper.isNonTerrestrialNetwork(mSubId); 601 addLogMessage("isNonTerrestrialNetwork=" + isNonTerrestrialNetwork); 602 logd("isNonTerrestrialNetwork=" + isNonTerrestrialNetwork); 603 } 604 getAvailableServices(View view)605 private void getAvailableServices(View view) { 606 List<Integer> as = mSatelliteManagerWrapper.getAvailableServices(mSubId); 607 String availableServices = as.stream().map(Object::toString).collect( 608 Collectors.joining(", ")); 609 addLogMessage("getAvailableServices=" + availableServices); 610 logd("getAvailableServices=" + availableServices); 611 } 612 isUsingNonTerrestrialNetwork(View view)613 private void isUsingNonTerrestrialNetwork(View view) { 614 boolean isUsingNonTerrestrialNetwork = 615 mSatelliteManagerWrapper.isUsingNonTerrestrialNetwork(mSubId); 616 addLogMessage("isUsingNonTerrestrialNetwork=" + isUsingNonTerrestrialNetwork); 617 logd("isUsingNonTerrestrialNetwork=" + isUsingNonTerrestrialNetwork); 618 } 619 requestAttachEnabledForCarrier_enable(View view)620 private void requestAttachEnabledForCarrier_enable(View view) { 621 addLogMessage("requestAttachEnabledForCarrier"); 622 logd("requestAttachEnabledForCarrier"); 623 624 if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { 625 addLogMessage("requestAttachEnabledForCarrier: Subscription ID is invalid"); 626 logd("requestAttachEnabledForCarrier: Subscription ID is invalid"); 627 return; 628 } 629 630 Consumer<Integer> callback = result -> { 631 addLogMessage("requestAttachEnabledForCarrier result: " + result); 632 logd("requestAttachEnabledForCarrier result: " + result); 633 }; 634 635 try { 636 mSatelliteManagerWrapper.requestAttachEnabledForCarrier(mSubId, true, mExecutor, 637 callback); 638 } catch (SecurityException | IllegalArgumentException ex) { 639 String errorMessage = "requestAttachEnabledForCarrier: " + ex.getMessage(); 640 logd(errorMessage); 641 addLogMessage(errorMessage); 642 } 643 } 644 requestAttachEnabledForCarrier_disable(View view)645 private void requestAttachEnabledForCarrier_disable(View view) { 646 addLogMessage("requestAttachEnabledForCarrier"); 647 logd("requestAttachEnabledForCarrier"); 648 649 if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { 650 addLogMessage("requestAttachEnabledForCarrier: Subscription ID is invalid"); 651 logd("requestAttachEnabledForCarrier: Subscription ID is invalid"); 652 return; 653 } 654 655 Consumer<Integer> callback = result -> { 656 addLogMessage("requestAttachEnabledForCarrier result: " + result); 657 logd("requestAttachEnabledForCarrier result: " + result); 658 }; 659 660 try { 661 mSatelliteManagerWrapper.requestAttachEnabledForCarrier(mSubId, false, mExecutor, 662 callback); 663 } catch (SecurityException | IllegalArgumentException ex) { 664 String errorMessage = "requestAttachEnabledForCarrier: " + ex.getMessage(); 665 logd(errorMessage); 666 addLogMessage(errorMessage); 667 } 668 } 669 requestIsAttachEnabledForCarrier(View view)670 private void requestIsAttachEnabledForCarrier(View view) { 671 logd("requestIsAttachEnabledForCarrier"); 672 addLogMessage("requestIsAttachEnabledForCarrier"); 673 674 if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { 675 addLogMessage("requestIsAttachEnabledForCarrier: Subscription ID is invalid"); 676 logd("requestIsAttachEnabledForCarrier: Subscription ID is invalid"); 677 return; 678 } 679 680 OutcomeReceiver<Boolean, 681 SatelliteManagerWrapper.SatelliteExceptionWrapper> receiver = 682 new OutcomeReceiver<>() { 683 @Override 684 public void onResult(Boolean result) { 685 logd("requestIsAttachEnabledForCarrier: onResult=" + result); 686 addLogMessage("requestIsAttachEnabledForCarrier: onResult=" + result); 687 } 688 689 @Override 690 public void onError( 691 SatelliteManagerWrapper.SatelliteExceptionWrapper exception) { 692 if (exception != null) { 693 String onError = "requestIsAttachEnabledForCarrier exception: " 694 + translateResultCodeToString(exception.getErrorCode()); 695 logd(onError); 696 addLogMessage(onError); 697 } 698 } 699 }; 700 701 try { 702 mSatelliteManagerWrapper.requestIsAttachEnabledForCarrier(mSubId, mExecutor, receiver); 703 } catch (SecurityException | IllegalStateException | IllegalArgumentException ex) { 704 String errorMessage = "requestIsAttachEnabledForCarrier: " + ex.getMessage(); 705 logd(errorMessage); 706 addLogMessage(errorMessage); 707 } 708 } 709 requestSatelliteAccessConfigurationForCurrentLocation(View view)710 private void requestSatelliteAccessConfigurationForCurrentLocation(View view) { 711 addLogMessage("requestSatelliteAccessConfigurationForCurrentLocation"); 712 logd("requestSatelliteAccessConfigurationForCurrentLocation"); 713 OutcomeReceiver<SatelliteAccessConfigurationWrapper, 714 SatelliteManagerWrapper.SatelliteExceptionWrapper> receiver = 715 new OutcomeReceiver<>() { 716 @Override 717 public void onResult(SatelliteAccessConfigurationWrapper result) { 718 if (result != null) { 719 addLogMessage("requestSatelliteAccessConfigurationForCurrentLocation: " 720 + result.getSatelliteInfos()); 721 } else { 722 addLogMessage("requestSatelliteAccessConfigurationForCurrentLocation: " 723 + "null"); 724 } 725 } 726 727 @Override 728 public void onError( 729 SatelliteManagerWrapper.SatelliteExceptionWrapper exception) { 730 if (exception != null) { 731 String onError = "requestSatelliteAccessConfigurationForCurrentLocation" 732 + " exception: " 733 + translateResultCodeToString(exception.getErrorCode()); 734 logd(onError); 735 addLogMessage(onError); 736 } 737 } 738 }; 739 740 try { 741 mSatelliteManagerWrapper 742 .requestSatelliteAccessConfigurationForCurrentLocation(mExecutor, receiver); 743 } catch (SecurityException ex) { 744 String errorMessage = "requestSatelliteAccessConfigurationForCurrentLocation: " 745 + ex.getMessage(); 746 logd(errorMessage); 747 addLogMessage(errorMessage); 748 } 749 } 750 addAttachRestrictionForCarrier(View view)751 private void addAttachRestrictionForCarrier(View view) { 752 addLogMessage("addAttachRestrictionForCarrier"); 753 logd("addAttachRestrictionForCarrier"); 754 755 if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { 756 addLogMessage("addAttachRestrictionForCarrier: Subscription ID is invalid"); 757 logd("addAttachRestrictionForCarrier: Subscription ID is invalid"); 758 return; 759 } 760 761 int reason = SatelliteManagerWrapper.SATELLITE_COMMUNICATION_RESTRICTION_REASON_USER; 762 763 Consumer<Integer> callback = result -> { 764 addLogMessage("addAttachRestrictionForCarrier result: " + result); 765 logd("addAttachRestrictionForCarrier result: " + result); 766 }; 767 768 try { 769 mSatelliteManagerWrapper.addAttachRestrictionForCarrier(mSubId, reason, mExecutor, 770 callback); 771 } catch (SecurityException | IllegalArgumentException ex) { 772 String errorMessage = "addAttachRestrictionForCarrier: " + ex.getMessage(); 773 logd(errorMessage); 774 addLogMessage(errorMessage); 775 } 776 } 777 removeAttachRestrictionForCarrier(View view)778 private void removeAttachRestrictionForCarrier(View view) { 779 addLogMessage("removeAttachRestrictionForCarrier"); 780 logd("removeAttachRestrictionForCarrier"); 781 782 if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { 783 addLogMessage("removeAttachRestrictionForCarrier: Subscription ID is invalid"); 784 logd("removeAttachRestrictionForCarrier: Subscription ID is invalid"); 785 return; 786 } 787 788 int reason = SatelliteManagerWrapper.SATELLITE_COMMUNICATION_RESTRICTION_REASON_USER; 789 790 Consumer<Integer> callback = result -> { 791 addLogMessage("removeAttachRestrictionForCarrier result: " + result); 792 logd("removeAttachRestrictionForCarrier result: " + result); 793 }; 794 795 try { 796 mSatelliteManagerWrapper.removeAttachRestrictionForCarrier(mSubId, reason, mExecutor, 797 callback); 798 } catch (SecurityException | IllegalArgumentException ex) { 799 String errorMessage = "removeAttachRestrictionForCarrier: " + ex.getMessage(); 800 logd(errorMessage); 801 addLogMessage(errorMessage); 802 } 803 } 804 getAttachRestrictionReasonsForCarrier(View view)805 private void getAttachRestrictionReasonsForCarrier(View view) { 806 addLogMessage("getAttachRestrictionReasonsForCarrier"); 807 logd("getAttachRestrictionReasonsForCarrier"); 808 809 if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { 810 addLogMessage("getAttachRestrictionReasonsForCarrier: Subscription ID is invalid"); 811 logd("getAttachRestrictionReasonsForCarrier: Subscription ID is invalid"); 812 return; 813 } 814 815 try { 816 Set<Integer> reasons = mSatelliteManagerWrapper.getAttachRestrictionReasonsForCarrier( 817 mSubId); 818 String stringReasons = reasons.stream().map(Object::toString).collect( 819 Collectors.joining(", ")); 820 logd("getAttachRestrictionReasonsForCarrier=" + stringReasons); 821 addLogMessage("getAttachRestrictionReasonsForCarrier=" + stringReasons); 822 } catch (SecurityException | IllegalArgumentException ex) { 823 String errorMessage = "getAttachRestrictionReasonsForCarrier: " + ex.getMessage(); 824 logd(errorMessage); 825 addLogMessage(errorMessage); 826 } 827 } 828 getSatellitePlmnsForCarrier(View view)829 private void getSatellitePlmnsForCarrier(View view) { 830 addLogMessage("getSatellitePlmnsForCarrier"); 831 logd("getSatellitePlmnsForCarrier"); 832 833 if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { 834 addLogMessage("getSatellitePlmnsForCarrier: Subscription ID is invalid"); 835 logd("getSatellitePlmnsForCarrier: Subscription ID is invalid"); 836 return; 837 } 838 839 try { 840 List<String> reasons = mSatelliteManagerWrapper.getSatellitePlmnsForCarrier( 841 mSubId); 842 String stringReasons = reasons.stream().collect(Collectors.joining(", ")); 843 logd("getSatellitePlmnsForCarrier=" + stringReasons); 844 addLogMessage("getSatellitePlmnsForCarrier=" + stringReasons); 845 } catch (SecurityException | IllegalArgumentException ex) { 846 String errorMessage = "getSatellitePlmnsForCarrier: " + ex.getMessage(); 847 logd(errorMessage); 848 addLogMessage(errorMessage); 849 } 850 } 851 setNtnSmsSupportedTrue(View view)852 private void setNtnSmsSupportedTrue(View view) { 853 setNtnSmsSupported(true); 854 } 855 setNtnSmsSupportedFalse(View view)856 private void setNtnSmsSupportedFalse(View view) { 857 setNtnSmsSupported(false); 858 } 859 setNtnSmsSupported(boolean ntnSmsSupported)860 private void setNtnSmsSupported(boolean ntnSmsSupported) { 861 String msg = "setNtnSmsSupported:" + ntnSmsSupported; 862 addLogMessage(msg); 863 logd(msg); 864 865 try { 866 mSatelliteManagerWrapper.setNtnSmsSupported(ntnSmsSupported); 867 msg = "setNtnSmsSupported=" + ntnSmsSupported + " is successful"; 868 logd(msg); 869 addLogMessage(msg); 870 } catch (SecurityException | IllegalStateException ex) { 871 msg = "setNtnSmsSupported=" + ntnSmsSupported + " failed. " + ex.getMessage(); 872 logd(msg); 873 addLogMessage(msg); 874 } 875 } 876 getActiveSubId()877 private int getActiveSubId() { 878 int subId; 879 List<SubscriptionInfo> subscriptionInfoList = 880 mSubscriptionManager.getActiveSubscriptionInfoList(); 881 882 if (subscriptionInfoList != null && subscriptionInfoList.size() > 0) { 883 subId = subscriptionInfoList.get(0).getSubscriptionId(); 884 } else { 885 subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 886 } 887 logd("getActiveSubId() returns " + subId); 888 return subId; 889 } 890 translateResultCodeToString( @atelliteManagerWrapper.SatelliteResult int result)891 private String translateResultCodeToString( 892 @SatelliteManagerWrapper.SatelliteResult int result) { 893 switch (result) { 894 case SatelliteManagerWrapper.SATELLITE_RESULT_SUCCESS: 895 return "SATELLITE_RESULT_SUCCESS"; 896 case SatelliteManagerWrapper.SATELLITE_RESULT_ERROR: 897 return "SATELLITE_RESULT_ERROR"; 898 case SatelliteManagerWrapper.SATELLITE_RESULT_SERVER_ERROR: 899 return "SATELLITE_RESULT_SERVER_ERROR"; 900 case SatelliteManagerWrapper.SATELLITE_RESULT_SERVICE_ERROR: 901 return "SATELLITE_RESULT_SERVICE_ERROR"; 902 case SatelliteManagerWrapper.SATELLITE_RESULT_MODEM_ERROR: 903 return "SATELLITE_RESULT_MODEM_ERROR"; 904 case SatelliteManagerWrapper.SATELLITE_RESULT_NETWORK_ERROR: 905 return "SATELLITE_RESULT_NETWORK_ERROR"; 906 case SatelliteManagerWrapper.SATELLITE_RESULT_INVALID_TELEPHONY_STATE: 907 return "SATELLITE_RESULT_INVALID_TELEPHONY_STATE"; 908 case SatelliteManagerWrapper.SATELLITE_RESULT_INVALID_MODEM_STATE: 909 return "SATELLITE_RESULT_INVALID_MODEM_STATE"; 910 case SatelliteManagerWrapper.SATELLITE_RESULT_INVALID_ARGUMENTS: 911 return "SATELLITE_RESULT_INVALID_ARGUMENTS"; 912 case SatelliteManagerWrapper.SATELLITE_RESULT_REQUEST_FAILED: 913 return "SATELLITE_RESULT_REQUEST_FAILED"; 914 case SatelliteManagerWrapper.SATELLITE_RESULT_RADIO_NOT_AVAILABLE: 915 return "SATELLITE_RESULT_RADIO_NOT_AVAILABLE"; 916 case SatelliteManagerWrapper.SATELLITE_RESULT_REQUEST_NOT_SUPPORTED: 917 return "SATELLITE_RESULT_REQUEST_NOT_SUPPORTED"; 918 case SatelliteManagerWrapper.SATELLITE_RESULT_NO_RESOURCES: 919 return "SATELLITE_RESULT_NO_RESOURCES"; 920 case SatelliteManagerWrapper.SATELLITE_RESULT_SERVICE_NOT_PROVISIONED: 921 return "SATELLITE_RESULT_SERVICE_NOT_PROVISIONED"; 922 case SatelliteManagerWrapper.SATELLITE_RESULT_SERVICE_PROVISION_IN_PROGRESS: 923 return "SATELLITE_RESULT_SERVICE_PROVISION_IN_PROGRESS"; 924 case SatelliteManagerWrapper.SATELLITE_RESULT_REQUEST_ABORTED: 925 return "SATELLITE_RESULT_REQUEST_ABORTED"; 926 case SatelliteManagerWrapper.SATELLITE_RESULT_ACCESS_BARRED: 927 return "SATELLITE_RESULT_ACCESS_BARRED"; 928 case SatelliteManagerWrapper.SATELLITE_RESULT_NETWORK_TIMEOUT: 929 return "SATELLITE_RESULT_NETWORK_TIMEOUT"; 930 case SatelliteManagerWrapper.SATELLITE_RESULT_NOT_REACHABLE: 931 return "SATELLITE_RESULT_NOT_REACHABLE"; 932 case SatelliteManagerWrapper.SATELLITE_RESULT_NOT_AUTHORIZED: 933 return "SATELLITE_RESULT_NOT_AUTHORIZED"; 934 case SatelliteManagerWrapper.SATELLITE_RESULT_NOT_SUPPORTED: 935 return "SATELLITE_RESULT_NOT_SUPPORTED"; 936 case SatelliteManagerWrapper.SATELLITE_RESULT_REQUEST_IN_PROGRESS: 937 return "SATELLITE_RESULT_REQUEST_IN_PROGRESS"; 938 case SatelliteManagerWrapper.SATELLITE_RESULT_MODEM_BUSY: 939 return "SATELLITE_RESULT_MODEM_BUSY"; 940 case SatelliteManagerWrapper.SATELLITE_RESULT_ILLEGAL_STATE: 941 return "SATELLITE_RESULT_ILLEGAL_STATE"; 942 default: 943 return "INVALID CODE: " + result; 944 } 945 } 946 addLogMessage(String message)947 private void addLogMessage(String message) { 948 runOnUiThread(() -> { 949 mLogMessages.add(message); 950 mAdapter.notifyDataSetChanged(); 951 mLogListView.setSelection(mAdapter.getCount() - 1); 952 }); 953 } 954 logd(String message)955 private static void logd(String message) { 956 if (message != null) { 957 Log.d(TAG, message); 958 } 959 } 960 } 961