Merge "Move InputApplication to use std::shared_ptr."
This commit is contained in:
committed by
Android (Google) Code Review
commit
bbfaaf2eba
@@ -77,32 +77,28 @@ bool NativeInputApplicationHandle::updateInfo() {
|
||||
return mInfo.token.get() != nullptr;
|
||||
}
|
||||
|
||||
|
||||
// --- Global functions ---
|
||||
|
||||
sp<InputApplicationHandle> android_view_InputApplicationHandle_getHandle(
|
||||
std::shared_ptr<InputApplicationHandle> android_view_InputApplicationHandle_getHandle(
|
||||
JNIEnv* env, jobject inputApplicationHandleObj) {
|
||||
if (!inputApplicationHandleObj) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
AutoMutex _l(gHandleMutex);
|
||||
|
||||
jlong ptr = env->GetLongField(inputApplicationHandleObj, gInputApplicationHandleClassInfo.ptr);
|
||||
NativeInputApplicationHandle* handle;
|
||||
std::shared_ptr<NativeInputApplicationHandle>* handle;
|
||||
if (ptr) {
|
||||
handle = reinterpret_cast<NativeInputApplicationHandle*>(ptr);
|
||||
handle = reinterpret_cast<std::shared_ptr<NativeInputApplicationHandle>*>(ptr);
|
||||
} else {
|
||||
jweak objWeak = env->NewWeakGlobalRef(inputApplicationHandleObj);
|
||||
handle = new NativeInputApplicationHandle(objWeak);
|
||||
handle->incStrong((void*)android_view_InputApplicationHandle_getHandle);
|
||||
handle = new std::shared_ptr(std::make_shared<NativeInputApplicationHandle>(objWeak));
|
||||
env->SetLongField(inputApplicationHandleObj, gInputApplicationHandleClassInfo.ptr,
|
||||
reinterpret_cast<jlong>(handle));
|
||||
}
|
||||
return handle;
|
||||
return *handle;
|
||||
}
|
||||
|
||||
|
||||
// --- JNI ---
|
||||
|
||||
static void android_view_InputApplicationHandle_nativeDispose(JNIEnv* env, jobject obj) {
|
||||
@@ -112,8 +108,9 @@ static void android_view_InputApplicationHandle_nativeDispose(JNIEnv* env, jobje
|
||||
if (ptr) {
|
||||
env->SetLongField(obj, gInputApplicationHandleClassInfo.ptr, 0);
|
||||
|
||||
NativeInputApplicationHandle* handle = reinterpret_cast<NativeInputApplicationHandle*>(ptr);
|
||||
handle->decStrong((void*)android_view_InputApplicationHandle_getHandle);
|
||||
std::shared_ptr<NativeInputApplicationHandle>* handle =
|
||||
reinterpret_cast<std::shared_ptr<NativeInputApplicationHandle>*>(ptr);
|
||||
delete handle;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,7 @@ private:
|
||||
jweak mObjWeak;
|
||||
};
|
||||
|
||||
|
||||
extern sp<InputApplicationHandle> android_view_InputApplicationHandle_getHandle(
|
||||
extern std::shared_ptr<InputApplicationHandle> android_view_InputApplicationHandle_getHandle(
|
||||
JNIEnv* env, jobject inputApplicationHandleObj);
|
||||
|
||||
} // namespace android
|
||||
|
||||
@@ -168,8 +168,8 @@ bool NativeInputWindowHandle::updateInfo() {
|
||||
jobject inputApplicationHandleObj = env->GetObjectField(obj,
|
||||
gInputWindowHandleClassInfo.inputApplicationHandle);
|
||||
if (inputApplicationHandleObj) {
|
||||
sp<InputApplicationHandle> inputApplicationHandle =
|
||||
android_view_InputApplicationHandle_getHandle(env, inputApplicationHandleObj);
|
||||
std::shared_ptr<InputApplicationHandle> inputApplicationHandle =
|
||||
android_view_InputApplicationHandle_getHandle(env, inputApplicationHandleObj);
|
||||
if (inputApplicationHandle != nullptr) {
|
||||
inputApplicationHandle->updateInfo();
|
||||
mInfo.applicationInfo = *(inputApplicationHandle->getInfo());
|
||||
|
||||
@@ -239,9 +239,9 @@ public:
|
||||
void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask,
|
||||
uint32_t policyFlags) override;
|
||||
void notifyConfigurationChanged(nsecs_t when) override;
|
||||
std::chrono::nanoseconds notifyAnr(const sp<InputApplicationHandle>& inputApplicationHandle,
|
||||
const sp<IBinder>& token,
|
||||
const std::string& reason) override;
|
||||
std::chrono::nanoseconds notifyAnr(
|
||||
const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle,
|
||||
const sp<IBinder>& token, const std::string& reason) override;
|
||||
void notifyInputChannelBroken(const sp<IBinder>& token) override;
|
||||
void notifyFocusChanged(const sp<IBinder>& oldToken, const sp<IBinder>& newToken) override;
|
||||
bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override;
|
||||
@@ -682,8 +682,8 @@ void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
|
||||
checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
|
||||
}
|
||||
|
||||
static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
|
||||
const sp<InputApplicationHandle>& inputApplicationHandle) {
|
||||
static jobject getInputApplicationHandleObjLocalRef(
|
||||
JNIEnv* env, const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) {
|
||||
if (inputApplicationHandle == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -694,8 +694,8 @@ static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
|
||||
}
|
||||
|
||||
std::chrono::nanoseconds NativeInputManager::notifyAnr(
|
||||
const sp<InputApplicationHandle>& inputApplicationHandle, const sp<IBinder>& token,
|
||||
const std::string& reason) {
|
||||
const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle,
|
||||
const sp<IBinder>& token, const std::string& reason) {
|
||||
#if DEBUG_INPUT_DISPATCHER_POLICY
|
||||
ALOGD("notifyANR");
|
||||
#endif
|
||||
@@ -780,8 +780,12 @@ void NativeInputManager::displayRemoved(JNIEnv* env, int32_t displayId) {
|
||||
|
||||
void NativeInputManager::setFocusedApplication(JNIEnv* env, int32_t displayId,
|
||||
jobject applicationHandleObj) {
|
||||
sp<InputApplicationHandle> applicationHandle =
|
||||
if (!applicationHandleObj) {
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<InputApplicationHandle> applicationHandle =
|
||||
android_view_InputApplicationHandle_getHandle(env, applicationHandleObj);
|
||||
applicationHandle->updateInfo();
|
||||
mInputManager->getDispatcher()->setFocusedApplication(displayId, applicationHandle);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user