mirror of
https://github.com/M66B/NetGuard.git
synced 2024-12-25 01:07:52 +00:00
Listen to service state changes (roaming)
This commit is contained in:
parent
3946a9ba95
commit
372bb6fc11
1 changed files with 23 additions and 0 deletions
|
@ -13,6 +13,9 @@ import android.net.VpnService;
|
|||
import android.os.ParcelFileDescriptor;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.telephony.PhoneStateListener;
|
||||
import android.telephony.ServiceState;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -97,6 +100,10 @@ public class SinkholeService extends VpnService {
|
|||
boolean interactive = Util.isInteractive(this);
|
||||
Log.i(TAG, "interactive=" + interactive);
|
||||
|
||||
// Check roaming
|
||||
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
||||
Log.i(TAG, "roaming=" + tm.isNetworkRoaming());
|
||||
|
||||
// Build VPN service
|
||||
final Builder builder = new Builder();
|
||||
builder.setSession(getString(R.string.app_name));
|
||||
|
@ -243,6 +250,14 @@ public class SinkholeService extends VpnService {
|
|||
}
|
||||
};
|
||||
|
||||
private PhoneStateListener phoneStateListener = new PhoneStateListener() {
|
||||
@Override
|
||||
public void onServiceStateChanged(ServiceState serviceState) {
|
||||
super.onServiceStateChanged(serviceState);
|
||||
Log.i(TAG, "Service state changed roaming=" + serviceState.getRoaming());
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
@ -264,6 +279,10 @@ public class SinkholeService extends VpnService {
|
|||
ifInteractive.addAction(Intent.ACTION_SCREEN_ON);
|
||||
ifInteractive.addAction(Intent.ACTION_SCREEN_OFF);
|
||||
registerReceiver(interactiveStateReceiver, ifInteractive);
|
||||
|
||||
// Listen for service state changes
|
||||
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
||||
tm.listen(phoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -280,6 +299,10 @@ public class SinkholeService extends VpnService {
|
|||
unregisterReceiver(connectivityChangedReceiver);
|
||||
unregisterReceiver(interactiveStateReceiver);
|
||||
|
||||
// Listen for service state changes
|
||||
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
||||
tm.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue