• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "ability_manager_privacy_proxy.h"
17 #include "accesstoken_log.h"
18 #include "privacy_error.h"
19 
20 namespace OHOS {
21 namespace Security {
22 namespace AccessToken {
23 namespace {
24     constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_PRIVACY, "AbilityManagerPrivacyProxy"};
25 }
26 
StartAbility(const AAFwk::Want & want,const sptr<IRemoteObject> & callerToken,int requestCode,int32_t userId)27 int AbilityManagerPrivacyProxy::StartAbility(const AAFwk::Want &want, const sptr<IRemoteObject> &callerToken,
28     int requestCode, int32_t userId)
29 {
30     MessageParcel data;
31     MessageParcel reply;
32     MessageOption option;
33 
34     if (!data.WriteInterfaceToken(GetDescriptor())) {
35         ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write WriteInterfaceToken.");
36         return PrivacyError::ERR_WRITE_PARCEL_FAILED;
37     }
38 
39     if (!data.WriteParcelable(&want)) {
40         ACCESSTOKEN_LOG_ERROR(LABEL, "want write failed.");
41         return PrivacyError::ERR_WRITE_PARCEL_FAILED;
42     }
43     if (callerToken) {
44         if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
45             ACCESSTOKEN_LOG_ERROR(LABEL, "callerToken and flag write failed.");
46             return PrivacyError::ERR_WRITE_PARCEL_FAILED;
47         }
48     } else {
49         if (!data.WriteBool(false)) {
50             ACCESSTOKEN_LOG_ERROR(LABEL, "flag write failed.");
51             return PrivacyError::ERR_WRITE_PARCEL_FAILED;
52         }
53     }
54     if (!data.WriteInt32(userId)) {
55         ACCESSTOKEN_LOG_ERROR(LABEL, "userId write failed.");
56         return PrivacyError::ERR_WRITE_PARCEL_FAILED;
57     }
58     if (!data.WriteInt32(requestCode)) {
59         ACCESSTOKEN_LOG_ERROR(LABEL, "requestCode write failed.");
60         return PrivacyError::ERR_WRITE_PARCEL_FAILED;
61     }
62 
63     int error = Remote()->SendRequest(
64         static_cast<uint32_t>(IAbilityManager::AbilityManagerMessage::START_ABILITY_ADD_CALLER), data, reply, option);
65     if (error != 0) {
66         ACCESSTOKEN_LOG_ERROR(LABEL, "Send request error: %{public}d", error);
67         return error;
68     }
69     return reply.ReadInt32();
70 }
71 } // namespace AccessToken
72 } // namespace Security
73 } // namespace OHOS
74