From 3250a7fec4434739403361e0f726e546d33c103b Mon Sep 17 00:00:00 2001 From: Hall Liu Date: Tue, 13 Oct 2020 14:38:57 -0700 Subject: Add CTS for requestModemActivityInfo Test: atest TelephonyManagerTest#testRequestModemActivityInfo Bug: 170427831 Change-Id: I93b7a9fbd718fbd5ad4970b656bee338d3baf362 Merged-In: I93b7a9fbd718fbd5ad4970b656bee338d3baf362 --- .../telephony/cts/TelephonyManagerTest.java | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/tests/telephony/current/src/android/telephony/cts/TelephonyManagerTest.java b/tests/tests/telephony/current/src/android/telephony/cts/TelephonyManagerTest.java index 7ec5f67edcb..b95ccb018bf 100644 --- a/tests/tests/telephony/current/src/android/telephony/cts/TelephonyManagerTest.java +++ b/tests/tests/telephony/current/src/android/telephony/cts/TelephonyManagerTest.java @@ -68,6 +68,7 @@ import android.telephony.CellIdentityNr; import android.telephony.CellInfo; import android.telephony.CellLocation; import android.telephony.DataThrottlingRequest; +import android.telephony.ModemActivityInfo; import android.telephony.NetworkRegistrationInfo; import android.telephony.PhoneCapability; import android.telephony.PhoneStateListener; @@ -114,6 +115,7 @@ import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; import java.util.concurrent.LinkedBlockingQueue; @@ -3000,6 +3002,40 @@ public class TelephonyManagerTest { } } + @Test + public void testRequestModemActivityInfo() throws Exception { + if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { + return; + } + + InstrumentationRegistry.getInstrumentation().getUiAutomation() + .adoptShellPermissionIdentity("android.permission.MODIFY_PHONE_STATE"); + try { + // Get one instance of activity info and make sure it's valid + CompletableFuture future1 = new CompletableFuture<>(); + mTelephonyManager.requestModemActivityInfo(getContext().getMainExecutor(), + future1::complete); + ModemActivityInfo activityInfo1 = future1.get(TOLERANCE, TimeUnit.MILLISECONDS); + assertNotNull(activityInfo1); + assertTrue("first activity info is" + activityInfo1, activityInfo1.isValid()); + + // Wait a bit, then get another instance to make sure that some info has accumulated + CompletableFuture future2 = new CompletableFuture<>(); + mTelephonyManager.requestModemActivityInfo(getContext().getMainExecutor(), + future2::complete); + ModemActivityInfo activityInfo2 = future2.get(TOLERANCE, TimeUnit.MILLISECONDS); + assertNotNull(activityInfo2); + assertTrue("second activity info is" + activityInfo2, activityInfo2.isValid()); + + ModemActivityInfo diff = activityInfo1.getDelta(activityInfo2); + assertNotNull(diff); + assertTrue("diff is" + diff, diff.isValid() || diff.isEmpty()); + } finally { + InstrumentationRegistry.getInstrumentation().getUiAutomation() + .dropShellPermissionIdentity(); + } + } + @Test public void testGetSupportedModemCount() { if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { -- cgit v1.2.3