mirror of
https://github.com/openharmony/telephony_data_storage.git
synced 2026-07-19 20:43:32 -04:00
@@ -13,38 +13,38 @@
|
||||
- [Parameters of the Update API](#section1099113151207)
|
||||
- [Parameters of the Query API](#section1096113151208)
|
||||
- [Sample Code](#section1558565082915)
|
||||
|
||||
|
||||
- [Repositories Involved](#section206mcpsimp)
|
||||
|
||||
## Introduction<a name="section117mcpsimp"></a>
|
||||
|
||||
The data storage module stores persistent data of key modules of the Telephony subsystem, such as the SIM cards and SMS modules, and provides the **DataAbility** API for data access.
|
||||
|
||||
**Figure 1** Architecture of the data storage module<a name="fig13267152558"></a>
|
||||
**Figure 1** Architecture of the data storage module<a name="fig13267152558"></a>
|
||||
|
||||

|
||||
|
||||
## Directory Structure<a name="section124mcpsimp"></a>
|
||||
## Directory Structure<a name="section124mcpsimp"></a>
|
||||
|
||||
```
|
||||
/base/telephony/data_storage # Data storage
|
||||
├─ BUILD.gn # Build script (gn)
|
||||
├─ README.md # Readme
|
||||
├─ common # Public and common files
|
||||
│ ├─ include
|
||||
│ └─ src
|
||||
│ ├─ include
|
||||
│ └─ src
|
||||
├─ opkey # opkey framework
|
||||
│ ├─ include
|
||||
│ └─ src
|
||||
├─ pdp_profile # Network carrier
|
||||
│ ├─ include
|
||||
│ └─ src
|
||||
│ ├─ include
|
||||
│ └─ src
|
||||
├─ sim # SIM card
|
||||
│ ├─ include
|
||||
│ └─ src
|
||||
│ ├─ include
|
||||
│ └─ src
|
||||
├─ sms_mms # SMS/MMS
|
||||
│ ├─ include
|
||||
│ └─ src
|
||||
│ ├─ include
|
||||
│ └─ src
|
||||
├─ ohos.build # Build code
|
||||
└─ test # Test code
|
||||
```
|
||||
@@ -142,7 +142,7 @@ The following provides the procedure and sample code for you to query, insert, d
|
||||
1. Call **SystemAbilityManagerClient** to obtain a **SystemAbilityManager** object.
|
||||
2. Call **saManager** to obtain an **IRemoteObject** object based on the specified service ID.
|
||||
3. Call **IRemoteObject** to create a **DataAbilityHelper** object.
|
||||
4. Call **DataAbilityHelper::Query** to query data, and call the other related APIs to process data.
|
||||
4. Call **DataAbilityHelper::Query** to query data, and call the other related APIs to process data.
|
||||
|
||||
Sample code for creating a **DataAbilityHelper** instance:
|
||||
```
|
||||
@@ -167,7 +167,7 @@ The following provides the procedure and sample code for you to query, insert, d
|
||||
Sample code for querying SMS/MMS messages:
|
||||
```
|
||||
std::shared_ptr<NativeRdb::AbsSharedResultSet> SmsSelect(std::shared_ptr<AppExecFwk::DataAbilityHelper> helper)
|
||||
{
|
||||
{
|
||||
// Resource path
|
||||
Uri uri("dataability:///com.ohos.smsmmsability/sms_mms/sms_mms_info");
|
||||
// Fields in the query result
|
||||
|
||||
@@ -57,35 +57,6 @@ public:
|
||||
private:
|
||||
int LoaderJsonFile(char *&content, const char *path) const;
|
||||
int CloseFile(FILE *f) const;
|
||||
|
||||
private:
|
||||
const char *PATH = "/system/etc/telephony/pdp_profile.json";
|
||||
const char *ITEM_OPERATOR_INFOS = "operator_infos";
|
||||
const char *ITEM_OPERATOR_NAME = "operator_name";
|
||||
const char *ITEM_AUTH_USER = "auth_user";
|
||||
const char *ITEM_AUTH_PWD = "auth_pwd";
|
||||
const char *ITEM_AUTH_TYPE = "auth_type";
|
||||
const char *ITEM_MCC = "mcc";
|
||||
const char *ITEM_MNC = "mnc";
|
||||
const char *ITEM_APN = "apn";
|
||||
const char *ITEM_APN_TYPES = "apn_types";
|
||||
const char *ITEM_IP_ADDRESS = "ip_addr";
|
||||
const char *ITEM_MMS_IP_ADDRESS = "mms_ip_addr";
|
||||
const char *ITEM_HOME_URL = "home_url";
|
||||
const std::string APN_VERSION = "apn_version";
|
||||
const char *OPKEY_INFO_PATH = "etc/telephony/OpkeyInfo.json";
|
||||
const char *ITEM_OPERATOR_ID = "operator_id";
|
||||
const char *ITEM_RULE = "rule";
|
||||
const char *ITEM_MCCMNC = "mcc_mnc";
|
||||
const char *ITEM_GID_ONE = "gid1";
|
||||
const char *ITEM_GID_TWO = "gid2";
|
||||
const char *ITEM_IMSI = "imsi";
|
||||
const char *ITEM_SPN = "spn";
|
||||
const char *ITEM_ICCID = "iccid";
|
||||
const char *ITEM_OPERATOR_NAME_OPKEY = "operator_name";
|
||||
const char *ITEM_OPERATOR_KEY = "operator_key";
|
||||
const char *ITEM_OPERATOR_KEY_EXT = "operator_key_ext";
|
||||
const int MAX_BYTE_LEN = 10 * 1024 * 1024;
|
||||
};
|
||||
} // namespace Telephony
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -68,8 +68,8 @@ void GetCurrentTime(std::string &date)
|
||||
if (now == -1) {
|
||||
return;
|
||||
}
|
||||
tm *ltm = nullptr;
|
||||
ltm = localtime_r(&now, ltm);
|
||||
struct tm tm = { 0 };
|
||||
struct tm *ltm = localtime_r(&now, &tm);
|
||||
if (ltm == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,34 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Telephony {
|
||||
const char *PATH = "/system/etc/telephony/pdp_profile.json";
|
||||
const char *ITEM_OPERATOR_INFOS = "operator_infos";
|
||||
const char *ITEM_OPERATOR_NAME = "operator_name";
|
||||
const char *ITEM_AUTH_USER = "auth_user";
|
||||
const char *ITEM_AUTH_PWD = "auth_pwd";
|
||||
const char *ITEM_AUTH_TYPE = "auth_type";
|
||||
const char *ITEM_MCC = "mcc";
|
||||
const char *ITEM_MNC = "mnc";
|
||||
const char *ITEM_APN = "apn";
|
||||
const char *ITEM_APN_TYPES = "apn_types";
|
||||
const char *ITEM_IP_ADDRESS = "ip_addr";
|
||||
const char *ITEM_MMS_IP_ADDRESS = "mms_ip_addr";
|
||||
const char *ITEM_HOME_URL = "home_url";
|
||||
const char *APN_VERSION = "apn_version";
|
||||
const char *OPKEY_INFO_PATH = "etc/telephony/OpkeyInfo.json";
|
||||
const char *ITEM_OPERATOR_ID = "operator_id";
|
||||
const char *ITEM_RULE = "rule";
|
||||
const char *ITEM_MCCMNC = "mcc_mnc";
|
||||
const char *ITEM_GID_ONE = "gid1";
|
||||
const char *ITEM_GID_TWO = "gid2";
|
||||
const char *ITEM_IMSI = "imsi";
|
||||
const char *ITEM_SPN = "spn";
|
||||
const char *ITEM_ICCID = "iccid";
|
||||
const char *ITEM_OPERATOR_NAME_OPKEY = "operator_name";
|
||||
const char *ITEM_OPERATOR_KEY = "operator_key";
|
||||
const char *ITEM_OPERATOR_KEY_EXT = "operator_key_ext";
|
||||
const int MAX_BYTE_LEN = 10 * 1024 * 1024;
|
||||
|
||||
int ParserUtil::ParserPdpProfileJson(std::vector<PdpProfile> &vec)
|
||||
{
|
||||
char *content = nullptr;
|
||||
@@ -50,6 +78,7 @@ int ParserUtil::ParserPdpProfileJson(std::vector<PdpProfile> &vec)
|
||||
const int contentLength = strlen(content);
|
||||
const std::string rawJson(content);
|
||||
free(content);
|
||||
content = nullptr;
|
||||
JSONCPP_STRING err;
|
||||
Json::Value root;
|
||||
Json::CharReaderBuilder builder;
|
||||
@@ -59,6 +88,7 @@ int ParserUtil::ParserPdpProfileJson(std::vector<PdpProfile> &vec)
|
||||
return static_cast<int>(LoadProFileErrorType::FILE_PARSER_ERROR);
|
||||
}
|
||||
delete reader;
|
||||
reader = nullptr;
|
||||
Json::Value itemRoots = root[ITEM_OPERATOR_INFOS];
|
||||
if (itemRoots.size() == 0) {
|
||||
DATA_STORAGE_LOGE("ParserUtil::ParserPdpProfileJson itemRoots size == 0!\n");
|
||||
@@ -150,7 +180,8 @@ int ParserUtil::ParserOpKeyJson(std::vector<OpKey> &vec, const char *path)
|
||||
}
|
||||
const int contentLength = strlen(content);
|
||||
const std::string rawJson(content);
|
||||
delete content;
|
||||
free(content);
|
||||
content = nullptr;
|
||||
JSONCPP_STRING err;
|
||||
Json::Value root;
|
||||
Json::CharReaderBuilder builder;
|
||||
@@ -160,6 +191,7 @@ int ParserUtil::ParserOpKeyJson(std::vector<OpKey> &vec, const char *path)
|
||||
return static_cast<int>(LoadProFileErrorType::FILE_PARSER_ERROR);
|
||||
}
|
||||
delete reader;
|
||||
reader = nullptr;
|
||||
Json::Value itemRoots = root[ITEM_OPERATOR_ID];
|
||||
if (itemRoots.size() == 0) {
|
||||
DATA_STORAGE_LOGE("ParserUtil::ParserOpKeyInfos itemRoots size == 0!\n");
|
||||
@@ -224,7 +256,7 @@ void ParserUtil::ParserOpKeyToValuesBucket(NativeRdb::ValuesBucket &value, const
|
||||
|
||||
int ParserUtil::LoaderJsonFile(char *&content, const char *path) const
|
||||
{
|
||||
size_t len = 0;
|
||||
long len = 0;
|
||||
char realPath[PATH_MAX] = { 0x00 };
|
||||
if (realpath(path, realPath) == nullptr) {
|
||||
DATA_STORAGE_LOGE("ParserUtil::LoaderJsonFile realpath fail! #PATH: %{public}s", path);
|
||||
@@ -241,14 +273,14 @@ int ParserUtil::LoaderJsonFile(char *&content, const char *path) const
|
||||
CloseFile(f);
|
||||
return static_cast<int>(LoadProFileErrorType::LOAD_FILE_ERROR);
|
||||
}
|
||||
len = static_cast<size_t>(ftell(f));
|
||||
len = ftell(f);
|
||||
int ret_seek_set = fseek(f, 0, SEEK_SET);
|
||||
if (ret_seek_set != 0) {
|
||||
DATA_STORAGE_LOGE("ParserUtil::LoaderJsonFile ret_seek_set != 0!");
|
||||
CloseFile(f);
|
||||
return static_cast<int>(LoadProFileErrorType::LOAD_FILE_ERROR);
|
||||
}
|
||||
if (len == 0 || len > MAX_BYTE_LEN) {
|
||||
if (len == 0 || len > static_cast<long>(MAX_BYTE_LEN)) {
|
||||
DATA_STORAGE_LOGE("ParserUtil::LoaderJsonFile len <= 0 or len > LONG_MAX!");
|
||||
CloseFile(f);
|
||||
return static_cast<int>(LoadProFileErrorType::LOAD_FILE_ERROR);
|
||||
|
||||
@@ -84,10 +84,9 @@ private:
|
||||
private:
|
||||
RdbOpKeyHelper helper_;
|
||||
std::mutex lock_;
|
||||
std::map<std::string, OpKeyUriType> opKeyUriMap;
|
||||
bool initDatabaseDir = false;
|
||||
bool initRdbStore = false;
|
||||
int CHANGED_ROWS = 0;
|
||||
std::map<std::string, OpKeyUriType> opKeyUriMap_;
|
||||
bool initDatabaseDir_ = false;
|
||||
bool initRdbStore_ = false;
|
||||
};
|
||||
} // namespace Telephony
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -73,7 +73,6 @@ private:
|
||||
private:
|
||||
const std::string DB_NAME = "opkey.db";
|
||||
std::string dbPath_ = FOLDER_PATH + DB_NAME;
|
||||
const int VERSION = 1;
|
||||
};
|
||||
} // namespace Telephony
|
||||
} // namespace OHOS
|
||||
|
||||
+12
-11
@@ -33,6 +33,7 @@ namespace OHOS {
|
||||
using AppExecFwk::AbilityLoader;
|
||||
using AppExecFwk::Ability;
|
||||
namespace Telephony {
|
||||
const int32_t CHANGED_ROWS = 0;
|
||||
void OpKeyAbility::OnStart(const AppExecFwk::Want &want)
|
||||
{
|
||||
DATA_STORAGE_LOGI("OpKeyAbility::OnStart\n");
|
||||
@@ -45,19 +46,19 @@ void OpKeyAbility::OnStart(const AppExecFwk::Want &want)
|
||||
std::string path = abilityContext->GetDatabaseDir();
|
||||
DATA_STORAGE_LOGI("GetDatabaseDir: %{public}s", path.c_str());
|
||||
if (!path.empty()) {
|
||||
initDatabaseDir = true;
|
||||
initDatabaseDir_ = true;
|
||||
path.append("/");
|
||||
helper_.UpdateDbPath(path);
|
||||
InitUriMap();
|
||||
int rdbInitCode = helper_.Init();
|
||||
if (rdbInitCode == NativeRdb::E_OK) {
|
||||
initRdbStore = true;
|
||||
initRdbStore_ = true;
|
||||
} else {
|
||||
DATA_STORAGE_LOGE("OpKeyAbility::OnStart rdb init failed!");
|
||||
initRdbStore = false;
|
||||
initRdbStore_ = false;
|
||||
}
|
||||
} else {
|
||||
initDatabaseDir = false;
|
||||
initDatabaseDir_ = false;
|
||||
DATA_STORAGE_LOGE("OpKeyAbility::OnStart##the databaseDir is empty!");
|
||||
}
|
||||
}
|
||||
@@ -164,12 +165,12 @@ int OpKeyAbility::Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates
|
||||
|
||||
bool OpKeyAbility::IsInitOk()
|
||||
{
|
||||
if (!initDatabaseDir) {
|
||||
DATA_STORAGE_LOGE("OpKeyAbility::IsInitOk initDatabaseDir failed!");
|
||||
if (!initDatabaseDir_) {
|
||||
DATA_STORAGE_LOGE("OpKeyAbility::IsInitOk initDatabaseDir_ failed!");
|
||||
return false;
|
||||
}
|
||||
if (!initRdbStore) {
|
||||
DATA_STORAGE_LOGE("OpKeyAbility::IsInitOk initRdbStore failed!");
|
||||
if (!initRdbStore_) {
|
||||
DATA_STORAGE_LOGE("OpKeyAbility::IsInitOk initRdbStore_ failed!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -177,7 +178,7 @@ bool OpKeyAbility::IsInitOk()
|
||||
|
||||
void OpKeyAbility::InitUriMap()
|
||||
{
|
||||
opKeyUriMap = {
|
||||
opKeyUriMap_ = {
|
||||
{"/opkey/opkey_info", OpKeyUriType::OPKEY_INFO}
|
||||
};
|
||||
}
|
||||
@@ -208,8 +209,8 @@ OpKeyUriType OpKeyAbility::ParseUriType(Uri &uri)
|
||||
std::string path = tempUri.GetPath();
|
||||
if (!path.empty()) {
|
||||
DATA_STORAGE_LOGI("OpKeyAbility::ParseUriType##path = %{public}s\n", path.c_str());
|
||||
std::map<std::string, OpKeyUriType>::iterator it = opKeyUriMap.find(path);
|
||||
if (it != opKeyUriMap.end()) {
|
||||
std::map<std::string, OpKeyUriType>::iterator it = opKeyUriMap_.find(path);
|
||||
if (it != opKeyUriMap_.end()) {
|
||||
opKeyUriType = it->second;
|
||||
DATA_STORAGE_LOGI("OpKeyAbility::ParseUriType##opKeyUriType = %{public}d\n",
|
||||
opKeyUriType);
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Telephony {
|
||||
const int VERSION = 1;
|
||||
RdbOpKeyHelper::RdbOpKeyHelper()
|
||||
{
|
||||
}
|
||||
@@ -80,9 +81,8 @@ void RdbOpKeyHelper::CreateOpKeyInfoIndexStr(std::string &createIndexStr)
|
||||
|
||||
int RdbOpKeyHelper::EndTransactionAction()
|
||||
{
|
||||
int result = MarkAsCommit();
|
||||
result = EndTransaction();
|
||||
return result;
|
||||
MarkAsCommit();
|
||||
return EndTransaction();
|
||||
}
|
||||
|
||||
int RdbOpKeyHelper::CommitTransactionAction()
|
||||
|
||||
@@ -51,7 +51,7 @@ std::shared_ptr<AppExecFwk::DataAbilityHelper> CreateDataAHelper(
|
||||
return nullptr;
|
||||
}
|
||||
auto remoteObj = saManager->GetSystemAbility(systemAbilityId);
|
||||
while (remoteObj == nullptr) {
|
||||
if (remoteObj == nullptr) {
|
||||
DATA_STORAGE_LOGE("DataSimRdbHelper GetSystemAbility Service Failed.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user