mirror of
https://gitee.com/openharmony/global_resource_management
synced 2024-11-23 16:09:52 +00:00
修改智能指针
Signed-off-by: fangyunzhong <fangyunzhong2@huawei.com>
This commit is contained in:
parent
2ba90b72f3
commit
24f133bd8f
@ -37,7 +37,7 @@ public:
|
||||
* @param resConfig resource config
|
||||
* @param isSystem system flag, default value is false
|
||||
*/
|
||||
HapManager(ResConfigImpl *resConfig, bool isSystem = false);
|
||||
HapManager(std::shared_ptr<ResConfigImpl> resConfig, bool isSystem = false);
|
||||
|
||||
/**
|
||||
* The destructor of HapManager
|
||||
@ -108,7 +108,7 @@ public:
|
||||
* @param id the resource id
|
||||
* @return the resources related to resource id
|
||||
*/
|
||||
const IdItem *FindResourceById(uint32_t id);
|
||||
const std::shared_ptr<IdItem> FindResourceById(uint32_t id);
|
||||
|
||||
/**
|
||||
* Find resource by resource name
|
||||
@ -116,7 +116,7 @@ public:
|
||||
* @param resType the resource type
|
||||
* @return the resources related to resource name
|
||||
*/
|
||||
const IdItem *FindResourceByName(const char *name, const ResType resType);
|
||||
const std::shared_ptr<IdItem> FindResourceByName(const char *name, const ResType resType);
|
||||
|
||||
/**
|
||||
* Find best resource path by resource id
|
||||
@ -124,7 +124,8 @@ public:
|
||||
* @param density the input screen density
|
||||
* @return the best resource path
|
||||
*/
|
||||
const HapResource::ValueUnderQualifierDir *FindQualifierValueById(uint32_t id, uint32_t density = 0);
|
||||
const std::shared_ptr<HapResource::ValueUnderQualifierDir> FindQualifierValueById(uint32_t id,
|
||||
uint32_t density = 0);
|
||||
|
||||
/**
|
||||
* Find best resource path by resource name
|
||||
@ -133,8 +134,8 @@ public:
|
||||
* @param density the input screen density
|
||||
* @return the best resource path
|
||||
*/
|
||||
const HapResource::ValueUnderQualifierDir *FindQualifierValueByName(const char *name, const ResType resType,
|
||||
uint32_t density = 0);
|
||||
const std::shared_ptr<HapResource::ValueUnderQualifierDir> FindQualifierValueByName(const char *name,
|
||||
const ResType resType, uint32_t density = 0);
|
||||
|
||||
/**
|
||||
* Find the raw file path
|
||||
@ -163,7 +164,7 @@ public:
|
||||
* @param outValue the media data
|
||||
* @return SUCCESS if get the media data success, else NOT_FOUND
|
||||
*/
|
||||
RState GetMediaData(const HapResource::ValueUnderQualifierDir *qd, size_t& len,
|
||||
RState GetMediaData(const std::shared_ptr<HapResource::ValueUnderQualifierDir> qd, size_t& len,
|
||||
std::unique_ptr<uint8_t[]> &outValue);
|
||||
|
||||
/**
|
||||
@ -172,7 +173,7 @@ public:
|
||||
* @param outValue the mediabase64 data
|
||||
* @return SUCCESS if get the mediabase64 data success, else NOT_FOUND
|
||||
*/
|
||||
RState GetMediaBase64Data(const HapResource::ValueUnderQualifierDir *qd, std::string &outValue);
|
||||
RState GetMediaBase64Data(const std::shared_ptr<HapResource::ValueUnderQualifierDir> qd, std::string &outValue);
|
||||
|
||||
/**
|
||||
* Get the Profile data
|
||||
@ -181,7 +182,7 @@ public:
|
||||
* @param outValue the profile data
|
||||
* @return SUCCESS if get the profile data success, else NOT_FOUND
|
||||
*/
|
||||
RState GetProfileData(const HapResource::ValueUnderQualifierDir *qd, size_t &len,
|
||||
RState GetProfileData(const std::shared_ptr<HapResource::ValueUnderQualifierDir> qd, size_t &len,
|
||||
std::unique_ptr<uint8_t[]> &outValue);
|
||||
|
||||
/**
|
||||
@ -238,7 +239,7 @@ public:
|
||||
* @param outValue the resource path write to
|
||||
* @return SUCCESS if resource exist, else not found
|
||||
*/
|
||||
RState GetFilePath(const HapResource::ValueUnderQualifierDir *qd, const ResType resType,
|
||||
RState GetFilePath(const std::shared_ptr<HapResource::ValueUnderQualifierDir> qd, const ResType resType,
|
||||
std::string &outValue);
|
||||
|
||||
/**
|
||||
@ -248,7 +249,7 @@ public:
|
||||
* @param outValue the media data write to
|
||||
* @return SUCCESS if resource exist, else not found
|
||||
*/
|
||||
RState GetMediaDataFromHap(const HapResource::ValueUnderQualifierDir *qd, size_t &len,
|
||||
RState GetMediaDataFromHap(const std::shared_ptr<HapResource::ValueUnderQualifierDir> qd, size_t &len,
|
||||
std::unique_ptr<uint8_t[]> &outValue);
|
||||
|
||||
/**
|
||||
@ -258,7 +259,7 @@ public:
|
||||
* @param outValue the media data write to
|
||||
* @return SUCCESS if resource exist, else not found
|
||||
*/
|
||||
RState GetMediaDataFromIndex(const HapResource::ValueUnderQualifierDir *qd, size_t &len,
|
||||
RState GetMediaDataFromIndex(const std::shared_ptr<HapResource::ValueUnderQualifierDir> qd, size_t &len,
|
||||
std::unique_ptr<uint8_t[]> &outValue);
|
||||
|
||||
/**
|
||||
@ -267,7 +268,8 @@ public:
|
||||
* @param outValue the mediabase64 data write to
|
||||
* @return SUCCESS if resource exist, else not found
|
||||
*/
|
||||
RState GetMediaBase64DataFromHap(const HapResource::ValueUnderQualifierDir *qd, std::string &outValue);
|
||||
RState GetMediaBase64DataFromHap(const std::shared_ptr<HapResource::ValueUnderQualifierDir> qd,
|
||||
std::string &outValue);
|
||||
|
||||
/**
|
||||
* Get the raw file list
|
||||
@ -275,7 +277,8 @@ public:
|
||||
* @param outValue the mediabase64 data write to
|
||||
* @return SUCCESS if resource exist, else not found
|
||||
*/
|
||||
RState GetMediaBase64DataFromIndex(const HapResource::ValueUnderQualifierDir *qd, std::string &outValue);
|
||||
RState GetMediaBase64DataFromIndex(const std::shared_ptr<HapResource::ValueUnderQualifierDir> qd,
|
||||
std::string &outValue);
|
||||
|
||||
/**
|
||||
* Get the raw file list
|
||||
@ -297,14 +300,14 @@ public:
|
||||
*
|
||||
* @return HapResource vector of manager
|
||||
*/
|
||||
std::vector<HapResource *> GetHapResource();
|
||||
std::vector<std::shared_ptr<HapResource>> GetHapResource();
|
||||
|
||||
/**
|
||||
* Add system resourc to app resource vector
|
||||
*
|
||||
* @param systemHapManager system manager
|
||||
*/
|
||||
void AddSystemResource(const HapManager *systemHapManager);
|
||||
void AddSystemResource(const std::shared_ptr<HapManager> &systemHapManager);
|
||||
|
||||
/**
|
||||
* Get the resource limit keys value which every binary bit corresponds to existing limit key {@link KeyType}
|
||||
@ -346,12 +349,13 @@ private:
|
||||
|
||||
void GetResConfigImpl(ResConfigImpl &resConfig);
|
||||
|
||||
std::vector<const HapResource::IdValues *> GetResourceList(uint32_t ident) const;
|
||||
std::vector<std::shared_ptr<HapResource::IdValues>> GetResourceList(uint32_t ident) const;
|
||||
|
||||
std::vector<const HapResource::IdValues *> GetResourceListByName(const char *name, const ResType resType) const;
|
||||
std::vector<std::shared_ptr<HapResource::IdValues>> GetResourceListByName(const char *name,
|
||||
const ResType resType) const;
|
||||
|
||||
const HapResource::ValueUnderQualifierDir *GetBestMatchResource(std::vector<const HapResource::IdValues *>
|
||||
candidates, uint32_t density);
|
||||
const std::shared_ptr<HapResource::ValueUnderQualifierDir> GetBestMatchResource(
|
||||
std::vector<std::shared_ptr<HapResource::IdValues>> candidates, uint32_t density);
|
||||
|
||||
bool AddResourcePath(const char *path);
|
||||
|
||||
@ -363,10 +367,10 @@ private:
|
||||
static bool icuInitialized;
|
||||
|
||||
// app res config
|
||||
ResConfigImpl *resConfig_;
|
||||
std::shared_ptr<ResConfigImpl> resConfig_;
|
||||
|
||||
// set of hap Resources
|
||||
std::vector<HapResource *> hapResources_;
|
||||
std::vector<std::shared_ptr<HapResource>> hapResources_;
|
||||
|
||||
// set of loaded hap path
|
||||
std::unordered_map<std::string, std::vector<std::string>> loadedHapPaths_;
|
||||
|
@ -137,21 +137,22 @@ public:
|
||||
* @return OK if the resource hex parse success, else SYS_ERROR
|
||||
*/
|
||||
static int32_t ParseResHex(const char *buffer, const size_t bufLen, ResDesc &resDesc,
|
||||
const ResConfigImpl *defaultConfig = nullptr);
|
||||
const std::shared_ptr<ResConfigImpl> defaultConfig = nullptr);
|
||||
|
||||
/**
|
||||
* Create resource config from KeyParams
|
||||
* @param keyParams the keyParams contain type and value
|
||||
* @return the resource config related to the keyParams
|
||||
*/
|
||||
static ResConfigImpl *CreateResConfigFromKeyParams(const std::vector<KeyParam *> &keyParams);
|
||||
static std::shared_ptr<ResConfigImpl> CreateResConfigFromKeyParams(
|
||||
const std::vector<std::shared_ptr<KeyParam>> &keyParams);
|
||||
|
||||
/**
|
||||
* To resource folder path
|
||||
* @param keyParams the keyParams contain type and value
|
||||
* @return the resources folder path
|
||||
*/
|
||||
static std::string ToFolderPath(const std::vector<KeyParam *> &keyParams);
|
||||
static std::string ToFolderPath(const std::vector<std::shared_ptr<KeyParam>> &keyParams);
|
||||
|
||||
/**
|
||||
* Get screen density
|
||||
@ -224,7 +225,7 @@ private:
|
||||
};
|
||||
|
||||
static std::string BuildFolderPath(Determiner *determiner);
|
||||
static ResConfigImpl *BuildResConfig(ResConfigKey *configKey);
|
||||
static std::shared_ptr<ResConfigImpl> BuildResConfig(ResConfigKey *configKey);
|
||||
};
|
||||
} // namespace Resource
|
||||
} // namespace Global
|
||||
|
@ -44,8 +44,8 @@ public:
|
||||
* replace non-overlay resource.
|
||||
* @return pResource if create pResource success, else nullptr
|
||||
*/
|
||||
static const HapResource *LoadFromIndex(const char *path, const ResConfigImpl *defaultConfig,
|
||||
bool isSystem = false, bool isOverlay = false);
|
||||
static const std::shared_ptr<HapResource> LoadFromIndex(const char *path,
|
||||
const std::shared_ptr<ResConfigImpl> defaultConfig, bool isSystem = false, bool isOverlay = false);
|
||||
|
||||
/**
|
||||
* Creates an HapResource.
|
||||
@ -59,8 +59,8 @@ public:
|
||||
* replace non-overlay resource.
|
||||
* @return pResource if create pResource success, else nullptr
|
||||
*/
|
||||
static const HapResource *LoadFromHap(const char *path, const ResConfigImpl *defaultConfig,
|
||||
bool isSystem = false, bool isOverlay = false);
|
||||
static const std::shared_ptr<HapResource> LoadFromHap(const char *path,
|
||||
const std::shared_ptr<ResConfigImpl> defaultConfig, bool isSystem = false, bool isOverlay = false);
|
||||
|
||||
/**
|
||||
* Creates an HapResource.
|
||||
@ -74,8 +74,8 @@ public:
|
||||
* replace non-overlay resource.
|
||||
* @return pResource if create pResource success, else nullptr
|
||||
*/
|
||||
static const HapResource *Load(const char* path, const ResConfigImpl* defaultConfig,
|
||||
bool isSystem = false, bool isOverlay = false);
|
||||
static const std::shared_ptr<HapResource> Load(const char* path,
|
||||
const std::shared_ptr<ResConfigImpl> defaultConfig, bool isSystem = false, bool isOverlay = false);
|
||||
|
||||
/**
|
||||
* Load overlay resources
|
||||
@ -85,8 +85,9 @@ public:
|
||||
* @param isSystem judge the overlay is system or not
|
||||
* @return the map of overlay resource path and resource info if success, else null
|
||||
*/
|
||||
static const std::unordered_map<std::string, HapResource *> LoadOverlays(const std::string &path,
|
||||
const std::vector<std::string> &overlayPath, const ResConfigImpl *defaultConfig, bool isSystem = false);
|
||||
static const std::unordered_map<std::string, std::shared_ptr<HapResource>> LoadOverlays(
|
||||
const std::string &path, const std::vector<std::string> &overlayPath,
|
||||
const std::shared_ptr<ResConfigImpl> defaultConfig, bool isSystem = false);
|
||||
|
||||
/**
|
||||
* The destructor of HapResource
|
||||
@ -139,7 +140,7 @@ public:
|
||||
*/
|
||||
class ValueUnderQualifierDir {
|
||||
public:
|
||||
inline const std::vector<KeyParam *> GetKeyParams() const
|
||||
inline const std::vector<std::shared_ptr<KeyParam>> GetKeyParams() const
|
||||
{
|
||||
return keyParams_;
|
||||
}
|
||||
@ -149,12 +150,12 @@ public:
|
||||
return folder_;
|
||||
}
|
||||
|
||||
inline const IdItem *GetIdItem() const
|
||||
inline const std::shared_ptr<IdItem> GetIdItem() const
|
||||
{
|
||||
return idItem_;
|
||||
}
|
||||
|
||||
inline const ResConfigImpl *GetResConfig() const
|
||||
inline const std::shared_ptr<ResConfigImpl> GetResConfig() const
|
||||
{
|
||||
return resConfig_;
|
||||
}
|
||||
@ -188,7 +189,7 @@ public:
|
||||
* @param isOverlay the overlay flag, default value is false.
|
||||
* @param isSystemResource the system flag, default value is false.
|
||||
*/
|
||||
ValueUnderQualifierDir(const ResKey *resKey, IdItem *idItem,
|
||||
ValueUnderQualifierDir(const std::shared_ptr<ResKey> resKey, std::shared_ptr<IdItem> idItem,
|
||||
const std::pair<std::string, std::string> &resPath, bool isOverlay = false, bool isSystemResource = false);
|
||||
|
||||
~ValueUnderQualifierDir();
|
||||
@ -198,14 +199,14 @@ public:
|
||||
/*
|
||||
* keyParams_, folder_, resConfig_ are 3 different ways to describe Qualifiers Sub-directory
|
||||
*/
|
||||
std::vector<KeyParam *> keyParams_;
|
||||
std::vector<std::shared_ptr<KeyParam>> keyParams_;
|
||||
// the qualifier path name
|
||||
std::string folder_;
|
||||
// this resConfig_ point to the ResKey resConfig_ and resConfig_ will be unified free in ResKey destruct.
|
||||
const ResConfigImpl *resConfig_;
|
||||
std::shared_ptr<ResConfigImpl> resConfig_;
|
||||
|
||||
// the value
|
||||
IdItem *idItem_;
|
||||
std::shared_ptr<IdItem> idItem_;
|
||||
|
||||
friend class HapResource;
|
||||
|
||||
@ -223,12 +224,12 @@ public:
|
||||
*/
|
||||
class IdValues {
|
||||
public:
|
||||
inline void AddLimitPath(ValueUnderQualifierDir *vuqd)
|
||||
inline void AddLimitPath(std::shared_ptr<ValueUnderQualifierDir> vuqd)
|
||||
{
|
||||
limitPaths_.push_back(vuqd);
|
||||
}
|
||||
|
||||
inline const std::vector<ValueUnderQualifierDir *> &GetLimitPathsConst() const
|
||||
inline const std::vector<std::shared_ptr<ValueUnderQualifierDir>> &GetLimitPathsConst() const
|
||||
{
|
||||
return limitPaths_;
|
||||
}
|
||||
@ -237,7 +238,7 @@ public:
|
||||
|
||||
private:
|
||||
// the folder desc
|
||||
std::vector<ValueUnderQualifierDir *> limitPaths_;
|
||||
std::vector<std::shared_ptr<ValueUnderQualifierDir>> limitPaths_;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -245,7 +246,7 @@ public:
|
||||
* @param id the resource id
|
||||
* @return the resource value related to id
|
||||
*/
|
||||
const IdValues *GetIdValues(const uint32_t id) const;
|
||||
const std::shared_ptr<IdValues> GetIdValues(const uint32_t id) const;
|
||||
|
||||
/**
|
||||
* Get the resource value by resource name
|
||||
@ -253,7 +254,7 @@ public:
|
||||
* @param resType the resource type
|
||||
* @return the resource value related to resource name
|
||||
*/
|
||||
const IdValues *GetIdValuesByName(const std::string name, const ResType resType) const;
|
||||
const std::shared_ptr<IdValues> GetIdValuesByName(const std::string name, const ResType resType) const;
|
||||
|
||||
/**
|
||||
* Get the resource id by resource name
|
||||
@ -287,16 +288,16 @@ public:
|
||||
*/
|
||||
void GetLocales(std::set<std::string> &outValue, bool includeSystem);
|
||||
|
||||
private:
|
||||
HapResource(const std::string path, time_t lastModTime, ResDesc *resDes,
|
||||
HapResource(const std::string path, time_t lastModTime, std::shared_ptr<ResDesc> resDes,
|
||||
bool isSystem = false, bool isOverlay = false);
|
||||
private:
|
||||
|
||||
void UpdateOverlayInfo(std::unordered_map<std::string, std::unordered_map<ResType, uint32_t>> &nameTypeId);
|
||||
|
||||
uint32_t GetLimitPathsKeys(const std::vector<ValueUnderQualifierDir *> &limitPaths,
|
||||
uint32_t GetLimitPathsKeys(const std::vector<std::shared_ptr<ValueUnderQualifierDir>> &limitPaths,
|
||||
std::vector<bool> &keyTypes) const;
|
||||
|
||||
void GetKeyParamsLocales(const std::vector<KeyParam *> keyParams, std::set<std::string> &outValue);
|
||||
void GetKeyParamsLocales(const std::vector<std::shared_ptr<KeyParam>> keyParams, std::set<std::string> &outValue);
|
||||
|
||||
// must call Init() after constructor
|
||||
bool Init();
|
||||
@ -314,13 +315,13 @@ private:
|
||||
time_t lastModTime_;
|
||||
|
||||
// resource information stored in resDesc_
|
||||
ResDesc *resDesc_;
|
||||
std::shared_ptr<ResDesc> resDesc_;
|
||||
|
||||
std::map<uint32_t, IdValues *> idValuesMap_;
|
||||
std::map<uint32_t, std::shared_ptr<IdValues>> idValuesMap_;
|
||||
|
||||
// the key is name, each restype holds one map
|
||||
// name may conflict in same restype !
|
||||
std::vector<std::map<std::string, IdValues *> *> idValuesNameMap_;
|
||||
std::vector<std::map<std::string, std::shared_ptr<IdValues>> *> idValuesNameMap_;
|
||||
|
||||
// judge the hap resource is system or not.
|
||||
bool isSystem_;
|
||||
|
@ -37,7 +37,8 @@ public:
|
||||
* @param density the input screen density
|
||||
* @return true if this resConfig more match request resConfig than other resConfig, else false
|
||||
*/
|
||||
bool IsMoreSuitable(const ResConfigImpl *other, const ResConfigImpl *request, uint32_t density = 0) const;
|
||||
bool IsMoreSuitable(const std::shared_ptr<ResConfigImpl> other, const std::shared_ptr<ResConfigImpl> request,
|
||||
uint32_t density = 0) const;
|
||||
|
||||
/**
|
||||
* Set locale information
|
||||
@ -116,7 +117,7 @@ public:
|
||||
* @param other the other resConfig
|
||||
* @return true if this resConfig match other resConfig, else false
|
||||
*/
|
||||
bool Match(const ResConfigImpl *other) const;
|
||||
bool Match(const std::shared_ptr<ResConfigImpl> other) const;
|
||||
|
||||
/**
|
||||
* Copy other resConfig to this resConfig
|
||||
@ -157,7 +158,7 @@ public:
|
||||
virtual ~ResConfigImpl();
|
||||
|
||||
private:
|
||||
bool IsMoreSpecificThan(const ResConfigImpl *other, uint32_t density = 0) const;
|
||||
bool IsMoreSpecificThan(const std::shared_ptr<ResConfigImpl> other, uint32_t density = 0) const;
|
||||
|
||||
bool CopyLocale(ResConfig &other);
|
||||
|
||||
|
@ -124,7 +124,7 @@ public:
|
||||
|
||||
uint32_t id_;
|
||||
uint32_t offset_;
|
||||
IdItem *idItem_;
|
||||
std::shared_ptr<IdItem> idItem_;
|
||||
};
|
||||
|
||||
class ResId {
|
||||
@ -137,7 +137,7 @@ public:
|
||||
|
||||
char tag_[4];
|
||||
uint32_t count_; // ID count
|
||||
std::vector<IdParam *> idParams_;
|
||||
std::vector<std::shared_ptr<IdParam>> idParams_;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -200,13 +200,13 @@ public:
|
||||
uint32_t keyParamsCount_;
|
||||
|
||||
// the qualifiers
|
||||
std::vector<KeyParam *> keyParams_;
|
||||
std::vector<std::shared_ptr<KeyParam>> keyParams_;
|
||||
|
||||
// the resource ID data
|
||||
ResId *resId_;
|
||||
std::shared_ptr<ResId> resId_;
|
||||
|
||||
// the resConfig of each ResKey and all resConfig_ in ValueUnderQualifierDir will point to this resConfig_
|
||||
ResConfigImpl *resConfig_;
|
||||
std::shared_ptr<ResConfigImpl> resConfig_;
|
||||
};
|
||||
/**
|
||||
* a ResDesc means a index file in hap zip
|
||||
@ -221,7 +221,7 @@ public:
|
||||
|
||||
ResHeader *resHeader_;
|
||||
|
||||
std::vector<ResKey *> keys_;
|
||||
std::vector<std::shared_ptr<ResKey>> keys_;
|
||||
|
||||
std::string GetCurrentDeviceType();
|
||||
};
|
||||
|
@ -625,62 +625,65 @@ public:
|
||||
virtual std::string GetThemeMask();
|
||||
|
||||
private:
|
||||
RState GetString(const IdItem *idItem, std::string &outValue);
|
||||
RState GetString(const std::shared_ptr<IdItem> idItem, std::string &outValue);
|
||||
|
||||
RState GetStringArray(const IdItem *idItem, std::vector<std::string> &outValue);
|
||||
RState GetStringArray(const std::shared_ptr<IdItem> idItem, std::vector<std::string> &outValue);
|
||||
|
||||
RState GetPattern(const IdItem *idItem, std::map<std::string, std::string> &outValue);
|
||||
RState GetPattern(const std::shared_ptr<IdItem> idItem, std::map<std::string, std::string> &outValue);
|
||||
|
||||
RState GetTheme(const IdItem *idItem, std::map<std::string, std::string> &outValue);
|
||||
RState GetTheme(const std::shared_ptr<IdItem> idItem, std::map<std::string, std::string> &outValue);
|
||||
|
||||
RState GetPluralString(const HapResource::ValueUnderQualifierDir *vuqd, int quantity, std::string &outValue);
|
||||
RState GetPluralString(const std::shared_ptr<HapResource::ValueUnderQualifierDir> vuqd, int quantity,
|
||||
std::string &outValue);
|
||||
|
||||
RState ResolveReference(const std::string value, std::string &outValue);
|
||||
|
||||
RState GetBoolean(const IdItem *idItem, bool &outValue);
|
||||
RState GetBoolean(const std::shared_ptr<IdItem> idItem, bool &outValue);
|
||||
|
||||
RState ParseFloat(const std::string &strValue, float &result, std::string &unit);
|
||||
|
||||
RState RecalculateFloat(const std::string &unit, float &result);
|
||||
|
||||
RState GetFloat(const IdItem *idItem, float &outValue, std::string &unit);
|
||||
RState GetFloat(const std::shared_ptr<IdItem> idItem, float &outValue, std::string &unit);
|
||||
|
||||
RState GetInteger(const IdItem *idItem, int &outValue);
|
||||
RState GetInteger(const std::shared_ptr<IdItem> idItem, int &outValue);
|
||||
|
||||
RState GetColor(const IdItem *idItem, uint32_t &outValue);
|
||||
RState GetColor(const std::shared_ptr<IdItem> idItem, uint32_t &outValue);
|
||||
|
||||
RState GetIntArray(const IdItem *idItem, std::vector<int> &outValue);
|
||||
RState GetIntArray(const std::shared_ptr<IdItem> idItem, std::vector<int> &outValue);
|
||||
|
||||
RState GetSymbol(const IdItem *idItem, uint32_t &outValue);
|
||||
RState GetSymbol(const std::shared_ptr<IdItem> idItem, uint32_t &outValue);
|
||||
|
||||
void ProcessPsuedoTranslate(std::string &outValue);
|
||||
|
||||
RState ResolveParentReference(const IdItem *idItem, std::map<std::string, std::string> &outValue);
|
||||
RState ResolveParentReference(const std::shared_ptr<IdItem> idItem, std::map<std::string, std::string> &outValue);
|
||||
|
||||
bool IsDensityValid(uint32_t density);
|
||||
|
||||
bool IsFileExist(const std::string& path);
|
||||
|
||||
RState GetThemeColor(const IdItem *idItem, uint32_t &outValue);
|
||||
RState GetThemeColor(const std::shared_ptr<IdItem> idItem, uint32_t &outValue);
|
||||
|
||||
RState GetThemeFloat(const IdItem *idItem, float &outValue);
|
||||
RState GetThemeFloat(const std::shared_ptr<IdItem> idItem, float &outValue);
|
||||
|
||||
RState GetThemeMedia(const IdItem *idItem, size_t &len, std::unique_ptr<uint8_t[]> &outValue, uint32_t density);
|
||||
RState GetThemeMedia(const std::shared_ptr<IdItem> idItem, size_t &len,
|
||||
std::unique_ptr<uint8_t[]> &outValue, uint32_t density);
|
||||
|
||||
RState GetThemeMediaBase64(const IdItem *idItem, std::string &outValue);
|
||||
RState GetThemeMediaBase64(const std::shared_ptr<IdItem> idItem, std::string &outValue);
|
||||
|
||||
RState GetThemeDrawable(const IdItem *idItem, size_t &len, std::unique_ptr<uint8_t[]> &outValue,
|
||||
RState GetThemeDrawable(const std::shared_ptr<IdItem> idItem, size_t &len, std::unique_ptr<uint8_t[]> &outValue,
|
||||
uint32_t iconType, uint32_t density);
|
||||
|
||||
RState GetThemeIcon(const IdItem *idItem, size_t &len, std::unique_ptr<uint8_t[]> &outValue, uint32_t density);
|
||||
RState GetThemeIcon(const std::shared_ptr<IdItem> idItem, size_t &len, std::unique_ptr<uint8_t[]> &outValue,
|
||||
uint32_t density);
|
||||
|
||||
RState ProcessReference(const std::string value, std::vector<const IdItem *> &idItems);
|
||||
RState ProcessReference(const std::string value, std::vector<std::shared_ptr<IdItem>> &idItems);
|
||||
|
||||
RState GetThemeIconInfo(const std::string &iconName, size_t &len, std::unique_ptr<uint8_t[]> &outValue);
|
||||
|
||||
RState GetThemeValues(const std::string &value, std::string &outValue);
|
||||
|
||||
HapManager *hapManager_;
|
||||
std::shared_ptr<HapManager> hapManager_;
|
||||
|
||||
float fontRatio_ = 0.0f;
|
||||
|
||||
|
@ -83,7 +83,7 @@ public:
|
||||
* @return the best resource or empty
|
||||
*/
|
||||
const std::string FindThemeResource(const std::pair<std::string, std::string> &bundleInfo,
|
||||
std::vector<const IdItem *> idItems, const ResConfigImpl &resConfig);
|
||||
std::vector<std::shared_ptr<IdItem>> idItems, const ResConfigImpl &resConfig);
|
||||
|
||||
/**
|
||||
* Find the best icon resource related to bundlename, modulename, resource name.
|
||||
|
@ -56,7 +56,7 @@ namespace Resource {
|
||||
constexpr uint32_t PLURAL_CACHE_MAX_COUNT = 3;
|
||||
#endif
|
||||
Lock g_rawFileLock;
|
||||
HapManager::HapManager(ResConfigImpl *resConfig, bool isSystem)
|
||||
HapManager::HapManager(std::shared_ptr<ResConfigImpl> resConfig, bool isSystem)
|
||||
: resConfig_(resConfig), isSystem_(isSystem)
|
||||
{
|
||||
}
|
||||
@ -150,7 +150,7 @@ std::string HapManager::GetPluralRulesAndSelect(int quantity)
|
||||
#endif
|
||||
}
|
||||
|
||||
const IdItem *HapManager::FindResourceById(uint32_t id)
|
||||
const std::shared_ptr<IdItem> HapManager::FindResourceById(uint32_t id)
|
||||
{
|
||||
auto qualifierValue = FindQualifierValueById(id);
|
||||
if (qualifierValue == nullptr) {
|
||||
@ -159,7 +159,7 @@ const IdItem *HapManager::FindResourceById(uint32_t id)
|
||||
return qualifierValue->GetIdItem();
|
||||
}
|
||||
|
||||
const IdItem *HapManager::FindResourceByName(const char *name, const ResType resType)
|
||||
const std::shared_ptr<IdItem> HapManager::FindResourceByName(const char *name, const ResType resType)
|
||||
{
|
||||
auto qualifierValue = FindQualifierValueByName(name, resType);
|
||||
if (qualifierValue == nullptr) {
|
||||
@ -168,44 +168,45 @@ const IdItem *HapManager::FindResourceByName(const char *name, const ResType res
|
||||
return qualifierValue->GetIdItem();
|
||||
}
|
||||
|
||||
const HapResource::ValueUnderQualifierDir *HapManager::FindQualifierValueByName(
|
||||
const std::shared_ptr<HapResource::ValueUnderQualifierDir> HapManager::FindQualifierValueByName(
|
||||
const char *name, const ResType resType, uint32_t density)
|
||||
{
|
||||
AutoMutex mutex(this->lock_);
|
||||
std::vector<const HapResource::IdValues *> candidates = this->GetResourceListByName(name, resType);
|
||||
std::vector<std::shared_ptr<HapResource::IdValues>> candidates = this->GetResourceListByName(name, resType);
|
||||
if (candidates.size() == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return this->GetBestMatchResource(candidates, density);
|
||||
}
|
||||
|
||||
const HapResource::ValueUnderQualifierDir *HapManager::FindQualifierValueById(uint32_t id, uint32_t density)
|
||||
const std::shared_ptr<HapResource::ValueUnderQualifierDir> HapManager::FindQualifierValueById(uint32_t id,
|
||||
uint32_t density)
|
||||
{
|
||||
AutoMutex mutex(this->lock_);
|
||||
std::vector<const HapResource::IdValues *> candidates = this->GetResourceList(id);
|
||||
std::vector<std::shared_ptr<HapResource::IdValues>> candidates = this->GetResourceList(id);
|
||||
if (candidates.size() == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return this->GetBestMatchResource(candidates, density);
|
||||
}
|
||||
|
||||
const HapResource::ValueUnderQualifierDir *HapManager::GetBestMatchResource(std::vector<const HapResource::IdValues *>
|
||||
candidates, uint32_t density)
|
||||
const std::shared_ptr<HapResource::ValueUnderQualifierDir> HapManager::GetBestMatchResource(
|
||||
std::vector<std::shared_ptr<HapResource::IdValues>> candidates, uint32_t density)
|
||||
{
|
||||
const ResConfigImpl *bestResConfig = nullptr;
|
||||
const ResConfigImpl *bestOverlayResConfig = nullptr;
|
||||
const HapResource::ValueUnderQualifierDir *result = nullptr;
|
||||
const HapResource::ValueUnderQualifierDir *overlayResult = nullptr;
|
||||
const ResConfigImpl *currentResConfig = this->resConfig_;
|
||||
std::shared_ptr<ResConfigImpl> bestResConfig = nullptr;
|
||||
std::shared_ptr<ResConfigImpl> bestOverlayResConfig = nullptr;
|
||||
std::shared_ptr<HapResource::ValueUnderQualifierDir> result = nullptr;
|
||||
std::shared_ptr<HapResource::ValueUnderQualifierDir> overlayResult = nullptr;
|
||||
const std::shared_ptr<ResConfigImpl> currentResConfig = this->resConfig_;
|
||||
// When there are multiple overlays, reverse the search to find the first match resource.
|
||||
for (auto iter = candidates.rbegin(); iter != candidates.rend(); iter++) {
|
||||
const std::vector<HapResource::ValueUnderQualifierDir *> paths = (*iter)->GetLimitPathsConst();
|
||||
const std::vector<std::shared_ptr<HapResource::ValueUnderQualifierDir>> paths = (*iter)->GetLimitPathsConst();
|
||||
size_t len = paths.size();
|
||||
size_t i = 0;
|
||||
bool isOverlayHapResource = paths[0]->IsOverlay();
|
||||
for (i = 0; i < len; i++) {
|
||||
HapResource::ValueUnderQualifierDir *path = paths[i];
|
||||
const ResConfigImpl *resConfig = path->GetResConfig();
|
||||
std::shared_ptr<HapResource::ValueUnderQualifierDir> path = paths[i];
|
||||
const auto resConfig = path->GetResConfig();
|
||||
if (!this->resConfig_->Match(resConfig)) {
|
||||
continue;
|
||||
}
|
||||
@ -312,7 +313,7 @@ bool HapManager::AddResource(const std::string &path, const std::vector<std::str
|
||||
return true;
|
||||
}
|
||||
loadedHapPaths_[path] = overlayPaths;
|
||||
std::unordered_map<std::string, HapResource *> result = HapResource::LoadOverlays(path, overlayPaths,
|
||||
std::unordered_map<std::string, std::shared_ptr<HapResource>> result = HapResource::LoadOverlays(path, overlayPaths,
|
||||
resConfig_, isSystem_);
|
||||
if (result.size() > 0) {
|
||||
for (auto iter = result.begin(); iter != result.end(); iter++) {
|
||||
@ -368,21 +369,7 @@ bool HapManager::RemoveAppOverlay(const std::string &overlayPath)
|
||||
|
||||
HapManager::~HapManager()
|
||||
{
|
||||
for (size_t i = 0; i < hapResources_.size(); ++i) {
|
||||
if (hapResources_[i] == nullptr) {
|
||||
continue;
|
||||
}
|
||||
// system resource is static, no need to release in each hap manager
|
||||
if (hapResources_[i]->IsSystemResource()) {
|
||||
continue;
|
||||
}
|
||||
delete hapResources_[i];
|
||||
hapResources_[i] = nullptr;
|
||||
}
|
||||
if (resConfig_ != nullptr) {
|
||||
delete resConfig_;
|
||||
resConfig_ = nullptr;
|
||||
}
|
||||
hapResources_.clear();
|
||||
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
auto iter = plurRulesCache_.begin();
|
||||
@ -397,13 +384,13 @@ HapManager::~HapManager()
|
||||
#endif
|
||||
}
|
||||
|
||||
std::vector<const HapResource::IdValues *> HapManager::GetResourceList(uint32_t ident) const
|
||||
std::vector<std::shared_ptr<HapResource::IdValues>> HapManager::GetResourceList(uint32_t ident) const
|
||||
{
|
||||
std::vector<const HapResource::IdValues *> result;
|
||||
std::vector<std::shared_ptr<HapResource::IdValues>> result;
|
||||
// one id only exit in one hap
|
||||
for (size_t i = 0; i < hapResources_.size(); ++i) {
|
||||
HapResource *pResource = hapResources_[i];
|
||||
const HapResource::IdValues *out = pResource->GetIdValues(ident);
|
||||
std::shared_ptr<HapResource> pResource = hapResources_[i];
|
||||
const std::shared_ptr<HapResource::IdValues>out = pResource->GetIdValues(ident);
|
||||
if (out != nullptr) {
|
||||
result.emplace_back(out);
|
||||
}
|
||||
@ -411,14 +398,14 @@ std::vector<const HapResource::IdValues *> HapManager::GetResourceList(uint32_t
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<const HapResource::IdValues *> HapManager::GetResourceListByName(const char *name,
|
||||
std::vector<std::shared_ptr<HapResource::IdValues>> HapManager::GetResourceListByName(const char *name,
|
||||
const ResType resType) const
|
||||
{
|
||||
std::vector<const HapResource::IdValues *> result;
|
||||
std::vector<std::shared_ptr<HapResource::IdValues>> result;
|
||||
// all match will return
|
||||
for (size_t i = 0; i < hapResources_.size(); ++i) {
|
||||
HapResource *pResource = hapResources_[i];
|
||||
const HapResource::IdValues *out = pResource->GetIdValuesByName(std::string(name), resType);
|
||||
std::shared_ptr<HapResource> pResource = hapResources_[i];
|
||||
const std::shared_ptr<HapResource::IdValues> out = pResource->GetIdValuesByName(std::string(name), resType);
|
||||
if (out != nullptr) {
|
||||
result.emplace_back(out);
|
||||
}
|
||||
@ -433,44 +420,34 @@ bool HapManager::AddResourcePath(const char *path)
|
||||
if (it != loadedHapPaths_.end()) {
|
||||
return false;
|
||||
}
|
||||
const HapResource *pResource = HapResource::Load(path, resConfig_, isSystem_);
|
||||
const std::shared_ptr<HapResource> pResource = HapResource::Load(path, resConfig_, isSystem_);
|
||||
if (pResource == nullptr) {
|
||||
return false;
|
||||
}
|
||||
this->hapResources_.push_back(const_cast<HapResource *>(pResource));
|
||||
this->hapResources_.push_back(pResource);
|
||||
this->loadedHapPaths_[sPath] = std::vector<std::string>();
|
||||
return true;
|
||||
}
|
||||
|
||||
void DeleteNewResource(std::vector<HapResource *> &newResources)
|
||||
{
|
||||
for (size_t i = 0; i < newResources.size(); ++i) {
|
||||
if (newResources[i] != nullptr) {
|
||||
delete (newResources[i]);
|
||||
newResources[i] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RState HapManager::ReloadAll()
|
||||
{
|
||||
if (hapResources_.size() == 0) {
|
||||
return SUCCESS;
|
||||
}
|
||||
std::vector<HapResource *> newResources;
|
||||
std::vector<std::shared_ptr<HapResource>> newResources;
|
||||
for (auto iter = loadedHapPaths_.begin(); iter != loadedHapPaths_.end(); iter++) {
|
||||
std::vector<std::string> &overlayPaths = iter->second;
|
||||
if (overlayPaths.size() == 0) {
|
||||
const HapResource *pResource = HapResource::Load(iter->first.c_str(), resConfig_);
|
||||
const auto pResource = HapResource::Load(iter->first.c_str(), resConfig_);
|
||||
if (pResource == nullptr) {
|
||||
DeleteNewResource(newResources);
|
||||
newResources.clear();
|
||||
return HAP_INIT_FAILED;
|
||||
}
|
||||
newResources.push_back(const_cast<HapResource *>(pResource));
|
||||
newResources.push_back(pResource);
|
||||
continue;
|
||||
}
|
||||
std::unordered_map<std::string, HapResource *> result = HapResource::LoadOverlays(iter->first.c_str(),
|
||||
overlayPaths, resConfig_);
|
||||
std::unordered_map<std::string, std::shared_ptr<HapResource>> result = HapResource::LoadOverlays(
|
||||
iter->first.c_str(), overlayPaths, resConfig_);
|
||||
if (result.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
@ -478,9 +455,7 @@ RState HapManager::ReloadAll()
|
||||
newResources.push_back(iter->second);
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < hapResources_.size(); ++i) {
|
||||
delete (hapResources_[i]);
|
||||
}
|
||||
hapResources_.clear();
|
||||
hapResources_ = newResources;
|
||||
return SUCCESS;
|
||||
}
|
||||
@ -514,10 +489,10 @@ std::string GetImageType(const std::string fileName)
|
||||
|
||||
#if !defined(__WINNT__) && !defined(__IDE_PREVIEW__) && !defined(__ARKUI_CROSS__)
|
||||
std::string GetFilePathFromHap(std::shared_ptr<AbilityBase::Extractor> &extractor,
|
||||
const HapResource::ValueUnderQualifierDir *qd, const ResType resType)
|
||||
const std::shared_ptr<HapResource::ValueUnderQualifierDir> qd, const ResType resType)
|
||||
{
|
||||
std::string filePath;
|
||||
const IdItem *idItem = qd->GetIdItem();
|
||||
const std::shared_ptr<IdItem> idItem = qd->GetIdItem();
|
||||
if (idItem == nullptr || idItem->resType_ != resType) {
|
||||
std::string hapPath = qd->GetIndexPath();
|
||||
HILOG_ERROR("actual resType = %{public}d, expect resType = %{public}d, hapPath = %{public}s",
|
||||
@ -541,7 +516,8 @@ std::string GetFilePathFromHap(std::shared_ptr<AbilityBase::Extractor> &extracto
|
||||
return filePath;
|
||||
}
|
||||
|
||||
std::shared_ptr<AbilityBase::Extractor> GetAbilityExtractor(const HapResource::ValueUnderQualifierDir *qd)
|
||||
std::shared_ptr<AbilityBase::Extractor> GetAbilityExtractor(
|
||||
const std::shared_ptr<HapResource::ValueUnderQualifierDir> qd)
|
||||
{
|
||||
std::string hapPath = qd->GetIndexPath();
|
||||
bool isNewExtractor = false;
|
||||
@ -550,7 +526,7 @@ std::shared_ptr<AbilityBase::Extractor> GetAbilityExtractor(const HapResource::V
|
||||
}
|
||||
#endif
|
||||
|
||||
RState HapManager::GetProfileData(const HapResource::ValueUnderQualifierDir *qd, size_t &len,
|
||||
RState HapManager::GetProfileData(const std::shared_ptr<HapResource::ValueUnderQualifierDir> qd, size_t &len,
|
||||
std::unique_ptr<uint8_t[]> &outValue)
|
||||
{
|
||||
#if !defined(__WINNT__) && !defined(__IDE_PREVIEW__) && !defined(__ARKUI_CROSS__)
|
||||
@ -573,7 +549,7 @@ RState HapManager::GetProfileData(const HapResource::ValueUnderQualifierDir *qd,
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
RState HapManager::GetMediaData(const HapResource::ValueUnderQualifierDir *qd, size_t &len,
|
||||
RState HapManager::GetMediaData(const std::shared_ptr<HapResource::ValueUnderQualifierDir> qd, size_t &len,
|
||||
std::unique_ptr<uint8_t[]> &outValue)
|
||||
{
|
||||
std::string filePath = qd->GetIndexPath();
|
||||
@ -586,7 +562,7 @@ RState HapManager::GetMediaData(const HapResource::ValueUnderQualifierDir *qd, s
|
||||
return state;
|
||||
}
|
||||
|
||||
RState HapManager::GetMediaDataFromHap(const HapResource::ValueUnderQualifierDir *qd, size_t &len,
|
||||
RState HapManager::GetMediaDataFromHap(const std::shared_ptr<HapResource::ValueUnderQualifierDir> qd, size_t &len,
|
||||
std::unique_ptr<uint8_t[]> &outValue)
|
||||
{
|
||||
#if !defined(__WINNT__) && !defined(__IDE_PREVIEW__) && !defined(__ARKUI_CROSS__)
|
||||
@ -610,7 +586,7 @@ RState HapManager::GetMediaDataFromHap(const HapResource::ValueUnderQualifierDir
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
RState HapManager::GetMediaDataFromIndex(const HapResource::ValueUnderQualifierDir *qd, size_t &len,
|
||||
RState HapManager::GetMediaDataFromIndex(const std::shared_ptr<HapResource::ValueUnderQualifierDir> qd, size_t &len,
|
||||
std::unique_ptr<uint8_t[]> &outValue)
|
||||
{
|
||||
std::string filePath;
|
||||
@ -622,7 +598,8 @@ RState HapManager::GetMediaDataFromIndex(const HapResource::ValueUnderQualifierD
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
RState HapManager::GetMediaBase64Data(const HapResource::ValueUnderQualifierDir *qd, std::string &outValue)
|
||||
RState HapManager::GetMediaBase64Data(const std::shared_ptr<HapResource::ValueUnderQualifierDir> qd,
|
||||
std::string &outValue)
|
||||
{
|
||||
std::string filePath = qd->GetIndexPath();
|
||||
RState state;
|
||||
@ -634,7 +611,8 @@ RState HapManager::GetMediaBase64Data(const HapResource::ValueUnderQualifierDir
|
||||
return state;
|
||||
}
|
||||
|
||||
RState HapManager::GetMediaBase64DataFromHap(const HapResource::ValueUnderQualifierDir *qd, std::string &outValue)
|
||||
RState HapManager::GetMediaBase64DataFromHap(const std::shared_ptr<HapResource::ValueUnderQualifierDir> qd,
|
||||
std::string &outValue)
|
||||
{
|
||||
#if !defined(__WINNT__) && !defined(__IDE_PREVIEW__) && !defined(__ARKUI_CROSS__)
|
||||
auto extractor = GetAbilityExtractor(qd);
|
||||
@ -656,7 +634,8 @@ RState HapManager::GetMediaBase64DataFromHap(const HapResource::ValueUnderQualif
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
RState HapManager::GetMediaBase64DataFromIndex(const HapResource::ValueUnderQualifierDir *qd, std::string &outValue)
|
||||
RState HapManager::GetMediaBase64DataFromIndex(const std::shared_ptr<HapResource::ValueUnderQualifierDir> qd,
|
||||
std::string &outValue)
|
||||
{
|
||||
std::string filePath;
|
||||
RState state = HapManager::GetFilePath(qd, ResType::MEDIA, filePath);
|
||||
@ -773,14 +752,14 @@ bool HapManager::IsLoadHap(std::string &hapPath)
|
||||
return HapManager::GetValidHapPath(hapPath) == OK ? true : false;
|
||||
}
|
||||
|
||||
RState HapManager::GetFilePath(const HapResource::ValueUnderQualifierDir *vuqd, const ResType resType,
|
||||
RState HapManager::GetFilePath(const std::shared_ptr<HapResource::ValueUnderQualifierDir> vuqd, const ResType resType,
|
||||
std::string &outValue)
|
||||
{
|
||||
// not found or type invalid
|
||||
if (vuqd == nullptr) {
|
||||
return NOT_FOUND;
|
||||
}
|
||||
const IdItem *idItem = vuqd->GetIdItem();
|
||||
const std::shared_ptr<IdItem> idItem = vuqd->GetIdItem();
|
||||
if (idItem == nullptr || idItem->resType_ != resType) {
|
||||
return NOT_FOUND;
|
||||
}
|
||||
@ -899,12 +878,12 @@ bool HapManager::RemoveResource(const std::string &path, const std::vector<std::
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<HapResource *> HapManager::GetHapResource()
|
||||
std::vector<std::shared_ptr<HapResource>> HapManager::GetHapResource()
|
||||
{
|
||||
return hapResources_;
|
||||
}
|
||||
|
||||
void HapManager::AddSystemResource(const HapManager *systemHapManager)
|
||||
void HapManager::AddSystemResource(const std::shared_ptr<HapManager> &systemHapManager)
|
||||
{
|
||||
if (systemHapManager == nullptr) {
|
||||
HILOG_ERROR("add system resource failed, systemHapManager is nullptr");
|
||||
@ -916,7 +895,7 @@ void HapManager::AddSystemResource(const HapManager *systemHapManager)
|
||||
}
|
||||
AutoMutex mutex(this->lock_);
|
||||
// add system resource to app resource vector
|
||||
const std::vector<HapResource *> &systemResources = systemHapManager->hapResources_;
|
||||
const std::vector<std::shared_ptr<HapResource>> &systemResources = systemHapManager->hapResources_;
|
||||
for (size_t i = 0; i < systemResources.size(); i++) {
|
||||
this->hapResources_.push_back(systemResources[i]);
|
||||
}
|
||||
|
@ -42,8 +42,9 @@
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace Resource {
|
||||
HapResource::ValueUnderQualifierDir::ValueUnderQualifierDir(const ResKey *resKey, IdItem *idItem,
|
||||
const std::pair<std::string, std::string> &resPath, bool isOverlay, bool systemResource)
|
||||
HapResource::ValueUnderQualifierDir::ValueUnderQualifierDir(const std::shared_ptr<ResKey> resKey,
|
||||
std::shared_ptr<IdItem> idItem, const std::pair<std::string, std::string> &resPath, bool isOverlay,
|
||||
bool systemResource)
|
||||
{
|
||||
keyParams_ = resKey->keyParams_;
|
||||
folder_ = HapParser::ToFolderPath(keyParams_);
|
||||
@ -61,34 +62,18 @@ HapResource::ValueUnderQualifierDir::~ValueUnderQualifierDir()
|
||||
// IdValues
|
||||
HapResource::IdValues::~IdValues()
|
||||
{
|
||||
for (size_t i = 0; i < limitPaths_.size(); ++i) {
|
||||
if (limitPaths_[i] != nullptr) {
|
||||
delete limitPaths_[i];
|
||||
limitPaths_[i] = nullptr;
|
||||
}
|
||||
}
|
||||
limitPaths_.clear();
|
||||
}
|
||||
|
||||
// HapResource
|
||||
HapResource::HapResource(const std::string path, time_t lastModTime, ResDesc *resDes, bool isSystem, bool isOverlay)
|
||||
: indexPath_(path), lastModTime_(lastModTime), resDesc_(resDes), isSystem_(isSystem), isOverlay_(isOverlay)
|
||||
HapResource::HapResource(const std::string path, time_t lastModTime, std::shared_ptr<ResDesc> resDes,
|
||||
bool isSystem, bool isOverlay) : indexPath_(path), lastModTime_(lastModTime), resDesc_(resDes),
|
||||
isSystem_(isSystem), isOverlay_(isOverlay)
|
||||
{}
|
||||
|
||||
HapResource::~HapResource()
|
||||
{
|
||||
if (resDesc_ != nullptr) {
|
||||
delete (resDesc_);
|
||||
resDesc_ = nullptr;
|
||||
}
|
||||
std::map<uint32_t, IdValues *>::iterator iter;
|
||||
for (iter = idValuesMap_.begin(); iter != idValuesMap_.end(); ++iter) {
|
||||
if (iter->second != nullptr) {
|
||||
IdValues *ptr = iter->second;
|
||||
delete (ptr);
|
||||
iter->second = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
idValuesMap_.clear();
|
||||
for (size_t i = 0; i < idValuesNameMap_.size(); ++i) {
|
||||
if (idValuesNameMap_[i] != nullptr) {
|
||||
delete (idValuesNameMap_[i]);
|
||||
@ -98,8 +83,8 @@ HapResource::~HapResource()
|
||||
lastModTime_ = 0;
|
||||
}
|
||||
|
||||
const HapResource* HapResource::Load(const char *path, const ResConfigImpl* defaultConfig,
|
||||
bool isSystem, bool isOverlay)
|
||||
const std::shared_ptr<HapResource> HapResource::Load(const char *path,
|
||||
const std::shared_ptr<ResConfigImpl> defaultConfig, bool isSystem, bool isOverlay)
|
||||
{
|
||||
if (Utils::ContainsTail(path, Utils::tailSet)) {
|
||||
return LoadFromHap(path, defaultConfig, isSystem, isOverlay);
|
||||
@ -108,8 +93,8 @@ const HapResource* HapResource::Load(const char *path, const ResConfigImpl* defa
|
||||
}
|
||||
}
|
||||
|
||||
const HapResource* HapResource::LoadFromIndex(const char *path, const ResConfigImpl *defaultConfig,
|
||||
bool isSystem, bool isOverlay)
|
||||
const std::shared_ptr<HapResource> HapResource::LoadFromIndex(const char *path,
|
||||
const std::shared_ptr<ResConfigImpl> defaultConfig, bool isSystem, bool isOverlay)
|
||||
{
|
||||
char outPath[PATH_MAX + 1] = {0};
|
||||
Utils::CanonicalizePath(path, outPath, PATH_MAX);
|
||||
@ -136,7 +121,7 @@ const HapResource* HapResource::LoadFromIndex(const char *path, const ResConfigI
|
||||
|
||||
HILOG_DEBUG("extract success, bufLen:%d", bufLen);
|
||||
|
||||
ResDesc *resDesc = new (std::nothrow) ResDesc();
|
||||
std::shared_ptr<ResDesc> resDesc = std::make_shared<ResDesc>();
|
||||
if (resDesc == nullptr) {
|
||||
HILOG_ERROR("new ResDesc failed when LoadFromIndex");
|
||||
free(buf);
|
||||
@ -144,21 +129,19 @@ const HapResource* HapResource::LoadFromIndex(const char *path, const ResConfigI
|
||||
}
|
||||
int32_t out = HapParser::ParseResHex(static_cast<char *>(buf), bufLen, *resDesc, defaultConfig);
|
||||
if (out != OK) {
|
||||
delete (resDesc);
|
||||
free(buf);
|
||||
HILOG_ERROR("ParseResHex failed! retcode:%d", out);
|
||||
return nullptr;
|
||||
}
|
||||
free(buf);
|
||||
|
||||
HapResource *pResource = new (std::nothrow) HapResource(std::string(path), 0, resDesc, isSystem, isOverlay);
|
||||
std::shared_ptr<HapResource> pResource = std::make_shared<HapResource>(std::string(path),
|
||||
0, resDesc, isSystem, isOverlay);
|
||||
if (pResource == nullptr) {
|
||||
HILOG_ERROR("new HapResource failed when LoadFromIndex");
|
||||
delete (resDesc);
|
||||
return nullptr;
|
||||
}
|
||||
if (!pResource->Init()) {
|
||||
delete (pResource);
|
||||
return nullptr;
|
||||
}
|
||||
return pResource;
|
||||
@ -199,8 +182,8 @@ bool GetIndexData(const char *path, std::unique_ptr<uint8_t[]> &tmpBuf, size_t &
|
||||
return true;
|
||||
}
|
||||
|
||||
const HapResource* HapResource::LoadFromHap(const char *path, const ResConfigImpl *defaultConfig,
|
||||
bool isSystem, bool isOverlay)
|
||||
const std::shared_ptr<HapResource> HapResource::LoadFromHap(const char *path,
|
||||
const std::shared_ptr<ResConfigImpl> defaultConfig, bool isSystem, bool isOverlay)
|
||||
{
|
||||
std::unique_ptr<uint8_t[]> tmpBuf;
|
||||
size_t tmpLen = 0;
|
||||
@ -209,7 +192,7 @@ const HapResource* HapResource::LoadFromHap(const char *path, const ResConfigImp
|
||||
HILOG_ERROR("read Index from file failed path, %{public}s", path);
|
||||
return nullptr;
|
||||
}
|
||||
ResDesc *resDesc = new (std::nothrow) ResDesc();
|
||||
std::shared_ptr<ResDesc> resDesc = std::make_shared<ResDesc>();
|
||||
if (resDesc == nullptr) {
|
||||
HILOG_ERROR("new ResDesc failed when LoadFromHap");
|
||||
return nullptr;
|
||||
@ -217,46 +200,43 @@ const HapResource* HapResource::LoadFromHap(const char *path, const ResConfigImp
|
||||
int32_t out = HapParser::ParseResHex(reinterpret_cast<char *>(tmpBuf.get()), tmpLen, *resDesc, defaultConfig);
|
||||
if (out != OK) {
|
||||
HILOG_ERROR("ParseResHex failed! retcode:%d", out);
|
||||
delete (resDesc);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
HapResource *pResource = new (std::nothrow) HapResource(path, 0, resDesc, isSystem, isOverlay);
|
||||
auto pResource = std::make_shared<HapResource>(path, 0, resDesc, isSystem, isOverlay);
|
||||
if (pResource == nullptr) {
|
||||
delete (resDesc);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!pResource->Init()) {
|
||||
delete (pResource);
|
||||
return nullptr;
|
||||
}
|
||||
return pResource;
|
||||
}
|
||||
|
||||
const std::unordered_map<std::string, HapResource *> HapResource::LoadOverlays(const std::string &path,
|
||||
const std::vector<std::string> &overlayPaths, const ResConfigImpl *defaultConfig, bool isSystem)
|
||||
const std::unordered_map<std::string, std::shared_ptr<HapResource>> HapResource::LoadOverlays(const std::string &path,
|
||||
const std::vector<std::string> &overlayPaths, const std::shared_ptr<ResConfigImpl> defaultConfig, bool isSystem)
|
||||
{
|
||||
std::unordered_map<std::string, HapResource *> result;
|
||||
std::unordered_map<std::string, std::shared_ptr<HapResource>> result;
|
||||
do {
|
||||
const HapResource *targetResource = Load(path.c_str(), defaultConfig, isSystem);
|
||||
const std::shared_ptr<HapResource> targetResource = Load(path.c_str(), defaultConfig, isSystem);
|
||||
if (targetResource == nullptr) {
|
||||
HILOG_ERROR("load target failed");
|
||||
break;
|
||||
}
|
||||
result[path] = const_cast<HapResource*>(targetResource);
|
||||
result[path] = targetResource;
|
||||
bool success = true;
|
||||
std::unordered_map<std::string, std::unordered_map<ResType, uint32_t>> mapping =
|
||||
targetResource->BuildNameTypeIdMapping();
|
||||
for (auto iter = overlayPaths.begin(); iter != overlayPaths.end(); iter++) {
|
||||
// load overlay hap, the isOverlay flag set true.
|
||||
const HapResource *overlayResource = Load(iter->c_str(), defaultConfig, isSystem, true);
|
||||
const std::shared_ptr<HapResource> overlayResource = Load(iter->c_str(), defaultConfig, isSystem, true);
|
||||
if (overlayResource == nullptr) {
|
||||
HILOG_ERROR("load overlay failed");
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
result[*iter] = const_cast<HapResource*>(overlayResource);
|
||||
result[*iter] = overlayResource;
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
@ -273,19 +253,17 @@ const std::unordered_map<std::string, HapResource *> HapResource::LoadOverlays(c
|
||||
return result;
|
||||
} while (false);
|
||||
|
||||
for_each (result.begin(), result.end(), [](auto &iter) {
|
||||
delete iter.second;
|
||||
});
|
||||
return std::unordered_map<std::string, HapResource *>();
|
||||
result.clear();
|
||||
return std::unordered_map<std::string, std::shared_ptr<HapResource>>();
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, std::unordered_map<ResType, uint32_t>> HapResource::BuildNameTypeIdMapping() const
|
||||
{
|
||||
std::unordered_map<std::string, std::unordered_map<ResType, uint32_t>> result;
|
||||
for (auto iter = idValuesMap_.begin(); iter != idValuesMap_.end(); iter++) {
|
||||
const std::vector<ValueUnderQualifierDir *> &limitPaths = iter->second->GetLimitPathsConst();
|
||||
const std::vector<std::shared_ptr<ValueUnderQualifierDir>> &limitPaths = iter->second->GetLimitPathsConst();
|
||||
if (limitPaths.size() > 0) {
|
||||
ValueUnderQualifierDir* value = limitPaths[0];
|
||||
std::shared_ptr<ValueUnderQualifierDir> value = limitPaths[0];
|
||||
result[value->idItem_->name_][value->idItem_->resType_] = value->idItem_->id_;
|
||||
}
|
||||
}
|
||||
@ -294,11 +272,11 @@ std::unordered_map<std::string, std::unordered_map<ResType, uint32_t>> HapResour
|
||||
|
||||
void HapResource::UpdateOverlayInfo(std::unordered_map<std::string, std::unordered_map<ResType, uint32_t>> &nameTypeId)
|
||||
{
|
||||
std::map<uint32_t, IdValues *> newIdValuesMap;
|
||||
std::map<uint32_t, std::shared_ptr<IdValues>> newIdValuesMap;
|
||||
for (auto iter = idValuesMap_.begin(); iter != idValuesMap_.end(); iter++) {
|
||||
const std::vector<ValueUnderQualifierDir *> &limitPaths = iter->second->GetLimitPathsConst();
|
||||
const std::vector<std::shared_ptr<ValueUnderQualifierDir>> &limitPaths = iter->second->GetLimitPathsConst();
|
||||
if (limitPaths.size() > 0) {
|
||||
ValueUnderQualifierDir *value = limitPaths[0];
|
||||
std::shared_ptr<ValueUnderQualifierDir> value = limitPaths[0];
|
||||
std::string name = value->idItem_->name_;
|
||||
ResType type = value->idItem_->resType_;
|
||||
if (nameTypeId.find(name) == nameTypeId.end()) {
|
||||
@ -341,7 +319,7 @@ bool HapResource::Init()
|
||||
resourcePath_ = indexPath_.substr(0, index + 1);
|
||||
#endif
|
||||
for (int i = 0; i < ResType::MAX_RES_TYPE; ++i) {
|
||||
auto mptr = new (std::nothrow) std::map<std::string, IdValues *>();
|
||||
auto mptr = new (std::nothrow) std::map<std::string, std::shared_ptr<IdValues>>();
|
||||
if (mptr == nullptr) {
|
||||
HILOG_ERROR("new std::map failed in HapResource::Init");
|
||||
return false;
|
||||
@ -359,25 +337,24 @@ bool HapResource::InitIdList()
|
||||
}
|
||||
auto resPath = std::make_pair(indexPath_, resourcePath_);
|
||||
for (size_t i = 0; i < resDesc_->keys_.size(); i++) {
|
||||
ResKey *resKey = resDesc_->keys_[i];
|
||||
std::shared_ptr<ResKey> resKey = resDesc_->keys_[i];
|
||||
// init resConfig of each resKey.
|
||||
resKey->resConfig_ = HapParser::CreateResConfigFromKeyParams(resKey->keyParams_);
|
||||
|
||||
for (size_t j = 0; j < resKey->resId_->idParams_.size(); ++j) {
|
||||
IdParam *idParam = resKey->resId_->idParams_[j];
|
||||
std::shared_ptr<IdParam> idParam = resKey->resId_->idParams_[j];
|
||||
uint32_t id = idParam->id_;
|
||||
std::map<uint32_t, IdValues *>::iterator iter = idValuesMap_.find(id);
|
||||
std::map<uint32_t, std::shared_ptr<IdValues>>::iterator iter = idValuesMap_.find(id);
|
||||
if (iter == idValuesMap_.end()) {
|
||||
auto idValues = new (std::nothrow) HapResource::IdValues();
|
||||
auto idValues = std::make_shared<HapResource::IdValues>();
|
||||
if (idValues == nullptr) {
|
||||
HILOG_ERROR("new IdValues failed in HapResource::InitIdList");
|
||||
return false;
|
||||
}
|
||||
auto limitPath = new (std::nothrow) HapResource::ValueUnderQualifierDir(resKey,
|
||||
auto limitPath = std::make_shared<HapResource::ValueUnderQualifierDir>(resKey,
|
||||
idParam->idItem_, resPath, isOverlay_, isSystem_);
|
||||
if (limitPath == nullptr) {
|
||||
HILOG_ERROR("new ValueUnderQualifierDir failed in HapResource::InitIdList");
|
||||
delete (idValues);
|
||||
return false;
|
||||
}
|
||||
idValues->AddLimitPath(limitPath);
|
||||
@ -385,8 +362,8 @@ bool HapResource::InitIdList()
|
||||
std::string name = std::string(idParam->idItem_->name_);
|
||||
idValuesNameMap_[idParam->idItem_->resType_]->insert(std::make_pair(name, idValues));
|
||||
} else {
|
||||
HapResource::IdValues *idValues = iter->second;
|
||||
auto limitPath = new (std::nothrow) HapResource::ValueUnderQualifierDir(resKey,
|
||||
std::shared_ptr<HapResource::IdValues> idValues = iter->second;
|
||||
auto limitPath = std::make_shared<HapResource::ValueUnderQualifierDir>(resKey,
|
||||
idParam->idItem_, resPath, isOverlay_, isSystem_);
|
||||
if (limitPath == nullptr) {
|
||||
HILOG_ERROR("new ValueUnderQualifierDir failed in HapResource::InitIdList");
|
||||
@ -399,14 +376,14 @@ bool HapResource::InitIdList()
|
||||
return true;
|
||||
};
|
||||
|
||||
const HapResource::IdValues *HapResource::GetIdValues(const uint32_t id) const
|
||||
const std::shared_ptr<HapResource::IdValues> HapResource::GetIdValues(const uint32_t id) const
|
||||
{
|
||||
if (idValuesMap_.empty()) {
|
||||
HILOG_ERROR("idValuesMap_ is empty");
|
||||
return nullptr;
|
||||
}
|
||||
uint32_t uid = id;
|
||||
std::map<uint32_t, IdValues *>::const_iterator iter = idValuesMap_.find(uid);
|
||||
std::map<uint32_t, std::shared_ptr<IdValues>>::const_iterator iter = idValuesMap_.find(uid);
|
||||
if (iter == idValuesMap_.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -414,11 +391,11 @@ const HapResource::IdValues *HapResource::GetIdValues(const uint32_t id) const
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
const HapResource::IdValues *HapResource::GetIdValuesByName(
|
||||
const std::shared_ptr<HapResource::IdValues> HapResource::GetIdValuesByName(
|
||||
const std::string name, const ResType resType) const
|
||||
{
|
||||
const std::map<std::string, IdValues *> *map = idValuesNameMap_[resType];
|
||||
std::map<std::string, IdValues *>::const_iterator iter = map->find(name);
|
||||
const std::map<std::string, std::shared_ptr<IdValues>> *map = idValuesNameMap_[resType];
|
||||
std::map<std::string, std::shared_ptr<IdValues>>::const_iterator iter = map->find(name);
|
||||
if (iter == map->end()) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -431,12 +408,12 @@ int HapResource::GetIdByName(const char *name, const ResType resType) const
|
||||
if (name == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
const std::map<std::string, IdValues *> *map = idValuesNameMap_[resType];
|
||||
std::map<std::string, IdValues *>::const_iterator iter = map->find(name);
|
||||
const std::map<std::string, std::shared_ptr<IdValues>> *map = idValuesNameMap_[resType];
|
||||
std::map<std::string, std::shared_ptr<IdValues>>::const_iterator iter = map->find(name);
|
||||
if (iter == map->end()) {
|
||||
return OBJ_NOT_FOUND;
|
||||
}
|
||||
const IdValues *ids = iter->second;
|
||||
const std::shared_ptr<IdValues> ids = iter->second;
|
||||
|
||||
if (ids->GetLimitPathsConst().size() == 0) {
|
||||
HILOG_ERROR("limitPaths empty");
|
||||
@ -467,7 +444,7 @@ uint32_t HapResource::GetResourceLimitKeys() const
|
||||
if (iter->second == nullptr) {
|
||||
continue;
|
||||
}
|
||||
const std::vector<ValueUnderQualifierDir *> &limitPaths = iter->second->GetLimitPathsConst();
|
||||
const std::vector<std::shared_ptr<ValueUnderQualifierDir>> &limitPaths = iter->second->GetLimitPathsConst();
|
||||
if (limitPaths.size() <= 0) {
|
||||
continue;
|
||||
}
|
||||
@ -476,13 +453,13 @@ uint32_t HapResource::GetResourceLimitKeys() const
|
||||
return limitKeyValue;
|
||||
}
|
||||
|
||||
uint32_t HapResource::GetLimitPathsKeys(const std::vector<ValueUnderQualifierDir *> &limitPaths,
|
||||
uint32_t HapResource::GetLimitPathsKeys(const std::vector<std::shared_ptr<ValueUnderQualifierDir>> &limitPaths,
|
||||
std::vector<bool> &keyTypes) const
|
||||
{
|
||||
uint32_t limitKeyValue = 0;
|
||||
const uint32_t limitKeysBase = 0x00000001;
|
||||
for_each(limitPaths.begin(), limitPaths.end(), [&](auto &item) {
|
||||
const std::vector<KeyParam *> &keyParams = item->keyParams_;
|
||||
const std::vector<std::shared_ptr<KeyParam>> &keyParams = item->keyParams_;
|
||||
for_each(keyParams.begin(), keyParams.end(), [&](auto &keyParam) {
|
||||
uint32_t typeValue = static_cast<uint32_t>(keyParam->type_);
|
||||
if (keyParam->type_ < KeyType::KEY_TYPE_MAX && !keyTypes[typeValue]) {
|
||||
@ -504,7 +481,8 @@ void HapResource::GetLocales(std::set<std::string> &outValue, bool includeSystem
|
||||
}
|
||||
}
|
||||
|
||||
void HapResource::GetKeyParamsLocales(const std::vector<KeyParam *> keyParams, std::set<std::string> &outValue)
|
||||
void HapResource::GetKeyParamsLocales(const std::vector<std::shared_ptr<KeyParam>> keyParams,
|
||||
std::set<std::string> &outValue)
|
||||
{
|
||||
std::string locale;
|
||||
bool isLocale = false;
|
||||
|
@ -352,7 +352,7 @@ bool ResConfigImpl::Copy(ResConfig &other)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ResConfigImpl::Match(const ResConfigImpl *other) const
|
||||
bool ResConfigImpl::Match(const std::shared_ptr<ResConfigImpl> other) const
|
||||
{
|
||||
if (other == nullptr) {
|
||||
return false;
|
||||
@ -453,8 +453,8 @@ bool ResConfigImpl::IsInputDeviceMatch(InputDevice inputDevice) const
|
||||
* return false
|
||||
*
|
||||
*/
|
||||
bool ResConfigImpl::IsMoreSuitable(const ResConfigImpl *other,
|
||||
const ResConfigImpl *request, uint32_t density) const
|
||||
bool ResConfigImpl::IsMoreSuitable(const std::shared_ptr<ResConfigImpl> other,
|
||||
const std::shared_ptr<ResConfigImpl> request, uint32_t density) const
|
||||
{
|
||||
if (request != nullptr && other != nullptr) {
|
||||
int ret = IsMccMncMoreSuitable(other->mcc_, other->mnc_, request->mcc_, request->mnc_);
|
||||
@ -632,7 +632,7 @@ bool ResConfigImpl::IsCompletedScript() const
|
||||
return isCompletedScript_;
|
||||
}
|
||||
|
||||
bool ResConfigImpl::IsMoreSpecificThan(const ResConfigImpl *other, uint32_t density) const
|
||||
bool ResConfigImpl::IsMoreSpecificThan(const std::shared_ptr<ResConfigImpl> other, uint32_t density) const
|
||||
{
|
||||
if (other == nullptr) {
|
||||
return true;
|
||||
|
@ -277,12 +277,7 @@ std::string IdItem::ToString() const
|
||||
}
|
||||
|
||||
IdParam::~IdParam()
|
||||
{
|
||||
if (idItem_ != nullptr) {
|
||||
delete (idItem_);
|
||||
idItem_ = nullptr;
|
||||
}
|
||||
}
|
||||
{}
|
||||
|
||||
std::string IdParam::ToString() const
|
||||
{
|
||||
@ -292,12 +287,7 @@ std::string IdParam::ToString() const
|
||||
|
||||
ResId::~ResId()
|
||||
{
|
||||
for (size_t i = 0; i < idParams_.size(); ++i) {
|
||||
if (idParams_[i] != nullptr) {
|
||||
delete idParams_[i];
|
||||
idParams_[i] = nullptr;
|
||||
}
|
||||
}
|
||||
idParams_.clear();
|
||||
}
|
||||
|
||||
std::string ResId::ToString() const
|
||||
@ -312,21 +302,7 @@ std::string ResId::ToString() const
|
||||
ResKey::~ResKey()
|
||||
{
|
||||
HILOG_DEBUG("~ResKey()");
|
||||
if (resConfig_ != nullptr) {
|
||||
delete (resConfig_);
|
||||
resConfig_ = nullptr;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < keyParams_.size(); ++i) {
|
||||
if (keyParams_[i] != nullptr) {
|
||||
delete keyParams_[i];
|
||||
keyParams_[i] = nullptr;
|
||||
}
|
||||
}
|
||||
if (resId_ != nullptr) {
|
||||
delete (resId_);
|
||||
resId_ = nullptr;
|
||||
}
|
||||
keyParams_.clear();
|
||||
}
|
||||
|
||||
std::string ResKey::ToString() const
|
||||
@ -350,13 +326,7 @@ ResDesc::~ResDesc()
|
||||
delete (resHeader_);
|
||||
resHeader_ = nullptr;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < keys_.size(); ++i) {
|
||||
if (keys_[i] != nullptr) {
|
||||
delete keys_[i];
|
||||
keys_[i] = nullptr;
|
||||
}
|
||||
}
|
||||
keys_.clear();
|
||||
}
|
||||
|
||||
std::string ResDesc::ToString() const
|
||||
|
@ -66,14 +66,13 @@ ResourceManagerImpl::ResourceManagerImpl() : hapManager_(nullptr)
|
||||
|
||||
bool ResourceManagerImpl::Init(bool isSystem)
|
||||
{
|
||||
ResConfigImpl *resConfig = new (std::nothrow) ResConfigImpl;
|
||||
auto resConfig = std::make_shared<ResConfigImpl>();
|
||||
if (resConfig == nullptr) {
|
||||
HILOG_ERROR("new ResConfigImpl failed when ResourceManagerImpl::Init");
|
||||
return false;
|
||||
}
|
||||
hapManager_ = new (std::nothrow) HapManager(resConfig, isSystem);
|
||||
hapManager_ = std::make_shared<HapManager>(resConfig, isSystem);
|
||||
if (hapManager_ == nullptr) {
|
||||
delete (resConfig);
|
||||
HILOG_ERROR("new HapManager failed when ResourceManagerImpl::Init");
|
||||
return false;
|
||||
}
|
||||
@ -82,7 +81,7 @@ bool ResourceManagerImpl::Init(bool isSystem)
|
||||
|
||||
RState ResourceManagerImpl::GetStringById(uint32_t id, std::string &outValue)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceById(id);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceById(id);
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("find resource by string id error id = %{public}d", id);
|
||||
return ERROR_CODE_RES_ID_NOT_FOUND;
|
||||
@ -96,7 +95,7 @@ RState ResourceManagerImpl::GetStringById(uint32_t id, std::string &outValue)
|
||||
|
||||
RState ResourceManagerImpl::GetStringByName(const char *name, std::string &outValue)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::STRING);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceByName(name, ResType::STRING);
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("find resource by string name error name = %{public}s", name);
|
||||
return ERROR_CODE_RES_NAME_NOT_FOUND;
|
||||
@ -110,7 +109,7 @@ RState ResourceManagerImpl::GetStringByName(const char *name, std::string &outVa
|
||||
|
||||
RState ResourceManagerImpl::GetStringFormatById(std::string &outValue, uint32_t id, ...)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceById(id);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceById(id);
|
||||
std::string temp;
|
||||
RState rState = GetString(idItem, temp);
|
||||
if (rState != SUCCESS) {
|
||||
@ -125,7 +124,7 @@ RState ResourceManagerImpl::GetStringFormatById(std::string &outValue, uint32_t
|
||||
|
||||
RState ResourceManagerImpl::GetStringFormatByName(std::string &outValue, const char *name, ...)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::STRING);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceByName(name, ResType::STRING);
|
||||
std::string temp;
|
||||
RState rState = GetString(idItem, temp);
|
||||
if (rState != SUCCESS) {
|
||||
@ -138,7 +137,7 @@ RState ResourceManagerImpl::GetStringFormatByName(std::string &outValue, const c
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetString(const IdItem *idItem, std::string &outValue)
|
||||
RState ResourceManagerImpl::GetString(const std::shared_ptr<IdItem> idItem, std::string &outValue)
|
||||
{
|
||||
// not found or type invalid
|
||||
if (idItem == nullptr || idItem->resType_ != ResType::STRING) {
|
||||
@ -159,7 +158,7 @@ RState ResourceManagerImpl::GetString(const IdItem *idItem, std::string &outValu
|
||||
|
||||
RState ResourceManagerImpl::GetStringArrayById(uint32_t id, std::vector<std::string> &outValue)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceById(id);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceById(id);
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("find resource by string array id error id = %{public}d", id);
|
||||
return ERROR_CODE_RES_ID_NOT_FOUND;
|
||||
@ -173,7 +172,7 @@ RState ResourceManagerImpl::GetStringArrayById(uint32_t id, std::vector<std::str
|
||||
|
||||
RState ResourceManagerImpl::GetStringArrayByName(const char *name, std::vector<std::string> &outValue)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::STRINGARRAY);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceByName(name, ResType::STRINGARRAY);
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("find resource by string array name error name = %{public}s", name);
|
||||
return ERROR_CODE_RES_NAME_NOT_FOUND;
|
||||
@ -185,7 +184,7 @@ RState ResourceManagerImpl::GetStringArrayByName(const char *name, std::vector<s
|
||||
return state;
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetStringArray(const IdItem *idItem, std::vector<std::string> &outValue)
|
||||
RState ResourceManagerImpl::GetStringArray(const std::shared_ptr<IdItem> idItem, std::vector<std::string> &outValue)
|
||||
{
|
||||
// not found or type invalid
|
||||
if (idItem == nullptr || idItem->resType_ != ResType::STRINGARRAY) {
|
||||
@ -217,7 +216,7 @@ RState ResourceManagerImpl::GetStringArray(const IdItem *idItem, std::vector<std
|
||||
|
||||
RState ResourceManagerImpl::GetPatternById(uint32_t id, std::map<std::string, std::string> &outValue)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceById(id);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceById(id);
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("find resource by pattern id error id = %{public}d", id);
|
||||
return ERROR_CODE_RES_ID_NOT_FOUND;
|
||||
@ -231,7 +230,7 @@ RState ResourceManagerImpl::GetPatternById(uint32_t id, std::map<std::string, st
|
||||
|
||||
RState ResourceManagerImpl::GetPatternByName(const char *name, std::map<std::string, std::string> &outValue)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::PATTERN);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceByName(name, ResType::PATTERN);
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("find resource by Pattern name error name = %{public}s", name);
|
||||
return ERROR_CODE_RES_NAME_NOT_FOUND;
|
||||
@ -243,7 +242,8 @@ RState ResourceManagerImpl::GetPatternByName(const char *name, std::map<std::str
|
||||
return state;
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetPattern(const IdItem *idItem, std::map<std::string, std::string> &outValue)
|
||||
RState ResourceManagerImpl::GetPattern(const std::shared_ptr<IdItem> idItem, std::map<std::string,
|
||||
std::string> &outValue)
|
||||
{
|
||||
//type invalid
|
||||
if (idItem->resType_ != ResType::PATTERN) {
|
||||
@ -255,20 +255,20 @@ RState ResourceManagerImpl::GetPattern(const IdItem *idItem, std::map<std::strin
|
||||
|
||||
RState ResourceManagerImpl::GetPluralStringById(uint32_t id, int quantity, std::string &outValue)
|
||||
{
|
||||
const HapResource::ValueUnderQualifierDir *vuqd = hapManager_->FindQualifierValueById(id);
|
||||
const std::shared_ptr<HapResource::ValueUnderQualifierDir> vuqd = hapManager_->FindQualifierValueById(id);
|
||||
return GetPluralString(vuqd, quantity, outValue);
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetPluralStringByName(const char *name, int quantity, std::string &outValue)
|
||||
{
|
||||
const HapResource::ValueUnderQualifierDir *vuqd =
|
||||
const std::shared_ptr<HapResource::ValueUnderQualifierDir> vuqd =
|
||||
hapManager_->FindQualifierValueByName(name, ResType::PLURALS);
|
||||
return GetPluralString(vuqd, quantity, outValue);
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetPluralStringByIdFormat(std::string &outValue, uint32_t id, int quantity, ...)
|
||||
{
|
||||
const HapResource::ValueUnderQualifierDir *vuqd = hapManager_->FindQualifierValueById(id);
|
||||
const std::shared_ptr<HapResource::ValueUnderQualifierDir> vuqd = hapManager_->FindQualifierValueById(id);
|
||||
if (vuqd == nullptr) {
|
||||
HILOG_ERROR("find qualifier value by plural id error id = %{public}d", id);
|
||||
return ERROR_CODE_RES_ID_NOT_FOUND;
|
||||
@ -292,7 +292,7 @@ RState ResourceManagerImpl::GetPluralStringByIdFormat(std::string &outValue, uin
|
||||
|
||||
RState ResourceManagerImpl::GetPluralStringByNameFormat(std::string &outValue, const char *name, int quantity, ...)
|
||||
{
|
||||
const HapResource::ValueUnderQualifierDir *vuqd =
|
||||
const std::shared_ptr<HapResource::ValueUnderQualifierDir> vuqd =
|
||||
hapManager_->FindQualifierValueByName(name, ResType::PLURALS);
|
||||
if (vuqd == nullptr) {
|
||||
HILOG_ERROR("find qualifier value by plural name error name = %{public}s", name);
|
||||
@ -315,7 +315,7 @@ RState ResourceManagerImpl::GetPluralStringByNameFormat(std::string &outValue, c
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetPluralString(const HapResource::ValueUnderQualifierDir *vuqd,
|
||||
RState ResourceManagerImpl::GetPluralString(const std::shared_ptr<HapResource::ValueUnderQualifierDir> vuqd,
|
||||
int quantity, std::string &outValue)
|
||||
{
|
||||
// not found or type invalid
|
||||
@ -383,7 +383,7 @@ RState ResourceManagerImpl::ResolveReference(const std::string value, std::strin
|
||||
HILOG_DEBUG("ref %{public}s can't be array", refStr.c_str());
|
||||
return ERROR;
|
||||
}
|
||||
const IdItem *idItem = hapManager_->FindResourceById(id);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceById(id);
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("ref %s id not found", refStr.c_str());
|
||||
return ERROR;
|
||||
@ -408,7 +408,7 @@ RState ResourceManagerImpl::GetThemeValues(const std::string &value, std::string
|
||||
{
|
||||
ResConfigImpl resConfig;
|
||||
GetResConfig(resConfig);
|
||||
std::vector<const IdItem *> idItems;
|
||||
std::vector<std::shared_ptr<IdItem>> idItems;
|
||||
if (ProcessReference(value, idItems) != SUCCESS) {
|
||||
return NOT_FOUND;
|
||||
}
|
||||
@ -416,7 +416,8 @@ RState ResourceManagerImpl::GetThemeValues(const std::string &value, std::string
|
||||
return outValue.empty() ? NOT_FOUND : SUCCESS;
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::ResolveParentReference(const IdItem *idItem, std::map<std::string, std::string> &outValue)
|
||||
RState ResourceManagerImpl::ResolveParentReference(const std::shared_ptr<IdItem> idItem, std::map<std::string,
|
||||
std::string> &outValue)
|
||||
{
|
||||
// only pattern and theme
|
||||
// ref always at idx 0
|
||||
@ -425,7 +426,7 @@ RState ResourceManagerImpl::ResolveParentReference(const IdItem *idItem, std::ma
|
||||
|
||||
bool haveParent = false;
|
||||
int count = 0;
|
||||
const IdItem *currItem = idItem;
|
||||
std::shared_ptr<IdItem> currItem = idItem;
|
||||
do {
|
||||
haveParent = currItem->HaveParent();
|
||||
size_t startIdx = haveParent ? 1 : 0;
|
||||
@ -479,7 +480,7 @@ RState ResourceManagerImpl::ResolveParentReference(const IdItem *idItem, std::ma
|
||||
|
||||
RState ResourceManagerImpl::GetBooleanById(uint32_t id, bool &outValue)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceById(id);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceById(id);
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("find resource by Boolean id error id = %{public}d", id);
|
||||
return ERROR_CODE_RES_ID_NOT_FOUND;
|
||||
@ -493,7 +494,7 @@ RState ResourceManagerImpl::GetBooleanById(uint32_t id, bool &outValue)
|
||||
|
||||
RState ResourceManagerImpl::GetBooleanByName(const char *name, bool &outValue)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::BOOLEAN);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceByName(name, ResType::BOOLEAN);
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("find resource by Boolean name error name = %{public}s", name);
|
||||
return ERROR_CODE_RES_NAME_NOT_FOUND;
|
||||
@ -505,7 +506,7 @@ RState ResourceManagerImpl::GetBooleanByName(const char *name, bool &outValue)
|
||||
return state;
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetBoolean(const IdItem *idItem, bool &outValue)
|
||||
RState ResourceManagerImpl::GetBoolean(const std::shared_ptr<IdItem> idItem, bool &outValue)
|
||||
{
|
||||
if (idItem == nullptr || idItem->resType_ != ResType::BOOLEAN) {
|
||||
return NOT_FOUND;
|
||||
@ -526,11 +527,11 @@ RState ResourceManagerImpl::GetBoolean(const IdItem *idItem, bool &outValue)
|
||||
return state;
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetThemeFloat(const IdItem *idItem, float &outValue)
|
||||
RState ResourceManagerImpl::GetThemeFloat(const std::shared_ptr<IdItem> idItem, float &outValue)
|
||||
{
|
||||
ResConfigImpl resConfig;
|
||||
GetResConfig(resConfig);
|
||||
std::vector<const IdItem *> idItems;
|
||||
std::vector<std::shared_ptr<IdItem>> idItems;
|
||||
idItems.emplace_back(idItem);
|
||||
ProcessReference(idItem->value_, idItems);
|
||||
std::string result = ThemePackManager::GetThemePackManager()->FindThemeResource(bundleInfo, idItems, resConfig);
|
||||
@ -544,7 +545,7 @@ RState ResourceManagerImpl::GetThemeFloat(const IdItem *idItem, float &outValue)
|
||||
|
||||
RState ResourceManagerImpl::GetFloatById(uint32_t id, float &outValue)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceById(id);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceById(id);
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("find resource by Float id error id = %{public}d", id);
|
||||
return ERROR_CODE_RES_ID_NOT_FOUND;
|
||||
@ -568,13 +569,13 @@ RState ResourceManagerImpl::GetFloatById(uint32_t id, float &outValue)
|
||||
|
||||
RState ResourceManagerImpl::GetFloatById(uint32_t id, float &outValue, std::string &unit)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceById(id);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceById(id);
|
||||
return GetFloat(idItem, outValue, unit);
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetFloatByName(const char *name, float &outValue)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::FLOAT);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceByName(name, ResType::FLOAT);
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("find resource by Float name error name = %{public}s", name);
|
||||
return ERROR_CODE_RES_NAME_NOT_FOUND;
|
||||
@ -598,7 +599,7 @@ RState ResourceManagerImpl::GetFloatByName(const char *name, float &outValue)
|
||||
|
||||
RState ResourceManagerImpl::GetFloatByName(const char *name, float &outValue, std::string &unit)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::FLOAT);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceByName(name, ResType::FLOAT);
|
||||
return GetFloat(idItem, outValue, unit);
|
||||
}
|
||||
|
||||
@ -637,7 +638,7 @@ RState ResourceManagerImpl::ParseFloat(const std::string &strValue, float &resul
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetFloat(const IdItem *idItem, float &outValue, std::string &unit)
|
||||
RState ResourceManagerImpl::GetFloat(const std::shared_ptr<IdItem> idItem, float &outValue, std::string &unit)
|
||||
{
|
||||
if (idItem == nullptr || idItem->resType_ != ResType::FLOAT) {
|
||||
return NOT_FOUND;
|
||||
@ -652,7 +653,7 @@ RState ResourceManagerImpl::GetFloat(const IdItem *idItem, float &outValue, std:
|
||||
|
||||
RState ResourceManagerImpl::GetIntegerById(uint32_t id, int &outValue)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceById(id);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceById(id);
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("find resource by Integer id error id = %{public}d", id);
|
||||
return ERROR_CODE_RES_ID_NOT_FOUND;
|
||||
@ -666,7 +667,7 @@ RState ResourceManagerImpl::GetIntegerById(uint32_t id, int &outValue)
|
||||
|
||||
RState ResourceManagerImpl::GetIntegerByName(const char *name, int &outValue)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::INTEGER);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceByName(name, ResType::INTEGER);
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("find resource by Integer name error name = %{public}s", name);
|
||||
return ERROR_CODE_RES_NAME_NOT_FOUND;
|
||||
@ -678,7 +679,7 @@ RState ResourceManagerImpl::GetIntegerByName(const char *name, int &outValue)
|
||||
return state;
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetInteger(const IdItem *idItem, int &outValue)
|
||||
RState ResourceManagerImpl::GetInteger(const std::shared_ptr<IdItem> idItem, int &outValue)
|
||||
{
|
||||
if (idItem == nullptr || idItem->resType_ != ResType::INTEGER) {
|
||||
return NOT_FOUND;
|
||||
@ -692,7 +693,8 @@ RState ResourceManagerImpl::GetInteger(const IdItem *idItem, int &outValue)
|
||||
return state;
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::ProcessReference(const std::string value, std::vector<const IdItem *> &idItems)
|
||||
RState ResourceManagerImpl::ProcessReference(const std::string value,
|
||||
std::vector<std::shared_ptr<IdItem>> &idItems)
|
||||
{
|
||||
int id;
|
||||
ResType resType;
|
||||
@ -710,7 +712,7 @@ RState ResourceManagerImpl::ProcessReference(const std::string value, std::vecto
|
||||
HILOG_DEBUG("ref %{public}s can't be array", refStr.c_str());
|
||||
return ERROR;
|
||||
}
|
||||
const IdItem *idItem = hapManager_->FindResourceById(id);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceById(id);
|
||||
idItems.emplace_back(idItem);
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("ref %s id not found", refStr.c_str());
|
||||
@ -732,11 +734,11 @@ RState ResourceManagerImpl::ProcessReference(const std::string value, std::vecto
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetThemeColor(const IdItem *idItem, uint32_t &outValue)
|
||||
RState ResourceManagerImpl::GetThemeColor(const std::shared_ptr<IdItem> idItem, uint32_t &outValue)
|
||||
{
|
||||
ResConfigImpl resConfig;
|
||||
GetResConfig(resConfig);
|
||||
std::vector<const IdItem *> idItems;
|
||||
std::vector<std::shared_ptr<IdItem> > idItems;
|
||||
idItems.emplace_back(idItem);
|
||||
RState state = ProcessReference(idItem->value_, idItems);
|
||||
std::string result = ThemePackManager::GetThemePackManager()->FindThemeResource(bundleInfo, idItems, resConfig);
|
||||
@ -748,7 +750,7 @@ RState ResourceManagerImpl::GetThemeColor(const IdItem *idItem, uint32_t &outVal
|
||||
|
||||
RState ResourceManagerImpl::GetColorById(uint32_t id, uint32_t &outValue)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceById(id);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceById(id);
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("find resource by string id error id = %{public}d", id);
|
||||
return ERROR_CODE_RES_ID_NOT_FOUND;
|
||||
@ -768,7 +770,7 @@ RState ResourceManagerImpl::GetColorById(uint32_t id, uint32_t &outValue)
|
||||
|
||||
RState ResourceManagerImpl::GetColorByName(const char *name, uint32_t &outValue)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::COLOR);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceByName(name, ResType::COLOR);
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("find resource by string id error name = %{public}s", name);
|
||||
return ERROR_CODE_RES_NAME_NOT_FOUND;
|
||||
@ -786,7 +788,7 @@ RState ResourceManagerImpl::GetColorByName(const char *name, uint32_t &outValue)
|
||||
return state;
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetColor(const IdItem *idItem, uint32_t &outValue)
|
||||
RState ResourceManagerImpl::GetColor(const std::shared_ptr<IdItem> idItem, uint32_t &outValue)
|
||||
{
|
||||
if (idItem == nullptr || idItem->resType_ != ResType::COLOR) {
|
||||
return NOT_FOUND;
|
||||
@ -801,7 +803,7 @@ RState ResourceManagerImpl::GetColor(const IdItem *idItem, uint32_t &outValue)
|
||||
|
||||
RState ResourceManagerImpl::GetSymbolById(uint32_t id, uint32_t &outValue)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceById(id);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceById(id);
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("find resource by symbol id error id = %{public}d", id);
|
||||
return ERROR_CODE_RES_ID_NOT_FOUND;
|
||||
@ -815,7 +817,7 @@ RState ResourceManagerImpl::GetSymbolById(uint32_t id, uint32_t &outValue)
|
||||
|
||||
RState ResourceManagerImpl::GetSymbolByName(const char *name, uint32_t &outValue)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::SYMBOL);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceByName(name, ResType::SYMBOL);
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("find resource by symbol name error name = %{public}s", name);
|
||||
return ERROR_CODE_RES_NAME_NOT_FOUND;
|
||||
@ -827,7 +829,7 @@ RState ResourceManagerImpl::GetSymbolByName(const char *name, uint32_t &outValue
|
||||
return state;
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetSymbol(const IdItem *idItem, uint32_t &outValue)
|
||||
RState ResourceManagerImpl::GetSymbol(const std::shared_ptr<IdItem> idItem, uint32_t &outValue)
|
||||
{
|
||||
if (idItem == nullptr || idItem->resType_ != ResType::SYMBOL) {
|
||||
return NOT_FOUND;
|
||||
@ -842,17 +844,17 @@ RState ResourceManagerImpl::GetSymbol(const IdItem *idItem, uint32_t &outValue)
|
||||
|
||||
RState ResourceManagerImpl::GetIntArrayById(uint32_t id, std::vector<int> &outValue)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceById(id);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceById(id);
|
||||
return GetIntArray(idItem, outValue);
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetIntArrayByName(const char *name, std::vector<int> &outValue)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::INTARRAY);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceByName(name, ResType::INTARRAY);
|
||||
return GetIntArray(idItem, outValue);
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetIntArray(const IdItem *idItem, std::vector<int> &outValue)
|
||||
RState ResourceManagerImpl::GetIntArray(const std::shared_ptr<IdItem> idItem, std::vector<int> &outValue)
|
||||
{
|
||||
// not found or type invalid
|
||||
if (idItem == nullptr || idItem->resType_ != ResType::INTARRAY) {
|
||||
@ -874,7 +876,7 @@ RState ResourceManagerImpl::GetIntArray(const IdItem *idItem, std::vector<int> &
|
||||
|
||||
RState ResourceManagerImpl::GetThemeById(uint32_t id, std::map<std::string, std::string> &outValue)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceById(id);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceById(id);
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("find resource by Theme id error id = %{public}d", id);
|
||||
return ERROR_CODE_RES_ID_NOT_FOUND;
|
||||
@ -888,7 +890,7 @@ RState ResourceManagerImpl::GetThemeById(uint32_t id, std::map<std::string, std:
|
||||
|
||||
RState ResourceManagerImpl::GetThemeByName(const char *name, std::map<std::string, std::string> &outValue)
|
||||
{
|
||||
const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::THEME);
|
||||
const std::shared_ptr<IdItem> idItem = hapManager_->FindResourceByName(name, ResType::THEME);
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("find resource by Theme name error name = %{public}s", name);
|
||||
return ERROR_CODE_RES_NAME_NOT_FOUND;
|
||||
@ -900,7 +902,7 @@ RState ResourceManagerImpl::GetThemeByName(const char *name, std::map<std::strin
|
||||
return state;
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetTheme(const IdItem *idItem, std::map<std::string, std::string> &outValue)
|
||||
RState ResourceManagerImpl::GetTheme(const std::shared_ptr<IdItem> idItem, std::map<std::string, std::string> &outValue)
|
||||
{
|
||||
//type invalid
|
||||
if (idItem->resType_ != ResType::THEME) {
|
||||
@ -991,10 +993,6 @@ void ResourceManagerImpl::ProcessPsuedoTranslate(std::string &outValue)
|
||||
|
||||
ResourceManagerImpl::~ResourceManagerImpl()
|
||||
{
|
||||
if (hapManager_ != nullptr) {
|
||||
delete hapManager_;
|
||||
hapManager_ = nullptr;
|
||||
}
|
||||
if (psueManager_ != nullptr) {
|
||||
delete (psueManager_);
|
||||
psueManager_ = nullptr;
|
||||
@ -1091,12 +1089,12 @@ bool ResourceManagerImpl::IsDensityValid(uint32_t density)
|
||||
}
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetThemeMedia(const IdItem *idItem, size_t &len,
|
||||
RState ResourceManagerImpl::GetThemeMedia(const std::shared_ptr<IdItem> idItem, size_t &len,
|
||||
std::unique_ptr<uint8_t[]> &outValue, uint32_t density)
|
||||
{
|
||||
ResConfigImpl resConfig;
|
||||
GetResConfig(resConfig);
|
||||
std::vector<const IdItem *> idItems;
|
||||
std::vector<std::shared_ptr<IdItem>> idItems;
|
||||
idItems.emplace_back(idItem);
|
||||
std::string result = ThemePackManager::GetThemePackManager()->FindThemeResource(bundleInfo, idItems, resConfig);
|
||||
outValue = Utils::LoadResourceFile(result, len);
|
||||
@ -1117,7 +1115,7 @@ RState ResourceManagerImpl::GetMediaDataById(uint32_t id, size_t &len, std::uniq
|
||||
}
|
||||
|
||||
// find in theme
|
||||
const IdItem *idItem = qd->GetIdItem();
|
||||
const std::shared_ptr<IdItem> idItem = qd->GetIdItem();
|
||||
if (GetThemeMedia(idItem, len, outValue, density) == SUCCESS) {
|
||||
return SUCCESS;
|
||||
}
|
||||
@ -1140,7 +1138,7 @@ RState ResourceManagerImpl::GetMediaDataByName(const char *name, size_t &len, st
|
||||
return ERROR_CODE_RES_NAME_NOT_FOUND;
|
||||
}
|
||||
|
||||
const IdItem *idItem = qd->GetIdItem();
|
||||
const std::shared_ptr<IdItem> idItem = qd->GetIdItem();
|
||||
if (GetThemeMedia(idItem, len, outValue, density) == SUCCESS) {
|
||||
return SUCCESS;
|
||||
}
|
||||
@ -1149,13 +1147,16 @@ RState ResourceManagerImpl::GetMediaDataByName(const char *name, size_t &len, st
|
||||
return state == SUCCESS ? state : ERROR_CODE_RES_NOT_FOUND_BY_NAME;
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetThemeMediaBase64(const IdItem *idItem, std::string &outValue)
|
||||
RState ResourceManagerImpl::GetThemeMediaBase64(const std::shared_ptr<IdItem> idItem, std::string &outValue)
|
||||
{
|
||||
ResConfigImpl resConfig;
|
||||
GetResConfig(resConfig);
|
||||
std::vector<const IdItem *> idItems;
|
||||
std::vector<std::shared_ptr<IdItem>> idItems;
|
||||
idItems.emplace_back(idItem);
|
||||
std::string result = ThemePackManager::GetThemePackManager()->FindThemeResource(bundleInfo, idItems, resConfig);
|
||||
if (result.empty()) {
|
||||
return NOT_FOUND;
|
||||
}
|
||||
return Utils::GetMediaBase64Data(result, outValue);
|
||||
}
|
||||
|
||||
@ -1172,7 +1173,7 @@ RState ResourceManagerImpl::GetMediaBase64DataById(uint32_t id, std::string &out
|
||||
return ERROR_CODE_RES_ID_NOT_FOUND;
|
||||
}
|
||||
|
||||
const IdItem *idItem = qd->GetIdItem();
|
||||
const std::shared_ptr<IdItem> idItem = qd->GetIdItem();
|
||||
if (GetThemeMediaBase64(idItem, outValue) == SUCCESS) {
|
||||
return SUCCESS;
|
||||
}
|
||||
@ -1193,7 +1194,7 @@ RState ResourceManagerImpl::GetMediaBase64DataByName(const char *name, std::stri
|
||||
return ERROR_CODE_RES_NAME_NOT_FOUND;
|
||||
}
|
||||
|
||||
const IdItem *idItem = qd->GetIdItem();
|
||||
const std::shared_ptr<IdItem> idItem = qd->GetIdItem();
|
||||
if (GetThemeMediaBase64(idItem, outValue) == SUCCESS) {
|
||||
return SUCCESS;
|
||||
}
|
||||
@ -1256,9 +1257,9 @@ RState ResourceManagerImpl::GetRawFileList(const std::string &rawDirPath, std::v
|
||||
return hapManager_->GetRawFileList(rawDirPath, rawfileList);
|
||||
}
|
||||
|
||||
std::string GetSuffix(const HapResource::ValueUnderQualifierDir *qd)
|
||||
std::string GetSuffix(const std::shared_ptr<HapResource::ValueUnderQualifierDir> qd)
|
||||
{
|
||||
const IdItem *idItem = qd->GetIdItem();
|
||||
const std::shared_ptr<IdItem> idItem = qd->GetIdItem();
|
||||
if (idItem == nullptr || idItem->resType_ != ResType::MEDIA) {
|
||||
return std::string();
|
||||
}
|
||||
@ -1270,7 +1271,7 @@ std::string GetSuffix(const HapResource::ValueUnderQualifierDir *qd)
|
||||
return mediaPath.substr(pos + 1);
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetThemeIcon(const IdItem *idItem, size_t &len,
|
||||
RState ResourceManagerImpl::GetThemeIcon(const std::shared_ptr<IdItem> idItem, size_t &len,
|
||||
std::unique_ptr<uint8_t[]> &outValue, uint32_t density)
|
||||
{
|
||||
std::string iconName = idItem->GetItemResName();
|
||||
@ -1284,7 +1285,7 @@ RState ResourceManagerImpl::GetThemeIcon(const IdItem *idItem, size_t &len,
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetThemeDrawable(const IdItem *idItem, size_t &len,
|
||||
RState ResourceManagerImpl::GetThemeDrawable(const std::shared_ptr<IdItem> idItem, size_t &len,
|
||||
std::unique_ptr<uint8_t[]> &outValue, uint32_t iconType, uint32_t density)
|
||||
{
|
||||
if (iconType == 0 && GetThemeMedia(idItem, len, outValue, density) == SUCCESS) {
|
||||
@ -1357,7 +1358,7 @@ RState ResourceManagerImpl::GetDrawableInfoById(uint32_t id,
|
||||
}
|
||||
size_t len = 0;
|
||||
// find in theme
|
||||
const IdItem *idItem = qd->GetIdItem();
|
||||
const std::shared_ptr<IdItem> idItem = qd->GetIdItem();
|
||||
std::string themeMask = ThemePackManager::GetThemePackManager()->GetMask();
|
||||
if (GetThemeDrawable(idItem, len, outValue, iconType, density) == SUCCESS) {
|
||||
drawableInfo = std::make_tuple(type, len, themeMask);
|
||||
@ -1390,7 +1391,7 @@ RState ResourceManagerImpl::GetDrawableInfoByName(const char *name,
|
||||
size_t len = 0;
|
||||
// find in theme
|
||||
std::string themeMask = ThemePackManager::GetThemePackManager()->GetMask();
|
||||
const IdItem *idItem = qd->GetIdItem();
|
||||
const std::shared_ptr<IdItem> idItem = qd->GetIdItem();
|
||||
if (GetThemeDrawable(idItem, len, outValue, iconType, density) == SUCCESS) {
|
||||
drawableInfo = std::make_tuple(type, len, themeMask);
|
||||
return SUCCESS;
|
||||
|
@ -148,7 +148,7 @@ void ThemePackManager::LoadThemeRes(const std::string &bundleName, const std::st
|
||||
}
|
||||
|
||||
const std::string ThemePackManager::FindThemeResource(const std::pair<std::string, std::string> &bundleInfo,
|
||||
std::vector<const IdItem *> idItems, const ResConfigImpl &resConfig)
|
||||
std::vector<std::shared_ptr<IdItem>> idItems, const ResConfigImpl &resConfig)
|
||||
{
|
||||
std::string result;
|
||||
for (size_t i = 0; i < idItems.size(); i++) {
|
||||
|
@ -418,9 +418,9 @@ int32_t ParseStringArray(const char *buffer, uint32_t &offset, std::vector<std::
|
||||
return OK;
|
||||
}
|
||||
|
||||
int32_t ParseIdItem(const char *buffer, uint32_t &offset, IdItem *idItem)
|
||||
int32_t ParseIdItem(const char *buffer, uint32_t &offset, std::shared_ptr<IdItem> idItem)
|
||||
{
|
||||
errno_t eret = memcpy_s(idItem, sizeof(IdItem), buffer + offset, IdItem::HEADER_LEN);
|
||||
errno_t eret = memcpy_s(idItem.get(), sizeof(IdItem), buffer + offset, IdItem::HEADER_LEN);
|
||||
if (eret != OK) {
|
||||
return SYS_ERROR;
|
||||
}
|
||||
@ -450,9 +450,9 @@ int32_t ParseIdItem(const char *buffer, uint32_t &offset, IdItem *idItem)
|
||||
return OK;
|
||||
}
|
||||
|
||||
int32_t ParseId(const char *buffer, uint32_t &offset, ResId *id)
|
||||
int32_t ParseId(const char *buffer, uint32_t &offset, std::shared_ptr<ResId> id)
|
||||
{
|
||||
errno_t eret = memcpy_s(id, sizeof(ResId), buffer + offset, ResId::RESID_HEADER_LEN);
|
||||
errno_t eret = memcpy_s(id.get(), sizeof(ResId), buffer + offset, ResId::RESID_HEADER_LEN);
|
||||
if (eret != OK) {
|
||||
return SYS_ERROR;
|
||||
}
|
||||
@ -462,28 +462,24 @@ int32_t ParseId(const char *buffer, uint32_t &offset, ResId *id)
|
||||
return -1;
|
||||
}
|
||||
for (uint32_t i = 0; i < id->count_; ++i) {
|
||||
IdParam *ip = new (std::nothrow) IdParam();
|
||||
std::shared_ptr<IdParam> ip = std::make_shared<IdParam>();
|
||||
if (ip == nullptr) {
|
||||
HILOG_ERROR("new IdParam failed when ParseId");
|
||||
return SYS_ERROR;
|
||||
}
|
||||
errno_t eret = memcpy_s(ip, sizeof(IdParam), buffer + offset, ResId::IDPARAM_HEADER_LEN);
|
||||
errno_t eret = memcpy_s(ip.get(), sizeof(IdParam), buffer + offset, ResId::IDPARAM_HEADER_LEN);
|
||||
if (eret != OK) {
|
||||
delete (ip);
|
||||
return SYS_ERROR;
|
||||
}
|
||||
offset += ResId::IDPARAM_HEADER_LEN;
|
||||
IdItem *idItem = new (std::nothrow) IdItem();
|
||||
std::shared_ptr<IdItem> idItem = std::make_shared<IdItem>();
|
||||
if (idItem == nullptr) {
|
||||
HILOG_ERROR("new IdItem failed when ParseId");
|
||||
delete (ip);
|
||||
return SYS_ERROR;
|
||||
}
|
||||
uint32_t ipOffset = ip->offset_;
|
||||
int32_t ret = ParseIdItem(buffer, ipOffset, idItem);
|
||||
if (ret != OK) {
|
||||
delete (ip);
|
||||
delete (idItem);
|
||||
return ret;
|
||||
}
|
||||
ip->idItem_ = idItem;
|
||||
@ -493,28 +489,27 @@ int32_t ParseId(const char *buffer, uint32_t &offset, ResId *id)
|
||||
return OK;
|
||||
}
|
||||
|
||||
bool IsLocaleMatch(const ResConfigImpl *defaultConfig, const std::vector<KeyParam *> &keyParams)
|
||||
bool IsLocaleMatch(const std::shared_ptr<ResConfigImpl> defaultConfig,
|
||||
const std::vector<std::shared_ptr<KeyParam>> &keyParams)
|
||||
{
|
||||
if (defaultConfig == nullptr) {
|
||||
return true;
|
||||
}
|
||||
ResConfigImpl *config = HapParser::CreateResConfigFromKeyParams(keyParams);
|
||||
auto config = HapParser::CreateResConfigFromKeyParams(keyParams);
|
||||
if (config == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (LocaleMatcher::Match(defaultConfig->GetResLocale(), config->GetResLocale())) {
|
||||
delete (config);
|
||||
return true;
|
||||
}
|
||||
HILOG_DEBUG("mismatch, do not parse %s", HapParser::ToFolderPath(keyParams).c_str());
|
||||
delete (config);
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t ParseKey(const char *buffer, uint32_t &offset, ResKey *key,
|
||||
bool &match, const ResConfigImpl *defaultConfig, const std::string &deviceType)
|
||||
int32_t ParseKey(const char *buffer, uint32_t &offset, std::shared_ptr<ResKey> key,
|
||||
bool &match, const std::shared_ptr<ResConfigImpl> defaultConfig, const std::string &deviceType)
|
||||
{
|
||||
errno_t eret = memcpy_s(key, sizeof(ResKey), buffer + offset, ResKey::RESKEY_HEADER_LEN);
|
||||
errno_t eret = memcpy_s(key.get(), sizeof(ResKey), buffer + offset, ResKey::RESKEY_HEADER_LEN);
|
||||
if (eret != OK) {
|
||||
return SYS_ERROR;
|
||||
}
|
||||
@ -524,14 +519,13 @@ int32_t ParseKey(const char *buffer, uint32_t &offset, ResKey *key,
|
||||
return -1;
|
||||
}
|
||||
for (uint32_t i = 0; i < key->keyParamsCount_; ++i) {
|
||||
KeyParam *kp = new (std::nothrow) KeyParam();
|
||||
std::shared_ptr<KeyParam> kp = std::make_shared<KeyParam>();
|
||||
if (kp == nullptr) {
|
||||
HILOG_ERROR("new KeyParam failed when ParseKey");
|
||||
return SYS_ERROR;
|
||||
}
|
||||
errno_t eret = memcpy_s(kp, sizeof(KeyParam), buffer + offset, ResKey::KEYPARAM_HEADER_LEN);
|
||||
errno_t eret = memcpy_s(kp.get(), sizeof(KeyParam), buffer + offset, ResKey::KEYPARAM_HEADER_LEN);
|
||||
if (eret != OK) {
|
||||
delete (kp);
|
||||
return SYS_ERROR;
|
||||
}
|
||||
offset += ResKey::KEYPARAM_HEADER_LEN;
|
||||
@ -545,14 +539,13 @@ int32_t ParseKey(const char *buffer, uint32_t &offset, ResKey *key,
|
||||
key->keyParams_.push_back(kp);
|
||||
}
|
||||
uint32_t idOffset = key->offset_;
|
||||
ResId *id = new (std::nothrow) ResId();
|
||||
std::shared_ptr<ResId> id = std::make_shared<ResId>();
|
||||
if (id == nullptr) {
|
||||
HILOG_ERROR("new ResId failed when ParseKey");
|
||||
return SYS_ERROR;
|
||||
}
|
||||
int32_t ret = ParseId(buffer, idOffset, id);
|
||||
if (ret != OK) {
|
||||
delete (id);
|
||||
return ret;
|
||||
}
|
||||
key->resId_ = id;
|
||||
@ -561,7 +554,7 @@ int32_t ParseKey(const char *buffer, uint32_t &offset, ResKey *key,
|
||||
|
||||
|
||||
int32_t HapParser::ParseResHex(const char *buffer, const size_t bufLen, ResDesc &resDesc,
|
||||
const ResConfigImpl *defaultConfig)
|
||||
const std::shared_ptr<ResConfigImpl> defaultConfig)
|
||||
{
|
||||
ResHeader *resHeader = new (std::nothrow) ResHeader();
|
||||
if (resHeader == nullptr) {
|
||||
@ -583,7 +576,7 @@ int32_t HapParser::ParseResHex(const char *buffer, const size_t bufLen, ResDesc
|
||||
resDesc.resHeader_ = resHeader;
|
||||
const std::string deviceType = resDesc.GetCurrentDeviceType();
|
||||
for (uint32_t i = 0; i < resHeader->keyCount_; i++) {
|
||||
ResKey *key = new (std::nothrow) ResKey();
|
||||
std::shared_ptr<ResKey> key = std::make_shared<ResKey>();
|
||||
if (key == nullptr) {
|
||||
HILOG_ERROR("new ResKey failed when ParseResHex");
|
||||
return SYS_ERROR;
|
||||
@ -591,21 +584,19 @@ int32_t HapParser::ParseResHex(const char *buffer, const size_t bufLen, ResDesc
|
||||
bool match = true;
|
||||
int32_t ret = ParseKey(buffer, offset, key, match, defaultConfig, deviceType);
|
||||
if (ret != OK) {
|
||||
delete (key);
|
||||
return ret;
|
||||
}
|
||||
if (match) {
|
||||
resDesc.keys_.push_back(key);
|
||||
} else {
|
||||
delete (key);
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
ResConfigImpl *HapParser::CreateResConfigFromKeyParams(const std::vector<KeyParam *> &keyParams)
|
||||
std::shared_ptr<ResConfigImpl> HapParser::CreateResConfigFromKeyParams(
|
||||
const std::vector<std::shared_ptr<KeyParam>> &keyParams)
|
||||
{
|
||||
ResConfigImpl *resConfig = new (std::nothrow) ResConfigImpl;
|
||||
auto resConfig = std::make_shared<ResConfigImpl>();
|
||||
if (resConfig == nullptr) {
|
||||
HILOG_ERROR("new ResConfigImpl failed when CreateResConfigFromKeyParams");
|
||||
return nullptr;
|
||||
@ -616,11 +607,10 @@ ResConfigImpl *HapParser::CreateResConfigFromKeyParams(const std::vector<KeyPara
|
||||
resConfig->SetColorMode(COLOR_MODE_NOT_SET);
|
||||
return resConfig;
|
||||
}
|
||||
delete resConfig;
|
||||
size_t i = 0;
|
||||
ResConfigKey configKey;
|
||||
for (i = 0; i < len; ++i) {
|
||||
const KeyParam *kp = keyParams.at(i);
|
||||
const std::shared_ptr<KeyParam> kp = keyParams.at(i);
|
||||
if (kp->type_ == LANGUAGES) {
|
||||
configKey.language = kp->GetStr().c_str();
|
||||
} else if (kp->type_ == REGION) {
|
||||
@ -651,13 +641,13 @@ ResConfigImpl *HapParser::CreateResConfigFromKeyParams(const std::vector<KeyPara
|
||||
return BuildResConfig(&configKey);
|
||||
}
|
||||
|
||||
ResConfigImpl *HapParser::BuildResConfig(ResConfigKey *configKey)
|
||||
std::shared_ptr<ResConfigImpl> HapParser::BuildResConfig(ResConfigKey *configKey)
|
||||
{
|
||||
if (configKey == nullptr) {
|
||||
HILOG_ERROR("configKey is null");
|
||||
return nullptr;
|
||||
}
|
||||
ResConfigImpl *resConfig = new (std::nothrow) ResConfigImpl;
|
||||
auto resConfig = std::make_shared<ResConfigImpl>();
|
||||
if (resConfig == nullptr) {
|
||||
HILOG_ERROR("new ResConfigImpl failed when BuildResConfig");
|
||||
return nullptr;
|
||||
@ -758,7 +748,7 @@ void PathAppend(std::string &path, const std::string &append, const std::string
|
||||
}
|
||||
}
|
||||
|
||||
std::string HapParser::ToFolderPath(const std::vector<KeyParam *> &keyParams)
|
||||
std::string HapParser::ToFolderPath(const std::vector<std::shared_ptr<KeyParam>> &keyParams)
|
||||
{
|
||||
if (keyParams.size() == 0) {
|
||||
return std::string("default");
|
||||
@ -766,7 +756,7 @@ std::string HapParser::ToFolderPath(const std::vector<KeyParam *> &keyParams)
|
||||
// mcc-mnc-language_script_region-direction-deviceType-colorMode-inputDevice-screenDensity
|
||||
Determiner determiner;
|
||||
for (size_t i = 0; i < keyParams.size(); ++i) {
|
||||
KeyParam *keyParam = keyParams[i];
|
||||
std::shared_ptr<KeyParam> keyParam = keyParams[i];
|
||||
switch (keyParam->type_) {
|
||||
case KeyType::LANGUAGES:
|
||||
determiner.language = keyParam->GetStr();
|
||||
|
@ -70,13 +70,13 @@ void HapManagerTest::TearDown()
|
||||
*/
|
||||
HWTEST_F(HapManagerTest, HapManagerFuncTest001, TestSize.Level1)
|
||||
{
|
||||
HapManager *hapManager = new HapManager(new ResConfigImpl);
|
||||
HapManager *hapManager = new HapManager(std::make_shared<ResConfigImpl>());
|
||||
bool ret = hapManager->AddResourcePath(FormatFullPath(g_resFilePath).c_str());
|
||||
|
||||
EXPECT_TRUE(ret);
|
||||
|
||||
int id = 16777217;
|
||||
std::vector<const HapResource::IdValues *> idValues = hapManager->GetResourceList(id);
|
||||
auto idValues = hapManager->GetResourceList(id);
|
||||
if (idValues.size() == 0) {
|
||||
delete hapManager;
|
||||
EXPECT_TRUE(false);
|
||||
@ -95,7 +95,7 @@ HWTEST_F(HapManagerTest, HapManagerFuncTest001, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(HapManagerTest, HapManagerFuncTest002, TestSize.Level1)
|
||||
{
|
||||
ResConfig *rc = CreateResConfig();
|
||||
auto rc = CreateResConfig();
|
||||
if (rc == nullptr) {
|
||||
EXPECT_TRUE(false);
|
||||
return;
|
||||
@ -103,7 +103,7 @@ HWTEST_F(HapManagerTest, HapManagerFuncTest002, TestSize.Level1)
|
||||
rc->SetLocaleInfo("en", nullptr, "US");
|
||||
std::string resPath = FormatFullPath(g_resFilePath);
|
||||
const char *path = resPath.c_str();
|
||||
HapManager *hapManager = new HapManager(new ResConfigImpl);
|
||||
HapManager *hapManager = new HapManager(std::make_shared<ResConfigImpl>());
|
||||
if (hapManager == nullptr) {
|
||||
delete (rc);
|
||||
EXPECT_TRUE(false);
|
||||
@ -115,7 +115,7 @@ HWTEST_F(HapManagerTest, HapManagerFuncTest002, TestSize.Level1)
|
||||
EXPECT_TRUE(ret);
|
||||
|
||||
uint32_t id = 16777237; // 16777237 means string_ref
|
||||
std::vector<const HapResource::IdValues *> idValues = hapManager->GetResourceList(id);
|
||||
auto idValues = hapManager->GetResourceList(id);
|
||||
if (idValues.size() == 0) {
|
||||
delete (hapManager);
|
||||
delete (rc);
|
||||
@ -128,7 +128,7 @@ HWTEST_F(HapManagerTest, HapManagerFuncTest002, TestSize.Level1)
|
||||
|
||||
// reload
|
||||
|
||||
ResConfig *rc2 = CreateResConfig();
|
||||
auto rc2 = CreateResConfig();
|
||||
if (rc2 == nullptr) {
|
||||
delete (hapManager);
|
||||
delete (rc);
|
||||
@ -162,13 +162,13 @@ HWTEST_F(HapManagerTest, HapManagerFuncTest002, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(HapManagerTest, HapManagerFuncTest003, TestSize.Level1)
|
||||
{
|
||||
ResConfig *rc = CreateResConfig();
|
||||
auto rc = CreateResConfig();
|
||||
if (rc == nullptr) {
|
||||
EXPECT_TRUE(false);
|
||||
return;
|
||||
}
|
||||
rc->SetLocaleInfo("zh", nullptr, "CN");
|
||||
HapManager *hapManager = new HapManager(new ResConfigImpl);
|
||||
HapManager *hapManager = new HapManager(std::make_shared<ResConfigImpl>());
|
||||
hapManager->UpdateResConfig(*rc);
|
||||
if (hapManager == nullptr) {
|
||||
EXPECT_TRUE(false);
|
||||
@ -179,7 +179,7 @@ HWTEST_F(HapManagerTest, HapManagerFuncTest003, TestSize.Level1)
|
||||
EXPECT_TRUE(ret);
|
||||
|
||||
int id = 16777221; // 16777221 means 'aboutPage_title_primary'
|
||||
std::vector<const HapResource::IdValues *> idValues = hapManager->GetResourceList(id);
|
||||
auto idValues = hapManager->GetResourceList(id);
|
||||
if (idValues.size() == 0) {
|
||||
delete hapManager;
|
||||
EXPECT_TRUE(false);
|
||||
@ -204,13 +204,13 @@ HWTEST_F(HapManagerTest, HapManagerFuncTest003, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(HapManagerTest, HapManagerFuncTest004, TestSize.Level1)
|
||||
{
|
||||
ResConfig *rc = CreateResConfig();
|
||||
auto rc = CreateResConfig();
|
||||
if (rc == nullptr) {
|
||||
EXPECT_TRUE(false);
|
||||
return;
|
||||
}
|
||||
rc->SetLocaleInfo("en", nullptr, "US");
|
||||
HapManager *hapManager = new HapManager(new ResConfigImpl);
|
||||
HapManager *hapManager = new HapManager(std::make_shared<ResConfigImpl>());
|
||||
hapManager->UpdateResConfig(*rc);
|
||||
if (hapManager == nullptr) {
|
||||
EXPECT_TRUE(false);
|
||||
@ -219,7 +219,7 @@ HWTEST_F(HapManagerTest, HapManagerFuncTest004, TestSize.Level1)
|
||||
bool ret = hapManager->AddResourcePath(FormatFullPath(g_hapPath).c_str());
|
||||
EXPECT_TRUE(ret);
|
||||
int id = 16777221; // 16777221 means 'AboutPageFA' 'aboutPage_title_primary'
|
||||
std::vector<const HapResource::IdValues *> idValues = hapManager->GetResourceList(id);
|
||||
auto idValues = hapManager->GetResourceList(id);
|
||||
if (idValues.size() == 0) {
|
||||
delete hapManager;
|
||||
EXPECT_TRUE(false);
|
||||
|
@ -67,37 +67,37 @@ void HapParserTest::TearDown()
|
||||
*/
|
||||
HWTEST_F(HapParserTest, HapParserFuncTest001, TestSize.Level1)
|
||||
{
|
||||
std::vector<KeyParam *> keyParams;
|
||||
auto kp = new KeyParam();
|
||||
std::vector<std::shared_ptr<KeyParam>> keyParams;
|
||||
auto kp = std::make_shared<KeyParam>();
|
||||
kp->type_ = LANGUAGES;
|
||||
kp->value_ = 31336;
|
||||
kp->InitStr();
|
||||
keyParams.push_back(kp);
|
||||
kp = new KeyParam();
|
||||
kp->type_ = REGION;
|
||||
kp->value_ = 17230;
|
||||
auto kp1 = std::make_shared<KeyParam>();
|
||||
kp1->type_ = REGION;
|
||||
kp1->value_ = 17230;
|
||||
kp1->InitStr();
|
||||
keyParams.push_back(kp1);
|
||||
auto kp2 = std::make_shared<KeyParam>();
|
||||
kp2->type_ = SCREEN_DENSITY;
|
||||
kp2->value_ = SCREEN_DENSITY_SDPI;
|
||||
kp->InitStr();
|
||||
keyParams.push_back(kp);
|
||||
kp = new KeyParam();
|
||||
kp->type_ = SCREEN_DENSITY;
|
||||
kp->value_ = SCREEN_DENSITY_SDPI;
|
||||
kp->InitStr();
|
||||
keyParams.push_back(kp);
|
||||
kp = new KeyParam();
|
||||
kp->type_ = DEVICETYPE;
|
||||
kp->value_ = DEVICE_CAR;
|
||||
kp->InitStr();
|
||||
keyParams.push_back(kp);
|
||||
kp = new KeyParam();
|
||||
kp->type_ = DIRECTION;
|
||||
kp->value_ = DIRECTION_VERTICAL;
|
||||
kp->InitStr();
|
||||
keyParams.push_back(kp);
|
||||
kp = new KeyParam();
|
||||
kp->type_ = COLORMODE;
|
||||
kp->value_ = DARK;
|
||||
kp->InitStr();
|
||||
keyParams.push_back(kp);
|
||||
keyParams.push_back(kp2);
|
||||
auto kp3 = std::make_shared<KeyParam>();
|
||||
kp3->type_ = DEVICETYPE;
|
||||
kp3->value_ = DEVICE_CAR;
|
||||
kp3->InitStr();
|
||||
keyParams.push_back(kp3);
|
||||
auto kp4 = std::make_shared<KeyParam>();
|
||||
kp4->type_ = DIRECTION;
|
||||
kp4->value_ = DIRECTION_VERTICAL;
|
||||
kp4->InitStr();
|
||||
keyParams.push_back(kp4);
|
||||
auto kp5 = std::make_shared<KeyParam>();
|
||||
kp5->type_ = COLORMODE;
|
||||
kp5->value_ = DARK;
|
||||
kp5->InitStr();
|
||||
keyParams.push_back(kp5);
|
||||
auto config = HapParser::CreateResConfigFromKeyParams(keyParams);
|
||||
if (config != nullptr) {
|
||||
EXPECT_EQ(std::string("zh"), config->GetLocaleInfo()->getLanguage());
|
||||
@ -110,11 +110,7 @@ HWTEST_F(HapParserTest, HapParserFuncTest001, TestSize.Level1)
|
||||
} else {
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
|
||||
for (auto kp = keyParams.begin(); kp != keyParams.end(); kp++) {
|
||||
delete *kp;
|
||||
}
|
||||
delete config;
|
||||
keyParams.clear();
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -157,42 +153,40 @@ HWTEST_F(HapParserTest, HapParserFuncTest003, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(HapParserTest, HapParserFuncTest004, TestSize.Level1)
|
||||
{
|
||||
std::vector<KeyParam *> keyParams;
|
||||
auto kp = new KeyParam();
|
||||
kp->type_ = LANGUAGES;
|
||||
kp->value_ = 31336;
|
||||
kp->InitStr();
|
||||
keyParams.push_back(kp);
|
||||
kp = new KeyParam();
|
||||
kp->type_ = REGION;
|
||||
kp->value_ = 17230;
|
||||
kp->InitStr();
|
||||
keyParams.push_back(kp);
|
||||
kp = new KeyParam();
|
||||
kp->type_ = SCREEN_DENSITY;
|
||||
kp->value_ = SCREEN_DENSITY_SDPI;
|
||||
kp->InitStr();
|
||||
keyParams.push_back(kp);
|
||||
kp = new KeyParam();
|
||||
kp->type_ = DEVICETYPE;
|
||||
kp->value_ = DEVICE_CAR;
|
||||
kp->InitStr();
|
||||
keyParams.push_back(kp);
|
||||
kp = new KeyParam();
|
||||
kp->type_ = DIRECTION;
|
||||
kp->value_ = DIRECTION_VERTICAL;
|
||||
kp->InitStr();
|
||||
keyParams.push_back(kp);
|
||||
kp = new KeyParam();
|
||||
kp->type_ = COLORMODE;
|
||||
kp->value_ = DARK;
|
||||
kp->InitStr();
|
||||
keyParams.push_back(kp);
|
||||
std::vector<std::shared_ptr<KeyParam>> keyParams;
|
||||
auto kp1 = std::make_shared<KeyParam>();
|
||||
kp1->type_ = LANGUAGES;
|
||||
kp1->value_ = 31336;
|
||||
kp1->InitStr();
|
||||
keyParams.push_back(kp1);
|
||||
auto kp2 = std::make_shared<KeyParam>();
|
||||
kp2->type_ = REGION;
|
||||
kp2->value_ = 17230;
|
||||
kp2->InitStr();
|
||||
keyParams.push_back(kp2);
|
||||
auto kp3 = std::make_shared<KeyParam>();
|
||||
kp3->type_ = SCREEN_DENSITY;
|
||||
kp3->value_ = SCREEN_DENSITY_SDPI;
|
||||
kp3->InitStr();
|
||||
keyParams.push_back(kp3);
|
||||
auto kp4 = std::make_shared<KeyParam>();
|
||||
kp4->type_ = DEVICETYPE;
|
||||
kp4->value_ = DEVICE_CAR;
|
||||
kp4->InitStr();
|
||||
keyParams.push_back(kp4);
|
||||
auto kp5 = std::make_shared<KeyParam>();
|
||||
kp5->type_ = DIRECTION;
|
||||
kp5->value_ = DIRECTION_VERTICAL;
|
||||
kp5->InitStr();
|
||||
keyParams.push_back(kp5);
|
||||
auto kp6 = std::make_shared<KeyParam>();
|
||||
kp6->type_ = COLORMODE;
|
||||
kp6->value_ = DARK;
|
||||
kp6->InitStr();
|
||||
keyParams.push_back(kp6);
|
||||
std::string folder = HapParser::ToFolderPath(keyParams);
|
||||
ASSERT_EQ("zh_CN-vertical-car-dark-sdpi", folder);
|
||||
for (auto kp = keyParams.begin(); kp != keyParams.end(); kp++) {
|
||||
delete *kp;
|
||||
}
|
||||
keyParams.clear();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -62,7 +62,8 @@ void HapResourceTest::TearDown()
|
||||
// step 4: input testcase teardown step
|
||||
}
|
||||
|
||||
void TestGetIdValuesByName(const HapResource *pResource)
|
||||
//void TestGetIdValuesByName(const HapResource *pResource)
|
||||
void TestGetIdValuesByName(const std::shared_ptr<HapResource> pResource)
|
||||
{
|
||||
std::string name = std::string("app_name");
|
||||
auto start = CurrentTimeUsec();
|
||||
@ -101,7 +102,7 @@ void TestGetIdValuesByName(const HapResource *pResource)
|
||||
HWTEST_F(HapResourceTest, HapResourceFuncTest001, TestSize.Level0)
|
||||
{
|
||||
auto start = CurrentTimeUsec();
|
||||
const HapResource *pResource = HapResource::LoadFromIndex(FormatFullPath(g_resFilePath).c_str(), nullptr);
|
||||
auto pResource = HapResource::LoadFromIndex(FormatFullPath(g_resFilePath).c_str(), nullptr);
|
||||
auto cost = CurrentTimeUsec() - start;
|
||||
HILOG_DEBUG("load cost: %ld us.", cost);
|
||||
|
||||
@ -136,11 +137,10 @@ HWTEST_F(HapResourceTest, HapResourceFuncTest001, TestSize.Level0)
|
||||
EXPECT_TRUE(limitPath->GetIdItem()->value_ == "应用名称");
|
||||
}
|
||||
TestGetIdValuesByName(pResource);
|
||||
|
||||
delete (pResource);
|
||||
}
|
||||
|
||||
void GetIdValuesByNameFuncTest002(const HapResource *pResource, int id)
|
||||
//void GetIdValuesByNameFuncTest002(const HapResource *pResource, int id)
|
||||
void GetIdValuesByNameFuncTest002(const std::shared_ptr<HapResource> pResource, int id)
|
||||
{
|
||||
std::string name = std::string("app_name");
|
||||
auto start = CurrentTimeUsec();
|
||||
@ -172,18 +172,17 @@ void GetIdValuesByNameFuncTest002(const HapResource *pResource, int id)
|
||||
*/
|
||||
HWTEST_F(HapResourceTest, HapResourceFuncTest002, TestSize.Level1)
|
||||
{
|
||||
ResConfigImpl *rc = new ResConfigImpl;
|
||||
auto rc = std::make_shared<ResConfigImpl>();
|
||||
rc->SetLocaleInfo("en", nullptr, "US");
|
||||
std::string resPath = FormatFullPath(g_resFilePath);
|
||||
const char *path = resPath.c_str();
|
||||
|
||||
auto start = CurrentTimeUsec();
|
||||
const HapResource *pResource = HapResource::LoadFromIndex(path, rc);
|
||||
auto pResource = HapResource::LoadFromIndex(path, rc);
|
||||
auto cost = CurrentTimeUsec() - start;
|
||||
HILOG_DEBUG("load cost: %ld us.", cost);
|
||||
|
||||
if (pResource == nullptr) {
|
||||
delete rc;
|
||||
EXPECT_TRUE(false);
|
||||
return;
|
||||
}
|
||||
@ -210,8 +209,6 @@ HWTEST_F(HapResourceTest, HapResourceFuncTest002, TestSize.Level1)
|
||||
}
|
||||
|
||||
GetIdValuesByNameFuncTest002(pResource, id);
|
||||
delete pResource;
|
||||
delete rc;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -223,7 +220,7 @@ HWTEST_F(HapResourceTest, HapResourceFuncTest002, TestSize.Level1)
|
||||
HWTEST_F(HapResourceTest, HapResourceFuncTest003, TestSize.Level1)
|
||||
{
|
||||
auto start = CurrentTimeUsec();
|
||||
const HapResource *pResource = HapResource::LoadFromIndex(FormatFullPath(g_resFilePath).c_str(), nullptr);
|
||||
auto pResource = HapResource::LoadFromIndex(FormatFullPath(g_resFilePath).c_str(), nullptr);
|
||||
auto cost = CurrentTimeUsec() - start;
|
||||
HILOG_DEBUG("load cost: %ld us.", cost);
|
||||
|
||||
@ -260,7 +257,7 @@ HWTEST_F(HapResourceTest, HapResourceFuncTest003, TestSize.Level1)
|
||||
PrintIdValues(idv);
|
||||
}
|
||||
|
||||
ResDesc *LoadFromHap(const char *hapPath, const ResConfigImpl *defaultConfig)
|
||||
ResDesc *LoadFromHap(const char *hapPath, const std::shared_ptr<ResConfigImpl> defaultConfig)
|
||||
{
|
||||
std::unique_ptr<uint8_t[]> buf;
|
||||
size_t bufLen;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -63,16 +63,13 @@ void ResConfigTest::TearDown()
|
||||
*/
|
||||
HWTEST_F(ResConfigTest, ResConfigFuncTest001, TestSize.Level1)
|
||||
{
|
||||
ResConfigImpl *rc = new ResConfigImpl;
|
||||
auto rc = std::make_shared<ResConfigImpl>();
|
||||
rc->SetLocaleInfo("en", nullptr, "AU");
|
||||
ResConfigImpl *current = new ResConfigImpl;
|
||||
auto current = std::make_shared<ResConfigImpl>();
|
||||
current->SetLocaleInfo("en", nullptr, "GB");
|
||||
ResConfigImpl *target = new ResConfigImpl;
|
||||
auto target = std::make_shared<ResConfigImpl>();
|
||||
target->SetLocaleInfo("zh", nullptr, "CN");
|
||||
EXPECT_TRUE(rc->Match(current));
|
||||
EXPECT_TRUE(!(rc->Match(target)));
|
||||
delete target;
|
||||
delete current;
|
||||
delete rc;
|
||||
};
|
||||
}
|
@ -115,7 +115,7 @@ int ParseIndexCost(const std::string &pstr, char *buf, const size_t& bufLen)
|
||||
long long total = 0;
|
||||
for (int k = 0; k < 1000; ++k) {
|
||||
auto t1 = std::chrono::high_resolution_clock::now();
|
||||
ResDesc *resDesc = new(std::nothrow) ResDesc();
|
||||
auto resDesc = std::make_shared<ResDesc>();
|
||||
if (resDesc == nullptr) {
|
||||
HILOG_ERROR("new ResDesc failed when LoadFromIndex");
|
||||
free(buf);
|
||||
@ -123,7 +123,6 @@ int ParseIndexCost(const std::string &pstr, char *buf, const size_t& bufLen)
|
||||
}
|
||||
int32_t out = HapParser::ParseResHex((char *)buf, bufLen, *resDesc, nullptr);
|
||||
if (out != OK) {
|
||||
delete (resDesc);
|
||||
free(buf);
|
||||
HILOG_ERROR("ParseResHex failed! retcode:%d", out);
|
||||
return -1;
|
||||
@ -131,21 +130,18 @@ int ParseIndexCost(const std::string &pstr, char *buf, const size_t& bufLen)
|
||||
HILOG_DEBUG("ParseResHex success:\n%s", resDesc->ToString().c_str());
|
||||
}
|
||||
|
||||
HapResource *pResource = new(std::nothrow) HapResource(pstr, 0, resDesc);
|
||||
auto pResource = new(std::nothrow) HapResource(pstr, 0, resDesc);
|
||||
if (pResource == nullptr) {
|
||||
HILOG_ERROR("new HapResource failed when LoadFromIndex");
|
||||
delete (resDesc);
|
||||
free(buf);
|
||||
return -1;
|
||||
}
|
||||
if (!pResource->Init()) {
|
||||
delete (pResource);
|
||||
free(buf);
|
||||
return -1;
|
||||
}
|
||||
auto t2 = std::chrono::high_resolution_clock::now();
|
||||
total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
|
||||
delete pResource;
|
||||
}
|
||||
double average = total / 1000.0;
|
||||
g_logLevel = LOG_DEBUG;
|
||||
|
@ -267,7 +267,7 @@ HWTEST_F(ResourceManagerTest, ResourceManagerUpdateResConfigTest005, TestSize.Le
|
||||
rmc->AddResource("zh", nullptr, nullptr);
|
||||
|
||||
// make a fake hapResource, then reload will fail
|
||||
HapResource *hapResource = new HapResource("/data/test/non_exist", 0, nullptr);
|
||||
auto hapResource = std::make_shared<HapResource>("/data/test/non_exist", 0, nullptr);
|
||||
((ResourceManagerImpl *)rm)->hapManager_->hapResources_.push_back(hapResource);
|
||||
((ResourceManagerImpl *)rm)->hapManager_->loadedHapPaths_["/data/test/non_exist"] = std::vector<std::string>();
|
||||
RState state;
|
||||
@ -1769,12 +1769,11 @@ HWTEST_F(ResourceManagerTest, ResourceManagerResolveParentReferenceTest001, Test
|
||||
rm->AddResource(FormatFullPath(g_resFilePath).c_str());
|
||||
int id;
|
||||
std::map<std::string, std::string> outValue;
|
||||
const IdItem *idItem;
|
||||
RState ret;
|
||||
|
||||
id = rmc->GetResId("base", ResType::PATTERN);
|
||||
EXPECT_TRUE(id > 0);
|
||||
idItem = ((ResourceManagerImpl *)rm)->hapManager_->FindResourceById(id);
|
||||
auto idItem = ((ResourceManagerImpl *)rm)->hapManager_->FindResourceById(id);
|
||||
ASSERT_TRUE(idItem != nullptr);
|
||||
ret = ((ResourceManagerImpl *)rm)->ResolveParentReference(idItem, outValue);
|
||||
ASSERT_EQ(SUCCESS, ret);
|
||||
|
@ -39,7 +39,7 @@ std::string FormatFullPath(const char *fileRelativePath)
|
||||
return result;
|
||||
}
|
||||
|
||||
void PrintIdValues(const HapResource::IdValues *idValues)
|
||||
void PrintIdValues(const std::shared_ptr<HapResource::IdValues> &idValues)
|
||||
{
|
||||
if (idValues == nullptr) {
|
||||
return;
|
||||
|
@ -38,7 +38,7 @@ static const float BASE_DPI = 160.0f;
|
||||
static const int NON_EXIST_ID = 1111;
|
||||
std::string FormatFullPath(const char *fileRelativePath);
|
||||
|
||||
void PrintIdValues(const HapResource::IdValues *idValues);
|
||||
void PrintIdValues(const std::shared_ptr<HapResource::IdValues> &idValues);
|
||||
|
||||
void PrintMapString(const std::map<std::string, std::string> &value);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user