1 /*
2 * Copyright (C) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #define MLOG_TAG "DfxReporter"
16
17 #include "dfx_reporter.h"
18
19 #include <cinttypes>
20 #include "dfx_const.h"
21 #include "dfx_manager.h"
22 #include "hisysevent.h"
23 #include "preferences_helper.h"
24 #include "ringtone_file_utils.h"
25 #include "ringtone_log.h"
26
27 namespace OHOS {
28 namespace Media {
29 using namespace std;
30 static constexpr char RINGTONE_LIBRARY[] = "RINGTONE_LIBRARY";
31
DfxReporter()32 DfxReporter::DfxReporter()
33 {
34 }
35
~DfxReporter()36 DfxReporter::~DfxReporter()
37 {
38 }
39
ReportDfxMessage()40 void DfxReporter::ReportDfxMessage()
41 {
42 int32_t errCode;
43 shared_ptr<NativePreferences::Preferences> prefs =
44 NativePreferences::PreferencesHelper::GetPreferences(DFX_COMMON_XML, errCode);
45 if (!prefs) {
46 RINGTONE_ERR_LOG("get preferences error: %{public}d", errCode);
47 return;
48 }
49 std::string date = RingtoneFileUtils::StrCreateTimeByMilliseconds(DATE_FORMAT,
50 RingtoneFileUtils::UTCTimeMilliSeconds());
51 int64_t presetNum = DfxManager::GetInstance()->RequestTonesCount(SourceType::SOURCE_TYPE_PRESET);
52 int64_t customNum = DfxManager::GetInstance()->RequestTonesCount(SourceType::SOURCE_TYPE_CUSTOMISED);
53 RINGTONE_INFO_LOG("presetNum:%{public}" PRId64 ", customNum:%{public}" PRId64, presetNum, customNum);
54
55 int ret = HiSysEventWrite(
56 RINGTONE_LIBRARY,
57 "RINGTONELIB_DFX_MESSAGE",
58 HiviewDFX::HiSysEvent::EventType::STATISTIC,
59 "DATE", date,
60 "PRESET_NUM", presetNum,
61 "CUSTOM_NUM", customNum);
62 if (ret != 0) {
63 RINGTONE_ERR_LOG("ReportDfxMessage error:%{public}d", ret);
64 }
65 prefs->FlushSync();
66 }
67 } // namespace Media
68 } // namespace OHOS
69