Snap for 4927259 from ff0a2d8267 to qt-release
Change-Id: If43562683a47e3b8a0c81d7ca304b640393a866c
This commit is contained in:
@@ -9872,8 +9872,8 @@
|
||||
<!-- UI debug setting: logging level for Android Autofill [CHAR LIMIT=25] -->
|
||||
<string name="autofill_logging_level_title">Logging level</string>
|
||||
|
||||
<!-- Title of developer options to set the maximum number of partitions per session [CHAR LIMIT=60]-->
|
||||
<string name="autofill_max_partitions">Max partitions</string>
|
||||
<!-- Title of developer options to set the maximum number of requests per session [CHAR LIMIT=60]-->
|
||||
<string name="autofill_max_partitions">Max requests per session</string>
|
||||
|
||||
<!-- Title of developer options to set the maximum number of visible datasets in the autofill UX [CHAR LIMIT=60]-->
|
||||
<string name="autofill_max_visible_datasets">Max visible datasets</string>
|
||||
|
||||
@@ -290,8 +290,10 @@ public class SettingsActivity extends SettingsBaseActivity
|
||||
launchSettingFragment(initialFragmentName, isSubSettings, intent);
|
||||
}
|
||||
|
||||
final boolean deviceProvisioned = Utils.isDeviceProvisioned(this);
|
||||
if (mIsShowingDashboard) {
|
||||
findViewById(R.id.search_bar).setVisibility(View.VISIBLE);
|
||||
findViewById(R.id.search_bar).setVisibility(
|
||||
deviceProvisioned ? View.VISIBLE : View.INVISIBLE);
|
||||
findViewById(R.id.action_bar).setVisibility(View.GONE);
|
||||
final Toolbar toolbar = findViewById(R.id.search_action_bar);
|
||||
FeatureFactory.getFactory(this).getSearchFeatureProvider()
|
||||
@@ -310,7 +312,6 @@ public class SettingsActivity extends SettingsBaseActivity
|
||||
|
||||
ActionBar actionBar = getActionBar();
|
||||
if (actionBar != null) {
|
||||
boolean deviceProvisioned = Utils.isDeviceProvisioned(this);
|
||||
actionBar.setDisplayHomeAsUpEnabled(deviceProvisioned);
|
||||
actionBar.setHomeButtonEnabled(deviceProvisioned);
|
||||
actionBar.setDisplayShowTitleEnabled(!mIsShowingDashboard);
|
||||
|
||||
@@ -59,25 +59,6 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater
|
||||
forceUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state,
|
||||
int bluetoothProfile) {
|
||||
if (DBG) {
|
||||
Log.d(TAG, "onProfileConnectionStateChanged() device: " +
|
||||
cachedDevice.getName() + ", state: " + state + ", bluetoothProfile: "
|
||||
+ bluetoothProfile);
|
||||
}
|
||||
if (state == BluetoothProfile.STATE_CONNECTED) {
|
||||
if (isFilterMatched(cachedDevice)) {
|
||||
addPreference(cachedDevice);
|
||||
} else {
|
||||
removePreference(cachedDevice);
|
||||
}
|
||||
} else if (state == BluetoothProfile.STATE_DISCONNECTED) {
|
||||
removePreference(cachedDevice);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
|
||||
final int audioMode = mAudioManager.getMode();
|
||||
|
||||
@@ -162,6 +162,11 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
|
||||
@Override
|
||||
public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state,
|
||||
int bluetoothProfile) {
|
||||
if (DBG) {
|
||||
Log.d(TAG, "onProfileConnectionStateChanged() device: " + cachedDevice.getName()
|
||||
+ ", state: " + state + ", bluetoothProfile: " + bluetoothProfile);
|
||||
}
|
||||
update(cachedDevice);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -59,25 +59,6 @@ public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
|
||||
forceUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state,
|
||||
int bluetoothProfile) {
|
||||
if (DBG) {
|
||||
Log.d(TAG, "onProfileConnectionStateChanged() device: " +
|
||||
cachedDevice.getName() + ", state: " + state + ", bluetoothProfile: "
|
||||
+ bluetoothProfile);
|
||||
}
|
||||
if (state == BluetoothProfile.STATE_CONNECTED) {
|
||||
if (isFilterMatched(cachedDevice)) {
|
||||
addPreference(cachedDevice);
|
||||
} else {
|
||||
removePreference(cachedDevice);
|
||||
}
|
||||
} else if (state == BluetoothProfile.STATE_DISCONNECTED) {
|
||||
removePreference(cachedDevice);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
|
||||
final int audioMode = mAudioManager.getMode();
|
||||
|
||||
@@ -48,16 +48,6 @@ public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater
|
||||
super(fragment, devicePreferenceCallback, localBluetoothManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state,
|
||||
int bluetoothProfile) {
|
||||
if (state == BluetoothProfile.STATE_CONNECTED) {
|
||||
removePreference(cachedDevice);
|
||||
} else if (state == BluetoothProfile.STATE_DISCONNECTED) {
|
||||
addPreference(cachedDevice);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
|
||||
final BluetoothDevice device = cachedDevice.getDevice();
|
||||
|
||||
@@ -20,15 +20,14 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.service.settings.suggestions.Suggestion;
|
||||
import android.util.Pair;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
import com.android.settingslib.suggestions.SuggestionControllerMixinCompat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
/** Interface should be implemented if you have added new suggestions */
|
||||
public interface SuggestionFeatureProvider {
|
||||
|
||||
@@ -42,11 +41,6 @@ public interface SuggestionFeatureProvider {
|
||||
*/
|
||||
ComponentName getSuggestionServiceComponent();
|
||||
|
||||
/**
|
||||
* Returns true if smart suggestion should be used instead of xml based SuggestionParser.
|
||||
*/
|
||||
boolean isSmartSuggestionEnabled(Context context);
|
||||
|
||||
/** Return true if the suggestion has already been completed and does not need to be shown */
|
||||
boolean isSuggestionComplete(Context context, @NonNull ComponentName suggestion);
|
||||
|
||||
@@ -65,9 +59,4 @@ public interface SuggestionFeatureProvider {
|
||||
*/
|
||||
void dismissSuggestion(Context context, SuggestionControllerMixinCompat suggestionMixin,
|
||||
Suggestion suggestion);
|
||||
|
||||
/**
|
||||
* Returns common tagged data for suggestion logging.
|
||||
*/
|
||||
Pair<Integer, Object>[] getLoggingTaggedData(Context context);
|
||||
}
|
||||
|
||||
@@ -22,10 +22,10 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.service.settings.suggestions.Suggestion;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.Settings.NightDisplaySuggestionActivity;
|
||||
import com.android.settings.biometrics.fingerprint.FingerprintEnrollSuggestionActivity;
|
||||
import com.android.settings.biometrics.fingerprint.FingerprintSuggestionActivity;
|
||||
@@ -42,8 +42,6 @@ import com.android.settingslib.suggestions.SuggestionControllerMixinCompat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider {
|
||||
|
||||
private static final String TAG = "SuggestionFeature";
|
||||
@@ -67,11 +65,6 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
||||
"com.android.settings.intelligence.suggestions.SuggestionService");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSmartSuggestionEnabled(Context context) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuggestionComplete(Context context, @NonNull ComponentName component) {
|
||||
final String className = component.getClassName();
|
||||
@@ -126,12 +119,4 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
||||
suggestion.getId());
|
||||
mixin.dismissSuggestion(suggestion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<Integer, Object>[] getLoggingTaggedData(Context context) {
|
||||
final boolean isSmartSuggestionEnabled = isSmartSuggestionEnabled(context);
|
||||
return new Pair[] {Pair.create(
|
||||
MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED,
|
||||
isSmartSuggestionEnabled ? 1 : 0)};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,8 @@ public class AndroidBeam extends InstrumentedFragment
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mNfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
|
||||
if (mNfcAdapter == null)
|
||||
getActivity().finish();
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@@ -90,7 +92,6 @@ public class AndroidBeam extends InstrumentedFragment
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
SettingsActivity activity = (SettingsActivity) getActivity();
|
||||
|
||||
mOldActivityTitle = activity.getActionBar().getTitle();
|
||||
|
||||
@@ -42,7 +42,11 @@ public final class PaymentDefaultDialog extends AlertActivity implements
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mBackend = new PaymentBackend(this);
|
||||
try {
|
||||
mBackend = new PaymentBackend(this);
|
||||
} catch (NullPointerException e) {
|
||||
finish();
|
||||
}
|
||||
Intent intent = getIntent();
|
||||
ComponentName component = intent.getParcelableExtra(
|
||||
CardEmulation.EXTRA_SERVICE_COMPONENT);
|
||||
|
||||
@@ -165,6 +165,11 @@ public class ChooseLockGeneric extends SettingsActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
final Activity activity = getActivity();
|
||||
if (!Utils.isDeviceProvisioned(activity) && !canRunBeforeDeviceProvisioned()) {
|
||||
activity.finish();
|
||||
return;
|
||||
}
|
||||
|
||||
String chooseLockAction = getActivity().getIntent().getAction();
|
||||
mFingerprintManager = Utils.getFingerprintManagerOrNull(getActivity());
|
||||
@@ -249,6 +254,10 @@ public class ChooseLockGeneric extends SettingsActivity {
|
||||
addHeaderView();
|
||||
}
|
||||
|
||||
protected boolean canRunBeforeDeviceProvisioned() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void addHeaderView() {
|
||||
if (mForFingerprint) {
|
||||
setHeaderView(R.layout.choose_lock_generic_fingerprint_header);
|
||||
|
||||
@@ -130,6 +130,11 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
|
||||
return layout.onCreateRecyclerView(inflater, parent, savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canRunBeforeDeviceProvisioned() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/***
|
||||
* Disables preferences that are less secure than required quality and shows only secure
|
||||
* screen lock options here.
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.search.SearchFeatureProvider;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
@@ -53,6 +54,9 @@ public class SearchMenuController implements LifecycleObserver, OnCreateOptionsM
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
if (!Utils.isDeviceProvisioned(mHost.getContext())) {
|
||||
return;
|
||||
}
|
||||
if (menu == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -25,8 +25,11 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings.Global;
|
||||
import android.view.View;
|
||||
import com.android.settings.core.OnActivityResultListener;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
@@ -35,6 +38,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -52,14 +56,37 @@ public class SettingsActivityTest {
|
||||
@Mock
|
||||
private ActivityManager.TaskDescription mTaskDescription;
|
||||
private SettingsActivity mActivity;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mActivity = spy(new SettingsActivity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreate_deviceNotProvisioned_shouldDisableSearch() {
|
||||
Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 0);
|
||||
final Intent intent = new Intent(mContext, Settings.class);
|
||||
final SettingsActivity activity =
|
||||
Robolectric.buildActivity(SettingsActivity.class, intent).create(Bundle.EMPTY).get();
|
||||
|
||||
assertThat(activity.findViewById(R.id.search_bar).getVisibility())
|
||||
.isEqualTo(View.INVISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreate_deviceProvisioned_shouldEnableSearch() {
|
||||
Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 1);
|
||||
final Intent intent = new Intent(mContext, Settings.class);
|
||||
final SettingsActivity activity =
|
||||
Robolectric.buildActivity(SettingsActivity.class, intent).create(Bundle.EMPTY).get();
|
||||
|
||||
assertThat(activity.findViewById(R.id.search_bar).getVisibility()).isEqualTo(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchSettingFragment_nullExtraShowFragment_shouldNotCrash() {
|
||||
when(mActivity.getSupportFragmentManager()).thenReturn(mFragmentManager);
|
||||
|
||||
@@ -68,6 +68,7 @@ public class SavedBluetoothDeviceUpdaterTest {
|
||||
doReturn(mContext).when(mDashboardFragment).getContext();
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
|
||||
when(mLocalManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
|
||||
when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
||||
|
||||
mBluetoothDeviceUpdater = spy(new SavedBluetoothDeviceUpdater(mDashboardFragment,
|
||||
mDevicePreferenceCallback, mLocalManager));
|
||||
@@ -99,6 +100,8 @@ public class SavedBluetoothDeviceUpdaterTest {
|
||||
|
||||
@Test
|
||||
public void onProfileConnectionStateChanged_deviceConnected_removePreference() {
|
||||
when(mBluetoothDevice.isConnected()).thenReturn(true);
|
||||
|
||||
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
|
||||
|
||||
@@ -107,6 +110,8 @@ public class SavedBluetoothDeviceUpdaterTest {
|
||||
|
||||
@Test
|
||||
public void onProfileConnectionStateChanged_deviceDisconnected_addPreference() {
|
||||
when(mBluetoothDevice.isConnected()).thenReturn(false);
|
||||
|
||||
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||
BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.A2DP);
|
||||
|
||||
|
||||
@@ -18,10 +18,8 @@ package com.android.settings.dashboard.suggestions;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -32,10 +30,8 @@ import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.service.settings.suggestions.Suggestion;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
@@ -160,19 +156,4 @@ public class SuggestionFeatureProviderImplTest {
|
||||
|
||||
assertThat(suggestions).hasSize(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSmartSuggestionEnabledTaggedData_disabled() {
|
||||
assertThat(mProvider.getLoggingTaggedData(mContext)).asList().containsExactly(
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSmartSuggestionEnabledTaggedData_enabled() {
|
||||
final SuggestionFeatureProvider provider = spy(mProvider);
|
||||
when(provider.isSmartSuggestionEnabled(any(Context.class))).thenReturn(true);
|
||||
|
||||
assertThat(provider.getLoggingTaggedData(mContext)).asList().containsExactly(
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,19 +18,54 @@ package com.android.settings.password;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
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 android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings.Global;
|
||||
|
||||
import com.android.settings.password.ChooseLockGeneric.ChooseLockGenericFragment;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class ChooseLockGenericTest {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Global.putInt(RuntimeEnvironment.application.getContentResolver(),
|
||||
Global.DEVICE_PROVISIONED, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = SettingsShadowResources.SettingsShadowTheme.class)
|
||||
public void onCreate_deviceNotProvisioned_shouldFinishActivity() {
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
Global.putInt(context.getContentResolver(), Global.DEVICE_PROVISIONED, 0);
|
||||
final FragmentActivity activity = mock(FragmentActivity.class);
|
||||
when(activity.getContentResolver()).thenReturn(context.getContentResolver());
|
||||
when(activity.getTheme()).thenReturn(context.getTheme());
|
||||
|
||||
final ChooseLockGenericFragment fragment = spy(new ChooseLockGenericFragment());
|
||||
when(fragment.getActivity()).thenReturn(activity);
|
||||
when(fragment.getArguments()).thenReturn(Bundle.EMPTY);
|
||||
|
||||
fragment.onCreate(Bundle.EMPTY);
|
||||
verify(activity).finish();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onActivityResult_nullIntentData_shouldNotCrash() {
|
||||
ChooseLockGenericFragment fragment = spy(new ChooseLockGenericFragment());
|
||||
|
||||
@@ -17,11 +17,14 @@
|
||||
package com.android.settings.search.actionbar;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings.Global;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
@@ -35,6 +38,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class SearchMenuControllerTest {
|
||||
@@ -43,12 +47,16 @@ public class SearchMenuControllerTest {
|
||||
private Menu mMenu;
|
||||
private TestPreferenceFragment mPreferenceHost;
|
||||
private ObservableFragment mHost;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mHost = new ObservableFragment();
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mHost = spy(new ObservableFragment());
|
||||
when(mHost.getContext()).thenReturn(mContext);
|
||||
mPreferenceHost = new TestPreferenceFragment();
|
||||
Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 1);
|
||||
|
||||
when(mMenu.add(Menu.NONE, Menu.NONE, 0 /* order */, R.string.search_menu))
|
||||
.thenReturn(mock(MenuItem.class));
|
||||
@@ -81,9 +89,23 @@ public class SearchMenuControllerTest {
|
||||
verifyZeroInteractions(mMenu);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void init_deviceNotProvisioned_shouldNotAddMenu() {
|
||||
Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 0);
|
||||
SearchMenuController.init(mHost);
|
||||
mHost.getSettingsLifecycle().onCreateOptionsMenu(mMenu, null /* inflater */);
|
||||
|
||||
verifyZeroInteractions(mMenu);
|
||||
}
|
||||
|
||||
private static class TestPreferenceFragment extends ObservablePreferenceFragment {
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context getContext() {
|
||||
return RuntimeEnvironment.application;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user