1/*
2 * Copyright (c) 2021-2022 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#ifndef DATA_STORAGE_SIM_ABILITY_H
17#define DATA_STORAGE_SIM_ABILITY_H
18
19#include <functional>
20
21#include "__mutex_base"
22#include "ability.h"
23#include "ability_lifecycle.h"
24#include "abs_shared_result_set.h"
25#include "datashare_ext_ability.h"
26#include "datashare_ext_ability_context.h"
27#include "datashare_values_bucket.h"
28#include "iosfwd"
29#include "map"
30#include "memory"
31#include "rdb_predicates.h"
32#include "rdb_sim_helper.h"
33#include "string"
34#include "vector"
35#include "want.h"
36
37namespace OHOS {
38namespace NativeRdb {
39class AbsRdbPredicates;
40class ResultSet;
41class DataAbilityPredicates;
42class ValuesBucket;
43class ValueObject;
44}
45namespace Telephony {
46enum class SimUriType {
47    UNKNOW, SIM_INFO, SET_CARD
48};
49class SimAbility : public DataShare::DataShareExtAbility {
50public:
51    SimAbility();
52    virtual ~SimAbility() override;
53    static SimAbility* Create();
54    void DoInit();
55    sptr<IRemoteObject> OnConnect(const AAFwk::Want &want) override;
56    virtual void OnStart(const AppExecFwk::Want &want) override;
57    virtual int Insert(const Uri &uri, const DataShare::DataShareValuesBucket &value) override;
58    virtual std::shared_ptr<DataShare::DataShareResultSet> Query(const Uri &uri,
59        const DataShare::DataSharePredicates &predicates, std::vector<std::string> &columns,
60        DataShare::DatashareBusinessError &businessError) override;
61    virtual int Update(const Uri &uri, const DataShare::DataSharePredicates &predicates,
62        const DataShare::DataShareValuesBucket &value) override;
63    virtual int Delete(const Uri &uri, const DataShare::DataSharePredicates &predicates) override;
64    virtual std::string GetType(const Uri &uri) override;
65    virtual int OpenFile(const Uri &uri, const std::string &mode) override;
66
67private:
68    /**
69     * Parse Uri Type
70     *
71     * @param uri Resource address
72     * @return return SimUriType
73     */
74    SimUriType ParseUriType(Uri &uri);
75
76    /**
77     * Convert DataSharePredicates to RdbPredicates
78     *
79     * @param tableName table name of the predicates
80     * @param predicates DataSharePredicates
81     */
82    OHOS::NativeRdb::RdbPredicates ConvertPredicates(
83        const std::string &tableName, const DataShare::DataSharePredicates &predicates);
84
85    /**
86    * Set card type
87    *
88    * @param value Table field data
89    * @return Is it successful
90    */
91
92    int SetCard(const DataShare::DataShareValuesBucket &value);
93
94    /**
95    * Check whether the initialization succeeds
96    *
97    * @return true : succeed ,false : failed
98    */
99    bool IsInitOk();
100
101private:
102    RdbSimHelper helper_;
103    std::mutex lock_;
104    bool initDatabaseDir = false;
105    bool initRdbStore = false;
106};
107} // namespace Telephony
108} // namespace OHOS
109#endif // DATA_STORAGE_SIM_ABILITY_H
110