diff --git a/Android.bp b/Android.bp index cc8a8c875d..4ef905c15e 100644 --- a/Android.bp +++ b/Android.bp @@ -312,6 +312,8 @@ android_library { srcs: [ "tests/tapl/**/*.java", "tests/tapl/**/*.kt", + "tests/src_tapl_build_config/**/*.java", + "tests/src_tapl_build_config/**/*.kt", ], resource_dirs: [], manifest: "tests/tapl/AndroidManifest.xml", @@ -404,7 +406,7 @@ android_library { "com_android_systemui_shared_flags_lib", "launcher-dagger-qualifiers", "launcher-executor-qualifiers", - "launcher-executors-module" + "launcher-executors-module", ], manifest: "AndroidManifest-common.xml", sdk_version: "current", @@ -430,7 +432,7 @@ android_app { srcs: [ ":launcher-src", ":launcher-src_no_quickstep", - ":launcher-build-config" + ":launcher-build-config", ], optimize: { diff --git a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java index d1645ac445..6a28a974e4 100644 --- a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java +++ b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java @@ -41,6 +41,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; import android.os.RemoteException; +import android.platform.test.rule.ExtendedLongPressTimeoutRule; import androidx.test.filters.LargeTest; import androidx.test.runner.AndroidJUnit4; @@ -57,7 +58,6 @@ import com.android.launcher3.testcomponent.TestCommandReceiver; import com.android.launcher3.ui.AbstractLauncherUiTest; import com.android.launcher3.util.TestUtil; import com.android.launcher3.util.Wait; -import com.android.launcher3.util.rule.ExtendedLongPressTimeoutRule; import com.android.launcher3.util.rule.FailureWatcher; import com.android.launcher3.util.rule.MutualExclusionRule; import com.android.launcher3.util.rule.SamplerRule; diff --git a/tests/src/com/android/launcher3/ui/BaseLauncherTaplTest.java b/tests/src/com/android/launcher3/ui/BaseLauncherTaplTest.java index c9577dbf52..59800ecf6f 100644 --- a/tests/src/com/android/launcher3/ui/BaseLauncherTaplTest.java +++ b/tests/src/com/android/launcher3/ui/BaseLauncherTaplTest.java @@ -40,6 +40,7 @@ import android.os.RemoteException; import android.os.UserHandle; import android.os.UserManager; import android.platform.test.flag.junit.SetFlagsRule; +import android.platform.test.rule.ExtendedLongPressTimeoutRule; import android.platform.test.rule.LimitDevicesRule; import android.util.Log; @@ -57,7 +58,6 @@ import com.android.launcher3.tapl.LauncherInstrumentation; import com.android.launcher3.tapl.TestHelpers; import com.android.launcher3.util.TestUtil; import com.android.launcher3.util.Wait; -import com.android.launcher3.util.rule.ExtendedLongPressTimeoutRule; import com.android.launcher3.util.rule.FailureWatcher; import com.android.launcher3.util.rule.MutualExclusionRule; import com.android.launcher3.util.rule.SamplerRule; diff --git a/tests/src/com/android/launcher3/util/rule/ExtendedLongPressTimeoutRule.java b/tests/src/com/android/launcher3/util/rule/ExtendedLongPressTimeoutRule.java deleted file mode 100644 index b04df7ec01..0000000000 --- a/tests/src/com/android/launcher3/util/rule/ExtendedLongPressTimeoutRule.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2024 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.launcher3.util.rule; - -import static com.android.launcher3.util.TestUtil.grantWriteSecurePermission; - -import android.content.ContentResolver; -import android.provider.Settings; -import android.util.Log; -import android.view.ViewConfiguration; - -import androidx.test.InstrumentationRegistry; - -import com.android.launcher3.BuildConfig; - -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; - -/** - * Increases the device's long-press timeout in remote tests to reduce flakiness in slow-running - * devices. - */ -public class ExtendedLongPressTimeoutRule implements TestRule { - - private static final String TAG = "ExtendedLongPressTimeoutRule"; - - private static final float LONG_PRESS_TIMEOUT_MULTIPLIER = 10f; - - @Override - public Statement apply(Statement base, Description description) { - if (BuildConfig.IS_STUDIO_BUILD) { - // Skip rule on studio builds since cancelling a test run will not run the finally block - return base; - } - return new Statement() { - @Override - public void evaluate() throws Throwable { - ContentResolver contentResolver = InstrumentationRegistry.getInstrumentation() - .getContext() - .getContentResolver(); - int prevLongPressTimeout = Settings.Secure.getInt( - contentResolver, - Settings.Secure.LONG_PRESS_TIMEOUT, - ViewConfiguration.getLongPressTimeout()); - int newLongPressTimeout = - (int) (prevLongPressTimeout * LONG_PRESS_TIMEOUT_MULTIPLIER); - - try { - Log.d(TAG, "In try-block: Setting long press timeout from " - + prevLongPressTimeout + "ms to " + newLongPressTimeout + "ms"); - grantWriteSecurePermission(); - Settings.Secure.putInt( - contentResolver, - Settings.Secure.LONG_PRESS_TIMEOUT, - (int) (prevLongPressTimeout * LONG_PRESS_TIMEOUT_MULTIPLIER)); - - base.evaluate(); - } catch (Exception e) { - Log.e(TAG, "Error", e); - throw e; - } finally { - Log.d(TAG, "In finally-block: resetting long press timeout to " - + prevLongPressTimeout + "ms"); - grantWriteSecurePermission(); - Settings.Secure.putInt( - contentResolver, - Settings.Secure.LONG_PRESS_TIMEOUT, - prevLongPressTimeout); - } - } - }; - } -} diff --git a/tests/src_tapl_build_config/com/android/launcher3/testing/BuildConfig.java b/tests/src_tapl_build_config/com/android/launcher3/testing/BuildConfig.java new file mode 100644 index 0000000000..b60f517953 --- /dev/null +++ b/tests/src_tapl_build_config/com/android/launcher3/testing/BuildConfig.java @@ -0,0 +1,24 @@ +/* + * 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.launcher3.testing; + +public final class BuildConfig { + public static final boolean DEBUG = Boolean.parseBoolean("true"); + + // Field from default config. + public static final boolean IS_STUDIO_BUILD = false; +}