Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2018 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 static android.content.Context.DEVICE_POLICY_SERVICE;
     20 import static android.content.Context.FINGERPRINT_SERVICE;
     21 import static android.content.Context.SHORTCUT_SERVICE;
     22 import static android.content.Context.USB_SERVICE;
     23 import static android.content.Context.WALLPAPER_SERVICE;
     24 import static android.content.Context.WIFI_AWARE_SERVICE;
     25 import static android.content.Context.WIFI_P2P_SERVICE;
     26 import static android.content.Context.WIFI_SERVICE;
     27 
     28 import static org.junit.Assert.assertNull;
     29 
     30 import android.content.Context;
     31 import android.platform.test.annotations.AppModeInstant;
     32 import android.support.test.InstrumentationRegistry;
     33 import android.support.test.runner.AndroidJUnit4;
     34 
     35 import org.junit.Test;
     36 import org.junit.runner.RunWith;
     37 
     38 /**
     39  * Some services are not available to instant apps, see {@link Context#getSystemService}.
     40  */
     41 @AppModeInstant
     42 @RunWith(AndroidJUnit4.class)
     43 public class ServicesInstantAppsCannotAccessTests {
     44     @Test
     45     public void cannotGetDevicePolicyManager() {
     46     assertNull(InstrumentationRegistry.getTargetContext().getSystemService(
     47             DEVICE_POLICY_SERVICE));
     48     }
     49 
     50     @Test
     51     public void cannotGetFingerprintManager() {
     52         assertNull(InstrumentationRegistry.getTargetContext().getSystemService(
     53                 FINGERPRINT_SERVICE));
     54     }
     55 
     56     @Test
     57     public void cannotGetShortcutManager() {
     58         assertNull(InstrumentationRegistry.getTargetContext().getSystemService(
     59                 SHORTCUT_SERVICE));
     60     }
     61 
     62     @Test
     63     public void cannotGetUsbManager() {
     64         assertNull(InstrumentationRegistry.getTargetContext().getSystemService(
     65                 USB_SERVICE));
     66     }
     67 
     68     @Test
     69     public void cannotGetWallpaperManager() {
     70         assertNull(InstrumentationRegistry.getTargetContext().getSystemService(
     71                 WALLPAPER_SERVICE));
     72     }
     73 
     74     @Test
     75     public void cannotGetWifiP2pManager() {
     76         assertNull(InstrumentationRegistry.getTargetContext().getSystemService(
     77                 WIFI_P2P_SERVICE));
     78     }
     79 
     80     @Test
     81     public void cannotGetWifiManager() {
     82         assertNull(InstrumentationRegistry.getTargetContext().getSystemService(
     83                 WIFI_SERVICE));
     84     }
     85 
     86     @Test
     87     public void cannotGetWifiAwareManager() {
     88         assertNull(InstrumentationRegistry.getTargetContext().getSystemService(
     89                 WIFI_AWARE_SERVICE));
     90     }
     91 }
     92