diff options
author | Bram Bonné <brambonne@google.com> | 2022-04-01 10:08:59 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2022-04-01 10:08:59 +0000 |
commit | bdcc4a968dc2fabf8f30e8410781e23f56b6a7f2 (patch) | |
tree | fe52534028b2fd922fed9bafb034b43d0a0aee2d | |
parent | 265c8a4d3bd9313a2bf9cf3310de653ad51f7125 (diff) | |
parent | 34b82967986e1ccd0216f56c151d3bff1e924e6b (diff) | |
download | AdServices-bdcc4a968dc2fabf8f30e8410781e23f56b6a7f2.tar.gz |
Merge "Add tests for intent restrictions." into tm-dev
-rw-r--r-- | sdksandbox/SdkSandbox/tests_inprocess/src/com/android/sdksandbox/inprocess/SdkSandboxRestrictionsTest.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/sdksandbox/SdkSandbox/tests_inprocess/src/com/android/sdksandbox/inprocess/SdkSandboxRestrictionsTest.java b/sdksandbox/SdkSandbox/tests_inprocess/src/com/android/sdksandbox/inprocess/SdkSandboxRestrictionsTest.java index 8a0698959b..1771c729c9 100644 --- a/sdksandbox/SdkSandbox/tests_inprocess/src/com/android/sdksandbox/inprocess/SdkSandboxRestrictionsTest.java +++ b/sdksandbox/SdkSandbox/tests_inprocess/src/com/android/sdksandbox/inprocess/SdkSandboxRestrictionsTest.java @@ -26,6 +26,7 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.media.MediaDrm; import android.media.UnsupportedSchemeException; +import android.net.Uri; import androidx.test.platform.app.InstrumentationRegistry; @@ -78,4 +79,38 @@ public class SdkSandboxRestrictionsTest { assertThat(thrown).hasMessageThat().contains( "may not be broadcast from an SDK sandbox uid"); } + + /** + * Tests that sandbox cannot send implicit broadcast intents. + */ + @Test + public void testNoImplicitIntents() { + final Context ctx = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + Intent sendIntent = new Intent(); + sendIntent.setAction(Intent.ACTION_SEND); + sendIntent.putExtra(Intent.EXTRA_TEXT, "text"); + sendIntent.setType("text/plain"); + sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + + SecurityException thrown = assertThrows( + SecurityException.class, + () -> ctx.startActivity(sendIntent)); + assertThat(thrown).hasMessageThat().contains("may not be broadcast from an SDK sandbox"); + } + + /** + * Tests that sandbox can open URLs in a browser. + */ + @Test + public void testUrlViewIntents() { + final Context ctx = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + Intent intent = new Intent(); + intent.setAction(Intent.ACTION_VIEW); + intent.setData(Uri.parse("https://www.android.com")); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + + ctx.startActivity(intent); + } } |