Commit 90888244 authored by Gant Laborde's avatar Gant Laborde Committed by GitHub

Merge pull request #249 from kesha-antonov/fix_wifi_crash

Fix "Neither user nor current process has android.persmission.ACCESS_WIFI_STATE"
parents 61cdeaa2 88e6ba64
...@@ -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.getApplicationContext().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) {
...@@ -89,19 +93,19 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -89,19 +93,19 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
@ReactMethod @ReactMethod
public void isPinOrFingerprintSet(Callback callback) { 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()); callback.invoke(keyguardManager.isKeyguardSecure());
} }
@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);
} }
...@@ -161,7 +165,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -161,7 +165,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
(getCurrentActivity().checkCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED || (getCurrentActivity().checkCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED ||
getCurrentActivity().checkCallingOrSelfPermission(Manifest.permission.READ_SMS) == PackageManager.PERMISSION_GRANTED || getCurrentActivity().checkCallingOrSelfPermission(Manifest.permission.READ_SMS) == PackageManager.PERMISSION_GRANTED ||
getCurrentActivity().checkCallingOrSelfPermission("android.permission.READ_PHONE_NUMBERS") == 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()); constants.put("phoneNumber", telMgr.getLine1Number());
} }
return constants; return constants;
......
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