| 180 | } |
| 181 | |
| 182 | void LoaderService::onStopAllAppMessage(const std::string& id) { |
| 183 | auto lock = mutex.asScopedLock(); |
| 184 | if (!lock.lock(LOADER_TIMEOUT)) { |
| 185 | LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED); |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | if (!isRunning(id)) { |
| 190 | LOGGER.error("Stop all: {} not running", id); |
| 191 | return; |
| 192 | } |
| 193 | |
| 194 | int app_to_stop_index = findAppInStack(id); |
| 195 | if (app_to_stop_index < 0) { |
| 196 | LOGGER.error("Stop all: {} not found in stack", id); |
| 197 | return; |
| 198 | } |
| 199 | |
| 200 | |
| 201 | // Find an app to resume, if any |
| 202 | std::shared_ptr<app::AppInstance> instance_to_resume; |
| 203 | if (app_to_stop_index > 0) { |
| 204 | instance_to_resume = appStack[app_to_stop_index - 1]; |
| 205 | assert(instance_to_resume); |
| 206 | } |
| 207 | |
| 208 | // Stop all apps and find the LaunchId of the last-closed app, so we can call onResult() if needed |
| 209 | app::LaunchId last_launch_id = 0; |
| 210 | for (int i = appStack.size() - 1; i >= app_to_stop_index; i--) { |
| 211 | auto app_to_stop = appStack[i]; |
| 212 | // Hide the app first in case it's still being shown |
| 213 | if (app_to_stop->getState() == app::State::Showing) { |
| 214 | transitionAppToState(app_to_stop, app::State::Hiding); |
| 215 | } |
| 216 | transitionAppToState(app_to_stop, app::State::Destroyed); |
| 217 | last_launch_id = app_to_stop->getLaunchId(); |
| 218 | |
| 219 | appStack.pop_back(); |
| 220 | } |
| 221 | |
| 222 | if (instance_to_resume != nullptr) { |
| 223 | LOGGER.info("Resuming {}", instance_to_resume->getManifest().appId); |
| 224 | transitionAppToState(instance_to_resume, app::State::Showing); |
| 225 | |
| 226 | instance_to_resume->getApp()->onResult( |
| 227 | *instance_to_resume, |
| 228 | last_launch_id, |
| 229 | app::Result::Cancelled, |
| 230 | nullptr |
| 231 | ); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | void LoaderService::transitionAppToState(const std::shared_ptr<app::AppInstance>& app, app::State state) { |
| 236 | const app::AppManifest& app_manifest = app->getManifest(); |
nothing calls this directly
no test coverage detected