Prepare tests for impending robolectric merge

Many shadow methods will be protected. Call the true android class and
method where possible in tests.

Test: make -j56 RunSettingsLibRoboTests
  && make -j56 RunFrameworksServicesRoboTests

Change-Id: I59af18ac03446317c18fd30b5705e969b49b93d5
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java
index 47e51f3..08a75ab 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java
@@ -22,12 +22,11 @@
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.mockito.ArgumentMatchers.argThat;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
-import static org.robolectric.Shadows.shadowOf;
 
 import android.app.ActivityManager;
 import android.content.ContentResolver;
@@ -54,7 +53,6 @@
 import org.robolectric.annotation.Config;
 import org.robolectric.annotation.Implementation;
 import org.robolectric.annotation.Implements;
-import org.robolectric.shadows.ShadowAudioManager;
 import org.robolectric.shadows.ShadowSettings;
 
 import java.util.HashMap;
@@ -72,7 +70,7 @@
     private static final String PERCENTAGE_50 = "50%";
     private static final String PERCENTAGE_100 = "100%";
 
-    private ShadowAudioManager mShadowAudioManager;
+    private AudioManager mAudioManager;
     private Context mContext;
     @Mock
     private LocationManager mLocationManager;
@@ -85,7 +83,7 @@
         mContext = spy(RuntimeEnvironment.application);
         when(mContext.getSystemService(Context.LOCATION_SERVICE)).thenReturn(mLocationManager);
         ShadowSecure.reset();
-        mShadowAudioManager = shadowOf(mContext.getSystemService(AudioManager.class));
+        mAudioManager = mContext.getSystemService(AudioManager.class);
     }
 
     @Test
@@ -205,28 +203,28 @@
 
     @Test
     public void isAudioModeOngoingCall_modeInCommunication_returnTrue() {
-        mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
+        mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
 
         assertThat(Utils.isAudioModeOngoingCall(mContext)).isTrue();
     }
 
     @Test
     public void isAudioModeOngoingCall_modeInCall_returnTrue() {
-        mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
+        mAudioManager.setMode(AudioManager.MODE_IN_CALL);
 
         assertThat(Utils.isAudioModeOngoingCall(mContext)).isTrue();
     }
 
     @Test
     public void isAudioModeOngoingCall_modeRingtone_returnTrue() {
-        mShadowAudioManager.setMode(AudioManager.MODE_RINGTONE);
+        mAudioManager.setMode(AudioManager.MODE_RINGTONE);
 
         assertThat(Utils.isAudioModeOngoingCall(mContext)).isTrue();
     }
 
     @Test
     public void isAudioModeOngoingCall_modeNormal_returnFalse() {
-        mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+        mAudioManager.setMode(AudioManager.MODE_NORMAL);
 
         assertThat(Utils.isAudioModeOngoingCall(mContext)).isFalse();
     }
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java
index 49520c0..5ceede1 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java
@@ -17,15 +17,14 @@
 
 import static com.google.common.truth.Truth.assertThat;
 
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
-import static org.robolectric.Shadows.shadowOf;
 
 import android.bluetooth.BluetoothDevice;
 import android.bluetooth.BluetoothProfile;
@@ -40,7 +39,6 @@
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RuntimeEnvironment;
-import org.robolectric.shadows.ShadowAudioManager;
 
 @RunWith(SettingsLibRobolectricTestRunner.class)
 public class CachedBluetoothDeviceTest {
@@ -67,7 +65,7 @@
     @Mock
     private BluetoothDevice mSubDevice;
     private CachedBluetoothDevice mCachedDevice;
-    private ShadowAudioManager mShadowAudioManager;
+    private AudioManager mAudioManager;
     private Context mContext;
     private int mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN;
 
@@ -75,7 +73,7 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mContext = RuntimeEnvironment.application;
-        mShadowAudioManager = shadowOf(mContext.getSystemService(AudioManager.class));
+        mAudioManager = mContext.getSystemService(AudioManager.class);
         when(mDevice.getAddress()).thenReturn(DEVICE_ADDRESS);
         when(mHfpProfile.isProfileReady()).thenReturn(true);
         when(mA2dpProfile.isProfileReady()).thenReturn(true);
@@ -212,7 +210,7 @@
         //   2. Audio Manager: In Call
         updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED);
         mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.A2DP);
-        mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
+        mAudioManager.setMode(AudioManager.MODE_IN_CALL);
 
         // Act & Assert:
         //   Get null result without Battery Level.
@@ -228,7 +226,7 @@
         updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED);
         mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.A2DP);
         mBatteryLevel = 10;
-        mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
+        mAudioManager.setMode(AudioManager.MODE_IN_CALL);
 
         // Act & Assert:
         //   Get "10% battery" result with Battery Level 10.
@@ -244,14 +242,13 @@
 
         // Set device as Active for HFP and test connection state summary
         mCachedDevice.onAudioModeChanged();
-        mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
+        mAudioManager.setMode(AudioManager.MODE_IN_CALL);
         mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.HEADSET);
         assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Active");
 
         // Test with battery level
         mBatteryLevel = 10;
-        assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(
-                "Active, 10% battery");
+        assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Active, 10% battery");
 
         // Set HFP profile to be disconnected and test connection state summary
         updateProfileStatus(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED);
@@ -363,7 +360,7 @@
         //   2. Audio Manager: In Call
         updateProfileStatus(mHearingAidProfile, BluetoothProfile.STATE_CONNECTED);
         mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.HEARING_AID);
-        mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
+        mAudioManager.setMode(AudioManager.MODE_IN_CALL);
 
         // Act & Assert:
         //   Get "Active" result without Battery Level.
@@ -378,8 +375,8 @@
         //   3. Audio Manager: In Call
         updateProfileStatus(mHearingAidProfile, BluetoothProfile.STATE_CONNECTED);
         mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.HEARING_AID);
+        mAudioManager.setMode(AudioManager.MODE_IN_CALL);
         mBatteryLevel = 10;
-        mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
 
         // Act & Assert:
         //   Get "Active, 10% battery" result with Battery Level 10.
diff --git a/services/robotests/src/com/android/server/backup/BackupManagerServiceTest.java b/services/robotests/src/com/android/server/backup/BackupManagerServiceTest.java
index 25d1cc7..f7bb68c 100644
--- a/services/robotests/src/com/android/server/backup/BackupManagerServiceTest.java
+++ b/services/robotests/src/com/android/server/backup/BackupManagerServiceTest.java
@@ -42,6 +42,7 @@
 import android.content.Context;
 import android.content.ContextWrapper;
 import android.content.Intent;
+import android.os.Binder;
 import android.os.HandlerThread;
 import android.os.PowerManager;
 import android.os.PowerSaveState;
@@ -139,7 +140,7 @@
      * specifically to prevent overloading the logs in production.
      */
     @Test
-    public void testMoreDebug_isFalse() throws Exception {
+    public void testMoreDebug_isFalse() {
         boolean moreDebug = BackupManagerService.MORE_DEBUG;
 
         assertThat(moreDebug).isFalse();
@@ -943,7 +944,7 @@
         backupManagerService.backupNow();
 
         assertThat(ShadowKeyValueBackupJob.getCallingUid()).isEqualTo(ShadowBinder.LOCAL_UID);
-        assertThat(ShadowBinder.getCallingUid()).isEqualTo(1);
+        assertThat(Binder.getCallingUid()).isEqualTo(1);
     }
 
     /**
@@ -961,7 +962,7 @@
         expectThrows(IllegalArgumentException.class, backupManagerService::backupNow);
         assertThat(ShadowKeyValueBackupJobException.getCallingUid())
                 .isEqualTo(ShadowBinder.LOCAL_UID);
-        assertThat(ShadowBinder.getCallingUid()).isEqualTo(1);
+        assertThat(Binder.getCallingUid()).isEqualTo(1);
     }
 
     private BackupManagerService createBackupManagerServiceForRequestBackup() {
diff --git a/services/robotests/src/com/android/server/backup/testing/BackupManagerServiceTestUtils.java b/services/robotests/src/com/android/server/backup/testing/BackupManagerServiceTestUtils.java
index 603a471..f307730 100644
--- a/services/robotests/src/com/android/server/backup/testing/BackupManagerServiceTestUtils.java
+++ b/services/robotests/src/com/android/server/backup/testing/BackupManagerServiceTestUtils.java
@@ -18,9 +18,7 @@
 
 import static com.android.server.backup.testing.TestUtils.runToEndOfTasks;
 
-import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyBoolean;
-import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -36,18 +34,16 @@
 import android.os.Looper;
 import android.os.PowerManager;
 import android.os.Process;
-import android.util.SparseArray;
+import android.util.Log;
 
 import com.android.server.backup.BackupAgentTimeoutParameters;
 import com.android.server.backup.BackupManagerService;
 import com.android.server.backup.Trampoline;
 import com.android.server.backup.TransportManager;
-import com.android.server.backup.internal.Operation;
 
 import org.mockito.stubbing.Answer;
 import org.robolectric.shadows.ShadowApplication;
 import org.robolectric.shadows.ShadowBinder;
-import org.robolectric.shadows.ShadowLog;
 
 import java.io.File;
 import java.lang.Thread.UncaughtExceptionHandler;
@@ -192,8 +188,7 @@
     public static HandlerThread startSilentBackupThread(String tag) {
         return startBackupThread(
                 (thread, e) ->
-                        ShadowLog.e(
-                                tag, "Uncaught exception in test thread " + thread.getName(), e));
+                        Log.e(tag, "Uncaught exception in test thread " + thread.getName(), e));
     }
 
     private BackupManagerServiceTestUtils() {}
diff --git a/services/robotests/src/com/android/server/backup/testing/TestUtils.java b/services/robotests/src/com/android/server/backup/testing/TestUtils.java
index 2f54513..3fe1f3f 100644
--- a/services/robotests/src/com/android/server/backup/testing/TestUtils.java
+++ b/services/robotests/src/com/android/server/backup/testing/TestUtils.java
@@ -25,12 +25,12 @@
 import android.os.Looper;
 import android.os.Message;
 import android.os.MessageQueue;
+import android.os.SystemClock;
 
 import com.android.server.testing.shadows.ShadowEventLog;
 
 import org.robolectric.shadows.ShadowLog;
 import org.robolectric.shadows.ShadowLooper;
-import org.robolectric.shadows.ShadowSystemClock;
 
 import java.util.Arrays;
 import java.util.concurrent.Callable;
@@ -87,7 +87,7 @@
         // specific time to the looper the time of those messages will be before the looper's time.
         // To fix this we advance SystemClock as well since that is from where the handlers read
         // time.
-        ShadowSystemClock.setCurrentTimeMillis(shadowLooper.getScheduler().getCurrentTime());
+        SystemClock.setCurrentTimeMillis(shadowLooper.getScheduler().getCurrentTime());
     }
 
     /**
diff --git a/services/robotests/src/com/android/server/location/NtpTimeHelperTest.java b/services/robotests/src/com/android/server/location/NtpTimeHelperTest.java
index aac0a34..a8a258f 100644
--- a/services/robotests/src/com/android/server/location/NtpTimeHelperTest.java
+++ b/services/robotests/src/com/android/server/location/NtpTimeHelperTest.java
@@ -5,6 +5,7 @@
 import static org.mockito.Mockito.doReturn;
 
 import android.os.Looper;
+import android.os.SystemClock;
 import android.platform.test.annotations.Presubmit;
 import android.util.NtpTrustedTime;
 
@@ -18,7 +19,6 @@
 import org.robolectric.RobolectricTestRunner;
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.shadows.ShadowLooper;
-import org.robolectric.shadows.ShadowSystemClock;
 
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
@@ -74,7 +74,7 @@
         doReturn(true).when(mMockNtpTrustedTime).forceRefresh();
         doReturn(1L).when(mMockNtpTrustedTime).getCacheAge();
         doReturn(MOCK_NTP_TIME).when(mMockNtpTrustedTime).getCachedNtpTime();
-        ShadowSystemClock.sleep(NtpTimeHelper.RETRY_INTERVAL);
+        SystemClock.sleep(NtpTimeHelper.RETRY_INTERVAL);
 
         waitForTasksToBePostedOnHandlerAndRunThem();
         assertThat(mCountDownLatch.await(2, TimeUnit.SECONDS)).isTrue();