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 package com.android.cts.deviceadmin; 17 18 import android.os.Build; 19 20 /** 21 * Tests that: 22 * - need to be run as device admin (as opposed to device owner) and 23 * - require resetting the password at the end. 24 * 25 * Note: when adding a new method, make sure to add a corresponding method in 26 * BaseDeviceAdminHostSideTest. 27 */ 28 public class DeviceAdminPasswordTest extends BaseDeviceAdminTest { 29 30 @Override setUp()31 protected void setUp() throws Exception { 32 super.setUp(); 33 34 assertNotDeviceOwner(); 35 } 36 testResetPasswordDeprecated()37 public void testResetPasswordDeprecated() { 38 if (getTargetSdkLevel() < Build.VERSION_CODES.N) { 39 assertFalse(dpm.resetPassword("1234", 0)); 40 } else { 41 try { 42 dpm.resetPassword("1234", 0); 43 fail("resetPassword() should throw SecurityException"); 44 } catch (SecurityException e) { } 45 } 46 } 47 getTargetSdkLevel()48 private int getTargetSdkLevel() { 49 return mContext.getApplicationContext().getApplicationInfo().targetSdkVersion; 50 } 51 } 52