Merge "Don't render background in PreviewRenderer" into ub-launcher3-master
diff --git a/go/quickstep/res/layout/icon_recents_root_view.xml b/go/quickstep/res/layout/icon_recents_root_view.xml
index 122fadf..82d5890 100644
--- a/go/quickstep/res/layout/icon_recents_root_view.xml
+++ b/go/quickstep/res/layout/icon_recents_root_view.xml
@@ -14,11 +14,17 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<!-- TODO(114136250): Remove this temporary placeholder view for Go recents -->
-<TextView
+<com.android.quickstep.views.IconRecentsView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:gravity="center"
- android:text="Stub!"
- android:textSize="40sp"/>
\ No newline at end of file
+ android:gravity="center">
+ <!-- TODO(114136250): Remove this temporary placeholder view for Go recents -->
+ <TextView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center"
+ android:text="Stub!"
+ android:textSize="40sp"/>
+</com.android.quickstep.views.IconRecentsView>
\ No newline at end of file
diff --git a/go/quickstep/src/com/android/launcher3/uioverrides/PortraitOverviewStateTouchHelper.java b/go/quickstep/src/com/android/launcher3/uioverrides/PortraitOverviewStateTouchHelper.java
new file mode 100644
index 0000000..a3b41b0
--- /dev/null
+++ b/go/quickstep/src/com/android/launcher3/uioverrides/PortraitOverviewStateTouchHelper.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2019 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.uioverrides;
+
+import android.view.MotionEvent;
+
+import com.android.launcher3.Launcher;
+import com.android.launcher3.util.PendingAnimation;
+
+/**
+ * Helper class for {@link PortraitStatesTouchController} that determines swipeable regions and
+ * animations on the overview state that depend on the recents implementation.
+ */
+public final class PortraitOverviewStateTouchHelper {
+
+ public PortraitOverviewStateTouchHelper(Launcher launcher) {}
+
+ /**
+ * Whether or not {@link PortraitStatesTouchController} should intercept the touch when on the
+ * overview state.
+ *
+ * @param ev the motion event
+ * @return true if we should intercept the motion event
+ */
+ boolean canInterceptTouch(MotionEvent ev) {
+ // Go does not support swiping to all-apps from recents.
+ return false;
+ }
+
+ /**
+ * Whether or not swiping down to leave overview state should return to the currently running
+ * task app.
+ *
+ * @return true if going back should take the user to the currently running task
+ */
+ boolean shouldSwipeDownReturnToApp() {
+ // Go does not support swiping tasks down to launch tasks from recents.
+ return false;
+ }
+
+ /**
+ * Create the animation for going from overview to the task app via swiping.
+ *
+ * @param duration how long the animation should be
+ * @return the animation
+ */
+ PendingAnimation createSwipeDownToTaskAppAnimation(long duration) {
+ // Go does not support swiping tasks down to launch tasks from recents.
+ return null;
+ }
+}
diff --git a/go/quickstep/src/com/android/quickstep/views/IconRecentsView.java b/go/quickstep/src/com/android/quickstep/views/IconRecentsView.java
new file mode 100644
index 0000000..e4741e9
--- /dev/null
+++ b/go/quickstep/src/com/android/quickstep/views/IconRecentsView.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2019 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.views;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.util.FloatProperty;
+import android.view.ViewDebug;
+import android.widget.FrameLayout;
+
+/**
+ * Root view for the icon recents view.
+ */
+public final class IconRecentsView extends FrameLayout {
+
+ public static final FloatProperty<IconRecentsView> TRANSLATION_Y_FACTOR =
+ new FloatProperty<IconRecentsView>("translationYFactor") {
+
+ @Override
+ public void setValue(IconRecentsView view, float v) {
+ view.setTranslationYFactor(v);
+ }
+
+ @Override
+ public Float get(IconRecentsView view) {
+ return view.mTranslationYFactor;
+ }
+ };
+
+ public static final FloatProperty<IconRecentsView> CONTENT_ALPHA =
+ new FloatProperty<IconRecentsView>("contentAlpha") {
+ @Override
+ public void setValue(IconRecentsView view, float v) {
+ ALPHA.set(view, v);
+ }
+
+ @Override
+ public Float get(IconRecentsView view) {
+ return ALPHA.get(view);
+ }
+ };
+
+ /**
+ * A ratio representing the view's relative placement within its padded space. For example, 0
+ * is top aligned and 0.5 is centered vertically.
+ */
+ @ViewDebug.ExportedProperty(category = "launcher")
+ private float mTranslationYFactor;
+
+ public IconRecentsView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public void setTranslationYFactor(float translationFactor) {
+ mTranslationYFactor = translationFactor;
+ setTranslationY(computeTranslationYForFactor(mTranslationYFactor));
+ }
+
+ private float computeTranslationYForFactor(float translationYFactor) {
+ return translationYFactor * (getPaddingBottom() - getPaddingTop());
+ }
+}
diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/PortraitOverviewStateTouchHelper.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/PortraitOverviewStateTouchHelper.java
new file mode 100644
index 0000000..eead4c8
--- /dev/null
+++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/PortraitOverviewStateTouchHelper.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2019 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.uioverrides;
+
+import static com.android.launcher3.uioverrides.PortraitStatesTouchController.isTouchOverHotseat;
+
+import android.view.MotionEvent;
+
+import com.android.launcher3.Launcher;
+import com.android.launcher3.util.PendingAnimation;
+import com.android.quickstep.views.RecentsView;
+import com.android.quickstep.views.TaskView;
+
+/**
+ * Helper class for {@link PortraitStatesTouchController} that determines swipeable regions and
+ * animations on the overview state that depend on the recents implementation.
+ */
+public final class PortraitOverviewStateTouchHelper {
+
+ RecentsView mRecentsView;
+ Launcher mLauncher;
+
+ public PortraitOverviewStateTouchHelper(Launcher launcher) {
+ mLauncher = launcher;
+ mRecentsView = launcher.getOverviewPanel();
+ }
+
+ /**
+ * Whether or not {@link PortraitStatesTouchController} should intercept the touch when on the
+ * overview state.
+ *
+ * @param ev the motion event
+ * @return true if we should intercept the motion event
+ */
+ boolean canInterceptTouch(MotionEvent ev) {
+ if (mRecentsView.getChildCount() > 0) {
+ // Allow swiping up in the gap between the hotseat and overview.
+ return ev.getY() >= mRecentsView.getChildAt(0).getBottom();
+ } else {
+ // If there are no tasks, we only intercept if we're below the hotseat height.
+ return isTouchOverHotseat(mLauncher, ev);
+ }
+ }
+
+ /**
+ * Whether or not swiping down to leave overview state should return to the currently running
+ * task app.
+ *
+ * @return true if going back should take the user to the currently running task
+ */
+ boolean shouldSwipeDownReturnToApp() {
+ TaskView taskView = mRecentsView.getTaskViewAt(mRecentsView.getNextPage());
+ return taskView != null && mRecentsView.shouldSwipeDownLaunchApp();
+ }
+
+ /**
+ * Create the animation for going from overview to the task app via swiping. Should only be
+ * called when {@link #shouldSwipeDownReturnToApp()} returns true.
+ *
+ * @param duration how long the animation should be
+ * @return the animation
+ */
+ PendingAnimation createSwipeDownToTaskAppAnimation(long duration) {
+ TaskView taskView = mRecentsView.getTaskViewAt(mRecentsView.getNextPage());
+ if (taskView == null) {
+ throw new IllegalStateException("There is no task view to animate to.");
+ }
+ return mRecentsView.createTaskLauncherAnimation(taskView, duration);
+ }
+}
diff --git a/quickstep/res/drawable/bg_wellbeing_toast.xml b/quickstep/res/drawable/bg_wellbeing_toast.xml
new file mode 100644
index 0000000..22d6f8a
--- /dev/null
+++ b/quickstep/res/drawable/bg_wellbeing_toast.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2019 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.
+-->
+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
+ <solid android:color="#E61A73E8" />
+ <corners android:radius="@dimen/task_corner_radius" />
+</shape>
\ No newline at end of file
diff --git a/quickstep/res/drawable/hourglass_bottom.xml b/quickstep/res/drawable/hourglass_bottom.xml
new file mode 100644
index 0000000..b5ef008
--- /dev/null
+++ b/quickstep/res/drawable/hourglass_bottom.xml
@@ -0,0 +1,12 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <group>
+ <clip-path android:pathData="M0,0H24V24H0Z M 0,0"/>
+ <path
+ android:fillColor="#FFFFFFFF"
+ android:pathData="M6,2V8H6l4,4L6,16H6v6H18V16h0l-4,-4,4,-4h0V2Zm6,9.5,-4,-4V4h8V7.5Z"/>
+ </group>
+</vector>
diff --git a/quickstep/res/drawable/hourglass_top.xml b/quickstep/res/drawable/hourglass_top.xml
new file mode 100644
index 0000000..7fc77d3
--- /dev/null
+++ b/quickstep/res/drawable/hourglass_top.xml
@@ -0,0 +1,12 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <group>
+ <clip-path android:pathData="M0,0H24V24H0Z M 0,0"/>
+ <path
+ android:fillColor="#FFFFFFFF"
+ android:pathData="M6,2V8H6l4,4L6,16H6v6H18V16h0l-4,-4,4,-4h0V2ZM16,16.5V20H8V16.5l4,-4Z"/>
+ </group>
+</vector>
diff --git a/quickstep/res/layout/task.xml b/quickstep/res/layout/task.xml
index 8f43192..f96a66f 100644
--- a/quickstep/res/layout/task.xml
+++ b/quickstep/res/layout/task.xml
@@ -38,12 +38,26 @@
<com.android.quickstep.views.DigitalWellBeingToast
android:id="@+id/digital_well_being_toast"
android:layout_width="match_parent"
- android:layout_height="100dp"
+ android:layout_height="48dp"
android:importantForAccessibility="noHideDescendants"
- android:background="#800000FF"
+ android:background="@drawable/bg_wellbeing_toast"
android:layout_gravity="bottom"
android:gravity="center"
- android:textColor="@android:color/white"
- android:visibility="gone"
+ android:visibility="gone">
+ <ImageView
+ android:id="@+id/digital_well_being_hourglass"
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:layout_marginEnd="8dp"
/>
+ <TextView
+ android:id="@+id/digital_well_being_remaining_time"
+ android:layout_width="wrap_content"
+ android:layout_height="24dp"
+ android:fontFamily="sans-serif"
+ android:textSize="14sp"
+ android:textColor="@android:color/white"
+ android:gravity="center_vertical"
+ />
+ </com.android.quickstep.views.DigitalWellBeingToast>
</com.android.quickstep.views.TaskView>
\ No newline at end of file
diff --git a/quickstep/res/values/strings.xml b/quickstep/res/values/strings.xml
index 08132aa..7c47956 100644
--- a/quickstep/res/values/strings.xml
+++ b/quickstep/res/values/strings.xml
@@ -16,7 +16,7 @@
* limitations under the License.
*/
-->
-<resources>
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Application name -->
<string name="derived_app_name" translatable="false">Quickstep</string>
@@ -46,4 +46,24 @@
<!-- Accessibility title for the list of recent apps [CHAR_LIMIT=none] -->
<string name="accessibility_recent_apps">Recent apps</string>
+
+ <!-- Accessibility title for an app card in Recents for apps that have time limit set
+ [CHAR_LIMIT=none] -->
+ <string name="task_contents_description_with_remaining_time"><xliff:g id="task_description" example="GMail">%1$s</xliff:g>, <xliff:g id="remaining_time" example="7 minutes left today">%2$s</xliff:g></string>
+
+ <!-- Text to show total app usage per day if it is less than 1 minute ("<" is the
+ escaped form of '<'). [CHAR LIMIT=10] -->
+ <string name="shorter_duration_less_than_one_minute">< 1 minute</string>
+
+ <!-- Annotation shown on an app card in Recents, telling that the app was switched to a
+ grayscale because it ran over its time limit [CHAR LIMIT=25] -->
+ <string name="app_in_grayscale">App in grayscale</string>
+
+ <!-- Annotation shown on an app card in Recents, telling that the app has a usage limit set by
+ the user, and a given time is left for it today [CHAR LIMIT=20] -->
+ <string name="time_left_for_app"><xliff:g id="time" example="7 minutes">%1$s</xliff:g> left today</string>
+
+ <!-- Annotation shown on an app card in Recents, telling that the app is in a group that has a
+ usage limit set by the user, and a given time is left for the group today [CHAR LIMIT=20] -->
+ <string name="time_left_for_group"><xliff:g id="time" example="1 hour">%1$s</xliff:g> left for group</string>
</resources>
\ No newline at end of file
diff --git a/quickstep/src/com/android/launcher3/uioverrides/PortraitStatesTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/PortraitStatesTouchController.java
index 330dc87..ea0e552 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/PortraitStatesTouchController.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/PortraitStatesTouchController.java
@@ -47,8 +47,6 @@
import com.android.quickstep.RecentsModel;
import com.android.quickstep.TouchInteractionService;
import com.android.quickstep.util.LayoutUtils;
-import com.android.quickstep.views.RecentsView;
-import com.android.quickstep.views.TaskView;
/**
* Touch controller for handling various state transitions in portrait UI.
@@ -67,14 +65,16 @@
*/
private static final float RECENTS_FADE_THRESHOLD = 0.88f;
+ private final PortraitOverviewStateTouchHelper mOverviewPortraitStateTouchHelper;
+
private InterpolatorWrapper mAllAppsInterpolatorWrapper = new InterpolatorWrapper();
// If true, we will finish the current animation instantly on second touch.
private boolean mFinishFastOnSecondTouch;
-
public PortraitStatesTouchController(Launcher l) {
super(l, SwipeDetector.VERTICAL);
+ mOverviewPortraitStateTouchHelper = new PortraitOverviewStateTouchHelper(l);
}
@Override
@@ -98,22 +98,18 @@
}
return false;
}
- RecentsView recentsView = mLauncher.getOverviewPanel();
if (mLauncher.isInState(ALL_APPS)) {
// In all-apps only listen if the container cannot scroll itself
if (!mLauncher.getAppsView().shouldContainerScroll(ev)) {
return false;
}
- } else if (mLauncher.isInState(OVERVIEW) && recentsView.getChildCount() > 0) {
- // Allow swiping up in the gap between the hotseat and overview.
- if (ev.getY() < recentsView.getChildAt(0).getBottom()) {
+ } else if (mLauncher.isInState(OVERVIEW)) {
+ if (!mOverviewPortraitStateTouchHelper.canInterceptTouch(ev)) {
return false;
}
} else {
// For all other states, only listen if the event originated below the hotseat height
- DeviceProfile dp = mLauncher.getDeviceProfile();
- int hotseatHeight = dp.hotseatBarSizePx + dp.getInsets().bottom;
- if (ev.getY() < (mLauncher.getDragLayer().getHeight() - hotseatHeight)) {
+ if (!isTouchOverHotseat(mLauncher, ev)) {
return false;
}
}
@@ -197,13 +193,12 @@
cancelPendingAnim();
- RecentsView recentsView = mLauncher.getOverviewPanel();
- TaskView taskView = recentsView.getTaskViewAt(recentsView.getNextPage());
- if (recentsView.shouldSwipeDownLaunchApp() && mFromState == OVERVIEW && mToState == NORMAL
- && taskView != null) {
+ if (mFromState == OVERVIEW && mToState == NORMAL
+ && mOverviewPortraitStateTouchHelper.shouldSwipeDownReturnToApp()) {
// Reset the state manager, when changing the interaction mode
mLauncher.getStateManager().goToState(OVERVIEW, false /* animate */);
- mPendingAnimation = recentsView.createTaskLauncherAnimation(taskView, maxAccuracy);
+ mPendingAnimation = mOverviewPortraitStateTouchHelper
+ .createSwipeDownToTaskAppAnimation(maxAccuracy);
mPendingAnimation.anim.setInterpolator(Interpolators.LINEAR);
Runnable onCancelRunnable = () -> {
@@ -269,6 +264,19 @@
}
}
+ /**
+ * Whether the motion event is over the hotseat.
+ *
+ * @param launcher the launcher activity
+ * @param ev the event to check
+ * @return true if the event is over the hotseat
+ */
+ static boolean isTouchOverHotseat(Launcher launcher, MotionEvent ev) {
+ DeviceProfile dp = launcher.getDeviceProfile();
+ int hotseatHeight = dp.hotseatBarSizePx + dp.getInsets().bottom;
+ return (ev.getY() >= (launcher.getDragLayer().getHeight() - hotseatHeight));
+ }
+
private static class InterpolatorWrapper implements Interpolator {
public TimeInterpolator baseInterpolator = LINEAR;
diff --git a/quickstep/src/com/android/quickstep/views/DigitalWellBeingToast.java b/quickstep/src/com/android/quickstep/views/DigitalWellBeingToast.java
index b34d2bf..aafd725 100644
--- a/quickstep/src/com/android/quickstep/views/DigitalWellBeingToast.java
+++ b/quickstep/src/com/android/quickstep/views/DigitalWellBeingToast.java
@@ -20,19 +20,33 @@
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.LauncherApps;
+import android.content.res.Resources;
+import android.icu.text.MeasureFormat;
+import android.icu.text.MeasureFormat.FormatWidth;
+import android.icu.util.Measure;
+import android.icu.util.MeasureUnit;
+import android.os.UserHandle;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
import android.widget.TextView;
+import androidx.annotation.StringRes;
+
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.systemui.shared.recents.model.Task;
-public final class DigitalWellBeingToast extends TextView {
+import java.lang.reflect.Method;
+import java.time.Duration;
+import java.util.Locale;
+public final class DigitalWellBeingToast extends LinearLayout {
public interface InitializeCallback {
void call(float saturation, String contentDescription);
}
@@ -40,41 +54,144 @@
private static final String TAG = DigitalWellBeingToast.class.getSimpleName();
private Task mTask;
+ private ImageView mImage;
+ private TextView mText;
public DigitalWellBeingToast(Context context, AttributeSet attrs) {
super(context, attrs);
setLayoutDirection(Utilities.isRtl(getResources()) ?
View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR);
setOnClickListener((view) -> openAppUsageSettings());
+ }
+ @Override
+ protected void onFinishInflate() {
+ super.onFinishInflate();
+
+ mText = findViewById(R.id.digital_well_being_remaining_time);
+ mImage = findViewById(R.id.digital_well_being_hourglass);
}
public void initialize(Task task, InitializeCallback callback) {
mTask = task;
Utilities.THREAD_POOL_EXECUTOR.execute(() -> {
- final long appUsageLimitTimeMs = -1;
- final long appRemainingTimeMs = -1;
- final boolean isGroupLimit = true;
+ long appUsageLimitTimeMs = -1;
+ long appRemainingTimeMs = -1;
+ boolean isGroupLimit = true;
+
+ try {
+ final Method getAppUsageLimit = LauncherApps.class.getMethod(
+ "getAppUsageLimit",
+ String.class,
+ UserHandle.class);
+ final Object usageLimit = getAppUsageLimit.invoke(
+ getContext().getSystemService(LauncherApps.class),
+ task.getTopComponent().getPackageName(),
+ UserHandle.of(task.key.userId));
+
+ if (usageLimit != null) {
+ final Class appUsageLimitClass = usageLimit.getClass();
+ appUsageLimitTimeMs = (long) appUsageLimitClass.getMethod("getTotalUsageLimit").
+ invoke(usageLimit);
+ appRemainingTimeMs = (long) appUsageLimitClass.getMethod("getUsageRemaining").
+ invoke(usageLimit);
+ isGroupLimit = (boolean) appUsageLimitClass.getMethod("isGroupLimit").
+ invoke(usageLimit);
+ }
+ } catch (Exception e) {
+ // Do nothing
+ }
+
+ final long appUsageLimitTimeMsFinal = appUsageLimitTimeMs;
+ final long appRemainingTimeMsFinal = appRemainingTimeMs;
+ final boolean isGroupLimitFinal = isGroupLimit;
+
post(() -> {
- if (appUsageLimitTimeMs < 0) {
+ if (appUsageLimitTimeMsFinal < 0) {
setVisibility(GONE);
} else {
setVisibility(VISIBLE);
- setText(getText(appRemainingTimeMs, isGroupLimit));
+ mText.setText(getText(appRemainingTimeMsFinal, isGroupLimitFinal));
+ mImage.setImageResource(appRemainingTimeMsFinal > 0 ?
+ R.drawable.hourglass_top : R.drawable.hourglass_bottom);
}
callback.call(
- appUsageLimitTimeMs >= 0 && appRemainingTimeMs < 0 ? 0 : 1,
- getContentDescriptionForTask(task, appRemainingTimeMs, isGroupLimit));
+ appUsageLimitTimeMsFinal >= 0 && appRemainingTimeMsFinal <= 0 ? 0 : 1,
+ getContentDescriptionForTask(
+ task, appUsageLimitTimeMsFinal,
+ appRemainingTimeMsFinal,
+ isGroupLimitFinal));
});
});
}
- public static String getText(long remainingTime, boolean isGroupLimit) {
- return remainingTime < 0 ?
- "Grayed" :
- "Remaining time:" + (remainingTime + 59999) / 60000
- + " min " + (isGroupLimit ? "for group" : "for the app");
+ private String getReadableDuration(
+ Duration duration,
+ FormatWidth formatWidthHourAndMinute,
+ @StringRes int durationLessThanOneMinuteStringId,
+ boolean forceFormatWidth) {
+ int hours = Math.toIntExact(duration.toHours());
+ int minutes = Math.toIntExact(duration.minusHours(hours).toMinutes());
+
+ // Apply formatWidthHourAndMinute if both the hour part and the minute part are non-zero.
+ if (hours > 0 && minutes > 0) {
+ return MeasureFormat.getInstance(Locale.getDefault(), formatWidthHourAndMinute)
+ .formatMeasures(
+ new Measure(hours, MeasureUnit.HOUR),
+ new Measure(minutes, MeasureUnit.MINUTE));
+ }
+
+ // Apply formatWidthHourOrMinute if only the hour part is non-zero (unless forced).
+ if (hours > 0) {
+ return MeasureFormat.getInstance(
+ Locale.getDefault(),
+ forceFormatWidth ? formatWidthHourAndMinute : FormatWidth.WIDE)
+ .formatMeasures(new Measure(hours, MeasureUnit.HOUR));
+ }
+
+ // Apply formatWidthHourOrMinute if only the minute part is non-zero (unless forced).
+ if (minutes > 0) {
+ return MeasureFormat.getInstance(
+ Locale.getDefault()
+ , forceFormatWidth ? formatWidthHourAndMinute : FormatWidth.WIDE)
+ .formatMeasures(new Measure(minutes, MeasureUnit.MINUTE));
+ }
+
+ // Use a specific string for usage less than one minute but non-zero.
+ if (duration.compareTo(Duration.ZERO) > 0) {
+ return getResources().getString(durationLessThanOneMinuteStringId);
+ }
+
+ // Otherwise, return 0-minute string.
+ return MeasureFormat.getInstance(
+ Locale.getDefault(), forceFormatWidth ? formatWidthHourAndMinute : FormatWidth.WIDE)
+ .formatMeasures(new Measure(0, MeasureUnit.MINUTE));
+ }
+
+ private String getReadableDuration(
+ Duration duration,
+ FormatWidth formatWidthHourAndMinute,
+ @StringRes int durationLessThanOneMinuteStringId) {
+ return getReadableDuration(
+ duration,
+ formatWidthHourAndMinute,
+ durationLessThanOneMinuteStringId,
+ /* forceFormatWidth= */ false);
+ }
+
+ private String getShorterReadableDuration(Duration duration) {
+ return getReadableDuration(
+ duration, FormatWidth.NARROW, R.string.shorter_duration_less_than_one_minute);
+ }
+
+ private String getText(long remainingTime, boolean isGroupLimit) {
+ final Resources resources = getResources();
+ return (remainingTime <= 0) ?
+ resources.getString(R.string.app_in_grayscale) :
+ resources.getString(
+ isGroupLimit ? R.string.time_left_for_group : R.string.time_left_for_app,
+ getShorterReadableDuration(Duration.ofMillis(remainingTime)));
}
public void openAppUsageSettings() {
@@ -97,8 +214,8 @@
}
private String getContentDescriptionForTask(
- Task task, long appRemainingTimeMs, boolean isGroupLimit) {
- return appRemainingTimeMs > 0 ?
+ Task task, long appUsageLimitTimeMs, long appRemainingTimeMs, boolean isGroupLimit) {
+ return appUsageLimitTimeMs >= 0 ?
getResources().getString(
R.string.task_contents_description_with_remaining_time,
task.titleDescription,
diff --git a/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java b/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java
index 7389d65..722c721 100644
--- a/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java
@@ -67,6 +67,10 @@
}
};
+ /**
+ * A ratio representing the view's relative placement within its padded space. For example, 0
+ * is top aligned and 0.5 is centered vertically.
+ */
@ViewDebug.ExportedProperty(category = "launcher")
private float mTranslationYFactor;
diff --git a/quickstep/tests/src/com/android/quickstep/TaplTests.java b/quickstep/tests/src/com/android/quickstep/TaplTests.java
index 6a1123e..347b7ac 100644
--- a/quickstep/tests/src/com/android/quickstep/TaplTests.java
+++ b/quickstep/tests/src/com/android/quickstep/TaplTests.java
@@ -104,7 +104,7 @@
clearLauncherData();
- mDevice.pressHome();
+ mLauncher.pressHome();
waitForState("Launcher internal state didn't switch to Home", LauncherState.NORMAL);
waitForResumed("Launcher internal state is still Background");
}
@@ -424,7 +424,7 @@
executeOnLauncher(launcher -> assertTrue("Flinging backward didn't scroll widgets",
getWidgetsScroll(launcher) < flingForwardY));
- mDevice.pressHome();
+ mLauncher.pressHome();
waitForLauncherCondition("Widgets were not closed",
launcher -> getWidgetsView(launcher) == null);
}
diff --git a/res/values/strings.xml b/res/values/strings.xml
index a1089c6..51350c0 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -336,6 +336,4 @@
<!-- Failed action error message: e.g. Failed: Pause -->
<string name="remote_action_failed">Failed: <xliff:g id="what" example="Pause">%1$s</xliff:g></string>
-
- <string name="task_contents_description_with_remaining_time" translatable="false"><xliff:g id="task_description" example="GMail">%1$s</xliff:g>, <xliff:g id="remaining_time" example="7 minutes">%2$s</xliff:g></string>
</resources>
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index f09b6e8..ab83c6c 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -1377,6 +1377,11 @@
}
private void setWorkspaceLoading(boolean value) {
+ if (com.android.launcher3.Utilities.IS_RUNNING_IN_TEST_HARNESS
+ && com.android.launcher3.Utilities.IS_DEBUG_DEVICE) {
+ android.util.Log.d("b/117332845", "setWorkspaceLoading " + value + " @ " +
+ android.util.Log.getStackTraceString(new Throwable()));
+ }
mWorkspaceLoading = value;
}
diff --git a/src/com/android/launcher3/util/RaceConditionTracker.java b/src/com/android/launcher3/util/RaceConditionTracker.java
index 8b06787..6954d0e 100644
--- a/src/com/android/launcher3/util/RaceConditionTracker.java
+++ b/src/com/android/launcher3/util/RaceConditionTracker.java
@@ -24,6 +24,8 @@
public class RaceConditionTracker {
public final static boolean ENTER = true;
public final static boolean EXIT = false;
+ static final String ENTER_POSTFIX = "enter";
+ static final String EXIT_POSTFIX = "exit";
public interface EventProcessor {
void onEvent(String eventName);
@@ -46,7 +48,7 @@
}
public static String enterExitEvt(String eventName, boolean isEnter) {
- return eventName + ":" + (isEnter ? "enter" : "exit");
+ return eventName + ":" + (isEnter ? ENTER_POSTFIX : EXIT_POSTFIX);
}
public static String enterEvt(String eventName) {
diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
index 8c03e4b..1b34598 100644
--- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
+++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
@@ -123,7 +123,7 @@
public void evaluate() throws Throwable {
try {
// Create launcher activity if necessary and bring it to the front.
- mDevice.pressHome();
+ mLauncher.pressHome();
waitForLauncherCondition("Launcher activity wasn't created",
launcher -> launcher != null);
diff --git a/tests/src/com/android/launcher3/ui/AllAppsIconToHomeTest.java b/tests/src/com/android/launcher3/ui/AllAppsIconToHomeTest.java
index 9354862..fdf87be 100644
--- a/tests/src/com/android/launcher3/ui/AllAppsIconToHomeTest.java
+++ b/tests/src/com/android/launcher3/ui/AllAppsIconToHomeTest.java
@@ -21,14 +21,12 @@
LauncherActivityInfo settingsApp = getSettingsApp();
clearHomescreen();
- mDevice.pressHome();
- mDevice.waitForIdle();
final String appName = settingsApp.getLabel().toString();
// 1. Open all apps and wait for load complete.
// 2. Drag icon to homescreen.
// 3. Verify that the icon works on homescreen.
- mLauncher.getWorkspace().
+ mLauncher.pressHome().
switchToAllApps().
getAppIcon(appName).
dragToWorkspace().
diff --git a/tests/src/com/android/launcher3/util/RaceConditionReproducer.java b/tests/src/com/android/launcher3/util/RaceConditionReproducer.java
index 316e40d..0235f95 100644
--- a/tests/src/com/android/launcher3/util/RaceConditionReproducer.java
+++ b/tests/src/com/android/launcher3/util/RaceConditionReproducer.java
@@ -16,6 +16,9 @@
package com.android.launcher3.util;
+import static com.android.launcher3.util.RaceConditionTracker.ENTER_POSTFIX;
+import static com.android.launcher3.util.RaceConditionTracker.EXIT_POSTFIX;
+
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -46,7 +49,7 @@
* If an event A occurs before event B in the sequence, this is how execution order looks like:
* Events: ... A ... B ...
* Events and instructions, guaranteed order:
- * (instructions executed prior to A) A ... B (instructions executed after B)
+ * (instructions executed prior to A) A ... B (instructions executed after B)
*
* Each iteration has 3 parts (phases).
* Phase 1. Picking a previously seen event subsequence that we believe can have previously unseen
@@ -58,6 +61,8 @@
* Phase 3. Releasing all threads and letting the test iteration run till its end.
*
* The iterations end when all seen paths have been declared “uncontinuable”.
+ *
+ * When we register event XXX:enter, we hold all other events until we register XXX:exit.
*/
public class RaceConditionReproducer implements RaceConditionTracker.EventProcessor {
private static final String TAG = "RaceConditionReproducer";
@@ -81,7 +86,7 @@
private final Map<String, EventNode> mNextEvents = new HashMap<>();
// Whether we believe that further iterations will not be able to add more events to
// mNextEvents.
- private boolean mStoppedAddingChildren = false;
+ private boolean mStoppedAddingChildren = true;
private void debugDump(StringBuilder sb, int indent, String name) {
for (int i = 0; i < indent; ++i) sb.append('.');
@@ -134,6 +139,8 @@
}
}
if (!mStoppedAddingChildren) {
+ // Mark that we have finished adding children. It will remain true if no new
+ // children are added, or will be set to false upon adding a new child.
mStoppedAddingChildren = true;
return true;
}
@@ -216,6 +223,7 @@
RaceConditionTracker.setEventProcessor(null);
runResumeAllEventsCallbackLocked();
assertTrue("Non-empty postponed events", mPostponedEvents.isEmpty());
+ assertTrue("Last registered event is :enter", lastEventAsEnter() == null);
// No events came after mLastRegisteredEvent. It doesn't make sense to come to it again
// because we won't see new continuations.
@@ -246,12 +254,36 @@
}
/**
+ * Returns whether the last event was not an XXX:enter, or this event is a matching XXX:exit.
+ */
+ private boolean canRegisterEventNowLocked(String event) {
+ final String lastEventAsEnter = lastEventAsEnter();
+ final String thisEventAsExit = eventAsExit(event);
+
+ if (lastEventAsEnter != null) {
+ if (!lastEventAsEnter.equals(thisEventAsExit)) {
+ assertTrue("YYY:exit after XXX:enter", thisEventAsExit == null);
+ // Last event was :enter, but this event is not :exit.
+ return false;
+ }
+ } else {
+ // Previous event was not :enter.
+ assertTrue(":exit after a non-enter event", thisEventAsExit == null);
+ }
+ return true;
+ }
+
+ /**
* Registers an event issued by the app and returns null or decides that the event must be
* postponed, and returns an object to wait on.
*/
private synchronized Semaphore tryRegisterEvent(String event) {
Log.d(TAG, "Event issued by the app: " + event);
+ if (!canRegisterEventNowLocked(event)) {
+ return createWaitObjectForPostponedEventLocked(event);
+ }
+
if (mRegisteredEventCount < mSequenceToFollow.size()) {
// We are in the first part of the iteration. We only register events that follow the
// mSequenceToFollow and postponing all other events.
@@ -288,9 +320,14 @@
return createWaitObjectForPostponedEventLocked(event);
}
} else {
- // The second phase of the iteration. We are past the growth point and register
+ // The third phase of the iteration. We are past the growth point and register
// everything that comes.
registerEventLocked(event);
+ // Register events that may have been postponed while waiting for an :exit event
+ // during the third phase. We don't do this if just registered event is :enter.
+ if (eventAsEnter(event) == null && mRegisteredEventCount > mSequenceToFollow.size()) {
+ registerPostponedEventsLocked(new HashSet<>(mPostponedEvents.keySet()));
+ }
}
return null;
}
@@ -347,6 +384,11 @@
private void registerPostponedEventsLocked(Collection<String> events) {
for (String event : events) {
registerPostponedEventLocked(event);
+ if (eventAsEnter(event) != null) {
+ // Once :enter is registered, switch to waiting for :exit to come. Won't register
+ // other postponed events.
+ break;
+ }
}
}
@@ -355,14 +397,51 @@
registerEventLocked(event);
}
+ /**
+ * If the last registered event was XXX:enter, returns XXX, otherwise, null.
+ */
+ private String lastEventAsEnter() {
+ return eventAsEnter(mCurrentSequence.substring(mCurrentSequence.lastIndexOf("|") + 1));
+ }
+
+ /**
+ * If the event is XXX:postfix, returns XXX, otherwise, null.
+ */
+ private static String prefixFromPostfixedEvent(String event, String postfix) {
+ final int columnPos = event.indexOf(':');
+ if (columnPos != -1 && postfix.equals(event.substring(columnPos + 1))) {
+ return event.substring(0, columnPos);
+ }
+ return null;
+ }
+
+ /**
+ * If the event is XXX:enter, returns XXX, otherwise, null.
+ */
+ private static String eventAsEnter(String event) {
+ return prefixFromPostfixedEvent(event, ENTER_POSTFIX);
+ }
+
+ /**
+ * If the event is XXX:exit, returns XXX, otherwise, null.
+ */
+ private static String eventAsExit(String event) {
+ return prefixFromPostfixedEvent(event, EXIT_POSTFIX);
+ }
+
private void registerEventLocked(String event) {
+ assertTrue(canRegisterEventNowLocked(event));
+
Log.d(TAG, "Actually registering event: " + event);
EventNode next = mLastRegisteredEvent.mNextEvents.get(event);
if (next == null) {
// This event wasn't seen after mLastRegisteredEvent.
next = new EventNode();
mLastRegisteredEvent.mNextEvents.put(event, next);
- mLastRegisteredEvent.mStoppedAddingChildren = false;
+ // The fact that we've added a new event after the previous one means that the
+ // previous event is still a growth point, unless this event is :exit, which means
+ // that the previous event is :enter.
+ mLastRegisteredEvent.mStoppedAddingChildren = eventAsExit(event) != null;
}
mLastRegisteredEvent = next;
@@ -371,12 +450,6 @@
if (mCurrentSequence.length() > 0) mCurrentSequence.append("|");
mCurrentSequence.append(event);
Log.d(TAG, "Repro sequence: " + mCurrentSequence);
-
- if (mRegisteredEventCount == mSequenceToFollow.size() + 1) {
- // We just entered the third phase of the iteration, i.e. registered an event after
- // the growth point. Now we can let go of all postponed events.
- runResumeAllEventsCallbackLocked();
- }
}
private void runResumeAllEventsCallbackLocked() {
diff --git a/tests/src/com/android/launcher3/util/RaceConditionReproducerTest.java b/tests/src/com/android/launcher3/util/RaceConditionReproducerTest.java
index 7dde5cc..3fc268e 100644
--- a/tests/src/com/android/launcher3/util/RaceConditionReproducerTest.java
+++ b/tests/src/com/android/launcher3/util/RaceConditionReproducerTest.java
@@ -77,6 +77,46 @@
}
@Test
+ @Ignore // The test is too long for continuous testing.
+ // 2 threads, 3 events, including enter-exit pairs each.
+ public void test3_3_enter_exit() throws Exception {
+ final RaceConditionReproducer eventProcessor = new RaceConditionReproducer();
+ boolean sawTheValidSequence = false;
+
+ for (; ; ) {
+ eventProcessor.startIteration();
+ Thread tb = new Thread(() -> {
+ RaceConditionTracker.onEvent("B1:enter");
+ RaceConditionTracker.onEvent("B1:exit");
+ RaceConditionTracker.onEvent("B2");
+ RaceConditionTracker.onEvent("B3:enter");
+ RaceConditionTracker.onEvent("B3:exit");
+ });
+ tb.start();
+
+ RaceConditionTracker.onEvent("A1");
+ RaceConditionTracker.onEvent("A2:enter");
+ RaceConditionTracker.onEvent("A2:exit");
+ RaceConditionTracker.onEvent("A3:enter");
+ RaceConditionTracker.onEvent("A3:exit");
+
+ tb.join();
+ final boolean needMoreIterations = eventProcessor.finishIteration();
+
+ sawTheValidSequence = sawTheValidSequence ||
+ "B1:enter|B1:exit|A1|A2:enter|A2:exit|B2|A3:enter|A3:exit|B3:enter|B3:exit".
+ equals(eventProcessor.getCurrentSequenceString());
+
+ if (!needMoreIterations) break;
+ }
+
+ assertEquals("Wrong number of leaf nodes",
+ factorial(3 + 3) / (factorial(3) * factorial(3)),
+ eventProcessor.numberOfLeafNodes());
+ assertTrue(sawTheValidSequence);
+ }
+
+ @Test
// 2 threads, 3 events each; reproducing a particular event sequence.
public void test3_3_ReproMode() throws Exception {
final RaceConditionReproducer eventProcessor = new RaceConditionReproducer(
@@ -122,4 +162,42 @@
factorial(2 + 2 + 1) / (factorial(2) * factorial(2) * factorial(1)),
eventProcessor.numberOfLeafNodes());
}
+
+ @Test
+ @Ignore // The test is too long for continuous testing.
+ // 2 threads with 2 events; 1 thread with 1 event. Includes enter-exit pairs.
+ public void test2_1_2_enter_exit() throws Exception {
+ final RaceConditionReproducer eventProcessor = new RaceConditionReproducer();
+
+ for (; ; ) {
+ eventProcessor.startIteration();
+ Thread tb = new Thread(() -> {
+ RaceConditionTracker.onEvent("B1:enter");
+ RaceConditionTracker.onEvent("B1:exit");
+ RaceConditionTracker.onEvent("B2:enter");
+ RaceConditionTracker.onEvent("B2:exit");
+ });
+ tb.start();
+
+ Thread tc = new Thread(() -> {
+ RaceConditionTracker.onEvent("C1:enter");
+ RaceConditionTracker.onEvent("C1:exit");
+ });
+ tc.start();
+
+ RaceConditionTracker.onEvent("A1:enter");
+ RaceConditionTracker.onEvent("A1:exit");
+ RaceConditionTracker.onEvent("A2:enter");
+ RaceConditionTracker.onEvent("A2:exit");
+
+ tb.join();
+ tc.join();
+
+ if (!eventProcessor.finishIteration()) break;
+ }
+
+ assertEquals("Wrong number of leaf nodes",
+ factorial(2 + 2 + 1) / (factorial(2) * factorial(2) * factorial(1)),
+ eventProcessor.numberOfLeafNodes());
+ }
}