Commit a2eefc11 authored by Kesha Antonov's avatar Kesha Antonov

use wifi info only for 2 funcs

parent 61cdeaa2
...@@ -40,10 +40,6 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -40,10 +40,6 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
super(reactContext); super(reactContext);
this.reactContext = reactContext; this.reactContext = reactContext;
WifiManager manager = (WifiManager) reactContext.getSystemService(Context.WIFI_SERVICE);
this.wifiInfo = manager.getConnectionInfo();
} }
@Override @Override
...@@ -51,6 +47,14 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -51,6 +47,14 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
return "RNDeviceInfo"; return "RNDeviceInfo";
} }
private WifiInfo getWifiInfo() {
if ( this.wifiInfo == null ) {
WifiManager manager = (WifiManager) reactContext.getSystemService(Context.WIFI_SERVICE);
this.wifiInfo = manager.getConnectionInfo();
}
return this.wifiInfo;
}
private String getCurrentLanguage() { private String getCurrentLanguage() {
Locale current = getReactApplicationContext().getResources().getConfiguration().locale; Locale current = getReactApplicationContext().getResources().getConfiguration().locale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
...@@ -95,13 +99,13 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -95,13 +99,13 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
@ReactMethod @ReactMethod
public void getIpAddress(Promise p) { public void getIpAddress(Promise p) {
String ipAddress = Formatter.formatIpAddress(wifiInfo.getIpAddress()); String ipAddress = Formatter.formatIpAddress(getWifiInfo().getIpAddress());
p.resolve(ipAddress); p.resolve(ipAddress);
} }
@ReactMethod @ReactMethod
public void getMacAddress(Promise p) { public void getMacAddress(Promise p) {
String macAddress = wifiInfo.getMacAddress(); String macAddress = getWifiInfo().getMacAddress();
p.resolve(macAddress); p.resolve(macAddress);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment