diff --git a/README.md b/README.md
index 236248d..aeeb71a 100644
--- a/README.md
+++ b/README.md
@@ -13,38 +13,38 @@
- [Parameters of the Update API](#section1099113151207)
- [Parameters of the Query API](#section1096113151208)
- [Sample Code](#section1558565082915)
-
+
- [Repositories Involved](#section206mcpsimp)
## Introduction
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
+**Figure 1** Architecture of the data storage module

-## Directory Structure
+## Directory Structure
```
/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 SmsSelect(std::shared_ptr helper)
- {
+ {
// Resource path
Uri uri("dataability:///com.ohos.smsmmsability/sms_mms/sms_mms_info");
// Fields in the query result
diff --git a/common/include/parser_util.h b/common/include/parser_util.h
index 60721bd..32a2fc0 100755
--- a/common/include/parser_util.h
+++ b/common/include/parser_util.h
@@ -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
diff --git a/common/include/time_util.h b/common/include/time_util.h
index 98b625f..a661a86 100755
--- a/common/include/time_util.h
+++ b/common/include/time_util.h
@@ -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;
}
diff --git a/common/src/parser_util.cpp b/common/src/parser_util.cpp
index 1be918a..bdd4c7e 100755
--- a/common/src/parser_util.cpp
+++ b/common/src/parser_util.cpp
@@ -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 &vec)
{
char *content = nullptr;
@@ -50,6 +78,7 @@ int ParserUtil::ParserPdpProfileJson(std::vector &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 &vec)
return static_cast(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 &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 &vec, const char *path)
return static_cast(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(LoadProFileErrorType::LOAD_FILE_ERROR);
}
- len = static_cast(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(LoadProFileErrorType::LOAD_FILE_ERROR);
}
- if (len == 0 || len > MAX_BYTE_LEN) {
+ if (len == 0 || len > static_cast(MAX_BYTE_LEN)) {
DATA_STORAGE_LOGE("ParserUtil::LoaderJsonFile len <= 0 or len > LONG_MAX!");
CloseFile(f);
return static_cast(LoadProFileErrorType::LOAD_FILE_ERROR);
diff --git a/opkey/include/opkey_ability.h b/opkey/include/opkey_ability.h
index f97e09a..ee1a255 100644
--- a/opkey/include/opkey_ability.h
+++ b/opkey/include/opkey_ability.h
@@ -84,10 +84,9 @@ private:
private:
RdbOpKeyHelper helper_;
std::mutex lock_;
- std::map opKeyUriMap;
- bool initDatabaseDir = false;
- bool initRdbStore = false;
- int CHANGED_ROWS = 0;
+ std::map opKeyUriMap_;
+ bool initDatabaseDir_ = false;
+ bool initRdbStore_ = false;
};
} // namespace Telephony
} // namespace OHOS
diff --git a/opkey/include/rdb_opkey_helper.h b/opkey/include/rdb_opkey_helper.h
index 8b118d9..f585535 100644
--- a/opkey/include/rdb_opkey_helper.h
+++ b/opkey/include/rdb_opkey_helper.h
@@ -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
diff --git a/opkey/src/opkey_ability.cpp b/opkey/src/opkey_ability.cpp
index 2f81734..d052106 100644
--- a/opkey/src/opkey_ability.cpp
+++ b/opkey/src/opkey_ability.cpp
@@ -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::iterator it = opKeyUriMap.find(path);
- if (it != opKeyUriMap.end()) {
+ std::map::iterator it = opKeyUriMap_.find(path);
+ if (it != opKeyUriMap_.end()) {
opKeyUriType = it->second;
DATA_STORAGE_LOGI("OpKeyAbility::ParseUriType##opKeyUriType = %{public}d\n",
opKeyUriType);
diff --git a/opkey/src/rdb_opkey_helper.cpp b/opkey/src/rdb_opkey_helper.cpp
index 75c9cfb..066e788 100644
--- a/opkey/src/rdb_opkey_helper.cpp
+++ b/opkey/src/rdb_opkey_helper.cpp
@@ -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()
diff --git a/test/unittest/data_test/data_storage_test.cpp b/test/unittest/data_test/data_storage_test.cpp
index e7deccb..c4d3342 100755
--- a/test/unittest/data_test/data_storage_test.cpp
+++ b/test/unittest/data_test/data_storage_test.cpp
@@ -51,7 +51,7 @@ std::shared_ptr CreateDataAHelper(
return nullptr;
}
auto remoteObj = saManager->GetSystemAbility(systemAbilityId);
- while (remoteObj == nullptr) {
+ if (remoteObj == nullptr) {
DATA_STORAGE_LOGE("DataSimRdbHelper GetSystemAbility Service Failed.");
return nullptr;
}