diff options
| author | Jeff Sharkey <jsharkey@android.com> | 2011-08-02 17:22:34 -0700 |
|---|---|---|
| committer | Jeff Sharkey <jsharkey@android.com> | 2011-08-02 18:19:54 -0700 |
| commit | f0ceede8fff5df24e5c98701d81c2b71eb138aa9 (patch) | |
| tree | 67dc2c9f7a5eaf3b6f5cb5a5fe4dbfb8854dac0b /core/java/android/net/ConnectivityManager.java | |
| parent | 34e1fb1ee229a7e033dcd42f4efd194e1614d5ce (diff) | |
Expose quota status for active network.
Create API to expose quota status derived from underlying network
policy. This is designed to support applications making informed
decisions when performing network requests.
Fix bug with random stats generation, and write policy when changing
restrict background data flag. Deprecate EXTRA_NETWORK_INFO, since
it varies based on UID.
Bug: 4517283, 5088603
Change-Id: Ic6893a8967f69937e466be226ba7bb86ef5a5d2d
Diffstat (limited to 'core/java/android/net/ConnectivityManager.java')
| -rw-r--r-- | core/java/android/net/ConnectivityManager.java | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index a564d9771f7b..eb9cd213dd8e 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -16,10 +16,11 @@ package android.net; +import static com.android.internal.util.Preconditions.checkNotNull; + import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; import android.os.Binder; -import android.os.ParcelFileDescriptor; import android.os.RemoteException; import java.net.InetAddress; @@ -67,11 +68,19 @@ public class ConnectivityManager { * is set to {@code true} if there are no connected networks at all. */ public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE"; + /** * The lookup key for a {@link NetworkInfo} object. Retrieve with * {@link android.content.Intent#getParcelableExtra(String)}. + * + * @deprecated Since {@link NetworkInfo} can vary based on UID, applications + * should always obtain network information through + * {@link #getActiveNetworkInfo()} or + * {@link #getAllNetworkInfo()}. */ + @Deprecated public static final String EXTRA_NETWORK_INFO = "networkInfo"; + /** * The lookup key for a boolean that indicates whether a connect event * is for a network to which the connectivity manager was failing over @@ -515,6 +524,19 @@ public class ConnectivityManager { } /** + * Return quota status for the current active network, or {@code null} if no + * network is active. Quota status can change rapidly, so these values + * shouldn't be cached. + */ + public NetworkQuotaInfo getActiveNetworkQuotaInfo() { + try { + return mService.getActiveNetworkQuotaInfo(); + } catch (RemoteException e) { + return null; + } + } + + /** * Gets the value of the setting for enabling Mobile data. * * @return Whether mobile data is enabled. @@ -546,10 +568,7 @@ public class ConnectivityManager { * {@hide} */ public ConnectivityManager(IConnectivityManager service) { - if (service == null) { - throw new IllegalArgumentException("missing IConnectivityManager"); - } - mService = service; + mService = checkNotNull(service, "missing IConnectivityManager"); } /** |
