Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "config/ConfigManager.h" |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 18 | #include "storage/StorageManager.h" |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 19 | |
| 20 | #include "stats_util.h" |
| 21 | |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 22 | #include <android-base/file.h> |
| 23 | #include <dirent.h> |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 24 | #include <stdio.h> |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 25 | #include <vector> |
| 26 | #include "android-base/stringprintf.h" |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 27 | |
| 28 | namespace android { |
| 29 | namespace os { |
| 30 | namespace statsd { |
| 31 | |
Yao Chen | f09569f | 2017-12-13 17:00:51 -0800 | [diff] [blame] | 32 | using std::map; |
| 33 | using std::pair; |
| 34 | using std::set; |
| 35 | using std::string; |
| 36 | using std::vector; |
| 37 | |
yro | 03faf09 | 2017-12-12 00:17:50 -0800 | [diff] [blame] | 38 | #define STATS_SERVICE_DIR "/data/misc/stats-service" |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 39 | |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 40 | using android::base::StringPrintf; |
| 41 | using std::unique_ptr; |
| 42 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 43 | ConfigManager::ConfigManager() { |
| 44 | } |
| 45 | |
| 46 | ConfigManager::~ConfigManager() { |
| 47 | } |
| 48 | |
| 49 | void ConfigManager::Startup() { |
Yao Chen | f09569f | 2017-12-13 17:00:51 -0800 | [diff] [blame] | 50 | map<ConfigKey, StatsdConfig> configsFromDisk; |
| 51 | StorageManager::readConfigFromDisk(configsFromDisk); |
yro | 469cd80 | 2018-01-04 14:57:45 -0800 | [diff] [blame] | 52 | for (const auto& pair : configsFromDisk) { |
| 53 | UpdateConfig(pair.first, pair.second); |
| 54 | } |
| 55 | } |
Yao Chen | 3c0b95c | 2017-12-16 14:34:20 -0800 | [diff] [blame] | 56 | |
yro | 469cd80 | 2018-01-04 14:57:45 -0800 | [diff] [blame] | 57 | void ConfigManager::StartupForTest() { |
| 58 | // Dummy function to avoid reading configs from disks for tests. |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | void ConfigManager::AddListener(const sp<ConfigListener>& listener) { |
| 62 | mListeners.push_back(listener); |
| 63 | } |
| 64 | |
| 65 | void ConfigManager::UpdateConfig(const ConfigKey& key, const StatsdConfig& config) { |
Yao Chen | f09569f | 2017-12-13 17:00:51 -0800 | [diff] [blame] | 66 | // Add to set |
| 67 | mConfigs.insert(key); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 68 | |
| 69 | // Save to disk |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 70 | update_saved_configs(key, config); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 71 | |
| 72 | // Tell everyone |
| 73 | for (auto& listener : mListeners) { |
| 74 | listener->OnConfigUpdated(key, config); |
| 75 | } |
| 76 | } |
| 77 | |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 78 | void ConfigManager::SetConfigReceiver(const ConfigKey& key, const sp<IBinder>& intentSender) { |
| 79 | mConfigReceivers[key] = intentSender; |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | void ConfigManager::RemoveConfigReceiver(const ConfigKey& key) { |
| 83 | mConfigReceivers.erase(key); |
| 84 | } |
| 85 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 86 | void ConfigManager::RemoveConfig(const ConfigKey& key) { |
Yao Chen | f09569f | 2017-12-13 17:00:51 -0800 | [diff] [blame] | 87 | auto it = mConfigs.find(key); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 88 | if (it != mConfigs.end()) { |
| 89 | // Remove from map |
| 90 | mConfigs.erase(it); |
| 91 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 92 | // Tell everyone |
| 93 | for (auto& listener : mListeners) { |
| 94 | listener->OnConfigRemoved(key); |
| 95 | } |
| 96 | } |
yro | 9c98c05 | 2017-11-19 14:33:56 -0800 | [diff] [blame] | 97 | |
| 98 | // Remove from disk. There can still be a lingering file on disk so we check |
| 99 | // whether or not the config was on memory. |
| 100 | remove_saved_configs(key); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 101 | } |
| 102 | |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 103 | void ConfigManager::remove_saved_configs(const ConfigKey& key) { |
yro | e5f8292 | 2018-01-22 18:37:27 -0800 | [diff] [blame] | 104 | string suffix = StringPrintf("%d-%lld", key.GetUid(), (long long)key.GetId()); |
| 105 | StorageManager::deleteSuffixedFiles(STATS_SERVICE_DIR, suffix.c_str()); |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 106 | } |
| 107 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 108 | void ConfigManager::RemoveConfigs(int uid) { |
| 109 | vector<ConfigKey> removed; |
| 110 | |
| 111 | for (auto it = mConfigs.begin(); it != mConfigs.end();) { |
| 112 | // Remove from map |
Yao Chen | f09569f | 2017-12-13 17:00:51 -0800 | [diff] [blame] | 113 | if (it->GetUid() == uid) { |
yro | e5f8292 | 2018-01-22 18:37:27 -0800 | [diff] [blame] | 114 | remove_saved_configs(*it); |
Yao Chen | f09569f | 2017-12-13 17:00:51 -0800 | [diff] [blame] | 115 | removed.push_back(*it); |
| 116 | mConfigReceivers.erase(*it); |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 117 | it = mConfigs.erase(it); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 118 | } else { |
| 119 | it++; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | // Remove separately so if they do anything in the callback they can't mess up our iteration. |
| 124 | for (auto& key : removed) { |
| 125 | // Tell everyone |
| 126 | for (auto& listener : mListeners) { |
| 127 | listener->OnConfigRemoved(key); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 132 | void ConfigManager::RemoveAllConfigs() { |
| 133 | vector<ConfigKey> removed; |
| 134 | |
| 135 | for (auto it = mConfigs.begin(); it != mConfigs.end();) { |
| 136 | // Remove from map |
Yao Chen | f09569f | 2017-12-13 17:00:51 -0800 | [diff] [blame] | 137 | removed.push_back(*it); |
| 138 | auto receiverIt = mConfigReceivers.find(*it); |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 139 | if (receiverIt != mConfigReceivers.end()) { |
Yao Chen | f09569f | 2017-12-13 17:00:51 -0800 | [diff] [blame] | 140 | mConfigReceivers.erase(*it); |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 141 | } |
| 142 | it = mConfigs.erase(it); |
| 143 | } |
| 144 | |
| 145 | // Remove separately so if they do anything in the callback they can't mess up our iteration. |
| 146 | for (auto& key : removed) { |
| 147 | // Tell everyone |
| 148 | for (auto& listener : mListeners) { |
| 149 | listener->OnConfigRemoved(key); |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
Yangster | 7c334a1 | 2017-11-22 14:24:24 -0800 | [diff] [blame] | 154 | vector<ConfigKey> ConfigManager::GetAllConfigKeys() const { |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 155 | vector<ConfigKey> ret; |
| 156 | for (auto it = mConfigs.cbegin(); it != mConfigs.cend(); ++it) { |
Yao Chen | f09569f | 2017-12-13 17:00:51 -0800 | [diff] [blame] | 157 | ret.push_back(*it); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 158 | } |
| 159 | return ret; |
| 160 | } |
| 161 | |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 162 | const sp<android::IBinder> ConfigManager::GetConfigReceiver(const ConfigKey& key) const { |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 163 | auto it = mConfigReceivers.find(key); |
| 164 | if (it == mConfigReceivers.end()) { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 165 | return nullptr; |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 166 | } else { |
| 167 | return it->second; |
| 168 | } |
| 169 | } |
| 170 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 171 | void ConfigManager::Dump(FILE* out) { |
| 172 | fprintf(out, "CONFIGURATIONS (%d)\n", (int)mConfigs.size()); |
| 173 | fprintf(out, " uid name\n"); |
Yao Chen | f09569f | 2017-12-13 17:00:51 -0800 | [diff] [blame] | 174 | for (const auto& key : mConfigs) { |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 175 | fprintf(out, " %6d %lld\n", key.GetUid(), (long long)key.GetId()); |
Yao Chen | f09569f | 2017-12-13 17:00:51 -0800 | [diff] [blame] | 176 | auto receiverIt = mConfigReceivers.find(key); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 177 | if (receiverIt != mConfigReceivers.end()) { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 178 | fprintf(out, " -> received by PendingIntent as binder\n"); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 179 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 183 | void ConfigManager::update_saved_configs(const ConfigKey& key, const StatsdConfig& config) { |
yro | 9c98c05 | 2017-11-19 14:33:56 -0800 | [diff] [blame] | 184 | // If there is a pre-existing config with same key we should first delete it. |
| 185 | remove_saved_configs(key); |
| 186 | |
| 187 | // Then we save the latest config. |
yro | 98a2850 | 2018-01-18 17:00:14 -0800 | [diff] [blame] | 188 | string file_name = StringPrintf("%s/%ld_%d_%lld", STATS_SERVICE_DIR, time(nullptr), |
| 189 | key.GetUid(), (long long)key.GetId()); |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 190 | const int numBytes = config.ByteSize(); |
| 191 | vector<uint8_t> buffer(numBytes); |
| 192 | config.SerializeToArray(&buffer[0], numBytes); |
| 193 | StorageManager::writeFile(file_name.c_str(), &buffer[0], numBytes); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Yangster-mac | 756cd48 | 2017-11-21 21:58:44 -0800 | [diff] [blame] | 196 | StatsdConfig build_fake_config() { |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 197 | // HACK: Hard code a test metric for counting screen on events... |
| 198 | StatsdConfig config; |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 199 | config.set_id(12345); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 200 | |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 201 | int WAKE_LOCK_TAG_ID = 1111; // put a fake id here to make testing easier. |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 202 | int WAKE_LOCK_UID_KEY_ID = 1; |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 203 | int WAKE_LOCK_NAME_KEY = 3; |
| 204 | int WAKE_LOCK_STATE_KEY = 4; |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 205 | int WAKE_LOCK_ACQUIRE_VALUE = 1; |
| 206 | int WAKE_LOCK_RELEASE_VALUE = 0; |
| 207 | |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 208 | int APP_USAGE_TAG_ID = 12345; |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 209 | int APP_USAGE_UID_KEY_ID = 1; |
| 210 | int APP_USAGE_STATE_KEY = 2; |
| 211 | int APP_USAGE_FOREGROUND = 1; |
| 212 | int APP_USAGE_BACKGROUND = 0; |
| 213 | |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 214 | int SCREEN_EVENT_TAG_ID = 29; |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 215 | int SCREEN_EVENT_STATE_KEY = 1; |
| 216 | int SCREEN_EVENT_ON_VALUE = 2; |
| 217 | int SCREEN_EVENT_OFF_VALUE = 1; |
| 218 | |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 219 | int UID_PROCESS_STATE_TAG_ID = 27; |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 220 | int UID_PROCESS_STATE_UID_KEY = 1; |
| 221 | |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 222 | int KERNEL_WAKELOCK_TAG_ID = 1004; |
Chenjie Yu | 6842a8c | 2017-12-05 22:34:34 -0800 | [diff] [blame] | 223 | int KERNEL_WAKELOCK_COUNT_KEY = 2; |
| 224 | int KERNEL_WAKELOCK_NAME_KEY = 1; |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 225 | |
Yangster | 1d4d686 | 2017-10-31 12:58:51 -0700 | [diff] [blame] | 226 | int DEVICE_TEMPERATURE_TAG_ID = 33; |
| 227 | int DEVICE_TEMPERATURE_KEY = 1; |
| 228 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 229 | // Count Screen ON events. |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 230 | CountMetric* metric = config.add_count_metric(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 231 | metric->set_id(1); // METRIC_1 |
| 232 | metric->set_what(102); // "SCREEN_TURNED_ON" |
Yangster-mac | b814481 | 2018-01-04 10:56:23 -0800 | [diff] [blame] | 233 | metric->set_bucket(ONE_MINUTE); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 234 | |
Bookatz | d3606c7 | 2017-10-19 10:13:49 -0700 | [diff] [blame] | 235 | // Anomaly threshold for screen-on count. |
Yao Chen | f09569f | 2017-12-13 17:00:51 -0800 | [diff] [blame] | 236 | // TODO(b/70627390): Uncomment once the bug is fixed. |
| 237 | /*Alert* alert = config.add_alert(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 238 | alert->set_id("ALERT_1"); |
Stefan Lafon | 7c8f0a5 | 2017-11-21 14:49:09 -0800 | [diff] [blame] | 239 | alert->set_metric_name("METRIC_1"); |
Bookatz | d3606c7 | 2017-10-19 10:13:49 -0700 | [diff] [blame] | 240 | alert->set_number_of_buckets(6); |
| 241 | alert->set_trigger_if_sum_gt(10); |
| 242 | alert->set_refractory_period_secs(30); |
Bookatz | d1fd242 | 2017-11-22 15:21:03 -0800 | [diff] [blame] | 243 | Alert::IncidentdDetails* details = alert->mutable_incidentd_details(); |
| 244 | details->add_section(12); |
Yao Chen | f09569f | 2017-12-13 17:00:51 -0800 | [diff] [blame] | 245 | details->add_section(13);*/ |
Bookatz | d3606c7 | 2017-10-19 10:13:49 -0700 | [diff] [blame] | 246 | |
Yao Chen | 147ce60 | 2017-12-22 14:35:34 -0800 | [diff] [blame] | 247 | config.add_allowed_log_source("AID_ROOT"); |
| 248 | config.add_allowed_log_source("AID_SYSTEM"); |
| 249 | config.add_allowed_log_source("AID_BLUETOOTH"); |
| 250 | config.add_allowed_log_source("com.android.statsd.dogfood"); |
| 251 | config.add_allowed_log_source("com.android.systemui"); |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 252 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 253 | // Count process state changes, slice by uid. |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 254 | metric = config.add_count_metric(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 255 | metric->set_id(2); // "METRIC_2" |
| 256 | metric->set_what(104); |
Yangster-mac | b814481 | 2018-01-04 10:56:23 -0800 | [diff] [blame] | 257 | metric->set_bucket(ONE_MINUTE); |
Yangster-mac | 468ff04 | 2018-01-17 12:26:34 -0800 | [diff] [blame] | 258 | FieldMatcher* dimensions = metric->mutable_dimensions_in_what(); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 259 | dimensions->set_field(UID_PROCESS_STATE_TAG_ID); |
| 260 | dimensions->add_child()->set_field(UID_PROCESS_STATE_UID_KEY); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 261 | |
Yang Lu | 3eba621 | 2017-10-25 19:54:45 -0700 | [diff] [blame] | 262 | // Anomaly threshold for background count. |
Yao Chen | f09569f | 2017-12-13 17:00:51 -0800 | [diff] [blame] | 263 | // TODO(b/70627390): Uncomment once the bug is fixed. |
| 264 | /* |
Stefan Lafon | cfed20b | 2017-11-18 09:26:53 -0800 | [diff] [blame] | 265 | alert = config.add_alert(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 266 | alert->set_id("ALERT_2"); |
Stefan Lafon | 7c8f0a5 | 2017-11-21 14:49:09 -0800 | [diff] [blame] | 267 | alert->set_metric_name("METRIC_2"); |
Yang Lu | 3eba621 | 2017-10-25 19:54:45 -0700 | [diff] [blame] | 268 | alert->set_number_of_buckets(4); |
| 269 | alert->set_trigger_if_sum_gt(30); |
| 270 | alert->set_refractory_period_secs(20); |
Bookatz | d1fd242 | 2017-11-22 15:21:03 -0800 | [diff] [blame] | 271 | details = alert->mutable_incidentd_details(); |
| 272 | details->add_section(14); |
Yao Chen | f09569f | 2017-12-13 17:00:51 -0800 | [diff] [blame] | 273 | details->add_section(15);*/ |
Yang Lu | 3eba621 | 2017-10-25 19:54:45 -0700 | [diff] [blame] | 274 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 275 | // Count process state changes, slice by uid, while SCREEN_IS_OFF |
| 276 | metric = config.add_count_metric(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 277 | metric->set_id(3); |
| 278 | metric->set_what(104); |
Yangster-mac | b814481 | 2018-01-04 10:56:23 -0800 | [diff] [blame] | 279 | metric->set_bucket(ONE_MINUTE); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 280 | |
Yangster-mac | 468ff04 | 2018-01-17 12:26:34 -0800 | [diff] [blame] | 281 | dimensions = metric->mutable_dimensions_in_what(); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 282 | dimensions->set_field(UID_PROCESS_STATE_TAG_ID); |
| 283 | dimensions->add_child()->set_field(UID_PROCESS_STATE_UID_KEY); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 284 | metric->set_condition(202); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 285 | |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 286 | // Count wake lock, slice by uid, while SCREEN_IS_ON and app in background |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 287 | metric = config.add_count_metric(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 288 | metric->set_id(4); |
| 289 | metric->set_what(107); |
Yangster-mac | b814481 | 2018-01-04 10:56:23 -0800 | [diff] [blame] | 290 | metric->set_bucket(ONE_MINUTE); |
Yangster-mac | 468ff04 | 2018-01-17 12:26:34 -0800 | [diff] [blame] | 291 | dimensions = metric->mutable_dimensions_in_what(); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 292 | dimensions->set_field(WAKE_LOCK_TAG_ID); |
| 293 | dimensions->add_child()->set_field(WAKE_LOCK_UID_KEY_ID); |
| 294 | |
| 295 | |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 296 | metric->set_condition(204); |
Stefan Lafon | a5b5191 | 2017-12-05 21:43:52 -0800 | [diff] [blame] | 297 | MetricConditionLink* link = metric->add_links(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 298 | link->set_condition(203); |
Yangster-mac | 2c6dc47 | 2018-01-18 16:17:43 -0800 | [diff] [blame] | 299 | link->mutable_fields_in_what()->set_field(WAKE_LOCK_TAG_ID); |
| 300 | link->mutable_fields_in_what()->add_child()->set_field(WAKE_LOCK_UID_KEY_ID); |
| 301 | link->mutable_fields_in_condition()->set_field(APP_USAGE_TAG_ID); |
| 302 | link->mutable_fields_in_condition()->add_child()->set_field(APP_USAGE_UID_KEY_ID); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 303 | |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 304 | // Duration of an app holding any wl, while screen on and app in background, slice by uid |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 305 | DurationMetric* durationMetric = config.add_duration_metric(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 306 | durationMetric->set_id(5); |
Yangster-mac | b814481 | 2018-01-04 10:56:23 -0800 | [diff] [blame] | 307 | durationMetric->set_bucket(ONE_MINUTE); |
Stefan Lafon | cfed20b | 2017-11-18 09:26:53 -0800 | [diff] [blame] | 308 | durationMetric->set_aggregation_type(DurationMetric_AggregationType_SUM); |
Yangster-mac | 468ff04 | 2018-01-17 12:26:34 -0800 | [diff] [blame] | 309 | dimensions = durationMetric->mutable_dimensions_in_what(); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 310 | dimensions->set_field(WAKE_LOCK_TAG_ID); |
| 311 | dimensions->add_child()->set_field(WAKE_LOCK_UID_KEY_ID); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 312 | durationMetric->set_what(205); |
| 313 | durationMetric->set_condition(204); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 314 | link = durationMetric->add_links(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 315 | link->set_condition(203); |
Yangster-mac | 2c6dc47 | 2018-01-18 16:17:43 -0800 | [diff] [blame] | 316 | link->mutable_fields_in_what()->set_field(WAKE_LOCK_TAG_ID); |
| 317 | link->mutable_fields_in_what()->add_child()->set_field(WAKE_LOCK_UID_KEY_ID); |
| 318 | link->mutable_fields_in_condition()->set_field(APP_USAGE_TAG_ID); |
| 319 | link->mutable_fields_in_condition()->add_child()->set_field(APP_USAGE_UID_KEY_ID); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 320 | |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 321 | // max Duration of an app holding any wl, while screen on and app in background, slice by uid |
| 322 | durationMetric = config.add_duration_metric(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 323 | durationMetric->set_id(6); |
Yangster-mac | b814481 | 2018-01-04 10:56:23 -0800 | [diff] [blame] | 324 | durationMetric->set_bucket(ONE_MINUTE); |
Stefan Lafon | cfed20b | 2017-11-18 09:26:53 -0800 | [diff] [blame] | 325 | durationMetric->set_aggregation_type(DurationMetric_AggregationType_MAX_SPARSE); |
Yangster-mac | 468ff04 | 2018-01-17 12:26:34 -0800 | [diff] [blame] | 326 | dimensions = durationMetric->mutable_dimensions_in_what(); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 327 | dimensions->set_field(WAKE_LOCK_TAG_ID); |
| 328 | dimensions->add_child()->set_field(WAKE_LOCK_UID_KEY_ID); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 329 | durationMetric->set_what(205); |
| 330 | durationMetric->set_condition(204); |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 331 | link = durationMetric->add_links(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 332 | link->set_condition(203); |
Yangster-mac | 2c6dc47 | 2018-01-18 16:17:43 -0800 | [diff] [blame] | 333 | link->mutable_fields_in_what()->set_field(WAKE_LOCK_TAG_ID); |
| 334 | link->mutable_fields_in_what()->add_child()->set_field(WAKE_LOCK_UID_KEY_ID); |
| 335 | link->mutable_fields_in_condition()->set_field(APP_USAGE_TAG_ID); |
| 336 | link->mutable_fields_in_condition()->add_child()->set_field(APP_USAGE_UID_KEY_ID); |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 337 | |
| 338 | // Duration of an app holding any wl, while screen on and app in background |
| 339 | durationMetric = config.add_duration_metric(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 340 | durationMetric->set_id(7); |
Yangster-mac | b814481 | 2018-01-04 10:56:23 -0800 | [diff] [blame] | 341 | durationMetric->set_bucket(ONE_MINUTE); |
Stefan Lafon | cfed20b | 2017-11-18 09:26:53 -0800 | [diff] [blame] | 342 | durationMetric->set_aggregation_type(DurationMetric_AggregationType_MAX_SPARSE); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 343 | durationMetric->set_what(205); |
| 344 | durationMetric->set_condition(204); |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 345 | link = durationMetric->add_links(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 346 | link->set_condition(203); |
Yangster-mac | 2c6dc47 | 2018-01-18 16:17:43 -0800 | [diff] [blame] | 347 | link->mutable_fields_in_what()->set_field(WAKE_LOCK_TAG_ID); |
| 348 | link->mutable_fields_in_what()->add_child()->set_field(WAKE_LOCK_UID_KEY_ID); |
| 349 | link->mutable_fields_in_condition()->set_field(APP_USAGE_TAG_ID); |
| 350 | link->mutable_fields_in_condition()->add_child()->set_field(APP_USAGE_UID_KEY_ID); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 351 | |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 352 | |
| 353 | // Duration of screen on time. |
| 354 | durationMetric = config.add_duration_metric(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 355 | durationMetric->set_id(8); |
Yangster-mac | b814481 | 2018-01-04 10:56:23 -0800 | [diff] [blame] | 356 | durationMetric->set_bucket(ONE_MINUTE); |
Stefan Lafon | cfed20b | 2017-11-18 09:26:53 -0800 | [diff] [blame] | 357 | durationMetric->set_aggregation_type(DurationMetric_AggregationType_SUM); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 358 | durationMetric->set_what(201); |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 359 | |
Bookatz | 450099d | 2017-11-30 17:09:30 -0800 | [diff] [blame] | 360 | // Anomaly threshold for background count. |
Yao Chen | f09569f | 2017-12-13 17:00:51 -0800 | [diff] [blame] | 361 | // TODO(b/70627390): Uncomment once the bug is fixed. |
| 362 | /* |
Bookatz | 450099d | 2017-11-30 17:09:30 -0800 | [diff] [blame] | 363 | alert = config.add_alert(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 364 | alert->set_id(308); |
| 365 | alert->set_metric_id(8); |
Bookatz | 450099d | 2017-11-30 17:09:30 -0800 | [diff] [blame] | 366 | alert->set_number_of_buckets(4); |
| 367 | alert->set_trigger_if_sum_gt(2000000000); // 2 seconds |
| 368 | alert->set_refractory_period_secs(120); |
| 369 | details = alert->mutable_incidentd_details(); |
Yao Chen | f09569f | 2017-12-13 17:00:51 -0800 | [diff] [blame] | 370 | details->add_section(-1);*/ |
Bookatz | 450099d | 2017-11-30 17:09:30 -0800 | [diff] [blame] | 371 | |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 372 | // Value metric to count KERNEL_WAKELOCK when screen turned on |
| 373 | ValueMetric* valueMetric = config.add_value_metric(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 374 | valueMetric->set_id(11); |
| 375 | valueMetric->set_what(109); |
Yangster-mac | a7fb12d | 2018-01-03 17:17:20 -0800 | [diff] [blame] | 376 | valueMetric->mutable_value_field()->set_field(KERNEL_WAKELOCK_TAG_ID); |
| 377 | valueMetric->mutable_value_field()->add_child()->set_field(KERNEL_WAKELOCK_COUNT_KEY); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 378 | valueMetric->set_condition(201); |
Yangster-mac | 468ff04 | 2018-01-17 12:26:34 -0800 | [diff] [blame] | 379 | dimensions = valueMetric->mutable_dimensions_in_what(); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 380 | dimensions->set_field(KERNEL_WAKELOCK_TAG_ID); |
| 381 | dimensions->add_child()->set_field(KERNEL_WAKELOCK_NAME_KEY); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 382 | // This is for testing easier. We should never set bucket size this small. |
Yangster-mac | b814481 | 2018-01-04 10:56:23 -0800 | [diff] [blame] | 383 | durationMetric->set_bucket(ONE_MINUTE); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 384 | |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 385 | // Add an EventMetric to log process state change events. |
| 386 | EventMetric* eventMetric = config.add_event_metric(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 387 | eventMetric->set_id(9); |
| 388 | eventMetric->set_what(102); // "SCREEN_TURNED_ON" |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 389 | |
Yangster | 1d4d686 | 2017-10-31 12:58:51 -0700 | [diff] [blame] | 390 | // Add an GaugeMetric. |
| 391 | GaugeMetric* gaugeMetric = config.add_gauge_metric(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 392 | gaugeMetric->set_id(10); |
| 393 | gaugeMetric->set_what(101); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 394 | auto gaugeFieldMatcher = gaugeMetric->mutable_gauge_fields_filter()->mutable_fields(); |
| 395 | gaugeFieldMatcher->set_field(DEVICE_TEMPERATURE_TAG_ID); |
| 396 | gaugeFieldMatcher->add_child()->set_field(DEVICE_TEMPERATURE_KEY); |
Yangster-mac | b814481 | 2018-01-04 10:56:23 -0800 | [diff] [blame] | 397 | durationMetric->set_bucket(ONE_MINUTE); |
Yangster | 1d4d686 | 2017-10-31 12:58:51 -0700 | [diff] [blame] | 398 | |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 399 | // Event matchers. |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 400 | AtomMatcher* temperatureAtomMatcher = config.add_atom_matcher(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 401 | temperatureAtomMatcher->set_id(101); // "DEVICE_TEMPERATURE" |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 402 | temperatureAtomMatcher->mutable_simple_atom_matcher()->set_atom_id( |
Yangster | 1d4d686 | 2017-10-31 12:58:51 -0700 | [diff] [blame] | 403 | DEVICE_TEMPERATURE_TAG_ID); |
| 404 | |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 405 | AtomMatcher* eventMatcher = config.add_atom_matcher(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 406 | eventMatcher->set_id(102); // "SCREEN_TURNED_ON" |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 407 | SimpleAtomMatcher* simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher(); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 408 | simpleAtomMatcher->set_atom_id(SCREEN_EVENT_TAG_ID); |
| 409 | FieldValueMatcher* fieldValueMatcher = simpleAtomMatcher->add_field_value_matcher(); |
| 410 | fieldValueMatcher->set_field(SCREEN_EVENT_STATE_KEY); |
| 411 | fieldValueMatcher->set_eq_int(SCREEN_EVENT_ON_VALUE); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 412 | |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 413 | eventMatcher = config.add_atom_matcher(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 414 | eventMatcher->set_id(103); // "SCREEN_TURNED_OFF" |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 415 | simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher(); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 416 | simpleAtomMatcher->set_atom_id(SCREEN_EVENT_TAG_ID); |
| 417 | fieldValueMatcher = simpleAtomMatcher->add_field_value_matcher(); |
| 418 | fieldValueMatcher->set_field(SCREEN_EVENT_STATE_KEY); |
| 419 | fieldValueMatcher->set_eq_int(SCREEN_EVENT_OFF_VALUE); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 420 | |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 421 | eventMatcher = config.add_atom_matcher(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 422 | eventMatcher->set_id(104); // "PROCESS_STATE_CHANGE" |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 423 | simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher(); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 424 | simpleAtomMatcher->set_atom_id(UID_PROCESS_STATE_TAG_ID); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 425 | |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 426 | eventMatcher = config.add_atom_matcher(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 427 | eventMatcher->set_id(105); // "APP_GOES_BACKGROUND" |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 428 | simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher(); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 429 | simpleAtomMatcher->set_atom_id(APP_USAGE_TAG_ID); |
| 430 | fieldValueMatcher = simpleAtomMatcher->add_field_value_matcher(); |
| 431 | fieldValueMatcher->set_field(APP_USAGE_STATE_KEY); |
| 432 | fieldValueMatcher->set_eq_int(APP_USAGE_BACKGROUND); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 433 | |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 434 | eventMatcher = config.add_atom_matcher(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 435 | eventMatcher->set_id(106); // "APP_GOES_FOREGROUND" |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 436 | simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher(); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 437 | simpleAtomMatcher->set_atom_id(APP_USAGE_TAG_ID); |
| 438 | fieldValueMatcher = simpleAtomMatcher->add_field_value_matcher(); |
| 439 | fieldValueMatcher->set_field(APP_USAGE_STATE_KEY); |
| 440 | fieldValueMatcher->set_eq_int(APP_USAGE_FOREGROUND); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 441 | |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 442 | eventMatcher = config.add_atom_matcher(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 443 | eventMatcher->set_id(107); // "APP_GET_WL" |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 444 | simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher(); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 445 | simpleAtomMatcher->set_atom_id(WAKE_LOCK_TAG_ID); |
| 446 | fieldValueMatcher = simpleAtomMatcher->add_field_value_matcher(); |
| 447 | fieldValueMatcher->set_field(WAKE_LOCK_STATE_KEY); |
| 448 | fieldValueMatcher->set_eq_int(WAKE_LOCK_ACQUIRE_VALUE); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 449 | |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 450 | eventMatcher = config.add_atom_matcher(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 451 | eventMatcher->set_id(108); //"APP_RELEASE_WL" |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 452 | simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher(); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 453 | simpleAtomMatcher->set_atom_id(WAKE_LOCK_TAG_ID); |
| 454 | fieldValueMatcher = simpleAtomMatcher->add_field_value_matcher(); |
| 455 | fieldValueMatcher->set_field(WAKE_LOCK_STATE_KEY); |
| 456 | fieldValueMatcher->set_eq_int(WAKE_LOCK_RELEASE_VALUE); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 457 | |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 458 | // pulled events |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 459 | eventMatcher = config.add_atom_matcher(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 460 | eventMatcher->set_id(109); // "KERNEL_WAKELOCK" |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 461 | simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher(); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 462 | simpleAtomMatcher->set_atom_id(KERNEL_WAKELOCK_TAG_ID); |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 463 | |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 464 | // Predicates............. |
| 465 | Predicate* predicate = config.add_predicate(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 466 | predicate->set_id(201); // "SCREEN_IS_ON" |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 467 | SimplePredicate* simplePredicate = predicate->mutable_simple_predicate(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 468 | simplePredicate->set_start(102); // "SCREEN_TURNED_ON" |
| 469 | simplePredicate->set_stop(103); |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 470 | simplePredicate->set_count_nesting(false); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 471 | |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 472 | predicate = config.add_predicate(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 473 | predicate->set_id(202); // "SCREEN_IS_OFF" |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 474 | simplePredicate = predicate->mutable_simple_predicate(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 475 | simplePredicate->set_start(103); |
| 476 | simplePredicate->set_stop(102); // "SCREEN_TURNED_ON" |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 477 | simplePredicate->set_count_nesting(false); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 478 | |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 479 | predicate = config.add_predicate(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 480 | predicate->set_id(203); // "APP_IS_BACKGROUND" |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 481 | simplePredicate = predicate->mutable_simple_predicate(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 482 | simplePredicate->set_start(105); |
| 483 | simplePredicate->set_stop(106); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 484 | FieldMatcher* predicate_dimension1 = simplePredicate->mutable_dimensions(); |
| 485 | predicate_dimension1->set_field(APP_USAGE_TAG_ID); |
| 486 | predicate_dimension1->add_child()->set_field(APP_USAGE_UID_KEY_ID); |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 487 | simplePredicate->set_count_nesting(false); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 488 | |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 489 | predicate = config.add_predicate(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 490 | predicate->set_id(204); // "APP_IS_BACKGROUND_AND_SCREEN_ON" |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 491 | Predicate_Combination* combination_predicate = predicate->mutable_combination(); |
| 492 | combination_predicate->set_operation(LogicalOperation::AND); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 493 | combination_predicate->add_predicate(203); |
| 494 | combination_predicate->add_predicate(201); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 495 | |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 496 | predicate = config.add_predicate(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 497 | predicate->set_id(205); // "WL_HELD_PER_APP_PER_NAME" |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 498 | simplePredicate = predicate->mutable_simple_predicate(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 499 | simplePredicate->set_start(107); |
| 500 | simplePredicate->set_stop(108); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 501 | FieldMatcher* predicate_dimension = simplePredicate->mutable_dimensions(); |
| 502 | predicate_dimension1->set_field(WAKE_LOCK_TAG_ID); |
| 503 | predicate_dimension->add_child()->set_field(WAKE_LOCK_UID_KEY_ID); |
| 504 | predicate_dimension->add_child()->set_field(WAKE_LOCK_NAME_KEY); |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 505 | simplePredicate->set_count_nesting(true); |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 506 | |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 507 | predicate = config.add_predicate(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 508 | predicate->set_id(206); // "WL_HELD_PER_APP" |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 509 | simplePredicate = predicate->mutable_simple_predicate(); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 510 | simplePredicate->set_start(107); |
| 511 | simplePredicate->set_stop(108); |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 512 | simplePredicate->set_initial_value(SimplePredicate_InitialValue_FALSE); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 513 | predicate_dimension = simplePredicate->mutable_dimensions(); |
| 514 | predicate_dimension->set_field(WAKE_LOCK_TAG_ID); |
| 515 | predicate_dimension->add_child()->set_field(WAKE_LOCK_UID_KEY_ID); |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 516 | simplePredicate->set_count_nesting(true); |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 517 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 518 | return config; |
| 519 | } |
| 520 | |
| 521 | } // namespace statsd |
| 522 | } // namespace os |
| 523 | } // namespace android |