Revert "Update some SatelliteManagerTest test cases"
Revert submission 22148859-Cache satellite states
Reason for revert: cause regression b/275274229
Reverted changes: /q/submissionid:22148859-Cache+satellite+states
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:33090b9138aa39f15e8e7f6c30eba9bb2c7e6d89)
Merged-In: Ie9e38e8bb09542796b009e4465babe53ecd206ac
Change-Id: Ie9e38e8bb09542796b009e4465babe53ecd206ac
diff --git a/tests/tests/telephony/current/src/android/telephony/cts/SatelliteManagerTest.java b/tests/tests/telephony/current/src/android/telephony/cts/SatelliteManagerTest.java
index 390e288..2fc5e08 100644
--- a/tests/tests/telephony/current/src/android/telephony/cts/SatelliteManagerTest.java
+++ b/tests/tests/telephony/current/src/android/telephony/cts/SatelliteManagerTest.java
@@ -17,19 +17,16 @@
package android.telephony.cts;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import static org.junit.Assume.assumeNoException;
import static org.junit.Assume.assumeTrue;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
-import android.os.CancellationSignal;
import android.os.OutcomeReceiver;
import android.telephony.TelephonyManager;
import android.telephony.satellite.PointingInfo;
@@ -46,32 +43,21 @@
import com.android.internal.telephony.ILongConsumer;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.time.Duration;
-import java.util.ArrayList;
-import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
public class SatelliteManagerTest {
private static final String TAG = "SatelliteManagerTest";
- private static final String TOKEN = "TEST_TOKEN";
- private static final String REGION = "TEST_REGION";
-
private static final long TIMEOUT = 1000;
private SatelliteManager mSatelliteManager;
- private boolean mIsSatelliteSupported = false;
- private boolean mOriginalIsSatelliteEnabled = false;
- private boolean mOriginalIsSatelliteProvisioned = false;
- private boolean mIsProvisionable = false;
@Before
public void setUp() throws Exception {
@@ -84,45 +70,6 @@
assumeNoException("Skipping tests because Telephony service is null", e);
}
mSatelliteManager = getContext().getSystemService(SatelliteManager.class);
-
- grantSatellitePermission();
- mIsSatelliteSupported = isSatelliteSupported();
- if (mIsSatelliteSupported) {
- mOriginalIsSatelliteProvisioned = isSatelliteProvisioned();
-
- boolean provisioned = mOriginalIsSatelliteProvisioned;
- if (!mOriginalIsSatelliteProvisioned) {
- provisioned = provisionSatellite();
- if (provisioned) mIsProvisionable = true;
- }
-
- mOriginalIsSatelliteEnabled = isSatelliteEnabled();
- if (provisioned && !mOriginalIsSatelliteEnabled) {
- requestSatelliteEnabled(true);
- }
- }
- revokeSatellitePermission();
- }
-
- @After
- public void tearDown() {
- grantSatellitePermission();
- if (mIsSatelliteSupported) {
- // Restore enabled state
- requestSatelliteEnabled(mOriginalIsSatelliteEnabled);
-
- // Restore provision state
- if (mOriginalIsSatelliteProvisioned) {
- if (!isSatelliteProvisioned()) {
- provisionSatellite();
- }
- } else {
- if (isSatelliteProvisioned()) {
- assertTrue(deprovisionSatellite());
- }
- }
- }
- revokeSatellitePermission();
}
@Test
@@ -137,10 +84,10 @@
getContext().getMainExecutor(), error::offer, callback));
grantSatellitePermission();
+ int errorCode;
mSatelliteManager.startSatelliteTransmissionUpdates(
getContext().getMainExecutor(), error::offer, callback);
- Integer errorCode = error.poll(TIMEOUT, TimeUnit.MILLISECONDS);
- assertNotNull(errorCode);
+ errorCode = error.poll(TIMEOUT, TimeUnit.MILLISECONDS);
if (errorCode == SatelliteManager.SATELLITE_ERROR_NONE) {
Log.d(TAG, "Successfully started transmission updates.");
} else {
@@ -149,14 +96,12 @@
getContext().getSystemService(SatelliteManager.class).stopSatelliteTransmissionUpdates(
callback, getContext().getMainExecutor(), error::offer);
errorCode = error.poll(TIMEOUT, TimeUnit.MILLISECONDS);
- assertNotNull(errorCode);
Log.d(TAG, "Stop transmission updates: " + errorCode);
mSatelliteManager.stopSatelliteTransmissionUpdates(
callback, getContext().getMainExecutor(), error::offer);
errorCode = error.poll(TIMEOUT, TimeUnit.MILLISECONDS);
- assertNotNull(errorCode);
- assertEquals(SatelliteManager.SATELLITE_INVALID_ARGUMENTS, (long) errorCode);
+ assertEquals(errorCode, SatelliteManager.SATELLITE_INVALID_ARGUMENTS);
revokeSatellitePermission();
}
@@ -168,53 +113,6 @@
assertThrows(SecurityException.class,
() -> mSatelliteManager.provisionSatelliteService(
"", "", null, getContext().getMainExecutor(), error::offer));
-
- if (!mIsSatelliteSupported) {
- Log.d(TAG, "testProvisionSatelliteService: Satellite is not supported "
- + "on the device.");
- return;
- }
-
- grantSatellitePermission();
-
- SatelliteProvisionStateCallbackTest satelliteProvisionStateCallback =
- new SatelliteProvisionStateCallbackTest();
- long registerError = mSatelliteManager.registerForSatelliteProvisionStateChanged(
- getContext().getMainExecutor(), satelliteProvisionStateCallback);
- assertEquals(SatelliteManager.SATELLITE_ERROR_NONE, registerError);
-
- if (isSatelliteProvisioned()) {
- if (!deprovisionSatellite()) {
- Log.d(TAG, "testProvisionSatelliteService: deprovisionSatellite failed");
- return;
- }
- assertTrue(satelliteProvisionStateCallback.waitUntilResult());
- assertFalse(satelliteProvisionStateCallback.isProvisioned);
- }
-
- CancellationSignal cancellationSignal = new CancellationSignal();
- mSatelliteManager.provisionSatelliteService(
- TOKEN, REGION, cancellationSignal, getContext().getMainExecutor(), error::offer);
- cancellationSignal.cancel();
- Integer errorCode;
- try {
- errorCode = error.poll(TIMEOUT, TimeUnit.MILLISECONDS);
- } catch (InterruptedException ex) {
- fail("testProvisionSatelliteService: Got InterruptedException ex=" + ex);
- return;
- }
- assertNotNull(errorCode);
- Log.d(TAG, "testProvisionSatelliteService: provision result=" + errorCode);
-
- if (mIsProvisionable) {
- assertFalse(isSatelliteProvisioned());
- assertTrue(provisionSatellite());
- assertTrue(isSatelliteProvisioned());
- }
- mSatelliteManager.unregisterForSatelliteProvisionStateChanged(
- satelliteProvisionStateCallback);
-
- revokeSatellitePermission();
}
@Test
@@ -262,7 +160,7 @@
}
@Test
- public void testRequestSatelliteEnabled() throws Exception {
+ public void testRequestSatelliteEnabled() {
LinkedBlockingQueue<Integer> error = new LinkedBlockingQueue<>(1);
// Throws SecurityException as we do not have SATELLITE_COMMUNICATION permission.
@@ -280,13 +178,11 @@
new OutcomeReceiver<>() {
@Override
public void onResult(Boolean result) {
- Log.d(TAG, "onResult: result=" + result);
enabled.set(result);
}
@Override
public void onError(SatelliteManager.SatelliteException exception) {
- Log.d(TAG, "onError: onError=" + exception);
errorCode.set(exception.getErrorCode());
}
};
@@ -320,14 +216,12 @@
receiver);
assertTrue(latch.await(TIMEOUT, TimeUnit.MILLISECONDS));
- Integer error = errorCode.get();
- Boolean isSupported = supported.get();
- if (error == null) {
- assertNotNull(isSupported);
- Log.d(TAG, "testRequestIsSatelliteSupported isSupported=" + isSupported);
+ assertNotNull(errorCode.get());
+ int error = errorCode.get();
+ if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
+ assertNotNull(supported.get());
} else {
- assertNull(isSupported);
- Log.d(TAG, "testRequestIsSatelliteSupported error=" + error);
+ assertNull(supported.get());
}
}
@@ -354,7 +248,7 @@
}
@Test
- public void testSatelliteModemStateChanged() {
+ public void testSatelliteModemStateChanged() throws Exception {
SatelliteStateCallbackTest callback = new SatelliteStateCallbackTest();
// Throws SecurityException as we do not have SATELLITE_COMMUNICATION permission.
@@ -364,103 +258,6 @@
// Throws SecurityException as we do not have SATELLITE_COMMUNICATION permission.
assertThrows(SecurityException.class, ()-> mSatelliteManager
.unregisterForSatelliteModemStateChanged(callback));
-
- if (!mIsSatelliteSupported) {
- Log.d(TAG, "Satellite is not supported on the device");
- return;
- }
-
- grantSatellitePermission();
-
- if (!isSatelliteProvisioned()) {
- Log.d(TAG, "Satellite is not provisioned yet");
- return;
- }
-
- boolean originalEnabledState = isSatelliteEnabled();
- if (originalEnabledState) {
- requestSatelliteEnabled(false);
- assertFalse(isSatelliteEnabled());
- }
-
- long registerResult = mSatelliteManager
- .registerForSatelliteModemStateChanged(getContext().getMainExecutor(), callback);
- assertEquals(SatelliteManager.SATELLITE_ERROR_NONE, registerResult);
- assertTrue(callback.waitUntilResult(1));
- assertEquals(SatelliteManager.SATELLITE_MODEM_STATE_OFF, callback.modemState);
-
- requestSatelliteEnabled(true);
- assertTrue(isSatelliteEnabled());
- assertTrue(callback.waitUntilResult(1));
- assertEquals(SatelliteManager.SATELLITE_MODEM_STATE_IDLE, callback.modemState);
-
- SatelliteStateCallbackTest callback1 = new SatelliteStateCallbackTest();
- registerResult = mSatelliteManager
- .registerForSatelliteModemStateChanged(getContext().getMainExecutor(), callback1);
- assertEquals(SatelliteManager.SATELLITE_ERROR_NONE, registerResult);
- assertTrue(callback1.waitUntilResult(1));
- assertEquals(SatelliteManager.SATELLITE_MODEM_STATE_IDLE, callback1.modemState);
- mSatelliteManager.unregisterForSatelliteModemStateChanged(callback);
-
- LinkedBlockingQueue<Integer> resultListener = new LinkedBlockingQueue<>(1);
- String mText = "This is a test datagram message";
- SatelliteDatagram datagram = new SatelliteDatagram(mText.getBytes());
- callback1.clearModemStates();
- mSatelliteManager.sendSatelliteDatagram(
- SatelliteManager.DATAGRAM_TYPE_SOS_MESSAGE, datagram, true,
- getContext().getMainExecutor(), resultListener::offer);
-
- Integer errorCode;
- try {
- errorCode = resultListener.poll(TIMEOUT, TimeUnit.MILLISECONDS);
- } catch (InterruptedException ex) {
- fail("testSatelliteModemStateChanged: Got InterruptedException in waiting"
- + " for the sendSatelliteDatagram result code");
- return;
- }
- assertNotNull(errorCode);
- Log.d(TAG, "testSatelliteModemStateChanged: sendSatelliteDatagram errorCode="
- + errorCode);
-
- assertFalse(callback.waitUntilResult(1));
- assertTrue(callback1.waitUntilResult(2));
- assertTrue(callback1.getTotalCountOfModemStates() >= 2);
- assertEquals(SatelliteManager.SATELLITE_MODEM_STATE_DATAGRAM_TRANSFERRING,
- callback1.getModemState(0));
- if (errorCode == SatelliteManager.SATELLITE_ERROR_NONE) {
- /**
- * Modem state should have the following transitions:
- * 1) IDLE to TRANSFERRING.
- * 2) TRANSFERRING to LISTENING.
- * 3) LISTENING to IDLE
- */
- assertEquals(SatelliteManager.SATELLITE_MODEM_STATE_LISTENING,
- callback1.getModemState(1));
- /**
- * Satellite will stay at LISTENING mode for 3 minutes by default. Thus, we will skip
- * checking the last state transition.
- */
- } else {
- /**
- * Modem state should have the following transitions:
- * 1) IDLE to TRANSFERRING.
- * 2) TRANSFERRING to IDLE.
- */
- assertEquals(SatelliteManager.SATELLITE_MODEM_STATE_IDLE,
- callback1.getModemState(1));
- }
-
- if (!originalEnabledState) {
- // Restore original modem enabled state.
- requestSatelliteEnabled(false);
- assertFalse(isSatelliteEnabled());
- assertFalse(callback.waitUntilResult(1));
- assertTrue(callback1.waitUntilResult(1));
- assertEquals(SatelliteManager.SATELLITE_MODEM_STATE_OFF, callback1.modemState);
- }
- mSatelliteManager.unregisterForSatelliteModemStateChanged(callback1);
-
- revokeSatellitePermission();
}
@Test
@@ -582,91 +379,16 @@
private static class SatelliteProvisionStateCallbackTest implements
SatelliteProvisionStateCallback {
- public boolean isProvisioned = false;
- private final Semaphore mSemaphore = new Semaphore(0);
-
@Override
public void onSatelliteProvisionStateChanged(boolean provisioned) {
Log.d(TAG, "onSatelliteProvisionStateChanged: provisioned=" + provisioned);
- isProvisioned = provisioned;
- try {
- mSemaphore.release();
- } catch (Exception ex) {
- Log.d(TAG, "onSatelliteProvisionStateChanged: Got exception, ex=" + ex);
- }
- }
-
- public boolean waitUntilResult() {
- try {
- if (!mSemaphore.tryAcquire(TIMEOUT, TimeUnit.MILLISECONDS)) {
- Log.d(TAG, "Timeout to receive onSatelliteProvisionStateChanged");
- return false;
- }
- return true;
- } catch (Exception ex) {
- Log.d(TAG, "onSatelliteProvisionStateChanged: Got exception=" + ex);
- return false;
- }
}
}
private static class SatelliteStateCallbackTest implements SatelliteStateCallback {
- public int modemState = SatelliteManager.SATELLITE_MODEM_STATE_OFF;
- private List<Integer> mModemStates = new ArrayList<>();
- private final Object mModemStatesLock = new Object();
- private final Semaphore mSemaphore = new Semaphore(0);
-
@Override
public void onSatelliteModemStateChanged(int state) {
Log.d(TAG, "onSatelliteModemStateChanged: state=" + state);
- modemState = state;
- synchronized (mModemStatesLock) {
- mModemStates.add(state);
- }
- try {
- mSemaphore.release();
- } catch (Exception ex) {
- Log.d(TAG, "onSatelliteModemStateChanged: Got exception, ex=" + ex);
- }
- }
-
- public boolean waitUntilResult(int count) {
- for (int i = 0; i < count; i++) {
- try {
- if (!mSemaphore.tryAcquire(TIMEOUT, TimeUnit.MILLISECONDS)) {
- Log.d(TAG, "Timeout to receive onSatelliteModemStateChanged");
- return false;
- }
- } catch (Exception ex) {
- Log.d(TAG, "onSatelliteModemStateChanged: Got exception=" + ex);
- return false;
- }
- }
- return true;
- }
-
- public void clearModemStates() {
- synchronized (mModemStatesLock) {
- mModemStates.clear();
- }
- }
-
- public int getModemState(int index) {
- synchronized (mModemStatesLock) {
- if (index < mModemStates.size()) {
- return mModemStates.get(index);
- } else {
- Log.e(TAG, "getModemState: invalid index=" + index
- + ", mModemStates.size=" + mModemStates.size());
- return -1;
- }
- }
- }
-
- public int getTotalCountOfModemStates() {
- synchronized (mModemStatesLock) {
- return mModemStates.size();
- }
}
}
@@ -678,181 +400,4 @@
+ datagram + ", pendingCount=" + pendingCount);
}
}
-
- private boolean provisionSatellite() {
- LinkedBlockingQueue<Integer> error = new LinkedBlockingQueue<>(1);
-
- mSatelliteManager.provisionSatelliteService(
- TOKEN, REGION, null, getContext().getMainExecutor(), error::offer);
- Integer errorCode;
- try {
- errorCode = error.poll(TIMEOUT, TimeUnit.MILLISECONDS);
- } catch (InterruptedException ex) {
- Log.d(TAG, "provisionSatellite ex=" + ex);
- return false;
- }
- if (errorCode == null || errorCode != SatelliteManager.SATELLITE_ERROR_NONE) {
- Log.d(TAG, "provisionSatellite failed with errorCode=" + errorCode);
- return false;
- }
- return true;
- }
-
- private boolean deprovisionSatellite() {
- LinkedBlockingQueue<Integer> error = new LinkedBlockingQueue<>(1);
-
- mSatelliteManager.deprovisionSatelliteService(
- TOKEN, getContext().getMainExecutor(), error::offer);
- Integer errorCode;
- try {
- errorCode = error.poll(TIMEOUT, TimeUnit.MILLISECONDS);
- } catch (InterruptedException ex) {
- Log.d(TAG, "deprovisionSatellite ex=" + ex);
- return false;
- }
- if (errorCode == null || errorCode != SatelliteManager.SATELLITE_ERROR_NONE) {
- Log.d(TAG, "deprovisionSatellite failed with errorCode=" + errorCode);
- return false;
- }
- return true;
- }
-
- private boolean isSatelliteProvisioned() {
- final AtomicReference<Boolean> provisioned = new AtomicReference<>();
- final AtomicReference<Integer> errorCode = new AtomicReference<>();
- CountDownLatch latch = new CountDownLatch(1);
- OutcomeReceiver<Boolean, SatelliteManager.SatelliteException> receiver =
- new OutcomeReceiver<>() {
- @Override
- public void onResult(Boolean result) {
- provisioned.set(result);
- latch.countDown();
- }
-
- @Override
- public void onError(SatelliteManager.SatelliteException exception) {
- errorCode.set(exception.getErrorCode());
- latch.countDown();
- }
- };
-
- mSatelliteManager.requestIsSatelliteProvisioned(
- getContext().getMainExecutor(), receiver);
- try {
- assertTrue(latch.await(TIMEOUT, TimeUnit.MILLISECONDS));
- } catch (InterruptedException ex) {
- Log.d(TAG, "isSatelliteProvisioned ex=" + ex);
- return false;
- }
-
- Integer error = errorCode.get();
- Boolean isProvisioned = provisioned.get();
- if (error == null) {
- assertNotNull(isProvisioned);
- return isProvisioned;
- } else {
- assertNull(isProvisioned);
- Log.d(TAG, "isSatelliteProvisioned error=" + error);
- return false;
- }
- }
-
- private boolean isSatelliteEnabled() {
- final AtomicReference<Boolean> enabled = new AtomicReference<>();
- final AtomicReference<Integer> errorCode = new AtomicReference<>();
- CountDownLatch latch = new CountDownLatch(1);
- OutcomeReceiver<Boolean, SatelliteManager.SatelliteException> receiver =
- new OutcomeReceiver<>() {
- @Override
- public void onResult(Boolean result) {
- enabled.set(result);
- latch.countDown();
- }
-
- @Override
- public void onError(SatelliteManager.SatelliteException exception) {
- errorCode.set(exception.getErrorCode());
- latch.countDown();
- }
- };
-
-
- mSatelliteManager.requestIsSatelliteEnabled(
- getContext().getMainExecutor(), receiver);
- try {
- assertTrue(latch.await(TIMEOUT, TimeUnit.MILLISECONDS));
- } catch (InterruptedException ex) {
- Log.d(TAG, "isSatelliteEnabled ex=" + ex);
- return false;
- }
-
- Integer error = errorCode.get();
- Boolean isEnabled = enabled.get();
- if (error == null) {
- assertNotNull(isEnabled);
- return isEnabled;
- } else {
- assertNull(isEnabled);
- Log.d(TAG, "isSatelliteEnabled error=" + error);
- return false;
- }
- }
-
- private void requestSatelliteEnabled(boolean enabled) {
- LinkedBlockingQueue<Integer> error = new LinkedBlockingQueue<>(1);
- mSatelliteManager.requestSatelliteEnabled(
- enabled, true, getContext().getMainExecutor(), error::offer);
- Integer errorCode;
- try {
- errorCode = error.poll(TIMEOUT, TimeUnit.MILLISECONDS);
- } catch (InterruptedException ex) {
- Log.d(TAG, "requestSatelliteEnabled: ex=" + ex);
- fail("requestSatelliteEnabled failed with ex=" + ex);
- return;
- }
- assertNotNull(errorCode);
- Log.d(TAG, "requestSatelliteEnabled: errorCode=" + errorCode);
- assertEquals(SatelliteManager.SATELLITE_ERROR_NONE, (long) errorCode);
- }
-
- private boolean isSatelliteSupported() {
- final AtomicReference<Boolean> supported = new AtomicReference<>();
- final AtomicReference<Integer> errorCode = new AtomicReference<>();
- CountDownLatch latch = new CountDownLatch(1);
- OutcomeReceiver<Boolean, SatelliteManager.SatelliteException> receiver =
- new OutcomeReceiver<>() {
- @Override
- public void onResult(Boolean result) {
- supported.set(result);
- latch.countDown();
- }
-
- @Override
- public void onError(SatelliteManager.SatelliteException exception) {
- errorCode.set(exception.getErrorCode());
- latch.countDown();
- }
- };
-
- mSatelliteManager.requestIsSatelliteSupported(getContext().getMainExecutor(),
- receiver);
- try {
- assertTrue(latch.await(TIMEOUT, TimeUnit.MILLISECONDS));
- } catch (InterruptedException ex) {
- Log.d(TAG, "isSatelliteSupported ex=" + ex);
- return false;
- }
-
- Integer error = errorCode.get();
- Boolean isSupported = supported.get();
- if (error == null) {
- assertNotNull(isSupported);
- Log.d(TAG, "isSatelliteSupported isSupported=" + isSupported);
- return isSupported;
- } else {
- assertNull(isSupported);
- Log.d(TAG, "isSatelliteSupported error=" + error);
- return false;
- }
- }
}