Merge "Ignore failing tests in PreviouslyConnectedDevicePreferenceControllerTest" into main
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
index 5317ce0..39c381e 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
@@ -43,6 +43,7 @@
 import static org.mockito.Mockito.verifyNoInteractions;
 import static org.mockito.Mockito.when;
 
+import android.app.Application;
 import android.app.PendingIntent;
 import android.content.Context;
 import android.content.Intent;
@@ -62,6 +63,7 @@
 import androidx.fragment.app.FragmentActivity;
 import androidx.preference.Preference;
 import androidx.preference.SwitchPreference;
+import androidx.test.core.app.ApplicationProvider;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
@@ -83,16 +85,16 @@
 import com.android.settingslib.drawer.TileUtils;
 
 import org.junit.Before;
-import org.junit.Ignore;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Answers;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
 import org.robolectric.Robolectric;
 import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
 import org.robolectric.Shadows;
 import org.robolectric.annotation.Config;
 import org.robolectric.shadows.ShadowActivity;
@@ -104,10 +106,14 @@
 @RunWith(RobolectricTestRunner.class)
 @Config(shadows = ShadowUserManager.class)
 public class DashboardFeatureProviderImplTest {
+    @Rule
+    public final MockitoRule mMockitoRule = MockitoJUnit.rule();
 
     private static final String KEY = "key";
     private static final String SWITCH_URI = "content://com.android.settings/tile_switch";
 
+    private final Application mApplication = ApplicationProvider.getApplicationContext();
+
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private FragmentActivity mActivity;
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -126,9 +132,8 @@
 
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-        mContext = spy(RuntimeEnvironment.application);
-        doReturn(RuntimeEnvironment.application).when(mActivity).getApplicationContext();
+        mContext = spy(mApplication);
+        doReturn(mApplication).when(mActivity).getApplicationContext();
         mForceRoundedIcon = false;
         mActivityInfo = new ActivityInfo();
         mActivityInfo.packageName = mContext.getPackageName();
@@ -163,7 +168,7 @@
 
     @Test
     public void bindPreference_shouldBindAllData() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(mApplication);
         final Tile tile = spy(new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE));
         mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, 10);
         doReturn(Icon.createWithBitmap(Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565)))
@@ -183,7 +188,7 @@
 
     @Test
     public void bindPreference_shouldBindAllSwitchData() {
-        final Preference preference = new SwitchPreference(RuntimeEnvironment.application);
+        final Preference preference = new SwitchPreference(mApplication);
         final Tile tile = spy(new ProviderTile(mProviderInfo, CategoryKey.CATEGORY_HOMEPAGE,
                 mSwitchMetaData));
         mSwitchMetaData.putInt(META_DATA_KEY_ORDER, 10);
@@ -204,7 +209,7 @@
 
     @Test
     public void bindPreference_providerTileWithPendingIntent_shouldBindIntent() {
-        final Preference preference = new SwitchPreference(RuntimeEnvironment.application);
+        final Preference preference = new SwitchPreference(mApplication);
         Bundle metaData = new Bundle();
         metaData.putInt(META_DATA_PREFERENCE_TITLE, R.string.settings_label);
         metaData.putInt(META_DATA_PREFERENCE_SUMMARY, R.string.about_settings_summary);
@@ -212,7 +217,7 @@
         metaData.putString(META_DATA_PREFERENCE_KEYHINT, KEY);
         final Tile tile = new ProviderTile(mProviderInfo, CategoryKey.CATEGORY_HOMEPAGE, metaData);
         PendingIntent pendingIntent =
-                PendingIntent.getActivity(RuntimeEnvironment.application, 0, new Intent("test"), 0);
+                PendingIntent.getActivity(mApplication, 0, new Intent("test"), 0);
         tile.pendingIntentMap.put(UserHandle.CURRENT, pendingIntent);
 
         mImpl.bindPreferenceToTileAndGetObservers(mActivity, mFragment, mForceRoundedIcon,
@@ -225,7 +230,7 @@
 
     @Test
     public void bindPreference_noFragmentMetadata_shouldBindIntent() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(mApplication);
         mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, 10);
         final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
 
@@ -237,10 +242,9 @@
         assertThat(preference.getOrder()).isEqualTo(tile.getOrder());
     }
 
-    @Ignore("b/313569889")
     @Test
     public void bindPreference_noFragmentMetadata_shouldBindToProfileSelector() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(mApplication);
         final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
         tile.userHandle = new ArrayList<>();
         tile.userHandle.add(mock(UserHandle.class));
@@ -255,7 +259,7 @@
 
     @Test
     public void bindPreference_noFragmentMetadataSingleUser_shouldBindToDirectLaunchIntent() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(mApplication);
         final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
         tile.userHandle = new ArrayList<>();
         tile.userHandle.add(mock(UserHandle.class));
@@ -276,8 +280,8 @@
 
     @Test
     public void bindPreference_toInternalSettingActivity_shouldBindToDirectLaunchIntentAndNotLog() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
-        mActivityInfo.packageName = RuntimeEnvironment.application.getPackageName();
+        final Preference preference = new Preference(mApplication);
+        mActivityInfo.packageName = mApplication.getPackageName();
         final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
         tile.userHandle = new ArrayList<>();
         tile.userHandle.add(mock(UserHandle.class));
@@ -303,7 +307,7 @@
 
     @Test
     public void bindPreference_withNullKeyNullPriority_shouldGenerateKeyAndPriority() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(mApplication);
         final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
         mImpl.bindPreferenceToTileAndGetObservers(mActivity, mFragment, mForceRoundedIcon,
                 preference, tile, null /* key */,
@@ -315,7 +319,7 @@
 
     @Test
     public void bindPreference_noSummary_shouldSetNullSummary() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(mApplication);
         mActivityInfo.metaData.remove(META_DATA_PREFERENCE_SUMMARY);
 
         final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
@@ -329,7 +333,7 @@
     @Test
     @Config(shadows = {ShadowTileUtils.class})
     public void bindPreference_hasSummaryUri_shouldLoadSummaryFromContentProviderAndHaveObserver() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(mApplication);
         final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
         final String uriString = "content://com.android.settings/tile_summary";
         mActivityInfo.metaData.putString(TileUtils.META_DATA_PREFERENCE_SUMMARY_URI, uriString);
@@ -349,7 +353,7 @@
     @Test
     @Config(shadows = {ShadowTileUtils.class})
     public void bindPreference_hasTitleUri_shouldLoadFromContentProviderAndHaveObserver() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(mApplication);
         final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
         final String uriString =  "content://com.android.settings/tile_title";
         mActivityInfo.metaData.putString(TileUtils.META_DATA_PREFERENCE_TITLE_URI, uriString);
@@ -369,7 +373,7 @@
     @Test
     @Config(shadows = {ShadowTileUtils.class})
     public void bindPreference_onCheckedChanged_shouldPutStateToContentProvider() {
-        final SwitchPreference preference = new SwitchPreference(RuntimeEnvironment.application);
+        final SwitchPreference preference = new SwitchPreference(mApplication);
         final Tile tile = new ProviderTile(mProviderInfo, CategoryKey.CATEGORY_HOMEPAGE,
                 mSwitchMetaData);
         final Bundle bundle = new Bundle();
@@ -390,7 +394,7 @@
     @Test
     @Config(shadows = {ShadowTileUtils.class})
     public void bindPreference_onCheckedChangedError_shouldRevertCheckedState() {
-        final SwitchPreference preference = new SwitchPreference(RuntimeEnvironment.application);
+        final SwitchPreference preference = new SwitchPreference(mApplication);
         final Tile tile = new ProviderTile(mProviderInfo, CategoryKey.CATEGORY_HOMEPAGE,
                 mSwitchMetaData);
         final Bundle bundle = new Bundle();
@@ -411,7 +415,7 @@
     @Test
     @Config(shadows = {ShadowTileUtils.class})
     public void bindPreference_callbackOnChanged_shouldLoadFromContentProvider() {
-        final SwitchPreference preference = new SwitchPreference(RuntimeEnvironment.application);
+        final SwitchPreference preference = new SwitchPreference(mApplication);
         final Tile tile = new ProviderTile(mProviderInfo, CategoryKey.CATEGORY_HOMEPAGE,
                 mSwitchMetaData);
         final List<DynamicDataObserver> observers = mImpl.bindPreferenceToTileAndGetObservers(
@@ -432,7 +436,7 @@
 
     @Test
     public void bindPreference_withNullKeyTileKey_shouldUseTileKey() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(mApplication);
         mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
         final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
         mImpl.bindPreferenceToTileAndGetObservers(mActivity, mFragment, mForceRoundedIcon,
@@ -443,8 +447,8 @@
 
     @Test
     public void bindIcon_withStaticIcon_shouldLoadStaticIcon() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
-        mActivityInfo.packageName = RuntimeEnvironment.application.getPackageName();
+        final Preference preference = new Preference(mApplication);
+        mActivityInfo.packageName = mApplication.getPackageName();
         final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
         mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
         mActivityInfo.metaData.putInt(META_DATA_PREFERENCE_ICON, R.drawable.ic_add_40dp);
@@ -461,8 +465,8 @@
     @Test
     @Config(shadows = {ShadowTileUtils.class})
     public void bindIcon_withIconUri_shouldLoadIconFromContentProvider() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
-        mActivityInfo.packageName = RuntimeEnvironment.application.getPackageName();
+        final Preference preference = new Preference(mApplication);
+        mActivityInfo.packageName = mApplication.getPackageName();
         final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
         mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
         mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_URI,
@@ -476,8 +480,8 @@
     @Test
     @Config(shadows = {ShadowTileUtils.class})
     public void bindIcon_withStaticIconAndIconUri_shouldLoadIconFromContentProvider() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
-        mActivityInfo.packageName = RuntimeEnvironment.application.getPackageName();
+        final Preference preference = new Preference(mApplication);
+        mActivityInfo.packageName = mApplication.getPackageName();
         final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
         mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
         mActivityInfo.metaData.putInt(META_DATA_PREFERENCE_ICON, R.drawable.ic_add_40dp);
@@ -503,8 +507,8 @@
     @Test
     @Config(shadows = {ShadowTileUtils.class})
     public void bindIcon_noIcon_shouldNotLoadIcon() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
-        mActivityInfo.packageName = RuntimeEnvironment.application.getPackageName();
+        final Preference preference = new Preference(mApplication);
+        mActivityInfo.packageName = mApplication.getPackageName();
         final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
         mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
 
@@ -516,7 +520,7 @@
     @Test
     public void bindPreference_withBaseOrder_shouldOffsetOrder() {
         final int baseOrder = 100;
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(mApplication);
         mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, 10);
         final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
 
@@ -528,7 +532,7 @@
 
     @Test
     public void bindPreference_withOrderMetadata_shouldUseOrderInMetadata() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(mApplication);
         final int testOrder = -30;
         mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, 10);
         final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
@@ -541,7 +545,7 @@
 
     @Test
     public void bindPreference_invalidOrderMetadata_shouldIgnore() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(mApplication);
         final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
         mActivityInfo.metaData.putString(META_DATA_KEY_ORDER, "hello");
 
@@ -554,7 +558,7 @@
     @Test
     public void bindPreference_withIntentActionMetadata_shouldSetLaunchAction() {
         FragmentActivity activity = Robolectric.buildActivity(FragmentActivity.class).get();
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(mApplication);
         final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
         mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
         mActivityInfo.metaData.putString("com.android.settings.intent.action", "TestAction");
@@ -583,7 +587,7 @@
         String clickPrefKey = "highlight_pref_key";
         String highlightMixinPrefKey = "highlight_pref_key";
         FragmentActivity activity = Robolectric.buildActivity(FragmentActivity.class).get();
-        Preference preference = new Preference(RuntimeEnvironment.application);
+        Preference preference = new Preference(mApplication);
         Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
         mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
         mActivityInfo.metaData.putString("com.android.settings.intent.action", "TestAction");
@@ -614,7 +618,7 @@
         String clickPrefKey = "not_highlight_pref_key";
         String highlightMixinPrefKey = "highlight_pref_key";
         FragmentActivity activity = Robolectric.buildActivity(FragmentActivity.class).get();
-        Preference preference = new Preference(RuntimeEnvironment.application);
+        Preference preference = new Preference(mApplication);
         Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
         mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
         mActivityInfo.metaData.putString("com.android.settings.intent.action", "TestAction");
@@ -637,9 +641,9 @@
     @Test
     public void clickPreference_withUnresolvableIntent_shouldNotLaunchAnything() {
         ReflectionHelpers.setField(
-                mImpl, "mPackageManager", RuntimeEnvironment.application.getPackageManager());
+                mImpl, "mPackageManager", mApplication.getPackageManager());
         FragmentActivity activity = Robolectric.buildActivity(FragmentActivity.class).get();
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(mApplication);
         final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
         mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
         mActivityInfo.metaData.putString("com.android.settings.intent.action", "TestAction");
@@ -657,7 +661,7 @@
 
     @Test
     public void clickPreference_providerTileWithPendingIntent_singleUser_executesPendingIntent() {
-        final Preference preference = new SwitchPreference(RuntimeEnvironment.application);
+        final Preference preference = new SwitchPreference(mApplication);
         Bundle metaData = new Bundle();
         metaData.putInt(META_DATA_PREFERENCE_TITLE, R.string.settings_label);
         metaData.putInt(META_DATA_PREFERENCE_SUMMARY, R.string.about_settings_summary);
@@ -665,7 +669,7 @@
         metaData.putString(META_DATA_PREFERENCE_KEYHINT, KEY);
         final Tile tile = new ProviderTile(mProviderInfo, CategoryKey.CATEGORY_HOMEPAGE, metaData);
         PendingIntent pendingIntent =
-                PendingIntent.getActivity(RuntimeEnvironment.application, 0, new Intent("test"), 0);
+                PendingIntent.getActivity(mApplication, 0, new Intent("test"), 0);
         tile.pendingIntentMap.put(UserHandle.CURRENT, pendingIntent);
 
         mImpl.bindPreferenceToTileAndGetObservers(mActivity, mFragment, mForceRoundedIcon,
@@ -673,14 +677,14 @@
         preference.performClick();
 
         Intent nextStartedActivity =
-                Shadows.shadowOf(RuntimeEnvironment.application).peekNextStartedActivity();
+                Shadows.shadowOf((Application) mApplication).peekNextStartedActivity();
         assertThat(nextStartedActivity).isNotNull();
         assertThat(nextStartedActivity.getAction()).isEqualTo("test");
     }
 
     @Test
     public void clickPreference_providerTileWithPendingIntent_multiUser_showsProfileDialog() {
-        final Preference preference = new SwitchPreference(RuntimeEnvironment.application);
+        final Preference preference = new SwitchPreference(mApplication);
         Bundle metaData = new Bundle();
         metaData.putInt(META_DATA_PREFERENCE_TITLE, R.string.settings_label);
         metaData.putInt(META_DATA_PREFERENCE_SUMMARY, R.string.about_settings_summary);
@@ -688,7 +692,7 @@
         metaData.putString(META_DATA_PREFERENCE_KEYHINT, KEY);
         final Tile tile = new ProviderTile(mProviderInfo, CategoryKey.CATEGORY_HOMEPAGE, metaData);
         PendingIntent pendingIntent =
-                PendingIntent.getActivity(RuntimeEnvironment.application, 0, new Intent("test"), 0);
+                PendingIntent.getActivity(mApplication, 0, new Intent("test"), 0);
         tile.pendingIntentMap.put(UserHandle.CURRENT, pendingIntent);
         tile.pendingIntentMap.put(new UserHandle(10), pendingIntent);
 
@@ -700,11 +704,10 @@
                 mActivity.getSupportFragmentManager().findFragmentByTag("select_profile");
         assertThat(dialogFragment).isNotNull();
         Intent nextStartedActivity =
-                Shadows.shadowOf(RuntimeEnvironment.application).peekNextStartedActivity();
+                Shadows.shadowOf((Application) mApplication).peekNextStartedActivity();
         assertThat(nextStartedActivity).isNull();
     }
 
-    @Ignore("b/313569889")
     @Test
     public void openTileIntent_profileSelectionDialog_shouldShow() {
         ShadowUserManager.getShadow().addUser(10, "Someone", 0);
@@ -721,7 +724,6 @@
         verify(mActivity).getSupportFragmentManager();
     }
 
-    @Ignore("b/313569889")
     @Test
     public void openTileIntent_profileSelectionDialog_explicitMetadataShouldShow() {
         ShadowUserManager.getShadow().addUser(10, "Someone", 0);
@@ -739,7 +741,6 @@
         verify(mActivity).getSupportFragmentManager();
     }
 
-    @Ignore("b/313569889")
     @Test
     public void openTileIntent_profileSelectionDialog_shouldNotShow() {
         ShadowUserManager.getShadow().addUser(10, "Someone", 0);
@@ -757,7 +758,6 @@
         verify(mActivity, never()).getSupportFragmentManager();
     }
 
-    @Ignore("b/313569889")
     @Test
     public void openTileIntent_profileSelectionDialog_validUserHandleShouldNotShow() {
         final int userId = 10;
@@ -780,7 +780,6 @@
         verify(mActivity, never()).getSupportFragmentManager();
     }
 
-    @Ignore("b/313569889")
     @Test
     public void openTileIntent_profileSelectionDialog_invalidUserHandleShouldShow() {
         ShadowUserManager.getShadow().addUser(10, "Someone", 0);
@@ -799,7 +798,6 @@
         verify(mActivity).getSupportFragmentManager();
     }
 
-    @Ignore("b/313569889")
     @Test
     public void openTileIntent_profileSelectionDialog_unresolvableWorkProfileIntentShouldNotShow() {
         final int userId = 10;
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
index 449958c..bedfc59 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
@@ -49,7 +49,8 @@
 import androidx.preference.PreferenceFragmentCompat;
 import androidx.preference.PreferenceManager;
 import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
+import androidx.preference.SwitchPreferenceCompat;
+import androidx.test.core.app.ApplicationProvider;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
@@ -66,13 +67,13 @@
 import com.android.settingslib.drawer.Tile;
 
 import org.junit.Before;
-import org.junit.Ignore;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
 import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 import org.robolectric.annotation.Implementation;
 import org.robolectric.annotation.Implements;
@@ -86,6 +87,10 @@
 
 @RunWith(RobolectricTestRunner.class)
 public class DashboardFragmentTest {
+    @Rule
+    public final MockitoRule mMockitoRule = MockitoJUnit.rule();
+
+    private final Context mAppContext = ApplicationProvider.getApplicationContext();
 
     @Mock
     private FakeFeatureFactory mFakeFeatureFactory;
@@ -98,8 +103,7 @@
 
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-        mContext = spy(RuntimeEnvironment.application);
+        mContext = spy(mAppContext);
         final ActivityInfo activityInfo = new ActivityInfo();
         activityInfo.packageName = "pkg";
         activityInfo.name = "class";
@@ -120,11 +124,11 @@
         mProviderTile = new ProviderTile(providerInfo, mDashboardCategory.key, metaData);
         mDashboardCategory.addTile(mProviderTile);
 
-        mTestFragment = new TestFragment(RuntimeEnvironment.application);
+        mTestFragment = new TestFragment(mAppContext);
         when(mFakeFeatureFactory.dashboardFeatureProvider
                 .getTilesForCategory(nullable(String.class)))
                 .thenReturn(mDashboardCategory);
-        mTestFragment.onAttach(RuntimeEnvironment.application);
+        mTestFragment.onAttach(mAppContext);
         when(mContext.getPackageName()).thenReturn("TestPackage");
         mControllers = new ArrayList<>();
     }
@@ -297,7 +301,7 @@
         preferenceControllers.add(mockController2);
         when(mockController1.isAvailable()).thenReturn(false);
         when(mockController2.isAvailable()).thenReturn(true);
-        mTestFragment.onAttach(RuntimeEnvironment.application);
+        mTestFragment.onAttach(mAppContext);
         mTestFragment.onResume();
 
         verify(mockController1).getPreferenceKey();
@@ -387,12 +391,11 @@
         assertThat(mTestFragment.mBlockerController).isNull();
     }
 
-    @Ignore("b/313569889")
     @Test
     public void createPreference_isProviderTile_returnSwitchPreference() {
         final Preference pref = mTestFragment.createPreference(mProviderTile);
 
-        assertThat(pref).isInstanceOf(SwitchPreference.class);
+        assertThat(pref).isInstanceOf(SwitchPreferenceCompat.class);
     }
 
     @Test
@@ -401,7 +404,7 @@
 
         assertThat(pref).isInstanceOf(Preference.class);
         assertThat(pref).isNotInstanceOf(PrimarySwitchPreference.class);
-        assertThat(pref).isNotInstanceOf(SwitchPreference.class);
+        assertThat(pref).isNotInstanceOf(SwitchPreferenceCompat.class);
         assertThat(pref.getWidgetLayoutResource()).isEqualTo(0);
     }
 
@@ -431,7 +434,7 @@
 
         assertThat(pref).isInstanceOf(Preference.class);
         assertThat(pref).isNotInstanceOf(PrimarySwitchPreference.class);
-        assertThat(pref).isNotInstanceOf(SwitchPreference.class);
+        assertThat(pref).isNotInstanceOf(SwitchPreferenceCompat.class);
         assertThat(pref.getWidgetLayoutResource())
                 .isEqualTo(R.layout.preference_external_action_icon);
     }
diff --git a/tests/robotests/src/com/android/settings/location/LocationInjectedServicesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/LocationInjectedServicesPreferenceControllerTest.java
index 8726fc3..43b9839 100644
--- a/tests/robotests/src/com/android/settings/location/LocationInjectedServicesPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationInjectedServicesPreferenceControllerTest.java
@@ -38,20 +38,22 @@
 import androidx.preference.Preference;
 import androidx.preference.PreferenceCategory;
 import androidx.preference.PreferenceScreen;
+import androidx.test.core.app.ApplicationProvider;
 
+import com.android.settings.testutils.shadow.ShadowDevicePolicyManager;
 import com.android.settings.testutils.shadow.ShadowUserManager;
 import com.android.settings.widget.RestrictedAppPreference;
 import com.android.settingslib.core.lifecycle.Lifecycle;
 
 import org.junit.Before;
-import org.junit.Ignore;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Answers;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
 import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 
 import java.util.ArrayList;
@@ -59,8 +61,10 @@
 import java.util.Map;
 
 @RunWith(RobolectricTestRunner.class)
-@Config(shadows = ShadowUserManager.class)
+@Config(shadows = {ShadowUserManager.class, ShadowDevicePolicyManager.class})
 public class LocationInjectedServicesPreferenceControllerTest {
+    @Rule
+    public final MockitoRule mMockitoRule = MockitoJUnit.rule();
 
     private static final String KEY_LOCATION_SERVICES = "location_service";
 
@@ -82,8 +86,7 @@
 
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-        mContext = spy(RuntimeEnvironment.application);
+        mContext = spy(ApplicationProvider.getApplicationContext());
         mLifecycleOwner = () -> mLifecycle;
         mLifecycle = new Lifecycle(mLifecycleOwner);
         mController = spy(
@@ -115,7 +118,6 @@
         verify(mContext).unregisterReceiver(mController.mInjectedSettingsReceiver);
     }
 
-    @Ignore("b/313540388")
     @Test
     public void workProfileDisallowShareLocationOn_getParentUserLocationServicesOnly() {
         final int fakeWorkProfileId = 123;
@@ -168,7 +170,6 @@
         verify(mSettingsInjector).reloadStatusMessages();
     }
 
-    @Ignore("b/313540388")
     @Test
     public void withUserRestriction_shouldDisableLocationAccuracy() {
         final List<Preference> preferences = new ArrayList<>();
diff --git a/tests/robotests/testutils/com/android/settings/testutils/shadow/ShadowUserManager.java b/tests/robotests/testutils/com/android/settings/testutils/shadow/ShadowUserManager.java
index ce6dc6a..23df4ca 100644
--- a/tests/robotests/testutils/com/android/settings/testutils/shadow/ShadowUserManager.java
+++ b/tests/robotests/testutils/com/android/settings/testutils/shadow/ShadowUserManager.java
@@ -21,6 +21,7 @@
 
 import android.annotation.UserIdInt;
 import android.content.pm.UserInfo;
+import android.content.pm.UserProperties;
 import android.os.Bundle;
 import android.os.UserHandle;
 import android.os.UserManager;
@@ -156,6 +157,12 @@
         mDefaultGuestUserRestriction = restrictions;
     }
 
+    @Implementation
+    protected UserProperties getUserProperties(UserHandle userHandle) {
+        return new UserProperties.Builder().build();
+    }
+
+
     public void addGuestUserRestriction(String restriction) {
         mDefaultGuestUserRestriction.putBoolean(restriction, true);
     }