blob: ccffeb1327383af19a4d7e09370ee227d68e5eac [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
Robert Carr740167f2018-10-11 19:03:41 -070022#include <binder/IBinder.h>
23#include <binder/Parcel.h>
24
Michael Wrightd02c5b62014-02-10 15:10:22 -080025#include <input/Input.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080026#include <utils/RefBase.h>
27#include <utils/Timers.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080028
29namespace android {
30
31/*
32 * Describes the properties of an application that can receive input.
33 */
34struct InputApplicationInfo {
Robert Carr740167f2018-10-11 19:03:41 -070035 sp<IBinder> token;
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -080036 std::string name;
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -050037 std::chrono::nanoseconds dispatchingTimeout;
Robert Carr740167f2018-10-11 19:03:41 -070038
39 status_t write(Parcel& output) const;
40 static InputApplicationInfo read(const Parcel& from);
Michael Wrightd02c5b62014-02-10 15:10:22 -080041};
42
43
44/*
45 * Handle for an application that can receive input.
46 *
47 * Used by the native input dispatcher as a handle for the window manager objects
48 * that describe an application.
49 */
50class InputApplicationHandle : public RefBase {
51public:
52 inline const InputApplicationInfo* getInfo() const {
Arthur Hung7a0c39a2019-03-20 16:52:24 +080053 return &mInfo;
Michael Wrightd02c5b62014-02-10 15:10:22 -080054 }
55
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -080056 inline std::string getName() const {
Arthur Hung7a0c39a2019-03-20 16:52:24 +080057 return !mInfo.name.empty() ? mInfo.name : "<invalid>";
Michael Wrightd02c5b62014-02-10 15:10:22 -080058 }
59
Siarhei Vishniakou4cb50ca2020-05-26 21:43:02 -070060 inline std::chrono::nanoseconds getDispatchingTimeout(
61 std::chrono::nanoseconds defaultValue) const {
62 return mInfo.token ? std::chrono::nanoseconds(mInfo.dispatchingTimeout) : defaultValue;
63 }
64
Robert Carr740167f2018-10-11 19:03:41 -070065 inline sp<IBinder> getApplicationToken() const {
Arthur Hung7a0c39a2019-03-20 16:52:24 +080066 return mInfo.token;
Robert Carr740167f2018-10-11 19:03:41 -070067 }
68
Michael Wrightd02c5b62014-02-10 15:10:22 -080069 /**
70 * Requests that the state of this object be updated to reflect
71 * the most current available information about the application.
72 *
73 * This method should only be called from within the input dispatcher's
74 * critical section.
75 *
76 * Returns true on success, or false if the handle is no longer valid.
77 */
78 virtual bool updateInfo() = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -080079protected:
80 InputApplicationHandle();
81 virtual ~InputApplicationHandle();
82
Arthur Hung7a0c39a2019-03-20 16:52:24 +080083 InputApplicationInfo mInfo;
Michael Wrightd02c5b62014-02-10 15:10:22 -080084};
85
86} // namespace android
87
88#endif // _UI_INPUT_APPLICATION_H