xref: /aosp_15_r20/frameworks/native/include/gui/InputApplication.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright (C) 2011 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #ifndef _UI_INPUT_APPLICATION_H
18*38e8c45fSAndroid Build Coastguard Worker #define _UI_INPUT_APPLICATION_H
19*38e8c45fSAndroid Build Coastguard Worker 
20*38e8c45fSAndroid Build Coastguard Worker #include <string>
21*38e8c45fSAndroid Build Coastguard Worker 
22*38e8c45fSAndroid Build Coastguard Worker #include <android/gui/InputApplicationInfo.h>
23*38e8c45fSAndroid Build Coastguard Worker 
24*38e8c45fSAndroid Build Coastguard Worker #include <binder/IBinder.h>
25*38e8c45fSAndroid Build Coastguard Worker #include <binder/Parcel.h>
26*38e8c45fSAndroid Build Coastguard Worker #include <binder/Parcelable.h>
27*38e8c45fSAndroid Build Coastguard Worker 
28*38e8c45fSAndroid Build Coastguard Worker #include <utils/RefBase.h>
29*38e8c45fSAndroid Build Coastguard Worker #include <utils/Timers.h>
30*38e8c45fSAndroid Build Coastguard Worker 
31*38e8c45fSAndroid Build Coastguard Worker namespace android {
32*38e8c45fSAndroid Build Coastguard Worker 
33*38e8c45fSAndroid Build Coastguard Worker /*
34*38e8c45fSAndroid Build Coastguard Worker  * Handle for an application that can receive input.
35*38e8c45fSAndroid Build Coastguard Worker  *
36*38e8c45fSAndroid Build Coastguard Worker  * Used by the native input dispatcher as a handle for the window manager objects
37*38e8c45fSAndroid Build Coastguard Worker  * that describe an application.
38*38e8c45fSAndroid Build Coastguard Worker  */
39*38e8c45fSAndroid Build Coastguard Worker class InputApplicationHandle {
40*38e8c45fSAndroid Build Coastguard Worker public:
getInfo()41*38e8c45fSAndroid Build Coastguard Worker     inline const gui::InputApplicationInfo* getInfo() const { return &mInfo; }
42*38e8c45fSAndroid Build Coastguard Worker 
getName()43*38e8c45fSAndroid Build Coastguard Worker     inline std::string getName() const { return !mInfo.name.empty() ? mInfo.name : "<invalid>"; }
44*38e8c45fSAndroid Build Coastguard Worker 
getDispatchingTimeout(std::chrono::nanoseconds defaultValue)45*38e8c45fSAndroid Build Coastguard Worker     inline std::chrono::nanoseconds getDispatchingTimeout(
46*38e8c45fSAndroid Build Coastguard Worker             std::chrono::nanoseconds defaultValue) const {
47*38e8c45fSAndroid Build Coastguard Worker         return mInfo.token ? std::chrono::milliseconds(mInfo.dispatchingTimeoutMillis)
48*38e8c45fSAndroid Build Coastguard Worker                            : defaultValue;
49*38e8c45fSAndroid Build Coastguard Worker     }
50*38e8c45fSAndroid Build Coastguard Worker 
getApplicationToken()51*38e8c45fSAndroid Build Coastguard Worker     inline sp<IBinder> getApplicationToken() const { return mInfo.token; }
52*38e8c45fSAndroid Build Coastguard Worker 
53*38e8c45fSAndroid Build Coastguard Worker     bool operator==(const InputApplicationHandle& other) const {
54*38e8c45fSAndroid Build Coastguard Worker         return getName() == other.getName() && getApplicationToken() == other.getApplicationToken();
55*38e8c45fSAndroid Build Coastguard Worker     }
56*38e8c45fSAndroid Build Coastguard Worker 
57*38e8c45fSAndroid Build Coastguard Worker     bool operator!=(const InputApplicationHandle& other) const { return !(*this == other); }
58*38e8c45fSAndroid Build Coastguard Worker 
59*38e8c45fSAndroid Build Coastguard Worker     /**
60*38e8c45fSAndroid Build Coastguard Worker      * Requests that the state of this object be updated to reflect
61*38e8c45fSAndroid Build Coastguard Worker      * the most current available information about the application.
62*38e8c45fSAndroid Build Coastguard Worker      *
63*38e8c45fSAndroid Build Coastguard Worker      * This method should only be called from within the input dispatcher's
64*38e8c45fSAndroid Build Coastguard Worker      * critical section.
65*38e8c45fSAndroid Build Coastguard Worker      *
66*38e8c45fSAndroid Build Coastguard Worker      * Returns true on success, or false if the handle is no longer valid.
67*38e8c45fSAndroid Build Coastguard Worker      */
68*38e8c45fSAndroid Build Coastguard Worker     virtual bool updateInfo() = 0;
69*38e8c45fSAndroid Build Coastguard Worker 
70*38e8c45fSAndroid Build Coastguard Worker protected:
71*38e8c45fSAndroid Build Coastguard Worker     InputApplicationHandle() = default;
72*38e8c45fSAndroid Build Coastguard Worker     virtual ~InputApplicationHandle() = default;
73*38e8c45fSAndroid Build Coastguard Worker 
74*38e8c45fSAndroid Build Coastguard Worker     gui::InputApplicationInfo mInfo;
75*38e8c45fSAndroid Build Coastguard Worker };
76*38e8c45fSAndroid Build Coastguard Worker 
77*38e8c45fSAndroid Build Coastguard Worker } // namespace android
78*38e8c45fSAndroid Build Coastguard Worker 
79*38e8c45fSAndroid Build Coastguard Worker #endif // _UI_INPUT_APPLICATION_H
80