blob: 26741716cc22ad4b14ef7aabf756edd35872186b [file] [log] [blame]
David Chende701692017-10-05 13:16:02 -07001/*
yro0feae942017-11-15 14:38:48 -08002 * Copyright (C) 2017 The Android Open Source Project
David Chende701692017-10-05 13:16:02 -07003 *
4 * Licensed under the Apache License, versionCode 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 */
David Chenf384b902018-03-14 18:36:45 -070016#define DEBUG false // STOPSHIP if true
Joe Onorato9fc9edf2017-10-15 20:08:52 -070017#include "Log.h"
18
Yangster-mac330af582018-02-08 15:24:38 -080019#include "stats_log_util.h"
David Chenc136f45a2017-11-27 11:52:26 -080020#include "guardrail/StatsdStats.h"
Joe Onorato9fc9edf2017-10-15 20:08:52 -070021#include "packages/UidMap.h"
22
David Chenc136f45a2017-11-27 11:52:26 -080023#include <android/os/IStatsCompanionService.h>
24#include <binder/IServiceManager.h>
David Chende701692017-10-05 13:16:02 -070025#include <utils/Errors.h>
26
Dianne Hackborn3accca02013-09-20 09:32:11 -070027#include <inttypes.h>
28
David Chende701692017-10-05 13:16:02 -070029using namespace android;
30
David Chenf384b902018-03-14 18:36:45 -070031using android::base::StringPrintf;
32using android::util::FIELD_COUNT_REPEATED;
33using android::util::FIELD_TYPE_BOOL;
34using android::util::FIELD_TYPE_FLOAT;
35using android::util::FIELD_TYPE_INT32;
36using android::util::FIELD_TYPE_INT64;
37using android::util::FIELD_TYPE_MESSAGE;
38using android::util::FIELD_TYPE_STRING;
39using android::util::ProtoOutputStream;
40
David Chende701692017-10-05 13:16:02 -070041namespace android {
42namespace os {
43namespace statsd {
44
David Chenf384b902018-03-14 18:36:45 -070045const int FIELD_ID_SNAPSHOT_PACKAGE_NAME = 1;
46const int FIELD_ID_SNAPSHOT_PACKAGE_VERSION = 2;
47const int FIELD_ID_SNAPSHOT_PACKAGE_UID = 3;
David Chenbd125272018-04-04 19:02:50 -070048const int FIELD_ID_SNAPSHOT_PACKAGE_DELETED = 4;
David Chenf384b902018-03-14 18:36:45 -070049const int FIELD_ID_SNAPSHOT_TIMESTAMP = 1;
50const int FIELD_ID_SNAPSHOT_PACKAGE_INFO = 2;
51const int FIELD_ID_SNAPSHOTS = 1;
52const int FIELD_ID_CHANGES = 2;
53const int FIELD_ID_CHANGE_DELETION = 1;
54const int FIELD_ID_CHANGE_TIMESTAMP = 2;
55const int FIELD_ID_CHANGE_PACKAGE = 3;
56const int FIELD_ID_CHANGE_UID = 4;
David Chenbd125272018-04-04 19:02:50 -070057const int FIELD_ID_CHANGE_NEW_VERSION = 5;
58const int FIELD_ID_CHANGE_PREV_VERSION = 6;
David Chenf384b902018-03-14 18:36:45 -070059
Yangster9df9a7f2017-12-18 13:33:05 -080060UidMap::UidMap() : mBytesUsed(0) {}
61
62UidMap::~UidMap() {}
David Chenc136f45a2017-11-27 11:52:26 -080063
David Chende701692017-10-05 13:16:02 -070064bool UidMap::hasApp(int uid, const string& packageName) const {
65 lock_guard<mutex> lock(mMutex);
66
David Chenbd125272018-04-04 19:02:50 -070067 auto it = mMap.find(std::make_pair(uid, packageName));
68 return it != mMap.end() && !it->second.deleted;
David Chende701692017-10-05 13:16:02 -070069}
70
Yangster9df9a7f2017-12-18 13:33:05 -080071string UidMap::normalizeAppName(const string& appName) const {
72 string normalizedName = appName;
73 std::transform(normalizedName.begin(), normalizedName.end(), normalizedName.begin(), ::tolower);
74 return normalizedName;
75}
76
77std::set<string> UidMap::getAppNamesFromUid(const int32_t& uid, bool returnNormalized) const {
78 lock_guard<mutex> lock(mMutex);
79 return getAppNamesFromUidLocked(uid,returnNormalized);
80}
81
82std::set<string> UidMap::getAppNamesFromUidLocked(const int32_t& uid, bool returnNormalized) const {
83 std::set<string> names;
David Chenbd125272018-04-04 19:02:50 -070084 for (const auto& kv : mMap) {
85 if (kv.first.first == uid && !kv.second.deleted) {
86 names.insert(returnNormalized ? normalizeAppName(kv.first.second) : kv.first.second);
87 }
Yangster9df9a7f2017-12-18 13:33:05 -080088 }
89 return names;
90}
91
Dianne Hackborn3accca02013-09-20 09:32:11 -070092int64_t UidMap::getAppVersion(int uid, const string& packageName) const {
David Chende701692017-10-05 13:16:02 -070093 lock_guard<mutex> lock(mMutex);
94
David Chenbd125272018-04-04 19:02:50 -070095 auto it = mMap.find(std::make_pair(uid, packageName));
96 if (it == mMap.end() || it->second.deleted) {
97 return 0;
David Chende701692017-10-05 13:16:02 -070098 }
David Chenbd125272018-04-04 19:02:50 -070099 return it->second.versionCode;
David Chend6896892017-10-25 11:49:03 -0700100}
101
102void UidMap::updateMap(const int64_t& timestamp, const vector<int32_t>& uid,
Dianne Hackborn3accca02013-09-20 09:32:11 -0700103 const vector<int64_t>& versionCode, const vector<String16>& packageName) {
Yao Chend10f7b12017-12-18 12:53:50 -0800104 vector<wp<PackageInfoListener>> broadcastList;
105 {
106 lock_guard<mutex> lock(mMutex); // Exclusively lock for updates.
David Chende701692017-10-05 13:16:02 -0700107
David Chenbd125272018-04-04 19:02:50 -0700108 std::unordered_map<std::pair<int, string>, AppData, PairHash> deletedApps;
109
110 // Copy all the deleted apps.
111 for (const auto& kv : mMap) {
112 if (kv.second.deleted) {
113 deletedApps[kv.first] = kv.second;
114 }
Yao Chend10f7b12017-12-18 12:53:50 -0800115 }
David Chende701692017-10-05 13:16:02 -0700116
David Chenbd125272018-04-04 19:02:50 -0700117 mMap.clear();
118 for (size_t j = 0; j < uid.size(); j++) {
119 string package = string(String8(packageName[j]).string());
120 mMap[std::make_pair(uid[j], package)] = AppData(versionCode[j]);
121 }
David Chenf384b902018-03-14 18:36:45 -0700122
David Chenbd125272018-04-04 19:02:50 -0700123 for (const auto& kv : deletedApps) {
124 auto mMapIt = mMap.find(kv.first);
125 if (mMapIt != mMap.end()) {
126 // Insert this deleted app back into the current map.
127 mMap[kv.first] = kv.second;
128 }
129 }
130
David Chenc0f6f632018-01-18 16:02:42 -0800131 ensureBytesUsedBelowLimit();
Yao Chend10f7b12017-12-18 12:53:50 -0800132 StatsdStats::getInstance().setCurrentUidMapMemory(mBytesUsed);
Yao Chend10f7b12017-12-18 12:53:50 -0800133 getListenerListCopyLocked(&broadcastList);
David Chende701692017-10-05 13:16:02 -0700134 }
Yao Chend10f7b12017-12-18 12:53:50 -0800135 // To avoid invoking callback while holding the internal lock. we get a copy of the listener
136 // list and invoke the callback. It's still possible that after we copy the list, a
137 // listener removes itself before we call it. It's then the listener's job to handle it (expect
138 // the callback to be called after listener is removed, and the listener should properly
139 // ignore it).
140 for (auto weakPtr : broadcastList) {
141 auto strongPtr = weakPtr.promote();
142 if (strongPtr != NULL) {
David Chen27785a82018-01-19 17:06:45 -0800143 strongPtr->onUidMapReceived(timestamp);
Yao Chend10f7b12017-12-18 12:53:50 -0800144 }
145 }
David Chende701692017-10-05 13:16:02 -0700146}
147
David Chend6896892017-10-25 11:49:03 -0700148void UidMap::updateApp(const int64_t& timestamp, const String16& app_16, const int32_t& uid,
Dianne Hackborn3accca02013-09-20 09:32:11 -0700149 const int64_t& versionCode) {
Yao Chend10f7b12017-12-18 12:53:50 -0800150 vector<wp<PackageInfoListener>> broadcastList;
Yangster9df9a7f2017-12-18 13:33:05 -0800151 string appName = string(String8(app_16).string());
Yao Chend10f7b12017-12-18 12:53:50 -0800152 {
153 lock_guard<mutex> lock(mMutex);
David Chenbd125272018-04-04 19:02:50 -0700154 int32_t prevVersion = 0;
155 bool found = false;
156 auto it = mMap.find(std::make_pair(uid, appName));
157 if (it != mMap.end()) {
158 found = true;
159 prevVersion = it->second.versionCode;
160 it->second.versionCode = versionCode;
161 it->second.deleted = false;
162 }
163 if (!found) {
164 // Otherwise, we need to add an app at this uid.
165 mMap[std::make_pair(uid, appName)] = AppData(versionCode);
166 } else {
167 // Only notify the listeners if this is an app upgrade. If this app is being installed
168 // for the first time, then we don't notify the listeners.
David Chen81245fd2018-04-12 14:33:37 -0700169 // It's also OK to split again if we're forming a partial bucket after re-installing an
170 // app after deletion.
David Chenbd125272018-04-04 19:02:50 -0700171 getListenerListCopyLocked(&broadcastList);
172 }
173 mChanges.emplace_back(false, timestamp, appName, uid, versionCode, prevVersion);
David Chenf384b902018-03-14 18:36:45 -0700174 mBytesUsed += kBytesChangeRecord;
David Chenc0f6f632018-01-18 16:02:42 -0800175 ensureBytesUsedBelowLimit();
Yao Chend10f7b12017-12-18 12:53:50 -0800176 StatsdStats::getInstance().setCurrentUidMapMemory(mBytesUsed);
David Chenf384b902018-03-14 18:36:45 -0700177 StatsdStats::getInstance().setUidMapChanges(mChanges.size());
David Chende701692017-10-05 13:16:02 -0700178 }
179
Yao Chend10f7b12017-12-18 12:53:50 -0800180 for (auto weakPtr : broadcastList) {
181 auto strongPtr = weakPtr.promote();
182 if (strongPtr != NULL) {
David Chen27785a82018-01-19 17:06:45 -0800183 strongPtr->notifyAppUpgrade(timestamp, appName, uid, versionCode);
David Chende701692017-10-05 13:16:02 -0700184 }
David Chende701692017-10-05 13:16:02 -0700185 }
David Chende701692017-10-05 13:16:02 -0700186}
187
David Chenc136f45a2017-11-27 11:52:26 -0800188void UidMap::ensureBytesUsedBelowLimit() {
189 size_t limit;
190 if (maxBytesOverride <= 0) {
191 limit = StatsdStats::kMaxBytesUsedUidMap;
192 } else {
193 limit = maxBytesOverride;
194 }
195 while (mBytesUsed > limit) {
David Chenf384b902018-03-14 18:36:45 -0700196 ALOGI("Bytes used %zu is above limit %zu, need to delete something", mBytesUsed, limit);
David Chenbd125272018-04-04 19:02:50 -0700197 if (mChanges.size() > 0) {
David Chenf384b902018-03-14 18:36:45 -0700198 mBytesUsed -= kBytesChangeRecord;
199 mChanges.pop_front();
David Chenbd125272018-04-04 19:02:50 -0700200 StatsdStats::getInstance().noteUidMapDropped(1);
David Chenc136f45a2017-11-27 11:52:26 -0800201 }
David Chenc136f45a2017-11-27 11:52:26 -0800202 }
203}
204
Yao Chend10f7b12017-12-18 12:53:50 -0800205void UidMap::getListenerListCopyLocked(vector<wp<PackageInfoListener>>* output) {
206 for (auto weakIt = mSubscribers.begin(); weakIt != mSubscribers.end();) {
207 auto strongPtr = weakIt->promote();
208 if (strongPtr != NULL) {
209 output->push_back(*weakIt);
210 weakIt++;
211 } else {
212 weakIt = mSubscribers.erase(weakIt);
213 VLOG("The UidMap listener is gone, remove it now");
David Chende701692017-10-05 13:16:02 -0700214 }
215 }
David Chende701692017-10-05 13:16:02 -0700216}
217
Yao Chend10f7b12017-12-18 12:53:50 -0800218void UidMap::removeApp(const int64_t& timestamp, const String16& app_16, const int32_t& uid) {
219 vector<wp<PackageInfoListener>> broadcastList;
220 string app = string(String8(app_16).string());
221 {
222 lock_guard<mutex> lock(mMutex);
223
Chenjie Yue36018b2018-04-16 15:18:30 -0700224 int64_t prevVersion = 0;
David Chenbd125272018-04-04 19:02:50 -0700225 auto key = std::make_pair(uid, app);
226 auto it = mMap.find(key);
227 if (it != mMap.end() && !it->second.deleted) {
228 prevVersion = it->second.versionCode;
229 it->second.deleted = true;
230 mDeletedApps.push_back(key);
231 }
232 if (mDeletedApps.size() > StatsdStats::kMaxDeletedAppsInUidMap) {
233 // Delete the oldest one.
234 auto oldest = mDeletedApps.front();
235 mDeletedApps.pop_front();
236 mMap.erase(oldest);
237 StatsdStats::getInstance().noteUidMapAppDeletionDropped();
238 }
239 mChanges.emplace_back(true, timestamp, app, uid, 0, prevVersion);
David Chenf384b902018-03-14 18:36:45 -0700240 mBytesUsed += kBytesChangeRecord;
David Chenc0f6f632018-01-18 16:02:42 -0800241 ensureBytesUsedBelowLimit();
Yao Chend10f7b12017-12-18 12:53:50 -0800242 StatsdStats::getInstance().setCurrentUidMapMemory(mBytesUsed);
David Chenf384b902018-03-14 18:36:45 -0700243 StatsdStats::getInstance().setUidMapChanges(mChanges.size());
Yao Chend10f7b12017-12-18 12:53:50 -0800244 getListenerListCopyLocked(&broadcastList);
245 }
246
247 for (auto weakPtr : broadcastList) {
248 auto strongPtr = weakPtr.promote();
249 if (strongPtr != NULL) {
David Chen27785a82018-01-19 17:06:45 -0800250 strongPtr->notifyAppRemoved(timestamp, app, uid);
Yao Chend10f7b12017-12-18 12:53:50 -0800251 }
252 }
253}
254
255void UidMap::addListener(wp<PackageInfoListener> producer) {
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700256 lock_guard<mutex> lock(mMutex); // Lock for updates
David Chende701692017-10-05 13:16:02 -0700257 mSubscribers.insert(producer);
258}
259
Yao Chend10f7b12017-12-18 12:53:50 -0800260void UidMap::removeListener(wp<PackageInfoListener> producer) {
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700261 lock_guard<mutex> lock(mMutex); // Lock for updates
David Chende701692017-10-05 13:16:02 -0700262 mSubscribers.erase(producer);
263}
264
David Chen21582962017-11-01 17:32:46 -0700265void UidMap::assignIsolatedUid(int isolatedUid, int parentUid) {
266 lock_guard<mutex> lock(mIsolatedMutex);
267
268 mIsolatedUidMap[isolatedUid] = parentUid;
269}
270
271void UidMap::removeIsolatedUid(int isolatedUid, int parentUid) {
272 lock_guard<mutex> lock(mIsolatedMutex);
273
274 auto it = mIsolatedUidMap.find(isolatedUid);
275 if (it != mIsolatedUidMap.end()) {
276 mIsolatedUidMap.erase(it);
277 }
278}
279
Yangster-macd40053e2018-01-09 16:29:22 -0800280int UidMap::getHostUidOrSelf(int uid) const {
David Chen21582962017-11-01 17:32:46 -0700281 lock_guard<mutex> lock(mIsolatedMutex);
282
283 auto it = mIsolatedUidMap.find(uid);
284 if (it != mIsolatedUidMap.end()) {
285 return it->second;
286 }
287 return uid;
288}
289
David Chend6896892017-10-25 11:49:03 -0700290void UidMap::clearOutput() {
David Chenf384b902018-03-14 18:36:45 -0700291 mChanges.clear();
David Chenc136f45a2017-11-27 11:52:26 -0800292 // Also update the guardrail trackers.
293 StatsdStats::getInstance().setUidMapChanges(0);
David Chencfc311d2018-01-23 17:55:54 -0800294 mBytesUsed = 0;
David Chenc136f45a2017-11-27 11:52:26 -0800295 StatsdStats::getInstance().setCurrentUidMapMemory(mBytesUsed);
David Chend6896892017-10-25 11:49:03 -0700296}
David Chende701692017-10-05 13:16:02 -0700297
David Chend6896892017-10-25 11:49:03 -0700298int64_t UidMap::getMinimumTimestampNs() {
299 int64_t m = 0;
David Chenbd125272018-04-04 19:02:50 -0700300 for (const auto& kv : mLastUpdatePerConfigKey) {
David Chend6896892017-10-25 11:49:03 -0700301 if (m == 0) {
David Chenbd125272018-04-04 19:02:50 -0700302 m = kv.second;
303 } else if (kv.second < m) {
304 m = kv.second;
David Chend6896892017-10-25 11:49:03 -0700305 }
306 }
307 return m;
308}
309
Yao Chend10f7b12017-12-18 12:53:50 -0800310size_t UidMap::getBytesUsed() const {
David Chenc136f45a2017-11-27 11:52:26 -0800311 return mBytesUsed;
312}
313
yro4beccbe2018-03-15 19:42:05 -0700314void UidMap::appendUidMap(const int64_t& timestamp, const ConfigKey& key,
315 ProtoOutputStream* proto) {
David Chend6896892017-10-25 11:49:03 -0700316 lock_guard<mutex> lock(mMutex); // Lock for updates
317
David Chenf384b902018-03-14 18:36:45 -0700318 for (const ChangeRecord& record : mChanges) {
319 if (record.timestampNs > mLastUpdatePerConfigKey[key]) {
320 uint64_t changesToken =
yro4beccbe2018-03-15 19:42:05 -0700321 proto->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_CHANGES);
322 proto->write(FIELD_TYPE_BOOL | FIELD_ID_CHANGE_DELETION, (bool)record.deletion);
323 proto->write(FIELD_TYPE_INT64 | FIELD_ID_CHANGE_TIMESTAMP,
324 (long long)record.timestampNs);
325 proto->write(FIELD_TYPE_STRING | FIELD_ID_CHANGE_PACKAGE, record.package);
326 proto->write(FIELD_TYPE_INT32 | FIELD_ID_CHANGE_UID, (int)record.uid);
Chenjie Yue36018b2018-04-16 15:18:30 -0700327 proto->write(FIELD_TYPE_INT64 | FIELD_ID_CHANGE_NEW_VERSION, (long long)record.version);
328 proto->write(FIELD_TYPE_INT64 | FIELD_ID_CHANGE_PREV_VERSION,
329 (long long)record.prevVersion);
yro4beccbe2018-03-15 19:42:05 -0700330 proto->end(changesToken);
David Chenf384b902018-03-14 18:36:45 -0700331 }
332 }
333
David Chenbd125272018-04-04 19:02:50 -0700334 // Write snapshot from current uid map state.
335 uint64_t snapshotsToken =
336 proto->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_SNAPSHOTS);
337 proto->write(FIELD_TYPE_INT64 | FIELD_ID_SNAPSHOT_TIMESTAMP, (long long)timestamp);
338 for (const auto& kv : mMap) {
339 uint64_t token = proto->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED |
340 FIELD_ID_SNAPSHOT_PACKAGE_INFO);
341 proto->write(FIELD_TYPE_STRING | FIELD_ID_SNAPSHOT_PACKAGE_NAME, kv.first.second);
Chenjie Yue36018b2018-04-16 15:18:30 -0700342 proto->write(FIELD_TYPE_INT64 | FIELD_ID_SNAPSHOT_PACKAGE_VERSION,
343 (long long)kv.second.versionCode);
David Chenbd125272018-04-04 19:02:50 -0700344 proto->write(FIELD_TYPE_INT32 | FIELD_ID_SNAPSHOT_PACKAGE_UID, kv.first.first);
345 proto->write(FIELD_TYPE_BOOL | FIELD_ID_SNAPSHOT_PACKAGE_DELETED, kv.second.deleted);
346 proto->end(token);
David Chenf384b902018-03-14 18:36:45 -0700347 }
David Chenbd125272018-04-04 19:02:50 -0700348 proto->end(snapshotsToken);
David Chenf384b902018-03-14 18:36:45 -0700349
David Chend6896892017-10-25 11:49:03 -0700350 int64_t prevMin = getMinimumTimestampNs();
351 mLastUpdatePerConfigKey[key] = timestamp;
352 int64_t newMin = getMinimumTimestampNs();
353
David Chenf384b902018-03-14 18:36:45 -0700354 if (newMin > prevMin) { // Delete anything possible now that the minimum has
355 // moved forward.
David Chend6896892017-10-25 11:49:03 -0700356 int64_t cutoff_nanos = newMin;
Yao Chen34900c32018-03-19 13:43:29 -0700357 for (auto it_changes = mChanges.begin(); it_changes != mChanges.end();) {
David Chenf384b902018-03-14 18:36:45 -0700358 if (it_changes->timestampNs < cutoff_nanos) {
359 mBytesUsed -= kBytesChangeRecord;
Yao Chen34900c32018-03-19 13:43:29 -0700360 it_changes = mChanges.erase(it_changes);
361 } else {
362 ++it_changes;
David Chend6896892017-10-25 11:49:03 -0700363 }
364 }
365 }
David Chenc136f45a2017-11-27 11:52:26 -0800366 StatsdStats::getInstance().setCurrentUidMapMemory(mBytesUsed);
David Chenf384b902018-03-14 18:36:45 -0700367 StatsdStats::getInstance().setUidMapChanges(mChanges.size());
David Chende701692017-10-05 13:16:02 -0700368}
369
Yao Chend10f7b12017-12-18 12:53:50 -0800370void UidMap::printUidMap(FILE* out) const {
David Chende701692017-10-05 13:16:02 -0700371 lock_guard<mutex> lock(mMutex);
372
David Chenbd125272018-04-04 19:02:50 -0700373 for (const auto& kv : mMap) {
374 if (!kv.second.deleted) {
375 fprintf(out, "%s, v%" PRId64 " (%i)\n", kv.first.second.c_str(), kv.second.versionCode,
376 kv.first.first);
377 }
David Chende701692017-10-05 13:16:02 -0700378 }
379}
380
David Chend6896892017-10-25 11:49:03 -0700381void UidMap::OnConfigUpdated(const ConfigKey& key) {
382 mLastUpdatePerConfigKey[key] = -1;
383}
384
385void UidMap::OnConfigRemoved(const ConfigKey& key) {
386 mLastUpdatePerConfigKey.erase(key);
387}
388
Yao Chend10f7b12017-12-18 12:53:50 -0800389set<int32_t> UidMap::getAppUid(const string& package) const {
390 lock_guard<mutex> lock(mMutex);
391
392 set<int32_t> results;
David Chenbd125272018-04-04 19:02:50 -0700393 for (const auto& kv : mMap) {
394 if (kv.first.second == package && !kv.second.deleted) {
395 results.insert(kv.first.first);
Yao Chend10f7b12017-12-18 12:53:50 -0800396 }
397 }
398 return results;
399}
400
Yao Chen147ce602017-12-22 14:35:34 -0800401// Note not all the following AIDs are used as uids. Some are used only for gids.
402// It's ok to leave them in the map, but we won't ever see them in the log's uid field.
403// App's uid starts from 10000, and will not overlap with the following AIDs.
404const std::map<string, uint32_t> UidMap::sAidToUidMapping = {{"AID_ROOT", 0},
405 {"AID_SYSTEM", 1000},
406 {"AID_RADIO", 1001},
407 {"AID_BLUETOOTH", 1002},
408 {"AID_GRAPHICS", 1003},
409 {"AID_INPUT", 1004},
410 {"AID_AUDIO", 1005},
411 {"AID_CAMERA", 1006},
412 {"AID_LOG", 1007},
413 {"AID_COMPASS", 1008},
414 {"AID_MOUNT", 1009},
415 {"AID_WIFI", 1010},
416 {"AID_ADB", 1011},
417 {"AID_INSTALL", 1012},
418 {"AID_MEDIA", 1013},
419 {"AID_DHCP", 1014},
420 {"AID_SDCARD_RW", 1015},
421 {"AID_VPN", 1016},
422 {"AID_KEYSTORE", 1017},
423 {"AID_USB", 1018},
424 {"AID_DRM", 1019},
425 {"AID_MDNSR", 1020},
426 {"AID_GPS", 1021},
427 // {"AID_UNUSED1", 1022},
428 {"AID_MEDIA_RW", 1023},
429 {"AID_MTP", 1024},
430 // {"AID_UNUSED2", 1025},
431 {"AID_DRMRPC", 1026},
432 {"AID_NFC", 1027},
433 {"AID_SDCARD_R", 1028},
434 {"AID_CLAT", 1029},
435 {"AID_LOOP_RADIO", 1030},
436 {"AID_MEDIA_DRM", 1031},
437 {"AID_PACKAGE_INFO", 1032},
438 {"AID_SDCARD_PICS", 1033},
439 {"AID_SDCARD_AV", 1034},
440 {"AID_SDCARD_ALL", 1035},
441 {"AID_LOGD", 1036},
442 {"AID_SHARED_RELRO", 1037},
443 {"AID_DBUS", 1038},
444 {"AID_TLSDATE", 1039},
445 {"AID_MEDIA_EX", 1040},
446 {"AID_AUDIOSERVER", 1041},
447 {"AID_METRICS_COLL", 1042},
448 {"AID_METRICSD", 1043},
449 {"AID_WEBSERV", 1044},
450 {"AID_DEBUGGERD", 1045},
451 {"AID_MEDIA_CODEC", 1046},
452 {"AID_CAMERASERVER", 1047},
453 {"AID_FIREWALL", 1048},
454 {"AID_TRUNKS", 1049},
455 {"AID_NVRAM", 1050},
456 {"AID_DNS", 1051},
457 {"AID_DNS_TETHER", 1052},
458 {"AID_WEBVIEW_ZYGOTE", 1053},
459 {"AID_VEHICLE_NETWORK", 1054},
460 {"AID_MEDIA_AUDIO", 1055},
461 {"AID_MEDIA_VIDEO", 1056},
462 {"AID_MEDIA_IMAGE", 1057},
463 {"AID_TOMBSTONED", 1058},
464 {"AID_MEDIA_OBB", 1059},
465 {"AID_ESE", 1060},
466 {"AID_OTA_UPDATE", 1061},
467 {"AID_AUTOMOTIVE_EVS", 1062},
468 {"AID_LOWPAN", 1063},
469 {"AID_HSM", 1064},
Yao Chen29f79b52018-01-17 10:56:48 -0800470 {"AID_RESERVED_DISK", 1065},
471 {"AID_STATSD", 1066},
472 {"AID_INCIDENTD", 1067},
Yao Chen147ce602017-12-22 14:35:34 -0800473 {"AID_SHELL", 2000},
474 {"AID_CACHE", 2001},
475 {"AID_DIAG", 2002}};
476
David Chende701692017-10-05 13:16:02 -0700477} // namespace statsd
478} // namespace os
Yao Chen29f79b52018-01-17 10:56:48 -0800479} // namespace android