@@ -884,22 +884,25 @@ public NetworkQuotaInfo getActiveNetworkQuotaInfo() {
884884 @ Override
885885 public boolean isActiveNetworkMetered () {
886886 enforceAccessPermission ();
887-
888887 final long token = Binder .clearCallingIdentity ();
889888 try {
890- final NetworkState state = getNetworkStateUnchecked (mActiveDefaultNetwork );
891- if (state != null ) {
892- try {
893- return mPolicyManager .isNetworkMetered (state );
894- } catch (RemoteException e ) {
895- }
896- }
897- return false ;
889+ return isNetworkMeteredUnchecked (mActiveDefaultNetwork );
898890 } finally {
899891 Binder .restoreCallingIdentity (token );
900892 }
901893 }
902894
895+ private boolean isNetworkMeteredUnchecked (int networkType ) {
896+ final NetworkState state = getNetworkStateUnchecked (networkType );
897+ if (state != null ) {
898+ try {
899+ return mPolicyManager .isNetworkMetered (state );
900+ } catch (RemoteException e ) {
901+ }
902+ }
903+ return false ;
904+ }
905+
903906 public boolean setRadios (boolean turnOn ) {
904907 boolean result = true ;
905908 enforceChangePermission ();
@@ -993,7 +996,8 @@ public String toString() {
993996 public int startUsingNetworkFeature (int networkType , String feature ,
994997 IBinder binder ) {
995998 if (VDBG ) {
996- log ("startUsingNetworkFeature for net " + networkType + ": " + feature );
999+ log ("startUsingNetworkFeature for net " + networkType + ": " + feature + ", uid="
1000+ + Binder .getCallingUid ());
9971001 }
9981002 enforceChangePermission ();
9991003 if (!ConnectivityManager .isNetworkTypeValid (networkType ) ||
@@ -1010,6 +1014,16 @@ public int startUsingNetworkFeature(int networkType, String feature,
10101014 enforceConnectivityInternalPermission ();
10111015 }
10121016
1017+ // if UID is restricted, don't allow them to bring up metered APNs
1018+ final boolean networkMetered = isNetworkMeteredUnchecked (usedNetworkType );
1019+ final int uidRules ;
1020+ synchronized (mRulesLock ) {
1021+ uidRules = mUidRules .get (Binder .getCallingUid (), RULE_ALLOW_ALL );
1022+ }
1023+ if (networkMetered && (uidRules & RULE_REJECT_METERED ) != 0 ) {
1024+ return Phone .APN_REQUEST_FAILED ;
1025+ }
1026+
10131027 NetworkStateTracker network = mNetTrackers [usedNetworkType ];
10141028 if (network != null ) {
10151029 Integer currentPid = new Integer (getCallingPid ());
@@ -1432,7 +1446,6 @@ public void onUidRulesChanged(int uid, int uidRules) {
14321446 mUidRules .put (uid , uidRules );
14331447 }
14341448
1435- // TODO: dispatch into NMS to push rules towards kernel module
14361449 // TODO: notify UID when it has requested targeted updates
14371450 }
14381451
0 commit comments