From 416846499a548104110df9750b88e5452e3af867 Mon Sep 17 00:00:00 2001 From: Andrew Rabert Date: Sun, 5 Mar 2017 11:27:30 -0500 Subject: [PATCH] Prevent possible WifiManager leak --- app/src/main/java/net/nullsum/audinaut/util/ServerProxy.java | 2 +- app/src/main/java/net/nullsum/audinaut/util/Util.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/net/nullsum/audinaut/util/ServerProxy.java b/app/src/main/java/net/nullsum/audinaut/util/ServerProxy.java index 86bdba6..3cb0ccc 100644 --- a/app/src/main/java/net/nullsum/audinaut/util/ServerProxy.java +++ b/app/src/main/java/net/nullsum/audinaut/util/ServerProxy.java @@ -81,7 +81,7 @@ public abstract class ServerProxy implements Runnable { return getAddress("127.0.0.1", request); } public String getPublicAddress(String request) { - WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); int ipAddress = wifiManager.getConnectionInfo().getIpAddress(); if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) { diff --git a/app/src/main/java/net/nullsum/audinaut/util/Util.java b/app/src/main/java/net/nullsum/audinaut/util/Util.java index 1556e19..b000101 100644 --- a/app/src/main/java/net/nullsum/audinaut/util/Util.java +++ b/app/src/main/java/net/nullsum/audinaut/util/Util.java @@ -998,7 +998,7 @@ public final class Util { } public static String getSSID(Context context) { if (isWifiConnected(context)) { - WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); if (wifiManager.getConnectionInfo() != null && wifiManager.getConnectionInfo().getSSID() != null) { return wifiManager.getConnectionInfo().getSSID().replace("\"", ""); } @@ -1371,7 +1371,7 @@ public final class Util { } public static WifiManager.WifiLock createWifiLock(Context context, String tag) { - WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + WifiManager wm = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); int lockType = WifiManager.WIFI_MODE_FULL; if (Build.VERSION.SDK_INT >= 12) { lockType = 3;