use of android.net.NetworkInfo in project android_frameworks_base by ParanoidAndroid.
the class ConnectivityService method getProvisioningNetworkInfo.
/**
* Find the first Provisioning network.
*
* @return NetworkInfo or null if none.
*/
private NetworkInfo getProvisioningNetworkInfo() {
enforceAccessPermission();
// Find the first Provisioning Network
NetworkInfo provNi = null;
for (NetworkInfo ni : getAllNetworkInfo()) {
if (ni.isConnectedToProvisioningNetwork()) {
provNi = ni;
break;
}
}
if (DBG)
log("getProvisioningNetworkInfo: X provNi=" + provNi);
return provNi;
}
use of android.net.NetworkInfo in project android_frameworks_base by ParanoidAndroid.
the class LockdownVpnTracker method handleStateChangedLocked.
/**
* Watch for state changes to both active egress network, kicking off a VPN
* connection when ready, or setting firewall rules once VPN is connected.
*/
private void handleStateChangedLocked() {
Slog.d(TAG, "handleStateChanged()");
final NetworkInfo egressInfo = mConnService.getActiveNetworkInfoUnfiltered();
final LinkProperties egressProp = mConnService.getActiveLinkProperties();
final NetworkInfo vpnInfo = mVpn.getNetworkInfo();
final VpnConfig vpnConfig = mVpn.getLegacyVpnConfig();
// Restart VPN when egress network disconnected or changed
final boolean egressDisconnected = egressInfo == null || State.DISCONNECTED.equals(egressInfo.getState());
final boolean egressChanged = egressProp == null || !TextUtils.equals(mAcceptedEgressIface, egressProp.getInterfaceName());
if (egressDisconnected || egressChanged) {
clearSourceRulesLocked();
mAcceptedEgressIface = null;
mVpn.stopLegacyVpn();
}
if (egressDisconnected) {
hideNotification();
return;
}
final int egressType = egressInfo.getType();
if (vpnInfo.getDetailedState() == DetailedState.FAILED) {
EventLogTags.writeLockdownVpnError(egressType);
}
if (mErrorCount > MAX_ERROR_COUNT) {
showNotification(R.string.vpn_lockdown_error, R.drawable.vpn_disconnected);
} else if (egressInfo.isConnected() && !vpnInfo.isConnectedOrConnecting()) {
if (mProfile.isValidLockdownProfile()) {
Slog.d(TAG, "Active network connected; starting VPN");
EventLogTags.writeLockdownVpnConnecting(egressType);
showNotification(R.string.vpn_lockdown_connecting, R.drawable.vpn_disconnected);
mAcceptedEgressIface = egressProp.getInterfaceName();
mVpn.startLegacyVpn(mProfile, KeyStore.getInstance(), egressProp);
} else {
Slog.e(TAG, "Invalid VPN profile; requires IP-based server and DNS");
showNotification(R.string.vpn_lockdown_error, R.drawable.vpn_disconnected);
}
} else if (vpnInfo.isConnected() && vpnConfig != null) {
final String iface = vpnConfig.interfaze;
final String sourceAddr = vpnConfig.addresses;
if (TextUtils.equals(iface, mAcceptedIface) && TextUtils.equals(sourceAddr, mAcceptedSourceAddr)) {
return;
}
Slog.d(TAG, "VPN connected using iface=" + iface + ", sourceAddr=" + sourceAddr);
EventLogTags.writeLockdownVpnConnected(egressType);
showNotification(R.string.vpn_lockdown_connected, R.drawable.vpn_connected);
try {
clearSourceRulesLocked();
mNetService.setFirewallInterfaceRule(iface, true);
mNetService.setFirewallEgressSourceRule(sourceAddr, true);
mErrorCount = 0;
mAcceptedIface = iface;
mAcceptedSourceAddr = sourceAddr;
} catch (RemoteException e) {
throw new RuntimeException("Problem setting firewall rules", e);
}
mConnService.sendConnectedBroadcast(augmentNetworkInfo(egressInfo));
}
}
use of android.net.NetworkInfo in project android_frameworks_base by ParanoidAndroid.
the class NetworkStatsServiceTest method buildMobile3gState.
private static NetworkState buildMobile3gState(String subscriberId) {
final NetworkInfo info = new NetworkInfo(TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UMTS, null, null);
info.setDetailedState(DetailedState.CONNECTED, null, null);
final LinkProperties prop = new LinkProperties();
prop.setInterfaceName(TEST_IFACE);
return new NetworkState(info, prop, null, subscriberId, null);
}
use of android.net.NetworkInfo in project storymaker by StoryMaker.
the class StorymakerDownloadManager method downloadFromLigerServer.
private void downloadFromLigerServer() {
String ligerUrl = indexItem.getExpansionFileUrl();
String ligerPath = StorymakerIndexManager.buildFilePath(indexItem, context);
String ligerObb = fileName;
Timber.d("DOWNLOADING " + ligerObb + " FROM " + ligerUrl + " TO " + ligerPath);
try {
URI expansionFileUri = null;
HttpGet request = null;
HttpResponse response = null;
File targetFolder = new File(ligerPath);
String nameFilter = "";
if (ligerObb.contains(indexItem.getExpansionFileVersion())) {
nameFilter = fileName.replace(indexItem.getExpansionFileVersion(), "*") + "*.tmp";
} else {
nameFilter = fileName + "*.tmp";
}
Timber.d("CLEANUP: DELETING " + nameFilter + " FROM " + targetFolder.getPath());
WildcardFileFilter oldFileFilter = new WildcardFileFilter(nameFilter);
for (File oldFile : FileUtils.listFiles(targetFolder, oldFileFilter, null)) {
Timber.d("CLEANUP: FOUND " + oldFile.getPath() + ", DELETING");
FileUtils.deleteQuietly(oldFile);
}
// additional cleanup of pre-name-change files
if (fileName.contains(scal.io.liger.Constants.MAIN)) {
nameFilter = fileName.replace(scal.io.liger.Constants.MAIN + ".", "").replace(indexItem.getExpansionFileVersion(), "*");
Timber.d("CLEANUP: DELETING OLD FILES " + nameFilter + " FROM " + targetFolder.getPath());
oldFileFilter = new WildcardFileFilter(nameFilter);
for (File oldFile : FileUtils.listFiles(targetFolder, oldFileFilter, null)) {
Timber.d("CLEANUP: FOUND OLD FILE " + oldFile.getPath() + ", DELETING");
FileUtils.deleteQuietly(oldFile);
}
}
File targetFile = new File(targetFolder, ligerObb + ".tmp");
// if there is no connectivity, do not queue item (no longer seems to pause if connection is unavailable)
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if ((ni != null) && (ni.isConnectedOrConnecting())) {
if (context instanceof Activity) {
// FIXME move to strings
Utils.toastOnUiThread((Activity) context, "Starting download of " + indexItem.getTitle() + ".", false);
}
// check preferences. will also need to check whether tor is active within method
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
boolean useTor = settings.getBoolean("pusetor", false);
boolean useManager = settings.getBoolean("pusedownloadmanager", false);
//if (checkTor(useTor, context)) {
if (useTor && useManager) {
Timber.e("ANDROID DOWNLOAD MANAGER IS NOT COMPATABLE WITH TOR");
if (context instanceof Activity) {
// FIXME move to strings
Utils.toastOnUiThread((Activity) context, "Check settings, can't use download manager and tor", true);
}
StorymakerQueueManager.checkQueueFinished(context, targetFile.getName());
} else if (useTor || !useManager) {
downloadWithTor(useTor, Uri.parse(ligerUrl + ligerObb), mAppTitle + " content download", ligerObb, targetFile);
} else {
downloadWithManager(Uri.parse(ligerUrl + ligerObb), mAppTitle + " content download", ligerObb, Uri.fromFile(targetFile));
}
} else {
Timber.d("NO CONNECTION, NOT QUEUEING DOWNLOAD: " + ligerUrl + ligerObb + " -> " + targetFile.getPath());
if (context instanceof Activity) {
// FIXME move to strings
Utils.toastOnUiThread((Activity) context, "Check settings, no connection, can't start download", true);
}
StorymakerQueueManager.checkQueueFinished(context, targetFile.getName());
}
} catch (Exception e) {
Timber.e(e, "DOWNLOAD ERROR: " + ligerUrl + ligerObb + " -> " + e.getMessage());
}
}
use of android.net.NetworkInfo in project GT by Tencent.
the class NetUtils method getNetWorkType.
/**
* 获取网络连接类型
*
* @return -1表示没有网络
*/
public static final int getNetWorkType() {
Context c = GTApp.getContext();
ConnectivityManager conn = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
if (conn == null) {
return -1;
}
NetworkInfo info = conn.getActiveNetworkInfo();
if (info == null || !info.isAvailable()) {
return -1;
}
int type = info.getType();
if (type == ConnectivityManager.TYPE_WIFI) {
return TYPE_WIFI;
} else {
TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE);
switch(tm.getNetworkType()) {
case TelephonyManager.NETWORK_TYPE_CDMA:
return TYPE_GPRS;
case TelephonyManager.NETWORK_TYPE_EDGE:
return TYPE_GPRS;
case TelephonyManager.NETWORK_TYPE_GPRS:
return TYPE_GPRS;
default:
return TYPE_3G;
}
}
}
Aggregations