Removing code duplication for getting swipe-up setting
This is between Tapl and Launcher
Bug: 110103162
Test: TaplTests suite
Change-Id: I5b458438834204ca257f45c707577b4d2793fb4e
diff --git a/quickstep/src/com/android/quickstep/OverviewInteractionState.java b/quickstep/src/com/android/quickstep/OverviewInteractionState.java
index 922a7ff..aa318be 100644
--- a/quickstep/src/com/android/quickstep/OverviewInteractionState.java
+++ b/quickstep/src/com/android/quickstep/OverviewInteractionState.java
@@ -22,7 +22,6 @@
import android.content.ContentResolver;
import android.content.Context;
-import android.content.res.Resources;
import android.database.ContentObserver;
import android.os.Handler;
import android.os.Looper;
@@ -54,10 +53,6 @@
private static final String TAG = "OverviewFlags";
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.
private static OverviewInteractionState INSTANCE;
@@ -104,13 +99,13 @@
mUiHandler = new Handler(this::handleUiMessage);
mBgHandler = new Handler(UiThreadHelper.getBackgroundLooper(), this::handleBgMessage);
- if (getSystemBooleanRes(SWIPE_UP_SETTING_AVAILABLE_RES_NAME)) {
+ if (SwipeUpSetting.isSwipeUpSettingAvailable()) {
mSwipeUpSettingObserver = new SwipeUpGestureEnabledSettingObserver(mUiHandler,
context.getContentResolver());
mSwipeUpSettingObserver.register();
} else {
mSwipeUpSettingObserver = null;
- mSwipeUpEnabled = getSystemBooleanRes(SWIPE_UP_ENABLED_DEFAULT_RES_NAME);
+ mSwipeUpEnabled = SwipeUpSetting.isSwipeUpEnabledDefaultValue();
}
}
@@ -206,7 +201,7 @@
super(handler);
mHandler = handler;
mResolver = resolver;
- defaultValue = getSystemBooleanRes(SWIPE_UP_ENABLED_DEFAULT_RES_NAME) ? 1 : 0;
+ defaultValue = SwipeUpSetting.isSwipeUpEnabledDefaultValue() ? 1 : 0;
}
public void register() {
@@ -228,18 +223,6 @@
}
}
- private boolean getSystemBooleanRes(String resName) {
- Resources res = Resources.getSystem();
- int resId = res.getIdentifier(resName, "bool", "android");
-
- if (resId != 0) {
- return res.getBoolean(resId);
- } else {
- Log.e(TAG, "Failed to get system resource ID. Incompatible framework version?");
- return false;
- }
- }
-
private void resetHomeBounceSeenOnQuickstepEnabledFirstTime() {
if (mSwipeUpEnabled && !Utilities.getPrefs(mContext).getBoolean(
HAS_ENABLED_QUICKSTEP_ONCE, true)) {
diff --git a/quickstep/src/com/android/quickstep/SwipeUpSetting.java b/quickstep/src/com/android/quickstep/SwipeUpSetting.java
new file mode 100644
index 0000000..0f91f97
--- /dev/null
+++ b/quickstep/src/com/android/quickstep/SwipeUpSetting.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2018 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.quickstep;
+
+import android.content.res.Resources;
+import android.util.Log;
+
+public final class SwipeUpSetting {
+ private static final String TAG = "SwipeUpSetting";
+
+ 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";
+
+ private static boolean getSystemBooleanRes(String resName) {
+ Resources res = Resources.getSystem();
+ int resId = res.getIdentifier(resName, "bool", "android");
+
+ if (resId != 0) {
+ return res.getBoolean(resId);
+ } else {
+ Log.e(TAG, "Failed to get system resource ID. Incompatible framework version?");
+ return false;
+ }
+ }
+
+ public static boolean isSwipeUpSettingAvailable() {
+ return getSystemBooleanRes(SWIPE_UP_SETTING_AVAILABLE_RES_NAME);
+ }
+
+ public static boolean isSwipeUpEnabledDefaultValue() {
+ return getSystemBooleanRes(SWIPE_UP_ENABLED_DEFAULT_RES_NAME);
+ }
+}
diff --git a/tests/Android.mk b/tests/Android.mk
index c8e554d..c7a222a 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -37,7 +37,8 @@
include $(CLEAR_VARS)
LOCAL_STATIC_JAVA_LIBRARIES := android-support-test ub-uiautomator
-LOCAL_SRC_FILES := $(call all-java-files-under, tapl)
+LOCAL_SRC_FILES := $(call all-java-files-under, tapl) \
+ ../quickstep/src/com/android/quickstep/SwipeUpSetting.java
LOCAL_SDK_VERSION := current
LOCAL_MODULE := ub-launcher-aosp-tapl
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index 19fa391..c3f27ee 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -22,7 +22,6 @@
import android.app.ActivityManager;
import android.app.UiAutomation;
-import android.content.res.Resources;
import android.os.Bundle;
import android.provider.Settings;
import android.support.annotation.NonNull;
@@ -35,6 +34,8 @@
import android.support.test.uiautomator.Until;
import android.view.accessibility.AccessibilityEvent;
+import com.android.quickstep.SwipeUpSetting;
+
import java.lang.ref.WeakReference;
import java.util.concurrent.TimeoutException;
@@ -78,10 +79,6 @@
private static final String WIDGETS_RES_ID = "widgets_list_view";
static final String LAUNCHER_PKG = "com.google.android.apps.nexuslauncher";
static final int WAIT_TIME_MS = 60000;
- 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";
private static final String SYSTEMUI_PACKAGE = "com.android.systemui";
private static WeakReference<VisibleContainer> sActiveContainer = new WeakReference<>(null);
@@ -95,8 +92,8 @@
public LauncherInstrumentation(UiDevice device) {
mDevice = device;
final boolean swipeUpEnabledDefault =
- !getSystemBooleanRes(SWIPE_UP_SETTING_AVAILABLE_RES_NAME) ||
- getSystemBooleanRes(SWIPE_UP_ENABLED_DEFAULT_RES_NAME);
+ !SwipeUpSetting.isSwipeUpSettingAvailable() ||
+ SwipeUpSetting.isSwipeUpEnabledDefaultValue();
mSwipeUpEnabled = Settings.Secure.getInt(
InstrumentationRegistry.getTargetContext().getContentResolver(),
"swipe_up_to_switch_apps_enabled",
@@ -104,13 +101,6 @@
assertTrue("Device must run in a test harness", ActivityManager.isRunningInTestHarness());
}
- private boolean getSystemBooleanRes(String resName) {
- final Resources res = Resources.getSystem();
- final int resId = res.getIdentifier(resName, "bool", "android");
- assertTrue("Resource not found: " + resName, resId != 0);
- return res.getBoolean(resId);
- }
-
void setActiveContainer(VisibleContainer container) {
sActiveContainer = new WeakReference<>(container);
}