• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.server.usbtest;
18 
19 import android.content.Context;
20 import android.hardware.usb.UsbManager;
21 
22 import androidx.test.InstrumentationRegistry;
23 import androidx.test.filters.SmallTest;
24 import androidx.test.runner.AndroidJUnit4;
25 
26 import org.junit.Ignore;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 
30 import com.android.server.usblib.UsbManagerTestLib;
31 
32 /**
33  * Unit tests for {@link android.hardware.usb.UsbManager}.
34  * Note: MUST claimed MANAGE_USB permission in Manifest
35  */
36 @SmallTest
37 @RunWith(AndroidJUnit4.class)
38 public class UsbManagerApiTest {
39     private Context mContext;
40 
41     private final UsbManagerTestLib mUsbManagerTestLib =
42             new UsbManagerTestLib(mContext = InstrumentationRegistry.getContext());
43 
44     /**
45      * Verify NO SecurityException
46      * Go through System Server
47      */
48     @Test
testUsbApi_GetCurrentFunctionsSys_shouldNoSecurityException()49     public void testUsbApi_GetCurrentFunctionsSys_shouldNoSecurityException() throws Exception {
50         mUsbManagerTestLib.testGetCurrentFunctionsSysEx();
51     }
52 
53     /**
54      * Verify NO SecurityException
55      * Go through System Server
56      */
57     @Test
testUsbApi_SetCurrentFunctionsSys_shouldNoSecurityException()58     public void testUsbApi_SetCurrentFunctionsSys_shouldNoSecurityException() throws Exception {
59         mUsbManagerTestLib.testSetCurrentFunctionsSysEx(UsbManager.FUNCTION_NONE);
60     }
61 
62     /**
63      * Verify NO SecurityException
64      * Go through Direct API, will not be denied by @RequiresPermission annotation
65      */
66     @Test
testUsbApi_GetCurrentFunctions_shouldNoSecurityException()67     public void testUsbApi_GetCurrentFunctions_shouldNoSecurityException() throws Exception {
68         mUsbManagerTestLib.testGetCurrentFunctionsEx();
69     }
70 
71     /**
72      * Verify NO SecurityException
73      * Go through Direct API, will not be denied by @RequiresPermission annotation
74      */
75     @Test
testUsbApi_SetCurrentFunctions_shouldNoSecurityException()76     public void testUsbApi_SetCurrentFunctions_shouldNoSecurityException() throws Exception {
77         mUsbManagerTestLib.testSetCurrentFunctionsEx(UsbManager.FUNCTION_NONE);
78     }
79 
80     /**
81      * Verify API path from UsbManager to UsbService
82      */
83     @Test
testUsbApi_GetCurrentFunctions_shouldMatched()84     public void testUsbApi_GetCurrentFunctions_shouldMatched() {
85         mUsbManagerTestLib.testGetCurrentFunctions_shouldMatched();
86     }
87 
88     /**
89      * Verify API path from UsbManager to UsbService
90      */
91     @Test
testUsbApi_SetCurrentFunctions_shouldMatched()92     public void testUsbApi_SetCurrentFunctions_shouldMatched() {
93         mUsbManagerTestLib.testSetCurrentFunctions_shouldMatched();
94     }
95 }
96