Files
telephony_data_storage/README.md
T
2021-12-17 16:00:43 +08:00

9.4 KiB
Executable File

Data Storage

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

Directory Structure

/base/telephony/data_storage     # Data storage
├─ BUILD.gn                         # Build script (gn)
├─ README.md                        # Readme
├─ common                           # Public and common files
│  ├─ include                       
│  └─ src                           
├─ pdp_profile                      # Network carrier 
│  ├─ include                       
│  └─ src                           
├─ sim                              # SIM card 
│  ├─ include                       
│  └─ src                           
├─ sms_mms                          # SMS/MMS
│  ├─ include                      
│  └─ src                           
├─ ohos.build                       # Build code
└─ test                             # Test code

Constraints

  • Programming language: C++

  • Software constraints: This module must work with the Utils and Application Framework subsystems.

  • Hardware constraints: none

  • Use case: When a user needs to edit the persistent data stored in Telephony subsystem modules, such as the SIM card and SMS/MMS modules, your application can call the Insert, Delete, Update, and Query APIs provided by the DataAbilityHelper as demanded.

    You need to declare the corresponding permission for access to the specified URI.

Usage

Available APIs

Table 1 APIs provided by DataAbilityHelper

API Description
int Insert(const Uri &uri, const NativeRdb::ValuesBucket &value) Inserts data.      
int Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates) Deletes data.      
int Update( const Uri &uri, const NativeRdb::ValuesBucket &value, const NativeRdb::DataAbilityPredicates &predicates) Updates data.      
std::shared_ptr<NativeRdb::AbsSharedResultSet> Query( const Uri &uri, const std::vector<std::string> &columns, const NativeRdb::DataAbilityPredicates &predicates) Queries data.      

Table 2 Required permissions

Module Required Permission
SMS/MMS module com.ohos.smsmmsability.DataAbilityShellProvider.PROVIDER
SIM card module com.ohos.simability.DataAbilityShellProvider.PROVIDER
Network carrier module com.ohos.pdpprofileability.DataAbilityShellProvider.PROVIDER

Usage Guidelines

Parameters of the Insert API

Table 3 Parameters of the Insert API

Parameter Description
uri Resource path.
value Data set. This field corresponds to the table structure field on which the current operation is performed.

Parameters of the Delete API

Table 4 Parameters of the Delete API

Parameter Description
uri Resource path.
value Data set. This field corresponds to the table structure field on which the current operation is performed.
predicates Conditions for data deletion.

Parameters of the Update API

Table 5 Parameters of the Update API

Parameter Description
uri Resource path.
predicates Conditions for data updating.

Parameters of the Query API

Table 6 Parameters of the Query API

Parameter Description
uri Resource path.
columns Fields in the query result.
predicates Query criteria.

Sample Code

The following provides the procedure and sample code for you to query, insert, delete, or update SMS/MMS data:

  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.

    Sample code for creating a DataAbilityHelper instance:

    std::shared_ptr<AppExecFwk::DataAbilityHelper> CreateDataAHelper(int32_t systemAbilityId)
    {
        // Obtain a SystemAbilityManager instance through SystemAbilityManagerClient.
        auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
        if (saManager == nullptr) {
            DATA_STORAGE_LOGE("DataSimRdbHelper Get system ability mgr failed.");
            return nullptr;
        }
        // Obtain an IRemoteObject.
        auto remoteObj = saManager->GetSystemAbility(systemAbilityId);
        while (remoteObj == nullptr) {
            DATA_STORAGE_LOGE("DataSimRdbHelper GetSystemAbility Service Failed.");
            return nullptr;
        }
        // Create a DataAbilityHelper instance.
        return AppExecFwk::DataAbilityHelper::Creator(remoteObj);
    }
    

    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
        std::vector<std::string> colume;
        // Phone number of the message sender
        colume.push_back("sender_number");
        // Message title
        colume.push_back("msg_title");
        // Message content
        colume.push_back("msg_content");
        // Query predicates
        NativeRdb::DataAbilityPredicates predicates;
        // Call the DataAbilityHelper::Query API to query data.
        return helper->Query(uri, colume, predicates);
    }
    

    Sample code for inserting SMS/MMS messages:

    int SmsInsert(std::shared_ptr<AppExecFwk::DataAbilityHelper> helper)
    {
        Uri uri("dataability:///com.ohos.smsmmsability/sms_mms/sms_mms_info");
        NativeRdb::ValuesBucket value;
        // Phone number of the message recipient
        value.PutString(SmsMmsInfo::RECEIVER_NUMBER, "138XXXXXXXX");
        // Message content
        value.PutString(SmsMmsInfo::MSG_CONTENT, "ceshi");
        value.PutInt(SmsMmsInfo::GROUP_ID, 1);
        return helper->Insert(uri, value);
    }
    

    Sample code for deleting SMS/MMS messages:

     int SmsDelete(std::shared_ptr<AppExecFwk::DataAbilityHelper> helper)
     {
         Uri uri("dataability:///com.ohos.smsmmsability/sms_mms/sms_mms_info");
         NativeRdb::DataAbilityPredicates predicates;
         // Delete the message whose MSG_ID is 1.
         predicates.EqualTo(SmsMmsInfo::MSG_ID, "1");
         return helper->Delete(uri, predicates);
     }
    

    Sample code for updating SMS/MMS messages:

    int SmsUpdate(std::shared_ptr<AppExecFwk::DataAbilityHelper> helper)
    {
        Uri uri("dataability:///com.ohos.smsmmsability/sms_mms/sms_mms_info");
        NativeRdb::ValuesBucket values;
        // Message content
        values.PutString(SmsMmsInfo::MSG_CONTENT, "hi ohos");
        NativeRdb::DataAbilityPredicates predicates;
        // Message ID
        predicates.EqualTo(SmsMmsInfo::MSG_ID, "1");
        return helper->Update(uri, values, predicates);
    }
    

Repositories Involved

Telephony Subsystem

telephony_data_storage

telephony_core_service

telephony_sms_mms

telephony_cellular_call

telephony_call_manager