2 * Copyright (c) 2014, Ford Motor Company
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following
13 * disclaimer in the documentation and/or other materials provided with the
16 * Neither the name of the Ford Motor Company nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
33 #include "application_manager/usage_statistics.h"
35 #include "smart_objects/smart_object.h"
36 #include "smart_objects/enum_schema_item.h"
37 #include "usage_statistics/statistics_manager.h"
38 #include "utils/macro.h"
40 using namespace mobile_apis;
41 using namespace NsSmartDeviceLink::NsSmartObjects;
42 using namespace usage_statistics;
44 namespace application_manager {
48 std::string LanguageIdToString(Language::eType lang_id) {
49 typedef std::map<Language::eType, std::string> EnumMap;
50 const EnumMap& enum_map =
51 TEnumSchemaItem<Language::eType>::getEnumElementsStringRepresentation();
52 EnumMap::const_iterator found = enum_map.find(lang_id);
53 if (found != enum_map.end()) {
62 UsageStatistics::UsageStatistics(
63 const std::string& app_id,
64 usage_statistics::StatisticsManager* statistics_manager)
65 : time_in_hmi_state_(statistics_manager, app_id),
66 app_registration_language_gui_(statistics_manager, app_id, LANGUAGE_GUI),
67 app_registration_language_vui_(statistics_manager, app_id, LANGUAGE_VUI),
68 count_of_rejected_rpc_calls_(statistics_manager, app_id,
70 count_of_rpcs_sent_in_hmi_none_(statistics_manager, app_id,
72 count_of_user_selections_(statistics_manager, app_id, USER_SELECTIONS),
73 count_of_run_attempts_while_revoked_(statistics_manager, app_id,
74 RUN_ATTEMPTS_WHILE_REVOKED),
75 count_of_removals_for_bad_behavior_(statistics_manager, app_id,
76 REMOVALS_MISBEHAVED) {
77 time_in_hmi_state_.Start(SECONDS_HMI_NONE);
80 void UsageStatistics::RecordHmiStateChanged(HMILevel::eType new_hmi_level) {
81 using namespace mobile_apis::HMILevel;
82 AppStopwatchId next_stopwatch = SECONDS_HMI_NONE;
83 switch (new_hmi_level) {
85 next_stopwatch = SECONDS_HMI_FULL;
88 next_stopwatch = SECONDS_HMI_LIMITED;
91 next_stopwatch = SECONDS_HMI_BACKGROUND;
94 next_stopwatch = SECONDS_HMI_NONE;
100 time_in_hmi_state_.Switch(next_stopwatch);
103 void UsageStatistics::RecordAppRegistrationGuiLanguage(
104 Language::eType gui_language) {
105 app_registration_language_gui_.Update(LanguageIdToString(gui_language));
108 void UsageStatistics::RecordAppRegistrationVuiLanguage(
109 Language::eType vui_language) {
110 app_registration_language_gui_.Update(LanguageIdToString(vui_language));
113 void UsageStatistics::RecordRpcSentInHMINone() {
114 ++count_of_rpcs_sent_in_hmi_none_;
117 void UsageStatistics::RecordPolicyRejectedRpcCall() {
118 ++count_of_rejected_rpc_calls_;
121 void UsageStatistics::RecordAppUserSelection() {
122 ++count_of_user_selections_;
125 void UsageStatistics::RecordRunAttemptsWhileRevoked() {
126 ++count_of_run_attempts_while_revoked_;
129 void UsageStatistics::RecordRemovalsForBadBehavior() {
130 ++count_of_removals_for_bad_behavior_;
133 } // namespace application_manager