-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Description: As a follow up for PR2568, the PR maps the network_disconnected and quic exception errors. The network_changed error has been removed as this is not relevant to envoymobile. Signed-off-by: Chidera Olibie <[email protected]> Signed-off-by: JP Simard <[email protected]>
- Loading branch information
Showing
13 changed files
with
336 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
mobile/library/java/io/envoyproxy/envoymobile/engine/UpstreamHttpProtocol.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.envoyproxy.envoymobile.engine; | ||
|
||
import androidx.annotation.LongDef; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
/** | ||
* The upstream protocol, if an upstream connection was established. Field | ||
* entries are based off of Envoy's Http::Protocol | ||
* https://github.com/envoyproxy/envoy/blob/main/envoy/http/protocol.h | ||
*/ | ||
@LongDef({UpstreamHttpProtocol.HTTP10, UpstreamHttpProtocol.HTTP11, UpstreamHttpProtocol.HTTP2, | ||
UpstreamHttpProtocol.HTTP3}) | ||
@Retention(RetentionPolicy.SOURCE) | ||
public @interface UpstreamHttpProtocol { | ||
long HTTP10 = 0; | ||
long HTTP11 = 1; | ||
long HTTP2 = 2; | ||
long HTTP3 = 3; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
mobile/test/java/io/envoyproxy/envoymobile/engine/AndroidNetworkMonitorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package io.envoyproxy.envoymobile.engine; | ||
|
||
import static org.robolectric.Shadows.shadowOf; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.Manifest; | ||
import android.net.ConnectivityManager; | ||
import android.net.NetworkInfo; | ||
import androidx.test.filters.MediumTest; | ||
import androidx.test.platform.app.InstrumentationRegistry; | ||
import androidx.test.rule.GrantPermissionRule; | ||
import androidx.test.annotation.UiThreadTest; | ||
import io.envoyproxy.envoymobile.MockEnvoyEngine; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.shadows.ShadowConnectivityManager; | ||
|
||
/** | ||
* Tests functionality of AndroidNetworkMonitor | ||
*/ | ||
@RunWith(RobolectricTestRunner.class) | ||
public class AndroidNetworkMonitorTest { | ||
|
||
@Rule | ||
public GrantPermissionRule mRuntimePermissionRule = | ||
GrantPermissionRule.grant(Manifest.permission.ACCESS_NETWORK_STATE); | ||
|
||
private AndroidNetworkMonitor androidNetworkMonitor; | ||
private ShadowConnectivityManager connectivityManager; | ||
private Context context; | ||
|
||
@Before | ||
public void setUp() { | ||
context = InstrumentationRegistry.getInstrumentation().getTargetContext(); | ||
AndroidNetworkMonitor.load(context, new MockEnvoyEngine()); | ||
androidNetworkMonitor = AndroidNetworkMonitor.getInstance(); | ||
connectivityManager = shadowOf(androidNetworkMonitor.getConnectivityManager()); | ||
} | ||
|
||
/** | ||
* Tests that isOnline() returns the correct result. | ||
*/ | ||
@Test | ||
@MediumTest | ||
@UiThreadTest | ||
public void testAndroidNetworkMonitorIsOnline() { | ||
Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION); | ||
// Set up network change | ||
androidNetworkMonitor.onReceive(context, intent); | ||
Assert.assertTrue(androidNetworkMonitor.isOnline()); | ||
|
||
// Save old networkInfo and simulate a no network scenerio | ||
NetworkInfo networkInfo = androidNetworkMonitor.getConnectivityManager().getActiveNetworkInfo(); | ||
connectivityManager.setActiveNetworkInfo(null); | ||
androidNetworkMonitor.onReceive(context, intent); | ||
Assert.assertFalse(androidNetworkMonitor.isOnline()); | ||
|
||
// Bring back online since the AndroidNetworkMonitor class is a singleton | ||
connectivityManager.setActiveNetworkInfo(networkInfo); | ||
androidNetworkMonitor.onReceive(context, intent); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.