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