Use overlay settings for Swipe Up gesture default
Implements the following logic: if config_swipe_up_gesture_setting_available is false, always use the default value in config_swipe_up_gesture_default and ignore Settings.Secure if config_swipe_up_gesture_setting_available is true, use config_swipe_up_gesture_default as the default value for Settings.Secure, and respect Settings.Secure if user makes any changes. Bug: 78641268 Test: Manual test Change-Id: I586083b6655ccb3c94f08a911ed0de80f4738d62
This commit is contained in:
parent
0b1174ddbe
commit
25a8e6f063
|
@ -21,12 +21,10 @@ import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_HIDE_B
|
||||||
import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_SHOW_OVERVIEW_BUTTON;
|
import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_SHOW_OVERVIEW_BUTTON;
|
||||||
import static com.android.systemui.shared.system.SettingsCompat.SWIPE_UP_SETTING_NAME;
|
import static com.android.systemui.shared.system.SettingsCompat.SWIPE_UP_SETTING_NAME;
|
||||||
|
|
||||||
import static com.android.launcher3.Utilities.getSystemProperty;
|
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
@ -58,6 +56,10 @@ public class OverviewInteractionState {
|
||||||
private static final String TAG = "OverviewFlags";
|
private static final String TAG = "OverviewFlags";
|
||||||
|
|
||||||
private static final String HAS_ENABLED_QUICKSTEP_ONCE = "launcher.has_enabled_quickstep_once";
|
private static final String HAS_ENABLED_QUICKSTEP_ONCE = "launcher.has_enabled_quickstep_once";
|
||||||
|
private static final String SWIPE_UP_SETTING_AVAILABLE_RES_NAME =
|
||||||
|
"config_swipe_up_gesture_setting_available";
|
||||||
|
private static final String SWIPE_UP_ENABLED_DEFAULT_RES_NAME =
|
||||||
|
"config_swipe_up_gesture_default";
|
||||||
|
|
||||||
// We do not need any synchronization for this variable as its only written on UI thread.
|
// We do not need any synchronization for this variable as its only written on UI thread.
|
||||||
private static OverviewInteractionState INSTANCE;
|
private static OverviewInteractionState INSTANCE;
|
||||||
|
@ -100,13 +102,13 @@ public class OverviewInteractionState {
|
||||||
mUiHandler = new Handler(this::handleUiMessage);
|
mUiHandler = new Handler(this::handleUiMessage);
|
||||||
mBgHandler = new Handler(UiThreadHelper.getBackgroundLooper(), this::handleBgMessage);
|
mBgHandler = new Handler(UiThreadHelper.getBackgroundLooper(), this::handleBgMessage);
|
||||||
|
|
||||||
if (shouldIgnoreSwipeUpEnabledSettings()) {
|
if (getSystemBooleanRes(SWIPE_UP_SETTING_AVAILABLE_RES_NAME)) {
|
||||||
mSwipeUpSettingObserver = null;
|
|
||||||
mSwipeUpEnabled = true;
|
|
||||||
} else {
|
|
||||||
mSwipeUpSettingObserver = new SwipeUpGestureEnabledSettingObserver(mUiHandler,
|
mSwipeUpSettingObserver = new SwipeUpGestureEnabledSettingObserver(mUiHandler,
|
||||||
context.getContentResolver());
|
context.getContentResolver());
|
||||||
mSwipeUpSettingObserver.register();
|
mSwipeUpSettingObserver.register();
|
||||||
|
} else {
|
||||||
|
mSwipeUpSettingObserver = null;
|
||||||
|
mSwipeUpEnabled = getSystemBooleanRes(SWIPE_UP_ENABLED_DEFAULT_RES_NAME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,11 +178,13 @@ public class OverviewInteractionState {
|
||||||
private class SwipeUpGestureEnabledSettingObserver extends ContentObserver {
|
private class SwipeUpGestureEnabledSettingObserver extends ContentObserver {
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
private ContentResolver mResolver;
|
private ContentResolver mResolver;
|
||||||
|
private final int defaultValue;
|
||||||
|
|
||||||
SwipeUpGestureEnabledSettingObserver(Handler handler, ContentResolver resolver) {
|
SwipeUpGestureEnabledSettingObserver(Handler handler, ContentResolver resolver) {
|
||||||
super(handler);
|
super(handler);
|
||||||
mHandler = handler;
|
mHandler = handler;
|
||||||
mResolver = resolver;
|
mResolver = resolver;
|
||||||
|
defaultValue = getSystemBooleanRes(SWIPE_UP_ENABLED_DEFAULT_RES_NAME) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register() {
|
public void register() {
|
||||||
|
@ -198,20 +202,18 @@ public class OverviewInteractionState {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean getValue() {
|
private boolean getValue() {
|
||||||
return Settings.Secure.getInt(mResolver, SWIPE_UP_SETTING_NAME, 0) == 1;
|
return Settings.Secure.getInt(mResolver, SWIPE_UP_SETTING_NAME, defaultValue) == 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldIgnoreSwipeUpEnabledSettings() {
|
private boolean getSystemBooleanRes(String resName) {
|
||||||
int deviceApiLevel = Build.VERSION.SDK_INT;
|
Resources res = Resources.getSystem();
|
||||||
|
int resId = res.getIdentifier(resName, "bool", "android");
|
||||||
|
|
||||||
// Note: on factory ROM devices, this first_api_level property is intentionally not set.
|
if (resId != 0) {
|
||||||
// deviceApiLevel is used in these case.
|
return res.getBoolean(resId);
|
||||||
String sdkInt = getSystemProperty("ro.product.first_api_level",
|
} else {
|
||||||
Integer.toString(deviceApiLevel));
|
Log.e(TAG, "Failed to get system resource ID. Incompatible framework version?");
|
||||||
try {
|
|
||||||
return Integer.parseInt(sdkInt) >= Build.VERSION_CODES.P;
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue