1/*
2 * Copyright (c) 2023 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 UTD_CLIENT_H
17#define UTD_CLIENT_H
18
19#include <shared_mutex>
20#include <string>
21#include <vector>
22#include <map>
23#include "utd_common.h"
24#include "preset_type_descriptors.h"
25#include "preset_type_descriptors.h"
26#include "flexible_type.h"
27#include "type_descriptor.h"
28#include "error_code.h"
29#include "visibility.h"
30namespace OHOS {
31namespace UDMF {
32class TypeDescriptor;
33class UtdChangeSubscriber;
34class API_EXPORT UtdClient {
35public:
36    static UtdClient &GetInstance();
37    Status GetTypeDescriptor(const std::string &typeId, std::shared_ptr<TypeDescriptor> &descriptor);
38    Status GetUniformDataTypeByFilenameExtension(const std::string &fileExtension, std::string &typeId,
39                                                 std::string belongsTo = DEFAULT_TYPE_ID);
40    Status GetUniformDataTypesByFilenameExtension(const std::string &fileExtension,
41                    std::vector<std::string> &typeIds, const std::string &belongsTo = DEFAULT_TYPE_ID);
42    Status GetUniformDataTypeByMIMEType(const std::string &mimeType, std::string &typeId,
43                                        std::string belongsTo = DEFAULT_TYPE_ID);
44    Status GetUniformDataTypesByMIMEType(const std::string &mimeType, std::vector<std::string> &typeIds,
45                                        const std::string &belongsTo = DEFAULT_TYPE_ID);
46    Status IsUtd(std::string typeId, bool &result);
47    void InstallCustomUtds(const std::string &bundleName, const std::string &jsonStr, int32_t user);
48    void UninstallCustomUtds(const std::string &bundleName, int32_t user);
49
50private:
51    UtdClient();
52    ~UtdClient();
53    UtdClient(const UtdClient &obj) = delete;
54    UtdClient &operator=(const UtdClient &obj) = delete;
55    bool Init();
56    bool IsHapTokenType();
57    Status GetCurrentActiveUserId(int32_t& userId);
58    bool IsValidFileExtension(const std::string &fileExtension);
59    bool IsValidMimeType(const std::string &mimeType);
60    Status GetFlexibleTypeDescriptor(const std::string &typeId, std::shared_ptr<TypeDescriptor> &descriptor);
61    std::string GetTypeIdFromCfg(const std::string &mimeType);
62    std::vector<std::string> GetTypeIdsFromCfg(const std::string &mimeType);
63    void UpdateGraph(const std::vector<TypeDescriptorCfg> &customTyepCfgs);
64
65    std::vector<TypeDescriptorCfg> descriptorCfgs_;
66    std::shared_mutex utdMutex_;
67};
68} // namespace UDMF
69} // namespace OHOS
70#endif // UTD_CLIENT_H