mirror of
https://github.com/android/ndk-samples
synced 2025-11-10 02:21:11 +08:00
Merge pull request #696 from android/endless-tunnel-fix
Added workaround for b/149866792
This commit is contained in:
@@ -34,6 +34,9 @@
|
|||||||
|
|
||||||
static NativeEngine *_singleton = NULL;
|
static NativeEngine *_singleton = NULL;
|
||||||
|
|
||||||
|
// workaround for internal bug b/149866792
|
||||||
|
static NativeEngineSavedState appState = {false};
|
||||||
|
|
||||||
NativeEngine::NativeEngine(struct android_app *app) {
|
NativeEngine::NativeEngine(struct android_app *app) {
|
||||||
LOGD("NativeEngine: initializing.");
|
LOGD("NativeEngine: initializing.");
|
||||||
mApp = app;
|
mApp = app;
|
||||||
@@ -136,7 +139,6 @@ JNIEnv* NativeEngine::GetJniEnv() {
|
|||||||
return mJniEnv;
|
return mJniEnv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void NativeEngine::HandleCommand(int32_t cmd) {
|
void NativeEngine::HandleCommand(int32_t cmd) {
|
||||||
SceneManager *mgr = SceneManager::GetInstance();
|
SceneManager *mgr = SceneManager::GetInstance();
|
||||||
|
|
||||||
@@ -145,6 +147,7 @@ void NativeEngine::HandleCommand(int32_t cmd) {
|
|||||||
case APP_CMD_SAVE_STATE:
|
case APP_CMD_SAVE_STATE:
|
||||||
// The system has asked us to save our current state.
|
// The system has asked us to save our current state.
|
||||||
VLOGD("NativeEngine: APP_CMD_SAVE_STATE");
|
VLOGD("NativeEngine: APP_CMD_SAVE_STATE");
|
||||||
|
mState.mHasFocus = mHasFocus;
|
||||||
mApp->savedState = malloc(sizeof(mState));
|
mApp->savedState = malloc(sizeof(mState));
|
||||||
*((NativeEngineSavedState*)mApp->savedState) = mState;
|
*((NativeEngineSavedState*)mApp->savedState) = mState;
|
||||||
mApp->savedStateSize = sizeof(mState);
|
mApp->savedStateSize = sizeof(mState);
|
||||||
@@ -154,7 +157,16 @@ void NativeEngine::HandleCommand(int32_t cmd) {
|
|||||||
VLOGD("NativeEngine: APP_CMD_INIT_WINDOW");
|
VLOGD("NativeEngine: APP_CMD_INIT_WINDOW");
|
||||||
if (mApp->window != NULL) {
|
if (mApp->window != NULL) {
|
||||||
mHasWindow = true;
|
mHasWindow = true;
|
||||||
|
if (mApp->savedStateSize == sizeof(mState) && mApp->savedState != nullptr) {
|
||||||
|
mState = *((NativeEngineSavedState*)mApp->savedState);
|
||||||
|
mHasFocus = mState.mHasFocus;
|
||||||
|
} else {
|
||||||
|
// Workaround APP_CMD_GAINED_FOCUS issue where the focus state is not
|
||||||
|
// passed down from NativeActivity when restarting Activity
|
||||||
|
mHasFocus = appState.mHasFocus;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
VLOGD("HandleCommand(%d): hasWindow = %d, hasFocus = %d", cmd, mHasWindow?1:0, mHasFocus?1:0);
|
||||||
break;
|
break;
|
||||||
case APP_CMD_TERM_WINDOW:
|
case APP_CMD_TERM_WINDOW:
|
||||||
// The window is going away -- kill the surface
|
// The window is going away -- kill the surface
|
||||||
@@ -165,10 +177,12 @@ void NativeEngine::HandleCommand(int32_t cmd) {
|
|||||||
case APP_CMD_GAINED_FOCUS:
|
case APP_CMD_GAINED_FOCUS:
|
||||||
VLOGD("NativeEngine: APP_CMD_GAINED_FOCUS");
|
VLOGD("NativeEngine: APP_CMD_GAINED_FOCUS");
|
||||||
mHasFocus = true;
|
mHasFocus = true;
|
||||||
|
mState.mHasFocus = appState.mHasFocus = mHasFocus;
|
||||||
break;
|
break;
|
||||||
case APP_CMD_LOST_FOCUS:
|
case APP_CMD_LOST_FOCUS:
|
||||||
VLOGD("NativeEngine: APP_CMD_LOST_FOCUS");
|
VLOGD("NativeEngine: APP_CMD_LOST_FOCUS");
|
||||||
mHasFocus = false;
|
mHasFocus = false;
|
||||||
|
mState.mHasFocus = appState.mHasFocus = mHasFocus;
|
||||||
break;
|
break;
|
||||||
case APP_CMD_PAUSE:
|
case APP_CMD_PAUSE:
|
||||||
VLOGD("NativeEngine: APP_CMD_PAUSE");
|
VLOGD("NativeEngine: APP_CMD_PAUSE");
|
||||||
|
|||||||
@@ -18,7 +18,9 @@
|
|||||||
|
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
|
|
||||||
struct NativeEngineSavedState {};
|
struct NativeEngineSavedState {
|
||||||
|
bool mHasFocus;
|
||||||
|
};
|
||||||
|
|
||||||
class NativeEngine {
|
class NativeEngine {
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user