Merge "Add logging for nearby."

This commit is contained in:
TreeHugger Robot
2020-08-07 18:51:09 +00:00
committed by Android (Google) Code Review
6 changed files with 86 additions and 5 deletions

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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" />

View File

@@ -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" />

View File

@@ -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/"

View File

@@ -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);