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 <string> 21 22 #include <binder/IBinder.h> 23 #include <binder/Parcel.h> 24 25 #include <input/Input.h> 26 #include <utils/RefBase.h> 27 #include <utils/Timers.h> 28 29 namespace android { 30 31 /* 32 * Describes the properties of an application that can receive input. 33 */ 34 struct InputApplicationInfo { 35 sp<IBinder> token; 36 std::string name; 37 nsecs_t dispatchingTimeout; 38 39 status_t write(Parcel& output) const; 40 static InputApplicationInfo read(const Parcel& from); 41 }; 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 */ 50 class InputApplicationHandle : public RefBase { 51 public: getInfo()52 inline const InputApplicationInfo* getInfo() const { 53 return &mInfo; 54 } 55 getName()56 inline std::string getName() const { 57 return !mInfo.name.empty() ? mInfo.name : "<invalid>"; 58 } 59 getDispatchingTimeout(nsecs_t defaultValue)60 inline nsecs_t getDispatchingTimeout(nsecs_t defaultValue) const { 61 return mInfo.token ? mInfo.dispatchingTimeout : defaultValue; 62 } 63 getDispatchingTimeout(std::chrono::nanoseconds defaultValue)64 inline std::chrono::nanoseconds getDispatchingTimeout( 65 std::chrono::nanoseconds defaultValue) const { 66 return mInfo.token ? std::chrono::nanoseconds(mInfo.dispatchingTimeout) : defaultValue; 67 } 68 getApplicationToken()69 inline sp<IBinder> getApplicationToken() const { 70 return mInfo.token; 71 } 72 73 /** 74 * Requests that the state of this object be updated to reflect 75 * the most current available information about the application. 76 * 77 * This method should only be called from within the input dispatcher's 78 * critical section. 79 * 80 * Returns true on success, or false if the handle is no longer valid. 81 */ 82 virtual bool updateInfo() = 0; 83 protected: 84 InputApplicationHandle(); 85 virtual ~InputApplicationHandle(); 86 87 InputApplicationInfo mInfo; 88 }; 89 90 } // namespace android 91 92 #endif // _UI_INPUT_APPLICATION_H 93