Merge "Fix testAllAppsFromHome failure" into udc-qpr-dev
diff --git a/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java b/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java
index 6288937..1f06f94 100644
--- a/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java
+++ b/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java
@@ -110,8 +110,6 @@
public static final CopyOnWriteArrayList<StatsLogConsumer> LOGS_CONSUMER =
new CopyOnWriteArrayList<>();
- private final Context mContext;
-
public StatsLogCompatManager(Context context) {
mContext = context;
}
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 786088e..6796d4b 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -438,4 +438,8 @@
<!-- Folder spaces -->
<dimen name="folder_top_padding_default">24dp</dimen>
<dimen name="folder_footer_horiz_padding">20dp</dimen>
+
+ <!-- Default Ime height. Used only for logging purposes.
+ Assume this is default keyboard height in EN locale in case the keyboard height is not known when queried.-->
+ <dimen name="default_ime_height">300dp</dimen>
</resources>
diff --git a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java
index 9b7a05f..eb4ecaf 100644
--- a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java
@@ -45,7 +45,6 @@
import android.util.FloatProperty;
import android.util.Log;
import android.util.SparseArray;
-import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@@ -284,9 +283,8 @@
0,
0 // Bottom left
};
- final TypedValue value = new TypedValue();
- getContext().getTheme().resolveAttribute(android.R.attr.colorBackground, value, true);
- mBottomSheetBackgroundColor = value.data;
+ mBottomSheetBackgroundColor =
+ Themes.getAttrColor(getContext(), R.attr.materialColorSurfaceDim);
updateBackgroundVisibility(mActivityContext.getDeviceProfile());
mSearchUiManager.initializeSearch(this);
}
diff --git a/src/com/android/launcher3/logging/KeyboardStateManager.java b/src/com/android/launcher3/logging/KeyboardStateManager.java
index 6dc0a0b..d0f9c74 100644
--- a/src/com/android/launcher3/logging/KeyboardStateManager.java
+++ b/src/com/android/launcher3/logging/KeyboardStateManager.java
@@ -24,7 +24,10 @@
*/
public class KeyboardStateManager {
private long mUpdatedTime;
- private int mImeHeight;
+ private int mImeHeightPx;
+ // Height of the keyboard when it's shown.
+ // mImeShownHeightPx>=mImeHeightPx always.
+ private int mImeShownHeightPx;
public enum KeyboardState {
NO_IME_ACTION,
@@ -34,8 +37,9 @@
private KeyboardState mKeyboardState;
- public KeyboardStateManager() {
+ public KeyboardStateManager(int defaultImeShownHeightPx) {
mKeyboardState = NO_IME_ACTION;
+ mImeShownHeightPx = defaultImeShownHeightPx;
}
/**
@@ -64,13 +68,25 @@
* Returns keyboard's current height.
*/
public int getImeHeight() {
- return mImeHeight;
+ return mImeHeightPx;
}
/**
- * Setter method to set keyboard height.
+ * Returns keyboard's height in pixels when shown.
*/
- public void setImeHeight(int imeHeight) {
- mImeHeight = imeHeight;
+ public int getImeShownHeight() {
+ return mImeShownHeightPx;
+ }
+
+ /**
+ * Setter method to set keyboard height in pixels.
+ */
+ public void setImeHeight(int imeHeightPx) {
+ mImeHeightPx = imeHeightPx;
+ if (mImeHeightPx > 0) {
+ // Update the mImeShownHeightPx with the actual ime height when shown and store it
+ // for future sessions.
+ mImeShownHeightPx = mImeHeightPx;
+ }
}
}
diff --git a/src/com/android/launcher3/logging/StatsLogManager.java b/src/com/android/launcher3/logging/StatsLogManager.java
index 7e065a9..3e9731382 100644
--- a/src/com/android/launcher3/logging/StatsLogManager.java
+++ b/src/com/android/launcher3/logging/StatsLogManager.java
@@ -59,6 +59,7 @@
private InstanceId mInstanceId;
protected @Nullable ActivityContext mActivityContext = null;
+ protected @Nullable Context mContext = null;
private KeyboardStateManager mKeyboardStateManager;
/**
@@ -1035,7 +1036,9 @@
*/
public KeyboardStateManager keyboardStateManager() {
if (mKeyboardStateManager == null) {
- mKeyboardStateManager = new KeyboardStateManager();
+ mKeyboardStateManager = new KeyboardStateManager(
+ mContext != null ? mContext.getResources().getDimensionPixelSize(
+ R.dimen.default_ime_height) : 0);
}
return mKeyboardStateManager;
}
@@ -1071,6 +1074,7 @@
StatsLogManager manager = Overrides.getObject(StatsLogManager.class,
context.getApplicationContext(), R.string.stats_log_manager_class);
manager.mActivityContext = ActivityContext.lookupContextNoThrow(context);
+ manager.mContext = context;
return manager;
}
}
diff --git a/tests/src/com/android/launcher3/util/rule/LazyActivityRule.java b/tests/src/com/android/launcher3/util/rule/LazyActivityRule.java
new file mode 100644
index 0000000..6c300bb
--- /dev/null
+++ b/tests/src/com/android/launcher3/util/rule/LazyActivityRule.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2023 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 android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
+import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
+import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
+import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
+
+import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ResolveInfo;
+
+import androidx.annotation.Nullable;
+import androidx.test.core.app.ActivityScenario;
+
+import com.android.launcher3.Launcher;
+
+import org.junit.rules.ExternalResource;
+
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Supplier;
+
+/**
+ * Similar to {@code ActivityScenarioRule} but it creates the activity lazily when needed
+ */
+public class LazyActivityRule<A extends Activity> extends ExternalResource {
+
+ private final Supplier<ActivityScenario<A>> mScenarioSupplier;
+
+ @Nullable private ActivityScenario<A> mScenario;
+
+ /**
+ * Constructs LazyActivityScenarioRule for a given scenario provider.
+ */
+ public LazyActivityRule(Supplier<ActivityScenario<A>> supplier) {
+ mScenarioSupplier = supplier;
+ }
+
+ /**
+ * Resets the rule, such that the activity is in closed state
+ */
+ public synchronized void reset() {
+ if (mScenario != null) {
+ try {
+ mScenario.close();
+ } catch (AssertionError e) {
+ // Ignore errors during close
+ }
+ }
+ mScenario = null;
+ }
+
+ @Override
+ protected synchronized void after() {
+ reset();
+ }
+
+ /**
+ * Returns the scenario, creating one if it doesn't exist
+ */
+ public synchronized ActivityScenario<A> getScenario() {
+ if (mScenario == null) {
+ mScenario = mScenarioSupplier.get();
+ }
+ return mScenario;
+ }
+
+ /**
+ * Executes the function {@code f} on the activities main thread and returns the result
+ */
+ public <T> T getFromActivity(Function<A, T> f) {
+ AtomicReference<T> result = new AtomicReference<>();
+ getScenario().onActivity(a -> result.set(f.apply(a)));
+ return result.get();
+ }
+
+ /**
+ * Runs the provided function {@code f} on the activity if the scenario is already created
+ */
+ public synchronized void runOnActivity(Consumer<A> f) {
+ if (mScenario != null) {
+ mScenario.onActivity(f::accept);
+ }
+ }
+
+ /**
+ * Returns a {@link LazyActivityRule} for the Launcher activity
+ */
+ public static <T extends Launcher> LazyActivityRule<T> forLauncher() {
+ Context context = getInstrumentation().getTargetContext();
+ // Create the activity after the model setup is done.
+ Intent homeIntent = new Intent(Intent.ACTION_MAIN)
+ .addCategory(Intent.CATEGORY_HOME)
+ .addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK
+ | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | FLAG_ACTIVITY_NO_ANIMATION);
+ ResolveInfo ri = context.getPackageManager().resolveActivity(
+ new Intent(homeIntent).setPackage(context.getPackageName()), 0);
+ homeIntent.setComponent(ri.getComponentInfo().getComponentName());
+ return new LazyActivityRule<>(() -> ActivityScenario.launch(homeIntent));
+ }
+}
diff --git a/tests/src/com/android/launcher3/util/rule/WrapperRule.kt b/tests/src/com/android/launcher3/util/rule/WrapperRule.kt
new file mode 100644
index 0000000..290cc45
--- /dev/null
+++ b/tests/src/com/android/launcher3/util/rule/WrapperRule.kt
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2023 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 com.android.launcher3.config.FeatureFlags.BooleanFlag
+import com.android.launcher3.config.FeatureFlags.IntFlag
+import com.android.launcher3.util.SafeCloseable
+import com.android.launcher3.util.TestUtil
+import java.util.function.Supplier
+import org.junit.rules.ExternalResource
+
+/** Simple rule which wraps any SafeCloseable object */
+class WrapperRule(private val overrideProvider: Supplier<SafeCloseable>) : ExternalResource() {
+
+ private lateinit var overrideClosable: SafeCloseable
+
+ override fun before() {
+ overrideClosable = overrideProvider.get()
+ }
+
+ override fun after() {
+ overrideClosable.close()
+ }
+
+ companion object {
+
+ fun BooleanFlag.overrideFlag(value: Boolean) = WrapperRule {
+ TestUtil.overrideFlag(this, value)
+ }
+
+ fun IntFlag.overrideFlag(value: Int) = WrapperRule { TestUtil.overrideFlag(this, value) }
+ }
+}