@@ -420,6 +420,7 @@ private void registerGlobalAlert() {
420420 @ Override
421421 public INetworkStatsSession openSession () {
422422 mContext .enforceCallingOrSelfPermission (READ_NETWORK_USAGE_HISTORY , TAG );
423+ assertBandwidthControlEnabled ();
423424
424425 // return an IBinder which holds strong references to any loaded stats
425426 // for its lifetime; when caller closes only weak references remain.
@@ -486,6 +487,7 @@ public void close() {
486487 @ Override
487488 public long getNetworkTotalBytes (NetworkTemplate template , long start , long end ) {
488489 mContext .enforceCallingOrSelfPermission (READ_NETWORK_USAGE_HISTORY , TAG );
490+ assertBandwidthControlEnabled ();
489491 return mDevStatsCached .getSummary (template , start , end ).getTotalBytes ();
490492 }
491493
@@ -494,6 +496,7 @@ public NetworkStats getDataLayerSnapshotForUid(int uid) throws RemoteException {
494496 if (Binder .getCallingUid () != uid ) {
495497 mContext .enforceCallingOrSelfPermission (ACCESS_NETWORK_STATE , TAG );
496498 }
499+ assertBandwidthControlEnabled ();
497500
498501 // TODO: switch to data layer stats once kernel exports
499502 // for now, read network layer stats and flatten across all ifaces
@@ -565,6 +568,7 @@ public void setUidForeground(int uid, boolean uidForeground) {
565568 @ Override
566569 public void forceUpdate () {
567570 mContext .enforceCallingOrSelfPermission (READ_NETWORK_USAGE_HISTORY , TAG );
571+ assertBandwidthControlEnabled ();
568572
569573 final long token = Binder .clearCallingIdentity ();
570574 try {
@@ -1039,6 +1043,12 @@ public boolean handleMessage(Message msg) {
10391043 }
10401044 };
10411045
1046+ private void assertBandwidthControlEnabled () {
1047+ if (!isBandwidthControlEnabled ()) {
1048+ throw new IllegalStateException ("Bandwidth module disabled" );
1049+ }
1050+ }
1051+
10421052 private boolean isBandwidthControlEnabled () {
10431053 try {
10441054 return mNetworkManager .isBandwidthControlEnabled ();
0 commit comments