Add CTS tests for missing API calls
1) TelephonyManager#resetSettings - Modifies data enabled
and ensures resetSettings resets it to the default.
2) ImsFeature#getSlotIndex - Ensures that an ImsFeature
created during the tests matches the correct test slot index.
Fixes: 154861678
Fixes: 154861678
Test: atest CtsTelephonyTestCases:TelephonyManagerTest CtsTelephonyTestCases:ImsServiceTest
Change-Id: I1c3e48f054df1788efb20af31e9d797c94e96cd6
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 1953833c..686f793 100644
--- a/tests/tests/telephony/current/src/android/telephony/cts/TelephonyManagerTest.java
+++ b/tests/tests/telephony/current/src/android/telephony/cts/TelephonyManagerTest.java
@@ -37,17 +37,22 @@
import android.content.ServiceConnection;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
+import android.database.ContentObserver;
import android.net.ConnectivityManager;
+import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
+import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.PersistableBundle;
import android.os.Process;
import android.os.RemoteException;
+import android.os.UserManager;
+import android.provider.Settings;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
@@ -1210,6 +1215,73 @@
}
@Test
+ public void testResetSettings() throws Exception {
+ if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
+ Log.d(TAG, "skipping test on device without FEATURE_TELEPHONY present");
+ return;
+ }
+
+ UserManager userManager = getContext().getSystemService(UserManager.class);
+
+ boolean canChangeMobileNetworkSettings = userManager != null
+ && !userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS);
+ assertTrue("Primary user must be able to configure mobile networks to pass this test",
+ canChangeMobileNetworkSettings);
+
+ //First check permissions are correct
+ try {
+ mTelephonyManager.resetSettings();
+ fail("TelephonyManager#resetSettings requires the"
+ + " android.Manifest.permission.NETWORK_SETTINGS permission");
+ } catch (SecurityException e) {
+ //expected
+ }
+ // and then do a reset to move data to default.
+ try {
+ ShellIdentityUtils.invokeMethodWithShellPermissionsNoReturn(mTelephonyManager,
+ TelephonyManager::resetSettings, "android.permission.NETWORK_SETTINGS");
+ } catch (SecurityException e) {
+ fail("TelephonyManager#resetSettings requires the"
+ + " android.Manifest.permission.NETWORK_SETTINGS permission");
+ }
+
+ LinkedBlockingQueue<Boolean> queue = new LinkedBlockingQueue<>(2);
+ final ContentObserver mobileDataChangeObserver = new ContentObserver(
+ new Handler(Looper.getMainLooper())) {
+ @Override
+ public void onChange(boolean selfChange) {
+ queue.offer(isDataEnabled());
+ }
+ };
+
+ getContext().getContentResolver().registerContentObserver(
+ getObservableDataEnabledUri(mTestSub), /* notifyForDescendants= */ false,
+ mobileDataChangeObserver);
+ boolean defaultDataSetting = isDataEnabled();
+
+ // set data to not the default!
+ ShellIdentityUtils.invokeMethodWithShellPermissionsNoReturn(mTelephonyManager,
+ tm -> tm.setDataEnabled(!defaultDataSetting));
+ Boolean dataChangedResult = queue.poll(TOLERANCE, TimeUnit.MILLISECONDS);
+ assertNotNull("Data setting was not changed", dataChangedResult);
+ assertEquals("Data enable change didn't work", !defaultDataSetting,
+ dataChangedResult);
+
+ // and then do a reset to move data to default again.
+ try {
+ ShellIdentityUtils.invokeMethodWithShellPermissionsNoReturn(mTelephonyManager,
+ TelephonyManager::resetSettings, "android.permission.NETWORK_SETTINGS");
+ } catch (SecurityException e) {
+ fail("TelephonyManager#resetSettings requires the"
+ + " android.Manifest.permission.NETWORK_SETTINGS permission");
+ }
+ dataChangedResult = queue.poll(TOLERANCE, TimeUnit.MILLISECONDS);
+ assertNotNull("Data setting was not changed", dataChangedResult);
+ assertEquals("resetSettings did not reset default data", defaultDataSetting,
+ dataChangedResult);
+ }
+
+ @Test
public void testGetServiceState() throws InterruptedException {
if (mCm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) == null) {
Log.d(TAG, "Skipping test that requires ConnectivityManager.TYPE_MOBILE");
@@ -2648,6 +2720,19 @@
}
}
+ private boolean isDataEnabled() {
+ return ShellIdentityUtils.invokeMethodWithShellPermissions(mTelephonyManager,
+ TelephonyManager::isDataEnabled);
+ }
+
+ private Uri getObservableDataEnabledUri(int subId) {
+ Uri uri = Settings.Global.getUriFor(Settings.Global.MOBILE_DATA);
+ if (mTelephonyManager.getActiveModemCount() != 1) {
+ uri = Settings.Global.getUriFor(Settings.Global.MOBILE_DATA + subId);
+ }
+ return uri;
+ }
+
/**
* Validate Emergency Number address that only contains the dialable character.
*
diff --git a/tests/tests/telephony/current/src/android/telephony/ims/cts/ImsServiceTest.java b/tests/tests/telephony/current/src/android/telephony/ims/cts/ImsServiceTest.java
index 7c92b15..6899e42 100644
--- a/tests/tests/telephony/current/src/android/telephony/ims/cts/ImsServiceTest.java
+++ b/tests/tests/telephony/current/src/android/telephony/ims/cts/ImsServiceTest.java
@@ -1700,6 +1700,10 @@
TestImsService.LATCH_CREATE_MMTEL));
assertTrue(sServiceConnector.getCarrierService().waitForLatchCountdown(
TestImsService.LATCH_MMTEL_READY));
+ int serviceSlot = sServiceConnector.getCarrierService().getMmTelFeature().getSlotIndex();
+ assertEquals("The slot specified for the test (" + sTestSlot + ") does not match the "
+ + "assigned slot (" + serviceSlot + "+ for the associated MmTelFeature",
+ sTestSlot, serviceSlot);
// Wait until ImsSmsDispatcher connects and calls onReady.
assertTrue(sServiceConnector.getCarrierService().getMmTelFeature().getSmsImplementation()
.waitForOnReadyLatch());
@@ -1729,6 +1733,10 @@
// Make sure the RcsFeature was created in the test service.
assertNotNull("Device ImsService created, but TestDeviceImsService#createRcsFeature was not"
+ "called!", sServiceConnector.getCarrierService().getRcsFeature());
+ int serviceSlot = sServiceConnector.getCarrierService().getRcsFeature().getSlotIndex();
+ assertEquals("The slot specified for the test (" + sTestSlot + ") does not match the "
+ + "assigned slot (" + serviceSlot + "+ for the associated RcsFeature",
+ sTestSlot, serviceSlot);
}
private void triggerFrameworkConnectToCarrierImsService() throws Exception {
@@ -1744,6 +1752,10 @@
.waitForLatchCountdown(TestImsService.LATCH_MMTEL_READY));
assertNotNull("ImsService created, but ImsService#createMmTelFeature was not called!",
sServiceConnector.getCarrierService().getMmTelFeature());
+ int serviceSlot = sServiceConnector.getCarrierService().getMmTelFeature().getSlotIndex();
+ assertEquals("The slot specified for the test (" + sTestSlot + ") does not match the "
+ + "assigned slot (" + serviceSlot + "+ for the associated MmTelFeature",
+ sTestSlot, serviceSlot);
}
// Waiting for ImsRcsManager to become public before implementing RegistrationManager,