1 /*
2 * Copyright (C) 2024 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 "super_privacy_manager_client.h"
17
18 #include <thread>
19 #include <iremote_proxy.h>
20
21 #include "parameter.h"
22 #include "iservice_registry.h"
23
24 namespace OHOS {
25 namespace Telephony {
26 static const int SUPER_PRIVACY_MANAGER_SA_ID = 66102;
27 static constexpr int32_t LOAD_SA_TIMEOUT_SECONDS = 4;
28
SuperPrivacyManagerClient()29 SuperPrivacyManagerClient::SuperPrivacyManagerClient() {}
30
GetInstance()31 SuperPrivacyManagerClient &SuperPrivacyManagerClient::GetInstance()
32 {
33 static SuperPrivacyManagerClient instance;
34 return instance;
35 }
36
SetSuperPrivacyMode(const int32_t & mode,const int32_t & source)37 int32_t SuperPrivacyManagerClient::SetSuperPrivacyMode(const int32_t &mode, const int32_t &source)
38 {
39 auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
40 if (sam == nullptr) {
41 return ERR_INVALID_VALUE;
42 }
43 auto sa = sam->LoadSystemAbility(SUPER_PRIVACY_MANAGER_SA_ID, LOAD_SA_TIMEOUT_SECONDS);
44 if (sa == nullptr) {
45 return ERR_INVALID_VALUE;
46 }
47 MessageParcel data;
48 MessageParcel reply;
49 MessageOption option(MessageOption::TF_SYNC);
50 if (!data.WriteInterfaceToken(
51 u"OHOS.AppSecurityPrivacy.SecurityPrivacyServer.SuperPrivacy.ISuperPrivacyManager")) {
52 return ERR_INVALID_VALUE;
53 }
54 if (!data.WriteInt32(mode)) {
55 return ERR_INVALID_DATA;
56 }
57 if (!data.WriteInt32(source)) {
58 return ERR_INVALID_DATA;
59 }
60 int32_t result = sa->SendRequest(COMMAND_SET_SUPER_PRIVACY_MODE, data, reply, option);
61 return result;
62 }
63 } // namespace Telephony
64 } // namespace OHOS