mirror of https://github.com/M66B/NetGuard.git
parent
c03d838be6
commit
74e8ce8fc2
|
@ -163,7 +163,7 @@ public class SinkholeService extends VpnService {
|
|||
|
||||
// Listen for phone state changes
|
||||
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
||||
if (!phone_state &&
|
||||
if (tm != null && !phone_state &&
|
||||
Util.hasPhoneStatePermission(SinkholeService.this)) {
|
||||
tm.listen(phoneStateListener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE | PhoneStateListener.LISTEN_SERVICE_STATE);
|
||||
phone_state = true;
|
||||
|
@ -830,8 +830,10 @@ public class SinkholeService extends VpnService {
|
|||
|
||||
if (phone_state) {
|
||||
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
||||
tm.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
|
||||
phone_state = false;
|
||||
if (tm != null) {
|
||||
tm.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
|
||||
phone_state = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (subscriptionsChangedListener != null &&
|
||||
|
|
|
@ -84,7 +84,11 @@ public class Util {
|
|||
|
||||
public static boolean hasTelephony(Context context) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
|
||||
if (pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY))
|
||||
return true;
|
||||
// Workaround
|
||||
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
return (tm != null && tm.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
||||
}
|
||||
|
||||
public static boolean hasWifi(Context context) {
|
||||
|
@ -94,30 +98,30 @@ public class Util {
|
|||
|
||||
public static boolean isConnected(Context context) {
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo ni = cm.getActiveNetworkInfo();
|
||||
NetworkInfo ni = (cm == null ? null : cm.getActiveNetworkInfo());
|
||||
return (ni != null && ni.isConnected());
|
||||
}
|
||||
|
||||
public static boolean isWifiActive(Context context) {
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo ni = cm.getActiveNetworkInfo();
|
||||
NetworkInfo ni = (cm == null ? null : cm.getActiveNetworkInfo());
|
||||
return (ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI);
|
||||
}
|
||||
|
||||
public static boolean isMeteredNetwork(Context context) {
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
return cm.isActiveNetworkMetered();
|
||||
return (cm != null && cm.isActiveNetworkMetered());
|
||||
}
|
||||
|
||||
public static String getWifiSSID(Context context) {
|
||||
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
String ssid = wm.getConnectionInfo().getSSID();
|
||||
String ssid = (wm == null ? null : wm.getConnectionInfo().getSSID());
|
||||
return (ssid == null ? "NULL" : ssid);
|
||||
}
|
||||
|
||||
public static int getNetworkType(Context context) {
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo ni = cm.getActiveNetworkInfo();
|
||||
NetworkInfo ni = (cm == null ? null : cm.getActiveNetworkInfo());
|
||||
return (ni == null ? TelephonyManager.NETWORK_TYPE_UNKNOWN : ni.getSubtype());
|
||||
}
|
||||
|
||||
|
@ -129,7 +133,7 @@ public class Util {
|
|||
|
||||
public static boolean isRoaming(Context context) {
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo ni = cm.getActiveNetworkInfo();
|
||||
NetworkInfo ni = (cm == null ? null : cm.getActiveNetworkInfo());
|
||||
return (ni != null && ni.isRoaming());
|
||||
}
|
||||
|
||||
|
@ -161,7 +165,7 @@ public class Util {
|
|||
}
|
||||
}
|
||||
|
||||
return (tm.getSimCountryIso() == null ? true : !tm.getSimCountryIso().equals(tm.getNetworkCountryIso()));
|
||||
return (tm == null || tm.getSimCountryIso() == null ? true : !tm.getSimCountryIso().equals(tm.getNetworkCountryIso()));
|
||||
}
|
||||
|
||||
public static String getNetworkGeneration(int networkType) {
|
||||
|
@ -265,7 +269,7 @@ public class Util {
|
|||
|
||||
public static boolean isInteractive(Context context) {
|
||||
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
return pm.isInteractive();
|
||||
return (pm != null && pm.isInteractive());
|
||||
}
|
||||
|
||||
public static boolean isPackageInstalled(String packageName, Context context) {
|
||||
|
|
Loading…
Reference in New Issue