1 /* 2 * Copyright (C) 2016 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.cts.escalatepermission; 18 19 import android.content.Context; 20 import android.content.pm.PermissionInfo; 21 import android.support.test.InstrumentationRegistry; 22 import android.support.test.runner.AndroidJUnit4; 23 import org.junit.Test; 24 import org.junit.runner.RunWith; 25 26 import static org.junit.Assert.assertSame; 27 28 import com.android.cts.escalate.permission.Manifest; 29 30 @RunWith(AndroidJUnit4.class) 31 public class PermissionEscalationTest { 32 @Test testCannotEscalateNonRuntimePermissionsToRuntime()33 public void testCannotEscalateNonRuntimePermissionsToRuntime() throws Exception { 34 Context context = InstrumentationRegistry.getTargetContext(); 35 36 // Ensure normal permission cannot be made dangerous 37 PermissionInfo stealAudio1Permission1 = context.getPackageManager() 38 .getPermissionInfo(Manifest.permission.STEAL_AUDIO1, 0); 39 assertSame("Shouldn't be able to change normal permission to dangerous", 40 PermissionInfo.PROTECTION_NORMAL, (stealAudio1Permission1.protectionLevel 41 & PermissionInfo.PROTECTION_MASK_BASE)); 42 43 // Ensure signature permission cannot be made dangerous 44 PermissionInfo stealAudio1Permission2 = context.getPackageManager() 45 .getPermissionInfo(Manifest.permission.STEAL_AUDIO2, 0); 46 assertSame("Shouldn't be able to change signature permission to dangerous", 47 PermissionInfo.PROTECTION_SIGNATURE, (stealAudio1Permission2.protectionLevel 48 & PermissionInfo.PROTECTION_MASK_BASE)); 49 } 50 } 51