Merge change 3250 into donut

* changes:
  Integrate unsubmitted cupcake change 147444:     CTS: add permission test cases: NoActivityRelatedPermissionTest,     NoAudioPermissionTest, NoReadWritePermissionTest, NoReadLogsPermissionTest,     NoWakeLockPermissionTest and NoSystemFunctionPermissionTest
diff --git a/tests/tests/permission/Android.mk b/tests/tests/permission/Android.mk
index 7988384..869c19b 100644
--- a/tests/tests/permission/Android.mk
+++ b/tests/tests/permission/Android.mk
@@ -25,8 +25,6 @@
 
 LOCAL_PACKAGE_NAME := CtsPermissionTestCases
 
-LOCAL_INSTRUMENTATION_FOR := android.core.tests.runner
-
 LOCAL_SDK_VERSION := current
 
 include $(BUILD_PACKAGE)
diff --git a/tests/tests/permission/AndroidManifest.xml b/tests/tests/permission/AndroidManifest.xml
index 1ddadd0..f824c7d 100644
--- a/tests/tests/permission/AndroidManifest.xml
+++ b/tests/tests/permission/AndroidManifest.xml
@@ -20,10 +20,27 @@
 
     <application>
         <uses-library android:name="android.test.runner" />
+        <activity android:name="android.permission.cts.PermissionStubActivity"
+                  android:label="PermissionStubActivity">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN"/>
+                <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST"/>
+            </intent-filter>
+        </activity>
     </application>
 
-    <instrumentation android:name="android.test.InstrumentationCtsTestRunner"
-                     android:targetPackage="android.core.tests.runner"
+    <!--
+        The CTS stubs package cannot be used as the target application here,
+        since that requires many permissions to be set. Instead, specify this
+        package itself as the target and include any stub activities needed.
+
+        This test package uses the default InstrumentationTestRunner, because
+        the InstrumentationCtsTestRunner is only available in the stubs
+        package. That runner cannot be added to this package either, since it
+        relies on hidden APIs.
+    -->
+    <instrumentation android:name="android.test.InstrumentationTestRunner"
+                     android:targetPackage="com.android.cts.permission"
                      android:label="CTS tests of com.android.cts.permission"/>
 
 </manifest>
diff --git a/tests/tests/permission/src/android/permission/cts/NoActivityRelatedPermissionTest.java b/tests/tests/permission/src/android/permission/cts/NoActivityRelatedPermissionTest.java
new file mode 100644
index 0000000..1d0ba36
--- /dev/null
+++ b/tests/tests/permission/src/android/permission/cts/NoActivityRelatedPermissionTest.java
@@ -0,0 +1,120 @@
+/*
+ * 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 dalvik.annotation.TestTargetClass;
+
+import android.app.Activity;
+import android.app.ActivityManager;
+import android.app.AlertDialog;
+import android.content.Context;
+import android.test.ActivityInstrumentationTestCase2;
+import android.test.UiThreadTest;
+import android.view.WindowManager;
+import android.view.WindowManager.BadTokenException;
+
+/**
+ * Verify the Activity related operations require specific permissions.
+ */
+@TestTargetClass(Activity.class)
+public class NoActivityRelatedPermissionTest
+        extends ActivityInstrumentationTestCase2<PermissionStubActivity> {
+
+    private PermissionStubActivity mActivity;
+
+    public NoActivityRelatedPermissionTest() {
+        super("com.android.cts.permission", PermissionStubActivity.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mActivity = getActivity();
+    }
+
+    /**
+     * Verify that adding window of different types in Window Manager requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#SYSTEM_ALERT_WINDOW}.
+     */
+    @UiThreadTest
+    public void testSystemAlertWindow() {
+        final int[] types = new int[] {
+                WindowManager.LayoutParams.TYPE_PHONE,
+                WindowManager.LayoutParams.TYPE_PRIORITY_PHONE,
+                WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
+                WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
+                WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
+            };
+
+        AlertDialog dialog = (AlertDialog) (mActivity.getDialog());
+        // Use normal window type will success
+        dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION);
+        dialog.show();
+
+        // Test special window types which need to be check SYSTEM_ALERT_WINDOW
+        // permission.
+        for (int i = 0; i < types.length; i++) {
+            dialog = (AlertDialog) (mActivity.getDialog());
+            dialog.getWindow().setType(types[i]);
+            try {
+                dialog.show();
+                fail("Add dialog to Window Manager did not throw BadTokenException as expected");
+            } catch (BadTokenException e) {
+                // Expected
+            }
+        }
+    }
+
+    /**
+     * Verify that setting Activity's persistent attribute requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#PERSISTENT_ACTIVITY}.
+     */
+    @UiThreadTest
+    public void testSetPersistent() {
+        try {
+            mActivity.setPersistent(true);
+            fail("Activity.setPersistent() did not throw SecurityException as expected");
+        } catch (SecurityException e) {
+            // Expected
+        }
+    }
+
+    /**
+     * Verify that get task requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#GET_TASKS}
+     */
+    public void testGetTask() {
+        ActivityManager manager = (ActivityManager) getActivity()
+                .getSystemService(Context.ACTIVITY_SERVICE);
+        try {
+            manager.getRunningTasks(1);
+            fail("Activity.getRunningTasks did not throw SecurityException as expected");
+        } catch (SecurityException e) {
+            // Expected
+        }
+
+        try {
+            manager.getRecentTasks(1, 0);
+            fail("Activity.getRunningTasks did not throw SecurityException as expected");
+        } catch (SecurityException e) {
+            // Expected
+        }
+    }
+}
diff --git a/tests/tests/permission/src/android/permission/cts/NoAudioPermissionTest.java b/tests/tests/permission/src/android/permission/cts/NoAudioPermissionTest.java
new file mode 100644
index 0000000..b850c31
--- /dev/null
+++ b/tests/tests/permission/src/android/permission/cts/NoAudioPermissionTest.java
@@ -0,0 +1,112 @@
+/*
+ * 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.media.AudioManager;
+import android.test.AndroidTestCase;
+
+/**
+ * Verify the audio related operations require specific permissions.
+ */
+public class NoAudioPermissionTest extends AndroidTestCase {
+    private AudioManager mAudioManager;
+    private static final int MODE_COUNT = 3;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
+        assertNotNull(mAudioManager);
+    }
+
+    /**
+     * Verify that AudioManager.setMicrophoneMute, AudioManager.setMode requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#MODIFY_AUDIO_SETTINGS}.
+     */
+    public void testSetMicrophoneMute() {
+        boolean muteState = mAudioManager.isMicrophoneMute();
+        int originalMode = mAudioManager.getMode();
+        // If there is no permission of MODIFY_AUDIO_SETTINGS, setMicrophoneMute does nothing.
+        mAudioManager.setMicrophoneMute(!muteState);
+        assertEquals(muteState, mAudioManager.isMicrophoneMute());
+
+        // If there is no permission of MODIFY_AUDIO_SETTINGS, setMode does nothing.
+        assertTrue(AudioManager.MODE_NORMAL != AudioManager.MODE_RINGTONE);
+
+        mAudioManager.setMode(AudioManager.MODE_NORMAL);
+        assertEquals(originalMode, mAudioManager.getMode());
+
+        mAudioManager.setMode(AudioManager.MODE_RINGTONE);
+        assertEquals(originalMode, mAudioManager.getMode());
+    }
+
+    /**
+     * Verify that AudioManager.setRouting requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#MODIFY_AUDIO_SETTINGS}.
+     */
+    @SuppressWarnings("deprecation")
+    public void testSetRouting() {
+        int[] defaultRoutes = new int[MODE_COUNT];
+        defaultRoutes[0] = mAudioManager.getRouting(AudioManager.MODE_NORMAL);
+        defaultRoutes[1] = mAudioManager.getRouting(AudioManager.MODE_RINGTONE);
+        defaultRoutes[2] = mAudioManager.getRouting(AudioManager.MODE_IN_CALL);
+
+        // If there is no permission of MODIFY_AUDIO_SETTINGS, setRouting does nothing.
+        // Please referring android.media.cts.AudioManagerTest#testRouting().
+        mAudioManager.setBluetoothScoOn(true);
+        mAudioManager.setRouting(AudioManager.MODE_IN_CALL, AudioManager.ROUTE_BLUETOOTH_SCO,
+                AudioManager.ROUTE_ALL);
+        assertEquals(defaultRoutes[0], getRouting(AudioManager.MODE_NORMAL));
+        assertEquals(defaultRoutes[1], getRouting(AudioManager.MODE_RINGTONE));
+        assertEquals(defaultRoutes[2], getRouting(AudioManager.MODE_IN_CALL));
+
+        mAudioManager.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_SPEAKER,
+                AudioManager.ROUTE_ALL);
+        mAudioManager.setRouting(AudioManager.MODE_RINGTONE, AudioManager.ROUTE_SPEAKER,
+                AudioManager.ROUTE_ALL);
+        mAudioManager.setRouting(AudioManager.MODE_IN_CALL, AudioManager.ROUTE_SPEAKER,
+                AudioManager.ROUTE_ALL);
+        assertEquals(defaultRoutes[0], getRouting(AudioManager.MODE_NORMAL));
+        assertEquals(defaultRoutes[1], getRouting(AudioManager.MODE_RINGTONE));
+        assertEquals(defaultRoutes[2], getRouting(AudioManager.MODE_IN_CALL));
+
+        mAudioManager.setSpeakerphoneOn(true);
+        assertFalse(mAudioManager.isSpeakerphoneOn());
+        assertEquals(defaultRoutes[2], getRouting(AudioManager.MODE_IN_CALL));
+        mAudioManager.setSpeakerphoneOn(false);
+        assertFalse(mAudioManager.isSpeakerphoneOn());
+        assertEquals(defaultRoutes[2], getRouting(AudioManager.MODE_IN_CALL));
+
+        mAudioManager.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_EARPIECE,
+                AudioManager.ROUTE_ALL);
+        mAudioManager.setRouting(AudioManager.MODE_RINGTONE, AudioManager.ROUTE_EARPIECE,
+                AudioManager.ROUTE_ALL);
+        mAudioManager.setRouting(AudioManager.MODE_IN_CALL, AudioManager.ROUTE_EARPIECE,
+                AudioManager.ROUTE_ALL);
+        assertEquals(defaultRoutes[0], getRouting(AudioManager.MODE_NORMAL));
+        assertEquals(defaultRoutes[1], getRouting(AudioManager.MODE_RINGTONE));
+        assertEquals(defaultRoutes[2], getRouting(AudioManager.MODE_IN_CALL));
+    }
+
+    @SuppressWarnings("deprecation")
+    private int getRouting(int mode) {
+        return mAudioManager.getRouting(mode);
+    }
+}
diff --git a/tests/tests/permission/src/android/permission/cts/NoReadLogsPermissionTest.java b/tests/tests/permission/src/android/permission/cts/NoReadLogsPermissionTest.java
new file mode 100644
index 0000000..aa6e02b
--- /dev/null
+++ b/tests/tests/permission/src/android/permission/cts/NoReadLogsPermissionTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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 java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import android.test.AndroidTestCase;
+import android.util.Log;
+
+/**
+ * Verify the read system log require specific permissions.
+ */
+public class NoReadLogsPermissionTest extends AndroidTestCase {
+    private static final String LOGTAG = "CTS";
+
+    /**
+     * Verify that we won't get the system log without a READ_LOGS permission.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#READ_LOGS }.
+     * @throws IOException
+     */
+    public void testSetMicrophoneMute() throws IOException {
+        Process logcatProc = null;
+        BufferedReader reader = null;
+        try {
+            logcatProc = Runtime.getRuntime().exec(new String[]
+                    {"logcat", "-d", "AndroidRuntime:E :" + LOGTAG + ":V *:S" });
+            Log.d(LOGTAG, "no read logs permission test");
+
+            reader = new BufferedReader(new InputStreamReader(logcatProc.getInputStream()));
+
+            String line;
+            final StringBuilder log = new StringBuilder();
+            String separator = System.getProperty("line.separator");
+            while ((line = reader.readLine()) != null) {
+                log.append(line);
+                log.append(separator);
+            }
+            // no permission get empty log
+            assertEquals(0, log.length());
+
+        } finally {
+            if (reader != null) {
+                reader.close();
+            }
+        }
+    }
+}
diff --git a/tests/tests/permission/src/android/permission/cts/NoReadWritePermissionTest.java b/tests/tests/permission/src/android/permission/cts/NoReadWritePermissionTest.java
new file mode 100644
index 0000000..73d6c8e
--- /dev/null
+++ b/tests/tests/permission/src/android/permission/cts/NoReadWritePermissionTest.java
@@ -0,0 +1,194 @@
+/*
+ * 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 dalvik.annotation.ToBeFixed;
+
+import android.content.ContentResolver;
+import android.content.ContentValues;
+import android.net.Uri;
+import android.provider.Contacts;
+import android.provider.Settings;
+import android.test.AndroidTestCase;
+/**
+ * Verify the location access without specific permissions.
+ */
+public class NoReadWritePermissionTest extends AndroidTestCase {
+    private ContentResolver mContentResolver;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mContentResolver = getContext().getContentResolver();
+    }
+
+    private void queryProvider(Uri uri) {
+        try {
+            mContentResolver.query(uri, null, null, null, null);
+            fail("read from provider did not throw SecurityException as expected.");
+        } catch (SecurityException e) {
+            // expected
+        }
+    }
+
+    private void insertProvider(Uri uri, ContentValues values) {
+        try {
+            mContentResolver.insert(uri, values);
+            fail("Write into provider did not throw SecurityException as expected.");
+        } catch (SecurityException e) {
+            // expected
+        }
+    }
+
+    /**
+     * Verify that read and write to calendar requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#READ_CALENDAR}
+     *   {@link android.Manifest.permission#WRITE_CALENDAR}
+     */
+    public void testReadWriteCalendar() {
+        Uri uri = Uri.parse("content://calendar/events/");
+
+        // read permission
+        queryProvider(uri);
+
+            // write permission
+        ContentValues values = new ContentValues();
+        values.put("eventTimezone", "EST");
+        values.put("calendar_id", 1);
+        values.put("title", "Party over thurr");
+        values.put("allDay", 0);
+        values.put("transparency", 0);
+        values.put("visibility", 0);
+        values.put("hasAlarm", 0);
+
+        insertProvider(uri, values);
+    }
+
+    /**
+     * Verify that read and write to contact requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#READ_CONTACTS}
+     *   {@link android.Manifest.permission#WRITE_CONTACTS}
+     */
+    public void testReadWriteContacts() {
+        Uri uri = Contacts.People.CONTENT_URI;
+
+        // read permission
+        queryProvider(uri);
+
+
+        // write permission
+        ContentValues values = new ContentValues();
+        values.put(Contacts.People.NAME, "New Contact");
+
+        insertProvider(uri, values);
+    }
+
+    /**
+     * Verify that read and write to sms requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#READ_SMS}
+     *   {@link android.Manifest.permission#WRITE_SMS}
+     */
+    public void testReadWriteSms() {
+        Uri uri = Uri.parse("content://sms/inbox");
+
+        // read permission
+        queryProvider(uri);
+
+        // write permission
+        ContentValues values = new ContentValues();
+        values.put("person", "google");
+
+        insertProvider(uri, values);
+    }
+
+    /**
+     * Verify that read and write to sync settings requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#READ_SYNC_SETTINGS}
+     *   {@link android.Manifest.permission#WRITE_SYNC_SETTINGS}
+     */
+    public void testReadWriteSyncSettings() {
+        Uri uri = Uri.parse("content://sync/settings");
+
+        // read permission
+        queryProvider(uri);
+
+        // write permission
+        ContentValues values = new ContentValues();
+        values.put("name", "vendor");
+        values.put("value", "google");
+
+        insertProvider(uri, values);
+    }
+
+    /**
+     * Verify that read to sync stats requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#READ_SYNC_STATS}
+     */
+    public void testReadSyncStats() {
+        Uri uri = Uri.parse("content://sync/stats");
+
+        // read permission
+        queryProvider(uri);
+    }
+
+    /**
+     * Verify that write to apn settings requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#WRITE_APN_SETTINGS}
+     */
+    public void testWriteApnSettings() {
+        Uri uri = Uri.parse("content://telephony/carriers");
+
+        // write permission
+        ContentValues values = new ContentValues();
+        values.put("apn", "google");
+
+        insertProvider(uri, values);
+    }
+
+    /**
+     * Verify that write to settings requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#WRITE_SETTINGS}
+     */
+    public void testWriteSettings() {
+        Uri uri = Uri.parse("content://" + Settings.AUTHORITY + "/bookmarks");
+
+        // write permission
+        ContentValues values = new ContentValues();
+        values.put("title", "google");
+
+        insertProvider(uri, values);
+    }
+
+    /**
+     * Verify that read and write of subsribedfeeds requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#SUBSCRIBED_FEEDS_READ}
+     *   {@link android.Manifest.permission#SUBSCRIBED_FEEDS_WRITE}
+     */
+    @ToBeFixed(bug = "", explanation = "access subscribedfeeds data through ContentResolver"
+            + " should check permission of android.Manifest.permission#SUBSCRIBED_FEEDS.")
+    public void testReadSubscribedFeeds() {
+
+    }
+}
diff --git a/tests/tests/permission/src/android/permission/cts/NoSystemFunctionPermissionTest.java b/tests/tests/permission/src/android/permission/cts/NoSystemFunctionPermissionTest.java
new file mode 100644
index 0000000..c3e1474
--- /dev/null
+++ b/tests/tests/permission/src/android/permission/cts/NoSystemFunctionPermissionTest.java
@@ -0,0 +1,152 @@
+/*
+ * 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.ActivityManager;
+import android.app.AlarmManager;
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.os.Vibrator;
+import android.telephony.gsm.SmsManager;
+import android.test.AndroidTestCase;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.TimeZone;
+
+/**
+ * Verify the system function require specific permissions.
+ */
+@SuppressWarnings("deprecation")
+public class NoSystemFunctionPermissionTest extends AndroidTestCase {
+
+    /**
+     * Verify that ActivityManager.restartPackage() requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#RESTART_PACKAGES}.
+     */
+    public void testRestartPackage() {
+        ActivityManager activityManager = (ActivityManager) mContext.getSystemService(
+                Context.ACTIVITY_SERVICE);
+
+        try {
+            activityManager.restartPackage("packageName");
+            fail("ActivityManager.restartPackage() didn't throw SecurityException as expected.");
+        } catch (SecurityException e) {
+            // expected
+        }
+    }
+
+    /**
+     * Verify that AlarmManager.setTimeZone() requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#SET_TIME_ZONE}.
+     */
+    public void testSetTimeZone() {
+        AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(
+                Context.ALARM_SERVICE);
+        String[] timeZones = TimeZone.getAvailableIDs();
+        String timeZone = timeZones[0];
+
+        try {
+            alarmManager.setTimeZone(timeZone);
+            fail("AlarmManager.setTimeZone() did not throw SecurityException as expected.");
+        } catch (SecurityException e) {
+            // expected
+        }
+    }
+
+    /**
+     * Verify that setting wallpaper relate methods require permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#SET_WALLPAPER}.
+     * @throws IOException 
+     */
+    public void testSetWallpaper() throws IOException {
+        Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565);
+
+        try {
+            mContext.setWallpaper(bitmap);
+            fail("Context.setWallpaper(BitMap) did not throw SecurityException as expected.");
+        } catch (SecurityException e) {
+            // expected
+        }
+
+        try {
+            mContext.setWallpaper((InputStream) null);
+            fail("Context.setWallpaper(InputStream) did not throw SecurityException as expected.");
+        } catch (SecurityException e) {
+            // expected
+        }
+
+        try {
+            mContext.clearWallpaper();
+            fail("Context.clearWallpaper() did not throw SecurityException as expected.");
+        } catch (SecurityException e) {
+            // expected
+        }
+    }
+
+    /**
+     * Verify that Vibrator's vibrating related methods requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#VIBRATE}.
+     */
+    public void testVibrator() {
+        Vibrator vibrator = (Vibrator)getContext().getSystemService(Context.VIBRATOR_SERVICE);
+
+        try {
+            vibrator.cancel();
+            fail("Vibrator.cancel() did not throw SecurityException as expected.");
+        } catch (SecurityException e) {
+            // expected
+        }
+
+        try {
+            vibrator.vibrate(1);
+            fail("Vibrator.vibrate(long) did not throw SecurityException as expected.");
+        } catch (SecurityException e) {
+            // expected
+        }
+
+        long[] testPattern = {1, 1, 1, 1, 1};
+
+        try {
+            vibrator.vibrate(testPattern, 1);
+            fail("Vibrator.vibrate(long[], int) not throw SecurityException as expected.");
+        } catch (SecurityException e) {
+            // expected
+        }
+    }
+
+    /**
+     * Verify that sending sms requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#SMS}.
+     */
+    public void testSendSms() {
+        SmsManager smsManager = SmsManager.getDefault();
+        byte[] testData = new byte[10];
+        try {
+            smsManager.sendDataMessage("1233", "1233", (short) 0, testData, null, null);
+            fail("SmsManager.sendDataMessage() did not throw SecurityException as expected.");
+        } catch (SecurityException e) {
+            // expected
+        }
+    }
+}
diff --git a/tests/tests/permission/src/android/permission/cts/NoWakeLockPermissionTest.java b/tests/tests/permission/src/android/permission/cts/NoWakeLockPermissionTest.java
new file mode 100644
index 0000000..0bc573e
--- /dev/null
+++ b/tests/tests/permission/src/android/permission/cts/NoWakeLockPermissionTest.java
@@ -0,0 +1,120 @@
+/*
+ * 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.media.MediaPlayer;
+import android.net.wifi.WifiManager;
+import android.net.wifi.WifiManager.WifiLock;
+import android.os.PowerManager;
+import android.test.AndroidTestCase;
+
+/**
+ * Verify the Wake Lock related operations require specific permissions.
+ */
+public class NoWakeLockPermissionTest extends AndroidTestCase {
+    private PowerManager mPowerManager;
+
+    private PowerManager.WakeLock mWakeLock;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
+        mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "tag");
+    }
+
+    /**
+     * Verify that WifiManager.WifiLock.acquire() requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#WAKE_LOCK}.
+     */
+    public void testWifiLockAcquire() {
+        final WifiManager wifiManager = (WifiManager) mContext.getSystemService(
+                Context.WIFI_SERVICE);
+        final WifiLock wifiLock = wifiManager.createWifiLock("WakeLockPermissionTest");
+        try {
+            wifiLock.acquire();
+            fail("WifiManager.WifiLock.acquire() didn't throw SecurityException as expected");
+        } catch (SecurityException e) {
+            // expected
+        }
+    }
+
+    /**
+     * Verify that MediaPlayer.start() requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#WAKE_LOCK}.
+     */
+    public void testMediaPlayerWakeLock() {
+        final MediaPlayer mediaPlayer = new MediaPlayer();
+        mediaPlayer.setWakeMode(mContext, PowerManager.FULL_WAKE_LOCK);
+        try {
+            mediaPlayer.start();
+            fail("MediaPlayer.setWakeMode() did not throw SecurityException as expected");
+        } catch (SecurityException e) {
+            // expected
+        }
+
+        mediaPlayer.stop();
+    }
+
+    /**
+     * Verify that PowerManager.WakeLock.acquire() requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#WAKE_LOCK}.
+     */
+    public void testPowerManagerWakeLockAcquire() {
+        try {
+            mWakeLock.acquire();
+            fail("MediaPlayer.setWakeMode() did not throw SecurityException as expected");
+        } catch (SecurityException e) {
+            // expected
+        }
+    }
+
+    /**
+     * Verify that PowerManager.WakeLock.acquire(long) requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#WAKE_LOCK}.
+     */
+    public void testPowerManagerWakeLockAcquire2() {
+        // Tset acquire(long)
+        try {
+            mWakeLock.acquire(1);
+            fail("MediaPlayer.setWakeMode(long) did not throw SecurityException as expected");
+        } catch (SecurityException e) {
+            // expected
+        }
+    }
+
+    /**
+     * Verify that PowerManager.WakeLock.release() requires permissions.
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#WAKE_LOCK}.
+     */
+    public void testPowerManagerWakeLockRelease() {
+        mWakeLock.setReferenceCounted(false);
+        try {
+            mWakeLock.release();
+            fail("MediaPlayer.setWakeMode(long) did not throw SecurityException as expected");
+        } catch (SecurityException e) {
+            // expected
+        }
+    }
+}
diff --git a/tests/tests/permission/src/android/permission/cts/PermissionStubActivity.java b/tests/tests/permission/src/android/permission/cts/PermissionStubActivity.java
new file mode 100644
index 0000000..dd61177
--- /dev/null
+++ b/tests/tests/permission/src/android/permission/cts/PermissionStubActivity.java
@@ -0,0 +1,46 @@
+/*
+ * 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.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.os.Bundle;
+import android.view.ViewGroup.LayoutParams;
+import android.widget.ListView;
+
+/**
+ * A minimal application for Window test.
+ */
+public class PermissionStubActivity extends Activity {
+    private ListView mListView;
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        mListView = new ListView(this);
+        mListView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
+                LayoutParams.WRAP_CONTENT));
+
+        setContentView(mListView);
+    }
+
+    public Dialog getDialog() {
+        return new AlertDialog.Builder(PermissionStubActivity.this).create();
+    }
+}