Snap for 8228242 from 3afc9399f7 to tm-release

Change-Id: I0d1c85ffdbcb278fda075b1031ad298d757d8fc1
This commit is contained in:
Android Build Coastguard Worker
2022-02-26 04:09:10 +00:00
18 changed files with 419 additions and 40 deletions

View File

@@ -64,36 +64,38 @@
app:layout_constraintStart_toStartOf="@+id/preview" app:layout_constraintStart_toStartOf="@+id/preview"
app:layout_constraintEnd_toEndOf="@+id/preview"/> app:layout_constraintEnd_toEndOf="@+id/preview"/>
<ImageView
android:id="@+id/icon"
android:layout_width="@dimen/dream_item_icon_size"
android:layout_height="0dp"
android:layout_marginTop="@dimen/dream_item_title_margin_top"
android:layout_marginStart="@dimen/dream_item_icon_margin_start"
android:layout_marginBottom="@dimen/dream_item_title_margin_bottom"
android:gravity="center_vertical"
android:importantForAccessibility="no"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintTop_toBottomOf="@+id/preview"
app_layout_constraintEnd_toStartOf="@+id/title_text"
app:layout_constraintStart_toStartOf="parent"/>
<TextView <TextView
android:id="@+id/title_text" android:id="@+id/title_text"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dream_item_title_margin_top" android:layout_marginTop="@dimen/dream_item_title_margin_top"
android:layout_marginStart="@dimen/dream_item_title_margin_start" android:layout_marginHorizontal="@dimen/dream_item_title_margin_horizontal"
android:layout_marginBottom="@dimen/dream_item_title_margin_bottom" android:layout_marginBottom="@dimen/dream_item_title_margin_bottom"
android:gravity="center_vertical" android:gravity="center_vertical"
android:maxLines="1" android:maxLines="1"
android:ellipsize="end" android:ellipsize="end"
android:textSize="16sp" android:textSize="@dimen/dream_item_title_text_size"
android:textColor="@color/dream_card_text_color_state_list" android:textColor="@color/dream_card_text_color_state_list"
android:drawablePadding="@dimen/dream_item_icon_padding"
app:layout_constraintTop_toBottomOf="@+id/preview" app:layout_constraintTop_toBottomOf="@+id/preview"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/icon"/> app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/summary_text"/>
<TextView
android:id="@+id/summary_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/dream_item_title_margin_horizontal"
android:layout_marginBottom="@dimen/dream_item_title_margin_bottom"
android:maxLines="2"
android:ellipsize="end"
android:textSize="@dimen/dream_item_summary_text_size"
android:textColor="@color/dream_card_text_color_state_list"
app:layout_constraintTop_toBottomOf="@+id/title_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>

View File

@@ -24,10 +24,10 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/dream_preview_button_title" android:text="@string/dream_preview_button_title"
android:textAllCaps="false" android:textAllCaps="false"
android:textColor="?androidprv:attr/textColorOnAccent" android:textColor="?android:attr/textColorPrimaryInverse"
android:theme="@style/Theme.CollapsingToolbar.Settings" android:theme="@style/Theme.CollapsingToolbar.Settings"
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
android:layout_gravity="bottom|center" android:layout_gravity="bottom|center"
app:backgroundTint="?androidprv:attr/colorAccentPrimaryVariant" app:backgroundTint="?androidprv:attr/colorAccentPrimaryVariant"
app:iconTint="?androidprv:attr/textColorOnAccent" app:iconTint="?android:attr/textColorPrimaryInverse"
app:icon="@drawable/dream_preview_icon"/> app:icon="@drawable/dream_preview_icon"/>

View File

@@ -445,10 +445,12 @@
<dimen name="dream_item_corner_radius">28dp</dimen> <dimen name="dream_item_corner_radius">28dp</dimen>
<dimen name="dream_item_content_padding">8dp</dimen> <dimen name="dream_item_content_padding">8dp</dimen>
<dimen name="dream_item_icon_size">20dp</dimen> <dimen name="dream_item_icon_size">20dp</dimen>
<dimen name="dream_item_title_margin_top">18dp</dimen> <dimen name="dream_item_summary_text_size">14sp</dimen>
<dimen name="dream_item_title_margin_top">16dp</dimen>
<dimen name="dream_item_title_margin_bottom">8dp</dimen> <dimen name="dream_item_title_margin_bottom">8dp</dimen>
<dimen name="dream_item_title_margin_start">18dp</dimen> <dimen name="dream_item_title_text_size">16sp</dimen>
<dimen name="dream_item_icon_margin_start">10dp</dimen> <dimen name="dream_item_icon_padding">18dp</dimen>
<dimen name="dream_item_title_margin_horizontal">8dp</dimen>
<dimen name="dream_preference_card_padding">16dp</dimen> <dimen name="dream_preference_card_padding">16dp</dimen>
<dimen name="dream_preference_margin_bottom">20dp</dimen> <dimen name="dream_preference_margin_bottom">20dp</dimen>
<dimen name="dream_picker_margin_horizontal">48dp</dimen> <dimen name="dream_picker_margin_horizontal">48dp</dimen>

View File

@@ -13343,6 +13343,10 @@
<string name="lockscreen_privacy_controls_setting_toggle">Show device controls</string> <string name="lockscreen_privacy_controls_setting_toggle">Show device controls</string>
<!-- Device controls summary [CHAR LIMIT=NONE] --> <!-- Device controls summary [CHAR LIMIT=NONE] -->
<string name="lockscreen_privacy_controls_summary">Access controls when locked</string> <string name="lockscreen_privacy_controls_summary">Access controls when locked</string>
<!-- Trivial Device controls toggle name [CHAR LIMIT=60] -->
<string name="lockscreen_trivial_controls_setting_toggle">Control from locked device</string>
<!-- Trivial Device controls summary [CHAR LIMIT=NONE] -->
<string name="lockscreen_trivial_controls_summary">Control external devices without unlocking your phone or tablet if allowed by the device controls app</string>
<!-- Lockscreen double-line clock summary [CHAR LIMIT=NONE] --> <!-- Lockscreen double-line clock summary [CHAR LIMIT=NONE] -->
<string name="lockscreen_double_line_clock_summary">Show double-line clock when available</string> <string name="lockscreen_double_line_clock_summary">Show double-line clock when available</string>
<!-- Lockscreen double-line clock toggle [CHAR LIMIT=60] --> <!-- Lockscreen double-line clock toggle [CHAR LIMIT=60] -->

View File

@@ -734,6 +734,7 @@
parent="@android:style/TextAppearance.DeviceDefault.Widget.ActionBar.Title" > parent="@android:style/TextAppearance.DeviceDefault.Widget.ActionBar.Title" >
<item name="android:layout_gravity">center_horizontal</item> <item name="android:layout_gravity">center_horizontal</item>
<item name="android:padding">6dp</item> <item name="android:padding">6dp</item>
<item name="android:textSize">14sp</item>
</style> </style>
<style name="Widget.PopupWindow.Settings" <style name="Widget.PopupWindow.Settings"

View File

@@ -29,7 +29,7 @@
settings:keywords="@string/keywords_lock_screen_notif"/> settings:keywords="@string/keywords_lock_screen_notif"/>
<SwitchPreference <SwitchPreference
android:key="security_dispaly_lockscreen_bypass" android:key="security_display_lockscreen_bypass"
android:title="@string/lockscreen_bypass_title" android:title="@string/lockscreen_bypass_title"
android:summary="@string/lockscreen_bypass_summary" android:summary="@string/lockscreen_bypass_summary"
settings:searchable="false" settings:searchable="false"
@@ -63,6 +63,12 @@
android:summary="@string/lockscreen_privacy_controls_summary" android:summary="@string/lockscreen_privacy_controls_summary"
settings:controller="com.android.settings.display.ControlsPrivacyPreferenceController" /> settings:controller="com.android.settings.display.ControlsPrivacyPreferenceController" />
<SwitchPreference
android:key="lockscreen_trivial_controls_switch"
android:title="@string/lockscreen_trivial_controls_setting_toggle"
android:summary="@string/lockscreen_trivial_controls_summary"
settings:controller="com.android.settings.display.ControlsTrivialPrivacyPreferenceController"/>
<SwitchPreference <SwitchPreference
android:key="lockscreen_double_line_clock_switch" android:key="lockscreen_double_line_clock_switch"
android:title="@string/lockscreen_double_line_clock_setting_toggle" android:title="@string/lockscreen_double_line_clock_setting_toggle"

View File

@@ -222,7 +222,7 @@ public class AccessibilityDetailsSettingsFragment extends InstrumentedFragment {
new ComponentName(packageName, settingsClassName).flattenToString()); new ComponentName(packageName, settingsClassName).flattenToString());
} }
final String tileServiceClassName = info.getTileServiceClassName(); final String tileServiceClassName = info.getTileServiceName();
if (!TextUtils.isEmpty(tileServiceClassName)) { if (!TextUtils.isEmpty(tileServiceClassName)) {
extras.putString(AccessibilitySettings.EXTRA_TILE_SERVICE_COMPONENT_NAME, extras.putString(AccessibilitySettings.EXTRA_TILE_SERVICE_COMPONENT_NAME,
new ComponentName(packageName, tileServiceClassName).flattenToString()); new ComponentName(packageName, tileServiceClassName).flattenToString());

View File

@@ -576,7 +576,7 @@ public class AccessibilitySettings extends DashboardFragment {
serviceEnabled); serviceEnabled);
final String htmlDescription = info.loadHtmlDescription(mPm); final String htmlDescription = info.loadHtmlDescription(mPm);
final String settingsClassName = info.getSettingsActivityName(); final String settingsClassName = info.getSettingsActivityName();
final String tileServiceClassName = info.getTileServiceClassName(); final String tileServiceClassName = info.getTileServiceName();
putBasicExtras(preference, prefKey, title, intro, description, imageRes, putBasicExtras(preference, prefKey, title, intro, description, imageRes,
htmlDescription, componentName); htmlDescription, componentName);
@@ -637,7 +637,7 @@ public class AccessibilitySettings extends DashboardFragment {
final int imageRes = info.getAnimatedImageRes(); final int imageRes = info.getAnimatedImageRes();
final String htmlDescription = info.loadHtmlDescription(mPm); final String htmlDescription = info.loadHtmlDescription(mPm);
final String settingsClassName = info.getSettingsActivityName(); final String settingsClassName = info.getSettingsActivityName();
final String tileServiceClassName = info.getTileServiceClassName(); final String tileServiceClassName = info.getTileServiceName();
putBasicExtras(preference, prefKey, title, intro, description, imageRes, putBasicExtras(preference, prefKey, title, intro, description, imageRes,
htmlDescription, componentName); htmlDescription, componentName);

View File

@@ -48,6 +48,7 @@ import com.android.settingslib.widget.RadioButtonPreference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
/** /**
@@ -292,7 +293,7 @@ public class AppLocaleDetails extends AppInfoBase implements RadioButtonPreferen
}); });
// Other locales in suggested languages group. // Other locales in suggested languages group.
Collection<Locale> supportedSystemLocales = new ArrayList<>(); Collection<Locale> supportedSystemLocales = new HashSet<>();
getCurrentSystemLocales().forEach(systemLocale -> { getCurrentSystemLocales().forEach(systemLocale -> {
mAppSupportedLocales.forEach(supportedLocale -> { mAppSupportedLocales.forEach(supportedLocale -> {
if (compareLocale(systemLocale, supportedLocale)) { if (compareLocale(systemLocale, supportedLocale)) {

View File

@@ -30,6 +30,9 @@ import com.android.settings.overlay.FeatureFactory;
/** /**
* Preference for showing/hiding sensitive device controls content while the device is locked. * Preference for showing/hiding sensitive device controls content while the device is locked.
*
* Note that ControlsTrivialPrivacyPreferenceController depends on the preferenceKey
* of this controller.
*/ */
public class ControlsPrivacyPreferenceController extends TogglePreferenceController { public class ControlsPrivacyPreferenceController extends TogglePreferenceController {

View File

@@ -0,0 +1,84 @@
/*
* Copyright (C) 2022 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.display;
import android.content.Context;
import android.provider.Settings;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
/**
* Preference for requiring authorization to use home controls for certain devices.
*/
public class ControlsTrivialPrivacyPreferenceController extends TogglePreferenceController {
private static final String SETTING_KEY = Settings.Secure.LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS;
private static final String DEPENDENCY_SETTING_KEY = Settings.Secure.LOCKSCREEN_SHOW_CONTROLS;
public ControlsTrivialPrivacyPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
@Override
public boolean isChecked() {
return Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 0) != 0;
}
@Override
public boolean setChecked(boolean isChecked) {
return Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY,
isChecked ? 1 : 0);
}
@Override
public CharSequence getSummary() {
return mContext.getText(R.string.lockscreen_trivial_controls_summary);
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
preference.setEnabled(getAvailabilityStatus() != DISABLED_DEPENDENT_SETTING);
refreshSummary(preference);
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_display;
}
@Override
public int getAvailabilityStatus() {
return showDeviceControlsSettingsEnabled() ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
}
private boolean showDeviceControlsSettingsEnabled() {
return Settings.Secure.getInt(mContext.getContentResolver(), DEPENDENCY_SETTING_KEY, 0)
!= 0;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
Preference currentPreference = screen.findPreference(getPreferenceKey());
currentPreference.setDependency("lockscreen_privacy_controls_switch");
}
}

View File

@@ -16,9 +16,11 @@
package com.android.settings.dream; package com.android.settings.dream;
import android.annotation.LayoutRes;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.VectorDrawable; import android.graphics.drawable.VectorDrawable;
import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@@ -39,14 +41,15 @@ import java.util.List;
*/ */
public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final List<IDreamItem> mItemList; private final List<IDreamItem> mItemList;
private final @LayoutRes int mLayoutRes;
private int mLastSelectedPos = -1; private int mLastSelectedPos = -1;
/** /**
* View holder for each {@link IDreamItem}. * View holder for each {@link IDreamItem}.
*/ */
private class DreamViewHolder extends RecyclerView.ViewHolder { private class DreamViewHolder extends RecyclerView.ViewHolder {
private final ImageView mIconView;
private final TextView mTitleView; private final TextView mTitleView;
private final TextView mSummaryView;
private final ImageView mPreviewView; private final ImageView mPreviewView;
private final ImageView mPreviewPlaceholderView; private final ImageView mPreviewPlaceholderView;
private final Button mCustomizeButton; private final Button mCustomizeButton;
@@ -57,8 +60,8 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
mContext = context; mContext = context;
mPreviewView = view.findViewById(R.id.preview); mPreviewView = view.findViewById(R.id.preview);
mPreviewPlaceholderView = view.findViewById(R.id.preview_placeholder); mPreviewPlaceholderView = view.findViewById(R.id.preview_placeholder);
mIconView = view.findViewById(R.id.icon);
mTitleView = view.findViewById(R.id.title_text); mTitleView = view.findViewById(R.id.title_text);
mSummaryView = view.findViewById(R.id.summary_text);
mCustomizeButton = view.findViewById(R.id.customize_button); mCustomizeButton = view.findViewById(R.id.customize_button);
} }
@@ -68,6 +71,14 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
public void bindView(IDreamItem item, int position) { public void bindView(IDreamItem item, int position) {
mTitleView.setText(item.getTitle()); mTitleView.setText(item.getTitle());
final CharSequence summary = item.getSummary();
if (TextUtils.isEmpty(summary)) {
mSummaryView.setVisibility(View.GONE);
} else {
mSummaryView.setText(summary);
mSummaryView.setVisibility(View.VISIBLE);
}
final Drawable previewImage = item.getPreviewImage(); final Drawable previewImage = item.getPreviewImage();
if (previewImage != null) { if (previewImage != null) {
mPreviewView.setImageDrawable(previewImage); mPreviewView.setImageDrawable(previewImage);
@@ -82,7 +93,10 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
icon.setTint(Utils.getColorAttrDefaultColor(mContext, icon.setTint(Utils.getColorAttrDefaultColor(mContext,
com.android.internal.R.attr.colorAccentPrimaryVariant)); com.android.internal.R.attr.colorAccentPrimaryVariant));
} }
mIconView.setImageDrawable(icon); final int iconSize = mContext.getResources().getDimensionPixelSize(
R.dimen.dream_item_icon_size);
icon.setBounds(0, 0, iconSize, iconSize);
mTitleView.setCompoundDrawablesRelative(icon, null, null, null);
if (item.isActive()) { if (item.isActive()) {
mLastSelectedPos = position; mLastSelectedPos = position;
@@ -104,15 +118,16 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
} }
public DreamAdapter(List<IDreamItem> itemList) { public DreamAdapter(@LayoutRes int layoutRes, List<IDreamItem> itemList) {
mItemList = itemList; mItemList = itemList;
mLayoutRes = layoutRes;
} }
@NonNull @NonNull
@Override @Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) { public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
View view = LayoutInflater.from(viewGroup.getContext()) View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.dream_preference_layout, viewGroup, false); .inflate(mLayoutRes, viewGroup, false);
return new DreamViewHolder(view, viewGroup.getContext()); return new DreamViewHolder(view, viewGroup.getContext());
} }

View File

@@ -74,9 +74,10 @@ public class DreamPickerController extends BasePreferenceController {
public void displayPreference(PreferenceScreen screen) { public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen); super.displayPreference(screen);
mAdapter = new DreamAdapter(mDreamInfos.stream() mAdapter = new DreamAdapter(R.layout.dream_preference_layout,
.map(DreamItem::new) mDreamInfos.stream()
.collect(Collectors.toList())); .map(DreamItem::new)
.collect(Collectors.toList()));
final LayoutPreference pref = screen.findPreference(getPreferenceKey()); final LayoutPreference pref = screen.findPreference(getPreferenceKey());
if (pref == null) { if (pref == null) {
@@ -111,6 +112,11 @@ public class DreamPickerController extends BasePreferenceController {
return mDreamInfo.caption; return mDreamInfo.caption;
} }
@Override
public CharSequence getSummary() {
return mDreamInfo.description;
}
@Override @Override
public Drawable getIcon() { public Drawable getIcon() {
return mDreamInfo.icon; return mDreamInfo.icon;

View File

@@ -18,23 +18,52 @@ package com.android.settings.dream;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import androidx.annotation.Nullable;
/** /**
* Interface representing a dream item to be displayed. * Interface representing a dream item to be displayed.
*/ */
public interface IDreamItem { public interface IDreamItem {
/**
* Gets the title of this dream.
*/
CharSequence getTitle(); CharSequence getTitle();
/**
* Gets the summary of this dream, or null if the dream doesn't provide one.
*/
@Nullable
CharSequence getSummary();
/**
* Gets the icon for the dream.
*/
Drawable getIcon(); Drawable getIcon();
/**
* Callback which can be implemented to handle clicks on this dream.
*/
void onItemClicked(); void onItemClicked();
/**
* Callback which can be implemented to handle the customization of this dream.
*/
default void onCustomizeClicked() { default void onCustomizeClicked() {
} }
/**
* Gets the preview image of this dream.
*/
Drawable getPreviewImage(); Drawable getPreviewImage();
/**
* Returns whether or not this dream is currently active.
*/
boolean isActive(); boolean isActive();
/**
* Returns whether to allow customization of this dream or not.
*/
default boolean allowCustomization() { default boolean allowCustomization() {
return false; return false;
} }

View File

@@ -21,8 +21,13 @@ import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROF
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.Context; import android.content.Context;
import android.database.ContentObserver;
import android.hardware.display.AmbientDisplayConfiguration; import android.hardware.display.AmbientDisplayConfiguration;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
@@ -68,6 +73,8 @@ public class LockscreenDashboardFragment extends DashboardFragment
private AmbientDisplayConfiguration mConfig; private AmbientDisplayConfiguration mConfig;
private OwnerInfoPreferenceController mOwnerInfoPreferenceController; private OwnerInfoPreferenceController mOwnerInfoPreferenceController;
@VisibleForTesting
ContentObserver mControlsContentObserver;
@Override @Override
public int getMetricsCategory() { public int getMetricsCategory() {
@@ -106,6 +113,27 @@ public class LockscreenDashboardFragment extends DashboardFragment
use(AmbientDisplayNotificationsPreferenceController.class).setConfig(getConfig(context)); use(AmbientDisplayNotificationsPreferenceController.class).setConfig(getConfig(context));
use(DoubleTapScreenPreferenceController.class).setConfig(getConfig(context)); use(DoubleTapScreenPreferenceController.class).setConfig(getConfig(context));
use(PickupGesturePreferenceController.class).setConfig(getConfig(context)); use(PickupGesturePreferenceController.class).setConfig(getConfig(context));
mControlsContentObserver = new ContentObserver(
new Handler(Looper.getMainLooper())) {
@Override
public void onChange(boolean selfChange, Uri uri) {
super.onChange(selfChange, uri);
updatePreferenceStates();
}
};
context.getContentResolver().registerContentObserver(
Settings.Secure.getUriFor(Settings.Secure.LOCKSCREEN_SHOW_CONTROLS),
false /* notifyForDescendants */, mControlsContentObserver);
}
@Override
public void onDetach() {
if (mControlsContentObserver != null) {
getContext().getContentResolver().unregisterContentObserver(mControlsContentObserver);
mControlsContentObserver = null;
}
super.onDetach();
} }
@Override @Override

View File

@@ -0,0 +1,157 @@
/*
* Copyright (C) 2022 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.display;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.verify;
import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class ControlsTrivialPrivacyPreferenceControllerTest {
private static final String TEST_KEY = "test_key";
private static final String SETTING_KEY = Settings.Secure.LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS;
private static final String DEPENDENCY_SETTING_KEY = Settings.Secure.LOCKSCREEN_SHOW_CONTROLS;
private Context mContext;
private ContentResolver mContentResolver;
private ControlsTrivialPrivacyPreferenceController mController;
@Mock
private Preference mPreference;
@Mock
private PreferenceScreen mPreferenceScreen;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = ApplicationProvider.getApplicationContext();
mContentResolver = mContext.getContentResolver();
mController = new ControlsTrivialPrivacyPreferenceController(mContext, TEST_KEY);
}
@Test
public void isCheckedWhenSettingIsTrue() {
Settings.Secure.putInt(mContentResolver, SETTING_KEY, 1);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void isCheckedWhenSettingIsFalse() {
Settings.Secure.putInt(mContentResolver, SETTING_KEY, 0);
assertThat(mController.isChecked()).isFalse();
}
@Test
public void isCheckedWhenSettingIsNull() {
Settings.Secure.putString(mContentResolver, SETTING_KEY, null);
assertThat(mController.isChecked()).isFalse();
}
@Test
public void checkedMeansSettingIsTrue() {
mController.setChecked(true);
assertThat(Settings.Secure.getInt(mContentResolver, SETTING_KEY, 0)).isNotEqualTo(0);
}
@Test
public void uncheckedMeansSettingIsFalse() {
mController.setChecked(false);
assertThat(Settings.Secure.getInt(mContentResolver, SETTING_KEY, 0)).isEqualTo(0);
}
@Test
public void getSummaryRequireDeviceControls() {
Settings.Secure.putInt(mContentResolver, DEPENDENCY_SETTING_KEY, 0);
assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getText(R.string.lockscreen_trivial_controls_summary));
}
@Test
public void getSummaryDefault() {
Settings.Secure.putInt(mContentResolver, DEPENDENCY_SETTING_KEY, 1);
assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getText(R.string.lockscreen_trivial_controls_summary));
}
@Test
public void updateState() {
Settings.Secure.putInt(mContentResolver, DEPENDENCY_SETTING_KEY, 1);
mController.updateState(mPreference);
verify(mPreference).setEnabled(anyBoolean());
verify(mPreference, atLeastOnce()).setSummary(mController.getSummary());
}
@Test
public void getAvailabilityStatusWithoutDeviceControls() {
Settings.Secure.putInt(mContentResolver, DEPENDENCY_SETTING_KEY, 0);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.DISABLED_DEPENDENT_SETTING);
}
@Test
public void getAvailabilityStatusWithDeviceControls() {
Settings.Secure.putInt(mContentResolver, DEPENDENCY_SETTING_KEY, 1);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE);
}
@Test
public void setDependency() {
Mockito.when(mPreferenceScreen
.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mPreferenceScreen);
verify(mPreference).setDependency(anyString());
}
}

View File

@@ -67,6 +67,7 @@ public class LockscreenDashboardFragmentTest {
.thenReturn(mLockPatternUtils); .thenReturn(mLockPatternUtils);
mContext = RuntimeEnvironment.application; mContext = RuntimeEnvironment.application;
mTestFragment = spy(new TestFragment()); mTestFragment = spy(new TestFragment());
doReturn(mContext).when(mTestFragment).getContext();
} }
@Test @Test
@@ -131,6 +132,14 @@ public class LockscreenDashboardFragmentTest {
.doesNotContain("security_lockscreen_settings_screen"); .doesNotContain("security_lockscreen_settings_screen");
} }
@Test
public void controlsSettings() {
mTestFragment.onAttach(mContext);
assertThat(mTestFragment.mControlsContentObserver).isNotNull();
mTestFragment.onDetach();
assertThat(mTestFragment.mControlsContentObserver).isNull();
}
public static class TestFragment extends LockscreenDashboardFragment { public static class TestFragment extends LockscreenDashboardFragment {
@Override @Override
protected <T extends AbstractPreferenceController> T use(Class<T> clazz) { protected <T extends AbstractPreferenceController> T use(Class<T> clazz) {

View File

@@ -43,7 +43,9 @@ import org.mockito.MockitoAnnotations;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.Set;
/** /**
* Unittest for ApplocaleDetails * Unittest for ApplocaleDetails
@@ -151,8 +153,9 @@ public class AppLocaleDetailsTest {
@Test @Test
@UiThreadTest @UiThreadTest
public void public void
handleAllLocalesData_noAppAndNoSupportedSimLocale_1stSuggestedLocaleIsAssetLocale() { handleAllLocalesData_noAppAndNoSupportedSimLocale_suggestedLocaleIsSupported() {
Locale firstAssetLocale = new Locale("en", "GB"); Locale testEnAssetLocale = new Locale("en", "GB");
Locale testJaAssetLocale = new Locale("ja", "JP");
setupInitialLocales( setupInitialLocales(
/* appLocale= */ "", /* appLocale= */ "",
/* simCountry= */ "tw", /* simCountry= */ "tw",
@@ -166,8 +169,8 @@ public class AppLocaleDetailsTest {
helper.handleAllLocalesData(); helper.handleAllLocalesData();
Collection<Locale> suggestedLocales = helper.getSuggestedLocales(); Collection<Locale> suggestedLocales = helper.getSuggestedLocales();
Locale locale = suggestedLocales.iterator().next(); assertTrue(suggestedLocales.contains(testEnAssetLocale));
assertTrue(locale.equals(firstAssetLocale)); assertTrue(suggestedLocales.contains(testJaAssetLocale));
} }
@Test @Test
@@ -295,6 +298,35 @@ public class AppLocaleDetailsTest {
assertTrue(locale.equals(systemLocale)); assertTrue(locale.equals(systemLocale));
} }
@Test
@UiThreadTest
public void handleAllLocalesData_sameLocaleButDifferentRegion_notShowDuplicatedLocale() {
setupInitialLocales(
/* appLocale= */ "",
/* simCountry= */ "",
/* networkCountry= */ "",
/* systemLocales= */ "en-us, en-gb, jp, ne",
/* packageLocales= */ "pa, cn, tw, en-us, en-gb",
/* assetLocales= */ new String[]{});
DummyAppLocaleDetailsHelper helper =
new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME);
helper.handleAllLocalesData();
Collection<Locale> suggestedLocales = helper.getSuggestedLocales();
assertFalse(hasDuplicatedResult(suggestedLocales));
}
private boolean hasDuplicatedResult(Collection<Locale> locales) {
Set<Locale> tempSet = new HashSet<>();
for (Locale locale : locales) {
if (!tempSet.add(locale)) {
return true;
}
}
return false;
}
@Test @Test
@UiThreadTest @UiThreadTest
public void handleAllLocalesData_supportLocaleListIsNotEmpty() { public void handleAllLocalesData_supportLocaleListIsNotEmpty() {