Loading android/app/src/com/android/bluetooth/pan/BluetoothTetheringNetworkFactory.java +64 −19 Original line number Original line Diff line number Diff line Loading @@ -25,12 +25,17 @@ import android.net.NetworkCapabilities; import android.net.NetworkFactory; import android.net.NetworkFactory; import android.net.NetworkInfo; import android.net.NetworkInfo; import android.net.NetworkInfo.DetailedState; import android.net.NetworkInfo.DetailedState; import android.net.ip.IpClient; import android.net.ip.IIpClient; import android.net.ip.IpClient.WaitForProvisioningCallback; import android.net.ip.IpClientUtil; import android.net.ip.IpClientUtil.WaitForProvisioningCallbacks; import android.net.shared.ProvisioningConfiguration; import android.os.Looper; import android.os.Looper; import android.os.RemoteException; import android.text.TextUtils; import android.text.TextUtils; import android.util.Slog; import android.util.Slog; import com.android.internal.annotations.GuardedBy; /** /** * This class tracks the data connection associated with Bluetooth * This class tracks the data connection associated with Bluetooth * reverse tethering. PanService calls it when a reverse tethered * reverse tethering. PanService calls it when a reverse tethered Loading @@ -49,7 +54,9 @@ public class BluetoothTetheringNetworkFactory extends NetworkFactory { // All accesses to these must be synchronized(this). // All accesses to these must be synchronized(this). private final NetworkInfo mNetworkInfo; private final NetworkInfo mNetworkInfo; private IpClient mIpClient; private IIpClient mIpClient; @GuardedBy("this") private int mIpClientStartIndex = 0; private String mInterfaceName; private String mInterfaceName; private NetworkAgent mNetworkAgent; private NetworkAgent mNetworkAgent; Loading @@ -65,13 +72,64 @@ public class BluetoothTetheringNetworkFactory extends NetworkFactory { setCapabilityFilter(mNetworkCapabilities); setCapabilityFilter(mNetworkCapabilities); } } private class BtIpClientCallback extends WaitForProvisioningCallbacks { private final int mCurrentStartIndex; private BtIpClientCallback(int currentStartIndex) { mCurrentStartIndex = currentStartIndex; } @Override public void onIpClientCreated(IIpClient ipClient) { synchronized (BluetoothTetheringNetworkFactory.this) { if (mCurrentStartIndex != mIpClientStartIndex) { // Do not start IpClient: the current request is obsolete. // IpClient will be GCed eventually as the IIpClient Binder token goes out // of scope. return; } mIpClient = ipClient; try { mIpClient.startProvisioning(new ProvisioningConfiguration.Builder() .withoutMultinetworkPolicyTracker() .withoutIpReachabilityMonitor() .build().toStableParcelable()); } catch (RemoteException e) { Slog.e(TAG, "Error starting IpClient provisioning", e); } } } @Override public void onLinkPropertiesChange(LinkProperties newLp) { synchronized (BluetoothTetheringNetworkFactory.this) { if (mNetworkAgent != null && mNetworkInfo.isConnected()) { mNetworkAgent.sendLinkProperties(newLp); } } } } private void stopIpClientLocked() { private void stopIpClientLocked() { // Mark all previous start requests as obsolete mIpClientStartIndex++; if (mIpClient != null) { if (mIpClient != null) { try { mIpClient.shutdown(); mIpClient.shutdown(); } catch (RemoteException e) { Slog.e(TAG, "Error shutting down IpClient", e); } mIpClient = null; mIpClient = null; } } } } private BtIpClientCallback startIpClientLocked() { mIpClientStartIndex++; final BtIpClientCallback callback = new BtIpClientCallback(mIpClientStartIndex); IpClientUtil.makeIpClient(mContext, mInterfaceName, callback); return callback; } // Called by NetworkFactory when PanService and NetworkFactory both desire a Bluetooth // Called by NetworkFactory when PanService and NetworkFactory both desire a Bluetooth // reverse-tether connection. A network interface for Bluetooth reverse-tethering can be // reverse-tether connection. A network interface for Bluetooth reverse-tethering can be // assumed to be available because we only register our NetworkFactory when it is so. // assumed to be available because we only register our NetworkFactory when it is so. Loading @@ -84,16 +142,7 @@ public class BluetoothTetheringNetworkFactory extends NetworkFactory { @Override @Override public void run() { public void run() { LinkProperties linkProperties; LinkProperties linkProperties; final WaitForProvisioningCallback ipcCallback = new WaitForProvisioningCallback() { final WaitForProvisioningCallbacks ipcCallback; @Override public void onLinkPropertiesChange(LinkProperties newLp) { synchronized (BluetoothTetheringNetworkFactory.this) { if (mNetworkAgent != null && mNetworkInfo.isConnected()) { mNetworkAgent.sendLinkProperties(newLp); } } } }; synchronized (BluetoothTetheringNetworkFactory.this) { synchronized (BluetoothTetheringNetworkFactory.this) { if (TextUtils.isEmpty(mInterfaceName)) { if (TextUtils.isEmpty(mInterfaceName)) { Loading @@ -102,11 +151,7 @@ public class BluetoothTetheringNetworkFactory extends NetworkFactory { } } log("ipProvisioningThread(+" + mInterfaceName + "): " + "mNetworkInfo=" log("ipProvisioningThread(+" + mInterfaceName + "): " + "mNetworkInfo=" + mNetworkInfo); + mNetworkInfo); mIpClient = new IpClient(mContext, mInterfaceName, ipcCallback); ipcCallback = startIpClientLocked(); mIpClient.startProvisioning(mIpClient.buildProvisioningConfiguration() .withoutMultinetworkPolicyTracker() .withoutIpReachabilityMonitor() .build()); mNetworkInfo.setDetailedState(DetailedState.OBTAINING_IPADDR, null, null); mNetworkInfo.setDetailedState(DetailedState.OBTAINING_IPADDR, null, null); } } Loading Loading
android/app/src/com/android/bluetooth/pan/BluetoothTetheringNetworkFactory.java +64 −19 Original line number Original line Diff line number Diff line Loading @@ -25,12 +25,17 @@ import android.net.NetworkCapabilities; import android.net.NetworkFactory; import android.net.NetworkFactory; import android.net.NetworkInfo; import android.net.NetworkInfo; import android.net.NetworkInfo.DetailedState; import android.net.NetworkInfo.DetailedState; import android.net.ip.IpClient; import android.net.ip.IIpClient; import android.net.ip.IpClient.WaitForProvisioningCallback; import android.net.ip.IpClientUtil; import android.net.ip.IpClientUtil.WaitForProvisioningCallbacks; import android.net.shared.ProvisioningConfiguration; import android.os.Looper; import android.os.Looper; import android.os.RemoteException; import android.text.TextUtils; import android.text.TextUtils; import android.util.Slog; import android.util.Slog; import com.android.internal.annotations.GuardedBy; /** /** * This class tracks the data connection associated with Bluetooth * This class tracks the data connection associated with Bluetooth * reverse tethering. PanService calls it when a reverse tethered * reverse tethering. PanService calls it when a reverse tethered Loading @@ -49,7 +54,9 @@ public class BluetoothTetheringNetworkFactory extends NetworkFactory { // All accesses to these must be synchronized(this). // All accesses to these must be synchronized(this). private final NetworkInfo mNetworkInfo; private final NetworkInfo mNetworkInfo; private IpClient mIpClient; private IIpClient mIpClient; @GuardedBy("this") private int mIpClientStartIndex = 0; private String mInterfaceName; private String mInterfaceName; private NetworkAgent mNetworkAgent; private NetworkAgent mNetworkAgent; Loading @@ -65,13 +72,64 @@ public class BluetoothTetheringNetworkFactory extends NetworkFactory { setCapabilityFilter(mNetworkCapabilities); setCapabilityFilter(mNetworkCapabilities); } } private class BtIpClientCallback extends WaitForProvisioningCallbacks { private final int mCurrentStartIndex; private BtIpClientCallback(int currentStartIndex) { mCurrentStartIndex = currentStartIndex; } @Override public void onIpClientCreated(IIpClient ipClient) { synchronized (BluetoothTetheringNetworkFactory.this) { if (mCurrentStartIndex != mIpClientStartIndex) { // Do not start IpClient: the current request is obsolete. // IpClient will be GCed eventually as the IIpClient Binder token goes out // of scope. return; } mIpClient = ipClient; try { mIpClient.startProvisioning(new ProvisioningConfiguration.Builder() .withoutMultinetworkPolicyTracker() .withoutIpReachabilityMonitor() .build().toStableParcelable()); } catch (RemoteException e) { Slog.e(TAG, "Error starting IpClient provisioning", e); } } } @Override public void onLinkPropertiesChange(LinkProperties newLp) { synchronized (BluetoothTetheringNetworkFactory.this) { if (mNetworkAgent != null && mNetworkInfo.isConnected()) { mNetworkAgent.sendLinkProperties(newLp); } } } } private void stopIpClientLocked() { private void stopIpClientLocked() { // Mark all previous start requests as obsolete mIpClientStartIndex++; if (mIpClient != null) { if (mIpClient != null) { try { mIpClient.shutdown(); mIpClient.shutdown(); } catch (RemoteException e) { Slog.e(TAG, "Error shutting down IpClient", e); } mIpClient = null; mIpClient = null; } } } } private BtIpClientCallback startIpClientLocked() { mIpClientStartIndex++; final BtIpClientCallback callback = new BtIpClientCallback(mIpClientStartIndex); IpClientUtil.makeIpClient(mContext, mInterfaceName, callback); return callback; } // Called by NetworkFactory when PanService and NetworkFactory both desire a Bluetooth // Called by NetworkFactory when PanService and NetworkFactory both desire a Bluetooth // reverse-tether connection. A network interface for Bluetooth reverse-tethering can be // reverse-tether connection. A network interface for Bluetooth reverse-tethering can be // assumed to be available because we only register our NetworkFactory when it is so. // assumed to be available because we only register our NetworkFactory when it is so. Loading @@ -84,16 +142,7 @@ public class BluetoothTetheringNetworkFactory extends NetworkFactory { @Override @Override public void run() { public void run() { LinkProperties linkProperties; LinkProperties linkProperties; final WaitForProvisioningCallback ipcCallback = new WaitForProvisioningCallback() { final WaitForProvisioningCallbacks ipcCallback; @Override public void onLinkPropertiesChange(LinkProperties newLp) { synchronized (BluetoothTetheringNetworkFactory.this) { if (mNetworkAgent != null && mNetworkInfo.isConnected()) { mNetworkAgent.sendLinkProperties(newLp); } } } }; synchronized (BluetoothTetheringNetworkFactory.this) { synchronized (BluetoothTetheringNetworkFactory.this) { if (TextUtils.isEmpty(mInterfaceName)) { if (TextUtils.isEmpty(mInterfaceName)) { Loading @@ -102,11 +151,7 @@ public class BluetoothTetheringNetworkFactory extends NetworkFactory { } } log("ipProvisioningThread(+" + mInterfaceName + "): " + "mNetworkInfo=" log("ipProvisioningThread(+" + mInterfaceName + "): " + "mNetworkInfo=" + mNetworkInfo); + mNetworkInfo); mIpClient = new IpClient(mContext, mInterfaceName, ipcCallback); ipcCallback = startIpClientLocked(); mIpClient.startProvisioning(mIpClient.buildProvisioningConfiguration() .withoutMultinetworkPolicyTracker() .withoutIpReachabilityMonitor() .build()); mNetworkInfo.setDetailedState(DetailedState.OBTAINING_IPADDR, null, null); mNetworkInfo.setDetailedState(DetailedState.OBTAINING_IPADDR, null, null); } } Loading