1 /* 2 * Copyright (C) 2015 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 package com.android.preconditions.cts; 17 18 import android.content.Context; 19 import android.content.pm.PackageManager; 20 import android.test.AndroidTestCase; 21 import android.util.Log; 22 23 import com.android.compatibility.common.preconditions.ExternalStorageHelper; 24 import com.android.compatibility.common.preconditions.ScreenLockHelper; 25 26 /** 27 * A test to verify that device-side preconditions are met for CTS 28 */ 29 public class PreconditionsTest extends AndroidTestCase { 30 31 private static final String TAG = "PreconditionsTest"; 32 33 /** 34 * Test if device has no screen lock 35 * @throws Exception 36 */ 37 public void testScreenUnlocked() throws Exception { 38 PackageManager pm = this.getContext().getPackageManager(); 39 if (pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK) 40 || pm.hasSystemFeature(PackageManager.FEATURE_WATCH) 41 || pm.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)) { 42 Log.i(TAG, "Skipping screen lock precondition for this device type"); 43 return; // do not test for unlocked screen on devices with no screen lock 44 } 45 assertFalse("Device must have screen lock disabled", 46 ScreenLockHelper.isDeviceSecure(this.getContext())); 47 } 48 49 /** 50 * Test if device has accessible external storage 51 * @throws Exception 52 */ 53 public void testExternalStoragePresent() throws Exception { 54 assertTrue("Device must have external storage mounted in order to run CTS", 55 ExternalStorageHelper.isExternalStorageReadable()); 56 assertTrue("Device external storage must be writable in order to run CTS", 57 ExternalStorageHelper.isExternalStorageWritable()); 58 } 59 60 } 61