1 /* 2 * Copyright (C) 2021 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.systemui.usb 17 18 import android.app.PendingIntent 19 import android.content.Intent 20 import android.hardware.usb.IUsbSerialReader 21 import android.hardware.usb.UsbAccessory 22 import android.hardware.usb.UsbManager 23 import android.testing.AndroidTestingRunner 24 import android.testing.TestableLooper 25 import android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS 26 import androidx.test.filters.SmallTest 27 import androidx.test.rule.ActivityTestRule 28 import com.android.systemui.SysuiTestCase 29 import com.android.systemui.activity.SingleActivityFactory 30 import com.google.common.truth.Truth.assertThat 31 32 import javax.inject.Inject 33 34 import org.junit.After 35 import org.junit.Before 36 import org.junit.Rule 37 import org.junit.Test 38 import org.junit.runner.RunWith 39 40 /** 41 * UsbPermissionActivityTest 42 */ 43 @RunWith(AndroidTestingRunner::class) 44 @SmallTest 45 @TestableLooper.RunWithLooper 46 class UsbPermissionActivityTest : SysuiTestCase() { 47 48 private var mMessage: UsbAudioWarningDialogMessage = UsbAudioWarningDialogMessage() 49 50 open class UsbPermissionActivityTestable @Inject constructor ( 51 val message: UsbAudioWarningDialogMessage 52 ) : UsbPermissionActivity(UsbAudioWarningDialogMessage()) 53 54 @Rule 55 @JvmField 56 var activityRule = ActivityTestRule( <lambda>null57 /* activityFactory= */ SingleActivityFactory { 58 UsbPermissionActivityTestable(mMessage) 59 }, 60 /* initialTouchMode= */ false, 61 /* launchActivity= */ false, 62 ) 63 64 private val activityIntent = Intent(mContext, UsbPermissionActivityTestable::class.java) <lambda>null65 .apply { 66 flags = Intent.FLAG_ACTIVITY_NEW_TASK 67 putExtra(UsbManager.EXTRA_PACKAGE, "com.android.systemui") 68 putExtra(Intent.EXTRA_INTENT, PendingIntent.getBroadcast( 69 mContext, 70 334, 71 Intent("NO_ACTION").apply { 72 setPackage("com.android.systemui.tests") 73 }, 74 PendingIntent.FLAG_MUTABLE)) 75 putExtra(UsbManager.EXTRA_ACCESSORY, UsbAccessory( 76 "manufacturer", 77 "model", 78 "description", 79 "version", 80 "uri", 81 object : IUsbSerialReader.Stub() { 82 override fun getSerial(packageName: String): String { 83 return "serial" 84 } 85 })) 86 } 87 88 @Before setUpnull89 fun setUp() { 90 UsbPermissionActivityTestable(mMessage) 91 activityRule.launchActivity(activityIntent) 92 } 93 94 @After tearDownnull95 fun tearDown() { 96 activityRule.finishActivity() 97 } 98 99 @Test 100 @Throws(Exception::class) testHideNonSystemOverlaynull101 fun testHideNonSystemOverlay() { 102 assertThat(activityRule.activity.window.attributes.privateFlags and 103 SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) 104 .isEqualTo(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) 105 } 106 } 107