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