Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fix for issue 111 try 2 #114

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ apply plugin: "androidx.navigation.safeargs.kotlin"


android {
compileSdkVersion 30
compileSdkVersion 33

defaultConfig {
applicationId 'io.particle.android.app'
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 33
// scheme for these version numbers: EPOCH MAJOR MINOR PATCH BUILD
versionCode 1_03_01_02_01
versionName "3.1.2"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<activity
android:name="io.particle.android.sdk.ui.SplashActivity"
android:screenOrientation="portrait"
android:exported="true"
android:theme="@style/ParticleSetupTheme.NoActionBar.TranslucentSystemBars.Honeycomb"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
Expand All @@ -42,13 +43,15 @@
<activity
android:name="io.particle.android.sdk.ui.IntroActivity"
android:label="@string/title_activity_intro"
android:exported="true"
android:screenOrientation="portrait"
android:theme="@style/ParticleSetupTheme.NoActionBar.TranslucentSystemBars.Honeycomb" />

<activity
android:name="io.particle.android.sdk.ui.devicelist.DeviceListActivity"
android:label="@string/title_device_list"
android:screenOrientation="portrait"
android:exported="true"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
Expand All @@ -67,6 +70,7 @@
android:label="@string/title_inspector_detail"
android:parentActivityName="io.particle.android.sdk.ui.devicelist.DeviceListActivity"
android:screenOrientation="portrait"
android:exported="true"
android:theme="@style/TinkerSetup">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
Expand Down
4 changes: 2 additions & 2 deletions cloudsdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ ext {


android {
compileSdkVersion 30
compileSdkVersion 33

defaultConfig {
minSdkVersion 15
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName project.version

Expand Down
4 changes: 2 additions & 2 deletions commonui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 30
compileSdkVersion 33

defaultConfig {
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"

Expand Down
4 changes: 2 additions & 2 deletions devicesetup/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ ext {


android {
compileSdkVersion 30
compileSdkVersion 33

defaultConfig {
minSdkVersion 15
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.content.IntentFilter
import android.net.wifi.WifiConfiguration
import android.net.wifi.WifiInfo
import android.net.wifi.WifiManager
import android.os.Build.VERSION
import android.os.Handler
import android.os.Looper
import androidx.annotation.MainThread
Expand Down Expand Up @@ -53,7 +52,6 @@ class ApConnectorApi21(
wifiStateChangeListener = SimpleReceiver.newRegisteredReceiver(
appContext, WIFI_STATE_CHANGE_FILTER
) { ctx: Context?, intent: Intent -> onWifiChangeBroadcastReceived(intent, config) }
val useMoreComplexConnectionProcess = VERSION.SDK_INT < 18


// we don't need this for its atomicity, we just need it as a 'final' reference to an
Expand All @@ -64,7 +62,7 @@ class ApConnectorApi21(
// wonkiness I ran into when trying to do every one of these steps one right after
// the other on the same thread.
val alreadyConfiguredId = wifiFacade.getIdForConfiguredNetwork(configSSID)
if (alreadyConfiguredId != -1 && !useMoreComplexConnectionProcess) {
if (alreadyConfiguredId != -1) {
// For some unexplained (and probably sad-trombone-y) reason, if the AP specified was
// already configured and had been connected to in the past, it will often get to
// the "CONNECTING" event, but just before firing the "CONNECTED" event, the
Expand All @@ -82,7 +80,7 @@ class ApConnectorApi21(
}
}
}
if (alreadyConfiguredId == -1 || !useMoreComplexConnectionProcess) {
if (alreadyConfiguredId == -1 ) {
setupRunnables.add {
log.d("Adding network $configSSID")
networkID.set(wifiFacade.addNetwork(config))
Expand All @@ -100,21 +98,9 @@ class ApConnectorApi21(
}
}
}
if (useMoreComplexConnectionProcess) {
setupRunnables.add {
log.d("Disconnecting from networks; reconnecting momentarily.")
wifiFacade.disconnect()
}
}
setupRunnables.add {
log.i("Enabling network " + configSSID + " with network ID " + networkID.get())
wifiFacade.enableNetwork(networkID.get(), !useMoreComplexConnectionProcess)
}
if (useMoreComplexConnectionProcess) {
setupRunnables.add {
log.d("Disconnecting from networks; reconnecting momentarily.")
wifiFacade.reconnect()
}
wifiFacade.enableNetwork(networkID.get(), true)
}
val currentlyConnectedSSID = wifiFacade.currentlyConnectedSSID
softAPConfigRemover.onWifiNetworkDisabled(currentlyConnectedSSID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class ApConnectorApi29(
): ConnectivityManager.NetworkCallback {
return object : ConnectivityManager.NetworkCallback() {

@RequiresApi(VERSION_CODES.M)
override fun onAvailable(network: Network) {
log.info { "onAvailable: $network" }
decoratingClient.onApConnectionSuccessful(config)
Expand Down Expand Up @@ -108,6 +109,7 @@ class ApConnectorApi29(
}
}

@RequiresApi(VERSION_CODES.M)
private fun clearState() {
try {
DeviceSetupState.networkCallbacks = networkCallbacks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ public Network getNetworkObjectForCurrentWifiConnection() {
// Instead, you have to infer it based on the fact that you can only
// have one connected Wi-Fi connection at a time.
// (Update: one *regular* Wi-Fi connection, anyway. See below.)
Network[] networks = connectivityManager.getAllNetworks();

return Funcy.findFirstMatch(
Arrays.asList(connectivityManager.getAllNetworks()),
Network selectedNetwork = Funcy.findFirstMatch(
Arrays.asList(networks),
network -> {
NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(network);
if (capabilities == null) {
Expand All @@ -133,9 +134,36 @@ public Network getNetworkObjectForCurrentWifiConnection() {
if (capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_WIFI_P2P)) {
return false;
}
// Don't use any connections if they have internet!
// Note: Due to a known issue with certain Android phones (e.g., Pixel 6/7 series) running Android 12 or above,
// these devices may retain access to their current Wi-Fi network while also connecting to a Particle Wi-Fi Module
// in SoftAP mode. This behavior is due to a feature introduced in Android 12 known as Wi-Fi STA/STA concurrency,
// which allows devices to connect to two Wi-Fi networks concurrently.
//
// The correct way to handle this programmatically using Android's ConnectivityManager APIs (SDK 31+) has proven
// to be unreliable due to the bugs tracked at:
// https://issuetracker.google.com/issues/249023377
// https://issuetracker.google.com/issues/232107693
//
// Exhaustive testing was done after implementing this the correct way and it just didn't work.
// Before giving up, the Android source code was examined to see how the system itself handles this situation.
// In that code, we found a similar hack to the one below, which is used to determine whether a network is
// a "valid" internet connection. If it is, then the system will not bind to it.
//
// The current workaround involves excluding all networks with internet capability when binding to a network.
// While this is not a perfect fix (as future changes in Android might affect its effectiveness), this solution
// has proven to be reliable for the time being and manages to address the issue across all Pixel phones tested,
// ranging from the latest models back to those running Android 5.
//
// For more information, refer to the aforementioned issue trackers.
if (capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) {
return false;
}
return capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI);
}
);

return selectedNetwork;
}

public int addNetwork(WifiConfiguration config) {
Expand Down
4 changes: 2 additions & 2 deletions ecjpake4j/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ apply plugin: 'kotlin-android'


android {
compileSdkVersion 30
compileSdkVersion 33

defaultConfig {
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"

Expand Down
4 changes: 2 additions & 2 deletions firmwareprotos/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 30
compileSdkVersion 33



defaultConfig {
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"
}
Expand Down
4 changes: 2 additions & 2 deletions mesh/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ apply plugin: "androidx.navigation.safeargs.kotlin"


android {
compileSdkVersion 30
compileSdkVersion 33

defaultConfig {
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"

Expand Down
4 changes: 2 additions & 2 deletions meshui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ apply plugin: "androidx.navigation.safeargs.kotlin"


android {
compileSdkVersion 30
compileSdkVersion 33

defaultConfig {
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"

Expand Down
4 changes: 2 additions & 2 deletions sdk_example_app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 30
compileSdkVersion 33

defaultConfig {
applicationId "io.particle.cloudsdk.example_app"
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"
}
Expand Down
6 changes: 5 additions & 1 deletion sdk_example_app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
android:theme="@style/AppTheme">
<activity
android:name="io.particle.cloudsdk.example_app.SplashActivity"
android:exported="true"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
Expand All @@ -18,16 +19,19 @@
</activity>
<activity
android:name="io.particle.cloudsdk.example_app.LoginActivity"
android:exported="true"
android:label="@string/title_activity_login">
</activity>
<activity
android:name="io.particle.cloudsdk.example_app.ValueActivity"
android:exported="true"
android:label="@string/title_activity_value">
</activity>
<activity
android:name="io.particle.cloudsdk.example_app.DeviceInfoActivity"
android:exported="true"
android:label="@string/title_activity_device_info">
</activity>
</application>

</manifest>
</manifest>
4 changes: 2 additions & 2 deletions setup_exampleapp/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 30
compileSdkVersion 33

defaultConfig {
applicationId "io.particle.devicesetup.exampleapp"
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"

Expand Down
2 changes: 2 additions & 0 deletions setup_exampleapp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:exported="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
4 changes: 2 additions & 2 deletions setup_testapp/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 30
compileSdkVersion 33

defaultConfig {
applicationId "io.particle.devicesetup.testapp"
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"

Expand Down
1 change: 1 addition & 0 deletions setup_testapp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:exported="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
Expand Down
4 changes: 2 additions & 2 deletions setup_testapp/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
Expand All @@ -16,4 +16,4 @@
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>