Commit bf7b4208 authored by Justin Donnelly's avatar Justin Donnelly Committed by Commit Bot

Revert "Reland: Remove SeparateTaskCustomTabActivity for Android version > L."

This reverts commit 8eed4853.

Reason for revert: Suspected of breaking the following test:
org.chromium.chrome.browser.browseractions.BrowserActionActivityTest.testOpenSingleTabInBackgroundWhenChromeAvailable

On the Android CFI bot:
https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/Android%20CFI

Original change's description:
> Reland: Remove SeparateTaskCustomTabActivity for Android version > L.
> 
> Cause of revert:
> ===============
> A few MediaLauncherActivityTest don't run on the CQ. They were waiting
> on SeparateTaskCustomTabActivity to finish, but it is no more used.
> 
> Original description:
> =====================
> Remove SeparateTaskcustomTabActivity for Android version > L.
> 
> Make SeparateTaskcustomTabActivity to be used only for Android version
> pre L. The part used for Android version >= L is merged into
> CustomTabActivity.
> 
> This is a prerequisite for skipping the ChromeLauncherActivity and
> directly launch the CustomTabActivity.
> 
> TBR=tedchoc@chromium.org
> R=​lizeb@chromium.org
> 
> Bug: 681559
> Change-Id: I121241a2f43f62c346a24adb153649bec3b80af3
> Reviewed-on: https://chromium-review.googlesource.com/1201845
> Reviewed-by: Benoit L <lizeb@chromium.org>
> Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#588788}

TBR=lizeb@chromium.org,arthursonzogni@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 681559
Change-Id: I002cddd65d1fc326c5a212671d4f7d07355689a6
Reviewed-on: https://chromium-review.googlesource.com/1211242Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Commit-Queue: Justin Donnelly <jdonnelly@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589233}
parent 03c59d89
...@@ -387,11 +387,6 @@ by a child template that "extends" this file. ...@@ -387,11 +387,6 @@ by a child template that "extends" this file.
{{ self.supports_vr() }} {{ self.supports_vr() }}
{{ self.extra_web_rendering_activity_definitions() }} {{ self.extra_web_rendering_activity_definitions() }}
</activity> </activity>
<!-- SeparateTaskCustomTabActivity is a wrapper of CustomTabActivity. It provides the
general feeling of supporting multi tasks, even for versions that did not fully support
it.
TODO(arthursonzogni, tedchoc): Enabled this only on Android < 21 after M74.
-->
<activity android:name="org.chromium.chrome.browser.customtabs.SeparateTaskCustomTabActivity" <activity android:name="org.chromium.chrome.browser.customtabs.SeparateTaskCustomTabActivity"
android:theme="@style/MainTheme" android:theme="@style/MainTheme"
android:exported="false" android:exported="false"
...@@ -404,23 +399,21 @@ by a child template that "extends" this file. ...@@ -404,23 +399,21 @@ by a child template that "extends" this file.
{{ self.supports_vr() }} {{ self.supports_vr() }}
{{ self.extra_web_rendering_activity_definitions() }} {{ self.extra_web_rendering_activity_definitions() }}
</activity> </activity>
{% if min_sdk_version|int < 21 %} {% for i in range(10) %}
{% for i in range(10) %} <activity android:name="org.chromium.chrome.browser.customtabs.SeparateTaskCustomTabActivity{{ i }}"
<activity android:name="org.chromium.chrome.browser.customtabs.SeparateTaskCustomTabActivity{{ i }}" android:theme="@style/MainTheme"
android:theme="@style/MainTheme" android:icon="@mipmap/app_single_page_icon"
android:icon="@mipmap/app_single_page_icon" android:exported="false"
android:exported="false" android:launchMode="singleTask"
android:launchMode="singleTask" android:persistableMode="persistNever"
android:persistableMode="persistNever" android:taskAffinity=""
android:taskAffinity="" {{ self.chrome_activity_common() }}
{{ self.chrome_activity_common() }} {{ self.supports_video_persistence() }}
{{ self.supports_video_persistence() }} >
> {{ self.supports_vr() }}
{{ self.supports_vr() }} {{ self.extra_web_rendering_activity_definitions() }}
{{ self.extra_web_rendering_activity_definitions() }} </activity>
</activity> {% endfor %}
{% endfor %}
{% endif %}
<activity android:name="org.chromium.chrome.browser.incognito.IncognitoDisclosureActivity" <activity android:name="org.chromium.chrome.browser.incognito.IncognitoDisclosureActivity"
android:theme="@style/FullscreenTransparentActivityTheme" android:theme="@style/FullscreenTransparentActivityTheme"
......
...@@ -300,40 +300,34 @@ public class LaunchIntentDispatcher implements IntentHandler.IntentHandlerDelega ...@@ -300,40 +300,34 @@ public class LaunchIntentDispatcher implements IntentHandler.IntentHandlerDelega
newIntent.setFlags(newIntent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); newIntent.setFlags(newIntent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
} }
// Handle activity started in a new task. // If a CCT intent triggers First Run, then NEW_TASK will be automatically applied. As
// See https://developer.android.com/guide/components/activities/tasks-and-back-stack // part of that, it will inherit the EXCLUDE_FROM_RECENTS bit from ChromeLauncherActivity,
// so explicitly remove it to ensure the CCT does not get lost in recents.
if ((newIntent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0 if ((newIntent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0
|| (newIntent.getFlags() & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0) { || (newIntent.getFlags() & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0) {
// If a CCT intent triggers First Run, then NEW_TASK will be automatically applied. As
// part of that, it will inherit the EXCLUDE_FROM_RECENTS bit from
// ChromeLauncherActivity, so explicitly remove it to ensure the CCT does not get lost
// in recents.
newIntent.setFlags(newIntent.getFlags() & ~Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); newIntent.setFlags(newIntent.getFlags() & ~Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
String uuid = UUID.randomUUID().toString();
// Android will try to find and reuse an existing CCT activity in the background. Use
// this flag to always start a new one instead.
newIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); newIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Provide the general feeling of supporting multi tasks in Android version that did not // Force a new document L+ to ensure the proper task/stack creation.
// fully support them. Reuse the least recently used SeparateTaskCustomTabActivity newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
// instance. newIntent.setClassName(context, SeparateTaskCustomTabActivity.class.getName());
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { } else {
String uuid = UUID.randomUUID().toString();
int activityIndex = ActivityAssigner int activityIndex = ActivityAssigner
.instance(ActivityAssigner.ActivityAssignerNamespace .instance(ActivityAssigner.ActivityAssignerNamespace
.SEPARATE_TASK_CCT_NAMESPACE) .SEPARATE_TASK_CCT_NAMESPACE)
.assign(uuid); .assign(uuid);
String className = SeparateTaskCustomTabActivity.class.getName() + activityIndex; String className = SeparateTaskCustomTabActivity.class.getName() + activityIndex;
newIntent.setClassName(context, className); newIntent.setClassName(context, className);
String url = IntentHandler.getUrlFromIntent(newIntent);
assert url != null;
newIntent.setData(new Uri.Builder()
.scheme(UrlConstants.CUSTOM_TAB_SCHEME)
.authority(uuid)
.query(url)
.build());
} }
String url = IntentHandler.getUrlFromIntent(newIntent);
assert url != null;
newIntent.setData(new Uri.Builder()
.scheme(UrlConstants.CUSTOM_TAB_SCHEME)
.authority(uuid)
.query(url)
.build());
} }
// If the previous caller was not Chrome, but added EXTRA_IS_OPENED_BY_CHROME for malicious // If the previous caller was not Chrome, but added EXTRA_IS_OPENED_BY_CHROME for malicious
......
...@@ -15,7 +15,6 @@ import android.graphics.Color; ...@@ -15,7 +15,6 @@ import android.graphics.Color;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.StrictMode; import android.os.StrictMode;
import android.os.SystemClock; import android.os.SystemClock;
...@@ -47,7 +46,6 @@ import org.chromium.base.library_loader.LibraryLoader; ...@@ -47,7 +46,6 @@ import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction; import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ActivityTabTaskDescriptionHelper;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeFeatureList; import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
...@@ -197,19 +195,6 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -197,19 +195,6 @@ public class CustomTabActivity extends ChromeActivity {
private boolean mModuleOnResumePending; private boolean mModuleOnResumePending;
private boolean mHasSetOverlayView; private boolean mHasSetOverlayView;
private ActivityTabTaskDescriptionHelper mTaskDescriptionHelper;
/**
* Return true when the activity has been launched in a separate task. The default behavior is
* to reuse the same task and put the activity on top of the previous one (i.e hiding it). A
* separate task creates a new entry in the Android recent screen.
**/
private boolean useSeparateTask() {
final int separateTaskFlags =
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
return (getIntent().getFlags() & separateTaskFlags) != 0;
}
private TabModelObserver mCloseActivityWhenEmptyTabModelObserver = new EmptyTabModelObserver() { private TabModelObserver mCloseActivityWhenEmptyTabModelObserver = new EmptyTabModelObserver() {
@Override @Override
public void didCloseTab(int tabId, boolean incognito) { public void didCloseTab(int tabId, boolean incognito) {
...@@ -683,11 +668,6 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -683,11 +668,6 @@ public class CustomTabActivity extends ChromeActivity {
mTrustedWebActivityUi.initialShowSnackbarIfNeeded(); mTrustedWebActivityUi.initialShowSnackbarIfNeeded();
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && useSeparateTask()) {
mTaskDescriptionHelper = new ActivityTabTaskDescriptionHelper(this,
ApiCompatibilityUtils.getColor(getResources(), R.color.default_primary_color));
}
super.finishNativeInitialization(); super.finishNativeInitialization();
} }
...@@ -930,8 +910,6 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -930,8 +910,6 @@ public class CustomTabActivity extends ChromeActivity {
if (mIncognitoTabHost != null) { if (mIncognitoTabHost != null) {
IncognitoTabHostRegistry.getInstance().unregister(mIncognitoTabHost); IncognitoTabHostRegistry.getInstance().unregister(mIncognitoTabHost);
} }
if (mTaskDescriptionHelper != null) mTaskDescriptionHelper.destroy();
} }
@Override @Override
...@@ -1101,11 +1079,8 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -1101,11 +1079,8 @@ public class CustomTabActivity extends ChromeActivity {
* recents. * recents.
*/ */
protected void handleFinishAndClose() { protected void handleFinishAndClose() {
if (useSeparateTask()) { // When on top of another app, finish is all that is required.
ApiCompatibilityUtils.finishAndRemoveTask(this); finish();
} else {
finish();
}
} }
@Override @Override
......
...@@ -3,11 +3,39 @@ ...@@ -3,11 +3,39 @@
// found in the LICENSE file. // found in the LICENSE file.
package org.chromium.chrome.browser.customtabs; package org.chromium.chrome.browser.customtabs;
import android.os.Build;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ActivityTabTaskDescriptionHelper;
/** /**
* Wrapper around the CustomTabActivity for Android version pre L to be used when launching * Simple wrapper around the CustomTabActivity to be used when launching each CustomTab in a
* each CustomTab in a separate task. This class is copied 10 times as * separate task.
* SeparateTaskCustomTabActivity${i} to "emulate" having multi task being supported.
*
* TODO(arthursonzogni, tedchoc): Remove this after M74.
*/ */
public class SeparateTaskCustomTabActivity extends CustomTabActivity {} public class SeparateTaskCustomTabActivity extends CustomTabActivity {
private ActivityTabTaskDescriptionHelper mTaskDescriptionHelper;
@Override
public void finishNativeInitialization() {
super.finishNativeInitialization();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mTaskDescriptionHelper = new ActivityTabTaskDescriptionHelper(this,
ApiCompatibilityUtils.getColor(getResources(), R.color.default_primary_color));
}
}
@Override
protected void onDestroyInternal() {
super.onDestroyInternal();
if (mTaskDescriptionHelper != null) mTaskDescriptionHelper.destroy();
}
@Override
protected void handleFinishAndClose() {
ApiCompatibilityUtils.finishAndRemoveTask(this);
}
}
...@@ -24,7 +24,7 @@ import org.chromium.base.CollectionUtil; ...@@ -24,7 +24,7 @@ import org.chromium.base.CollectionUtil;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.UrlUtils; import org.chromium.base.test.util.UrlUtils;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.customtabs.CustomTabActivity; import org.chromium.chrome.browser.customtabs.SeparateTaskCustomTabActivity;
import org.chromium.chrome.browser.customtabs.SeparateTaskCustomTabActivity0; import org.chromium.chrome.browser.customtabs.SeparateTaskCustomTabActivity0;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
...@@ -122,10 +122,10 @@ public class MediaLauncherActivityTest { ...@@ -122,10 +122,10 @@ public class MediaLauncherActivityTest {
private void waitForCustomTabActivityToStart(Callable<Void> trigger, String expectedUrl) private void waitForCustomTabActivityToStart(Callable<Void> trigger, String expectedUrl)
throws Exception { throws Exception {
CustomTabActivity cta; SeparateTaskCustomTabActivity cta;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cta = ActivityUtils.waitForActivity( cta = ActivityUtils.waitForActivity(InstrumentationRegistry.getInstrumentation(),
InstrumentationRegistry.getInstrumentation(), CustomTabActivity.class, trigger); SeparateTaskCustomTabActivity.class, trigger);
} else { } else {
cta = ActivityUtils.waitForActivity(InstrumentationRegistry.getInstrumentation(), cta = ActivityUtils.waitForActivity(InstrumentationRegistry.getInstrumentation(),
SeparateTaskCustomTabActivity0.class, trigger); SeparateTaskCustomTabActivity0.class, trigger);
......
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