File tree Expand file tree Collapse file tree
lib/utilcode/src/main/java/com/blankj/utilcode/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -261,6 +261,34 @@ public static boolean getMobileDataEnabled() {
261261 }
262262 return false ;
263263 }
264+
265+ /**
266+ * Returns true if device is connecting to the internet via a proxy, works for both Wi-Fi and Mobile Data.
267+ *
268+ * @return true if using proxy to connect to the internet.
269+ */
270+ public static boolean isBehindProxy (){
271+ return !(System .getProperty ("http.proxyHost" ) == null || System .getProperty ("http.proxyPort" ) == null );
272+ }
273+
274+ /**
275+ * Returns true if device is connecting to the internet via a VPN.
276+ *
277+ * @return true if using VPN to conncet to the internet.
278+ */
279+ public static boolean isUsingVPN (){
280+ ConnectivityManager cm = (ConnectivityManager ) com .blankj .utilcode .util .Utils .getApp ().getSystemService (Context .CONNECTIVITY_SERVICE );
281+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
282+ return cm .getNetworkInfo (ConnectivityManager .TYPE_VPN ).isConnectedOrConnecting ()
283+ } else {
284+ return cm .getNetworkInfo (NetworkCapabilities .TRANSPORT_VPN ).isConnectedOrConnecting ()
285+ }
286+ }
287+
288+
289+
290+
291+
264292
265293 /**
266294 * Return whether using mobile data.
You can’t perform that action at this time.
0 commit comments