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 "net_manager_tactics_call_back.h"
17 
18 #include "cellular_data_error.h"
19 #include "cellular_data_service.h"
20 #include "core_manager_inner.h"
21 #include "telephony_common_utils.h"
22 #include "telephony_log_wrapper.h"
23 
24 namespace OHOS {
25 namespace Telephony {
NetStrategySwitch(const std::string & simId,bool enable)26 int32_t NetManagerTacticsCallBack::NetStrategySwitch(const std::string &simId, bool enable)
27 {
28     if (simId.length() == 0) {
29         TELEPHONY_LOGI("StrategySwitch[The simd length is 0]");
30         return CELLULAR_DATA_INVALID_PARAM;
31     }
32     if (!IsValidDecValue(simId)) {
33         return CELLULAR_DATA_INVALID_PARAM;
34     }
35     const int32_t netSimId = std::stoi(simId);
36     CoreManagerInner &coreInner = CoreManagerInner::GetInstance();
37     for (int32_t  i = 0; i < SIM_SLOT_COUNT; ++i) {
38         IccAccountInfo accountInfo;
39         if (coreInner.GetSimAccountInfo(i, accountInfo) != TELEPHONY_ERR_SUCCESS) {
40             continue;
41         }
42         if (netSimId == accountInfo.simId) {
43             int32_t result = DelayedRefSingleton<CellularDataService>::GetInstance().StrategySwitch(i, enable);
44             TELEPHONY_LOGI("StrategySwitch[%{public}s, %{public}d, %{public}d] result %{public}d", simId.c_str(),
45                 i, enable, result);
46             return result;
47         }
48     }
49     TELEPHONY_LOGI("StrategySwitch fail[%{public}s, %{public}d]", simId.c_str(), enable);
50     return CELLULAR_DATA_INVALID_PARAM;
51 }
52 } // Telephony
53 } // OHOS
54