Skip to content

Commit

Permalink
Merge pull request #249 from kesha-antonov/fix_wifi_crash
Browse files Browse the repository at this point in the history
Fix "Neither user nor current process has android.persmission.ACCESS_WIFI_STATE"
  • Loading branch information
GantMan committed Oct 17, 2017
2 parents 61cdeaa + 88e6ba6 commit 9088824
Showing 1 changed file with 12 additions and 8 deletions.
Expand Up @@ -40,17 +40,21 @@ public RNDeviceModule(ReactApplicationContext reactContext) {
super(reactContext);

this.reactContext = reactContext;


WifiManager manager = (WifiManager) reactContext.getSystemService(Context.WIFI_SERVICE);
this.wifiInfo = manager.getConnectionInfo();
}

@Override
public String getName() {
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() {
Locale current = getReactApplicationContext().getResources().getConfiguration().locale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Expand Down Expand Up @@ -89,19 +93,19 @@ 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());
}

@ReactMethod
public void getIpAddress(Promise p) {
String ipAddress = Formatter.formatIpAddress(wifiInfo.getIpAddress());
String ipAddress = Formatter.formatIpAddress(getWifiInfo().getIpAddress());
p.resolve(ipAddress);
}

@ReactMethod
public void getMacAddress(Promise p) {
String macAddress = wifiInfo.getMacAddress();
String macAddress = getWifiInfo().getMacAddress();
p.resolve(macAddress);
}

Expand Down Expand Up @@ -161,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 9088824

Please sign in to comment.