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
18 #include "ipc_types.h"
19 #include "iremote_object.h"
20 #include "message_option.h"
21 #include "message_parcel.h"
22 #include "refbase.h"
23
24 using namespace std;
25 using namespace OHOS::HiviewDFX;
26
27 namespace OHOS {
StartAbility(int32_t systemAbilityId)28 bool LocalAbilityManagerProxy::StartAbility(int32_t systemAbilityId)
29 {
30 if (systemAbilityId <= 0) {
31 HiLog::Warn(label_, "StartAbility systemAbilityId invalid.");
32 return false;
33 }
34
35 sptr<IRemoteObject> iro = Remote();
36 if (iro == nullptr) {
37 HiLog::Error(label_, "StartAbility Remote return null");
38 return false;
39 }
40
41 MessageParcel data;
42 if (!data.WriteInterfaceToken(LOCAL_ABILITY_MANAGER_INTERFACE_TOKEN)) {
43 HiLog::Warn(label_, "StartAbility interface token check failed");
44 return false;
45 }
46 bool ret = data.WriteInt32(systemAbilityId);
47 if (!ret) {
48 HiLog::Warn(label_, "StartAbility write systemAbilityId failed!");
49 return false;
50 }
51
52 MessageParcel reply;
53 MessageOption option(MessageOption::TF_ASYNC);
54 int32_t status = iro->SendRequest(START_ABILITY_TRANSACTION, data, reply, option);
55 if (status != NO_ERROR) {
56 HiLog::Error(label_, "StartAbility SendRequest failed, return value : %{public}d", status);
57 return false;
58 }
59 return true;
60 }
61 }
62