blob: 41ca6b6ef29ae8d5e796fe03a190ed97b09966df (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
package com.android.providers.downloads;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
import android.util.Log;
import java.util.BitSet;
class RealSystemFacade implements SystemFacade {
private Context mContext;
public RealSystemFacade(Context context) {
mContext = context;
}
public long currentTimeMillis() {
return System.currentTimeMillis();
}
public BitSet getConnectedNetworkTypes() {
BitSet connectedTypes = new BitSet();
ConnectivityManager connectivity =
(ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
Log.w(Constants.TAG, "couldn't get connectivity manager");
return connectedTypes;
}
NetworkInfo[] infos = connectivity.getAllNetworkInfo();
if (infos != null) {
for (NetworkInfo info : infos) {
if (info.getState() == NetworkInfo.State.CONNECTED) {
connectedTypes.set(info.getType());
}
}
}
if (Constants.LOGVV) {
boolean isConnected = !connectedTypes.isEmpty();
Log.v(Constants.TAG, "network is " + (isConnected ? "" : "not ") + "available");
}
return connectedTypes;
}
public boolean isNetworkRoaming() {
ConnectivityManager connectivity =
(ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
Log.w(Constants.TAG, "couldn't get connectivity manager");
return false;
}
NetworkInfo info = connectivity.getActiveNetworkInfo();
boolean isMobile = (info != null && info.getType() == ConnectivityManager.TYPE_MOBILE);
boolean isRoaming = isMobile && TelephonyManager.getDefault().isNetworkRoaming();
if (Constants.LOGVV) {
Log.v(Constants.TAG, "network is mobile: " + isMobile);
Log.v(Constants.TAG, "network is roaming: " + isRoaming);
}
return isMobile && isRoaming;
}
}
|