Move ExtendedLongPressTimeoutRule implementation to shared sysui test library

Flag: EXEMPT test fix
Fixes: 396862825
Test: TaskbarExpandCollapse
Change-Id: I950ed4ede8db150234d843422982792f5b6bfd8e
This commit is contained in:
Schneider Victor-Tulias
2025-04-22 15:54:12 -04:00
committed by Schneider Victor-tulias
parent 5d600e171d
commit 42d6c08d41
5 changed files with 30 additions and 92 deletions

View File

@@ -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: {

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);
}
}
};
}
}

View File

@@ -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;
}