Snap for 5681502 from e342579993 to qt-c2f2-release

Change-Id: I6d8f5225cb8211ae5883f7bf2b9ce17b69dc9051
This commit is contained in:
android-build-team Robot
2019-06-22 23:25:06 +00:00
14 changed files with 124 additions and 720 deletions

View File

@@ -16,10 +16,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="32.0"
android:viewportHeight="32.0"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M4.59 6.89c0.7-0.71 1.4-1.35 1.71-1.22 0.5 0.2 0 1.03-0.3 1.52-0.25 0.42 -2.86 3.89-2.86 6.31 0 1.28 0.48 2.34 1.34 2.98 0.75 0.56 1.74 0.73 2.64 0.46 1.07-0.31 1.95-1.4 3.06-2.77 1.21-1.49 2.83-3.44 4.08-3.44 1.63 0 1.65 1.01 1.76 1.79-3.78 0.64 -5.38 3.67-5.38 5.37 0 1.7 1.44 3.09 3.21 3.09 1.63 0 4.29-1.33 4.69-6.1H21v-2.5h-2.47c-0.15-1.65-1.09-4.2-4.03-4.2-2.25 0-4.18 1.91-4.94 2.84-0.58 0.73 -2.06 2.48-2.29 2.72-0.25 0.3 -0.68 0.84 -1.11 0.84 -0.45 0-0.72-0.83-0.36-1.92 0.35 -1.09 1.4-2.86 1.85-3.52 0.78 -1.14 1.3-1.92 1.3-3.28C8.95 3.69 7.31 3 6.44 3 5.12 3 3.97 4 3.72 4.25c-0.36 0.36 -0.66 0.66 -0.88 0.93 l1.75 1.71zm9.29 11.66c-0.31 0-0.74-0.26-0.74-0.72 0-0.6 0.73 -2.2 2.87-2.76-0.3 2.69-1.43 3.48-2.13 3.48z" />
android:pathData="M17,18L7,18L7,6L17,6L17,7L19,7L19,3C19,1.895 18.105,1 17,1L7,1C5.895,1 5,1.895 5,3L5,21C5,22.105 5.895,23 7,23L17,23C18.105,23 19,22.105 19,21L19,17L17,17L17,18ZM7,3L17,3L17,4L7,4L7,3ZM17,21L7,21L7,20L17,20L17,21ZM17.94,12.06L20,13L17.94,13.94L17,16L16.06,13.94L14,13L16.06,12.06L17,10L17.94,12.06ZM20.63,8.38L22,9L20.63,9.63L20,11L19.38,9.63L18,9L19.38,8.38L20,7L20.63,8.38Z"
android:strokeColor="#00000000"
android:fillType="nonZero"
android:fillColor="#000000"
android:strokeWidth="1"/>
</vector>

View File

@@ -1,57 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2019 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.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/gentle_notifications_title"
android:key="gentle_notification_settings">
<com.android.settingslib.widget.LayoutPreference
android:key="gentle_notifications_drawable"
android:title="@string/summary_placeholder"
android:layout="@layout/drawable_layout"
settings:controller="com.android.settings.notification.GentleDrawablePreferenceController"
android:selectable="false"
android:order="1"
settings:allowDividerBelow="true"
android:persistent="false" />
<Preference
android:key="gentle_notifications_footer"
android:title="@string/gentle_notifications_education"
android:order="2"
android:icon="@drawable/ic_info_outline_24"
style="?attr/footerPreferenceStyle"
settings:allowDividerAbove="true"
android:clickable="false"
android:selectable="false" />
<PreferenceCategory
android:key="gentle_notifications_settings"
android:title="@string/gentle_notifications_also_display"
android:order="3">
<SwitchPreference
android:key="silent_icons"
android:title="@string/gentle_notifications_display_status"
settings:controller="com.android.settings.notification.SilentStatusBarPreferenceController" />
<SwitchPreference
android:key="lock_screen"
android:title="@string/gentle_notifications_display_lock"
settings:controller="com.android.settings.notification.SilentLockscreenPreferenceController" />
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -29,19 +29,14 @@ public class AdaptiveSleepPreferenceController extends TogglePreferenceControlle
private static final String SYSTEM_KEY = ADAPTIVE_SLEEP;
private static final int DEFAULT_VALUE = 0;
private final boolean hasSufficientPermissions;
public AdaptiveSleepPreferenceController(Context context, String key) {
super(context, key);
final PackageManager packageManager = mContext.getPackageManager();
hasSufficientPermissions = hasSufficientPermission(packageManager);
}
@Override
public boolean isChecked() {
return hasSufficientPermissions && Settings.System.getInt(mContext.getContentResolver(),
SYSTEM_KEY, DEFAULT_VALUE) != DEFAULT_VALUE;
return hasSufficientPermission(mContext.getPackageManager()) && Settings.System.getInt(
mContext.getContentResolver(), SYSTEM_KEY, DEFAULT_VALUE) != DEFAULT_VALUE;
}
@Override

View File

@@ -279,7 +279,8 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
// Only search for the required action in the Device Owner's package
final Intent intent =
new Intent(mResources.getString(R.string.config_work_policy_info_intent_action))
.setPackage(ownerComponent.getPackageName());
.setPackage(ownerComponent.getPackageName())
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
final List<ResolveInfo> activities = mPm.queryIntentActivities(intent, 0);
if (activities.size() != 0) {
return intent;
@@ -302,7 +303,8 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
// Only search for the required action in the Profile Owner's package
final Intent intent =
new Intent(mResources.getString(R.string.config_work_policy_info_intent_action))
.setPackage(ownerComponent.getPackageName());
.setPackage(ownerComponent.getPackageName())
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
final List<ResolveInfo> activities = mPm.queryIntentActivitiesAsUser(intent, 0, userId);
if (activities.size() != 0) {
return intent;

View File

@@ -1,81 +0,0 @@
/*
* Copyright (C) 2019 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.notification;
import android.content.Context;
import android.provider.Settings;
import android.widget.ImageView;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.widget.LayoutPreference;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
public class GentleDrawablePreferenceController extends BasePreferenceController {
@VisibleForTesting
static final int ON = 1;
private NotificationBackend mBackend;
public GentleDrawablePreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
mBackend = new NotificationBackend();
}
@VisibleForTesting
void setBackend(NotificationBackend backend) {
mBackend = backend;
}
@Override
public void updateState(Preference preference) {
LayoutPreference pref = (LayoutPreference) preference;
boolean showOnLockscreen = showOnLockscreen();
boolean showOnStatusBar = showOnStatusBar();
ImageView view = pref.findViewById(R.id.drawable);
if (showOnLockscreen) {
if (showOnStatusBar) {
view.setImageResource(R.drawable.gentle_notifications_shade_status_lock);
} else {
view.setImageResource(R.drawable.gentle_notifications_shade_lock);
}
} else if (showOnStatusBar) {
view.setImageResource(R.drawable.gentle_notifications_shade_status);
} else {
view.setImageResource(R.drawable.gentle_notifications_shade);
}
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
private boolean showOnLockscreen() {
return Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, ON) == ON;
}
private boolean showOnStatusBar() {
return !mBackend.shouldHideSilentStatusBarIcons(mContext);
}
}

View File

@@ -1,74 +0,0 @@
/*
* Copyright (C) 2019 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.notification;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.provider.SearchIndexableResource;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
import java.util.Arrays;
import java.util.List;
@SearchIndexable
public class GentleNotificationSettings extends DashboardFragment {
private static final String TAG = "GentleNotiSettings";
@Override
public int getMetricsCategory() {
return SettingsEnums.GENTLE_NOTIFICATIONS_SCREEN;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.gentle_notification_settings;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
use(SilentStatusBarPreferenceController.class).setListener(
shown -> updatePreferenceStates());
use(SilentLockscreenPreferenceController.class).setListener(
shown -> updatePreferenceStates());
}
/**
* For Search.
*/
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.gentle_notification_settings;
return Arrays.asList(sir);
}
};
}

View File

@@ -1,70 +0,0 @@
/*
* Copyright (C) 2019 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.notification;
import static android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL;
import android.content.Context;
import android.os.UserHandle;
import android.provider.Settings;
import com.android.settings.core.TogglePreferenceController;
import com.google.common.annotations.VisibleForTesting;
public class SilentLockscreenPreferenceController extends TogglePreferenceController {
private static final String KEY = "lock_screen";
private Listener mListener;
public SilentLockscreenPreferenceController(Context context) {
super(context, KEY);
}
@Override
public boolean isChecked() {
return Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1) == 1;
}
@Override
public boolean setChecked(boolean isChecked) {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, isChecked ? 1 : 0);
if (mListener != null) {
mListener.onChange(isChecked);
}
return true;
}
@Override
public int getAvailabilityStatus() {
return Settings.Secure.getInt(
mContext.getContentResolver(), NOTIFICATION_NEW_INTERRUPTION_MODEL, 1) != 0
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
public void setListener(Listener listener) {
mListener = listener;
}
interface Listener {
void onChange(boolean shown);
}
}

View File

@@ -1,77 +0,0 @@
/*
* Copyright (C) 2019 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.notification;
import static android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL;
import android.content.Context;
import android.os.UserHandle;
import android.provider.Settings;
import com.android.settings.core.TogglePreferenceController;
import com.google.common.annotations.VisibleForTesting;
public class SilentStatusBarPreferenceController extends TogglePreferenceController {
private static final String KEY = "silent_icons";
private static final int MY_USER_ID = UserHandle.myUserId();
private NotificationBackend mBackend;
private Listener mListener;
public SilentStatusBarPreferenceController(Context context) {
super(context, KEY);
mBackend = new NotificationBackend();
}
@VisibleForTesting
void setBackend(NotificationBackend backend) {
mBackend = backend;
}
@Override
public boolean isChecked() {
return !mBackend.shouldHideSilentStatusBarIcons(mContext);
}
@Override
public boolean setChecked(boolean isChecked) {
mBackend.setHideSilentStatusIcons(!isChecked);
if (mListener != null) {
mListener.onChange(isChecked);
}
return true;
}
@Override
public int getAvailabilityStatus() {
return Settings.Secure.getInt(
mContext.getContentResolver(), NOTIFICATION_NEW_INTERRUPTION_MODEL, 1) != 0
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
public void setListener(Listener listener) {
mListener = listener;
}
interface Listener {
void onChange(boolean shown);
}
}

View File

@@ -30,6 +30,8 @@ import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import androidx.annotation.VisibleForTesting;
public class TtsEnginePreference extends Preference {
@@ -45,6 +47,7 @@ public class TtsEnginePreference extends Preference {
* The shared radio button state, which button is checked etc.
*/
private final RadioButtonGroupState mSharedState;
private RadioButton mRadioButton;
/**
* When true, the change callbacks on the radio button will not
@@ -95,6 +98,12 @@ public class TtsEnginePreference extends Preference {
mPreventRadioButtonCallbacks = true;
rb.setChecked(isChecked);
mPreventRadioButtonCallbacks = false;
mRadioButton = rb;
}
@Override
public void onClick() {
mRadioButton.setChecked(true);
}
private boolean shouldDisplayDataAlert() {

View File

@@ -686,6 +686,10 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
return;
}
if (mCamera.isDecodeTaskAlive()) {
mCamera.stop();
}
final SurfaceTexture surfaceTexture = mTextureView.getSurfaceTexture();
if (surfaceTexture == null) {
throw new IllegalStateException("SurfaceTexture is not ready for restarting camera");

View File

@@ -1,113 +0,0 @@
/*
* Copyright (C) 2019 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.notification;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.provider.Settings;
import android.widget.ImageView;
import com.android.settings.R;
import com.android.settingslib.widget.LayoutPreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import androidx.preference.Preference;
@RunWith(RobolectricTestRunner.class)
public class GentleDrawablePreferenceControllerTest {
private Context mContext;
private GentleDrawablePreferenceController mController;
@Mock
private LayoutPreference mPreference;
@Mock
NotificationBackend mBackend;
@Mock
ImageView mView;
private static final String KEY = "gentle_notifications";
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new GentleDrawablePreferenceController(mContext, KEY);
mController.setBackend(mBackend);
when(mPreference.findViewById(R.id.drawable)).thenReturn(mView);
}
@Test
public void display_shouldDisplay() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void updateState_lock() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1);
when(mBackend.shouldHideSilentStatusBarIcons(mContext)).thenReturn(true);
mController.updateState(mPreference);
verify(mView).setImageResource(R.drawable.gentle_notifications_shade_lock);
}
@Test
public void updateState_status() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0);
when(mBackend.shouldHideSilentStatusBarIcons(mContext)).thenReturn(false);
mController.updateState(mPreference);
verify(mView).setImageResource(R.drawable.gentle_notifications_shade_status);
}
@Test
public void updateState_both() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1);
when(mBackend.shouldHideSilentStatusBarIcons(mContext)).thenReturn(false);
mController.updateState(mPreference);
verify(mView).setImageResource(R.drawable.gentle_notifications_shade_status_lock);
}
@Test
public void updateState_neither() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0);
when(mBackend.shouldHideSilentStatusBarIcons(mContext)).thenReturn(true);
mController.updateState(mPreference);
verify(mView).setImageResource(R.drawable.gentle_notifications_shade);
}
}

View File

@@ -1,117 +0,0 @@
/*
* Copyright (C) 2019 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.notification;
import static android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.provider.Settings;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@RunWith(RobolectricTestRunner.class)
public class SilentLockscreenPreferenceControllerTest {
@Mock
private PreferenceScreen mScreen;
private Context mContext;
private SilentLockscreenPreferenceController mController;
private Preference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new SilentLockscreenPreferenceController(mContext);
mPreference = new Preference(mContext);
mPreference.setKey(mController.getPreferenceKey());
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
}
@Test
public void isAvailable_featureEnabled() {
Settings.Secure.putInt(
mContext.getContentResolver(), NOTIFICATION_NEW_INTERRUPTION_MODEL, 1);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_featureDisabled() {
Settings.Secure.putInt(
mContext.getContentResolver(), NOTIFICATION_NEW_INTERRUPTION_MODEL, 0);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isChecked_settingIsOff_false() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0);
assertThat(mController.isChecked()).isFalse();
}
@Test
public void isChecked_settingIsOn_true() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void onPreferenceChange_on() {
mController.onPreferenceChange(mPreference, true);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0)).isEqualTo(1);
}
@Test
public void onPreferenceChange_off() {
mController.onPreferenceChange(mPreference, false);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1)).isEqualTo(0);
}
@Test
public void listenerTriggered() {
SilentLockscreenPreferenceController.Listener listener = mock(
SilentLockscreenPreferenceController.Listener.class);
mController.setListener(listener);
mController.setChecked(false);
verify(listener).onChange(false);
mController.setChecked(true);
verify(listener).onChange(true);
}
}

View File

@@ -1,118 +0,0 @@
/*
* Copyright (C) 2019 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.notification;
import static android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.provider.Settings;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@RunWith(RobolectricTestRunner.class)
public class SilentStatusBarPreferenceControllerTest {
@Mock
private NotificationBackend mBackend;
@Mock
private PreferenceScreen mScreen;
private Context mContext;
private SilentStatusBarPreferenceController mController;
private Preference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new SilentStatusBarPreferenceController(mContext);
mController.setBackend(mBackend);
mPreference = new Preference(mContext);
mPreference.setKey(mController.getPreferenceKey());
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
}
@Test
public void isAvailable_featureEnabled() {
Settings.Secure.putInt(
mContext.getContentResolver(), NOTIFICATION_NEW_INTERRUPTION_MODEL, 1);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_featureDisabled() {
Settings.Secure.putInt(
mContext.getContentResolver(), NOTIFICATION_NEW_INTERRUPTION_MODEL, 0);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isChecked_settingIsOff_false() {
when(mBackend.shouldHideSilentStatusBarIcons(any())).thenReturn(true);
assertThat(mController.isChecked()).isFalse();
}
@Test
public void isChecked_settingIsOn_true() {
when(mBackend.shouldHideSilentStatusBarIcons(any())).thenReturn(false);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void onPreferenceChange_on() {
mController.onPreferenceChange(mPreference, true);
verify(mBackend).setHideSilentStatusIcons(false);
}
@Test
public void onPreferenceChange_off() {
mController.onPreferenceChange(mPreference, false);
verify(mBackend).setHideSilentStatusIcons(true);
}
@Test
public void listenerTriggered() {
SilentStatusBarPreferenceController.Listener listener = mock(
SilentStatusBarPreferenceController.Listener.class);
mController.setListener(listener);
mController.setChecked(false);
verify(listener).onChange(false);
mController.setChecked(true);
verify(listener).onChange(true);
}
}

View File

@@ -0,0 +1,98 @@
/*
* Copyright (C) 2019 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.tts;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.speech.tts.TextToSpeech;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Checkable;
import androidx.preference.PreferenceViewHolder;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class TtsEnginePreferenceTest {
private static final String KEY = "test_key";
private TtsEnginePreference mPreference;
private Context mContext;
private PreferenceViewHolder mViewHolder;
private View mRootView;
private FakeRadioButtonGroupState mState;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
final TextToSpeech.EngineInfo info = new TextToSpeech.EngineInfo();
info.system = true;
mState = new FakeRadioButtonGroupState();
mPreference = new TtsEnginePreference(mContext, info, mState);
mPreference.setKey(KEY);
// Create preference view holder
final LayoutInflater inflater = LayoutInflater.from(mContext);
mRootView = View.inflate(mContext, mPreference.getLayoutResource(), null /* parent */);
final ViewGroup widgetFrame = mRootView.findViewById(android.R.id.widget_frame);
inflater.inflate(mPreference.getWidgetLayoutResource(), widgetFrame);
mViewHolder = PreferenceViewHolder.createInstanceForTests(mRootView);
}
@Test
public void onClick_shouldInvokeOnCheckedChangeListener() {
mPreference.onBindViewHolder(mViewHolder);
mPreference.onClick();
assertThat(mState.getCurrentKey()).isEqualTo(mPreference.getKey());
}
public static class FakeRadioButtonGroupState implements
TtsEnginePreference.RadioButtonGroupState {
private String mKey;
@Override
public Checkable getCurrentChecked() {
return null;
}
@Override
public String getCurrentKey() {
return mKey;
}
@Override
public void setCurrentChecked(Checkable current) {
}
@Override
public void setCurrentKey(String key) {
mKey = key;
}
}
}