bootstrap: add return value for checking launchapp command is failure or
[platform/core/uifw/aurum.git] / org.tizen.aurum-bootstrap / src / Commands / LaunchAppCommand.cc
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
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
18 #include "bootstrap.h"
19 #include "LaunchAppCommand.h"
20 #include "LaunchAppRunnable.h"
21 #include "UiDevice.h"
22 #include <chrono>
23 #include <thread>
24
25 #define WAIT_APP_LAUNCH 10000
26
27 LaunchAppCommand::LaunchAppCommand(const ::aurum::ReqLaunchApp *request,
28                                    ::aurum::RspLaunchApp *response)
29     : mRequest{request}, mResponse{response}
30 {
31 }
32
33 ::grpc::Status LaunchAppCommand::execute()
34 {
35     bool ret = false;
36     LOGI("LaunchApp --------------- ");
37     std::unique_ptr<LaunchAppRunnable> cmd = std::make_unique<LaunchAppRunnable>(mRequest->packagename(), mRequest->data());
38     std::shared_ptr<UiDevice> obj = UiDevice::getInstance();
39     ret = obj->executeAndWaitForEvents(cmd.get(), A11yEvent::EVENT_WINDOW_ACTIVATE, WAIT_APP_LAUNCH, mRequest->packagename(), 0);
40
41     if (ret) mResponse->set_status(::aurum::RspStatus::OK);
42     else mResponse->set_status(::aurum::RspStatus::ERROR);
43
44     return grpc::Status::OK;
45 }