aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDaniel Erat <derat@google.com>2015-10-16 11:10:05 -0600
committerDaniel Erat <derat@google.com>2015-10-16 11:58:53 -0600
commit4f13a604088be86b9df607655d75b039aa5da4d2 (patch)
treeae6b1c9c2cf7d9fe0c83e76b8e78e07c3ebf4c1e /include
parent78132a0e300173bf3b738c9caf30f3941ff31cd2 (diff)
downloadnativepower-4f13a604088be86b9df607655d75b039aa5da4d2.tar.gz
Look up callers' UIDs when wake locks are acquired.
Update PowerManager::acquireWakeLock() to get the calling process's actual UID instead of just storing -1. (The UID isn't used for anything, though.) Also do some related refactoring that came up while adding tests: to avoid duplicated code, make PowerManagerStub use WakeLockManagerStub instead of recording wake lock requests itself. Bug: 24988639 Change-Id: If2d2d2935052ab268f6b21dd72a7b1f02a66d799
Diffstat (limited to 'include')
-rw-r--r--include/nativepower/power_manager_stub.h44
1 files changed, 18 insertions, 26 deletions
diff --git a/include/nativepower/power_manager_stub.h b/include/nativepower/power_manager_stub.h
index d31c130..47ae1dd 100644
--- a/include/nativepower/power_manager_stub.h
+++ b/include/nativepower/power_manager_stub.h
@@ -14,7 +14,10 @@
* limitations under the License.
*/
+#include <sys/types.h>
+
#include <map>
+#include <memory>
#include <string>
#include <vector>
@@ -23,17 +26,21 @@
namespace android {
+class WakeLockManagerStub;
+
// Stub implementation of BnPowerManager for use in tests.
+//
+// The BinderWrapper singleton must be initialized before using this class.
class PowerManagerStub : public BnPowerManager {
public:
PowerManagerStub();
~PowerManagerStub() override;
// Constructs a string that can be compared with one returned by
- // GetLockString().
- static std::string ConstructLockString(const std::string& tag,
- const std::string& package,
- int uid);
+ // GetWakeLockString().
+ static std::string ConstructWakeLockString(const std::string& tag,
+ const std::string& package,
+ uid_t uid);
// Constructs a string that can be compared with one returned by
// GetSuspendRequestString().
@@ -41,7 +48,6 @@ class PowerManagerStub : public BnPowerManager {
int reason,
int flags);
- size_t num_locks() const { return locks_.size(); }
size_t num_suspend_requests() const { return suspend_requests_.size(); }
const std::vector<std::string>& reboot_reasons() const {
return reboot_reasons_;
@@ -50,9 +56,12 @@ class PowerManagerStub : public BnPowerManager {
return shutdown_reasons_;
}
- // Returns a string describing the lock registered for |binder|, or an empty
- // string if no lock is present.
- std::string GetLockString(const sp<IBinder>& binder) const;
+ // Returns the number of currently-registered wake locks.
+ int GetNumWakeLocks() const;
+
+ // Returns a string describing the wake lock registered for |binder|, or an
+ // empty string if no wake lock is present.
+ std::string GetWakeLockString(const sp<IBinder>& binder) const;
// Returns a string describing position |index| in |suspend_requests_|.
std::string GetSuspendRequestString(size_t index) const;
@@ -83,22 +92,6 @@ class PowerManagerStub : public BnPowerManager {
status_t crash(const String16& message) override;
private:
- // Contains information passed to acquireWakeLock() or
- // acquireWakeLockWithUid().
- struct LockInfo {
- LockInfo();
- LockInfo(const LockInfo& info);
- LockInfo(const std::string& tag,
- const std::string& package,
- int uid);
-
- std::string tag;
- std::string package;
-
- // -1 if acquireWakeLock() was used.
- int uid;
- };
-
// Details about a request passed to goToSleep().
struct SuspendRequest {
SuspendRequest(int64 uptime_ms, int reason, int flags);
@@ -108,8 +101,7 @@ class PowerManagerStub : public BnPowerManager {
int flags;
};
- using LockInfoMap = std::map<sp<IBinder>, LockInfo>;
- LockInfoMap locks_;
+ std::unique_ptr<WakeLockManagerStub> wake_lock_manager_;
// Information about calls to goToSleep(), in the order they were made.
using SuspendRequests = std::vector<SuspendRequest>;