Instantiate pref controllers from xml if it's defined.

- If a <preference> tag also defines a controller, we will try to
  instantiate it before displaying the UI. The same logic is shared by
  BaseSearchIndexProvider so it also drives search suppression.

- If user also defines a list of controllers programatically, the
  programatically created ones takes precedence.

Bug: 73668763
Test: WIP
Change-Id: I7aecec270bcd3af261e012ef1f6995d2a523cfa1
This commit is contained in:
Fan Zhang
2018-02-21 15:22:25 -08:00
parent fc520ee38a
commit 917f101899
28 changed files with 496 additions and 267 deletions

View File

@@ -16,15 +16,14 @@
package com.android.settings.system;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.when;
import android.accounts.AccountManager;
import android.content.Context;
import android.os.UserManager;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowSecureSettings;
import com.android.settings.testutils.shadow.ShadowUtils;
@@ -34,7 +33,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
@@ -46,20 +47,20 @@ public class FactoryResetPreferenceControllerTest {
private static final String FACTORY_RESET_KEY = "factory_reset";
@Mock(answer = RETURNS_DEEP_STUBS)
private Context mContext;
@Mock
private UserManager mUserManager;
@Mock
private AccountManager mAccountManager;
private Context mContext;
private FactoryResetPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
when(mContext.getSystemService(Context.ACCOUNT_SERVICE)).thenReturn(mAccountManager);
mContext = RuntimeEnvironment.application;
ShadowApplication.getInstance().setSystemService(Context.USER_SERVICE, mUserManager);
ShadowApplication.getInstance().setSystemService(Context.ACCOUNT_SERVICE, mAccountManager);
mController = new FactoryResetPreferenceController(mContext);
}