import static android.text.format.DateUtils.FORMAT_ABBREV_MONTH;
import static android.text.format.DateUtils.FORMAT_SHOW_DATE;
-public class MobileDataController {
- private static final String TAG = "MobileDataController";
+public class DataUsageController {
+ private static final String TAG = "DataUsageController";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
- private static final long DEFAULT_WARNING_LEVEL = 2L * 1024 * 1024 * 1024;
+ public static final long DEFAULT_WARNING_LEVEL = 2L * 1024 * 1024 * 1024;
private static final int FIELDS = FIELD_RX_BYTES | FIELD_TX_BYTES;
private static final StringBuilder PERIOD_BUILDER = new StringBuilder(50);
private static final java.util.Formatter PERIOD_FORMATTER = new java.util.Formatter(
private Callback mCallback;
private NetworkNameProvider mNetworkController;
- public MobileDataController(Context context) {
+ public DataUsageController(Context context) {
mContext = context;
mTelephonyManager = TelephonyManager.from(context);
mConnectivityManager = ConnectivityManager.from(context);
if (subscriberId == null) {
return warn("no subscriber id");
}
+ NetworkTemplate template = NetworkTemplate.buildTemplateMobileAll(subscriberId);
+ template = NetworkTemplate.normalize(template, mTelephonyManager.getMergedSubscriberIds());
+
+ return getDataUsageInfo(template);
+ }
+
+ public DataUsageInfo getWifiDataUsageInfo() {
+ NetworkTemplate template = NetworkTemplate.buildTemplateWifiWildcard();
+ return getDataUsageInfo(template);
+ }
+
+ public DataUsageInfo getDataUsageInfo(NetworkTemplate template) {
final INetworkStatsSession session = getSession();
if (session == null) {
return warn("no stats session");
}
- NetworkTemplate template = NetworkTemplate.buildTemplateMobileAll(subscriberId);
- template = NetworkTemplate.normalize(template, mTelephonyManager.getMergedSubscriberIds());
-
final NetworkPolicy policy = findNetworkPolicy(template);
try {
- final NetworkStatsHistory history = mSession.getHistoryForNetwork(template, FIELDS);
+ final NetworkStatsHistory history = session.getHistoryForNetwork(template, FIELDS);
final long now = System.currentTimeMillis();
final long start, end;
if (policy != null && policy.cycleDay > 0) {
}
final long totalBytes = entry.rxBytes + entry.txBytes;
final DataUsageInfo usage = new DataUsageInfo();
+ usage.startDate = start;
usage.usageLevel = totalBytes;
usage.period = formatDateRange(start, end);
if (policy != null) {
public static class DataUsageInfo {
public String carrier;
public String period;
+ public long startDate;
public long limitLevel;
public long warningLevel;
public long usageLevel;
import android.view.View;
import android.view.ViewGroup;
import com.android.internal.logging.MetricsLogger;
-import com.android.settingslib.net.MobileDataController;
+import com.android.settingslib.net.DataUsageController;
import com.android.systemui.R;
import com.android.systemui.qs.QSIconView;
import com.android.systemui.qs.QSTile;
"com.android.settings", "com.android.settings.Settings$DataUsageSummaryActivity"));
private final NetworkController mController;
- private final MobileDataController mDataController;
+ private final DataUsageController mDataController;
private final CellularDetailAdapter mDetailAdapter;
private final CellSignalCallback mSignalCallback = new CellSignalCallback();
final DataUsageDetailView v = (DataUsageDetailView) (convertView != null
? convertView
: LayoutInflater.from(mContext).inflate(R.layout.data_usage, parent, false));
- final MobileDataController.DataUsageInfo info = mDataController.getDataUsageInfo();
+ final DataUsageController.DataUsageInfo info = mDataController.getDataUsageInfo();
if (info == null) return v;
v.bind(info);
return v;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
-import com.android.settingslib.net.MobileDataController;
+import com.android.settingslib.net.DataUsageController;
import com.android.systemui.FontSizeUtils;
import com.android.systemui.R;
import com.android.systemui.qs.DataUsageGraph;
R.dimen.qs_data_usage_text_size);
}
- public void bind(MobileDataController.DataUsageInfo info) {
+ public void bind(DataUsageController.DataUsageInfo info) {
final Resources res = mContext.getResources();
final int titleId;
final long bytes;
import android.content.Context;
import android.content.Intent;
import android.telephony.SubscriptionInfo;
-import com.android.settingslib.net.MobileDataController;
+import com.android.settingslib.net.DataUsageController;
import com.android.settingslib.wifi.AccessPoint;
import java.util.List;
void setWifiEnabled(boolean enabled);
void onUserSwitched(int newUserId);
AccessPointController getAccessPointController();
- MobileDataController getMobileDataController();
+ DataUsageController getMobileDataController();
public interface SignalCallback {
void setWifiIndicators(boolean enabled, IconState statusIcon, IconState qsIcon,
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyIntents;
-import com.android.settingslib.net.MobileDataController;
+import com.android.settingslib.net.DataUsageController;
import com.android.systemui.DemoMode;
import com.android.systemui.R;
/** Platform implementation of the network controller. **/
public class NetworkControllerImpl extends BroadcastReceiver
- implements NetworkController, DemoMode, MobileDataController.NetworkNameProvider {
+ implements NetworkController, DemoMode, DataUsageController.NetworkNameProvider {
// debug
static final String TAG = "NetworkController";
static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
// SIM for most actions. This may be null if there aren't any SIMs around.
private MobileSignalController mDefaultSignalController;
private final AccessPointControllerImpl mAccessPoints;
- private final MobileDataController mMobileDataController;
+ private final DataUsageController mDataUsageController;
private boolean mInetCondition; // Used for Logging and demo.
SubscriptionManager.from(context), Config.readConfig(context), bgLooper,
new CallbackHandler(),
new AccessPointControllerImpl(context, bgLooper),
- new MobileDataController(context),
+ new DataUsageController(context),
new SubscriptionDefaults());
mReceiverHandler.post(mRegisterListeners);
}
SubscriptionManager subManager, Config config, Looper bgLooper,
CallbackHandler callbackHandler,
AccessPointControllerImpl accessPointController,
- MobileDataController mobileDataController,
+ DataUsageController dataUsageController,
SubscriptionDefaults defaultsHandler) {
mContext = context;
mConfig = config;
mLocale = mContext.getResources().getConfiguration().locale;
mAccessPoints = accessPointController;
- mMobileDataController = mobileDataController;
- mMobileDataController.setNetworkController(this);
- // TODO: Find a way to move this into MobileDataController.
- mMobileDataController.setCallback(new MobileDataController.Callback() {
+ mDataUsageController = dataUsageController;
+ mDataUsageController.setNetworkController(this);
+ // TODO: Find a way to move this into DataUsageController.
+ mDataUsageController.setCallback(new DataUsageController.Callback() {
@Override
public void onMobileDataEnabled(boolean enabled) {
mCallbackHandler.setMobileDataEnabled(enabled);
}
@Override
- public MobileDataController getMobileDataController() {
- return mMobileDataController;
+ public DataUsageController getMobileDataController() {
+ return mDataUsageController;
}
public void addEmergencyListener(EmergencyListener listener) {
import android.util.Log;
import com.android.internal.telephony.cdma.EriInfo;
-import com.android.settingslib.net.MobileDataController;
+import com.android.settingslib.net.DataUsageController;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.policy.NetworkController.IconState;
import com.android.systemui.statusbar.policy.NetworkControllerImpl.Config;
mCallbackHandler = mock(CallbackHandler.class);
mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
mConfig, Looper.getMainLooper(), mCallbackHandler,
- mock(AccessPointControllerImpl.class), mock(MobileDataController.class),
+ mock(AccessPointControllerImpl.class), mock(DataUsageController.class),
mMockSubDefaults);
setupNetworkController();
= new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
mConfig, Looper.getMainLooper(), mCallbackHandler,
mock(AccessPointControllerImpl.class),
- mock(MobileDataController.class), mMockSubDefaults);
+ mock(DataUsageController.class), mMockSubDefaults);
setupNetworkController();
import android.telephony.TelephonyManager;
import android.test.suitebuilder.annotation.SmallTest;
-import com.android.settingslib.net.MobileDataController;
+import com.android.settingslib.net.DataUsageController;
import org.mockito.Mockito;
@SmallTest
mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
mConfig, Looper.getMainLooper(), mCallbackHandler,
Mockito.mock(AccessPointControllerImpl.class),
- Mockito.mock(MobileDataController.class), mMockSubDefaults);
+ Mockito.mock(DataUsageController.class), mMockSubDefaults);
setupNetworkController();
setupDefaultSignal();
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyIntents;
-import com.android.settingslib.net.MobileDataController;
+import com.android.settingslib.net.DataUsageController;
import com.android.systemui.R;
import org.mockito.ArgumentCaptor;
// Create a new NetworkController as this is currently handled in constructor.
mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
mConfig, Looper.getMainLooper(), mCallbackHandler,
- mock(AccessPointControllerImpl.class), mock(MobileDataController.class),
+ mock(AccessPointControllerImpl.class), mock(DataUsageController.class),
mMockSubDefaults);
setupNetworkController();
// Create a new NetworkController as this is currently handled in constructor.
mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
mConfig, Looper.getMainLooper(), mCallbackHandler,
- mock(AccessPointControllerImpl.class), mock(MobileDataController.class),
+ mock(AccessPointControllerImpl.class), mock(DataUsageController.class),
mMockSubDefaults);
setupNetworkController();