Commit 5d52e576 authored by Gang Wu's avatar Gang Wu Committed by Commit Bot

Reland "Reland "[Omnibox] Use ActivityState to check if we are in browser mode""

This is a reland of 5ae112d1

Original change's description:
> Reland "[Omnibox] Use ActivityState to check if we are in browser mode"
> 
> This is a reland of be1e9636
> 
> Update the test to run on UI thread.
> 
> Original change's description:
> > [Omnibox] Use ActivityState to check if we are in browser mode
> >
> >
> > In multi windows mode, check if we are in browser mode by WindowAndroid
> > is not working, should check ActivityState instead.
> >
> > Bug: 1102640
> > Change-Id: I35a720a2aa6f337cc9f9ae43e39d83c9368fcb5a
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2286478
> > Commit-Queue: Gang Wu <gangwu@chromium.org>
> > Reviewed-by: Ted Choc <tedchoc@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#786636}
> 
> Bug: 1102640
> Change-Id: Iefba5a5d0c181535bd7fb86cf0e073be2ebdbcdb
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2293074
> Reviewed-by: Ted Choc <tedchoc@chromium.org>
> Commit-Queue: Gang Wu <gangwu@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#788816}

Bug: 1102640
Change-Id: I6da3c7ad8402cef83083a53f7ffc517f975720f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2301285
Commit-Queue: Gang Wu <gangwu@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789727}
parent 85663d61
...@@ -20,6 +20,7 @@ import androidx.annotation.Px; ...@@ -20,6 +20,7 @@ import androidx.annotation.Px;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import org.chromium.base.ActivityState;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.IntentUtils; import org.chromium.base.IntentUtils;
...@@ -576,9 +577,10 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener, StartStopWi ...@@ -576,9 +577,10 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener, StartStopWi
} }
// When invoked directly from a browser, we want to trigger switch to tab animation. // When invoked directly from a browser, we want to trigger switch to tab animation.
// If invoded from other activitiies, ex. searchActivity, we do not need to trigger the // If invoked from other activities, ex. searchActivity, we do not need to trigger the
// animation since Android will show the animation for switching apps. // animation since Android will show the animation for switching apps.
if (mWindowAndroid.equals(tab.getWindowAndroid())) { if (tab.getWindowAndroid().getActivityState() != ActivityState.STOPPED
&& tab.getWindowAndroid().getActivityState() != ActivityState.DESTROYED) {
// TODO(1097292): Do not use Activity to get TabModelSelector. // TODO(1097292): Do not use Activity to get TabModelSelector.
assert tab.getWindowAndroid().getActivity().get() instanceof ChromeActivity; assert tab.getWindowAndroid().getActivity().get() instanceof ChromeActivity;
...@@ -589,13 +591,13 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener, StartStopWi ...@@ -589,13 +591,13 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener, StartStopWi
chromeActivity.getTabModelSelector().getCurrentModel().setIndex( chromeActivity.getTabModelSelector().getCurrentModel().setIndex(
tabIndex, TabSelectionType.FROM_OMNIBOX); tabIndex, TabSelectionType.FROM_OMNIBOX);
} else { } else {
// Browser is in background, bring to to foreground and switch to the tab.
Intent newIntent = ChromeIntentUtil.createBringTabToFrontIntent(tab.getId()); Intent newIntent = ChromeIntentUtil.createBringTabToFrontIntent(tab.getId());
if (newIntent != null) { if (newIntent != null) {
newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
IntentUtils.safeStartActivity(ContextUtils.getApplicationContext(), newIntent); IntentUtils.safeStartActivity(ContextUtils.getApplicationContext(), newIntent);
} }
} }
recordMetrics(position, WindowOpenDisposition.SWITCH_TO_TAB, suggestion); recordMetrics(position, WindowOpenDisposition.SWITCH_TO_TAB, suggestion);
} }
......
...@@ -203,7 +203,7 @@ public class TestTouchUtils { ...@@ -203,7 +203,7 @@ public class TestTouchUtils {
* @param v The view to call performClick on. * @param v The view to call performClick on.
*/ */
public static void performClickOnMainSync(Instrumentation instrumentation, final View v) { public static void performClickOnMainSync(Instrumentation instrumentation, final View v) {
instrumentation.runOnMainSync(() -> v.performClick()); TestThreadUtils.runOnUiThreadBlocking(() -> { v.performClick(); });
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment