1 /* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.app.activity; 18 19 import android.app.Activity; 20 import android.app.ActivityManager; 21 import android.app.BroadcastOptions; 22 import android.app.PendingIntent; 23 import android.content.BroadcastReceiver; 24 import android.content.Context; 25 import android.content.Intent; 26 import android.content.IntentFilter; 27 import android.os.Binder; 28 import android.os.Bundle; 29 import android.os.IBinder; 30 import android.os.Parcel; 31 import android.os.UserHandle; 32 import android.util.Log; 33 34 import androidx.test.filters.FlakyTest; 35 import androidx.test.filters.LargeTest; 36 37 @LargeTest 38 public class BroadcastTest extends ActivityTestsBase { 39 public static final int BROADCAST_TIMEOUT = 5 * 1000; 40 41 public static final String BROADCAST_REGISTERED = 42 "com.android.frameworks.coretests.activity.BROADCAST_REGISTERED"; 43 public static final String BROADCAST_LOCAL = 44 "com.android.frameworks.coretests.activity.BROADCAST_LOCAL"; 45 public static final String BROADCAST_LOCAL_GRANTED = 46 "com.android.frameworks.coretests.activity.BROADCAST_LOCAL_GRANTED"; 47 public static final String BROADCAST_LOCAL_DENIED = 48 "com.android.frameworks.coretests.activity.BROADCAST_LOCAL_DENIED"; 49 public static final String BROADCAST_REMOTE = 50 "com.android.frameworks.coretests.activity.BROADCAST_REMOTE"; 51 public static final String BROADCAST_REMOTE_GRANTED = 52 "com.android.frameworks.coretests.activity.BROADCAST_REMOTE_GRANTED"; 53 public static final String BROADCAST_REMOTE_DENIED = 54 "com.android.frameworks.coretests.activity.BROADCAST_REMOTE_DENIED"; 55 public static final String BROADCAST_ALL = 56 "com.android.frameworks.coretests.activity.BROADCAST_ALL"; 57 public static final String BROADCAST_MULTI = 58 "com.android.frameworks.coretests.activity.BROADCAST_MULTI"; 59 public static final String BROADCAST_ABORT = 60 "com.android.frameworks.coretests.activity.BROADCAST_ABORT"; 61 62 public static final String BROADCAST_STICKY1 = 63 "com.android.frameworks.coretests.activity.BROADCAST_STICKY1"; 64 public static final String BROADCAST_STICKY2 = 65 "com.android.frameworks.coretests.activity.BROADCAST_STICKY2"; 66 67 public static final String BROADCAST_FAIL_REGISTER = 68 "com.android.frameworks.coretests.activity.BROADCAST_FAIL_REGISTER"; 69 public static final String BROADCAST_FAIL_BIND = 70 "com.android.frameworks.coretests.activity.BROADCAST_FAIL_BIND"; 71 72 public static final String RECEIVER_REG = "receiver-reg"; 73 public static final String RECEIVER_LOCAL = "receiver-local"; 74 public static final String RECEIVER_REMOTE = "receiver-remote"; 75 public static final String RECEIVER_ABORT = "receiver-abort"; 76 public static final String RECEIVER_RESULTS = "receiver-results"; 77 78 public static final String DATA_1 = "one"; 79 public static final String DATA_2 = "two"; 80 81 public static final int GOT_RECEIVE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION; 82 public static final int ERROR_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 1; 83 84 private String[] mExpectedReceivers = null; 85 private int mNextReceiver; 86 87 private String[] mExpectedData = null; 88 private boolean[] mReceivedData = null; 89 90 boolean mReceiverRegistered = false; 91 setExpectedReceivers(String[] receivers)92 public void setExpectedReceivers(String[] receivers) { 93 mExpectedReceivers = receivers; 94 mNextReceiver = 0; 95 } 96 setExpectedData(String[] data)97 public void setExpectedData(String[] data) { 98 mExpectedData = data; 99 mReceivedData = new boolean[data.length]; 100 } 101 onTimeout()102 public void onTimeout() { 103 String msg = "Timeout"; 104 if (mExpectedReceivers != null && mNextReceiver < mExpectedReceivers.length) { 105 msg = msg + " waiting for " + mExpectedReceivers[mNextReceiver]; 106 } 107 finishBad(msg); 108 } 109 makeBroadcastIntent(String action)110 public Intent makeBroadcastIntent(String action) { 111 Intent intent = new Intent(action, null); 112 intent.putExtra("caller", mCallTarget); 113 intent.setPackage(getContext().getPackageName()); 114 return intent; 115 } 116 finishWithResult(int resultCode, Intent data)117 public void finishWithResult(int resultCode, Intent data) { 118 unregisterMyReceiver(); 119 super.finishWithResult(resultCode, data); 120 } 121 gotReceive(String name, Intent intent)122 public final void gotReceive(String name, Intent intent) { 123 synchronized (this) { 124 125 //System.out.println("Got receive: " + name); 126 //System.out.println(mNextReceiver + " in " + mExpectedReceivers); 127 //new RuntimeException("stack").printStackTrace(); 128 129 addIntermediate(name); 130 131 if (mExpectedData != null) { 132 int n = mExpectedData.length; 133 int i; 134 boolean prev = false; 135 for (i = 0; i < n; i++) { 136 if (mExpectedData[i].equals(intent.getStringExtra("test"))) { 137 if (mReceivedData[i]) { 138 prev = true; 139 continue; 140 } 141 mReceivedData[i] = true; 142 break; 143 } 144 } 145 if (i >= n) { 146 if (prev) { 147 finishBad("Receive got data too many times: " 148 + intent.getStringExtra("test")); 149 } else { 150 finishBad("Receive got unexpected data: " 151 + intent.getStringExtra("test")); 152 } 153 new RuntimeException("stack").printStackTrace(); 154 return; 155 } 156 } 157 158 if (mNextReceiver >= mExpectedReceivers.length) { 159 finishBad("Got too many onReceiveIntent() calls!"); 160 // System.out.println("Too many intents received: now at " 161 // + mNextReceiver + ", expect list: " 162 // + Arrays.toString(mExpectedReceivers)); 163 fail("Got too many onReceiveIntent() calls!"); 164 } else if (!mExpectedReceivers[mNextReceiver].equals(name)) { 165 finishBad("Receive out of order: got " + name 166 + " but expected " 167 + mExpectedReceivers[mNextReceiver]); 168 fail("Receive out of order: got " + name 169 + " but expected " 170 + mExpectedReceivers[mNextReceiver]); 171 } else { 172 mNextReceiver++; 173 if (mNextReceiver == mExpectedReceivers.length) { 174 finishTest(); 175 } 176 } 177 } 178 } 179 registerMyReceiver(IntentFilter filter, String permission)180 public void registerMyReceiver(IntentFilter filter, String permission) { 181 mReceiverRegistered = true; 182 //System.out.println("Registering: " + mReceiver); 183 getContext().registerReceiver(mReceiver, filter, permission, null, 184 Context.RECEIVER_EXPORTED); 185 } 186 unregisterMyReceiver()187 public void unregisterMyReceiver() { 188 if (mReceiverRegistered) { 189 unregisterMyReceiverNoCheck(); 190 } 191 } 192 unregisterMyReceiverNoCheck()193 public void unregisterMyReceiverNoCheck() { 194 mReceiverRegistered = false; 195 //System.out.println("Unregistering: " + mReceiver); 196 getContext().unregisterReceiver(mReceiver); 197 } 198 onRegisteredReceiver(Intent intent)199 public void onRegisteredReceiver(Intent intent) { 200 gotReceive(RECEIVER_REG, intent); 201 } 202 203 private Binder mCallTarget = new Binder() { 204 public boolean onTransact(int code, Parcel data, Parcel reply, 205 int flags) { 206 data.setDataPosition(0); 207 data.enforceInterface(LaunchpadActivity.LAUNCH); 208 if (code == GOT_RECEIVE_TRANSACTION) { 209 String name = data.readString(); 210 gotReceive(name, null); 211 return true; 212 } else if (code == ERROR_TRANSACTION) { 213 finishBad(data.readString()); 214 return true; 215 } 216 return false; 217 } 218 }; 219 finishTest()220 private void finishTest() { 221 if (mReceiverRegistered) { 222 addIntermediate("before-unregister"); 223 unregisterMyReceiver(); 224 } 225 finishTiming(true); 226 finishGood(); 227 } 228 229 private BroadcastReceiver mReceiver = new BroadcastReceiver() { 230 public void onReceive(Context context, Intent intent) { 231 //System.out.println("Receive in: " + this + ": " + intent); 232 onRegisteredReceiver(intent); 233 } 234 }; 235 236 // Mark flaky until http://b/issue?id=1191607 is resolved. 237 @FlakyTest testRegistered()238 public void testRegistered() throws Exception { 239 runLaunchpad(LaunchpadActivity.BROADCAST_REGISTERED); 240 } 241 testLocal()242 public void testLocal() throws Exception { 243 runLaunchpad(LaunchpadActivity.BROADCAST_LOCAL); 244 } 245 testRemote()246 public void testRemote() throws Exception { 247 runLaunchpad(LaunchpadActivity.BROADCAST_REMOTE); 248 } 249 testAbort()250 public void testAbort() throws Exception { 251 runLaunchpad(LaunchpadActivity.BROADCAST_ABORT); 252 } 253 254 @FlakyTest testAll()255 public void testAll() throws Exception { 256 runLaunchpad(LaunchpadActivity.BROADCAST_ALL); 257 } 258 259 @FlakyTest ignore_testMulti()260 public void ignore_testMulti() throws Exception { 261 runLaunchpad(LaunchpadActivity.BROADCAST_MULTI); 262 } 263 264 private class TestBroadcastReceiver extends BroadcastReceiver { 265 public boolean mHaveResult = false; 266 267 @Override onReceive(Context context, Intent intent)268 public void onReceive(Context context, Intent intent) { 269 synchronized (BroadcastTest.this) { 270 mHaveResult = true; 271 BroadcastTest.this.notifyAll(); 272 } 273 } 274 } 275 testResult()276 public void testResult() throws Exception { 277 TestBroadcastReceiver broadcastReceiver = new TestBroadcastReceiver(); 278 279 synchronized (this) { 280 Bundle map = new Bundle(); 281 map.putString("foo", "you"); 282 map.putString("remove", "me"); 283 final Intent intent = new Intent( 284 "com.android.frameworks.coretests.activity.BROADCAST_RESULT") 285 .setPackage(getContext().getPackageName()); 286 getContext().sendOrderedBroadcast( 287 intent, 288 null, broadcastReceiver, null, 1, "foo", map); 289 while (!broadcastReceiver.mHaveResult) { 290 try { 291 wait(); 292 } catch (InterruptedException e) { 293 } 294 } 295 296 //System.out.println("Code: " + mResultCode + ", data: " + mResultData); 297 //System.out.println("Extras: " + mResultExtras); 298 299 assertEquals("Incorrect code: " + broadcastReceiver.getResultCode(), 300 3, broadcastReceiver.getResultCode()); 301 302 assertEquals("bar", broadcastReceiver.getResultData()); 303 304 Bundle resultExtras = broadcastReceiver.getResultExtras(false); 305 assertEquals("them", resultExtras.getString("bar")); 306 assertEquals("you", resultExtras.getString("foo")); 307 assertNull(resultExtras.getString("remove")); 308 } 309 } 310 testSetSticky()311 public void testSetSticky() throws Exception { 312 Intent intent = new Intent(LaunchpadActivity.BROADCAST_STICKY1, null); 313 intent.putExtra("test", LaunchpadActivity.DATA_1); 314 ActivityManager.getService().unbroadcastIntent(null, intent, 315 UserHandle.myUserId()); 316 317 ActivityManager.broadcastStickyIntent(intent, UserHandle.myUserId()); 318 addIntermediate("finished-broadcast"); 319 320 IntentFilter filter = new IntentFilter(LaunchpadActivity.BROADCAST_STICKY1); 321 Intent sticky = getContext().registerReceiver(null, filter, Context.RECEIVER_EXPORTED); 322 assertNotNull("Sticky not found", sticky); 323 assertEquals(LaunchpadActivity.DATA_1, sticky.getStringExtra("test")); 324 } 325 testClearSticky()326 public void testClearSticky() throws Exception { 327 Intent intent = new Intent(LaunchpadActivity.BROADCAST_STICKY1, null); 328 intent.putExtra("test", LaunchpadActivity.DATA_1); 329 ActivityManager.broadcastStickyIntent(intent, UserHandle.myUserId()); 330 331 ActivityManager.getService().unbroadcastIntent( 332 null, new Intent(LaunchpadActivity.BROADCAST_STICKY1, null), 333 UserHandle.myUserId()); 334 addIntermediate("finished-unbroadcast"); 335 336 IntentFilter filter = new IntentFilter(LaunchpadActivity.BROADCAST_STICKY1); 337 Intent sticky = getContext().registerReceiver(null, filter, Context.RECEIVER_EXPORTED); 338 assertNull("Sticky not found", sticky); 339 } 340 testReplaceSticky()341 public void testReplaceSticky() throws Exception { 342 Intent intent = new Intent(LaunchpadActivity.BROADCAST_STICKY1, null); 343 intent.putExtra("test", LaunchpadActivity.DATA_1); 344 ActivityManager.broadcastStickyIntent(intent, UserHandle.myUserId()); 345 intent.putExtra("test", LaunchpadActivity.DATA_2); 346 347 ActivityManager.broadcastStickyIntent(intent, UserHandle.myUserId()); 348 addIntermediate("finished-broadcast"); 349 350 IntentFilter filter = new IntentFilter(LaunchpadActivity.BROADCAST_STICKY1); 351 Intent sticky = getContext().registerReceiver(null, filter, Context.RECEIVER_EXPORTED); 352 assertNotNull("Sticky not found", sticky); 353 assertEquals(LaunchpadActivity.DATA_2, sticky.getStringExtra("test")); 354 } 355 356 // Marking flaky until http://b/issue?id=1191337 is resolved 357 @FlakyTest testReceiveSticky()358 public void testReceiveSticky() throws Exception { 359 Intent intent = new Intent(LaunchpadActivity.BROADCAST_STICKY1, null); 360 intent.putExtra("test", LaunchpadActivity.DATA_1); 361 ActivityManager.broadcastStickyIntent(intent, UserHandle.myUserId()); 362 363 runLaunchpad(LaunchpadActivity.BROADCAST_STICKY1); 364 } 365 366 // Marking flaky until http://b/issue?id=1191337 is resolved 367 @FlakyTest testReceive2Sticky()368 public void testReceive2Sticky() throws Exception { 369 Intent intent = new Intent(LaunchpadActivity.BROADCAST_STICKY1, null); 370 intent.putExtra("test", LaunchpadActivity.DATA_1); 371 ActivityManager.broadcastStickyIntent(intent, UserHandle.myUserId()); 372 intent = new Intent(LaunchpadActivity.BROADCAST_STICKY2, null); 373 intent.putExtra("test", LaunchpadActivity.DATA_2); 374 ActivityManager.broadcastStickyIntent(intent, UserHandle.myUserId()); 375 376 runLaunchpad(LaunchpadActivity.BROADCAST_STICKY2); 377 } 378 ignore_testRegisteredReceivePermissionGranted()379 public void ignore_testRegisteredReceivePermissionGranted() throws Exception { 380 setExpectedReceivers(new String[]{RECEIVER_REG}); 381 registerMyReceiver(new IntentFilter(BROADCAST_REGISTERED), PERMISSION_GRANTED); 382 addIntermediate("after-register"); 383 getContext().sendBroadcast(makeBroadcastIntent(BROADCAST_REGISTERED)); 384 waitForResultOrThrow(BROADCAST_TIMEOUT); 385 } 386 testRegisteredReceivePermissionDenied()387 public void testRegisteredReceivePermissionDenied() throws Exception { 388 setExpectedReceivers(new String[]{RECEIVER_RESULTS}); 389 registerMyReceiver(new IntentFilter(BROADCAST_REGISTERED), PERMISSION_DENIED); 390 addIntermediate("after-register"); 391 392 BroadcastReceiver finish = new BroadcastReceiver() { 393 public void onReceive(Context context, Intent intent) { 394 gotReceive(RECEIVER_RESULTS, intent); 395 } 396 }; 397 398 getContext().sendOrderedBroadcast( 399 makeBroadcastIntent(BROADCAST_REGISTERED), 400 null, finish, null, Activity.RESULT_CANCELED, null, null); 401 waitForResultOrThrow(BROADCAST_TIMEOUT); 402 } 403 ignore_testRegisteredBroadcastPermissionGranted()404 public void ignore_testRegisteredBroadcastPermissionGranted() throws Exception { 405 setExpectedReceivers(new String[]{RECEIVER_REG}); 406 registerMyReceiver(new IntentFilter(BROADCAST_REGISTERED), null); 407 addIntermediate("after-register"); 408 getContext().sendBroadcast( 409 makeBroadcastIntent(BROADCAST_REGISTERED), 410 PERMISSION_GRANTED); 411 waitForResultOrThrow(BROADCAST_TIMEOUT); 412 } 413 testRegisteredBroadcastPermissionDenied()414 public void testRegisteredBroadcastPermissionDenied() throws Exception { 415 setExpectedReceivers(new String[]{RECEIVER_RESULTS}); 416 registerMyReceiver(new IntentFilter(BROADCAST_REGISTERED), null); 417 addIntermediate("after-register"); 418 419 BroadcastReceiver finish = new BroadcastReceiver() { 420 public void onReceive(Context context, Intent intent) { 421 gotReceive(RECEIVER_RESULTS, intent); 422 } 423 }; 424 425 getContext().sendOrderedBroadcast( 426 makeBroadcastIntent(BROADCAST_REGISTERED), 427 PERMISSION_DENIED, finish, null, Activity.RESULT_CANCELED, 428 null, null); 429 waitForResultOrThrow(BROADCAST_TIMEOUT); 430 } 431 testLocalReceivePermissionGranted()432 public void testLocalReceivePermissionGranted() throws Exception { 433 setExpectedReceivers(new String[]{RECEIVER_LOCAL}); 434 getContext().sendBroadcast(makeBroadcastIntent(BROADCAST_LOCAL_GRANTED)); 435 waitForResultOrThrow(BROADCAST_TIMEOUT); 436 } 437 ignore_testLocalReceivePermissionDenied()438 public void ignore_testLocalReceivePermissionDenied() throws Exception { 439 setExpectedReceivers(new String[]{RECEIVER_RESULTS}); 440 441 BroadcastReceiver finish = new BroadcastReceiver() { 442 public void onReceive(Context context, Intent intent) { 443 gotReceive(RECEIVER_RESULTS, intent); 444 } 445 }; 446 447 getContext().sendOrderedBroadcast( 448 makeBroadcastIntent(BROADCAST_LOCAL_DENIED), 449 null, finish, null, Activity.RESULT_CANCELED, 450 null, null); 451 waitForResultOrThrow(BROADCAST_TIMEOUT); 452 } 453 ignore_testLocalBroadcastPermissionGranted()454 public void ignore_testLocalBroadcastPermissionGranted() throws Exception { 455 setExpectedReceivers(new String[]{RECEIVER_LOCAL}); 456 getContext().sendBroadcast( 457 makeBroadcastIntent(BROADCAST_LOCAL), 458 PERMISSION_GRANTED); 459 waitForResultOrThrow(BROADCAST_TIMEOUT); 460 } 461 testLocalBroadcastPermissionDenied()462 public void testLocalBroadcastPermissionDenied() throws Exception { 463 setExpectedReceivers(new String[]{RECEIVER_RESULTS}); 464 465 BroadcastReceiver finish = new BroadcastReceiver() { 466 public void onReceive(Context context, Intent intent) { 467 gotReceive(RECEIVER_RESULTS, intent); 468 } 469 }; 470 471 getContext().sendOrderedBroadcast( 472 makeBroadcastIntent(BROADCAST_LOCAL), 473 PERMISSION_DENIED, finish, null, Activity.RESULT_CANCELED, 474 null, null); 475 waitForResultOrThrow(BROADCAST_TIMEOUT); 476 } 477 testRemoteReceivePermissionGranted()478 public void testRemoteReceivePermissionGranted() throws Exception { 479 setExpectedReceivers(new String[]{RECEIVER_REMOTE}); 480 getContext().sendBroadcast(makeBroadcastIntent(BROADCAST_REMOTE_GRANTED)); 481 waitForResultOrThrow(BROADCAST_TIMEOUT); 482 } 483 ignore_testRemoteReceivePermissionDenied()484 public void ignore_testRemoteReceivePermissionDenied() throws Exception { 485 setExpectedReceivers(new String[]{RECEIVER_RESULTS}); 486 487 BroadcastReceiver finish = new BroadcastReceiver() { 488 public void onReceive(Context context, Intent intent) { 489 gotReceive(RECEIVER_RESULTS, intent); 490 } 491 }; 492 493 getContext().sendOrderedBroadcast( 494 makeBroadcastIntent(BROADCAST_REMOTE_DENIED), 495 null, finish, null, Activity.RESULT_CANCELED, 496 null, null); 497 waitForResultOrThrow(BROADCAST_TIMEOUT); 498 } 499 ignore_testRemoteBroadcastPermissionGranted()500 public void ignore_testRemoteBroadcastPermissionGranted() throws Exception { 501 setExpectedReceivers(new String[]{RECEIVER_REMOTE}); 502 getContext().sendBroadcast( 503 makeBroadcastIntent(BROADCAST_REMOTE), 504 PERMISSION_GRANTED); 505 waitForResultOrThrow(BROADCAST_TIMEOUT); 506 } 507 testRemoteBroadcastPermissionDenied()508 public void testRemoteBroadcastPermissionDenied() throws Exception { 509 setExpectedReceivers(new String[]{RECEIVER_RESULTS}); 510 511 BroadcastReceiver finish = new BroadcastReceiver() { 512 public void onReceive(Context context, Intent intent) { 513 gotReceive(RECEIVER_RESULTS, intent); 514 } 515 }; 516 517 getContext().sendOrderedBroadcast( 518 makeBroadcastIntent(BROADCAST_REMOTE), 519 PERMISSION_DENIED, finish, null, Activity.RESULT_CANCELED, 520 null, null); 521 waitForResultOrThrow(BROADCAST_TIMEOUT); 522 } 523 ignore_testReceiverCanNotRegister()524 public void ignore_testReceiverCanNotRegister() throws Exception { 525 setExpectedReceivers(new String[]{RECEIVER_LOCAL}); 526 getContext().sendBroadcast(makeBroadcastIntent(BROADCAST_FAIL_REGISTER)); 527 waitForResultOrThrow(BROADCAST_TIMEOUT); 528 } 529 testReceiverCanNotBind()530 public void testReceiverCanNotBind() throws Exception { 531 setExpectedReceivers(new String[]{RECEIVER_LOCAL}); 532 getContext().sendBroadcast(makeBroadcastIntent(BROADCAST_FAIL_BIND)); 533 waitForResultOrThrow(BROADCAST_TIMEOUT); 534 } 535 testLocalUnregisterTwice()536 public void testLocalUnregisterTwice() throws Exception { 537 registerMyReceiver(new IntentFilter(BROADCAST_REGISTERED), null); 538 unregisterMyReceiverNoCheck(); 539 try { 540 unregisterMyReceiverNoCheck(); 541 fail("No exception thrown on second unregister"); 542 } catch (IllegalArgumentException e) { 543 Log.i("foo", "Unregister exception", e); 544 } 545 } 546 testBroadcastOption_interactive()547 public void testBroadcastOption_interactive() throws Exception { 548 final BroadcastOptions options = BroadcastOptions.makeBasic(); 549 options.setInteractive(true); 550 final Intent intent = makeBroadcastIntent(BROADCAST_REGISTERED); 551 552 try { 553 getContext().sendBroadcast(intent, null, options.toBundle()); 554 fail("No exception thrown with BroadcastOptions.setInteractive(true)"); 555 } catch (SecurityException se) { 556 // Expected, correct behavior - this case intentionally empty 557 } catch (Exception e) { 558 fail("Unexpected exception " + e.getMessage() 559 + " thrown with BroadcastOptions.setInteractive(true)"); 560 } 561 } 562 testBroadcastOption_interactive_PendingIntent()563 public void testBroadcastOption_interactive_PendingIntent() throws Exception { 564 final BroadcastOptions options = BroadcastOptions.makeBasic(); 565 options.setInteractive(true); 566 final Intent intent = makeBroadcastIntent(BROADCAST_REGISTERED); 567 PendingIntent brPending = PendingIntent.getBroadcast(getContext(), 568 1, intent, PendingIntent.FLAG_IMMUTABLE); 569 570 try { 571 brPending.send(getContext(), 1, null, null, null, null, options.toBundle()); 572 fail("No exception thrown with BroadcastOptions.setInteractive(true)"); 573 } catch (SecurityException se) { 574 // Expected, correct behavior - this case intentionally empty 575 } catch (Exception e) { 576 fail("Unexpected exception " + e.getMessage() 577 + " thrown with BroadcastOptions.setInteractive(true)"); 578 } finally { 579 brPending.cancel(); 580 } 581 } 582 } 583