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 | |
| 20 | #include <input/Input.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 21 | #include <utils/RefBase.h> |
| 22 | #include <utils/Timers.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | /* |
| 27 | * Describes the properties of an application that can receive input. |
| 28 | */ |
| 29 | struct InputApplicationInfo { |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 30 | std::string name; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 31 | nsecs_t dispatchingTimeout; |
| 32 | }; |
| 33 | |
| 34 | |
| 35 | /* |
| 36 | * Handle for an application that can receive input. |
| 37 | * |
| 38 | * Used by the native input dispatcher as a handle for the window manager objects |
| 39 | * that describe an application. |
| 40 | */ |
| 41 | class InputApplicationHandle : public RefBase { |
| 42 | public: |
| 43 | inline const InputApplicationInfo* getInfo() const { |
| 44 | return mInfo; |
| 45 | } |
| 46 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 47 | inline std::string getName() const { |
| 48 | return mInfo ? mInfo->name : "<invalid>"; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | inline nsecs_t getDispatchingTimeout(nsecs_t defaultValue) const { |
| 52 | return mInfo ? mInfo->dispatchingTimeout : defaultValue; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Requests that the state of this object be updated to reflect |
| 57 | * the most current available information about the application. |
| 58 | * |
| 59 | * This method should only be called from within the input dispatcher's |
| 60 | * critical section. |
| 61 | * |
| 62 | * Returns true on success, or false if the handle is no longer valid. |
| 63 | */ |
| 64 | virtual bool updateInfo() = 0; |
| 65 | |
| 66 | /** |
| 67 | * Releases the storage used by the associated information when it is |
| 68 | * no longer needed. |
| 69 | */ |
| 70 | void releaseInfo(); |
| 71 | |
| 72 | protected: |
| 73 | InputApplicationHandle(); |
| 74 | virtual ~InputApplicationHandle(); |
| 75 | |
| 76 | InputApplicationInfo* mInfo; |
| 77 | }; |
| 78 | |
| 79 | } // namespace android |
| 80 | |
| 81 | #endif // _UI_INPUT_APPLICATION_H |