Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1 | /* |
| 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 Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 20 | #include <string> |
| 21 | |
Chris Ye | 6c4243b | 2020-07-22 12:07:12 -0700 | [diff] [blame] | 22 | #include <android/InputApplicationInfo.h> |
| 23 | |
Robert Carr | 740167f | 2018-10-11 19:03:41 -0700 | [diff] [blame] | 24 | #include <binder/IBinder.h> |
| 25 | #include <binder/Parcel.h> |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 26 | #include <binder/Parcelable.h> |
Robert Carr | 740167f | 2018-10-11 19:03:41 -0700 | [diff] [blame] | 27 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 28 | #include <input/Input.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 29 | #include <utils/RefBase.h> |
| 30 | #include <utils/Timers.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 31 | |
| 32 | namespace android { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 33 | /* |
| 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 Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 39 | class InputApplicationHandle { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 40 | public: |
| 41 | inline const InputApplicationInfo* getInfo() const { |
Arthur Hung | 7a0c39a | 2019-03-20 16:52:24 +0800 | [diff] [blame] | 42 | return &mInfo; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 43 | } |
| 44 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 45 | inline std::string getName() const { |
Arthur Hung | 7a0c39a | 2019-03-20 16:52:24 +0800 | [diff] [blame] | 46 | return !mInfo.name.empty() ? mInfo.name : "<invalid>"; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 47 | } |
| 48 | |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 49 | inline std::chrono::nanoseconds getDispatchingTimeout( |
| 50 | std::chrono::nanoseconds defaultValue) const { |
Siarhei Vishniakou | 7062295 | 2020-07-30 11:17:23 -0500 | [diff] [blame] | 51 | return mInfo.token ? std::chrono::milliseconds(mInfo.dispatchingTimeoutMillis) |
| 52 | : defaultValue; |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Robert Carr | 740167f | 2018-10-11 19:03:41 -0700 | [diff] [blame] | 55 | inline sp<IBinder> getApplicationToken() const { |
Arthur Hung | 7a0c39a | 2019-03-20 16:52:24 +0800 | [diff] [blame] | 56 | return mInfo.token; |
Robert Carr | 740167f | 2018-10-11 19:03:41 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 59 | bool operator==(const InputApplicationHandle& other) const { |
| 60 | return getName() == other.getName() && getApplicationToken() == other.getApplicationToken(); |
| 61 | } |
| 62 | |
| 63 | bool operator!=(const InputApplicationHandle& other) const { return !(*this == other); } |
| 64 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 65 | /** |
| 66 | * Requests that the state of this object be updated to reflect |
| 67 | * the most current available information about the application. |
| 68 | * |
| 69 | * This method should only be called from within the input dispatcher's |
| 70 | * critical section. |
| 71 | * |
| 72 | * Returns true on success, or false if the handle is no longer valid. |
| 73 | */ |
| 74 | virtual bool updateInfo() = 0; |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 75 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 76 | protected: |
Chris Ye | 6c4243b | 2020-07-22 12:07:12 -0700 | [diff] [blame] | 77 | InputApplicationHandle() = default; |
| 78 | virtual ~InputApplicationHandle() = default; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 79 | |
Arthur Hung | 7a0c39a | 2019-03-20 16:52:24 +0800 | [diff] [blame] | 80 | InputApplicationInfo mInfo; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | } // namespace android |
| 84 | |
| 85 | #endif // _UI_INPUT_APPLICATION_H |