Merge "[automerger skipped] Merge "Clean up bugreport API." am: 2e44838064 am: 8deb2ecb31 am: ec0a01ec78 -s ours am skip reason: change_id I95f004106ba97bc9e99859a8b23b96a86b6a43f4 with SHA1 552e257a9d is in history"
diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java
index 79cf4c42..8d8ec4d 100644
--- a/core/java/com/android/internal/app/ChooserActivity.java
+++ b/core/java/com/android/internal/app/ChooserActivity.java
@@ -318,9 +318,7 @@
// Do not allow the title to be changed when sharing content
CharSequence title = null;
if (target != null) {
- String targetAction = target.getAction();
- if (!(Intent.ACTION_SEND.equals(targetAction) || Intent.ACTION_SEND_MULTIPLE.equals(
- targetAction))) {
+ if (!isSendAction(target)) {
title = intent.getCharSequenceExtra(Intent.EXTRA_TITLE);
} else {
Log.w(TAG, "Ignoring intent's EXTRA_TITLE, deprecated in P. You may wish to set a"
@@ -444,7 +442,7 @@
.getDimensionPixelSize(R.dimen.chooser_service_spacing);
// expand/shrink direct share 4 -> 8 viewgroup
- if (mResolverDrawerLayout != null) {
+ if (mResolverDrawerLayout != null && isSendAction(target)) {
mResolverDrawerLayout.setOnScrollChangeListener(this::handleScroll);
}
@@ -470,13 +468,8 @@
public void setHeader() {
super.setHeader();
- Intent targetIntent = getTargetIntent();
- if (targetIntent == null) {
- return;
- }
-
- String action = targetIntent.getAction();
- if (!(Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action))) {
+ final Intent targetIntent = getTargetIntent();
+ if (!isSendAction(targetIntent)) {
return;
}
@@ -943,9 +936,7 @@
}
private void modifyTargetIntent(Intent in) {
- final String action = in.getAction();
- if (Intent.ACTION_SEND.equals(action) ||
- Intent.ACTION_SEND_MULTIPLE.equals(action)) {
+ if (isSendAction(in)) {
in.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
}
@@ -1939,7 +1930,11 @@
}
public int getServiceTargetCount() {
- return Math.min(mServiceTargets.size(), MAX_SERVICE_TARGETS);
+ if (isSendAction(getTargetIntent())) {
+ return Math.min(mServiceTargets.size(), MAX_SERVICE_TARGETS);
+ }
+
+ return 0;
}
public int getStandardTargetCount() {
@@ -2088,6 +2083,23 @@
}
}
+ private boolean isSendAction(Intent targetIntent) {
+ if (targetIntent == null) {
+ return false;
+ }
+
+ String action = targetIntent.getAction();
+ if (action == null) {
+ return false;
+ }
+
+ if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
+ return true;
+ }
+
+ return false;
+ }
+
class ChooserRowAdapter extends BaseAdapter {
private ChooserListAdapter mChooserListAdapter;
private final LayoutInflater mLayoutInflater;
@@ -2141,7 +2153,10 @@
// There can be at most one row in the listview, that is internally
// a ViewGroup with 2 rows
public int getServiceTargetRowCount() {
- return 1;
+ if (isSendAction(getTargetIntent())) {
+ return 1;
+ }
+ return 0;
}
@Override
diff --git a/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java b/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java
index 3578bc0..4277b5a 100644
--- a/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java
+++ b/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java
@@ -97,9 +97,12 @@
when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(),
Mockito.anyBoolean(),
Mockito.isA(List.class))).thenReturn(resolvedComponentInfos);
- mActivityRule.launchActivity(Intent.createChooser(viewIntent, "chooser test"));
+ final ChooserWrapperActivity activity = mActivityRule.launchActivity(
+ Intent.createChooser(viewIntent, "chooser test"));
waitForIdle();
+ assertThat(activity.getAdapter().getCount(), is(2));
+ assertThat(activity.getAdapter().getServiceTargetCount(), is(0));
onView(withId(R.id.title)).check(matches(withText("chooser test")));
}
diff --git a/core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java b/core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java
index a8dd69a..5e71129 100644
--- a/core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java
+++ b/core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java
@@ -39,8 +39,8 @@
static final OverrideData sOverrides = new OverrideData();
private UsageStatsManager mUsm;
- ResolveListAdapter getAdapter() {
- return mAdapter;
+ ChooserListAdapter getAdapter() {
+ return (ChooserListAdapter) mAdapter;
}
boolean getIsSelected() { return mIsSuccessfullySelected; }