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
This commit is contained in:
@@ -16,10 +16,11 @@
|
|||||||
|
|
||||||
package android.net;
|
package android.net;
|
||||||
|
|
||||||
|
import static com.android.internal.util.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import android.annotation.SdkConstant;
|
import android.annotation.SdkConstant;
|
||||||
import android.annotation.SdkConstant.SdkConstantType;
|
import android.annotation.SdkConstant.SdkConstantType;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.ParcelFileDescriptor;
|
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
@@ -67,11 +68,19 @@ public class ConnectivityManager {
|
|||||||
* is set to {@code true} if there are no connected networks at all.
|
* is set to {@code true} if there are no connected networks at all.
|
||||||
*/
|
*/
|
||||||
public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
|
public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The lookup key for a {@link NetworkInfo} object. Retrieve with
|
* The lookup key for a {@link NetworkInfo} object. Retrieve with
|
||||||
* {@link android.content.Intent#getParcelableExtra(String)}.
|
* {@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";
|
public static final String EXTRA_NETWORK_INFO = "networkInfo";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The lookup key for a boolean that indicates whether a connect event
|
* The lookup key for a boolean that indicates whether a connect event
|
||||||
* is for a network to which the connectivity manager was failing over
|
* is for a network to which the connectivity manager was failing over
|
||||||
@@ -514,6 +523,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.
|
* Gets the value of the setting for enabling Mobile data.
|
||||||
*
|
*
|
||||||
@@ -546,10 +568,7 @@ public class ConnectivityManager {
|
|||||||
* {@hide}
|
* {@hide}
|
||||||
*/
|
*/
|
||||||
public ConnectivityManager(IConnectivityManager service) {
|
public ConnectivityManager(IConnectivityManager service) {
|
||||||
if (service == null) {
|
mService = checkNotNull(service, "missing IConnectivityManager");
|
||||||
throw new IllegalArgumentException("missing IConnectivityManager");
|
|
||||||
}
|
|
||||||
mService = service;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package android.net;
|
|||||||
|
|
||||||
import android.net.LinkProperties;
|
import android.net.LinkProperties;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
|
import android.net.NetworkQuotaInfo;
|
||||||
import android.net.NetworkState;
|
import android.net.NetworkState;
|
||||||
import android.net.ProxyProperties;
|
import android.net.ProxyProperties;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
@@ -47,6 +48,8 @@ interface IConnectivityManager
|
|||||||
|
|
||||||
NetworkState[] getAllNetworkState();
|
NetworkState[] getAllNetworkState();
|
||||||
|
|
||||||
|
NetworkQuotaInfo getActiveNetworkQuotaInfo();
|
||||||
|
|
||||||
boolean setRadios(boolean onOff);
|
boolean setRadios(boolean onOff);
|
||||||
|
|
||||||
boolean setRadio(int networkType, boolean turnOn);
|
boolean setRadio(int networkType, boolean turnOn);
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import android.net.MobileDataStateTracker;
|
|||||||
import android.net.NetworkConfig;
|
import android.net.NetworkConfig;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.NetworkInfo.DetailedState;
|
import android.net.NetworkInfo.DetailedState;
|
||||||
|
import android.net.NetworkQuotaInfo;
|
||||||
import android.net.NetworkState;
|
import android.net.NetworkState;
|
||||||
import android.net.NetworkStateTracker;
|
import android.net.NetworkStateTracker;
|
||||||
import android.net.NetworkUtils;
|
import android.net.NetworkUtils;
|
||||||
@@ -737,6 +738,30 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
return result.toArray(new NetworkState[result.size()]);
|
return result.toArray(new NetworkState[result.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private NetworkState getNetworkStateUnchecked(int networkType) {
|
||||||
|
if (isNetworkTypeValid(networkType)) {
|
||||||
|
final NetworkStateTracker tracker = mNetTrackers[networkType];
|
||||||
|
if (tracker != null) {
|
||||||
|
return new NetworkState(tracker.getNetworkInfo(), tracker.getLinkProperties(),
|
||||||
|
tracker.getLinkCapabilities());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NetworkQuotaInfo getActiveNetworkQuotaInfo() {
|
||||||
|
enforceAccessPermission();
|
||||||
|
final NetworkState state = getNetworkStateUnchecked(mActiveDefaultNetwork);
|
||||||
|
if (state != null) {
|
||||||
|
try {
|
||||||
|
return mPolicyManager.getNetworkQuotaInfo(state);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean setRadios(boolean turnOn) {
|
public boolean setRadios(boolean turnOn) {
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
enforceChangePermission();
|
enforceChangePermission();
|
||||||
|
|||||||
Reference in New Issue
Block a user