Add a new toggle for Bluetooth while driving.

The toggle is controlled by a platform feature flag.

Bug: 66679618
Test: Robotest
Change-Id: Ibe8e8756a4ab54a83ee03c6cf008193ed107955d
This commit is contained in:
Daniel Nishi
2018-01-02 16:49:52 -08:00
parent 475fa50461
commit cf4a5c7459
6 changed files with 157 additions and 4 deletions

View File

@@ -0,0 +1,83 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
package com.android.settings.connecteddevice;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.provider.Settings;
import android.util.FeatureFlagUtils;
import com.android.settings.TestConfig;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.FeatureFlags;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows =
SettingsShadowSystemProperties.class)
public class BluetoothOnWhileDrivingPreferenceControllerTest {
private BluetoothOnWhileDrivingPreferenceController mController;
private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new BluetoothOnWhileDrivingPreferenceController(mContext);
}
@After
public void teardown() {
SettingsShadowSystemProperties.clear();
}
@Test
public void getAvailabilityStatus_onWhenEnabled() {
FeatureFlagUtils.setEnabled(mContext, FeatureFlags.BLUETOOTH_WHILE_DRIVING, true);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
public void getAvailabilityStatus_offWhenDisabled() {
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.DISABLED_UNSUPPORTED);
}
@Test
public void setChecked_togglesSettingSecure() {
mController.setChecked(true);
assertThat(
Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.BLUETOOTH_ON_WHILE_DRIVING,
0))
.isEqualTo(1);
}
}