Cache monitored tag dump for watched clients when disconnected.
This CL updates the 'watch' command to allow monitoring specific
connected clients, and caches the latest monitored tags dump from
tracked clients when they disconnect.
This allows the 'watch' command to print tag information for short lived
camera sessions.
Specifically, this CL does the following:
- Adds fields to CameraService to track which clients should be watched
and cached
- Adds arguments to 'watch start' to allow passing tag list and client
list
- Renames 'watch live' to 'watch print' and prints cached dump for
disconnected watched clients.
Test: Manually tested
Bug: 199746421
Change-Id: I0931837fffcffc9005f57ad52d6f3cb390eba1d7
diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h
index f701d30..c5ab7cb 100644
--- a/services/camera/libcameraservice/CameraService.h
+++ b/services/camera/libcameraservice/CameraService.h
@@ -829,6 +829,14 @@
RingBuffer<String8> mEventLog;
Mutex mLogLock;
+ // set of client package names to watch. if this set contains 'all', then all clients will
+ // be watched. Access should be guarded by mLogLock
+ std::set<String16> mWatchedClientPackages;
+ // cache of last monitored tags dump immediately before the client disconnects. If a client
+ // re-connects, its entry is not updated until it disconnects again. Access should be guarded
+ // by mLogLock
+ std::map<String16, std::string> mWatchedClientsDumpCache;
+
// The last monitored tags set by client
String8 mMonitorTags;
@@ -961,6 +969,8 @@
*/
void dumpEventLog(int fd);
+ void cacheClientTagDumpIfNeeded(const char *cameraId, BasicClient *client);
+
/**
* This method will acquire mServiceLock
*/
@@ -1154,17 +1164,21 @@
status_t handleSetCameraMute(const Vector<String16>& args);
// Handle 'watch' command as passed through 'cmd'
- status_t handleWatchCommand(const Vector<String16> &args, int out);
+ status_t handleWatchCommand(const Vector<String16> &args, int outFd);
- // Enable tag monitoring of the given tags in all attached clients
- status_t startWatchingTags(const String16 &tags, int outFd);
+ // Enable tag monitoring of the given tags in provided clients
+ status_t startWatchingTags(const Vector<String16> &args, int outFd);
- // Disable tag monitoring in all attached clients
+ // Disable tag monitoring
status_t stopWatchingTags(int outFd);
- // Print events of monitored tags in all attached devices as they are captured
+ // Print events of monitored tags in all cached and attached clients
+ status_t printWatchedTags(const Vector<String16> &args, int outFd);
+
+ // Print events of monitored tags in all attached clients as they are captured. New events are
+ // fetched every `refreshMicros` us
// NOTE: This function does not terminate unless interrupted.
- status_t printWatchedTagsUntilInterrupt(const Vector<String16> &args, int outFd);
+ status_t printWatchedTagsUntilInterrupt(useconds_t refreshMicros, int outFd);
// Print all events in vector `events' that came after lastPrintedEvent
static void printNewWatchedEvents(int outFd,
@@ -1173,9 +1187,23 @@
const std::vector<std::string> &events,
const std::string &lastPrintedEvent);
+ // Parses comma separated clients list and adds them to mWatchedClientPackages.
+ // Does not acquire mLogLock before modifying mWatchedClientPackages. It is the caller's
+ // responsibility to acquire mLogLock before calling this function.
+ void parseClientsToWatchLocked(String8 clients);
+
// Prints the shell command help
status_t printHelp(int out);
+ // Returns true if client should monitor tags based on the contents of mWatchedClientPackages.
+ // Acquires mLogLock before querying mWatchedClientPackages.
+ bool isClientWatched(const BasicClient *client);
+
+ // Returns true if client should monitor tags based on the contents of mWatchedClientPackages.
+ // Does not acquire mLogLock before querying mWatchedClientPackages. It is the caller's
+ // responsibility to acquire mLogLock before calling this functions.
+ bool isClientWatchedLocked(const BasicClient *client);
+
/**
* Get the current system time as a formatted string.
*/
@@ -1206,6 +1234,10 @@
// Use separate keys for offline devices.
static const String8 kOfflineDevice;
+ // Sentinel value to be stored in `mWatchedClientsPackages` to indicate that all clients should
+ // be watched.
+ static const String16 kWatchAllClientsFlag;
+
// TODO: right now each BasicClient holds one AppOpsManager instance.
// We can refactor the code so all of clients share this instance
AppOpsManager mAppOps;