Move hub mode settings under display.
And add a "when to show" setting. Bug: 401001786 Test: manually Flag: com.android.systemui.glanceable_hub_v2 Change-Id: I5f660a1be4bdbb5ab5bb14aa070bfa81b31da6b4
This commit is contained in:
@@ -1059,6 +1059,20 @@
|
|||||||
<item>either_charging_or_docked</item>
|
<item>either_charging_or_docked</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="when_to_start_hubmode_entries" translatable="false">
|
||||||
|
<item>@string/when_to_show_hubmode_never</item>
|
||||||
|
<item>@string/when_to_show_hubmode_charging</item>
|
||||||
|
<item>@string/when_to_show_hubmode_charging_and_upright</item>
|
||||||
|
<item>@string/when_to_show_hubmode_docked</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="when_to_start_hubmode_values" translatable="false">
|
||||||
|
<item>never</item>
|
||||||
|
<item>while_charging</item>
|
||||||
|
<item>while_charging_and_upright</item>
|
||||||
|
<item>while_docked</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="zen_mode_contacts_calls_entries" translatable="false">
|
<string-array name="zen_mode_contacts_calls_entries" translatable="false">
|
||||||
<item>@string/zen_mode_from_anyone</item>
|
<item>@string/zen_mode_from_anyone</item>
|
||||||
<item>@string/zen_mode_from_contacts</item>
|
<item>@string/zen_mode_from_contacts</item>
|
||||||
|
@@ -3650,6 +3650,21 @@
|
|||||||
<string name="communal_settings_title">Communal</string>
|
<string name="communal_settings_title">Communal</string>
|
||||||
<!-- Summary of the communal settings under Settings > Communal [CHAR LIMIT=50] -->
|
<!-- Summary of the communal settings under Settings > Communal [CHAR LIMIT=50] -->
|
||||||
<string name="communal_settings_summary">Communal settings</string>
|
<string name="communal_settings_summary">Communal settings</string>
|
||||||
|
<!-- Title of Hub mode category [CHAR LIMIT=30] -->
|
||||||
|
<string name="hub_mode_category_title">Hub mode</string>
|
||||||
|
<!-- Title of the "widgets on lockscreen" settings page. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="widgets_on_lockscreen_title">Widgets on lock screen</string>
|
||||||
|
|
||||||
|
<!-- Title of a setting to control when to automatically show widgets on the lockscren. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="when_to_auto_show_hubmode_title">When to automatically show</string>
|
||||||
|
<!-- Summary for when to automatically show hub mode (widgets on lockscreen): never [CHAR LIMIT=100] -->
|
||||||
|
<string name="when_to_show_hubmode_never">Never</string>
|
||||||
|
<!-- Summary for when to automatically show hub mode (widgets on lockscreen): charging [CHAR LIMIT=100] -->
|
||||||
|
<string name="when_to_show_hubmode_charging">While charging</string>
|
||||||
|
<!-- Summary for when to automatically show hub mode (widgets on lockscreen): charging and upright [CHAR LIMIT=100] -->
|
||||||
|
<string name="when_to_show_hubmode_charging_and_upright">While charging and upright</string>
|
||||||
|
<!-- Summary for when to automatically show hub mode (widgets on lockscreen): docked [CHAR LIMIT=100] -->
|
||||||
|
<string name="when_to_show_hubmode_docked">While docked</string>
|
||||||
|
|
||||||
<!-- _satellite_setting_preference_layout -->
|
<!-- _satellite_setting_preference_layout -->
|
||||||
<!-- _satellite_setting_preference_layout screen title-->
|
<!-- _satellite_setting_preference_layout screen title-->
|
||||||
|
@@ -88,6 +88,12 @@
|
|||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:title="@string/accessibility_text_reading_options_title"
|
android:title="@string/accessibility_text_reading_options_title"
|
||||||
settings:controller="com.android.settings.accessibility.TextReadingFragmentForDisplaySettingsController"/>
|
settings:controller="com.android.settings.accessibility.TextReadingFragmentForDisplaySettingsController"/>
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="widgets_on_lockscreen"
|
||||||
|
android:title="@string/widgets_on_lockscreen_title"
|
||||||
|
android:fragment="com.android.settings.communal.WidgetsOnLockscreenFragment"
|
||||||
|
settings:controller="com.android.settings.display.WidgetsOnLockscreenPreferenceController"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
|
19
res/xml/when_to_start_hubmode_settings.xml
Normal file
19
res/xml/when_to_start_hubmode_settings.xml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<!--
|
||||||
|
~ Copyright (C) 2025 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"
|
||||||
|
android:title="@string/when_to_auto_show_hubmode_title" />
|
29
res/xml/widgets_on_lockscreen_settings.xml
Normal file
29
res/xml/widgets_on_lockscreen_settings.xml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<!--
|
||||||
|
~ Copyright (C) 2025 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:key="widgets_on_lockscreen"
|
||||||
|
android:title="@string/widgets_on_lockscreen_title">
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="when_to_start"
|
||||||
|
android:title="@string/when_to_auto_show_hubmode_title"
|
||||||
|
android:fragment="com.android.settings.communal.WhenToStartHubPicker"
|
||||||
|
settings:controller="com.android.settings.communal.WhenToStartHubPreferenceController" />
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
@@ -39,15 +39,14 @@ public class CommunalPreferenceController extends BasePreferenceController {
|
|||||||
* Returns whether communal preferences are available.
|
* Returns whether communal preferences are available.
|
||||||
*/
|
*/
|
||||||
public static boolean isAvailable(Context context) {
|
public static boolean isAvailable(Context context) {
|
||||||
|
if (com.android.systemui.Flags.glanceableHubV2()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!Utils.canCurrentUserDream(context)) {
|
if (!Utils.canCurrentUserDream(context)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.getResources().getBoolean(R.bool.config_show_communal_settings)) {
|
return context.getResources().getBoolean(R.bool.config_show_communal_settings);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return com.android.systemui.Flags.glanceableHubV2()
|
|
||||||
&& context.getResources().getBoolean(R.bool.config_show_communal_settings_mobile);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
179
src/com/android/settings/communal/WhenToStartHubPicker.java
Normal file
179
src/com/android/settings/communal/WhenToStartHubPicker.java
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2025 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.communal;
|
||||||
|
|
||||||
|
import static android.provider.Settings.Secure.GLANCEABLE_HUB_START_CHARGING;
|
||||||
|
import static android.provider.Settings.Secure.GLANCEABLE_HUB_START_CHARGING_UPRIGHT;
|
||||||
|
import static android.provider.Settings.Secure.GLANCEABLE_HUB_START_DOCKED;
|
||||||
|
import static android.provider.Settings.Secure.GLANCEABLE_HUB_START_NEVER;
|
||||||
|
import static android.provider.Settings.Secure.WHEN_TO_START_GLANCEABLE_HUB;
|
||||||
|
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.widget.RadioButtonPickerFragment;
|
||||||
|
import com.android.settingslib.widget.CandidateInfo;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fragment that provides radio buttons to allow the user to choose when the hub should auto-start.
|
||||||
|
*/
|
||||||
|
public class WhenToStartHubPicker extends RadioButtonPickerFragment {
|
||||||
|
private static final String TAG = "WhenToStartHubPicker";
|
||||||
|
private static final String SHOW_WHILE_CHARGING = "while_charging";
|
||||||
|
private static final String SHOW_WHILE_DOCKED = "while_docked";
|
||||||
|
private static final String SHOW_WHILE_CHARGING_AND_UPRIGHT = "while_charging_and_upright";
|
||||||
|
private static final String SHOW_NEVER = "never";
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(@NonNull Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
|
||||||
|
mContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getPreferenceScreenResId() {
|
||||||
|
return R.xml.when_to_start_hubmode_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
return SettingsEnums.WHEN_TO_SHOW_WIDGETS_ON_LOCKSCREEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<? extends CandidateInfo> getCandidates() {
|
||||||
|
final List<WhenToStartHubCandidateInfo> candidates = new ArrayList<>();
|
||||||
|
|
||||||
|
final String[] entries = entries();
|
||||||
|
final String[] values = keys();
|
||||||
|
|
||||||
|
if (entries == null || entries.length <= 0) return candidates;
|
||||||
|
if (values == null || values.length != entries.length) {
|
||||||
|
throw new IllegalArgumentException("Entries and values must be of the same length.");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < entries.length; i++) {
|
||||||
|
candidates.add(new WhenToStartHubCandidateInfo(entries[i], values[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return candidates;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] entries() {
|
||||||
|
return getResources().getStringArray(R.array.when_to_start_hubmode_entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] keys() {
|
||||||
|
return getResources().getStringArray(R.array.when_to_start_hubmode_values);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getDefaultKey() {
|
||||||
|
final int defaultValue = mContext.getResources().getInteger(
|
||||||
|
com.android.internal.R.integer.config_whenToStartHubModeDefault);
|
||||||
|
final int setting = Settings.Secure.getInt(
|
||||||
|
mContext.getContentResolver(), WHEN_TO_START_GLANCEABLE_HUB, defaultValue);
|
||||||
|
return getKeyFromSetting(setting);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean setDefaultKey(String key) {
|
||||||
|
Settings.Secure.putInt(
|
||||||
|
mContext.getContentResolver(),
|
||||||
|
WHEN_TO_START_GLANCEABLE_HUB,
|
||||||
|
getSettingFromPrefKey(key));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSelectionPerformed(boolean success) {
|
||||||
|
super.onSelectionPerformed(success);
|
||||||
|
|
||||||
|
getActivity().finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Settings.Secure.WhenToStartGlanceableHub
|
||||||
|
private static int getSettingFromPrefKey(String key) {
|
||||||
|
switch (key) {
|
||||||
|
case SHOW_WHILE_CHARGING:
|
||||||
|
return GLANCEABLE_HUB_START_CHARGING;
|
||||||
|
case SHOW_WHILE_DOCKED:
|
||||||
|
return GLANCEABLE_HUB_START_DOCKED;
|
||||||
|
case SHOW_WHILE_CHARGING_AND_UPRIGHT:
|
||||||
|
return GLANCEABLE_HUB_START_CHARGING_UPRIGHT;
|
||||||
|
case SHOW_NEVER:
|
||||||
|
default:
|
||||||
|
return GLANCEABLE_HUB_START_NEVER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getKeyFromSetting(@Settings.Secure.WhenToStartGlanceableHub int setting) {
|
||||||
|
switch (setting) {
|
||||||
|
case GLANCEABLE_HUB_START_CHARGING:
|
||||||
|
return SHOW_WHILE_CHARGING;
|
||||||
|
case GLANCEABLE_HUB_START_DOCKED:
|
||||||
|
return SHOW_WHILE_DOCKED;
|
||||||
|
case GLANCEABLE_HUB_START_CHARGING_UPRIGHT:
|
||||||
|
return SHOW_WHILE_CHARGING_AND_UPRIGHT;
|
||||||
|
case GLANCEABLE_HUB_START_NEVER:
|
||||||
|
default:
|
||||||
|
return SHOW_NEVER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class WhenToStartHubCandidateInfo extends CandidateInfo {
|
||||||
|
private final String mName;
|
||||||
|
private final String mKey;
|
||||||
|
|
||||||
|
WhenToStartHubCandidateInfo(String title, String value) {
|
||||||
|
super(true);
|
||||||
|
|
||||||
|
mName = title;
|
||||||
|
mKey = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence loadLabel() {
|
||||||
|
return mName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public Drawable loadIcon() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getKey() {
|
||||||
|
return mKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2025 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.communal;
|
||||||
|
|
||||||
|
import static android.provider.Settings.Secure.GLANCEABLE_HUB_START_CHARGING;
|
||||||
|
import static android.provider.Settings.Secure.GLANCEABLE_HUB_START_CHARGING_UPRIGHT;
|
||||||
|
import static android.provider.Settings.Secure.GLANCEABLE_HUB_START_DOCKED;
|
||||||
|
import static android.provider.Settings.Secure.GLANCEABLE_HUB_START_NEVER;
|
||||||
|
import static android.provider.Settings.Secure.WHEN_TO_START_GLANCEABLE_HUB;
|
||||||
|
|
||||||
|
import android.annotation.StringRes;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A preference controller that is responsible for showing the "when to auto start hub" setting in
|
||||||
|
* hub settings.
|
||||||
|
*/
|
||||||
|
public class WhenToStartHubPreferenceController extends BasePreferenceController implements
|
||||||
|
PreferenceControllerMixin {
|
||||||
|
public WhenToStartHubPreferenceController(Context context, String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
super.updateState(preference);
|
||||||
|
|
||||||
|
preference.setSummary(getSummaryResId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getSummary() {
|
||||||
|
return mContext.getString(getSummaryResId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@StringRes
|
||||||
|
private int getSummaryResId() {
|
||||||
|
final int setting = Settings.Secure.getInt(
|
||||||
|
mContext.getContentResolver(),
|
||||||
|
WHEN_TO_START_GLANCEABLE_HUB,
|
||||||
|
GLANCEABLE_HUB_START_NEVER);
|
||||||
|
|
||||||
|
switch (setting) {
|
||||||
|
case GLANCEABLE_HUB_START_CHARGING:
|
||||||
|
return R.string.when_to_show_hubmode_charging;
|
||||||
|
case GLANCEABLE_HUB_START_DOCKED:
|
||||||
|
return R.string.when_to_show_hubmode_docked;
|
||||||
|
case GLANCEABLE_HUB_START_CHARGING_UPRIGHT:
|
||||||
|
return R.string.when_to_show_hubmode_charging_and_upright;
|
||||||
|
case GLANCEABLE_HUB_START_NEVER:
|
||||||
|
default:
|
||||||
|
return R.string.when_to_show_hubmode_never;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2025 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.communal;
|
||||||
|
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fragment that contains settings related to communal hub.
|
||||||
|
*/
|
||||||
|
@SearchIndexable
|
||||||
|
public class WidgetsOnLockscreenFragment extends DashboardFragment {
|
||||||
|
private static final String TAG = "WidgetsOnLockscreenFragment";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
return SettingsEnums.WIDGETS_ON_LOCK_SCREEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getPreferenceScreenResId() {
|
||||||
|
return R.xml.widgets_on_lockscreen_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getLogTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
|
new BaseSearchIndexProvider(R.xml.widgets_on_lockscreen_settings);
|
||||||
|
}
|
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2025 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.os.UserHandle;
|
||||||
|
import android.os.UserManager;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
|
/** Controls the "widgets on lock screen" preferences (under "Display & touch"). */
|
||||||
|
public class WidgetsOnLockscreenPreferenceController extends BasePreferenceController {
|
||||||
|
public WidgetsOnLockscreenPreferenceController(Context context, String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return isAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether "widgets on lock screen" preferences are available.
|
||||||
|
*/
|
||||||
|
public static boolean isAvailable(Context context) {
|
||||||
|
if (!isMainUser(context)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return com.android.systemui.Flags.glanceableHubV2()
|
||||||
|
&& (context.getResources().getBoolean(R.bool.config_show_communal_settings)
|
||||||
|
|| context.getResources().getBoolean(
|
||||||
|
R.bool.config_show_communal_settings_mobile));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isMainUser(Context context) {
|
||||||
|
final UserManager userManager = context.getSystemService(UserManager.class);
|
||||||
|
return userManager.getUserInfo(UserHandle.myUserId()).isMain();
|
||||||
|
}
|
||||||
|
}
|
@@ -16,11 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settings.communal;
|
package com.android.settings.communal;
|
||||||
|
|
||||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
|
||||||
import static com.android.systemui.Flags.FLAG_GLANCEABLE_HUB_V2;
|
import static com.android.systemui.Flags.FLAG_GLANCEABLE_HUB_V2;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
@@ -66,6 +63,7 @@ public class CommunalPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(FLAG_GLANCEABLE_HUB_V2)
|
||||||
public void isAvailable_communalEnabled_shouldBeTrueForPrimaryUser() {
|
public void isAvailable_communalEnabled_shouldBeTrueForPrimaryUser() {
|
||||||
setCommunalEnabled(true);
|
setCommunalEnabled(true);
|
||||||
mShadowUserManager.setUserForeground(true);
|
mShadowUserManager.setUserForeground(true);
|
||||||
@@ -73,6 +71,7 @@ public class CommunalPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(FLAG_GLANCEABLE_HUB_V2)
|
||||||
public void isAvailable_communalEnabled_shouldBeFalseForSecondaryUser() {
|
public void isAvailable_communalEnabled_shouldBeFalseForSecondaryUser() {
|
||||||
setCommunalEnabled(true);
|
setCommunalEnabled(true);
|
||||||
mShadowUserManager.setUserForeground(false);
|
mShadowUserManager.setUserForeground(false);
|
||||||
@@ -80,6 +79,7 @@ public class CommunalPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(FLAG_GLANCEABLE_HUB_V2)
|
||||||
public void isAvailable_communalDisabled_shouldBeFalseForPrimaryUser() {
|
public void isAvailable_communalDisabled_shouldBeFalseForPrimaryUser() {
|
||||||
setCommunalEnabled(false);
|
setCommunalEnabled(false);
|
||||||
mShadowUserManager.setUserForeground(true);
|
mShadowUserManager.setUserForeground(true);
|
||||||
@@ -88,36 +88,8 @@ public class CommunalPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableFlags(FLAG_GLANCEABLE_HUB_V2)
|
@EnableFlags(FLAG_GLANCEABLE_HUB_V2)
|
||||||
public void isAvailable_communalOnMobileEnabled_shouldBeTrueForPrimaryUser() {
|
public void isAvailable_glanceableHubV2Enabled_shouldBeFalseForPrimaryUser() {
|
||||||
setCommunalEnabled(false);
|
setCommunalEnabled(true);
|
||||||
setCommunalOnMobileEnabled(true);
|
|
||||||
mShadowUserManager.setUserForeground(true);
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@EnableFlags(FLAG_GLANCEABLE_HUB_V2)
|
|
||||||
public void isAvailable_communalOnMobileEnabled_shouldBeFalseForSecondaryUser() {
|
|
||||||
setCommunalEnabled(false);
|
|
||||||
setCommunalOnMobileEnabled(true);
|
|
||||||
mShadowUserManager.setUserForeground(false);
|
|
||||||
assertFalse(mController.isAvailable());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@EnableFlags(FLAG_GLANCEABLE_HUB_V2)
|
|
||||||
public void isAvailable_communalOnMobileDisabled_shouldBeFalseForPrimaryUser() {
|
|
||||||
setCommunalEnabled(false);
|
|
||||||
setCommunalOnMobileEnabled(false);
|
|
||||||
mShadowUserManager.setUserForeground(true);
|
|
||||||
assertFalse(mController.isAvailable());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisableFlags(FLAG_GLANCEABLE_HUB_V2)
|
|
||||||
public void isAvailable_glanceableHubV2FlagDisabled_shouldBeFalseForPrimaryUser() {
|
|
||||||
setCommunalEnabled(false);
|
|
||||||
setCommunalOnMobileEnabled(true);
|
|
||||||
mShadowUserManager.setUserForeground(true);
|
mShadowUserManager.setUserForeground(true);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
@@ -125,9 +97,4 @@ public class CommunalPreferenceControllerTest {
|
|||||||
private void setCommunalEnabled(boolean enabled) {
|
private void setCommunalEnabled(boolean enabled) {
|
||||||
SettingsShadowResources.overrideResource(R.bool.config_show_communal_settings, enabled);
|
SettingsShadowResources.overrideResource(R.bool.config_show_communal_settings, enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCommunalOnMobileEnabled(boolean enabled) {
|
|
||||||
SettingsShadowResources.overrideResource(
|
|
||||||
R.bool.config_show_communal_settings_mobile, enabled);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user