Methods Summary |
---|
private void | finishTest()
if (mReceiverRegistered) {
addIntermediate("before-unregister");
unregisterMyReceiver();
}
finishTiming(true);
finishGood();
|
public void | finishWithResult(int resultCode, android.content.Intent data)
unregisterMyReceiver();
super.finishWithResult(resultCode, data);
|
public final void | gotReceive(java.lang.String name, android.content.Intent intent)
synchronized (this) {
//System.out.println("Got receive: " + name);
//System.out.println(mNextReceiver + " in " + mExpectedReceivers);
//new RuntimeException("stack").printStackTrace();
addIntermediate(name);
if (mExpectedData != null) {
int n = mExpectedData.length;
int i;
boolean prev = false;
for (i = 0; i < n; i++) {
if (mExpectedData[i].equals(intent.getStringExtra("test"))) {
if (mReceivedData[i]) {
prev = true;
continue;
}
mReceivedData[i] = true;
break;
}
}
if (i >= n) {
if (prev) {
finishBad("Receive got data too many times: "
+ intent.getStringExtra("test"));
} else {
finishBad("Receive got unexpected data: "
+ intent.getStringExtra("test"));
}
new RuntimeException("stack").printStackTrace();
return;
}
}
if (mNextReceiver >= mExpectedReceivers.length) {
finishBad("Got too many onReceiveIntent() calls!");
// System.out.println("Too many intents received: now at "
// + mNextReceiver + ", expect list: "
// + Arrays.toString(mExpectedReceivers));
fail("Got too many onReceiveIntent() calls!");
} else if (!mExpectedReceivers[mNextReceiver].equals(name)) {
finishBad("Receive out of order: got " + name
+ " but expected "
+ mExpectedReceivers[mNextReceiver]);
fail("Receive out of order: got " + name
+ " but expected "
+ mExpectedReceivers[mNextReceiver]);
} else {
mNextReceiver++;
if (mNextReceiver == mExpectedReceivers.length) {
finishTest();
}
}
}
|
public android.content.Intent | makeBroadcastIntent(java.lang.String action)
Intent intent = new Intent(action, null);
intent.putExtra("caller", mCallTarget);
return intent;
|
public void | onRegisteredReceiver(android.content.Intent intent)
gotReceive(RECEIVER_REG, intent);
|
public void | onTimeout()
String msg = "Timeout";
if (mExpectedReceivers != null && mNextReceiver < mExpectedReceivers.length) {
msg = msg + " waiting for " + mExpectedReceivers[mNextReceiver];
}
finishBad(msg);
|
public void | registerMyReceiver(android.content.IntentFilter filter, java.lang.String permission)
mReceiverRegistered = true;
//System.out.println("Registering: " + mReceiver);
getContext().registerReceiver(mReceiver, filter, permission, null);
|
public void | setExpectedData(java.lang.String[] data)
mExpectedData = data;
mReceivedData = new boolean[data.length];
|
public void | setExpectedReceivers(java.lang.String[] receivers)
mExpectedReceivers = receivers;
mNextReceiver = 0;
|
public void | testAbort()
runLaunchpad(LaunchpadActivity.BROADCAST_ABORT);
|
public void | testAll()
runLaunchpad(LaunchpadActivity.BROADCAST_ALL);
|
public void | testClearSticky()
Intent intent = new Intent(LaunchpadActivity.BROADCAST_STICKY1, null);
intent.putExtra("test", LaunchpadActivity.DATA_1);
ActivityManagerNative.broadcastStickyIntent(intent, null);
ActivityManagerNative.getDefault().unbroadcastIntent(
null, new Intent(LaunchpadActivity.BROADCAST_STICKY1, null));
addIntermediate("finished-unbroadcast");
IntentFilter filter = new IntentFilter(LaunchpadActivity.BROADCAST_STICKY1);
Intent sticky = getContext().registerReceiver(null, filter);
assertNull("Sticky not found", sticky);
|
public void | testLocal()
runLaunchpad(LaunchpadActivity.BROADCAST_LOCAL);
|
public void | testLocalBroadcastPermissionDenied()
setExpectedReceivers(new String[]{RECEIVER_RESULTS});
BroadcastReceiver finish = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
gotReceive(RECEIVER_RESULTS, intent);
}
};
getContext().sendOrderedBroadcast(
makeBroadcastIntent(BROADCAST_LOCAL),
PERMISSION_DENIED, finish, null, Activity.RESULT_CANCELED,
null, null);
waitForResultOrThrow(BROADCAST_TIMEOUT);
|
public void | testLocalBroadcastPermissionGranted()
setExpectedReceivers(new String[]{RECEIVER_LOCAL});
getContext().sendBroadcast(
makeBroadcastIntent(BROADCAST_LOCAL),
PERMISSION_GRANTED);
waitForResultOrThrow(BROADCAST_TIMEOUT);
|
public void | testLocalReceivePermissionDenied()
setExpectedReceivers(new String[]{RECEIVER_RESULTS});
BroadcastReceiver finish = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
gotReceive(RECEIVER_RESULTS, intent);
}
};
getContext().sendOrderedBroadcast(
makeBroadcastIntent(BROADCAST_LOCAL_DENIED),
null, finish, null, Activity.RESULT_CANCELED,
null, null);
waitForResultOrThrow(BROADCAST_TIMEOUT);
|
public void | testLocalReceivePermissionGranted()
setExpectedReceivers(new String[]{RECEIVER_LOCAL});
getContext().sendBroadcast(makeBroadcastIntent(BROADCAST_LOCAL_GRANTED));
waitForResultOrThrow(BROADCAST_TIMEOUT);
|
public void | testLocalUnregisterTwice()
registerMyReceiver(new IntentFilter(BROADCAST_REGISTERED), null);
unregisterMyReceiverNoCheck();
try {
unregisterMyReceiverNoCheck();
fail("No exception thrown on second unregister");
} catch (IllegalArgumentException e) {
Log.i("foo", "Unregister exception", e);
}
|
public void | testMulti()
runLaunchpad(LaunchpadActivity.BROADCAST_MULTI);
|
public void | testReceive2Sticky()
Intent intent = new Intent(LaunchpadActivity.BROADCAST_STICKY1, null);
intent.putExtra("test", LaunchpadActivity.DATA_1);
ActivityManagerNative.broadcastStickyIntent(intent, null);
intent = new Intent(LaunchpadActivity.BROADCAST_STICKY2, null);
intent.putExtra("test", LaunchpadActivity.DATA_2);
ActivityManagerNative.broadcastStickyIntent(intent, null);
runLaunchpad(LaunchpadActivity.BROADCAST_STICKY2);
|
public void | testReceiveSticky()
Intent intent = new Intent(LaunchpadActivity.BROADCAST_STICKY1, null);
intent.putExtra("test", LaunchpadActivity.DATA_1);
ActivityManagerNative.broadcastStickyIntent(intent, null);
runLaunchpad(LaunchpadActivity.BROADCAST_STICKY1);
|
public void | testReceiverCanNotBind()
setExpectedReceivers(new String[]{RECEIVER_LOCAL});
getContext().sendBroadcast(makeBroadcastIntent(BROADCAST_FAIL_BIND));
waitForResultOrThrow(BROADCAST_TIMEOUT);
|
public void | testReceiverCanNotRegister()
setExpectedReceivers(new String[]{RECEIVER_LOCAL});
getContext().sendBroadcast(makeBroadcastIntent(BROADCAST_FAIL_REGISTER));
waitForResultOrThrow(BROADCAST_TIMEOUT);
|
public void | testRegistered()
// Mark flaky until http://b/issue?id=1191607 is resolved.
runLaunchpad(LaunchpadActivity.BROADCAST_REGISTERED);
|
public void | testRegisteredBroadcastPermissionDenied()
setExpectedReceivers(new String[]{RECEIVER_RESULTS});
registerMyReceiver(new IntentFilter(BROADCAST_REGISTERED), null);
addIntermediate("after-register");
BroadcastReceiver finish = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
gotReceive(RECEIVER_RESULTS, intent);
}
};
getContext().sendOrderedBroadcast(
makeBroadcastIntent(BROADCAST_REGISTERED),
PERMISSION_DENIED, finish, null, Activity.RESULT_CANCELED,
null, null);
waitForResultOrThrow(BROADCAST_TIMEOUT);
|
public void | testRegisteredBroadcastPermissionGranted()
setExpectedReceivers(new String[]{RECEIVER_REG});
registerMyReceiver(new IntentFilter(BROADCAST_REGISTERED), null);
addIntermediate("after-register");
getContext().sendBroadcast(
makeBroadcastIntent(BROADCAST_REGISTERED),
PERMISSION_GRANTED);
waitForResultOrThrow(BROADCAST_TIMEOUT);
|
public void | testRegisteredReceivePermissionDenied()
setExpectedReceivers(new String[]{RECEIVER_RESULTS});
registerMyReceiver(new IntentFilter(BROADCAST_REGISTERED), PERMISSION_DENIED);
addIntermediate("after-register");
BroadcastReceiver finish = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
gotReceive(RECEIVER_RESULTS, intent);
}
};
getContext().sendOrderedBroadcast(
makeBroadcastIntent(BROADCAST_REGISTERED),
null, finish, null, Activity.RESULT_CANCELED, null, null);
waitForResultOrThrow(BROADCAST_TIMEOUT);
|
public void | testRegisteredReceivePermissionGranted()
setExpectedReceivers(new String[]{RECEIVER_REG});
registerMyReceiver(new IntentFilter(BROADCAST_REGISTERED), PERMISSION_GRANTED);
addIntermediate("after-register");
getContext().sendBroadcast(makeBroadcastIntent(BROADCAST_REGISTERED));
waitForResultOrThrow(BROADCAST_TIMEOUT);
|
public void | testRemote()
runLaunchpad(LaunchpadActivity.BROADCAST_REMOTE);
|
public void | testRemoteBroadcastPermissionDenied()
setExpectedReceivers(new String[]{RECEIVER_RESULTS});
BroadcastReceiver finish = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
gotReceive(RECEIVER_RESULTS, intent);
}
};
getContext().sendOrderedBroadcast(
makeBroadcastIntent(BROADCAST_REMOTE),
PERMISSION_DENIED, finish, null, Activity.RESULT_CANCELED,
null, null);
waitForResultOrThrow(BROADCAST_TIMEOUT);
|
public void | testRemoteBroadcastPermissionGranted()
setExpectedReceivers(new String[]{RECEIVER_REMOTE});
getContext().sendBroadcast(
makeBroadcastIntent(BROADCAST_REMOTE),
PERMISSION_GRANTED);
waitForResultOrThrow(BROADCAST_TIMEOUT);
|
public void | testRemoteReceivePermissionDenied()
setExpectedReceivers(new String[]{RECEIVER_RESULTS});
BroadcastReceiver finish = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
gotReceive(RECEIVER_RESULTS, intent);
}
};
getContext().sendOrderedBroadcast(
makeBroadcastIntent(BROADCAST_REMOTE_DENIED),
null, finish, null, Activity.RESULT_CANCELED,
null, null);
waitForResultOrThrow(BROADCAST_TIMEOUT);
|
public void | testRemoteReceivePermissionGranted()
setExpectedReceivers(new String[]{RECEIVER_REMOTE});
getContext().sendBroadcast(makeBroadcastIntent(BROADCAST_REMOTE_GRANTED));
waitForResultOrThrow(BROADCAST_TIMEOUT);
|
public void | testReplaceSticky()
Intent intent = new Intent(LaunchpadActivity.BROADCAST_STICKY1, null);
intent.putExtra("test", LaunchpadActivity.DATA_1);
ActivityManagerNative.broadcastStickyIntent(intent, null);
intent.putExtra("test", LaunchpadActivity.DATA_2);
ActivityManagerNative.broadcastStickyIntent(intent, null);
addIntermediate("finished-broadcast");
IntentFilter filter = new IntentFilter(LaunchpadActivity.BROADCAST_STICKY1);
Intent sticky = getContext().registerReceiver(null, filter);
assertNotNull("Sticky not found", sticky);
assertEquals(LaunchpadActivity.DATA_2, sticky.getStringExtra("test"));
|
public void | testResult()
TestBroadcastReceiver broadcastReceiver = new TestBroadcastReceiver();
synchronized (this) {
Bundle map = new Bundle();
map.putString("foo", "you");
map.putString("remove", "me");
getContext().sendOrderedBroadcast(
new Intent("com.android.unit_tests.activity.BROADCAST_RESULT"),
null, broadcastReceiver, null, 1, "foo", map);
while (!broadcastReceiver.mHaveResult) {
try {
wait();
} catch (InterruptedException e) {
}
}
//System.out.println("Code: " + mResultCode + ", data: " + mResultData);
//System.out.println("Extras: " + mResultExtras);
assertEquals("Incorrect code: " + broadcastReceiver.getResultCode(),
3, broadcastReceiver.getResultCode());
assertEquals("bar", broadcastReceiver.getResultData());
Bundle resultExtras = broadcastReceiver.getResultExtras(false);
assertEquals("them", resultExtras.getString("bar"));
assertEquals("you", resultExtras.getString("foo"));
assertNull(resultExtras.getString("remove"));
}
|
public void | testSetSticky()
Intent intent = new Intent(LaunchpadActivity.BROADCAST_STICKY1, null);
intent.putExtra("test", LaunchpadActivity.DATA_1);
ActivityManagerNative.getDefault().unbroadcastIntent(null, intent);
ActivityManagerNative.broadcastStickyIntent(intent, null);
addIntermediate("finished-broadcast");
IntentFilter filter = new IntentFilter(LaunchpadActivity.BROADCAST_STICKY1);
Intent sticky = getContext().registerReceiver(null, filter);
assertNotNull("Sticky not found", sticky);
assertEquals(LaunchpadActivity.DATA_1, sticky.getStringExtra("test"));
|
public void | unregisterMyReceiver()
if (mReceiverRegistered) {
unregisterMyReceiverNoCheck();
}
|
public void | unregisterMyReceiverNoCheck()
mReceiverRegistered = false;
//System.out.println("Unregistering: " + mReceiver);
getContext().unregisterReceiver(mReceiver);
|