Always use chooser for Share Bug Report intent.

When using startActivity(intent), the platform allows the user to pick
the same activity for the intent, which can be a problem for sharing bug
reports when the device has personal and work profiles.

Change-Id: I1fd66905feb5d894307bbe5656c2aec705a59ab7
Fixes: 22115530
This commit is contained in:
Felipe Leme
2016-07-28 15:16:55 -07:00
parent e116bcf72a
commit 91699af8c6
5 changed files with 23 additions and 45 deletions

View File

@@ -76,4 +76,7 @@
<!-- Label of button that save bugreport details. -->
<string name="save">Save</string>
<!-- Title displayed in the activity chooser used to share the bug report [CHAR LIMIT=30]-->
<string name="bugreport_intent_chooser_title">Share Bug report</string>
</resources>

View File

@@ -1000,12 +1000,17 @@ public class BugreportProgressService extends Service {
notifIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Send the share intent...
mContext.startActivity(notifIntent);
sendShareIntent(mContext, notifIntent);
// ... and stop watching this process.
stopProgress(id);
}
static void sendShareIntent(Context context, Intent intent) {
context.startActivity(Intent.createChooser(intent,
context.getResources().getText(R.string.bugreport_intent_chooser_title)));
}
/**
* Sends a notification indicating the bugreport has finished so use can share it.
*/

View File

@@ -21,6 +21,7 @@ import static com.android.shell.BugreportPrefs.STATE_SHOW;
import static com.android.shell.BugreportPrefs.STATE_UNKNOWN;
import static com.android.shell.BugreportPrefs.getWarningState;
import static com.android.shell.BugreportPrefs.setWarningState;
import static com.android.shell.BugreportProgressService.sendShareIntent;
import android.app.AlertDialog;
import android.content.DialogInterface;
@@ -78,7 +79,7 @@ public class BugreportWarningActivity extends AlertActivity
if (which == AlertDialog.BUTTON_POSITIVE) {
// Remember confirm state, and launch target
setWarningState(this, mConfirmRepeat.isChecked() ? STATE_HIDE : STATE_SHOW);
startActivity(mSendIntent);
sendShareIntent(this, mSendIntent);
}
finish();

View File

@@ -175,6 +175,8 @@ public class BugreportReceiverTest extends InstrumentationTestCase {
mDescription = sb.toString();
setWarningState(mContext, STATE_HIDE);
mUiBot.turnScreenOn();
}
public void testProgress() throws Exception {

View File

@@ -22,7 +22,6 @@ import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiScrollable;
import android.support.test.uiautomator.UiSelector;
import android.support.test.uiautomator.Until;
import android.util.Log;
@@ -156,56 +155,24 @@ final class UiBot {
}
/**
* Chooses a given activity to handle an Intent, using the "Just Once" button.
* Chooses a given activity to handle an Intent.
*
* @param name name of the activity as displayed in the UI (typically the value set by
* {@code android:label} in the manifest).
*/
// TODO: UI Automator should provide such logic.
public void chooseActivity(String name) {
// First check if the activity is the default option.
String shareText = "Share with " + name;
Log.v(TAG, "Waiting for ActivityChooser text: '" + shareText + "'");
boolean gotIt = mDevice.wait(Until.hasObject(By.text(shareText)), mTimeout);
boolean justOnceHack = false;
if (gotIt) {
Log.v(TAG, "Found activity " + name + ", it's the default action");
clickJustOnce();
} else {
// Since it's not, need to find it in the scrollable list...
Log.v(TAG, "Activity " + name + " is not default action");
UiScrollable activitiesList = new UiScrollable(new UiSelector().scrollable(true));
try {
activitiesList.scrollForward();
} catch (UiObjectNotFoundException e) {
// TODO: for some paranormal issue, the first time a test is run the scrollable
// activity list is displayed but calling scrollForwad() (or even isScrollable())
// throws a "UiObjectNotFoundException: UiSelector[SCROLLABLE=true]" exception
justOnceHack = true;
Log.d(TAG, "could not scroll forward", e);
}
UiObject activity = getVisibleObject(name);
// ... then select it.
click(activity, name);
if (justOnceHack) {
clickJustOnce();
}
}
}
private void clickJustOnce() {
boolean gotIt = mDevice.wait(Until.hasObject(By.res("android", "button_once")), mTimeout);
assertTrue("'Just Once' button not visible yet", gotIt);
UiObject justOnce = mDevice
.findObject(new UiSelector().resourceId("android:id/button_once"));
assertTrue("'Just Once' button not found", justOnce.exists());
click(justOnce, "Just Once");
// It uses an intent chooser now, so just getting the activity by text is enough...
UiObject activity = getVisibleObject(name);
click(activity, name);
}
public void pressBack() {
mDevice.pressBack();
}
public void turnScreenOn() throws Exception {
mDevice.executeShellCommand("input keyevent KEYCODE_WAKEUP");
mDevice.executeShellCommand("wm dismiss-keyguard");
}
}