Commit c945299c authored by tedchoc's avatar tedchoc Committed by Commit bot

Ensure CATEGORY_LAUNCHER exists for MAIN intents for NTP inactivity/logging.

For the logging of main intent metrics and creating NTPs due to
inactivity, we only want to do this if we believe the user came
from the launcher.  Chrome sends itself MAIN intents and those
should not be counted towards this.

We should follow up and remove dispatching MAIN intents to ourself
as a followup, but this is a step towards the intent of this logging
and behavior.

Adds a test that if we get a MAIN intent without the launcher
category, that we are not going to be waiting for a behavior to
be logged via the main intent tracker.

BUG=717754

Review-Url: https://codereview.chromium.org/2858043007
Cr-Commit-Position: refs/heads/master@{#469441}
parent aa944155
......@@ -576,7 +576,7 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode
TraceEvent.begin("ChromeTabbedActivity.onNewIntentWithNative");
super.onNewIntentWithNative(intent);
if (isMainIntent(intent)) {
if (isMainIntentFromLauncher(intent)) {
if (IntentHandler.getUrlFromIntent(intent) == null) {
maybeLaunchNtpFromMainIntent(intent);
}
......@@ -737,18 +737,25 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode
textBubble.show();
}
private boolean isMainIntent(Intent intent) {
return intent != null && TextUtils.equals(intent.getAction(), Intent.ACTION_MAIN);
private boolean isMainIntentFromLauncher(Intent intent) {
return intent != null && TextUtils.equals(intent.getAction(), Intent.ACTION_MAIN)
&& intent.hasCategory(Intent.CATEGORY_LAUNCHER);
}
private void logMainIntentBehavior(Intent intent) {
assert isMainIntent(intent);
assert isMainIntentFromLauncher(intent);
long currentTime = System.currentTimeMillis();
long lastBackgroundedTimeMs = ContextUtils.getAppSharedPreferences().getLong(
LAST_BACKGROUNDED_TIME_MS_PREF, currentTime);
mMainIntentMetrics.onMainIntentWithNative(currentTime - lastBackgroundedTimeMs);
}
/** Access the main intent metrics for test validation. */
@VisibleForTesting
public MainIntentBehaviorMetrics getMainIntentBehaviorMetricsForTesting() {
return mMainIntentMetrics;
}
/**
* Determines if the intent should trigger an NTP and launches it if applicable.
*
......@@ -756,7 +763,7 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode
* @return Whether an NTP was triggered as a result of this intent.
*/
private boolean maybeLaunchNtpFromMainIntent(Intent intent) {
assert isMainIntent(intent);
assert isMainIntentFromLauncher(intent);
if (!mIntentHandler.isIntentUserVisible()) return false;
if (FeatureUtilities.isChromeHomeEnabled()) return false;
......@@ -860,7 +867,7 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode
mIntentWithEffect = mIntentHandler.onNewIntent(intent);
}
if (isMainIntent(intent)) {
if (isMainIntentFromLauncher(intent)) {
if (IntentHandler.getUrlFromIntent(intent) == null) {
assert !mIntentWithEffect
: "ACTION_MAIN should not have triggered any prior action";
......
......@@ -161,6 +161,13 @@ public class MainIntentBehaviorMetrics implements ApplicationStatus.ActivityStat
sTimeoutDurationMs = duration;
}
/**
* @return Whether we are pending action for a received main intent.
*/
public boolean getPendingActionRecordForMainIntent() {
return mPendingActionRecordForMainIntent;
}
private String getHistogramNameForBehavior(@MainIntentActionType int behavior) {
switch (behavior) {
case CONTINUATION:
......
......@@ -4,8 +4,10 @@
package org.chromium.chrome.browser.metrics;
import android.content.Intent;
import android.support.test.filters.MediumTest;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -122,6 +124,15 @@ public class MainIntentBehaviorMetricsIntegrationTest {
}
}
@MediumTest
@Test
public void testMainIntentWithLauncherCategory() throws InterruptedException {
mActivityTestRule.startMainActivityFromIntent(new Intent(Intent.ACTION_MAIN), null);
assertMainIntentBehavior(null);
Assert.assertFalse(mActivityTestRule.getActivity().getMainIntentBehaviorMetricsForTesting()
.getPendingActionRecordForMainIntent());
}
private void assertMainIntentBehavior(Integer expected) {
CriteriaHelper.pollUiThread(Criteria.equals(expected, new Callable<Integer>() {
@Override
......
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