Lint - Use easily identifiable wake lock tags.

fork-5.53.8
Alan Evans 2019-05-20 12:19:57 -03:00
rodzic 95858898d7
commit 10ad3fbf82
5 zmienionych plików z 21 dodań i 8 usunięć

Wyświetl plik

@ -44,7 +44,7 @@ public class MmsRadio {
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
this.context = context; this.context = context;
this.connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 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); this.wakeLock.setReferenceCounted(true);
} }

Wyświetl plik

@ -149,7 +149,7 @@ public class ApplicationMigrationService extends Service
public void run() { public void run() {
notification = initializeBackgroundNotification(); notification = initializeBackgroundNotification();
PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE); 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 { try {
wakeLock.acquire(); wakeLock.acquire();

Wyświetl plik

@ -13,6 +13,8 @@ public class WakeLockUtil {
/** /**
* Run a runnable with a wake lock. Ensures that the lock is safely acquired and released. * 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) { public static void runWithLock(@NonNull Context context, int lockType, long timeout, @NonNull String tag, @NonNull Runnable task) {
WakeLock wakeLock = null; 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) { public static WakeLock acquire(@NonNull Context context, int lockType, long timeout, @NonNull String tag) {
tag = prefixTag(tag);
try { try {
PowerManager powerManager = ServiceUtil.getPowerManager(context); PowerManager powerManager = ServiceUtil.getPowerManager(context);
WakeLock wakeLock = powerManager.newWakeLock(lockType, tag); 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) { public static void release(@NonNull WakeLock wakeLock, @NonNull String tag) {
tag = prefixTag(tag);
try { try {
if (wakeLock.isHeld()) { if (wakeLock.isHeld()) {
wakeLock.release(); wakeLock.release();
@ -53,4 +63,8 @@ public class WakeLockUtil {
Log.w(TAG, "Failed to release wakelock with tag: " + tag, e); 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;
}
} }

Wyświetl plik

@ -44,12 +44,12 @@ public class LockManager {
public LockManager(Context context) { public LockManager(Context context) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
fullLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "RedPhone Full"); fullLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "signal:full");
partialLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RedPhone Partial"); partialLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "signal:partial");
proximityLock = new ProximityLock(pm); proximityLock = new ProximityLock(pm);
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); 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); fullLock.setReferenceCounted(false);
partialLock.setReferenceCounted(false); partialLock.setReferenceCounted(false);

Wyświetl plik

@ -32,14 +32,13 @@ class ProximityLock {
private Optional<PowerManager.WakeLock> getProximityLock(PowerManager pm) { private Optional<PowerManager.WakeLock> getProximityLock(PowerManager pm) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (pm.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) { if (pm.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) {
return Optional.fromNullable(pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, return Optional.fromNullable(pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "signal:proximity"));
"Signal Proximity Lock"));
} else { } else {
return Optional.absent(); return Optional.absent();
} }
} else { } else {
try { 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) { } catch (Throwable t) {
Log.e(TAG, "Failed to create proximity lock", t); Log.e(TAG, "Failed to create proximity lock", t);
return Optional.absent(); return Optional.absent();