2 * Copyright (C) 2006 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.framework.permission.tests;
19 import junit.framework.TestCase;
20 import android.content.pm.PackageManager;
21 import android.test.AndroidTestCase;
22 import android.test.suitebuilder.annotation.SmallTest;
25 * Verify PackageManager api's that require specific permissions.
27 public class PmPermissionsTests extends AndroidTestCase {
28 private PackageManager mPm;
29 private String mPkgName = "com.android.framework.permission.tests";
32 protected void setUp() throws Exception {
34 mPm = getContext().getPackageManager();
38 * This test verifies that PackageManger.getPackageSizeInfo enforces permission
39 * android.permission.GET_PACKAGE_SIZE
42 public void testGetPackageSize() {
44 mPm.getPackageSizeInfo(mPkgName, null);
45 fail("PackageManager.getPackageSizeInfo" +
46 "did not throw SecurityException as expected");
47 } catch (SecurityException e) {
53 * This test verifies that PackageManger.DeleteApplicationCacheFiles enforces permission
54 * android.permission.DELETE_CACHE_FILES
57 public void testDeleteApplicationCacheFiles() {
59 mPm.deleteApplicationCacheFiles(mPkgName, null);
60 fail("PackageManager.deleteApplicationCacheFiles" +
61 "did not throw SecurityException as expected");
62 } catch (SecurityException e) {
68 * This test verifies that PackageManger.installPackage enforces permission
69 * android.permission.INSTALL_PACKAGES
72 public void testInstallPackage() {
74 mPm.installPackage(null, null, 0, null);
75 fail("PackageManager.installPackage" +
76 "did not throw SecurityException as expected");
77 } catch (SecurityException e) {
83 * This test verifies that PackageManger.freeStorage
84 * enforces permission android.permission.CLEAR_APP_CACHE
87 public void testFreeStorage1() {
89 mPm.freeStorage(100000, null);
90 fail("PackageManager.freeStorage " +
91 "did not throw SecurityException as expected");
92 } catch (SecurityException e) {
98 * This test verifies that PackageManger.freeStorageAndNotify
99 * enforces permission android.permission.CLEAR_APP_CACHE
102 public void testFreeStorage2() {
104 mPm.freeStorageAndNotify(100000, null);
105 fail("PackageManager.freeStorageAndNotify" +
106 " did not throw SecurityException as expected");
107 } catch (SecurityException e) {
113 * This test verifies that PackageManger.clearApplicationUserData
114 * enforces permission android.permission.CLEAR_APP_USER_DATA
117 public void testClearApplicationUserData() {
119 mPm.clearApplicationUserData(mPkgName, null);
120 fail("PackageManager.clearApplicationUserData" +
121 "did not throw SecurityException as expected");
122 } catch (SecurityException e) {
128 * This test verifies that PackageManger.deletePackage
129 * enforces permission android.permission.DELETE_PACKAGES
132 public void testDeletePackage() {
134 mPm.deletePackage(mPkgName, null, 0);
135 fail("PackageManager.deletePackage" +
136 "did not throw SecurityException as expected");
137 } catch (SecurityException e) {