|
22 | 22 | import android.content.Context; |
23 | 23 | import android.content.Intent; |
24 | 24 | import android.content.IntentFilter; |
| 25 | +import android.database.Cursor; |
25 | 26 | import android.location.Criteria; |
26 | 27 | import android.location.IGpsStatusListener; |
27 | 28 | import android.location.IGpsStatusProvider; |
|
33 | 34 | import android.net.ConnectivityManager; |
34 | 35 | import android.net.NetworkInfo; |
35 | 36 | import android.net.SntpClient; |
| 37 | +import android.net.Uri; |
36 | 38 | import android.os.Binder; |
37 | 39 | import android.os.Bundle; |
38 | 40 | import android.os.Handler; |
|
46 | 48 | import android.os.SystemClock; |
47 | 49 | import android.os.WorkSource; |
48 | 50 | import android.provider.Settings; |
| 51 | +import android.provider.Telephony.Carriers; |
49 | 52 | import android.provider.Telephony.Sms.Intents; |
50 | 53 | import android.telephony.SmsMessage; |
51 | 54 | import android.telephony.TelephonyManager; |
@@ -490,8 +493,17 @@ private void handleUpdateNetworkState(int state, NetworkInfo info) { |
490 | 493 | } |
491 | 494 |
|
492 | 495 | if (info != null) { |
| 496 | + boolean dataEnabled = Settings.Secure.getInt(mContext.getContentResolver(), |
| 497 | + Settings.Secure.MOBILE_DATA, 1) == 1; |
| 498 | + boolean networkAvailable = info.isAvailable() && dataEnabled; |
| 499 | + String defaultApn = getSelectedApn(); |
| 500 | + if (defaultApn == null) { |
| 501 | + defaultApn = "dummy-apn"; |
| 502 | + } |
| 503 | + |
493 | 504 | native_update_network_state(info.isConnected(), info.getType(), |
494 | | - info.isRoaming(), info.getExtraInfo()); |
| 505 | + info.isRoaming(), networkAvailable, |
| 506 | + info.getExtraInfo(), defaultApn); |
495 | 507 | } |
496 | 508 |
|
497 | 509 | if (info != null && info.getType() == ConnectivityManager.TYPE_MOBILE_SUPL |
@@ -1578,6 +1590,25 @@ public void run() { |
1578 | 1590 | } |
1579 | 1591 | } |
1580 | 1592 |
|
| 1593 | + private String getSelectedApn() { |
| 1594 | + Uri uri = Uri.parse("content://telephony/carriers/preferapn"); |
| 1595 | + String apn = null; |
| 1596 | + |
| 1597 | + Cursor cursor = mContext.getContentResolver().query(uri, new String[] {"apn"}, |
| 1598 | + null, null, Carriers.DEFAULT_SORT_ORDER); |
| 1599 | + |
| 1600 | + if (null != cursor) { |
| 1601 | + try { |
| 1602 | + if (cursor.moveToFirst()) { |
| 1603 | + apn = cursor.getString(0); |
| 1604 | + } |
| 1605 | + } finally { |
| 1606 | + cursor.close(); |
| 1607 | + } |
| 1608 | + } |
| 1609 | + return apn; |
| 1610 | + } |
| 1611 | + |
1581 | 1612 | // for GPS SV statistics |
1582 | 1613 | private static final int MAX_SVS = 32; |
1583 | 1614 | private static final int EPHEMERIS_MASK = 0; |
@@ -1636,5 +1667,5 @@ private native void native_agps_set_ref_location_cellid(int type, int mcc, int m |
1636 | 1667 | private native void native_agps_set_id(int type, String setid); |
1637 | 1668 |
|
1638 | 1669 | private native void native_update_network_state(boolean connected, int type, |
1639 | | - boolean roaming, String extraInfo); |
| 1670 | + boolean roaming, boolean available, String extraInfo, String defaultAPN); |
1640 | 1671 | } |
0 commit comments