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 "pdp_profile_rdb_helper.h"
17 #include "telephony_data_helper.h"
18 #include "telephony_log_wrapper.h"
19 
20 static constexpr const char *PDP_PROFILE_RDB_URI = "datashare:///com.ohos.pdpprofileability/net";
21 static constexpr const char *PDP_PROFILE_RDB_INIT_URI =
22     "datashare:///com.ohos.pdpprofileability/net/pdp_profile/init";
23 static constexpr const char *SLOT_ID = "slotId";
24 
25 namespace OHOS {
26 namespace Telephony {
PdpProfileRdbHelper()27 PdpProfileRdbHelper::PdpProfileRdbHelper() {}
28 
29 PdpProfileRdbHelper::~PdpProfileRdbHelper() = default;
30 
CreatePdpProfileDataHelper()31 std::shared_ptr<DataShare::DataShareHelper> PdpProfileRdbHelper::CreatePdpProfileDataHelper()
32 {
33     TELEPHONY_LOGI("PdpProfileRdbHelper::CreatePdpProfileDataHelper");
34     auto helper = TelephonyDataHelper::GetInstance();
35     if (helper == nullptr) {
36         TELEPHONY_LOGE("get CreatePdpProfileDataHelper Failed");
37         return nullptr;
38     }
39     return helper->CreatePdpHelper();
40 }
41 
notifyInitApnConfigs(int32_t slotId)42 void PdpProfileRdbHelper::notifyInitApnConfigs(int32_t slotId)
43 {
44     std::shared_ptr<DataShare::DataShareHelper> dataShareHelper = CreatePdpProfileDataHelper();
45     if (dataShareHelper == nullptr) {
46         TELEPHONY_LOGE("dataShareHelper is nullptr");
47         return;
48     }
49     std::vector<DataShare::DataShareValuesBucket> values;
50     DataShare::DataShareValuesBucket value;
51     value.Put(SLOT_ID, slotId);
52     values.push_back(value);
53     Uri pdpProfileUri(PDP_PROFILE_RDB_INIT_URI);
54     dataShareHelper->BatchInsert(pdpProfileUri, values);
55     dataShareHelper->Release();
56     dataShareHelper = nullptr;
57 }
58 }  // namespace Telephony
59 }  // namespace OHOS