Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2013 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 android.permission.cts;
     18 
     19 import android.content.pm.PackageManager;
     20 import android.os.Process;
     21 import android.test.AndroidTestCase;
     22 import android.test.suitebuilder.annotation.SmallTest;
     23 
     24 /**
     25  * Verify permission behaviors with android:maxSdkVersion
     26  */
     27 public class PermissionMaxSdkVersionTest extends AndroidTestCase {
     28     // These two permission names must match the corresponding <uses-permission>
     29     // declarations in the test app manifest.
     30     static final String UNGRANTABLE_PERMISSION = "android.permission.INTERNET";
     31     static final String GRANTABLE_PERMISSION = "android.permission.ACCESS_NETWORK_STATE";
     32 
     33     /**
     34      * Verify that with android:maxSdkVersion set to a previous API level,
     35      * the permission is not being granted.
     36      */
     37     @SmallTest
     38     public void testMaxSdkInPast() {
     39         int result = mContext.checkPermission(UNGRANTABLE_PERMISSION,
     40                 Process.myPid(), Process.myUid());
     41         assertEquals("Permissions with maxSdkVersion in the past should not be granted",
     42                 result,
     43                 PackageManager.PERMISSION_DENIED);
     44     }
     45 
     46     /**
     47      * Verify that with android:maxSdkVersion set to a future API level,
     48      * the permission is being granted.
     49      */
     50     @SmallTest
     51     public void testMaxSdkInFuture() {
     52         int result = mContext.checkPermission(GRANTABLE_PERMISSION,
     53                 Process.myPid(), Process.myUid());
     54         assertEquals("Permissions with maxSdkVersion in the future should be granted",
     55                 result,
     56                 PackageManager.PERMISSION_GRANTED);
     57     }
     58 }
     59