From 10ad3fbf821d00a26b82689b16ca2fc59f2b2b55 Mon Sep 17 00:00:00 2001 From: Alan Evans Date: Mon, 20 May 2019 12:19:57 -0300 Subject: [PATCH] Lint - Use easily identifiable wake lock tags. --- src/org/thoughtcrime/securesms/mms/MmsRadio.java | 2 +- .../service/ApplicationMigrationService.java | 2 +- .../thoughtcrime/securesms/util/WakeLockUtil.java | 14 ++++++++++++++ .../securesms/webrtc/locks/LockManager.java | 6 +++--- .../securesms/webrtc/locks/ProximityLock.java | 5 ++--- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/org/thoughtcrime/securesms/mms/MmsRadio.java b/src/org/thoughtcrime/securesms/mms/MmsRadio.java index 1d5325631a..2ae17f5d02 100644 --- a/src/org/thoughtcrime/securesms/mms/MmsRadio.java +++ b/src/org/thoughtcrime/securesms/mms/MmsRadio.java @@ -44,7 +44,7 @@ public class MmsRadio { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); this.context = context; this.connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - this.wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MMS Connection"); + this.wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "signal:mms"); this.wakeLock.setReferenceCounted(true); } diff --git a/src/org/thoughtcrime/securesms/service/ApplicationMigrationService.java b/src/org/thoughtcrime/securesms/service/ApplicationMigrationService.java index 9ca26774c2..0436711b16 100644 --- a/src/org/thoughtcrime/securesms/service/ApplicationMigrationService.java +++ b/src/org/thoughtcrime/securesms/service/ApplicationMigrationService.java @@ -149,7 +149,7 @@ public class ApplicationMigrationService extends Service public void run() { notification = initializeBackgroundNotification(); PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE); - WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Migration"); + WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "signal:migration"); try { wakeLock.acquire(); diff --git a/src/org/thoughtcrime/securesms/util/WakeLockUtil.java b/src/org/thoughtcrime/securesms/util/WakeLockUtil.java index f5ed6d13f3..6d16e354c6 100644 --- a/src/org/thoughtcrime/securesms/util/WakeLockUtil.java +++ b/src/org/thoughtcrime/securesms/util/WakeLockUtil.java @@ -13,6 +13,8 @@ public class WakeLockUtil { /** * Run a runnable with a wake lock. Ensures that the lock is safely acquired and released. + * + * @param tag will be prefixed with "signal:" if it does not already start with it. */ public static void runWithLock(@NonNull Context context, int lockType, long timeout, @NonNull String tag, @NonNull Runnable task) { WakeLock wakeLock = null; @@ -26,7 +28,11 @@ public class WakeLockUtil { } } + /** + * @param tag will be prefixed with "signal:" if it does not already start with it. + */ public static WakeLock acquire(@NonNull Context context, int lockType, long timeout, @NonNull String tag) { + tag = prefixTag(tag); try { PowerManager powerManager = ServiceUtil.getPowerManager(context); WakeLock wakeLock = powerManager.newWakeLock(lockType, tag); @@ -41,7 +47,11 @@ public class WakeLockUtil { } } + /** + * @param tag will be prefixed with "signal:" if it does not already start with it. + */ public static void release(@NonNull WakeLock wakeLock, @NonNull String tag) { + tag = prefixTag(tag); try { if (wakeLock.isHeld()) { wakeLock.release(); @@ -53,4 +63,8 @@ public class WakeLockUtil { Log.w(TAG, "Failed to release wakelock with tag: " + tag, e); } } + + private static String prefixTag(@NonNull String tag) { + return tag.startsWith("signal:") ? tag : "signal:" + tag; + } } diff --git a/src/org/thoughtcrime/securesms/webrtc/locks/LockManager.java b/src/org/thoughtcrime/securesms/webrtc/locks/LockManager.java index 0eb278a0f7..20a6edeba7 100644 --- a/src/org/thoughtcrime/securesms/webrtc/locks/LockManager.java +++ b/src/org/thoughtcrime/securesms/webrtc/locks/LockManager.java @@ -44,12 +44,12 @@ public class LockManager { public LockManager(Context context) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); - fullLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "RedPhone Full"); - partialLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RedPhone Partial"); + fullLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "signal:full"); + partialLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "signal:partial"); proximityLock = new ProximityLock(pm); WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); - wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "RedPhone Wifi"); + wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "signal:wifi"); fullLock.setReferenceCounted(false); partialLock.setReferenceCounted(false); diff --git a/src/org/thoughtcrime/securesms/webrtc/locks/ProximityLock.java b/src/org/thoughtcrime/securesms/webrtc/locks/ProximityLock.java index 938381e7ea..323db13dc4 100644 --- a/src/org/thoughtcrime/securesms/webrtc/locks/ProximityLock.java +++ b/src/org/thoughtcrime/securesms/webrtc/locks/ProximityLock.java @@ -32,14 +32,13 @@ class ProximityLock { private Optional getProximityLock(PowerManager pm) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (pm.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) { - return Optional.fromNullable(pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, - "Signal Proximity Lock")); + return Optional.fromNullable(pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "signal:proximity")); } else { return Optional.absent(); } } else { try { - return Optional.fromNullable(pm.newWakeLock(PROXIMITY_SCREEN_OFF_WAKE_LOCK, "RedPhone Incall")); + return Optional.fromNullable(pm.newWakeLock(PROXIMITY_SCREEN_OFF_WAKE_LOCK, "signal:incall")); } catch (Throwable t) { Log.e(TAG, "Failed to create proximity lock", t); return Optional.absent();