Loading tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java +22 −0 Original line number Diff line number Diff line Loading @@ -1052,6 +1052,28 @@ public abstract class TelephonyTest { Log.d(TAG, s); } protected void unmockActivityManager() throws Exception { // Normally, these two should suffice. But we're having some flakiness due to restored // instances being mocks... restoreInstance(Singleton.class, "mInstance", mIActivityManagerSingleton); restoreInstance(ActivityManager.class, "IActivityManagerSingleton", null); // Copy-paste from android.app.ActivityManager.IActivityManagerSingleton Singleton<IActivityManager> amSingleton = new Singleton<IActivityManager>() { @Override protected IActivityManager create() { final IBinder b = ServiceManager.getService(Context.ACTIVITY_SERVICE); final IActivityManager am = IActivityManager.Stub.asInterface(b); return am; } }; // ...so we're setting correct values explicitly, to be sure and not let the flake propagate // to other tests. replaceInstance(Singleton.class, "mInstance", mIActivityManagerSingleton, null); replaceInstance(ActivityManager.class, "IActivityManagerSingleton", null, amSingleton); } public static class FakeBlockedNumberContentProvider extends MockContentProvider { public Set<String> mBlockedNumbers = new HashSet<>(); public int mNumEmergencyContactNotifications = 0; Loading tests/telephonytests/src/com/android/internal/telephony/gsm/GsmSmsDispatcherTest.java +5 −7 Original line number Diff line number Diff line Loading @@ -36,7 +36,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.app.Activity; import android.app.ActivityManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.ComponentName; Loading @@ -46,7 +45,6 @@ import android.content.IntentFilter; import android.content.pm.ServiceInfo; import android.location.Country; import android.location.CountryDetector; import android.net.Uri; import android.os.Binder; import android.os.HandlerThread; import android.os.Message; Loading @@ -60,7 +58,6 @@ import android.telephony.ServiceState; import android.telephony.SmsManager; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.util.Singleton; import androidx.test.filters.FlakyTest; import androidx.test.filters.MediumTest; Loading Loading @@ -139,6 +136,11 @@ public class GsmSmsDispatcherTest extends TelephonyTest { @Before public void setUp() throws Exception { super.setUp(getClass().getSimpleName()); // unmock ActivityManager to be able to register receiver, create real PendingIntent and // receive TEST_INTENT unmockActivityManager(); mSmsDispatchersController = mock(SmsDispatchersController.class); mGsmInboundSmsHandler = mock(GsmInboundSmsHandler.class); mCountryDetector = mock(CountryDetector.class); Loading Loading @@ -233,10 +235,6 @@ public class GsmSmsDispatcherTest extends TelephonyTest { } private void registerTestIntentReceiver() throws Exception { // unmock ActivityManager to be able to register receiver, create real PendingIntent and // receive TEST_INTENT restoreInstance(Singleton.class, "mInstance", mIActivityManagerSingleton); restoreInstance(ActivityManager.class, "IActivityManagerSingleton", null); Context realContext = TestApplication.getAppContext(); realContext.registerReceiver(mTestReceiver, new IntentFilter(TEST_INTENT), Context.RECEIVER_EXPORTED); Loading tests/telephonytests/src/com/android/internal/telephony/security/CellularNetworkSecuritySafetySourceTest.java +1 −5 Original line number Diff line number Diff line Loading @@ -31,13 +31,11 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import android.app.ActivityManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.safetycenter.SafetySourceData; import android.safetycenter.SafetySourceIssue; import android.util.Singleton; import com.android.internal.R; import com.android.internal.telephony.TelephonyTest; Loading @@ -61,9 +59,7 @@ public final class CellularNetworkSecuritySafetySourceTest extends TelephonyTest public void setUp() throws Exception { super.setUp(getClass().getSimpleName()); // unmock ActivityManager to be able to register receiver, create real PendingIntents. restoreInstance(Singleton.class, "mInstance", mIActivityManagerSingleton); restoreInstance(ActivityManager.class, "IActivityManagerSingleton", null); unmockActivityManager(); SubscriptionInfoInternal info0 = new SubscriptionInfoInternal.Builder() .setId(0) Loading Loading
tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java +22 −0 Original line number Diff line number Diff line Loading @@ -1052,6 +1052,28 @@ public abstract class TelephonyTest { Log.d(TAG, s); } protected void unmockActivityManager() throws Exception { // Normally, these two should suffice. But we're having some flakiness due to restored // instances being mocks... restoreInstance(Singleton.class, "mInstance", mIActivityManagerSingleton); restoreInstance(ActivityManager.class, "IActivityManagerSingleton", null); // Copy-paste from android.app.ActivityManager.IActivityManagerSingleton Singleton<IActivityManager> amSingleton = new Singleton<IActivityManager>() { @Override protected IActivityManager create() { final IBinder b = ServiceManager.getService(Context.ACTIVITY_SERVICE); final IActivityManager am = IActivityManager.Stub.asInterface(b); return am; } }; // ...so we're setting correct values explicitly, to be sure and not let the flake propagate // to other tests. replaceInstance(Singleton.class, "mInstance", mIActivityManagerSingleton, null); replaceInstance(ActivityManager.class, "IActivityManagerSingleton", null, amSingleton); } public static class FakeBlockedNumberContentProvider extends MockContentProvider { public Set<String> mBlockedNumbers = new HashSet<>(); public int mNumEmergencyContactNotifications = 0; Loading
tests/telephonytests/src/com/android/internal/telephony/gsm/GsmSmsDispatcherTest.java +5 −7 Original line number Diff line number Diff line Loading @@ -36,7 +36,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.app.Activity; import android.app.ActivityManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.ComponentName; Loading @@ -46,7 +45,6 @@ import android.content.IntentFilter; import android.content.pm.ServiceInfo; import android.location.Country; import android.location.CountryDetector; import android.net.Uri; import android.os.Binder; import android.os.HandlerThread; import android.os.Message; Loading @@ -60,7 +58,6 @@ import android.telephony.ServiceState; import android.telephony.SmsManager; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.util.Singleton; import androidx.test.filters.FlakyTest; import androidx.test.filters.MediumTest; Loading Loading @@ -139,6 +136,11 @@ public class GsmSmsDispatcherTest extends TelephonyTest { @Before public void setUp() throws Exception { super.setUp(getClass().getSimpleName()); // unmock ActivityManager to be able to register receiver, create real PendingIntent and // receive TEST_INTENT unmockActivityManager(); mSmsDispatchersController = mock(SmsDispatchersController.class); mGsmInboundSmsHandler = mock(GsmInboundSmsHandler.class); mCountryDetector = mock(CountryDetector.class); Loading Loading @@ -233,10 +235,6 @@ public class GsmSmsDispatcherTest extends TelephonyTest { } private void registerTestIntentReceiver() throws Exception { // unmock ActivityManager to be able to register receiver, create real PendingIntent and // receive TEST_INTENT restoreInstance(Singleton.class, "mInstance", mIActivityManagerSingleton); restoreInstance(ActivityManager.class, "IActivityManagerSingleton", null); Context realContext = TestApplication.getAppContext(); realContext.registerReceiver(mTestReceiver, new IntentFilter(TEST_INTENT), Context.RECEIVER_EXPORTED); Loading
tests/telephonytests/src/com/android/internal/telephony/security/CellularNetworkSecuritySafetySourceTest.java +1 −5 Original line number Diff line number Diff line Loading @@ -31,13 +31,11 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import android.app.ActivityManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.safetycenter.SafetySourceData; import android.safetycenter.SafetySourceIssue; import android.util.Singleton; import com.android.internal.R; import com.android.internal.telephony.TelephonyTest; Loading @@ -61,9 +59,7 @@ public final class CellularNetworkSecuritySafetySourceTest extends TelephonyTest public void setUp() throws Exception { super.setUp(getClass().getSimpleName()); // unmock ActivityManager to be able to register receiver, create real PendingIntents. restoreInstance(Singleton.class, "mInstance", mIActivityManagerSingleton); restoreInstance(ActivityManager.class, "IActivityManagerSingleton", null); unmockActivityManager(); SubscriptionInfoInternal info0 = new SubscriptionInfoInternal.Builder() .setId(0) Loading