1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "local_ability_manager_proxy.h"
17 #include "ipc_types.h"
18 #include "parcel.h"
19
20 using namespace std;
21 using namespace OHOS::HiviewDFX;
22
23 namespace OHOS {
StartAbility(int32_t systemAbilityId)24 bool LocalAbilityManagerProxy::StartAbility(int32_t systemAbilityId)
25 {
26 if (systemAbilityId <= 0) {
27 HiLog::Warn(label_, "StartAbility systemAbilityId invalid.");
28 return false;
29 }
30
31 sptr<IRemoteObject> iro = Remote();
32 if (iro == nullptr) {
33 HiLog::Error(label_, "StartAbility Remote return null");
34 return false;
35 }
36
37 MessageParcel data;
38 if (!data.WriteInterfaceToken(LOCAL_ABILITY_MANAGER_INTERFACE_TOKEN)) {
39 HiLog::Warn(label_, "StartAbility interface token check failed");
40 return false;
41 }
42 bool ret = data.WriteInt32(systemAbilityId);
43 if (!ret) {
44 HiLog::Warn(label_, "StartAbility write systemAbilityId failed!");
45 return false;
46 }
47
48 MessageParcel reply;
49 MessageOption option(MessageOption::TF_ASYNC);
50 int32_t status = iro->SendRequest(START_ABILITY_TRANSACTION, data, reply, option);
51 if (status != NO_ERROR) {
52 HiLog::Error(label_, "StartAbility SendRequest failed, return value : %{public}d", status);
53 return false;
54 }
55 return true;
56 }
57 }
58