summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Aishwarya Mallampati <amallampati@google.com> 2025-03-26 21:20:09 +0000
committer Android Build Coastguard Worker <android-build-coastguard-worker@google.com> 2025-03-30 15:21:57 -0700
commit0f40261c9b435c1eff821aa3084a1b1febfc83c8 (patch)
tree1c8e5e44d3d3b3e293f2a0202bdd11e359378001
parente7fba6d6e8eea20661da6445e478ea1cb9e751df (diff)
Check if ar.result is boolean before calling cast
Bug: 405485612 Test: atest SatelliteControllerTest Flag: EXEMPT bugfix (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:dfc58e7543c8c6842f236c62f6307d46875ab468) Merged-In: I4f07455f1a5842f5d26308db9c596da316524cce Change-Id: I4f07455f1a5842f5d26308db9c596da316524cce
-rw-r--r--src/java/com/android/internal/telephony/satellite/SatelliteController.java10
-rw-r--r--src/java/com/android/internal/telephony/satellite/SatelliteModemInterface.java8
-rw-r--r--tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteControllerTest.java39
3 files changed, 47 insertions, 10 deletions
diff --git a/src/java/com/android/internal/telephony/satellite/SatelliteController.java b/src/java/com/android/internal/telephony/satellite/SatelliteController.java
index e4cf041e23..d311b8a663 100644
--- a/src/java/com/android/internal/telephony/satellite/SatelliteController.java
+++ b/src/java/com/android/internal/telephony/satellite/SatelliteController.java
@@ -1307,7 +1307,8 @@ public class SatelliteController extends Handler {
}
}
- private static final class SatelliteControllerHandlerRequest {
+ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
+ public static final class SatelliteControllerHandlerRequest {
/** The argument to use for the request */
public @NonNull Object argument;
/** The caller needs to specify the phone to be used for the request */
@@ -1315,7 +1316,7 @@ public class SatelliteController extends Handler {
/** The result of the request that is run on the main thread */
public @Nullable Object result;
- SatelliteControllerHandlerRequest(Object argument, Phone phone) {
+ public SatelliteControllerHandlerRequest(Object argument, Phone phone) {
this.argument = argument;
this.phone = phone;
}
@@ -2302,7 +2303,7 @@ public class SatelliteController extends Handler {
int subId = (int) ar.userObj;
int error = SatelliteServiceUtils.getSatelliteError(
ar, "isSatelliteEnabledForCarrier");
- boolean satelliteEnabled = (boolean) ar.result;
+ boolean satelliteEnabled = (Boolean) ar.result;
plogd("EVENT_GET_SATELLITE_ENABLED_FOR_CARRIER_DONE: subId=" + subId
+ " error=" + error + " satelliteEnabled=" + satelliteEnabled);
@@ -6129,7 +6130,8 @@ public class SatelliteController extends Handler {
* @param subId subscription ID
* @return {@code true} if satellite modem is enabled, {@code false} otherwise.
*/
- private boolean isSatelliteEnabledForCarrierAtModem(int subId) {
+ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
+ public boolean isSatelliteEnabledForCarrierAtModem(int subId) {
synchronized (mIsSatelliteEnabledLock) {
return mIsSatelliteAttachEnabledForCarrierArrayPerSub.getOrDefault(subId, false);
}
diff --git a/src/java/com/android/internal/telephony/satellite/SatelliteModemInterface.java b/src/java/com/android/internal/telephony/satellite/SatelliteModemInterface.java
index 2ebd258a1b..9e5d9de20b 100644
--- a/src/java/com/android/internal/telephony/satellite/SatelliteModemInterface.java
+++ b/src/java/com/android/internal/telephony/satellite/SatelliteModemInterface.java
@@ -1160,13 +1160,9 @@ public class SatelliteModemInterface {
}, new IBooleanConsumer.Stub() {
@Override
public void accept(boolean result) {
- // Convert for compatibility with SatelliteResponse
- // TODO: This should just report result instead.
- int[] enabled = new int[] {result ? 1 : 0};
- plogd("requestIsSatelliteEnabledForCarrier: "
- + Arrays.toString(enabled));
+ plogd("requestIsSatelliteEnabledForCarrier: " + result);
Binder.withCleanCallingIdentity(() -> sendMessageWithResult(
- message, enabled,
+ message, result,
SatelliteManager.SATELLITE_RESULT_SUCCESS));
}
});
diff --git a/tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteControllerTest.java b/tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteControllerTest.java
index a519067e78..2120f4682b 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteControllerTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteControllerTest.java
@@ -5693,6 +5693,22 @@ public class SatelliteControllerTest extends TelephonyTest {
61 /* CMD_EVALUATE_CARRIER_ROAMING_NTN_ELIGIBILITY_CHANGE */).sendToTarget();
}
+ private void sendCmdGetSatelliteEnabledForCarrier(Phone phone) {
+ SatelliteController.SatelliteControllerHandlerRequest request =
+ new SatelliteController.SatelliteControllerHandlerRequest(null, phone);
+ Message msg = mSatelliteControllerUT.obtainMessage(
+ 64 /* CMD_GET_SATELLITE_ENABLED_FOR_CARRIER */, request);
+ msg.sendToTarget();
+ }
+
+ private void sendEventGetSatelliteEnabledForCarrierDone(int subId, Boolean result,
+ Throwable exception) {
+ Message msg = mSatelliteControllerUT.obtainMessage(
+ 65 /* EVENT_GET_SATELLITE_ENABLED_FOR_CARRIER_DONE */, subId);
+ msg.obj = new AsyncResult(subId, result, exception);
+ msg.sendToTarget();
+ }
+
private void setRadioPower(boolean on) {
mSimulatedCommands.setRadioPower(on, false, false, null);
}
@@ -7009,4 +7025,27 @@ public class SatelliteControllerTest extends TelephonyTest {
verify(mPhone, times(1)).notifyCarrierRoamingNtnEligibleStateChanged(eq(true));
}
+
+ @Test
+ public void testGetSatelliteEnabledForCarrier() {
+ reset(mPhone);
+ sendCmdGetSatelliteEnabledForCarrier(mPhone);
+ processAllMessages();
+ verify(mPhone, times(1)).isSatelliteEnabledForCarrier(anyInt(), any());
+ reset(mPhone);
+
+ sendEventGetSatelliteEnabledForCarrierDone(mPhone.getSubId(), false,
+ new SatelliteException(SATELLITE_RESULT_ERROR));
+ processAllMessages();
+ assertFalse(mSatelliteControllerUT.isSatelliteEnabledForCarrierAtModem(mPhone.getSubId()));
+
+ sendEventGetSatelliteEnabledForCarrierDone(mPhone.getSubId(), true, null);
+ processAllMessages();
+ assertTrue(mSatelliteControllerUT.isSatelliteEnabledForCarrierAtModem(mPhone.getSubId()));
+
+ sendEventGetSatelliteEnabledForCarrierDone(mPhone.getSubId(), false, null);
+ processAllMessages();
+ assertFalse(mSatelliteControllerUT.isSatelliteEnabledForCarrierAtModem(mPhone.getSubId()));
+ }
+
}