Add logging for nearby.
Bug: 157234789 Test: with statsd_testdrive; new tests in ChooserActivityTest Change-Id: Iad154c4f18058b8a2c67aa6ca909d615db639f95
This commit is contained in:
@@ -206,6 +206,7 @@ public class ChooserActivity extends ResolverActivity implements
|
||||
public static final int SELECTION_TYPE_APP = 2;
|
||||
public static final int SELECTION_TYPE_STANDARD = 3;
|
||||
public static final int SELECTION_TYPE_COPY = 4;
|
||||
public static final int SELECTION_TYPE_NEARBY = 5;
|
||||
|
||||
private static final int SCROLL_STATUS_IDLE = 0;
|
||||
private static final int SCROLL_STATUS_SCROLLING_VERTICAL = 1;
|
||||
@@ -1135,7 +1136,8 @@ public class ChooserActivity extends ResolverActivity implements
|
||||
return displayContentPreview(previewType, targetIntent, getLayoutInflater(), parent);
|
||||
}
|
||||
|
||||
private ComponentName getNearbySharingComponent() {
|
||||
@VisibleForTesting
|
||||
protected ComponentName getNearbySharingComponent() {
|
||||
String nearbyComponent = Settings.Secure.getString(
|
||||
getContentResolver(),
|
||||
Settings.Secure.NEARBY_SHARING_COMPONENT);
|
||||
@@ -1148,7 +1150,8 @@ public class ChooserActivity extends ResolverActivity implements
|
||||
return ComponentName.unflattenFromString(nearbyComponent);
|
||||
}
|
||||
|
||||
private TargetInfo getNearbySharingTarget(Intent originalIntent) {
|
||||
@VisibleForTesting
|
||||
protected TargetInfo getNearbySharingTarget(Intent originalIntent) {
|
||||
final ComponentName cn = getNearbySharingComponent();
|
||||
if (cn == null) return null;
|
||||
|
||||
@@ -1216,14 +1219,21 @@ public class ChooserActivity extends ResolverActivity implements
|
||||
final TargetInfo ti = getNearbySharingTarget(originalIntent);
|
||||
if (ti == null) return null;
|
||||
|
||||
return createActionButton(
|
||||
final Button b = createActionButton(
|
||||
ti.getDisplayIcon(this),
|
||||
ti.getDisplayLabel(),
|
||||
(View unused) -> {
|
||||
// Log share completion via nearby
|
||||
getChooserActivityLogger().logShareTargetSelected(
|
||||
SELECTION_TYPE_NEARBY,
|
||||
"",
|
||||
-1);
|
||||
safelyStartActivity(ti);
|
||||
finish();
|
||||
}
|
||||
);
|
||||
b.setId(R.id.chooser_nearby_button);
|
||||
return b;
|
||||
}
|
||||
|
||||
private void addActionButton(ViewGroup parent, Button b) {
|
||||
@@ -2616,7 +2626,9 @@ public class ChooserActivity extends ResolverActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
static final class EmptyTargetInfo extends NotSelectableTargetInfo {
|
||||
protected static final class EmptyTargetInfo extends NotSelectableTargetInfo {
|
||||
public EmptyTargetInfo() {}
|
||||
|
||||
public Drawable getDisplayIcon(Context context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -116,7 +116,9 @@ public interface ChooserActivityLogger {
|
||||
@UiEvent(doc = "User selected a standard target.")
|
||||
SHARESHEET_STANDARD_TARGET_SELECTED(234),
|
||||
@UiEvent(doc = "User selected the copy target.")
|
||||
SHARESHEET_COPY_TARGET_SELECTED(235);
|
||||
SHARESHEET_COPY_TARGET_SELECTED(235),
|
||||
@UiEvent(doc = "User selected the nearby target.")
|
||||
SHARESHEET_NEARBY_TARGET_SELECTED(626);
|
||||
|
||||
private final int mId;
|
||||
SharesheetTargetSelectedEvent(int id) {
|
||||
@@ -136,6 +138,8 @@ public interface ChooserActivityLogger {
|
||||
return SHARESHEET_STANDARD_TARGET_SELECTED;
|
||||
case ChooserActivity.SELECTION_TYPE_COPY:
|
||||
return SHARESHEET_COPY_TARGET_SELECTED;
|
||||
case ChooserActivity.SELECTION_TYPE_NEARBY:
|
||||
return SHARESHEET_NEARBY_TARGET_SELECTED;
|
||||
default:
|
||||
return INVALID;
|
||||
}
|
||||
|
||||
@@ -197,6 +197,9 @@
|
||||
<!-- Marks the "copy to clipboard" button in the ChooserActivity -->
|
||||
<item type="id" name="chooser_copy_button" />
|
||||
|
||||
<!-- Marks the "nearby" button in the ChooserActivity -->
|
||||
<item type="id" name="chooser_nearby_button" />
|
||||
|
||||
<!-- Accessibility action identifier for {@link android.accessibilityservice.AccessibilityService#GLOBAL_ACTION_BACK}. -->
|
||||
<item type="id" name="accessibilitySystemActionBack" />
|
||||
|
||||
|
||||
@@ -3841,6 +3841,7 @@
|
||||
<java-symbol type="layout" name="chooser_dialog_item" />
|
||||
<java-symbol type="drawable" name="chooser_dialog_background" />
|
||||
<java-symbol type="id" name="chooser_copy_button" />
|
||||
<java-symbol type="id" name="chooser_nearby_button" />
|
||||
<java-symbol type="layout" name="chooser_action_button" />
|
||||
<java-symbol type="dimen" name="chooser_action_button_icon_size" />
|
||||
<java-symbol type="string" name="config_defaultNearbySharingComponent" />
|
||||
|
||||
@@ -590,6 +590,54 @@ public class ChooserActivityTest {
|
||||
is(1));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNearbyShareLogging() throws Exception {
|
||||
Intent sendIntent = createSendTextIntent();
|
||||
List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2);
|
||||
|
||||
when(ChooserWrapperActivity.sOverrides.resolverListController.getResolversForIntent(
|
||||
Mockito.anyBoolean(),
|
||||
Mockito.anyBoolean(),
|
||||
Mockito.isA(List.class))).thenReturn(resolvedComponentInfos);
|
||||
|
||||
final ChooserWrapperActivity activity = mActivityRule
|
||||
.launchActivity(Intent.createChooser(sendIntent, null));
|
||||
waitForIdle();
|
||||
|
||||
onView(withId(R.id.chooser_nearby_button)).check(matches(isDisplayed()));
|
||||
onView(withId(R.id.chooser_nearby_button)).perform(click());
|
||||
|
||||
ChooserActivityLoggerFake logger =
|
||||
(ChooserActivityLoggerFake) activity.getChooserActivityLogger();
|
||||
assertThat(logger.numCalls(), is(6));
|
||||
// first one should be SHARESHEET_TRIGGERED uievent
|
||||
assertThat(logger.get(0).atomId, is(FrameworkStatsLog.UI_EVENT_REPORTED));
|
||||
assertThat(logger.get(0).event.getId(),
|
||||
is(ChooserActivityLogger.SharesheetStandardEvent.SHARESHEET_TRIGGERED.getId()));
|
||||
// second one should be SHARESHEET_STARTED event
|
||||
assertThat(logger.get(1).atomId, is(FrameworkStatsLog.SHARESHEET_STARTED));
|
||||
assertThat(logger.get(1).intent, is(Intent.ACTION_SEND));
|
||||
assertThat(logger.get(1).mimeType, is("text/plain"));
|
||||
assertThat(logger.get(1).packageName, is("com.android.frameworks.coretests"));
|
||||
assertThat(logger.get(1).appProvidedApp, is(0));
|
||||
assertThat(logger.get(1).appProvidedDirect, is(0));
|
||||
assertThat(logger.get(1).isWorkprofile, is(false));
|
||||
assertThat(logger.get(1).previewType, is(3));
|
||||
// third one should be SHARESHEET_APP_LOAD_COMPLETE uievent
|
||||
assertThat(logger.get(2).atomId, is(FrameworkStatsLog.UI_EVENT_REPORTED));
|
||||
assertThat(logger.get(2).event.getId(),
|
||||
is(ChooserActivityLogger
|
||||
.SharesheetStandardEvent.SHARESHEET_APP_LOAD_COMPLETE.getId()));
|
||||
// fourth and fifth are just artifacts of test set-up
|
||||
// sixth one should be ranking atom with SHARESHEET_NEARBY_TARGET_SELECTED event
|
||||
assertThat(logger.get(5).atomId, is(FrameworkStatsLog.RANKING_SELECTED));
|
||||
assertThat(logger.get(5).targetType,
|
||||
is(ChooserActivityLogger
|
||||
.SharesheetTargetSelectedEvent.SHARESHEET_NEARBY_TARGET_SELECTED.getId()));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void oneVisibleImagePreview() throws InterruptedException {
|
||||
Uri uri = Uri.parse("android.resource://com.android.frameworks.coretests/"
|
||||
|
||||
@@ -21,6 +21,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.usage.UsageStatsManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -89,6 +90,18 @@ public class ChooserWrapperActivity extends ChooserActivity {
|
||||
|
||||
boolean getIsSelected() { return mIsSuccessfullySelected; }
|
||||
|
||||
@Override
|
||||
protected ComponentName getNearbySharingComponent() {
|
||||
// an arbitrary pre-installed activity that handles this type of intent
|
||||
return ComponentName.unflattenFromString("com.google.android.apps.messaging/"
|
||||
+ "com.google.android.apps.messaging.ui.conversationlist.ShareIntentActivity");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TargetInfo getNearbySharingTarget(Intent originalIntent) {
|
||||
return new ChooserWrapperActivity.EmptyTargetInfo();
|
||||
}
|
||||
|
||||
UsageStatsManager getUsageStatsManager() {
|
||||
if (mUsm == null) {
|
||||
mUsm = (UsageStatsManager) getSystemService(Context.USAGE_STATS_SERVICE);
|
||||
|
||||
Reference in New Issue
Block a user