Network data activity change intent for network interfaces.
The activity notification is received from netd, an intent DATA_ACTIVITY_CHANGE is then raised for other part of the system to consume. Change-Id: Idfcc4763c51c5b314c57f546c12557082f06bebf
This commit is contained in:
@@ -136,6 +136,28 @@ public class ConnectivityManager {
|
|||||||
*/
|
*/
|
||||||
public static final String EXTRA_INET_CONDITION = "inetCondition";
|
public static final String EXTRA_INET_CONDITION = "inetCondition";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Broadcast action to indicate the change of data activity status
|
||||||
|
* (idle or active) on a network in a recent period.
|
||||||
|
* The network becomes active when data transimission is started, or
|
||||||
|
* idle if there is no data transimition for a period of time.
|
||||||
|
* {@hide}
|
||||||
|
*/
|
||||||
|
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
|
||||||
|
public static final String ACTION_DATA_ACTIVITY_CHANGE = "android.net.conn.DATA_ACTIVITY_CHANGE";
|
||||||
|
/**
|
||||||
|
* The lookup key for an enum that indicates the network device type on which this data activity
|
||||||
|
* change happens.
|
||||||
|
* {@hide}
|
||||||
|
*/
|
||||||
|
public static final String EXTRA_DEVICE_TYPE = "deviceType";
|
||||||
|
/**
|
||||||
|
* The lookup key for a boolean that indicates the device is active or not. {@code true} means
|
||||||
|
* it is actively sending or receiving data and {@code false} means it is idle.
|
||||||
|
* {@hide}
|
||||||
|
*/
|
||||||
|
public static final String EXTRA_IS_ACTIVE = "isActive";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Broadcast Action: The setting for background data usage has changed
|
* Broadcast Action: The setting for background data usage has changed
|
||||||
* values. Use {@link #getBackgroundDataSetting()} to get the current value.
|
* values. Use {@link #getBackgroundDataSetting()} to get the current value.
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.android.server;
|
package com.android.server;
|
||||||
|
|
||||||
import static android.Manifest.permission.MANAGE_NETWORK_POLICY;
|
import static android.Manifest.permission.MANAGE_NETWORK_POLICY;
|
||||||
|
import static android.Manifest.permission.RECEIVE_DATA_ACTIVITY_CHANGE;
|
||||||
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
|
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
|
||||||
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION_IMMEDIATE;
|
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION_IMMEDIATE;
|
||||||
import static android.net.ConnectivityManager.isNetworkTypeValid;
|
import static android.net.ConnectivityManager.isNetworkTypeValid;
|
||||||
@@ -35,6 +36,7 @@ import android.net.ConnectivityManager;
|
|||||||
import android.net.DummyDataStateTracker;
|
import android.net.DummyDataStateTracker;
|
||||||
import android.net.EthernetDataTracker;
|
import android.net.EthernetDataTracker;
|
||||||
import android.net.IConnectivityManager;
|
import android.net.IConnectivityManager;
|
||||||
|
import android.net.INetworkManagementEventObserver;
|
||||||
import android.net.INetworkPolicyListener;
|
import android.net.INetworkPolicyListener;
|
||||||
import android.net.INetworkPolicyManager;
|
import android.net.INetworkPolicyManager;
|
||||||
import android.net.INetworkStatsService;
|
import android.net.INetworkStatsService;
|
||||||
@@ -546,6 +548,13 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
mSettingsObserver = new SettingsObserver(mHandler, EVENT_APPLY_GLOBAL_HTTP_PROXY);
|
mSettingsObserver = new SettingsObserver(mHandler, EVENT_APPLY_GLOBAL_HTTP_PROXY);
|
||||||
mSettingsObserver.observe(mContext);
|
mSettingsObserver.observe(mContext);
|
||||||
|
|
||||||
|
INetworkManagementEventObserver netdObserver = new NetdObserver();
|
||||||
|
try {
|
||||||
|
mNetd.registerObserver(netdObserver);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
loge("Error registering observer :" + e);
|
||||||
|
}
|
||||||
|
|
||||||
loadGlobalProxy();
|
loadGlobalProxy();
|
||||||
}
|
}
|
||||||
private NetworkStateTracker makeWimaxStateTracker() {
|
private NetworkStateTracker makeWimaxStateTracker() {
|
||||||
@@ -923,6 +932,19 @@ private NetworkStateTracker makeWimaxStateTracker() {
|
|||||||
return tracker != null && tracker.setRadio(turnOn);
|
return tracker != null && tracker.setRadio(turnOn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class NetdObserver extends INetworkManagementEventObserver.Stub {
|
||||||
|
public void interfaceClassDataActivityChanged(String label, boolean active) {
|
||||||
|
int deviceType = Integer.parseInt(label);
|
||||||
|
sendDataActivityBroadcast(deviceType, active);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void interfaceStatusChanged(String iface, boolean up) {}
|
||||||
|
public void interfaceLinkStateChanged(String iface, boolean up) {}
|
||||||
|
public void interfaceAdded(String iface) {}
|
||||||
|
public void interfaceRemoved(String iface) {}
|
||||||
|
public void limitReached(String limitName, String iface) {}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to notice when the calling process dies so we can self-expire
|
* Used to notice when the calling process dies so we can self-expire
|
||||||
*
|
*
|
||||||
@@ -1759,6 +1781,13 @@ private NetworkStateTracker makeWimaxStateTracker() {
|
|||||||
sendStickyBroadcastDelayed(makeGeneralIntent(info, bcastType), delayMs);
|
sendStickyBroadcastDelayed(makeGeneralIntent(info, bcastType), delayMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendDataActivityBroadcast(int deviceType, boolean active) {
|
||||||
|
Intent intent = new Intent(ConnectivityManager.ACTION_DATA_ACTIVITY_CHANGE);
|
||||||
|
intent.putExtra(ConnectivityManager.EXTRA_DEVICE_TYPE, deviceType);
|
||||||
|
intent.putExtra(ConnectivityManager.EXTRA_IS_ACTIVE, active);
|
||||||
|
mContext.sendOrderedBroadcast(intent, RECEIVE_DATA_ACTIVITY_CHANGE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when an attempt to fail over to another network has failed.
|
* Called when an attempt to fail over to another network has failed.
|
||||||
* @param info the {@link NetworkInfo} for the failed network
|
* @param info the {@link NetworkInfo} for the failed network
|
||||||
|
|||||||
Reference in New Issue
Block a user