use of android.net.Network in project platform_frameworks_base by android.
the class CaptivePortalLoginActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mCm = ConnectivityManager.from(this);
mNetwork = getIntent().getParcelableExtra(ConnectivityManager.EXTRA_NETWORK);
mCaptivePortal = getIntent().getParcelableExtra(ConnectivityManager.EXTRA_CAPTIVE_PORTAL);
mUserAgent = getIntent().getStringExtra(ConnectivityManager.EXTRA_CAPTIVE_PORTAL_USER_AGENT);
mUrl = getUrl();
if (mUrl == null) {
// getUrl() failed to parse the url provided in the intent: bail out in a way that
// at least provides network access.
done(Result.WANTED_AS_IS);
return;
}
if (DBG) {
Log.d(TAG, String.format("onCreate for %s", mUrl.toString()));
}
// Also initializes proxy system properties.
mCm.bindProcessToNetwork(mNetwork);
// Proxy system properties must be initialized before setContentView is called because
// setContentView initializes the WebView logic which in turn reads the system properties.
setContentView(R.layout.activity_captive_portal_login);
getActionBar().setDisplayShowHomeEnabled(false);
// Exit app if Network disappears.
final NetworkCapabilities networkCapabilities = mCm.getNetworkCapabilities(mNetwork);
if (networkCapabilities == null) {
finishAndRemoveTask();
return;
}
mNetworkCallback = new NetworkCallback() {
@Override
public void onLost(Network lostNetwork) {
if (mNetwork.equals(lostNetwork))
done(Result.UNWANTED);
}
};
final NetworkRequest.Builder builder = new NetworkRequest.Builder();
for (int transportType : networkCapabilities.getTransportTypes()) {
builder.addTransportType(transportType);
}
mCm.registerNetworkCallback(builder.build(), mNetworkCallback);
final WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.clearCache(true);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
mWebViewClient = new MyWebViewClient();
myWebView.setWebViewClient(mWebViewClient);
myWebView.setWebChromeClient(new MyWebChromeClient());
// Start initial page load so WebView finishes loading proxy settings.
// Actual load of mUrl is initiated by MyWebViewClient.
myWebView.loadData("", "text/html", null);
}
use of android.net.Network in project platform_frameworks_base by android.
the class ConnectivityService method getAllNetworkState.
@Override
public NetworkState[] getAllNetworkState() {
// Require internal since we're handing out IMSI details
enforceConnectivityInternalPermission();
final ArrayList<NetworkState> result = Lists.newArrayList();
for (Network network : getAllNetworks()) {
final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
if (nai != null) {
result.add(nai.getNetworkState());
}
}
return result.toArray(new NetworkState[result.size()]);
}
use of android.net.Network in project platform_frameworks_base by android.
the class NetworkTest method testGetNetworkHandle.
@SmallTest
public void testGetNetworkHandle() {
Network one = new Network(1);
Network two = new Network(2);
Network three = new Network(3);
// None of the hashcodes are zero.
assertNotEqual(0, one.hashCode());
assertNotEqual(0, two.hashCode());
assertNotEqual(0, three.hashCode());
// All the hashcodes are distinct.
assertNotEqual(one.hashCode(), two.hashCode());
assertNotEqual(one.hashCode(), three.hashCode());
assertNotEqual(two.hashCode(), three.hashCode());
// None of the handles are zero.
assertNotEqual(0, one.getNetworkHandle());
assertNotEqual(0, two.getNetworkHandle());
assertNotEqual(0, three.getNetworkHandle());
// All the handles are distinct.
assertNotEqual(one.getNetworkHandle(), two.getNetworkHandle());
assertNotEqual(one.getNetworkHandle(), three.getNetworkHandle());
assertNotEqual(two.getNetworkHandle(), three.getNetworkHandle());
// The handles are not equal to the hashcodes.
assertNotEqual(one.hashCode(), one.getNetworkHandle());
assertNotEqual(two.hashCode(), two.getNetworkHandle());
assertNotEqual(three.hashCode(), three.getNetworkHandle());
// Adjust as necessary to test an implementation's specific constants.
// When running with runtest, "adb logcat -s TestRunner" can be useful.
assertEquals(4311403230L, one.getNetworkHandle());
assertEquals(8606370526L, two.getNetworkHandle());
assertEquals(12901337822L, three.getNetworkHandle());
}
use of android.net.Network in project platform_frameworks_base by android.
the class LingerMonitorTest method nai.
NetworkAgentInfo nai(int netId, int transport, int networkType, String networkTypeName) {
NetworkInfo info = new NetworkInfo(networkType, 0, networkTypeName, "");
NetworkCapabilities caps = new NetworkCapabilities();
caps.addCapability(0);
caps.addTransportType(transport);
NetworkAgentInfo nai = new NetworkAgentInfo(null, null, new Network(netId), info, null, caps, 50, mCtx, null, mMisc, null, mConnService);
nai.everValidated = true;
return nai;
}
use of android.net.Network in project platform_frameworks_base by android.
the class NetdEventListenerServiceTest method testBatchAndNetworkLost.
@SmallTest
public void testBatchAndNetworkLost() throws Exception {
byte[] eventTypes = Arrays.copyOf(EVENT_TYPES, 20);
byte[] returnCodes = Arrays.copyOf(RETURN_CODES, 20);
int[] latencies = Arrays.copyOf(LATENCIES, 20);
log(105, LATENCIES);
log(105, latencies);
mCallbackCaptor.getValue().onLost(new Network(105));
log(105, LATENCIES);
verifyLoggedEvents(new DnsEvent(105, eventTypes, returnCodes, latencies), new DnsEvent(105, EVENT_TYPES, RETURN_CODES, LATENCIES), new DnsEvent(105, EVENT_TYPES, RETURN_CODES, LATENCIES));
}
Aggregations