Skip to content

Commit

Permalink
fix: Error: The WIFI_SERVICE must be looked up on the Application con…
Browse files Browse the repository at this point in the history
…text or memory will leak on devices < Android N. Try changing reactContext to reactContext.getApplicationContext() [WifiManagerLeak] WifiManager manager = (WifiManager) reactContext.getSystemService(Context.WIFI_SERVICE);
  • Loading branch information
kesha-antonov committed Oct 16, 2017
1 parent a2eefc1 commit 88e6ba6
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public String getName() {

private WifiInfo getWifiInfo() {
if ( this.wifiInfo == null ) {
WifiManager manager = (WifiManager) reactContext.getSystemService(Context.WIFI_SERVICE);
WifiManager manager = (WifiManager) reactContext.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
this.wifiInfo = manager.getConnectionInfo();
}
return this.wifiInfo;
Expand Down Expand Up @@ -93,7 +93,7 @@ private Boolean isTablet() {

@ReactMethod
public void isPinOrFingerprintSet(Callback callback) {
KeyguardManager keyguardManager = (KeyguardManager) this.reactContext.getSystemService(Context.KEYGUARD_SERVICE); //api 16+
KeyguardManager keyguardManager = (KeyguardManager) this.reactContext.getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE); //api 16+
callback.invoke(keyguardManager.isKeyguardSecure());
}

Expand Down Expand Up @@ -165,7 +165,7 @@ public void getMacAddress(Promise p) {
(getCurrentActivity().checkCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED ||
getCurrentActivity().checkCallingOrSelfPermission(Manifest.permission.READ_SMS) == PackageManager.PERMISSION_GRANTED ||
getCurrentActivity().checkCallingOrSelfPermission("android.permission.READ_PHONE_NUMBERS") == PackageManager.PERMISSION_GRANTED)) {
TelephonyManager telMgr = (TelephonyManager) this.reactContext.getSystemService(Context.TELEPHONY_SERVICE);
TelephonyManager telMgr = (TelephonyManager) this.reactContext.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
constants.put("phoneNumber", telMgr.getLine1Number());
}
return constants;
Expand Down

0 comments on commit 88e6ba6

Please sign in to comment.