• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.usepermission;
18 
19 import static junit.framework.Assert.assertEquals;
20 
21 import android.Manifest;
22 import android.content.pm.PackageManager;
23 
24 import org.junit.Test;
25 
26 /**
27  * Runtime permission behavior tests for apps targeting API 26
28  */
29 public class UsePermissionTest26 extends BasePermissionsTest {
30     private static final int REQUEST_CODE_PERMISSIONS = 42;
31 
32     @Test
testRuntimeGroupGrantNoExpansion()33     public void testRuntimeGroupGrantNoExpansion() throws Exception {
34         // Start out without permission
35         assertEquals(PackageManager.PERMISSION_DENIED, getInstrumentation().getContext()
36                 .checkSelfPermission(Manifest.permission.RECEIVE_SMS));
37         assertEquals(PackageManager.PERMISSION_DENIED, getInstrumentation().getContext()
38                 .checkSelfPermission(Manifest.permission.SEND_SMS));
39 
40         String[] permissions = new String[]{Manifest.permission.RECEIVE_SMS};
41 
42         // request only one permission from the 'SMS' permission group at runtime,
43         // but two from this group are <uses-permission> in the manifest
44         // request only one permission from the 'contacts' permission group
45         BasePermissionActivity.Result result = requestPermissions(permissions,
46                 REQUEST_CODE_PERMISSIONS,
47                 BasePermissionActivity.class,
48                 () -> {
49                     try {
50                         clickAllowButton();
51                         getUiDevice().waitForIdle();
52                     } catch (Exception e) {
53                         throw new RuntimeException(e);
54                     }
55                 });
56 
57         // Expect the permission is granted
58         assertPermissionRequestResult(result, REQUEST_CODE_PERMISSIONS,
59                 permissions, new boolean[]{true});
60 
61         assertEquals(PackageManager.PERMISSION_DENIED, getInstrumentation().getTargetContext()
62                 .checkSelfPermission(Manifest.permission.SEND_SMS));
63     }
64 }
65