Skip to content

Commit

Permalink
Release 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ThanosFisherman committed Jan 19, 2020
1 parent 4e712d6 commit 9bf85eb
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ WifiUtils.withContext(getApplicationContext())
If you want to receive some extra logging info comming from WiFi Utils you can enable its logging capabilities with `WifiUtils.enableLog(true);`

### Permissions
Damn You are required to set a few permissions in order for this lib to work correctly :(
Damn You are required to set a few permissions in order for this lib to work correctly :( Also please check [this](https://issuetracker.google.com/issues/37060483) issue

```xml
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ ext {
buildToolsVersion = '29.0.0'
minSdkVersion = 15
targetSdkVersion = 29
publishVersionName = '1.4.2'
publishVersionCode = 14
publishVersionName = '1.5.0'
publishVersionCode = 15

currentVersionDesc = 'WifiUtils current version'
bintrayRepo = 'maven'
Expand Down
2 changes: 1 addition & 1 deletion wifiutils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies {
implementation "androidx.annotation:annotation:1.1.0"
implementation 'com.thanosfisherman.elvis:elvis:2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2-alpha02'
androidTestImplementation 'androidx.test.ext:junit:1.1.2-alpha03'
}
//apply from: 'install.gradle'
//apply from: 'bintray.gradle'
1 change: 1 addition & 0 deletions wifiutils/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<manifest package="com.thanosfisherman.wifiutils"
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresPermission;

import com.thanosfisherman.elvis.Objects;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import static android.Manifest.permission.ACCESS_FINE_LOCATION;
import static android.Manifest.permission.ACCESS_WIFI_STATE;
import static com.thanosfisherman.wifiutils.ConnectorUtils.convertToQuotedString;
import static com.thanosfisherman.wifiutils.WifiUtils.wifiLog;

Expand All @@ -34,6 +37,7 @@ final class ConfigSecurities {
* @param password Password of the network if security is not OPEN.
*/

@RequiresPermission(allOf = {ACCESS_FINE_LOCATION, ACCESS_WIFI_STATE})
static void setupSecurity(@NonNull WifiConfiguration config, String security, @NonNull final String password) {
config.allowedAuthAlgorithms.clear();
config.allowedGroupCiphers.clear();
Expand Down Expand Up @@ -125,6 +129,7 @@ static void setupWifiNetworkSpecifierSecurities(@NonNull WifiNetworkSpecifier.Bu
}
}

@RequiresPermission(allOf = {ACCESS_FINE_LOCATION, ACCESS_WIFI_STATE})
@Nullable
static WifiConfiguration getWifiConfiguration(@NonNull final WifiManager wifiMgr, @NonNull final WifiConfiguration configToFind) {
final String ssid = configToFind.SSID;
Expand Down Expand Up @@ -153,6 +158,7 @@ static WifiConfiguration getWifiConfiguration(@NonNull final WifiManager wifiMgr
return null;
}

@RequiresPermission(allOf = {ACCESS_FINE_LOCATION, ACCESS_WIFI_STATE})
@Nullable
static WifiConfiguration getWifiConfiguration(@NonNull final WifiManager wifiMgr, @NonNull final ScanResult scanResult) {
if (scanResult.BSSID == null || scanResult.SSID == null || scanResult.SSID.isEmpty() || scanResult.BSSID.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.thanosfisherman.wifiutils;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
Expand All @@ -21,15 +22,19 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.RequiresPermission;

import com.thanosfisherman.elvis.Objects;
import com.thanosfisherman.wifiutils.wifiWps.ConnectionWpsListener;

import java.util.Collections;
import java.util.List;

import static android.Manifest.permission.ACCESS_FINE_LOCATION;
import static android.Manifest.permission.ACCESS_WIFI_STATE;
import static com.thanosfisherman.wifiutils.WifiUtils.wifiLog;

@SuppressLint("MissingPermission")
public final class ConnectorUtils {
private static final int MAX_PRIORITY = 99999;

Expand Down Expand Up @@ -169,6 +174,7 @@ static void unregisterReceiver(@NonNull Context context, @Nullable BroadcastRece
}
}

@RequiresPermission(allOf = {ACCESS_FINE_LOCATION, ACCESS_WIFI_STATE})
static boolean connectToWifi(@NonNull Context context, @Nullable WifiManager wifiManager, @NonNull ScanResult scanResult, @NonNull String password) {
if (wifiManager == null)
return false;
Expand All @@ -181,6 +187,7 @@ static boolean connectToWifi(@NonNull Context context, @Nullable WifiManager wif
return connectPreAndroidQ(context, wifiManager, scanResult, password);
}

@RequiresPermission(allOf = {ACCESS_FINE_LOCATION, ACCESS_WIFI_STATE})
private static boolean connectPreAndroidQ(@NonNull Context context, @Nullable WifiManager wifiManager, @NonNull ScanResult scanResult, @NonNull String password) {
WifiConfiguration config = ConfigSecurities.getWifiConfiguration(wifiManager, scanResult);
if (config != null && password.isEmpty()) {
Expand Down Expand Up @@ -222,6 +229,7 @@ private static boolean connectPreAndroidQ(@NonNull Context context, @Nullable Wi
return connectToConfiguredNetwork(wifiManager, config, true);
}

@RequiresPermission(allOf = {ACCESS_FINE_LOCATION, ACCESS_WIFI_STATE})
private static boolean connectToConfiguredNetwork(@Nullable WifiManager wifiManager, @Nullable WifiConfiguration config, boolean reassociate) {
if (config == null || wifiManager == null)
return false;
Expand Down Expand Up @@ -265,18 +273,18 @@ private static boolean connectAndroidQ(@Nullable ConnectivityManager connectivit
}

WifiNetworkSpecifier.Builder wifiNetworkSpecifierBuilder = new WifiNetworkSpecifier.Builder()
.setSsid(scanResult.SSID)
.setBssid(MacAddress.fromString(scanResult.BSSID));
.setSsid(scanResult.SSID)
.setBssid(MacAddress.fromString(scanResult.BSSID));

final String security = ConfigSecurities.getSecurity(scanResult);

ConfigSecurities.setupWifiNetworkSpecifierSecurities(wifiNetworkSpecifierBuilder, security , password);
ConfigSecurities.setupWifiNetworkSpecifierSecurities(wifiNetworkSpecifierBuilder, security, password);


NetworkRequest networkRequest = new NetworkRequest.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
.setNetworkSpecifier(wifiNetworkSpecifierBuilder.build())
.build();
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
.setNetworkSpecifier(wifiNetworkSpecifierBuilder.build())
.build();

connectivityManager.requestNetwork(networkRequest, new ConnectivityManager.NetworkCallback() {
@Override
Expand Down Expand Up @@ -357,6 +365,7 @@ public static boolean reEnableNetworkIfPossible(@Nullable final WifiManager wifi
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@RequiresPermission(allOf = {ACCESS_FINE_LOCATION, ACCESS_WIFI_STATE})
static void connectWps(@Nullable final WifiManager wifiManager, @NonNull final ScanResult scanResult, @NonNull String pin, long timeOutMillis,
@NonNull final ConnectionWpsListener connectionWpsListener) {
if (wifiManager == null) {
Expand Down Expand Up @@ -431,6 +440,7 @@ public void onFailed(int reason) {
wifiManager.startWps(wpsInfo, wpsCallback);
}

@RequiresPermission(allOf = {ACCESS_FINE_LOCATION, ACCESS_WIFI_STATE})
static boolean cleanPreviousConfiguration(@Nullable final WifiManager wifiManager, @NonNull final ScanResult scanResult) {
if (wifiManager == null)
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.thanosfisherman.wifiutils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.IntentFilter;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import android.util.Log;

import com.thanosfisherman.wifiutils.wifiConnect.ConnectionScanResultsListener;
import com.thanosfisherman.wifiutils.wifiConnect.ConnectionSuccessListener;
Expand Down Expand Up @@ -36,6 +38,7 @@
import static com.thanosfisherman.wifiutils.ConnectorUtils.registerReceiver;
import static com.thanosfisherman.wifiutils.ConnectorUtils.unregisterReceiver;

@SuppressLint("MissingPermission")
public final class WifiUtils implements WifiConnectorBuilder,
WifiConnectorBuilder.WifiUtilsBuilder,
WifiConnectorBuilder.WifiSuccessListener,
Expand Down

0 comments on commit 9bf85eb

Please sign in to comment.