Prevent possible WifiManager leak

This commit is contained in:
Andrew Rabert 2017-03-05 11:27:30 -05:00
parent 17401fd7e1
commit 416846499a
2 changed files with 3 additions and 3 deletions

View File

@ -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)) {

View File

@ -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;