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 com.android.framework.permission.tests; 18 19 import android.app.PackageInstallObserver; 20 import android.content.pm.PackageManager; 21 import android.test.AndroidTestCase; 22 import android.test.suitebuilder.annotation.SmallTest; 23 24 /** 25 * Verify PackageManager api's that require specific permissions. 26 */ 27 public class PmPermissionsTests extends AndroidTestCase { 28 private PackageManager mPm; 29 private String mPkgName = "com.android.framework.permission.tests"; 30 31 @Override 32 protected void setUp() throws Exception { 33 super.setUp(); 34 mPm = getContext().getPackageManager(); 35 } 36 37 /* 38 * This test verifies that PackageManger.getPackageSizeInfo enforces permission 39 * android.permission.GET_PACKAGE_SIZE 40 */ 41 @SmallTest 42 public void testGetPackageSize() { 43 try { 44 mPm.getPackageSizeInfo(mPkgName, null); 45 fail("PackageManager.getPackageSizeInfo" + 46 "did not throw SecurityException as expected"); 47 } catch (SecurityException e) { 48 // expected 49 } 50 } 51 52 /* 53 * This test verifies that PackageManger.DeleteApplicationCacheFiles enforces permission 54 * android.permission.DELETE_CACHE_FILES 55 */ 56 @SmallTest 57 public void testDeleteApplicationCacheFiles() { 58 try { 59 mPm.deleteApplicationCacheFiles(mPkgName, null); 60 fail("PackageManager.deleteApplicationCacheFiles" + 61 "did not throw SecurityException as expected"); 62 } catch (SecurityException e) { 63 // expected 64 } 65 } 66 67 /* 68 * This test verifies that PackageManger.installPackage enforces permission 69 * android.permission.INSTALL_PACKAGES 70 */ 71 private class TestInstallObserver extends PackageInstallObserver { 72 } 73 74 /* 75 * This test verifies that PackageManger.freeStorage 76 * enforces permission android.permission.CLEAR_APP_CACHE 77 */ 78 @SmallTest 79 public void testFreeStorage1() { 80 try { 81 mPm.freeStorage(100000, null); 82 fail("PackageManager.freeStorage " + 83 "did not throw SecurityException as expected"); 84 } catch (SecurityException e) { 85 // expected 86 } 87 } 88 89 /* 90 * This test verifies that PackageManger.freeStorageAndNotify 91 * enforces permission android.permission.CLEAR_APP_CACHE 92 */ 93 @SmallTest 94 public void testFreeStorage2() { 95 try { 96 mPm.freeStorageAndNotify(100000, null); 97 fail("PackageManager.freeStorageAndNotify" + 98 " did not throw SecurityException as expected"); 99 } catch (SecurityException e) { 100 // expected 101 } 102 } 103 104 /* 105 * This test verifies that PackageManger.clearApplicationUserData 106 * enforces permission android.permission.CLEAR_APP_USER_DATA 107 */ 108 @SmallTest 109 public void testClearApplicationUserData() { 110 try { 111 mPm.clearApplicationUserData(mPkgName, null); 112 fail("PackageManager.clearApplicationUserData" + 113 "did not throw SecurityException as expected"); 114 } catch (SecurityException e) { 115 // expected 116 } 117 } 118 119 /* 120 * This test verifies that PackageManger.deletePackage 121 * enforces permission android.permission.DELETE_PACKAGES 122 */ 123 @SmallTest 124 public void testDeletePackage() { 125 try { 126 mPm.deletePackage(mPkgName, null, 0); 127 fail("PackageManager.deletePackage" + 128 "did not throw SecurityException as expected"); 129 } catch (SecurityException e) { 130 // expected 131 } 132 } 133 }