AI 145638: am: CL 145601 am: CL 145254 CTS: add Android permissions test cases.
Original author: sus
Merged from: //branches/cupcake/...
Original author: android-build
Automated import of CL 145638
diff --git a/tests/res/values/strings.xml b/tests/res/values/strings.xml
index 20f0319..0178406 100644
--- a/tests/res/values/strings.xml
+++ b/tests/res/values/strings.xml
@@ -1,37 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
-<!--
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- -->
+<!-- Copyright (C) 2008 The Android Open Source Project
-<resources>
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="permlab_testGranted">Test Granted</string>
<string name="permdesc_testGranted">Used for running CTS tests, for testing operations
where we have the permission.</string>
+ <string name="permlab_testDynamic">Test Dynamic</string>
+ <string name="permdesc_testDynamic">Used for running CTS tests, for testing adding
+ dynamic permissions.</string>
<string name="permlab_testDenied">Test Denied</string>
<string name="permdesc_testDenied">Used for running CTS tests, for testing operations
where we do not have the permission.</string>
- <string name="explain">1. click start. \n2. if above image shaked, then press pass button, else press failed button.</string>
+ <string name="explain">1. click start. \n2. if above image shaked, then press pass button,
+ else press failed button.</string>
<string name="text_view_hello">Hello! Text view!</string>
+ <string name="text_view_simple_hint">This is a hint.</string>
<string name="text_view_hint">This is a string for testing hint of textview.</string>
<string name="activity_forwarding">App/Forwarding</string>
<string name="forwarding">$$$</string>
<string name="go">Go</string>
<string name="back">Back</string>
- <string name="forward_target">Press back button and notice we don\'t see the previous activity.</string>
+ <string name="forward_target">
+ Press back button and notice we don\'t see the previous activity.
+ </string>
<string name="edit_text">testing</string>
<string name="text">DialogTest</string>
+ <string name="text_country">Country</string>
+ <string name="text_name">Name</string>
<string name="dialog_stub_dialog_test_button1">Test Dialog without theme</string>
<string name="dialog_stub_dialog_test_button2">Test Dialog with theme</string>
<string name="dialog_stub_dialog_test_button3">Test AlertDialog</string>
@@ -41,6 +49,15 @@
<string name="dialog_stub_dialog_test_button7">Test TimePickerDialog</string>
<string name="dialog_stub_dialog_test_button8">Test TimePickerDialog with theme</string>
<string name="dialog_stub_dialog_test_button9">Test onStart() and onStop()</string>
+ <string name="dialog_stub_dialog_test_button10">Test AlertDialog deprecated</string>
+ <string name="dialog_stub_dialog_test_button11">Test AlertDialog callback</string>
+ <string name="dialog_stub_dialog_test_button12">Test AlertDialog setview </string>
+ <string name="dialog_stub_dialog_test_button13">Test AlertDialog deprecated with Message</string>
+ <string name="dialog_stub_dialog_test_button14">Test AlertDialog with theme</string>
+ <string name="dialog_stub_dialog_test_button15">Test AlertDialog cancelable</string>
+ <string name="dialog_stub_dialog_test_button16">Test AlertDialog can'n cancelable</string>
+ <string name="dialog_stub_dialog_test_button17">Test Dialog cancelable</string>
+ <string name="dialog_stub_dialog_test_button18">Test Dialog not cancelable</string>
<string name="hello_world">Hello, World!</string>
<string name="hello_android">Hello, Android!</string>
<string name="alert_dialog_username">Name:</string>
@@ -82,4 +99,70 @@
<string name="vertical_text_1">vertical 1</string>
<string name="vertical_text_2">vertical 2</string>
<string name="vertical_text_3">vertical 3</string>
+ <string name="reference">here</string>
+ <string name="coerceIntegerToString">100</string>
+ <string name="coerceBooleanToString">true</string>
+ <string name="coerceColorToString">#fff</string>
+ <string name="coerceFloatToString">100.0</string>
+ <string name="coerceDimensionToString">100px</string>
+ <string name="coerceFractionToString">100<xliff:g id="percent">%</xliff:g></string>
+ <string name="formattedStringNone">Format[]</string>
+ <string name="formattedStringOne">Format[<xliff:g id="format">%d</xliff:g>]</string>
+ <string name="formattedStringTwo">Format[<xliff:g id="format">%3$d,%2$s</xliff:g>]</string>
+ <string name="checkboxpref_key">checkboxpref_key</string>
+ <string name="checkboxpref_title">title of preference</string>
+ <string name="checkboxpref_summary">summary of preference</string>
+ <string name="checkboxpref_summary_on">summary on of preference</string>
+ <string name="checkboxpref_summary_off">summary off of preference</string>
+ <string name="checkboxpref_depend">checkboxpref_depend</string>
+ <string name="checkboxpref_depend_title"> depend title of preference</string>
+ <string name="checkboxpref_depend_summary"> depend summary of preference</string>
+ <string name="edittextpref_key">edittextpref_key</string>
+ <string name="edittextpref_default_value">default value of preference</string>
+ <string name="edittextpref_title">title of edit text preference</string>
+ <string name="edittextpref_summary">summary of edit text preference</string>
+ <string name="edittextpref_dialog_title">dialog title of edit text preference</string>
+ <string name="edittextpref_text">text of edit text preference</string>
+ <string name="listpref_key">listpref_key</string>
+ <string name="listpref_title">title of list preference</string>
+ <string name="listpref_summary">summary of list preference</string>
+ <string name="listpref_dialogtitle">dialog title of list preference</string>
+ <string name="easy">Easy</string>
+ <string name="medium">Medium</string>
+ <string name="hard">Hard</string>
+ <string name="footer_view">Footer view</string>
+ <string name="header_view">Header view</string>
+ <string name="dialogpref_title">title of dialog preference </string>
+ <string name="dialogpref_dialog_title">dialog title of dialog preference </string>
+ <string name="dialogpref_key">dialogpref_key</string>
+ <string name="dialogpref_default_value">default value of dialog preference</string>
+ <string name="dialogpref_summary">summary of dialog preference</string>
+ <string name="dialogpref_message">message of dialog preference</string>
+ <string name="dialogpref_sure">Sure</string>
+ <string name="dialogpref_cancel">Cancel</string>
+ <string name="pref_key">pref_key</string>
+ <string name="pref_title">title of preference</string>
+ <string name="pref_summary">summary of preference</string>
+ <string name="pref_depend_key">pref_depend_key</string>
+ <string name="pref_depend_title"> depend title of preference</string>
+ <string name="pref_depend_summary"> depend summary of preference</string>
+ <string name="android_intent_action_preference">android.intent.action.PREFERENCE</string>
+ <string name="def_pref_key">def_pref_key</string>
+ <string name="def_pref_title">default preference</string>
+ <string name="def_pref_summary">This is default preference of cts</string>
+ <string name="relative_view1">view 1</string>
+ <string name="relative_view2">view 2</string>
+ <string name="relative_view3">view 3</string>
+ <string name="relative_view4">view 4</string>
+ <string name="relative_view5">view 5</string>
+ <string name="relative_view6">view 6</string>
+ <string name="relative_view7">view 7</string>
+ <string name="relative_view8">view 8</string>
+ <string name="relative_view9">view 9</string>
+ <string name="relative_view10">view 10</string>
+ <string name="relative_view11">view 11</string>
+ <string name="relative_view12">view 12</string>
+ <string name="relative_view13">view 13</string>
+ <string name="footer_view">Footer view</string>
+ <string name="header_view">Header view</string>
</resources>
diff --git a/tests/tests/permission/src/android/permission/cts/NoBroadcastPackageRemovedPermissionTest.java b/tests/tests/permission/src/android/permission/cts/NoBroadcastPackageRemovedPermissionTest.java
new file mode 100644
index 0000000..b5a1b81
--- /dev/null
+++ b/tests/tests/permission/src/android/permission/cts/NoBroadcastPackageRemovedPermissionTest.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.permission.cts;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.test.AndroidTestCase;
+
+/**
+ * Verify Context related methods without specific BROADCAST series permissions.
+ */
+public class NoBroadcastPackageRemovedPermissionTest extends AndroidTestCase {
+ private static final String TEST_RECEIVER_PERMISSION = "receiverPermission";
+
+ /**
+ * Verify that Context#sendStickyBroadcast(Intent),
+ * Context#removeStickyBroadcast(Intent)
+ * requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#BROADCAST_STICKY }.
+ */
+ public void testSendOrRemoveStickyBroadcast() {
+ try {
+ mContext.sendStickyBroadcast(createIntent(Intent.ACTION_WALLPAPER_CHANGED));
+ fail("Context.sendStickyBroadcast did not throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+
+ try {
+ mContext.removeStickyBroadcast(createIntent(Intent.ACTION_WALLPAPER_CHANGED));
+ fail("Context.removeStickyBroadcast did not throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that Context#sendBroadcast(Intent),
+ * Context#sendBroadcast(Intent, String)
+ * Context#sendOrderedBroadcast(Intent, String, BroadcastReceiver,
+ * Handler, int, String, Bundle)
+ * Context#sendOrderedBroadcast(Intent, String) with ACTION_UID_REMOVED
+ * with ACTION_PACKAGE_REMOVED requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#BROADCAST_PACKAGE_REMOVED}.
+ */
+ public void testSendBroadcast() {
+ try {
+ mContext.sendBroadcast(createIntent(Intent.ACTION_PACKAGE_REMOVED));
+ fail("Context.sendBroadcast did not throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+
+ try {
+ mContext.sendBroadcast(createIntent(Intent.ACTION_PACKAGE_REMOVED),
+ TEST_RECEIVER_PERMISSION);
+ fail("Context.sendBroadcast did not throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+
+ try {
+ mContext.sendOrderedBroadcast(createIntent(Intent.ACTION_PACKAGE_REMOVED),
+ TEST_RECEIVER_PERMISSION, null, null, 0, "initialData", Bundle.EMPTY);
+ fail("Context.sendOrderedBroadcast did not throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+
+ try {
+ mContext.sendOrderedBroadcast(createIntent(Intent.ACTION_PACKAGE_REMOVED),
+ TEST_RECEIVER_PERMISSION);
+ fail("Context.sendOrderedBroadcast did not throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ private Intent createIntent(String action) {
+ Intent intent = new Intent();
+ intent.setAction(action);
+ return intent;
+ }
+}
diff --git a/tests/tests/permission/src/android/permission/cts/NoCallPermissionTest.java b/tests/tests/permission/src/android/permission/cts/NoCallPermissionTest.java
new file mode 100644
index 0000000..209a0f0
--- /dev/null
+++ b/tests/tests/permission/src/android/permission/cts/NoCallPermissionTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.permission.cts;
+
+import android.content.Intent;
+import android.net.Uri;
+import android.test.AndroidTestCase;
+
+/**
+ * Verify Phone calling related methods without specific Phone/Call permissions.
+ */
+public class NoCallPermissionTest extends AndroidTestCase {
+
+ /**
+ * Verify that Intent.ACTION_CALL requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#CALL_PHONE}.
+ */
+ public void testActionCall() {
+ Uri uri = Uri.parse("tel:123456");
+ Intent intent = new Intent(Intent.ACTION_CALL, uri);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ try {
+ mContext.startActivity(intent);
+ fail("startActivity(Intent.ACTION_CALL) did not throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+}
diff --git a/tests/tests/permission/src/android/permission/cts/NoKeyPermissionTest.java b/tests/tests/permission/src/android/permission/cts/NoKeyPermissionTest.java
new file mode 100644
index 0000000..568ff67d
--- /dev/null
+++ b/tests/tests/permission/src/android/permission/cts/NoKeyPermissionTest.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.permission.cts;
+
+import android.app.KeyguardManager;
+import android.content.Context;
+import android.test.AndroidTestCase;
+
+/**
+ * Verify the key input related operations require specific permissions.
+ */
+public class NoKeyPermissionTest extends AndroidTestCase {
+ KeyguardManager mKeyManager;
+ KeyguardManager.KeyguardLock mKeyLock;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mKeyManager = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
+ mKeyLock = mKeyManager.newKeyguardLock("testTag");
+ }
+
+ /**
+ * Verify that KeyguardManager.KeyguardLock.disableKeyguard requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#DISABLE_KEYGUARD}.
+ */
+ public void testDisableKeyguard() {
+ try {
+ mKeyLock.disableKeyguard();
+ fail("KeyguardManager.KeyguardLock.disableKeyguard did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that KeyguardManager.KeyguardLock.reenableKeyguard requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#DISABLE_KEYGUARD}.
+ */
+ public void testEeenableKeyguard() {
+ try {
+ mKeyLock.reenableKeyguard();
+ fail("KeyguardManager.KeyguardLock.reenableKeyguard did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that KeyguardManager.exitKeyguardSecurely requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#DISABLE_KEYGUARD}.
+ */
+ public void testExitKeyguardSecurely() {
+ try {
+ mKeyManager.exitKeyguardSecurely(null);
+ fail("KeyguardManager.exitKeyguardSecurely did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+}
diff --git a/tests/tests/permission/src/android/permission/cts/NoLocationPermissionTest.java b/tests/tests/permission/src/android/permission/cts/NoLocationPermissionTest.java
index 25cc841..5594200 100644
--- a/tests/tests/permission/src/android/permission/cts/NoLocationPermissionTest.java
+++ b/tests/tests/permission/src/android/permission/cts/NoLocationPermissionTest.java
@@ -45,6 +45,8 @@
mLocationManager = (LocationManager) getContext().getSystemService(
Context.LOCATION_SERVICE);
mAllProviders = mLocationManager.getAllProviders();
+
+ assertNotNull(mLocationManager);
assertNotNull(mAllProviders);
}
@@ -53,7 +55,7 @@
}
/**
- * Verify that listening to cell location requires permissions.
+ * Verify that listen or get cell location requires permissions.
* <p>Requires Permission:
* {@link android.Manifest.permission#ACCESS_COARSE_LOCATION.}
*/
@@ -68,16 +70,7 @@
} catch (SecurityException e) {
// expected
}
- }
- /**
- * Verify that getting cell location requires permissions.
- * <p>Requires Permission:
- * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}.
- */
- public void testGetCellLocation() {
- TelephonyManager telephonyManager = (TelephonyManager) getContext().getSystemService(
- Context.TELEPHONY_SERVICE);
try {
telephonyManager.getCellLocation();
fail("TelephonyManager.getCellLocation did not throw SecurityException as expected");
@@ -100,7 +93,6 @@
LocationListener mockListener = new MockLocationListener();
Looper looper = Looper.myLooper();
-
try {
mLocationManager.requestLocationUpdates(provider, 0, 0, mockListener);
fail("LocationManager.requestLocationUpdates did not" +
@@ -384,7 +376,7 @@
}
}
- private final class MockLocationListener implements LocationListener {
+ private static class MockLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
// ignore
}
diff --git a/tests/tests/permission/src/android/permission/cts/NoNetworkStatePermissionTest.java b/tests/tests/permission/src/android/permission/cts/NoNetworkStatePermissionTest.java
new file mode 100644
index 0000000..e1becfa
--- /dev/null
+++ b/tests/tests/permission/src/android/permission/cts/NoNetworkStatePermissionTest.java
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.permission.cts;
+
+import android.content.Context;
+import android.net.ConnectivityManager;
+import android.test.AndroidTestCase;
+
+/**
+ * Verify ConnectivityManager related methods without specific network state permissions.
+ */
+public class NoNetworkStatePermissionTest extends AndroidTestCase {
+ private ConnectivityManager mConnectivityManager;
+ private static final int TEST_NETWORK_TYPE = 1;
+ private static final int TEST_PREFERENCE = 1;
+ private static final String TEST_FEATURE = "feature";
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mConnectivityManager = (ConnectivityManager) mContext.getSystemService(
+ Context.CONNECTIVITY_SERVICE);
+ assertNotNull(mConnectivityManager);
+ }
+
+ /**
+ * Verify that ConnectivityManager#getNetworkPreference() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
+ */
+ public void testGetNetworkPreference() {
+ try {
+ mConnectivityManager.getNetworkPreference();
+ fail("ConnectivityManager.getNetworkPreference didn't throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that ConnectivityManager#getActiveNetworkInfo() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
+ */
+ public void testGetActiveNetworkInfo() {
+ try {
+ mConnectivityManager.getActiveNetworkInfo();
+ fail("ConnectivityManager.getActiveNetworkInfo didn't throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that ConnectivityManager#getNetworkInfo() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
+ */
+ public void testGetNetworkInfo() {
+ try {
+ mConnectivityManager.getNetworkInfo(TEST_NETWORK_TYPE);
+ fail("ConnectivityManager.getNetworkInfo didn't throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that ConnectivityManager#getAllNetworkInfo() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
+ */
+ public void testGetAllNetworkInfo() {
+ try {
+ mConnectivityManager.getAllNetworkInfo();
+ fail("ConnectivityManager.getAllNetworkInfo didn't throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that ConnectivityManager#setNetworkPreference() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
+ */
+ public void testSetNetworkPreference() {
+ try {
+ mConnectivityManager.setNetworkPreference(TEST_PREFERENCE);
+ fail("ConnectivityManager.setNetworkPreference didn't throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that ConnectivityManager#startUsingNetworkFeature() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
+ */
+ public void testStartUsingNetworkFeature() {
+ try {
+ mConnectivityManager.startUsingNetworkFeature(TEST_NETWORK_TYPE, TEST_FEATURE);
+ fail("ConnectivityManager.startUsingNetworkFeature didn't throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that ConnectivityManager#stopUsingNetworkFeature() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
+ */
+ public void testStopUsingNetworkFeature() {
+ try {
+ mConnectivityManager.stopUsingNetworkFeature(TEST_NETWORK_TYPE, TEST_FEATURE);
+ fail("ConnectivityManager.stopUsingNetworkFeature didn't throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that ConnectivityManager#requestRouteToHost() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
+ */
+ public void testRequestRouteToHost() {
+ try {
+ mConnectivityManager.requestRouteToHost(TEST_NETWORK_TYPE, 0xffffffff);
+ fail("ConnectivityManager.requestRouteToHost didn't throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+}
diff --git a/tests/tests/permission/src/android/permission/cts/NoWifiStatePermissionTest.java b/tests/tests/permission/src/android/permission/cts/NoWifiStatePermissionTest.java
new file mode 100644
index 0000000..ec1cc51
--- /dev/null
+++ b/tests/tests/permission/src/android/permission/cts/NoWifiStatePermissionTest.java
@@ -0,0 +1,278 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.permission.cts;
+
+import android.content.Context;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
+import android.test.AndroidTestCase;
+
+/**
+ * Verify WifiManager related methods without specific Wifi state permissions.
+ */
+public class NoWifiStatePermissionTest extends AndroidTestCase {
+ private static final int TEST_NET_ID = 1;
+ private static final WifiConfiguration TEST_WIFI_CONFIGURATION = new WifiConfiguration();
+ private WifiManager mWifiManager;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
+ assertNotNull(mWifiManager);
+ }
+
+ /**
+ * Verify that WifiManager#getWifiState() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#ACCESS_WIFI_STATE}.
+ */
+ public void testGetWifiState() {
+ try {
+ mWifiManager.getWifiState();
+ fail("WifiManager.getWifiState didn't throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that WifiManager#getConfiguredNetworks() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#ACCESS_WIFI_STATE}.
+ */
+ public void testGetConfiguredNetworks() {
+ try {
+ mWifiManager.getConfiguredNetworks();
+ fail("WifiManager.getConfiguredNetworks didn't throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that WifiManager#getConnectionInfo() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#ACCESS_WIFI_STATE}.
+ */
+ public void testGetConnectionInfo() {
+ try {
+ mWifiManager.getConnectionInfo();
+ fail("WifiManager.getConnectionInfo didn't throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that WifiManager#getScanResults() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#ACCESS_WIFI_STATE}.
+ */
+ public void testGetScanResults() {
+ try {
+ mWifiManager.getScanResults();
+ fail("WifiManager.getScanResults didn't throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that WifiManager#getDhcpInfo() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#ACCESS_WIFI_STATE}.
+ */
+ public void testGetDhcpInfo() {
+ try {
+ mWifiManager.getDhcpInfo();
+ fail("WifiManager.getDhcpInfo didn't throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that WifiManager#disconnect() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#CHANGE_WIFI_STATE}.
+ */
+ public void testDisconnect() {
+ try {
+ mWifiManager.disconnect();
+ fail("WifiManager.disconnect didn't throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that WifiManager#reconnect() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#CHANGE_WIFI_STATE}.
+ */
+ public void testReconnect() {
+ try {
+ mWifiManager.reconnect();
+ fail("WifiManager.reconnect didn't throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that WifiManager#reassociate() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#CHANGE_WIFI_STATE}.
+ */
+ public void testReassociate() {
+ try {
+ mWifiManager.reassociate();
+ fail("WifiManager.reassociate didn't throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that WifiManager#addNetwork() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#CHANGE_WIFI_STATE}.
+ */
+ public void testAddNetwork() {
+ try {
+ mWifiManager.addNetwork(TEST_WIFI_CONFIGURATION);
+ fail("WifiManager.addNetwork didn't throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that WifiManager#updateNetwork() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#CHANGE_WIFI_STATE}.
+ */
+ public void testUpdateNetwork() {
+ TEST_WIFI_CONFIGURATION.networkId = 2;
+
+ try {
+ mWifiManager.updateNetwork(TEST_WIFI_CONFIGURATION);
+ fail("WifiManager.updateNetwork didn't throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that WifiManager#removeNetwork() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#CHANGE_WIFI_STATE}.
+ */
+ public void testRemoveNetwork() {
+ try {
+ mWifiManager.removeNetwork(TEST_NET_ID);
+ fail("WifiManager.removeNetwork didn't throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that WifiManager#enableNetwork() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#CHANGE_WIFI_STATE}.
+ */
+ public void testEnableNetwork() {
+ try {
+ mWifiManager.enableNetwork(TEST_NET_ID, false);
+ fail("WifiManager.enableNetwork didn't throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that WifiManager#disableNetwork() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#CHANGE_WIFI_STATE}.
+ */
+ public void testDisableNetwork() {
+ try {
+ mWifiManager.disableNetwork(TEST_NET_ID);
+ fail("WifiManager.disableNetwork didn't throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that WifiManager#saveConfiguration() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#CHANGE_WIFI_STATE}.
+ */
+ public void testSaveConfiguration() {
+ try {
+ mWifiManager.saveConfiguration();
+ fail("WifiManager.saveConfiguration didn't throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that WifiManager#pingSupplicant() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#CHANGE_WIFI_STATE}.
+ */
+ public void testPingSupplicant() {
+ try {
+ mWifiManager.pingSupplicant();
+ fail("WifiManager.pingSupplicant didn't throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that WifiManager#startScan() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#CHANGE_WIFI_STATE}.
+ */
+ public void testStartScan() {
+ try {
+ mWifiManager.startScan();
+ fail("WifiManager.startScan didn't throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that WifiManager#setWifiEnabled() requires permissions.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#CHANGE_WIFI_STATE}.
+ */
+ public void testSetWifiEnabled() {
+ try {
+ mWifiManager.setWifiEnabled(true);
+ fail("WifiManager.setWifiEnabled didn't throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+}
diff --git a/tests/tests/permission/src/android/permission/cts/PackageManagerRequiringPermissionsTest.java b/tests/tests/permission/src/android/permission/cts/PackageManagerRequiringPermissionsTest.java
new file mode 100644
index 0000000..2dc87d8
--- /dev/null
+++ b/tests/tests/permission/src/android/permission/cts/PackageManagerRequiringPermissionsTest.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.permission.cts;
+
+import android.content.pm.PackageManager;
+import android.test.AndroidTestCase;
+
+/**
+ * Verify the PackageManager related operations require specific permissions.
+ */
+public class PackageManagerRequiringPermissionsTest extends AndroidTestCase {
+ private static final String PACKAGE_NAME = "com.android.cts.stub";
+ private PackageManager mPackageManager;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mPackageManager = getContext().getPackageManager();
+ assertNotNull(mPackageManager);
+ }
+
+ /**
+ * Verify that PackageManager.setApplicationEnabledSetting requires permission.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#CHANGE_COMPONENT_ENABLED_STATE}.
+ */
+ public void testSetApplicationEnabledSetting() {
+ try {
+ mPackageManager.setApplicationEnabledSetting(PACKAGE_NAME,
+ PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
+ PackageManager.DONT_KILL_APP);
+ fail("PackageManager.setApplicationEnabledSetting did not throw SecurityException as"
+ + "expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that PackageManager.installPackage(Uri, IPackageInstallObserver, int) requires
+ * permission.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#INSTALL_PACKAGES}.
+ */
+ public void testInstallPackage() {
+ try {
+ mPackageManager.installPackage(null, null, 0);
+ fail("PackageManager.installPackage(Uri, IPackageInstallObserver, int)" +
+ " did not throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that PackageManager.installPackage(Uri) requires
+ * permission.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#INSTALL_PACKAGES}.
+ */
+ public void testInstallPackage2() {
+ try {
+ mPackageManager.installPackage(null);
+ fail("PackageManager.installPackage(Uri) did not throw SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that PackageManager.addPackageToPreferred requires permission.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#SET_PREFERRED_APPLICATIONS}.
+ */
+ public void testAddPackageToPreferred() {
+ try {
+ mPackageManager.addPackageToPreferred(null);
+ fail("PackageManager.addPackageToPreferred did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that PackageManager.removePackageFromPreferred requires permission.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#SET_PREFERRED_APPLICATIONS}.
+ */
+ public void testRemovePackageFromPreferred() {
+ try {
+ mPackageManager.removePackageFromPreferred(null);
+ fail("PackageManager.removePackageFromPreferred did not throw SecurityException as"
+ + "expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that PackageManager.addPreferredActivity requires permission.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#SET_PREFERRED_APPLICATIONS}.
+ */
+ public void testAddPreferredActivity() {
+ try {
+ mPackageManager.addPreferredActivity(null, 0, null, null);
+ fail("PackageManager.addPreferredActivity did not throw" +
+ " SecurityException as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that PackageManager.clearPackagePreferredActivities requires permission.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#SET_PREFERRED_APPLICATIONS}.
+ */
+ public void testClearPackagePreferredActivities() {
+ try {
+ mPackageManager.clearPackagePreferredActivities(null);
+ fail("PackageManager.clearPackagePreferredActivities did not throw SecurityException"
+ + " as expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+}