@@ -82,7 +82,7 @@ impl ConnectivityListener {
82
82
} ;
83
83
84
84
Ok ( ConnectivityListener {
85
- jvm : android_context. clone ( ) . jvm ,
85
+ jvm : android_context. jvm ,
86
86
android_listener,
87
87
} )
88
88
}
@@ -98,18 +98,16 @@ impl ConnectivityListener {
98
98
99
99
/// Return the current offline/connectivity state
100
100
pub fn connectivity ( & self ) -> Connectivity {
101
- self . get_is_connected ( )
102
- . map ( |( ipv4, ipv6) | Connectivity :: Status { ipv4, ipv6 } )
103
- . unwrap_or_else ( |error| {
104
- log:: error!(
105
- "{}" ,
106
- error. display_chain_with_msg( "Failed to check connectivity status" )
107
- ) ;
108
- Connectivity :: PresumeOnline
109
- } )
101
+ self . get_is_connected ( ) . unwrap_or_else ( |error| {
102
+ log:: error!(
103
+ "{}" ,
104
+ error. display_chain_with_msg( "Failed to check connectivity status" )
105
+ ) ;
106
+ Connectivity :: PresumeOnline
107
+ } )
110
108
}
111
109
112
- fn get_is_connected ( & self ) -> Result < ( bool , bool ) , Error > {
110
+ fn get_is_connected ( & self ) -> Result < Connectivity , Error > {
113
111
let env = JnixEnv :: from (
114
112
self . jvm
115
113
. attach_current_thread_as_daemon ( )
@@ -120,26 +118,14 @@ impl ConnectivityListener {
120
118
. call_method (
121
119
self . android_listener . as_obj ( ) ,
122
120
"isConnected" ,
123
- "()Lnet/mullvad/talpid/model/ConnectionStatus ;" ,
121
+ "()Lnet/mullvad/talpid/model/Connectivity ;" ,
124
122
& [ ] ,
125
123
)
126
124
. expect ( "Missing isConnected" )
127
125
. l ( )
128
126
. expect ( "isConnected is not an object" ) ;
129
127
130
- let ipv4 = env
131
- . call_method ( is_connected, "component1" , "()Z" , & [ ] )
132
- . expect ( "Missing ConnectionStatus.ipv4" )
133
- . z ( )
134
- . expect ( "ipv4 is not a boolean" ) ;
135
-
136
- let ipv6 = env
137
- . call_method ( is_connected, "component2" , "()Z" , & [ ] )
138
- . expect ( "Missing ConnectionStatus.ipv6" )
139
- . z ( )
140
- . expect ( "ipv6 is not a boolean" ) ;
141
-
142
- Ok ( ( ipv4, ipv6) )
128
+ Ok ( Connectivity :: from_java ( & env, is_connected) )
143
129
}
144
130
145
131
/// Return the current DNS servers according to Android
@@ -183,13 +169,13 @@ pub extern "system" fn Java_net_mullvad_talpid_ConnectivityListener_notifyConnec
183
169
return ;
184
170
} ;
185
171
186
- let isIPv4 = JNI_TRUE == is_ipv4;
187
- let isIPv6 = JNI_TRUE == is_ipv6;
172
+ let is_ipv4 = JNI_TRUE == is_ipv4;
173
+ let is_ipv6 = JNI_TRUE == is_ipv6;
188
174
189
175
if tx
190
176
. unbounded_send ( Connectivity :: Status {
191
- ipv4 : isIPv4 ,
192
- ipv6 : isIPv6 ,
177
+ ipv4 : is_ipv4 ,
178
+ ipv6 : is_ipv6 ,
193
179
} )
194
180
. is_err ( )
195
181
{
0 commit comments