xref: /aosp_15_r20/frameworks/base/tests/Input/src/com/android/test/input/UnresponsiveGestureMonitorActivity.kt (revision d57664e9bc4670b3ecf6748a746a57c557b6bc9e)
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 // InputMonitor is deprecated, but we still need to test it.
18 @file:Suppress("DEPRECATION")
19 
20 package com.android.test.input
21 
22 import android.app.Activity
23 import android.hardware.input.InputManager
24 import android.os.Bundle
25 import android.os.Looper
26 import android.util.Log
27 import android.view.InputChannel
28 import android.view.InputEvent
29 import android.view.InputEventReceiver
30 import android.view.InputMonitor
31 
32 class UnresponsiveReceiver(channel: InputChannel, looper: Looper) :
33         InputEventReceiver(channel, looper) {
34     companion object {
35         const val TAG = "UnresponsiveReceiver"
36     }
onInputEventnull37     override fun onInputEvent(event: InputEvent) {
38         Log.i(TAG, "Received $event")
39         // Not calling 'finishInputEvent' in order to trigger the ANR
40     }
41 }
42 
43 class UnresponsiveGestureMonitorActivity : Activity() {
44     companion object {
45         const val MONITOR_NAME = "unresponsive gesture monitor"
46     }
47     private lateinit var mInputEventReceiver: InputEventReceiver
48     private lateinit var mInputMonitor: InputMonitor
49 
onCreatenull50     override fun onCreate(savedInstanceState: Bundle?) {
51         super.onCreate(savedInstanceState)
52         val inputManager = checkNotNull(getSystemService(InputManager::class.java))
53         mInputMonitor = inputManager.monitorGestureInput(MONITOR_NAME, displayId)
54         mInputEventReceiver = UnresponsiveReceiver(
55                 mInputMonitor.getInputChannel(), Looper.myLooper()!!)
56     }
57 }
58