Skip to content

Commit

Permalink
Merge branch 'master_new' into update483
Browse files Browse the repository at this point in the history
* master_new:
  chore(asdf): add a .tool-versions for asdf, set node to 16.18.0 and update package-lock files
  chore(release): 4.8.3 [skip ci]
  fix(iOS): add missing isHidden flag to connectToProtectedSSID (JuanSeBestia#306)
  chore(release): 4.8.2 [skip ci]
  fix: prefer not to mutate the ScanResult object (JuanSeBestia#268)
  chore(release): 4.8.1 [skip ci]
  fix: update android native dependencies
  chore(release): 4.8.0 [skip ci]
  feat(Android): added feature to connect to hidden wifi on android 10 (JuanSeBestia#287)
  chore(release): 4.7.1 [skip ci]
  fix(Android): * add location permission check for getCurrentWifiSSID and reScanAndLoadWifiList and change error message for clarity (JuanSeBestia#264)
  • Loading branch information
timok06 committed Aug 4, 2023
2 parents b8c0aa3 + b698894 commit ba73782
Show file tree
Hide file tree
Showing 14 changed files with 48,118 additions and 1,260 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: 'circleci/node:latest'
- image: 'cimg/node:16.8.0'
steps:
- checkout

Expand Down
3 changes: 3 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodejs 16.18.0
ruby 2.7.4
java zulu-11.52.13
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
## [4.8.3](https://github.com/JuanSeBestia/react-native-wifi-reborn/compare/v4.8.2...v4.8.3) (2023-05-26)


### Bug Fixes

* **iOS:** add missing isHidden flag to connectToProtectedSSID ([#306](https://github.com/JuanSeBestia/react-native-wifi-reborn/issues/306)) ([11a703d](https://github.com/JuanSeBestia/react-native-wifi-reborn/commit/11a703d4ece723fb9fce90e0dc0e02f865613190)), closes [#287](https://github.com/JuanSeBestia/react-native-wifi-reborn/issues/287)

## [4.8.2](https://github.com/JuanSeBestia/react-native-wifi-reborn/compare/v4.8.1...v4.8.2) (2023-05-26)


### Bug Fixes

* prefer not to mutate the ScanResult object ([#268](https://github.com/JuanSeBestia/react-native-wifi-reborn/issues/268)) ([840c80d](https://github.com/JuanSeBestia/react-native-wifi-reborn/commit/840c80de870d91238c50842ab53827334d380ec2))

## [4.8.1](https://github.com/JuanSeBestia/react-native-wifi-reborn/compare/v4.8.0...v4.8.1) (2023-05-26)


### Bug Fixes

* update android native dependencies ([472896d](https://github.com/JuanSeBestia/react-native-wifi-reborn/commit/472896d51c90b67ac6ba7329eb34929acde50155))

# [4.8.0](https://github.com/JuanSeBestia/react-native-wifi-reborn/compare/v4.7.1...v4.8.0) (2023-05-26)


### Features

* **Android:** added feature to connect to hidden wifi on android 10 ([#287](https://github.com/JuanSeBestia/react-native-wifi-reborn/issues/287)) ([32b5db2](https://github.com/JuanSeBestia/react-native-wifi-reborn/commit/32b5db2e1ebcdc757a4dec39f1441a4c9586a827))

## [4.7.1](https://github.com/JuanSeBestia/react-native-wifi-reborn/compare/v4.7.0...v4.7.1) (2023-05-26)


### Bug Fixes

* **Android:** * add location permission check for getCurrentWifiSSID and reScanAndLoadWifiList and change error message for clarity ([#264](https://github.com/JuanSeBestia/react-native-wifi-reborn/issues/264)) ([c3ba4e5](https://github.com/JuanSeBestia/react-native-wifi-reborn/commit/c3ba4e532fc937cf757937448140af50e360988c))

# [4.7.0](https://github.com/JuanSeBestia/react-native-wifi-reborn/compare/v4.6.0...v4.7.0) (2022-07-12)


Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ _The api documentation is in progress._

The following methods work on both Android and iOS

### `connectToProtectedSSID(SSID: string, password: string, isWEP: boolean): Promise`
### `connectToProtectedSSID(SSID: string, password: string, isWEP: boolean, isHidden: boolean): Promise`

Returns a promise that resolves when connected or rejects with the error when it couldn't connect to the wifi network.

Expand All @@ -188,9 +188,15 @@ Type: `string`
The password of the wifi network to connect with.

#### isWep

Type: `boolean`
Used on iOS. If true, the network is WEP Wi-Fi; otherwise it is a WPA or WPA2 personal Wi-Fi network.

#### isHidden

Type: `boolean`
Used on Android. If true, the network is a hidden Wi-Fi network.

#### Errors:
* iOS:
* `unavailableForOSVersion`: Starting from iOS 11, NEHotspotConfigurationError is available.
Expand Down
17 changes: 10 additions & 7 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

buildscript {
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.android.tools.build:gradle:7.1.3'
}
}

apply plugin: 'com.android.library'

android {
compileSdkVersion 30
buildToolsVersion '29.0.3'
compileSdkVersion safeExtGet(compileSdkVersion, 31)

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
minSdkVersion 21
targetSdkVersion 30
minSdkVersion safeExtGet(minSdkVersion, 21)
targetSdkVersion safeExtGet(targetSdkVersion, 31)
versionCode 1
versionName "1.0"
versionName '1.0'
}
}

Expand All @@ -34,7 +37,7 @@ repositories {
url "$projectDir/../node_modules/react-native/android"
}
google()
jcenter()
mavenCentral()
}

dependencies {
Expand Down
6 changes: 3 additions & 3 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Jun 11 07:37:41 CEST 2020
#Mon Sep 05 19:12:21 CEST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip
zipStoreBase=GRADLE_USER_HOME
70 changes: 41 additions & 29 deletions android/src/main/java/com/reactlibrary/rnwifi/RNWifiModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,7 @@ public String getName() {
*/
@ReactMethod
public void loadWifiList(final Promise promise) {
final boolean locationPermissionGranted = PermissionUtils.isLocationPermissionGranted(context);
if (!locationPermissionGranted) {
promise.reject(LoadWifiListErrorCodes.locationPermissionMissing.toString(), "Location permission (ACCESS_FINE_LOCATION) is not granted");
return;
}

final boolean isLocationOn = LocationUtils.isLocationOn(context);
if (!isLocationOn) {
promise.reject(LoadWifiListErrorCodes.locationServicesOff.toString(), "Location service is turned off");
if(!assertLocationPermissionGranted(promise)){
return;
}

Expand Down Expand Up @@ -254,19 +246,12 @@ public void setEnabled(final boolean enabled) {
* @param SSID name of the network to connect with
* @param password password of the network to connect with
* @param isWep only for iOS
* @param isHidden only for Android, use if WiFi is hidden
* @param promise to send success/error feedback
*/
@ReactMethod
public void connectToProtectedSSID(@NonNull final String SSID, @NonNull final String password, final boolean isWep, final Promise promise) {
final boolean locationPermissionGranted = PermissionUtils.isLocationPermissionGranted(context);
if (!locationPermissionGranted) {
promise.reject(ConnectErrorCodes.locationPermissionMissing.toString(), "Location permission (ACCESS_FINE_LOCATION) is not granted");
return;
}

final boolean isLocationOn = LocationUtils.isLocationOn(context);
if (!isLocationOn) {
promise.reject(ConnectErrorCodes.locationServicesOff.toString(), "Location service is turned off");
public void connectToProtectedSSID(@NonNull final String SSID, @NonNull final String password, final boolean isWep, final boolean isHidden, final Promise promise) {
if(!assertLocationPermissionGranted(promise)) {
return;
}

Expand All @@ -275,9 +260,8 @@ public void connectToProtectedSSID(@NonNull final String SSID, @NonNull final St
return;
}


this.removeWifiNetwork(SSID, promise, () -> {
connectToWifiDirectly(SSID, password, promise);
connectToWifiDirectly(SSID, password, isHidden, promise);
});
}

Expand Down Expand Up @@ -338,6 +322,10 @@ public void failed(@NonNull DisconnectionErrorCode errorCode) {
*/
@ReactMethod
public void getCurrentWifiSSID(final Promise promise) {
if(!assertLocationPermissionGranted(promise)){
return;
}

String ssid = getWifiSSID();
if (ssid == null) {
promise.reject(GetCurrentWifiSSIDErrorCodes.couldNotDetectSSID.toString(), "Not connected or connecting.");
Expand Down Expand Up @@ -452,16 +440,18 @@ public void failed(@NonNull RemoveErrorCode errorCode) {
*/
@ReactMethod
public void reScanAndLoadWifiList(final Promise promise) {
if(!assertLocationPermissionGranted(promise)) {
return;
}

final WifiScanResultReceiver wifiScanResultReceiver = new WifiScanResultReceiver(wifi, promise);
getReactApplicationContext().registerReceiver(wifiScanResultReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
wifi.startScan();
}

private void connectToWifiDirectly(@NonNull final String SSID, @NonNull final String password, final Promise promise) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
connectAndroidR(SSID, password, promise);
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
connectAndroidQ(SSID, password, promise);
private void connectToWifiDirectly(@NonNull final String SSID, @NonNull final String password, final boolean isHidden, final Promise promise) {
if (isAndroidTenOrLater()) {
connectAndroidQ(SSID, password, isHidden, promise);
} else {
connectPreAndroidQ(SSID, password, promise);
}
Expand Down Expand Up @@ -498,7 +488,10 @@ private void connectPreAndroidQ(@NonNull final String SSID, @NonNull final Strin
}

@RequiresApi(api = Build.VERSION_CODES.Q)
private void connectAndroidQ(@NonNull final String SSID, @NonNull final String password, final Promise promise) {
private void connectAndroidQ(@NonNull final String SSID, @NonNull final String password, final boolean isHidden, final Promise promise) {
WifiNetworkSpecifier.Builder wifiNetworkSpecifier = new WifiNetworkSpecifier.Builder()
.setIsHiddenSsid(isHidden)
.setSsid(SSID);

WifiNetworkSuggestion suggestion =
new WifiNetworkSuggestion.Builder()
Expand Down Expand Up @@ -537,8 +530,11 @@ private void connectAndroidR(@NonNull final String SSID, @NonNull final String p
.setWpa2Passphrase(password)
.build();

WifiManager wifiManager =
(WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
@Override
public void onUnavailable() {
super.onUnavailable();
promise.reject(ConnectErrorCodes.didNotFindNetwork.toString(), "Network not found or network request cannot be fulfilled.");
}

ArrayList<WifiNetworkSuggestion> suggestionsList =
new ArrayList<WifiNetworkSuggestion>();
Expand Down Expand Up @@ -645,4 +641,20 @@ private void stuffWifiConfigurationWithoutEncryption(final WifiConfiguration wif
private String formatWithBackslashes(final String value) {
return String.format("\"%s\"", value);
}

private boolean assertLocationPermissionGranted(final Promise promise) {
final boolean locationPermissionGranted = PermissionUtils.isLocationPermissionGranted(context);
if (!locationPermissionGranted) {
promise.reject(ConnectErrorCodes.locationPermissionMissing.toString(), "Location permission (ACCESS_FINE_LOCATION) is not granted");
return false;
}

final boolean isLocationOn = LocationUtils.isLocationOn(context);
if (!isLocationOn) {
promise.reject(ConnectErrorCodes.locationServicesOff.toString(), "Location service is turned off");
return false;
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@ public class WifiScanResultsMapper {
private WifiScanResultsMapper() {
}

private static String parseSSID(final ScanResult scanResult) {
if (scanResult.SSID.equals("")) {
return "(hidden SSID)";
}

return scanResult.SSID;
}

public static WritableArray mapWifiScanResults(final List<ScanResult> scanResults) {
final WritableArray wifiArray = new WritableNativeArray();

for (ScanResult result : scanResults) {
final WritableMap wifiObject = new WritableNativeMap();
if (result.SSID.equals("")) {
result.SSID = "(hidden SSID)";
}
wifiObject.putString("SSID", result.SSID);
wifiObject.putString("SSID", parseSSID(result));
wifiObject.putString("BSSID", result.BSSID);
wifiObject.putString("capabilities", result.capabilities);
wifiObject.putInt("frequency", result.frequency);
Expand Down
1 change: 1 addition & 0 deletions example/RNWifiReborn/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const App = () => {
ssid,
password,
false,
false,
);
console.log('Connected successfully!', {data});
setConnected({connected: true, ssid});
Expand Down
Loading

0 comments on commit ba73782

Please sign in to comment.