MCPcopy Create free account
hub / github.com/android/ndk-samples / HandleCommand

Method HandleCommand

endless-tunnel/app/src/main/cpp/native_engine.cpp:136–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134}
135
136void NativeEngine::HandleCommand(int32_t cmd) {
137 SceneManager* mgr = SceneManager::GetInstance();
138
139 VLOGD("NativeEngine: handling command %d.", cmd);
140 switch (cmd) {
141 case APP_CMD_SAVE_STATE:
142 // The system has asked us to save our current state.
143 VLOGD("NativeEngine: APP_CMD_SAVE_STATE");
144 mState.mHasFocus = mHasFocus;
145 mApp->savedState = malloc(sizeof(mState));
146 *((NativeEngineSavedState*)mApp->savedState) = mState;
147 mApp->savedStateSize = sizeof(mState);
148 break;
149 case APP_CMD_INIT_WINDOW:
150 // We have a window!
151 VLOGD("NativeEngine: APP_CMD_INIT_WINDOW");
152 if (mApp->window != NULL) {
153 mHasWindow = true;
154 if (mApp->savedStateSize == sizeof(mState) &&
155 mApp->savedState != nullptr) {
156 mState = *((NativeEngineSavedState*)mApp->savedState);
157 mHasFocus = mState.mHasFocus;
158 } else {
159 // Workaround APP_CMD_GAINED_FOCUS issue where the focus state is not
160 // passed down from NativeActivity when restarting Activity
161 mHasFocus = appState.mHasFocus;
162 }
163 }
164 VLOGD("HandleCommand(%d): hasWindow = %d, hasFocus = %d", cmd,
165 mHasWindow ? 1 : 0, mHasFocus ? 1 : 0);
166 break;
167 case APP_CMD_TERM_WINDOW:
168 // The window is going away -- kill the surface
169 VLOGD("NativeEngine: APP_CMD_TERM_WINDOW");
170 KillSurface();
171 mHasWindow = false;
172 break;
173 case APP_CMD_GAINED_FOCUS:
174 VLOGD("NativeEngine: APP_CMD_GAINED_FOCUS");
175 mHasFocus = true;
176 mState.mHasFocus = appState.mHasFocus = mHasFocus;
177 break;
178 case APP_CMD_LOST_FOCUS:
179 VLOGD("NativeEngine: APP_CMD_LOST_FOCUS");
180 mHasFocus = false;
181 mState.mHasFocus = appState.mHasFocus = mHasFocus;
182 break;
183 case APP_CMD_PAUSE:
184 VLOGD("NativeEngine: APP_CMD_PAUSE");
185 mgr->OnPause();
186 break;
187 case APP_CMD_RESUME:
188 VLOGD("NativeEngine: APP_CMD_RESUME");
189 mgr->OnResume();
190 break;
191 case APP_CMD_STOP:
192 VLOGD("NativeEngine: APP_CMD_STOP");
193 mIsVisible = false;

Callers 1

_handle_cmd_proxyFunction · 0.80

Calls 2

OnPauseMethod · 0.45
OnResumeMethod · 0.45

Tested by

no test coverage detected