Refactors the System Navigation settings page
Bug: 130915285 Bug: 128855215 Bug: 127718810 Bug: 129115299 Test: make RunSettingsRoboTests ROBOTEST_FILTER=SystemNavigationGestureSettingsTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=SystemNavigationPreferenceControllerTest Change-Id: If11e1fe4bf150d2dd9578f731e71abf6b74f5d90
This commit is contained in:
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
BIN
res/drawable-nodpi/system_nav_3_button.png
Normal file
BIN
res/drawable-nodpi/system_nav_3_button.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
BIN
res/drawable-nodpi/system_nav_fully_gestural.png
Normal file
BIN
res/drawable-nodpi/system_nav_fully_gestural.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
BIN
res/raw/system_nav_3_button.mp4
Normal file
BIN
res/raw/system_nav_3_button.mp4
Normal file
Binary file not shown.
BIN
res/raw/system_nav_fully_gestural.mp4
Normal file
BIN
res/raw/system_nav_fully_gestural.mp4
Normal file
Binary file not shown.
@@ -49,7 +49,7 @@
|
|||||||
android:key="gesture_system_navigation_input_summary"
|
android:key="gesture_system_navigation_input_summary"
|
||||||
android:title="@string/system_navigation_title"
|
android:title="@string/system_navigation_title"
|
||||||
android:fragment="com.android.settings.gestures.SystemNavigationGestureSettings"
|
android:fragment="com.android.settings.gestures.SystemNavigationGestureSettings"
|
||||||
settings:controller="com.android.settings.gestures.SystemNavigationLegacyPreferenceController" />
|
settings:controller="com.android.settings.gestures.SystemNavigationPreferenceController" />
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="gesture_tap_screen_input_summary"
|
android:key="gesture_tap_screen_input_summary"
|
||||||
|
@@ -17,35 +17,7 @@
|
|||||||
|
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||||
android:key="gesture_system_navigation_screen"
|
android:key="gesture_system_navigation_screen"
|
||||||
android:title="@string/system_navigation_title">
|
android:title="@string/system_navigation_title"
|
||||||
|
settings:keywords="@string/keywords_system_navigation"/>
|
||||||
<com.android.settings.widget.VideoPreference
|
|
||||||
android:key="gesture_swipe_up_video"
|
|
||||||
app:animation="@raw/gesture_swipe_up"
|
|
||||||
app:preview="@drawable/gesture_swipe_up" />
|
|
||||||
|
|
||||||
<com.android.settings.widget.RadioButtonPreference
|
|
||||||
android:key="gesture_edge_to_edge"
|
|
||||||
android:title="@string/edge_to_edge_navigation_title"
|
|
||||||
android:summary="@string/edge_to_edge_navigation_summary"
|
|
||||||
app:keywords="@string/keywords_gesture"
|
|
||||||
app:controller="com.android.settings.gestures.SystemNavigationEdgeToEdgePreferenceController"
|
|
||||||
app:allowDividerAbove="true" />
|
|
||||||
|
|
||||||
<com.android.settings.widget.RadioButtonPreference
|
|
||||||
android:key="gesture_swipe_up"
|
|
||||||
android:title="@string/swipe_up_to_switch_apps_title"
|
|
||||||
android:summary="@string/swipe_up_to_switch_apps_summary"
|
|
||||||
app:keywords="@string/keywords_gesture"
|
|
||||||
app:controller="com.android.settings.gestures.SystemNavigationSwipeUpPreferenceController" />
|
|
||||||
|
|
||||||
<com.android.settings.widget.RadioButtonPreference
|
|
||||||
android:key="gesture_legacy"
|
|
||||||
android:title="@string/legacy_navigation_title"
|
|
||||||
android:summary="@string/legacy_navigation_summary"
|
|
||||||
app:keywords="@string/keywords_gesture"
|
|
||||||
app:controller="com.android.settings.gestures.SystemNavigationLegacyPreferenceController" />
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
|
||||||
|
@@ -1,55 +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.gestures;
|
|
||||||
|
|
||||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.om.IOverlayManager;
|
|
||||||
import android.os.ServiceManager;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
|
|
||||||
import com.android.settings.widget.RadioButtonPreference;
|
|
||||||
|
|
||||||
public class SystemNavigationEdgeToEdgePreferenceController extends
|
|
||||||
SystemNavigationPreferenceController {
|
|
||||||
static final String PREF_KEY_EDGE_TO_EDGE = "gesture_edge_to_edge";
|
|
||||||
|
|
||||||
public SystemNavigationEdgeToEdgePreferenceController(Context context, String key) {
|
|
||||||
this(context, IOverlayManager.Stub.asInterface(ServiceManager.getService(
|
|
||||||
Context.OVERLAY_SERVICE)), key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
public SystemNavigationEdgeToEdgePreferenceController(Context context,
|
|
||||||
IOverlayManager overlayManager, String key) {
|
|
||||||
super(context, overlayManager, key, NAV_BAR_MODE_GESTURAL_OVERLAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRadioButtonClicked(RadioButtonPreference preference) {
|
|
||||||
setNavBarInteractionMode(mOverlayManager, NAV_BAR_MODE_GESTURAL_OVERLAY);
|
|
||||||
selectRadioButtonInGroup(PREF_KEY_EDGE_TO_EDGE, mPreferenceScreen);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isChecked() {
|
|
||||||
return isEdgeToEdgeEnabled(mContext);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -16,29 +16,58 @@
|
|||||||
|
|
||||||
package com.android.settings.gestures;
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
|
import static android.os.UserHandle.USER_CURRENT;
|
||||||
|
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON_OVERLAY;
|
||||||
|
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON_OVERLAY;
|
||||||
|
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY;
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.om.IOverlayManager;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.RemoteException;
|
||||||
|
import android.os.ServiceManager;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
|
import com.android.settings.search.Indexable;
|
||||||
|
import com.android.settings.widget.RadioButtonPickerFragment;
|
||||||
|
import com.android.settings.widget.RadioButtonPreference;
|
||||||
|
import com.android.settings.widget.VideoPreference;
|
||||||
import com.android.settingslib.search.SearchIndexable;
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
|
import com.android.settingslib.widget.CandidateInfo;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@SearchIndexable
|
@SearchIndexable
|
||||||
public class SystemNavigationGestureSettings extends DashboardFragment {
|
public class SystemNavigationGestureSettings extends RadioButtonPickerFragment {
|
||||||
|
|
||||||
private static final String TAG = "SystemNavigationGesture";
|
private static final String TAG = "SystemNavigationGesture";
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static final String KEY_SYSTEM_NAV_3BUTTONS = "system_nav_3buttons";
|
||||||
|
@VisibleForTesting
|
||||||
|
static final String KEY_SYSTEM_NAV_2BUTTONS = "system_nav_2buttons";
|
||||||
|
@VisibleForTesting
|
||||||
|
static final String KEY_SYSTEM_NAV_GESTURAL = "system_nav_gestural";
|
||||||
|
|
||||||
public static final String PREF_KEY_SUGGESTION_COMPLETE =
|
public static final String PREF_KEY_SUGGESTION_COMPLETE =
|
||||||
"pref_system_navigation_suggestion_complete";
|
"pref_system_navigation_suggestion_complete";
|
||||||
|
|
||||||
|
private IOverlayManager mOverlayManager;
|
||||||
|
|
||||||
|
private VideoPreference mVideoPreference;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
@@ -46,6 +75,12 @@ public class SystemNavigationGestureSettings extends DashboardFragment {
|
|||||||
.getSuggestionFeatureProvider(context);
|
.getSuggestionFeatureProvider(context);
|
||||||
SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context);
|
SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context);
|
||||||
prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply();
|
prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply();
|
||||||
|
|
||||||
|
mOverlayManager = IOverlayManager.Stub.asInterface(
|
||||||
|
ServiceManager.getService(Context.OVERLAY_SERVICE));
|
||||||
|
|
||||||
|
mVideoPreference = new VideoPreference(context);
|
||||||
|
setIllustrationVideo(mVideoPreference, getDefaultKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -53,17 +88,154 @@ public class SystemNavigationGestureSettings extends DashboardFragment {
|
|||||||
return SettingsEnums.SETTINGS_GESTURE_SWIPE_UP;
|
return SettingsEnums.SETTINGS_GESTURE_SWIPE_UP;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getLogTag() {
|
|
||||||
return TAG;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getPreferenceScreenResId() {
|
protected int getPreferenceScreenResId() {
|
||||||
return R.xml.system_navigation_gesture_settings;
|
return R.xml.system_navigation_gesture_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
@Override
|
||||||
|
protected void addStaticPreferences(PreferenceScreen screen) {
|
||||||
|
screen.addPreference(mVideoPreference);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<? extends CandidateInfo> getCandidates() {
|
||||||
|
final Context c = getContext();
|
||||||
|
List<NavModeCandidateInfo> candidates = new ArrayList<>();
|
||||||
|
|
||||||
|
if (SystemNavigationPreferenceController.isOverlayPackageAvailable(c,
|
||||||
|
NAV_BAR_MODE_GESTURAL_OVERLAY)) {
|
||||||
|
candidates.add(new NavModeCandidateInfo(
|
||||||
|
c.getText(R.string.edge_to_edge_navigation_title),
|
||||||
|
c.getText(R.string.edge_to_edge_navigation_summary),
|
||||||
|
KEY_SYSTEM_NAV_GESTURAL, true /* enabled */));
|
||||||
|
}
|
||||||
|
if (SystemNavigationPreferenceController.isOverlayPackageAvailable(c,
|
||||||
|
NAV_BAR_MODE_2BUTTON_OVERLAY)) {
|
||||||
|
candidates.add(new NavModeCandidateInfo(
|
||||||
|
c.getText(R.string.swipe_up_to_switch_apps_title),
|
||||||
|
c.getText(R.string.swipe_up_to_switch_apps_summary),
|
||||||
|
KEY_SYSTEM_NAV_2BUTTONS, true /* enabled */));
|
||||||
|
}
|
||||||
|
if (SystemNavigationPreferenceController.isOverlayPackageAvailable(c,
|
||||||
|
NAV_BAR_MODE_3BUTTON_OVERLAY)) {
|
||||||
|
candidates.add(new NavModeCandidateInfo(
|
||||||
|
c.getText(R.string.legacy_navigation_title),
|
||||||
|
c.getText(R.string.legacy_navigation_summary),
|
||||||
|
KEY_SYSTEM_NAV_3BUTTONS, true /* enabled */));
|
||||||
|
}
|
||||||
|
|
||||||
|
return candidates;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getDefaultKey() {
|
||||||
|
return getCurrentSystemNavigationMode(getContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean setDefaultKey(String key) {
|
||||||
|
setCurrentSystemNavigationMode(mOverlayManager, key);
|
||||||
|
setIllustrationVideo(mVideoPreference, key);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static String getCurrentSystemNavigationMode(Context context) {
|
||||||
|
if (SystemNavigationPreferenceController.isEdgeToEdgeEnabled(context)) {
|
||||||
|
return KEY_SYSTEM_NAV_GESTURAL;
|
||||||
|
} else if (SystemNavigationPreferenceController.isSwipeUpEnabled(context)) {
|
||||||
|
return KEY_SYSTEM_NAV_2BUTTONS;
|
||||||
|
} else {
|
||||||
|
return KEY_SYSTEM_NAV_3BUTTONS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static void setCurrentSystemNavigationMode(IOverlayManager overlayManager, String key) {
|
||||||
|
switch (key) {
|
||||||
|
case KEY_SYSTEM_NAV_GESTURAL:
|
||||||
|
setNavBarInteractionMode(overlayManager, NAV_BAR_MODE_GESTURAL_OVERLAY);
|
||||||
|
break;
|
||||||
|
case KEY_SYSTEM_NAV_2BUTTONS:
|
||||||
|
setNavBarInteractionMode(overlayManager, NAV_BAR_MODE_2BUTTON_OVERLAY);
|
||||||
|
break;
|
||||||
|
case KEY_SYSTEM_NAV_3BUTTONS:
|
||||||
|
setNavBarInteractionMode(overlayManager, NAV_BAR_MODE_3BUTTON_OVERLAY);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables the specified overlay package.
|
||||||
|
*/
|
||||||
|
static void setNavBarInteractionMode(IOverlayManager overlayManager, String overlayPackage) {
|
||||||
|
try {
|
||||||
|
overlayManager.setEnabledExclusiveInCategory(overlayPackage, USER_CURRENT);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
throw e.rethrowFromSystemServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setIllustrationVideo(VideoPreference videoPref, String systemNavKey) {
|
||||||
|
videoPref.setVideo(0, 0);
|
||||||
|
switch (systemNavKey) {
|
||||||
|
case KEY_SYSTEM_NAV_GESTURAL:
|
||||||
|
videoPref.setVideo(R.raw.system_nav_fully_gestural,
|
||||||
|
R.drawable.system_nav_fully_gestural);
|
||||||
|
break;
|
||||||
|
case KEY_SYSTEM_NAV_2BUTTONS:
|
||||||
|
videoPref.setVideo(R.raw.system_nav_2_button, R.drawable.system_nav_2_button);
|
||||||
|
break;
|
||||||
|
case KEY_SYSTEM_NAV_3BUTTONS:
|
||||||
|
videoPref.setVideo(R.raw.system_nav_3_button, R.drawable.system_nav_3_button);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bindPreferenceExtra(RadioButtonPreference pref,
|
||||||
|
String key, CandidateInfo info, String defaultKey, String systemDefaultKey) {
|
||||||
|
if (info instanceof NavModeCandidateInfo) {
|
||||||
|
pref.setSummary(((NavModeCandidateInfo) info).loadSummary());
|
||||||
|
pref.setAppendixVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class NavModeCandidateInfo extends CandidateInfo {
|
||||||
|
private final CharSequence mLabel;
|
||||||
|
private final CharSequence mSummary;
|
||||||
|
private final String mKey;
|
||||||
|
|
||||||
|
NavModeCandidateInfo(CharSequence label, CharSequence summary, String key,
|
||||||
|
boolean enabled) {
|
||||||
|
super(enabled);
|
||||||
|
mLabel = label;
|
||||||
|
mSummary = summary;
|
||||||
|
mKey = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence loadLabel() {
|
||||||
|
return mLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CharSequence loadSummary() {
|
||||||
|
return mSummary;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Drawable loadIcon() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getKey() {
|
||||||
|
return mKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
new BaseSearchIndexProvider() {
|
new BaseSearchIndexProvider() {
|
||||||
@Override
|
@Override
|
||||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
||||||
|
@@ -1,55 +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.gestures;
|
|
||||||
|
|
||||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON_OVERLAY;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.om.IOverlayManager;
|
|
||||||
import android.os.ServiceManager;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
|
|
||||||
import com.android.settings.widget.RadioButtonPreference;
|
|
||||||
|
|
||||||
public class SystemNavigationLegacyPreferenceController extends
|
|
||||||
SystemNavigationPreferenceController {
|
|
||||||
static final String PREF_KEY_LEGACY = "gesture_legacy";
|
|
||||||
|
|
||||||
public SystemNavigationLegacyPreferenceController(Context context, String key) {
|
|
||||||
this(context, IOverlayManager.Stub.asInterface(ServiceManager.getService(
|
|
||||||
Context.OVERLAY_SERVICE)), key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
public SystemNavigationLegacyPreferenceController(Context context,
|
|
||||||
IOverlayManager overlayManager, String key) {
|
|
||||||
super(context, overlayManager, key, NAV_BAR_MODE_3BUTTON_OVERLAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRadioButtonClicked(RadioButtonPreference preference) {
|
|
||||||
setNavBarInteractionMode(mOverlayManager, NAV_BAR_MODE_3BUTTON_OVERLAY);
|
|
||||||
selectRadioButtonInGroup(PREF_KEY_LEGACY, mPreferenceScreen);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isChecked() {
|
|
||||||
return !isEdgeToEdgeEnabled(mContext) && !isSwipeUpEnabled(mContext);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -16,79 +16,29 @@
|
|||||||
|
|
||||||
package com.android.settings.gestures;
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
import static android.os.UserHandle.USER_CURRENT;
|
|
||||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON;
|
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON;
|
||||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON_OVERLAY;
|
|
||||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON_OVERLAY;
|
|
||||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
|
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
|
||||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY;
|
|
||||||
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.om.IOverlayManager;
|
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.widget.RadioButtonPreference;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
public abstract class SystemNavigationPreferenceController extends GesturePreferenceController
|
public class SystemNavigationPreferenceController extends BasePreferenceController {
|
||||||
implements RadioButtonPreference.OnClickListener {
|
|
||||||
|
|
||||||
|
static final String PREF_KEY_SYSTEM_NAVIGATION = "gesture_system_navigation";
|
||||||
private static final String ACTION_QUICKSTEP = "android.intent.action.QUICKSTEP_SERVICE";
|
private static final String ACTION_QUICKSTEP = "android.intent.action.QUICKSTEP_SERVICE";
|
||||||
private static final String PREF_KEY_VIDEO = "gesture_swipe_up_video";
|
|
||||||
|
|
||||||
private static final String[] RADIO_BUTTONS_IN_GROUP = {
|
public SystemNavigationPreferenceController(Context context, String key) {
|
||||||
SystemNavigationLegacyPreferenceController.PREF_KEY_LEGACY,
|
|
||||||
SystemNavigationSwipeUpPreferenceController.PREF_KEY_SWIPE_UP,
|
|
||||||
SystemNavigationEdgeToEdgePreferenceController.PREF_KEY_EDGE_TO_EDGE,
|
|
||||||
};
|
|
||||||
|
|
||||||
protected final IOverlayManager mOverlayManager;
|
|
||||||
protected PreferenceScreen mPreferenceScreen;
|
|
||||||
private final String mOverlayPackage;
|
|
||||||
|
|
||||||
public SystemNavigationPreferenceController(Context context, IOverlayManager overlayManager,
|
|
||||||
String key, String overlayPackage) {
|
|
||||||
super(context, key);
|
super(context, key);
|
||||||
mOverlayManager = overlayManager;
|
|
||||||
mOverlayPackage = overlayPackage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
return isGestureAvailable(mContext, mOverlayPackage) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
return isGestureAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
|
||||||
super.displayPreference(screen);
|
|
||||||
mPreferenceScreen = screen;
|
|
||||||
|
|
||||||
Preference preference = screen.findPreference(getPreferenceKey());
|
|
||||||
if (preference != null && preference instanceof RadioButtonPreference) {
|
|
||||||
RadioButtonPreference radioPreference = (RadioButtonPreference) preference;
|
|
||||||
radioPreference.setOnClickListener(this);
|
|
||||||
radioPreference.setAppendixVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setChecked(boolean isChecked) {
|
|
||||||
if (!isChecked || mPreferenceScreen == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Preference preference = mPreferenceScreen.findPreference(getPreferenceKey());
|
|
||||||
if (preference != null && preference instanceof RadioButtonPreference) {
|
|
||||||
onRadioButtonClicked((RadioButtonPreference) preference);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -102,17 +52,7 @@ public abstract class SystemNavigationPreferenceController extends GesturePrefer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getVideoPrefKey() {
|
|
||||||
return PREF_KEY_VIDEO;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static boolean isGestureAvailable(Context context) {
|
static boolean isGestureAvailable(Context context) {
|
||||||
return isGestureAvailable(context, null /* overlayPackage */);
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean isGestureAvailable(Context context, String overlayPackage) {
|
|
||||||
// Skip if the swipe up settings are not available
|
// Skip if the swipe up settings are not available
|
||||||
if (!context.getResources().getBoolean(
|
if (!context.getResources().getBoolean(
|
||||||
com.android.internal.R.bool.config_swipe_up_gesture_setting_available)) {
|
com.android.internal.R.bool.config_swipe_up_gesture_setting_available)) {
|
||||||
@@ -127,44 +67,22 @@ public abstract class SystemNavigationPreferenceController extends GesturePrefer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Skip if the overview proxy service exists
|
// Skip if the overview proxy service exists
|
||||||
final PackageManager pm = context.getPackageManager();
|
|
||||||
final Intent quickStepIntent = new Intent(ACTION_QUICKSTEP)
|
final Intent quickStepIntent = new Intent(ACTION_QUICKSTEP)
|
||||||
.setPackage(recentsComponentName.getPackageName());
|
.setPackage(recentsComponentName.getPackageName());
|
||||||
if (pm.resolveService(quickStepIntent, PackageManager.MATCH_SYSTEM_ONLY) == null) {
|
if (context.getPackageManager().resolveService(quickStepIntent,
|
||||||
|
PackageManager.MATCH_SYSTEM_ONLY) == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip if the required overlay package is defined but doesn't exist
|
|
||||||
if (overlayPackage != null) {
|
|
||||||
try {
|
|
||||||
return pm.getPackageInfo(overlayPackage, 0 /* flags */) != null;
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
// Not found, just return unavailable
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void selectRadioButtonInGroup(String preferenceKey, PreferenceScreen screen) {
|
static boolean isOverlayPackageAvailable(Context context, String overlayPackage) {
|
||||||
if (screen == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (String key : RADIO_BUTTONS_IN_GROUP) {
|
|
||||||
((RadioButtonPreference) screen.findPreference(key)).setChecked(
|
|
||||||
TextUtils.equals(key, preferenceKey));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables the specified overlay package.
|
|
||||||
*/
|
|
||||||
static void setNavBarInteractionMode(IOverlayManager overlayManager, String overlayPackage) {
|
|
||||||
try {
|
try {
|
||||||
overlayManager.setEnabledExclusiveInCategory(overlayPackage, USER_CURRENT);
|
return context.getPackageManager().getPackageInfo(overlayPackage, 0) != null;
|
||||||
} catch (RemoteException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
// Not found, just return unavailable
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,55 +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.gestures;
|
|
||||||
|
|
||||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON_OVERLAY;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.om.IOverlayManager;
|
|
||||||
import android.os.ServiceManager;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
|
|
||||||
import com.android.settings.widget.RadioButtonPreference;
|
|
||||||
|
|
||||||
public class SystemNavigationSwipeUpPreferenceController extends
|
|
||||||
SystemNavigationPreferenceController {
|
|
||||||
static final String PREF_KEY_SWIPE_UP = "gesture_swipe_up";
|
|
||||||
|
|
||||||
public SystemNavigationSwipeUpPreferenceController(Context context, String key) {
|
|
||||||
this(context, IOverlayManager.Stub.asInterface(ServiceManager.getService(
|
|
||||||
Context.OVERLAY_SERVICE)), key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
public SystemNavigationSwipeUpPreferenceController(Context context,
|
|
||||||
IOverlayManager overlayManager, String key) {
|
|
||||||
super(context, overlayManager, key, NAV_BAR_MODE_2BUTTON_OVERLAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRadioButtonClicked(RadioButtonPreference preference) {
|
|
||||||
setNavBarInteractionMode(mOverlayManager, NAV_BAR_MODE_2BUTTON_OVERLAY);
|
|
||||||
selectRadioButtonInGroup(PREF_KEY_SWIPE_UP, mPreferenceScreen);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isChecked() {
|
|
||||||
return isSwipeUpEnabled(mContext);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,199 +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.gestures;
|
|
||||||
|
|
||||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON;
|
|
||||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
|
|
||||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
|
|
||||||
|
|
||||||
import static com.android.settings.gestures.SystemNavigationEdgeToEdgePreferenceController.PREF_KEY_EDGE_TO_EDGE;
|
|
||||||
import static com.android.settings.gestures.SystemNavigationLegacyPreferenceController.PREF_KEY_LEGACY;
|
|
||||||
import static com.android.settings.gestures.SystemNavigationSwipeUpPreferenceController.PREF_KEY_SWIPE_UP;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.times;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.om.IOverlayManager;
|
|
||||||
import android.content.pm.ApplicationInfo;
|
|
||||||
import android.content.pm.ResolveInfo;
|
|
||||||
import android.content.pm.ServiceInfo;
|
|
||||||
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.internal.R;
|
|
||||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
|
||||||
import com.android.settings.widget.RadioButtonPreference;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
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 org.robolectric.Shadows;
|
|
||||||
import org.robolectric.annotation.Config;
|
|
||||||
import org.robolectric.shadows.ShadowPackageManager;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
@Config(shadows = SettingsShadowResources.class)
|
|
||||||
public class SystemNavigationEdgeToEdgePreferenceControllerTest {
|
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private ShadowPackageManager mPackageManager;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private IOverlayManager mOverlayManager;
|
|
||||||
|
|
||||||
private SystemNavigationEdgeToEdgePreferenceController mController;
|
|
||||||
|
|
||||||
private static final String ACTION_QUICKSTEP = "android.intent.action.QUICKSTEP_SERVICE";
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
|
|
||||||
SettingsShadowResources.overrideResource(R.bool.config_swipe_up_gesture_setting_available,
|
|
||||||
true);
|
|
||||||
|
|
||||||
mContext = RuntimeEnvironment.application;
|
|
||||||
mPackageManager = Shadows.shadowOf(mContext.getPackageManager());
|
|
||||||
|
|
||||||
mController = new SystemNavigationEdgeToEdgePreferenceController(mContext, mOverlayManager,
|
|
||||||
PREF_KEY_EDGE_TO_EDGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
SettingsShadowResources.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsGestureAvailable_matchingServiceExists_shouldReturnTrue() {
|
|
||||||
final ComponentName recentsComponentName = ComponentName.unflattenFromString(
|
|
||||||
mContext.getString(com.android.internal.R.string.config_recentsComponentName));
|
|
||||||
final Intent quickStepIntent = new Intent(ACTION_QUICKSTEP)
|
|
||||||
.setPackage(recentsComponentName.getPackageName());
|
|
||||||
final ResolveInfo info = new ResolveInfo();
|
|
||||||
info.serviceInfo = new ServiceInfo();
|
|
||||||
info.resolvePackageName = recentsComponentName.getPackageName();
|
|
||||||
info.serviceInfo.packageName = info.resolvePackageName;
|
|
||||||
info.serviceInfo.name = recentsComponentName.getClassName();
|
|
||||||
info.serviceInfo.applicationInfo = new ApplicationInfo();
|
|
||||||
info.serviceInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
|
|
||||||
mPackageManager.addResolveInfoForIntent(quickStepIntent, info);
|
|
||||||
|
|
||||||
assertThat(SystemNavigationEdgeToEdgePreferenceController.isGestureAvailable(mContext))
|
|
||||||
.isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsGestureAvailable_overlayDisabled_matchingServiceExists_shouldReturnFalse() {
|
|
||||||
SettingsShadowResources.overrideResource(R.bool.config_swipe_up_gesture_setting_available,
|
|
||||||
false);
|
|
||||||
|
|
||||||
final ComponentName recentsComponentName = ComponentName.unflattenFromString(
|
|
||||||
mContext.getString(com.android.internal.R.string.config_recentsComponentName));
|
|
||||||
final Intent quickStepIntent = new Intent(ACTION_QUICKSTEP)
|
|
||||||
.setPackage(recentsComponentName.getPackageName());
|
|
||||||
mPackageManager.addResolveInfoForIntent(quickStepIntent, new ResolveInfo());
|
|
||||||
|
|
||||||
assertThat(SystemNavigationEdgeToEdgePreferenceController.isGestureAvailable(mContext))
|
|
||||||
.isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsGestureAvailable_noMatchingServiceExists_shouldReturnFalse() {
|
|
||||||
assertThat(SystemNavigationEdgeToEdgePreferenceController.isGestureAvailable(mContext))
|
|
||||||
.isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsGestureAvailable_noOverlayPackage_shouldReturnFalse() {
|
|
||||||
assertThat(SystemNavigationEdgeToEdgePreferenceController.isGestureAvailable(mContext,
|
|
||||||
"com.package.fake")).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsChecked_defaultIsEdgeToEdge_shouldReturnTrue() {
|
|
||||||
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
|
||||||
NAV_BAR_MODE_GESTURAL);
|
|
||||||
assertThat(mController.isChecked()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsChecked_defaultIsLegacy_shouldReturnFalse() {
|
|
||||||
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
|
||||||
NAV_BAR_MODE_3BUTTON);
|
|
||||||
assertThat(mController.isChecked()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsChecked_defaultIsSwipeUp_shouldReturnFalse() {
|
|
||||||
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
|
||||||
NAV_BAR_MODE_2BUTTON);
|
|
||||||
assertThat(mController.isChecked()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsChecked_radioButtonClicked_shouldReturnTrue() {
|
|
||||||
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
|
||||||
NAV_BAR_MODE_GESTURAL);
|
|
||||||
// Set the setting to be enabled.
|
|
||||||
mController.onRadioButtonClicked(null);
|
|
||||||
assertThat(mController.isChecked()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOnRadioButtonClicked_setsCorrectRadioButtonChecked() {
|
|
||||||
RadioButtonPreference radioLegacy = mock(RadioButtonPreference.class);
|
|
||||||
RadioButtonPreference radioSwipeUp = mock(RadioButtonPreference.class);
|
|
||||||
RadioButtonPreference radioEdgeToEdge = mock(RadioButtonPreference.class);
|
|
||||||
PreferenceScreen screen = mock(PreferenceScreen.class);
|
|
||||||
|
|
||||||
when(screen.findPreference(PREF_KEY_LEGACY)).thenReturn(radioLegacy);
|
|
||||||
when(screen.findPreference(PREF_KEY_SWIPE_UP)).thenReturn(radioSwipeUp);
|
|
||||||
when(screen.findPreference(PREF_KEY_EDGE_TO_EDGE)).thenReturn(radioEdgeToEdge);
|
|
||||||
|
|
||||||
mController.displayPreference(screen);
|
|
||||||
mController.onRadioButtonClicked(radioEdgeToEdge);
|
|
||||||
|
|
||||||
verify(radioLegacy, times(1)).setChecked(false);
|
|
||||||
verify(radioSwipeUp, times(1)).setChecked(false);
|
|
||||||
verify(radioEdgeToEdge, times(1)).setChecked(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isSliceable_returnsFalse() {
|
|
||||||
assertThat(mController.isSliceable()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isSliceableIncorrectKey_returnsFalse() {
|
|
||||||
final SystemNavigationEdgeToEdgePreferenceController controller =
|
|
||||||
new SystemNavigationEdgeToEdgePreferenceController(mContext, "bad_key");
|
|
||||||
assertThat(controller.isSliceable()).isFalse();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
* 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.gestures;
|
||||||
|
|
||||||
|
import static android.os.UserHandle.USER_CURRENT;
|
||||||
|
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON;
|
||||||
|
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON_OVERLAY;
|
||||||
|
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
|
||||||
|
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON_OVERLAY;
|
||||||
|
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
|
||||||
|
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY;
|
||||||
|
|
||||||
|
import static com.android.settings.gestures.SystemNavigationGestureSettings.KEY_SYSTEM_NAV_2BUTTONS;
|
||||||
|
import static com.android.settings.gestures.SystemNavigationGestureSettings.KEY_SYSTEM_NAV_3BUTTONS;
|
||||||
|
import static com.android.settings.gestures.SystemNavigationGestureSettings.KEY_SYSTEM_NAV_GESTURAL;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.om.IOverlayManager;
|
||||||
|
import android.os.ServiceManager;
|
||||||
|
import android.provider.SearchIndexableResource;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.android.internal.R;
|
||||||
|
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(shadows = SettingsShadowResources.class)
|
||||||
|
public class SystemNavigationGestureSettingsTest {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
private IOverlayManager mOverlayManager;
|
||||||
|
|
||||||
|
private SystemNavigationGestureSettings mSettings;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
|
mOverlayManager = mock(IOverlayManager.class);
|
||||||
|
|
||||||
|
mSettings = new SystemNavigationGestureSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSearchIndexProvider_shouldIndexResource() {
|
||||||
|
final List<SearchIndexableResource> indexRes =
|
||||||
|
SystemNavigationGestureSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
|
||||||
|
RuntimeEnvironment.application, true /* enabled */);
|
||||||
|
|
||||||
|
assertThat(indexRes).isNotNull();
|
||||||
|
assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetCurrentSystemNavigationMode() {
|
||||||
|
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
||||||
|
NAV_BAR_MODE_GESTURAL);
|
||||||
|
assertThat(TextUtils.equals(mSettings.getCurrentSystemNavigationMode(mContext),
|
||||||
|
KEY_SYSTEM_NAV_GESTURAL)).isTrue();
|
||||||
|
|
||||||
|
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
||||||
|
NAV_BAR_MODE_3BUTTON);
|
||||||
|
assertThat(TextUtils.equals(mSettings.getCurrentSystemNavigationMode(mContext),
|
||||||
|
KEY_SYSTEM_NAV_3BUTTONS)).isTrue();
|
||||||
|
|
||||||
|
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
||||||
|
NAV_BAR_MODE_2BUTTON);
|
||||||
|
assertThat(TextUtils.equals(mSettings.getCurrentSystemNavigationMode(mContext),
|
||||||
|
KEY_SYSTEM_NAV_2BUTTONS)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetCurrentSystemNavigationMode() throws Exception {
|
||||||
|
mSettings.setCurrentSystemNavigationMode(mOverlayManager, KEY_SYSTEM_NAV_GESTURAL);
|
||||||
|
verify(mOverlayManager, times(1)).setEnabledExclusiveInCategory(
|
||||||
|
NAV_BAR_MODE_GESTURAL_OVERLAY, USER_CURRENT);
|
||||||
|
|
||||||
|
mSettings.setCurrentSystemNavigationMode(mOverlayManager, KEY_SYSTEM_NAV_2BUTTONS);
|
||||||
|
verify(mOverlayManager, times(1)).setEnabledExclusiveInCategory(
|
||||||
|
NAV_BAR_MODE_2BUTTON_OVERLAY, USER_CURRENT);
|
||||||
|
|
||||||
|
mSettings.setCurrentSystemNavigationMode(mOverlayManager, KEY_SYSTEM_NAV_3BUTTONS);
|
||||||
|
verify(mOverlayManager, times(1)).setEnabledExclusiveInCategory(
|
||||||
|
NAV_BAR_MODE_3BUTTON_OVERLAY, USER_CURRENT);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,201 +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.gestures;
|
|
||||||
|
|
||||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON;
|
|
||||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
|
|
||||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
|
|
||||||
|
|
||||||
import static com.android.settings.gestures.SystemNavigationEdgeToEdgePreferenceController.PREF_KEY_EDGE_TO_EDGE;
|
|
||||||
import static com.android.settings.gestures.SystemNavigationLegacyPreferenceController.PREF_KEY_LEGACY;
|
|
||||||
import static com.android.settings.gestures.SystemNavigationSwipeUpPreferenceController.PREF_KEY_SWIPE_UP;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.times;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.om.IOverlayManager;
|
|
||||||
import android.content.pm.ApplicationInfo;
|
|
||||||
import android.content.pm.ResolveInfo;
|
|
||||||
import android.content.pm.ServiceInfo;
|
|
||||||
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.internal.R;
|
|
||||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
|
||||||
import com.android.settings.widget.RadioButtonPreference;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
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 org.robolectric.Shadows;
|
|
||||||
import org.robolectric.annotation.Config;
|
|
||||||
import org.robolectric.shadows.ShadowPackageManager;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
@Config(shadows = SettingsShadowResources.class)
|
|
||||||
public class SystemNavigationLegacyPreferenceControllerTest {
|
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private ShadowPackageManager mPackageManager;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private IOverlayManager mOverlayManager;
|
|
||||||
|
|
||||||
private SystemNavigationLegacyPreferenceController mController;
|
|
||||||
|
|
||||||
private static final String ACTION_QUICKSTEP = "android.intent.action.QUICKSTEP_SERVICE";
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
|
|
||||||
SettingsShadowResources.overrideResource(R.bool.config_swipe_up_gesture_setting_available,
|
|
||||||
true);
|
|
||||||
|
|
||||||
mContext = RuntimeEnvironment.application;
|
|
||||||
mPackageManager = Shadows.shadowOf(mContext.getPackageManager());
|
|
||||||
|
|
||||||
mController = new SystemNavigationLegacyPreferenceController(mContext, mOverlayManager,
|
|
||||||
PREF_KEY_LEGACY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
SettingsShadowResources.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsGestureAvailable_matchingServiceExists_shouldReturnTrue() {
|
|
||||||
final ComponentName recentsComponentName = ComponentName.unflattenFromString(
|
|
||||||
mContext.getString(com.android.internal.R.string.config_recentsComponentName));
|
|
||||||
final Intent quickStepIntent = new Intent(ACTION_QUICKSTEP)
|
|
||||||
.setPackage(recentsComponentName.getPackageName());
|
|
||||||
final ResolveInfo info = new ResolveInfo();
|
|
||||||
info.serviceInfo = new ServiceInfo();
|
|
||||||
info.resolvePackageName = recentsComponentName.getPackageName();
|
|
||||||
info.serviceInfo.packageName = info.resolvePackageName;
|
|
||||||
info.serviceInfo.name = recentsComponentName.getClassName();
|
|
||||||
info.serviceInfo.applicationInfo = new ApplicationInfo();
|
|
||||||
info.serviceInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
|
|
||||||
mPackageManager.addResolveInfoForIntent(quickStepIntent, info);
|
|
||||||
|
|
||||||
assertThat(SystemNavigationLegacyPreferenceController.isGestureAvailable(mContext))
|
|
||||||
.isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsGestureAvailable_overlayDisabled_matchingServiceExists_shouldReturnFalse() {
|
|
||||||
SettingsShadowResources.overrideResource(R.bool.config_swipe_up_gesture_setting_available,
|
|
||||||
false);
|
|
||||||
|
|
||||||
final ComponentName recentsComponentName = ComponentName.unflattenFromString(
|
|
||||||
mContext.getString(com.android.internal.R.string.config_recentsComponentName));
|
|
||||||
final Intent quickStepIntent = new Intent(ACTION_QUICKSTEP)
|
|
||||||
.setPackage(recentsComponentName.getPackageName());
|
|
||||||
mPackageManager.addResolveInfoForIntent(quickStepIntent, new ResolveInfo());
|
|
||||||
|
|
||||||
assertThat(
|
|
||||||
SystemNavigationLegacyPreferenceController.isGestureAvailable(mContext)).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsGestureAvailable_noMatchingServiceExists_shouldReturnFalse() {
|
|
||||||
assertThat(
|
|
||||||
SystemNavigationLegacyPreferenceController.isGestureAvailable(mContext)).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsGestureAvailable_noOverlayPackage_shouldReturnFalse() {
|
|
||||||
assertThat(SystemNavigationLegacyPreferenceController.isGestureAvailable(mContext,
|
|
||||||
"com.package.fake")).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsChecked_defaultIsLegacy_shouldReturnTrue() {
|
|
||||||
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
|
||||||
NAV_BAR_MODE_3BUTTON);
|
|
||||||
assertThat(mController.isChecked()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsChecked_defaultIsSwipeUp_shouldReturnFalse() {
|
|
||||||
// Turn on the Swipe Up mode (2-buttons)
|
|
||||||
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
|
||||||
NAV_BAR_MODE_2BUTTON);
|
|
||||||
assertThat(mController.isChecked()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsChecked_defaultIsEdgeToEdge_shouldReturnFalse() {
|
|
||||||
// Turn on the Edge to Edge
|
|
||||||
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
|
||||||
NAV_BAR_MODE_GESTURAL);
|
|
||||||
assertThat(mController.isChecked()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsChecked_radioButtonClicked_shouldReturnTrue() {
|
|
||||||
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
|
||||||
NAV_BAR_MODE_3BUTTON);
|
|
||||||
// Set the setting to be enabled.
|
|
||||||
mController.onRadioButtonClicked(null);
|
|
||||||
assertThat(mController.isChecked()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOnRadioButtonClicked_setsCorrectRadioButtonChecked() {
|
|
||||||
RadioButtonPreference radioLegacy = mock(RadioButtonPreference.class);
|
|
||||||
RadioButtonPreference radioSwipeUp = mock(RadioButtonPreference.class);
|
|
||||||
RadioButtonPreference radioEdgeToEdge = mock(RadioButtonPreference.class);
|
|
||||||
PreferenceScreen screen = mock(PreferenceScreen.class);
|
|
||||||
|
|
||||||
when(screen.findPreference(PREF_KEY_LEGACY)).thenReturn(radioLegacy);
|
|
||||||
when(screen.findPreference(PREF_KEY_SWIPE_UP)).thenReturn(radioSwipeUp);
|
|
||||||
when(screen.findPreference(PREF_KEY_EDGE_TO_EDGE)).thenReturn(radioEdgeToEdge);
|
|
||||||
|
|
||||||
mController.displayPreference(screen);
|
|
||||||
mController.onRadioButtonClicked(radioLegacy);
|
|
||||||
|
|
||||||
verify(radioLegacy, times(1)).setChecked(true);
|
|
||||||
verify(radioSwipeUp, times(1)).setChecked(false);
|
|
||||||
verify(radioEdgeToEdge, times(1)).setChecked(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isSliceable_returnsFalse() {
|
|
||||||
assertThat(mController.isSliceable()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isSliceableIncorrectKey_returnsFalse() {
|
|
||||||
final SystemNavigationLegacyPreferenceController controller =
|
|
||||||
new SystemNavigationLegacyPreferenceController(mContext, "bad_key");
|
|
||||||
assertThat(controller.isSliceable()).isFalse();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -11,7 +11,7 @@
|
|||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.settings.gestures;
|
package com.android.settings.gestures;
|
||||||
@@ -20,36 +20,25 @@ import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON;
|
|||||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
|
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
|
||||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
|
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
|
||||||
|
|
||||||
import static com.android.settings.gestures.SystemNavigationEdgeToEdgePreferenceController.PREF_KEY_EDGE_TO_EDGE;
|
import static com.android.settings.gestures.SystemNavigationPreferenceController.PREF_KEY_SYSTEM_NAVIGATION;
|
||||||
import static com.android.settings.gestures.SystemNavigationLegacyPreferenceController.PREF_KEY_LEGACY;
|
|
||||||
import static com.android.settings.gestures.SystemNavigationSwipeUpPreferenceController.PREF_KEY_SWIPE_UP;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.times;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.om.IOverlayManager;
|
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.content.pm.ServiceInfo;
|
import android.content.pm.ServiceInfo;
|
||||||
|
import android.text.TextUtils;
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.internal.R;
|
import com.android.internal.R;
|
||||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||||
import com.android.settings.widget.RadioButtonPreference;
|
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
@@ -59,15 +48,12 @@ import org.robolectric.shadows.ShadowPackageManager;
|
|||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(shadows = SettingsShadowResources.class)
|
@Config(shadows = SettingsShadowResources.class)
|
||||||
public class SystemNavigationSwipeUpPreferenceControllerTest {
|
public class SystemNavigationPreferenceControllerTest {
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private ShadowPackageManager mPackageManager;
|
private ShadowPackageManager mPackageManager;
|
||||||
|
|
||||||
@Mock
|
private SystemNavigationPreferenceController mController;
|
||||||
private IOverlayManager mOverlayManager;
|
|
||||||
|
|
||||||
private SystemNavigationSwipeUpPreferenceController mController;
|
|
||||||
|
|
||||||
private static final String ACTION_QUICKSTEP = "android.intent.action.QUICKSTEP_SERVICE";
|
private static final String ACTION_QUICKSTEP = "android.intent.action.QUICKSTEP_SERVICE";
|
||||||
|
|
||||||
@@ -81,8 +67,8 @@ public class SystemNavigationSwipeUpPreferenceControllerTest {
|
|||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
mPackageManager = Shadows.shadowOf(mContext.getPackageManager());
|
mPackageManager = Shadows.shadowOf(mContext.getPackageManager());
|
||||||
|
|
||||||
mController = new SystemNavigationSwipeUpPreferenceController(mContext, mOverlayManager,
|
mController = new SystemNavigationPreferenceController(mContext,
|
||||||
PREF_KEY_SWIPE_UP);
|
PREF_KEY_SYSTEM_NAVIGATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@@ -105,8 +91,7 @@ public class SystemNavigationSwipeUpPreferenceControllerTest {
|
|||||||
info.serviceInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
|
info.serviceInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
|
||||||
mPackageManager.addResolveInfoForIntent(quickStepIntent, info);
|
mPackageManager.addResolveInfoForIntent(quickStepIntent, info);
|
||||||
|
|
||||||
assertThat(SystemNavigationSwipeUpPreferenceController.isGestureAvailable(mContext))
|
assertThat(SystemNavigationPreferenceController.isGestureAvailable(mContext)).isTrue();
|
||||||
.isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -120,80 +105,65 @@ public class SystemNavigationSwipeUpPreferenceControllerTest {
|
|||||||
.setPackage(recentsComponentName.getPackageName());
|
.setPackage(recentsComponentName.getPackageName());
|
||||||
mPackageManager.addResolveInfoForIntent(quickStepIntent, new ResolveInfo());
|
mPackageManager.addResolveInfoForIntent(quickStepIntent, new ResolveInfo());
|
||||||
|
|
||||||
assertThat(SystemNavigationSwipeUpPreferenceController.isGestureAvailable(mContext))
|
assertThat(SystemNavigationPreferenceController.isGestureAvailable(mContext)).isFalse();
|
||||||
.isFalse();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsGestureAvailable_noMatchingServiceExists_shouldReturnFalse() {
|
public void testIsGestureAvailable_noMatchingServiceExists_shouldReturnFalse() {
|
||||||
assertThat(SystemNavigationSwipeUpPreferenceController.isGestureAvailable(mContext))
|
assertThat(SystemNavigationPreferenceController.isGestureAvailable(mContext)).isFalse();
|
||||||
.isFalse();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsGestureAvailable_noOverlayPackage_shouldReturnFalse() {
|
public void testIsOverlayPackageAvailable_noOverlayPackage_shouldReturnFalse() {
|
||||||
assertThat(SystemNavigationSwipeUpPreferenceController.isGestureAvailable(mContext,
|
assertThat(SystemNavigationPreferenceController.isOverlayPackageAvailable(mContext,
|
||||||
"com.package.fake")).isFalse();
|
"com.package.fake")).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsChecked_defaultIsSwipeUp_shouldReturnTrue() {
|
public void testIsSwipeUpEnabled() {
|
||||||
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
||||||
NAV_BAR_MODE_2BUTTON);
|
NAV_BAR_MODE_2BUTTON);
|
||||||
assertThat(mController.isChecked()).isTrue();
|
assertThat(SystemNavigationPreferenceController.isSwipeUpEnabled(mContext)).isTrue();
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsChecked_defaultIsLegacy_shouldReturnFalse() {
|
|
||||||
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
||||||
NAV_BAR_MODE_3BUTTON);
|
NAV_BAR_MODE_3BUTTON);
|
||||||
assertThat(mController.isChecked()).isFalse();
|
assertThat(SystemNavigationPreferenceController.isSwipeUpEnabled(mContext)).isFalse();
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsChecked_defaultIsEdgeToEdge_shouldReturnFalse() {
|
|
||||||
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
||||||
NAV_BAR_MODE_GESTURAL);
|
NAV_BAR_MODE_GESTURAL);
|
||||||
assertThat(mController.isChecked()).isFalse();
|
assertThat(SystemNavigationPreferenceController.isSwipeUpEnabled(mContext)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsChecked_radioButtonClicked_shouldReturnTrue() {
|
public void testIsEdgeToEdgeEnabled() {
|
||||||
|
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
||||||
|
NAV_BAR_MODE_GESTURAL);
|
||||||
|
assertThat(SystemNavigationPreferenceController.isEdgeToEdgeEnabled(mContext)).isTrue();
|
||||||
|
|
||||||
|
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
||||||
|
NAV_BAR_MODE_3BUTTON);
|
||||||
|
assertThat(SystemNavigationPreferenceController.isEdgeToEdgeEnabled(mContext)).isFalse();
|
||||||
|
|
||||||
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
||||||
NAV_BAR_MODE_2BUTTON);
|
NAV_BAR_MODE_2BUTTON);
|
||||||
// Set the setting to be enabled.
|
assertThat(SystemNavigationPreferenceController.isEdgeToEdgeEnabled(mContext)).isFalse();
|
||||||
mController.onRadioButtonClicked(null);
|
|
||||||
assertThat(mController.isChecked()).isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnRadioButtonClicked_setsCorrectRadioButtonChecked() {
|
public void testGetSummary() {
|
||||||
RadioButtonPreference radioLegacy = mock(RadioButtonPreference.class);
|
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
||||||
RadioButtonPreference radioSwipeUp = mock(RadioButtonPreference.class);
|
NAV_BAR_MODE_GESTURAL);
|
||||||
RadioButtonPreference radioEdgeToEdge = mock(RadioButtonPreference.class);
|
assertThat(TextUtils.equals(mController.getSummary(), mContext.getText(
|
||||||
PreferenceScreen screen = mock(PreferenceScreen.class);
|
com.android.settings.R.string.edge_to_edge_navigation_title))).isTrue();
|
||||||
|
|
||||||
when(screen.findPreference(PREF_KEY_LEGACY)).thenReturn(radioLegacy);
|
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
||||||
when(screen.findPreference(PREF_KEY_SWIPE_UP)).thenReturn(radioSwipeUp);
|
NAV_BAR_MODE_3BUTTON);
|
||||||
when(screen.findPreference(PREF_KEY_EDGE_TO_EDGE)).thenReturn(radioEdgeToEdge);
|
assertThat(TextUtils.equals(mController.getSummary(),
|
||||||
|
mContext.getText(com.android.settings.R.string.legacy_navigation_title))).isTrue();
|
||||||
|
|
||||||
mController.displayPreference(screen);
|
SettingsShadowResources.overrideResource(R.integer.config_navBarInteractionMode,
|
||||||
mController.onRadioButtonClicked(radioSwipeUp);
|
NAV_BAR_MODE_2BUTTON);
|
||||||
|
assertThat(TextUtils.equals(mController.getSummary(), mContext.getText(
|
||||||
verify(radioLegacy, times(1)).setChecked(false);
|
com.android.settings.R.string.swipe_up_to_switch_apps_title))).isTrue();
|
||||||
verify(radioSwipeUp, times(1)).setChecked(true);
|
|
||||||
verify(radioEdgeToEdge, times(1)).setChecked(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isSliceable_returnsFalse() {
|
|
||||||
assertThat(mController.isSliceable()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isSliceableIncorrectKey_returnsFalse() {
|
|
||||||
final SystemNavigationSwipeUpPreferenceController controller =
|
|
||||||
new SystemNavigationSwipeUpPreferenceController(mContext, "bad_key");
|
|
||||||
assertThat(controller.isSliceable()).isFalse();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user