1 /* 2 * Copyright (C) 2020 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.dynamicmime.cts; 18 19 import static org.junit.Assume.assumeTrue; 20 21 import com.android.compatibility.common.util.ApiTest; 22 import com.android.compatibility.common.util.PropertyUtil; 23 import com.android.tradefed.device.DeviceNotAvailableException; 24 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; 25 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; 26 27 import org.junit.Before; 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 31 /** 32 * Preferred Activities test cases 33 * 34 * Verifies that preferred activity is removed after any change to any MIME group 35 * declared by preferred activity package 36 */ 37 @ApiTest(apis = { 38 "android.content.pm.PackageManager#getMimeGroup", 39 "android.content.pm.PackageManager#setMimeGroup" 40 }) 41 @RunWith(DeviceJUnit4ClassRunner.class) 42 public class PreferredActivitiesTestCases extends BaseHostJUnit4Test { 43 private static final String PACKAGE_TEST_APP = "android.dynamicmime.testapp"; 44 isShippedAtLeastS()45 private boolean isShippedAtLeastS() { 46 try { 47 return PropertyUtil.getFirstApiLevel(getDevice()) > 30 /* BUILD.VERSION_CODES.R */; 48 } catch (Exception e) { 49 return false; 50 } 51 } 52 53 @Before setUp()54 public void setUp() throws DeviceNotAvailableException { 55 assumeTrue("The device shipped at least OS S", isShippedAtLeastS()); 56 // wake up and unlock device 57 getDevice().executeShellCommand("input keyevent KEYCODE_WAKEUP"); 58 getDevice().disableKeyguard(); 59 } 60 61 @Test testRemoveFromGroup()62 public void testRemoveFromGroup() throws DeviceNotAvailableException { 63 runDeviceTest("testRemoveFromGroup"); 64 } 65 66 @Test testAddToGroup()67 public void testAddToGroup() throws DeviceNotAvailableException { 68 runDeviceTest("testAddToGroup"); 69 } 70 71 @Test testClearGroup()72 public void testClearGroup() throws DeviceNotAvailableException { 73 runDeviceTest("testClearGroup"); 74 } 75 76 @Test testModifyGroupWithoutActualGroupChanges()77 public void testModifyGroupWithoutActualGroupChanges() throws DeviceNotAvailableException { 78 runDeviceTest("testModifyGroupWithoutActualGroupChanges"); 79 } 80 81 @Test testModifyGroupWithoutActualIntentFilterChanges()82 public void testModifyGroupWithoutActualIntentFilterChanges() 83 throws DeviceNotAvailableException { 84 runDeviceTest("testModifyGroupWithoutActualIntentFilterChanges"); 85 } 86 runDeviceTest(String testMethodName)87 private void runDeviceTest(String testMethodName) throws DeviceNotAvailableException { 88 runDeviceTests(PACKAGE_TEST_APP, PACKAGE_TEST_APP + ".preferred.PreferredActivitiesTest", 89 testMethodName); 90 } 91 } 92