diff options
author | Giorgos Mavrikas <gmavrikas@googlemail.com> | 2011-01-19 19:44:04 +0200 |
---|---|---|
committer | Giorgos Mavrikas <gmavrikas@googlemail.com> | 2011-01-19 19:44:04 +0200 |
commit | 34722b1f699c55998231b1c965d193c33196bc2d (patch) | |
tree | 4fb6acdcdc88bbf131caf763ad68721d4e512392 /voip | |
parent | 81d4483f528686b70f56eac77fba713b93e60575 (diff) | |
download | frameworks_base-34722b1f699c55998231b1c965d193c33196bc2d.zip frameworks_base-34722b1f699c55998231b1c965d193c33196bc2d.tar.gz frameworks_base-34722b1f699c55998231b1c965d193c33196bc2d.tar.bz2 |
Force SIP service to find the new local IP and reregister all SIP accounts on VPN on/off
Change-Id: I6f973d7f755838ccea20edafd98f9658fa1f8466
Diffstat (limited to 'voip')
-rw-r--r-- | voip/java/com/android/server/sip/SipService.java | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/voip/java/com/android/server/sip/SipService.java b/voip/java/com/android/server/sip/SipService.java index f480fec..720227d 100644 --- a/voip/java/com/android/server/sip/SipService.java +++ b/voip/java/com/android/server/sip/SipService.java @@ -32,6 +32,8 @@ import android.net.sip.SipManager; import android.net.sip.SipProfile; import android.net.sip.SipSession; import android.net.sip.SipSessionAdapter; +import android.net.vpn.VpnManager; +import android.net.vpn.VpnState; import android.net.wifi.WifiManager; import android.os.Binder; import android.os.Bundle; @@ -94,6 +96,7 @@ public final class SipService extends ISipService.Stub { new HashMap<String, ISipSession>(); private ConnectivityReceiver mConnectivityReceiver; + private VpnConnectivityReceiver mVpnConnectivityReceiver; private boolean mWifiEnabled; private SipWakeLock mMyWakeLock; @@ -113,8 +116,11 @@ public final class SipService extends ISipService.Stub { if (DEBUG) Log.d(TAG, " service started!"); mContext = context; mConnectivityReceiver = new ConnectivityReceiver(); + mVpnConnectivityReceiver = new VpnConnectivityReceiver(); context.registerReceiver(mConnectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); + context.registerReceiver(mVpnConnectivityReceiver, + new IntentFilter(VpnManager.ACTION_VPN_CONNECTIVITY)); context.registerReceiver(mWifiStateReceiver, new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION)); mMyWakeLock = new SipWakeLock((PowerManager) @@ -1108,6 +1114,55 @@ public final class SipService extends ISipService.Stub { } } + private class VpnConnectivityReceiver extends BroadcastReceiver { + @Override + public void onReceive(final Context context, final Intent intent) { + // Run the handler in MyExecutor to be protected by wake lock + getExecutor().execute(new Runnable() { + public void run() { + onReceiveInternal(context, intent); + } + }); + } + + private void onReceiveInternal(Context context, Intent intent) { + String action = intent.getAction(); + VpnState state = (VpnState)intent.getExtra(VpnManager.BROADCAST_CONNECTION_STATE); + if (action.equals(VpnManager.ACTION_VPN_CONNECTIVITY)) { + if (DEBUG) Log.d(TAG, "VpnListener got a CONNECTIVITY_ACTION"); + switch (state) { + case IDLE: + case CONNECTED: + if (DEBUG) Log.d(TAG, "VpnListener:: CONNECTED"); + onChanged("vpn", true); + break; + case CONNECTING: + case DISCONNECTING: + case CANCELLED: + case UNUSABLE: + case UNKNOWN: + default: + break; + } + } else { + if (DEBUG) Log.d(TAG, "VpnListener got a non CONNECTIVITY_ACTION intent " + action.toString()); + } + } + + private NetworkInfo getActiveNetworkInfo() { + ConnectivityManager cm = (ConnectivityManager) + mContext.getSystemService(Context.CONNECTIVITY_SERVICE); + return cm.getActiveNetworkInfo(); + } + + private void onChanged(String type, boolean connected) { + synchronized (SipService.this) { + mMyWakeLock.acquire(this); + onConnectivityChanged(type, connected); + mMyWakeLock.release(this); + } + } + } /** * Timer that can schedule events to occur even when the device is in sleep. * Only used internally in this package. |