Loading core/java/com/android/internal/app/ChooserActivity.java +16 −4 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading @@ -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; Loading Loading @@ -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) { Loading Loading @@ -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; } Loading core/java/com/android/internal/app/ChooserActivityLogger.java +5 −1 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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; } Loading core/res/res/values/ids.xml +3 −0 Original line number Diff line number Diff line Loading @@ -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" /> Loading core/res/res/values/symbols.xml +1 −0 Original line number Diff line number Diff line Loading @@ -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" /> Loading core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java +48 −0 Original line number Diff line number Diff line Loading @@ -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/" Loading Loading
core/java/com/android/internal/app/ChooserActivity.java +16 −4 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading @@ -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; Loading Loading @@ -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) { Loading Loading @@ -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; } Loading
core/java/com/android/internal/app/ChooserActivityLogger.java +5 −1 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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; } Loading
core/res/res/values/ids.xml +3 −0 Original line number Diff line number Diff line Loading @@ -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" /> Loading
core/res/res/values/symbols.xml +1 −0 Original line number Diff line number Diff line Loading @@ -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" /> Loading
core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java +48 −0 Original line number Diff line number Diff line Loading @@ -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/" Loading