Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | // Proxy for media player implementations |
| 18 | |
| 19 | //#define LOG_NDEBUG 0 |
| 20 | #define LOG_TAG "MediaAnalyticsService" |
| 21 | #include <utils/Log.h> |
| 22 | |
| 23 | #include <inttypes.h> |
| 24 | #include <sys/types.h> |
| 25 | #include <sys/stat.h> |
| 26 | #include <sys/time.h> |
| 27 | #include <dirent.h> |
| 28 | #include <unistd.h> |
| 29 | |
| 30 | #include <string.h> |
| 31 | |
| 32 | #include <cutils/atomic.h> |
| 33 | #include <cutils/properties.h> // for property_get |
| 34 | |
| 35 | #include <utils/misc.h> |
| 36 | |
| 37 | #include <binder/IPCThreadState.h> |
| 38 | #include <binder/IServiceManager.h> |
| 39 | #include <binder/MemoryHeapBase.h> |
| 40 | #include <binder/MemoryBase.h> |
| 41 | #include <gui/Surface.h> |
| 42 | #include <utils/Errors.h> // for status_t |
| 43 | #include <utils/List.h> |
| 44 | #include <utils/String8.h> |
| 45 | #include <utils/SystemClock.h> |
| 46 | #include <utils/Timers.h> |
| 47 | #include <utils/Vector.h> |
| 48 | |
| 49 | #include <media/AudioPolicyHelper.h> |
| 50 | #include <media/IMediaHTTPService.h> |
| 51 | #include <media/IRemoteDisplay.h> |
| 52 | #include <media/IRemoteDisplayClient.h> |
| 53 | #include <media/MediaPlayerInterface.h> |
| 54 | #include <media/mediarecorder.h> |
| 55 | #include <media/MediaMetadataRetrieverInterface.h> |
| 56 | #include <media/Metadata.h> |
| 57 | #include <media/AudioTrack.h> |
| 58 | #include <media/MemoryLeakTrackUtil.h> |
| 59 | #include <media/stagefright/MediaCodecList.h> |
| 60 | #include <media/stagefright/MediaErrors.h> |
| 61 | #include <media/stagefright/Utils.h> |
| 62 | #include <media/stagefright/foundation/ADebug.h> |
| 63 | #include <media/stagefright/foundation/ALooperRoster.h> |
| 64 | #include <mediautils/BatteryNotifier.h> |
| 65 | |
| 66 | //#include <memunreachable/memunreachable.h> |
| 67 | #include <system/audio.h> |
| 68 | |
| 69 | #include <private/android_filesystem_config.h> |
| 70 | |
| 71 | #include "MediaAnalyticsService.h" |
| 72 | |
| 73 | |
| 74 | namespace android { |
| 75 | |
| 76 | |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 77 | #define DEBUG_QUEUE 0 |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 78 | |
| 79 | //using android::status_t; |
| 80 | //using android::OK; |
| 81 | //using android::BAD_VALUE; |
| 82 | //using android::NOT_ENOUGH_DATA; |
| 83 | //using android::Parcel; |
| 84 | |
| 85 | |
| 86 | void MediaAnalyticsService::instantiate() { |
| 87 | defaultServiceManager()->addService( |
| 88 | String16("media.analytics"), new MediaAnalyticsService()); |
| 89 | } |
| 90 | |
| 91 | // XXX: add dynamic controls for mMaxRecords |
| 92 | MediaAnalyticsService::MediaAnalyticsService() |
| 93 | : mMaxRecords(100) { |
| 94 | |
| 95 | ALOGD("MediaAnalyticsService created"); |
| 96 | // clear our queues |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 97 | mOpen = new List<MediaAnalyticsItem *>(); |
| 98 | mFinalized = new List<MediaAnalyticsItem *>(); |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 99 | |
| 100 | mItemsSubmitted = 0; |
| 101 | mItemsFinalized = 0; |
| 102 | mItemsDiscarded = 0; |
| 103 | |
| 104 | mLastSessionID = 0; |
| 105 | // recover any persistency we set up |
| 106 | // etc |
| 107 | } |
| 108 | |
| 109 | MediaAnalyticsService::~MediaAnalyticsService() { |
| 110 | ALOGD("MediaAnalyticsService destroyed"); |
| 111 | |
| 112 | // XXX: clean out mOpen and mFinalized |
| 113 | } |
| 114 | |
| 115 | |
| 116 | MediaAnalyticsItem::SessionID_t MediaAnalyticsService::generateUniqueSessionID() { |
| 117 | // generate a new sessionid |
| 118 | |
| 119 | Mutex::Autolock _l(mLock_ids); |
| 120 | return (++mLastSessionID); |
| 121 | } |
| 122 | |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 123 | // caller surrenders ownership of 'item' |
| 124 | MediaAnalyticsItem::SessionID_t MediaAnalyticsService::submit(MediaAnalyticsItem *item, bool forcenew) { |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 125 | |
| 126 | MediaAnalyticsItem::SessionID_t id = MediaAnalyticsItem::SessionIDInvalid; |
| 127 | |
| 128 | // we control these, not using whatever the user might have sent |
| 129 | nsecs_t now = systemTime(SYSTEM_TIME_REALTIME); |
| 130 | item->setTimestamp(now); |
| 131 | int pid = IPCThreadState::self()->getCallingPid(); |
| 132 | item->setPid(pid); |
| 133 | int uid = IPCThreadState::self()->getCallingUid(); |
| 134 | item->setUid(uid); |
| 135 | |
| 136 | mItemsSubmitted++; |
| 137 | |
| 138 | // validate the record; we discard if we don't like it |
| 139 | if (contentValid(item) == false) { |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 140 | delete item; |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 141 | return MediaAnalyticsItem::SessionIDInvalid; |
| 142 | } |
| 143 | |
| 144 | |
| 145 | // if we have a sesisonid in the new record, look to make |
| 146 | // sure it doesn't appear in the finalized list. |
| 147 | // XXX: this is for security / DOS prevention. |
| 148 | // may also require that we persist the unique sessionIDs |
| 149 | // across boots [instead of within a single boot] |
| 150 | |
| 151 | |
| 152 | // match this new record up against records in the open |
| 153 | // list... |
| 154 | // if there's a match, merge them together |
| 155 | // deal with moving the old / merged record into the finalized que |
| 156 | |
| 157 | bool finalizing = item->getFinalized(); |
| 158 | |
| 159 | // if finalizing, we'll remove it |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 160 | MediaAnalyticsItem *oitem = findItem(mOpen, item, finalizing | forcenew); |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 161 | if (oitem != NULL) { |
| 162 | if (forcenew) { |
| 163 | // old one gets finalized, then we insert the new one |
| 164 | // so we'll have 2 records at the end of this. |
| 165 | // but don't finalize an empty record |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 166 | if (oitem->count() == 0) { |
| 167 | // we're responsible for disposing of the dead record |
| 168 | delete oitem; |
| 169 | oitem = NULL; |
| 170 | } else { |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 171 | oitem->setFinalized(true); |
| 172 | saveItem(mFinalized, oitem, 0); |
| 173 | } |
| 174 | // new record could itself be marked finalized... |
| 175 | if (finalizing) { |
| 176 | saveItem(mFinalized, item, 0); |
| 177 | mItemsFinalized++; |
| 178 | } else { |
| 179 | saveItem(mOpen, item, 1); |
| 180 | } |
| 181 | id = item->getSessionID(); |
| 182 | } else { |
| 183 | // combine the records, send it to finalized if appropriate |
| 184 | oitem->merge(item); |
| 185 | if (finalizing) { |
| 186 | saveItem(mFinalized, oitem, 0); |
| 187 | mItemsFinalized++; |
| 188 | } |
| 189 | id = oitem->getSessionID(); |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 190 | |
| 191 | // we're responsible for disposing of the dead record |
| 192 | delete item; |
| 193 | item = NULL; |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 194 | } |
| 195 | } else { |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 196 | // nothing to merge, save the new record |
| 197 | id = item->getSessionID(); |
| 198 | if (finalizing) { |
| 199 | if (item->count() == 0) { |
| 200 | // drop empty records |
| 201 | delete item; |
| 202 | item = NULL; |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 203 | } else { |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 204 | saveItem(mFinalized, item, 0); |
| 205 | mItemsFinalized++; |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 206 | } |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 207 | } else { |
| 208 | saveItem(mOpen, item, 1); |
| 209 | } |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 210 | } |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 211 | return id; |
| 212 | } |
| 213 | |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 214 | List<MediaAnalyticsItem *> *MediaAnalyticsService::getMediaAnalyticsItemList(bool finished, nsecs_t ts) { |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 215 | // this might never get called; the binder interface maps to the full parm list |
| 216 | // on the client side before making the binder call. |
| 217 | // but this lets us be sure... |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 218 | List<MediaAnalyticsItem*> *list; |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 219 | list = getMediaAnalyticsItemList(finished, ts, MediaAnalyticsItem::kKeyAny); |
| 220 | return list; |
| 221 | } |
| 222 | |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 223 | List<MediaAnalyticsItem *> *MediaAnalyticsService::getMediaAnalyticsItemList(bool , nsecs_t , MediaAnalyticsItem::Key ) { |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 224 | |
| 225 | // XXX: implement the get-item-list semantics |
| 226 | |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 227 | List<MediaAnalyticsItem *> *list = NULL; |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 228 | // set up our query on the persistent data |
| 229 | // slurp in all of the pieces |
| 230 | // return that |
| 231 | return list; |
| 232 | } |
| 233 | |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 234 | status_t MediaAnalyticsService::dump(int fd, const Vector<String16>& args) |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 235 | { |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 236 | const size_t SIZE = 512; |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 237 | char buffer[SIZE]; |
| 238 | String8 result; |
| 239 | |
| 240 | if (checkCallingPermission(String16("android.permission.DUMP")) == false) { |
| 241 | snprintf(buffer, SIZE, "Permission Denial: " |
| 242 | "can't dump MediaAnalyticsService from pid=%d, uid=%d\n", |
| 243 | IPCThreadState::self()->getCallingPid(), |
| 244 | IPCThreadState::self()->getCallingUid()); |
| 245 | result.append(buffer); |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 246 | write(fd, result.string(), result.size()); |
| 247 | return NO_ERROR; |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 248 | } |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 249 | |
| 250 | // crack any parameters |
| 251 | bool clear = false; |
| 252 | nsecs_t ts_since = 0; |
| 253 | String16 clearOption("-clear"); |
| 254 | String16 sinceOption("-since"); |
| 255 | int n = args.size(); |
| 256 | for (int i = 0; i < n; i++) { |
| 257 | String8 myarg(args[i]); |
| 258 | if (args[i] == clearOption) { |
| 259 | clear = true; |
| 260 | } else if (args[i] == sinceOption) { |
| 261 | i++; |
| 262 | if (i < n) { |
| 263 | String8 value(args[i]); |
| 264 | char *endp; |
| 265 | const char *p = value.string(); |
| 266 | ts_since = strtoll(p, &endp, 10); |
| 267 | if (endp == p || *endp != '\0') { |
| 268 | ts_since = 0; |
| 269 | } |
| 270 | } else { |
| 271 | ts_since = 0; |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | Mutex::Autolock _l(mLock); |
| 277 | |
| 278 | snprintf(buffer, SIZE, "Dump of the mediaanalytics process:\n"); |
| 279 | result.append(buffer); |
| 280 | |
| 281 | int enabled = MediaAnalyticsItem::isEnabled(); |
| 282 | if (enabled) { |
| 283 | snprintf(buffer, SIZE, "Analytics gathering: enabled\n"); |
| 284 | } else { |
| 285 | snprintf(buffer, SIZE, "Analytics gathering: DISABLED via property\n"); |
| 286 | } |
| 287 | result.append(buffer); |
| 288 | |
| 289 | snprintf(buffer, SIZE, |
| 290 | "Since Boot: Submissions: %" PRId64 |
| 291 | " Finalizations: %" PRId64 |
| 292 | " Discarded: %" PRId64 "\n", |
| 293 | mItemsSubmitted, mItemsFinalized, mItemsDiscarded); |
| 294 | result.append(buffer); |
| 295 | if (ts_since != 0) { |
| 296 | snprintf(buffer, SIZE, |
| 297 | "Dumping Queue entries more recent than: %" PRId64 "\n", |
| 298 | (int64_t) ts_since); |
| 299 | result.append(buffer); |
| 300 | } |
| 301 | |
| 302 | // show the recently recorded records |
| 303 | snprintf(buffer, sizeof(buffer), "\nFinalized Analytics (oldest first):\n"); |
| 304 | result.append(buffer); |
| 305 | result.append(this->dumpQueue(mFinalized, ts_since)); |
| 306 | |
| 307 | snprintf(buffer, sizeof(buffer), "\nIn-Progress Analytics (newest first):\n"); |
| 308 | result.append(buffer); |
| 309 | result.append(this->dumpQueue(mOpen, ts_since)); |
| 310 | |
| 311 | // show who is connected and injecting records? |
| 312 | // talk about # records fed to the 'readers' |
| 313 | // talk about # records we discarded, perhaps "discarded w/o reading" too |
| 314 | |
| 315 | if (clear) { |
| 316 | // remove everything from the finalized queue |
| 317 | while (mFinalized->size() > 0) { |
| 318 | MediaAnalyticsItem * oitem = *(mFinalized->begin()); |
| 319 | if (DEBUG_QUEUE) { |
| 320 | ALOGD("zap old record: key %s sessionID %" PRId64 " ts %" PRId64 "", |
| 321 | oitem->getKey().c_str(), oitem->getSessionID(), |
| 322 | oitem->getTimestamp()); |
| 323 | } |
| 324 | mFinalized->erase(mFinalized->begin()); |
| 325 | mItemsDiscarded++; |
| 326 | } |
| 327 | } |
| 328 | |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 329 | write(fd, result.string(), result.size()); |
| 330 | return NO_ERROR; |
| 331 | } |
| 332 | |
| 333 | // caller has locked mLock... |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 334 | String8 MediaAnalyticsService::dumpQueue(List<MediaAnalyticsItem *> *theList) { |
| 335 | return dumpQueue(theList, (nsecs_t) 0); |
| 336 | } |
| 337 | |
| 338 | String8 MediaAnalyticsService::dumpQueue(List<MediaAnalyticsItem *> *theList, nsecs_t ts_since) { |
| 339 | const size_t SIZE = 512; |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 340 | char buffer[SIZE]; |
| 341 | String8 result; |
| 342 | int slot = 0; |
| 343 | |
| 344 | if (theList->empty()) { |
| 345 | result.append("empty\n"); |
| 346 | } else { |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 347 | List<MediaAnalyticsItem *>::iterator it = theList->begin(); |
| 348 | for (; it != theList->end(); it++) { |
| 349 | nsecs_t when = (*it)->getTimestamp(); |
| 350 | if (when < ts_since) { |
| 351 | continue; |
| 352 | } |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 353 | AString entry = (*it)->toString(); |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 354 | snprintf(buffer, sizeof(buffer), "%4d: %s", |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 355 | slot, entry.c_str()); |
| 356 | result.append(buffer); |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 357 | buffer[0] = '\n'; |
| 358 | buffer[1] = '\0'; |
| 359 | result.append(buffer); |
| 360 | slot++; |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 361 | } |
| 362 | } |
| 363 | |
| 364 | return result; |
| 365 | } |
| 366 | |
| 367 | // |
| 368 | // Our Cheap in-core, non-persistent records management. |
| 369 | // XXX: rewrite this to manage persistence, etc. |
| 370 | |
| 371 | // insert appropriately into queue |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 372 | void MediaAnalyticsService::saveItem(List<MediaAnalyticsItem *> *l, MediaAnalyticsItem * item, int front) { |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 373 | |
| 374 | Mutex::Autolock _l(mLock); |
| 375 | |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 376 | if (DEBUG_QUEUE) { |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 377 | ALOGD("Inject a record: session %" PRId64 " ts %" PRId64 "", |
| 378 | item->getSessionID(), item->getTimestamp()); |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 379 | String8 before = dumpQueue(l); |
| 380 | ALOGD("Q before insert: %s", before.string()); |
| 381 | } |
| 382 | |
| 383 | // adding at back of queue (fifo order) |
| 384 | if (front) { |
| 385 | l->push_front(item); |
| 386 | } else { |
| 387 | l->push_back(item); |
| 388 | } |
| 389 | |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 390 | if (DEBUG_QUEUE) { |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 391 | String8 after = dumpQueue(l); |
| 392 | ALOGD("Q after insert: %s", after.string()); |
| 393 | } |
| 394 | |
| 395 | // keep removing old records the front until we're in-bounds |
| 396 | if (mMaxRecords > 0) { |
| 397 | while (l->size() > (size_t) mMaxRecords) { |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 398 | MediaAnalyticsItem * oitem = *(l->begin()); |
| 399 | if (DEBUG_QUEUE) { |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 400 | ALOGD("zap old record: key %s sessionID %" PRId64 " ts %" PRId64 "", |
| 401 | oitem->getKey().c_str(), oitem->getSessionID(), |
| 402 | oitem->getTimestamp()); |
| 403 | } |
| 404 | l->erase(l->begin()); |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 405 | ALOGD("drop record at %s:%d", __FILE__, __LINE__); |
| 406 | delete oitem; |
| 407 | ALOGD("[done] drop record at %s:%d", __FILE__, __LINE__); |
| 408 | mItemsDiscarded++; |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 412 | if (DEBUG_QUEUE) { |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 413 | String8 after = dumpQueue(l); |
| 414 | ALOGD("Q after cleanup: %s", after.string()); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | // are they alike enough that nitem can be folded into oitem? |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 419 | static bool compatibleItems(MediaAnalyticsItem * oitem, MediaAnalyticsItem * nitem) { |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 420 | |
| 421 | if (0) { |
| 422 | ALOGD("Compare: o %s n %s", |
| 423 | oitem->toString().c_str(), nitem->toString().c_str()); |
| 424 | } |
| 425 | |
| 426 | // general safety |
| 427 | if (nitem->getUid() != oitem->getUid()) { |
| 428 | return false; |
| 429 | } |
| 430 | if (nitem->getPid() != oitem->getPid()) { |
| 431 | return false; |
| 432 | } |
| 433 | |
| 434 | // key -- needs to match |
| 435 | if (nitem->getKey() == oitem->getKey()) { |
| 436 | // still in the game. |
| 437 | } else { |
| 438 | return false; |
| 439 | } |
| 440 | |
| 441 | // session id -- empty field in new is allowed |
| 442 | MediaAnalyticsItem::SessionID_t osession = oitem->getSessionID(); |
| 443 | MediaAnalyticsItem::SessionID_t nsession = nitem->getSessionID(); |
| 444 | if (nsession != osession) { |
| 445 | // incoming '0' matches value in osession |
| 446 | if (nsession != 0) { |
| 447 | return false; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | return true; |
| 452 | } |
| 453 | |
| 454 | // find the incomplete record that this will overlay |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 455 | MediaAnalyticsItem *MediaAnalyticsService::findItem(List<MediaAnalyticsItem*> *theList, MediaAnalyticsItem *nitem, bool removeit) { |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 456 | if (nitem == NULL) { |
| 457 | return NULL; |
| 458 | } |
| 459 | |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 460 | MediaAnalyticsItem *item = NULL; |
| 461 | |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 462 | Mutex::Autolock _l(mLock); |
| 463 | |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 464 | for (List<MediaAnalyticsItem *>::iterator it = theList->begin(); |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 465 | it != theList->end(); it++) { |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 466 | MediaAnalyticsItem *tmp = (*it); |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 467 | |
| 468 | if (!compatibleItems(tmp, nitem)) { |
| 469 | continue; |
| 470 | } |
| 471 | |
| 472 | // we match! this is the one I want. |
| 473 | if (removeit) { |
| 474 | theList->erase(it); |
| 475 | } |
| 476 | item = tmp; |
| 477 | break; |
| 478 | } |
| 479 | return item; |
| 480 | } |
| 481 | |
| 482 | |
| 483 | // delete the indicated record |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 484 | void MediaAnalyticsService::deleteItem(List<MediaAnalyticsItem *> *l, MediaAnalyticsItem *item) { |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 485 | |
| 486 | Mutex::Autolock _l(mLock); |
| 487 | |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 488 | if(DEBUG_QUEUE) { |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 489 | String8 before = dumpQueue(l); |
| 490 | ALOGD("Q before delete: %s", before.string()); |
| 491 | } |
| 492 | |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 493 | for (List<MediaAnalyticsItem *>::iterator it = l->begin(); |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 494 | it != l->end(); it++) { |
| 495 | if ((*it)->getSessionID() != item->getSessionID()) |
| 496 | continue; |
| 497 | |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 498 | if (DEBUG_QUEUE) { |
| 499 | ALOGD(" --- removing record for SessionID %" PRId64 "", item->getSessionID()); |
| 500 | ALOGD("drop record at %s:%d", __FILE__, __LINE__); |
| 501 | } |
| 502 | delete *it; |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 503 | l->erase(it); |
| 504 | break; |
| 505 | } |
| 506 | |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 507 | if (DEBUG_QUEUE) { |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 508 | String8 after = dumpQueue(l); |
| 509 | ALOGD("Q after delete: %s", after.string()); |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | // are the contents good |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 514 | bool MediaAnalyticsService::contentValid(MediaAnalyticsItem *) { |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 515 | |
| 516 | // certain keys require certain uids |
| 517 | // internal consistency |
| 518 | |
| 519 | return true; |
| 520 | } |
| 521 | |
| 522 | // are we rate limited, normally false |
Ray Essick | b5fac8e | 2016-12-12 11:33:56 -0800 | [diff] [blame] | 523 | bool MediaAnalyticsService::rateLimited(MediaAnalyticsItem *) { |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 524 | |
| 525 | return false; |
| 526 | } |
| 527 | |
| 528 | |
| 529 | } // namespace android |