| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.server.usb; |
| 18 |
|
| 19 |
import static org.junit.Assert.assertEquals; |
| 20 |
|
| 21 |
import android.content.Context; |
| 22 |
import android.hardware.usb.UsbManager; |
| 23 |
|
| 24 |
import androidx.test.InstrumentationRegistry; |
| 25 |
import androidx.test.filters.SmallTest; |
| 26 |
import androidx.test.runner.AndroidJUnit4; |
| 27 |
|
| 28 |
import com.android.server.usblib.UsbManagerTestLib; |
| 29 |
|
| 30 |
import org.junit.Ignore; |
| 31 |
import org.junit.Test; |
| 32 |
import org.junit.runner.RunWith; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
@SmallTest |
| 39 |
@RunWith(AndroidJUnit4.class) |
| 40 |
public class UsbManagerNoPermTest { |
| 41 |
private Context mContext; |
| 42 |
|
| 43 |
private final UsbManagerTestLib mUsbManagerTestLib = |
| 44 |
new UsbManagerTestLib(mContext = InstrumentationRegistry.getContext()); |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
@Test(expected = SecurityException.class) |
| 51 |
public void testUsbApi_GetCurrentFunctionsSys_OnSecurityException() throws Exception { |
| 52 |
mUsbManagerTestLib.testGetCurrentFunctionsSysEx(); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
@Test(expected = SecurityException.class) |
| 60 |
public void testUsbApi_SetCurrentFunctionsSys_OnSecurityException() throws Exception { |
| 61 |
mUsbManagerTestLib.testSetCurrentFunctionsSysEx(UsbManager.FUNCTION_NONE); |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
@Test(expected = SecurityException.class) |
| 69 |
@Ignore |
| 70 |
public void testUsbApi_GetCurrentFunctions_OnSecurityException() throws Exception { |
| 71 |
mUsbManagerTestLib.testGetCurrentFunctionsEx(); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
@Test(expected = SecurityException.class) |
| 79 |
@Ignore |
| 80 |
public void testUsbApi_SetCurrentFunctions_OnSecurityException() throws Exception { |
| 81 |
mUsbManagerTestLib.testSetCurrentFunctionsEx(UsbManager.FUNCTION_NONE); |
| 82 |
} |
| 83 |
|
| 84 |
public void assertSettableFunctions(boolean settable, long functions) { |
| 85 |
assertEquals( |
| 86 |
"areSettableFunctions(" + UsbManager.usbFunctionsToString(functions) + "):", |
| 87 |
settable, UsbManager.areSettableFunctions(functions)); |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
@Test |
| 95 |
public void testUsbManager_AreSettableFunctions() { |
| 96 |
|
| 97 |
assertSettableFunctions(true, UsbManager.FUNCTION_NONE); |
| 98 |
|
| 99 |
|
| 100 |
assertSettableFunctions(true, UsbManager.FUNCTION_MTP); |
| 101 |
assertSettableFunctions(true, UsbManager.FUNCTION_PTP); |
| 102 |
assertSettableFunctions(true, UsbManager.FUNCTION_RNDIS); |
| 103 |
assertSettableFunctions(true, UsbManager.FUNCTION_MIDI); |
| 104 |
assertSettableFunctions(true, UsbManager.FUNCTION_NCM); |
| 105 |
|
| 106 |
|
| 107 |
assertSettableFunctions(false, UsbManager.FUNCTION_MTP | UsbManager.FUNCTION_PTP); |
| 108 |
assertSettableFunctions(false, UsbManager.FUNCTION_PTP | UsbManager.FUNCTION_RNDIS); |
| 109 |
assertSettableFunctions(false, UsbManager.FUNCTION_MIDI | UsbManager.FUNCTION_NCM); |
| 110 |
|
| 111 |
|
| 112 |
assertSettableFunctions(true, UsbManager.FUNCTION_RNDIS | UsbManager.FUNCTION_NCM); |
| 113 |
} |
| 114 |
} |