blob: 6cca4565d284b36835d2d9b79089b5d1a9bf3644 [file] [log] [blame]
Michael Wrightd02c5b62014-02-10 15:10:22 -08001/*
2 * Copyright (C) 2011 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#ifndef _UI_INPUT_APPLICATION_H
18#define _UI_INPUT_APPLICATION_H
19
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010020#include <string>
21
Chris Ye6c4243b2020-07-22 12:07:12 -070022#include <android/InputApplicationInfo.h>
23
Robert Carr740167f2018-10-11 19:03:41 -070024#include <binder/IBinder.h>
25#include <binder/Parcel.h>
Chris Ye0783e992020-06-02 21:34:49 -070026#include <binder/Parcelable.h>
Robert Carr740167f2018-10-11 19:03:41 -070027
Michael Wrightd02c5b62014-02-10 15:10:22 -080028#include <input/Input.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080029#include <utils/RefBase.h>
30#include <utils/Timers.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080031
32namespace android {
Michael Wrightd02c5b62014-02-10 15:10:22 -080033/*
34 * Handle for an application that can receive input.
35 *
36 * Used by the native input dispatcher as a handle for the window manager objects
37 * that describe an application.
38 */
Chris Yea209fde2020-07-22 13:54:51 -070039class InputApplicationHandle {
Michael Wrightd02c5b62014-02-10 15:10:22 -080040public:
41 inline const InputApplicationInfo* getInfo() const {
Arthur Hung7a0c39a2019-03-20 16:52:24 +080042 return &mInfo;
Michael Wrightd02c5b62014-02-10 15:10:22 -080043 }
44
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -080045 inline std::string getName() const {
Arthur Hung7a0c39a2019-03-20 16:52:24 +080046 return !mInfo.name.empty() ? mInfo.name : "<invalid>";
Michael Wrightd02c5b62014-02-10 15:10:22 -080047 }
48
Siarhei Vishniakou4cb50ca2020-05-26 21:43:02 -070049 inline std::chrono::nanoseconds getDispatchingTimeout(
50 std::chrono::nanoseconds defaultValue) const {
Chris Ye6c4243b2020-07-22 12:07:12 -070051 return mInfo.token ? std::chrono::nanoseconds(mInfo.dispatchingTimeoutNanos) : defaultValue;
Siarhei Vishniakou4cb50ca2020-05-26 21:43:02 -070052 }
53
Robert Carr740167f2018-10-11 19:03:41 -070054 inline sp<IBinder> getApplicationToken() const {
Arthur Hung7a0c39a2019-03-20 16:52:24 +080055 return mInfo.token;
Robert Carr740167f2018-10-11 19:03:41 -070056 }
57
Chris Yea209fde2020-07-22 13:54:51 -070058 bool operator==(const InputApplicationHandle& other) const {
59 return getName() == other.getName() && getApplicationToken() == other.getApplicationToken();
60 }
61
62 bool operator!=(const InputApplicationHandle& other) const { return !(*this == other); }
63
Michael Wrightd02c5b62014-02-10 15:10:22 -080064 /**
65 * Requests that the state of this object be updated to reflect
66 * the most current available information about the application.
67 *
68 * This method should only be called from within the input dispatcher's
69 * critical section.
70 *
71 * Returns true on success, or false if the handle is no longer valid.
72 */
73 virtual bool updateInfo() = 0;
Chris Ye0783e992020-06-02 21:34:49 -070074
Michael Wrightd02c5b62014-02-10 15:10:22 -080075protected:
Chris Ye6c4243b2020-07-22 12:07:12 -070076 InputApplicationHandle() = default;
77 virtual ~InputApplicationHandle() = default;
Michael Wrightd02c5b62014-02-10 15:10:22 -080078
Arthur Hung7a0c39a2019-03-20 16:52:24 +080079 InputApplicationInfo mInfo;
Michael Wrightd02c5b62014-02-10 15:10:22 -080080};
81
82} // namespace android
83
84#endif // _UI_INPUT_APPLICATION_H