From a4c263f7cc5e6a0b7788111b2cd69d037037181b Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Tue, 24 Jul 2018 22:07:06 +0200 Subject: [PATCH] WIP - Extend run condition monitor functions --- .../service/RunConditionMonitor.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/RunConditionMonitor.java b/app/src/main/java/com/nutomic/syncthingandroid/service/RunConditionMonitor.java index 883b8b6e..18fe8521 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/RunConditionMonitor.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/RunConditionMonitor.java @@ -227,6 +227,48 @@ public class RunConditionMonitor implements SharedPreferences.OnSharedPreference return powerManager.isPowerSaveMode(); } + private boolean isFlightMode() { + ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo ni = cm.getActiveNetworkInfo(); + return ni == null; + } + + private boolean isMeteredNetworkConnection() { + ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo ni = cm.getActiveNetworkInfo(); + if (ni == null) { + // In flight mode. + return false; + } + if (!ni.isConnected()) { + // No network connection. + return false; + } + return cm.isActiveNetworkMetered(); + } + + private boolean isMobileDataConnection() { + ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo ni = cm.getActiveNetworkInfo(); + if (ni == null) { + // In flight mode. + return false; + } + if (!ni.isConnected()) { + // No network connection. + return false; + } + switch (ni.getType()) { + case ConnectivityManager.TYPE_BLUETOOTH: + case ConnectivityManager.TYPE_MOBILE: + case ConnectivityManager.TYPE_MOBILE_DUN: + case ConnectivityManager.TYPE_MOBILE_HIPRI: + return true; + default: + return false; + } + } + private boolean isWifiOrEthernetConnection() { ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo();