4545import android .net .RouteInfo ;
4646import android .net .wifi .WifiConfiguration ;
4747import android .net .wifi .WifiConfiguration .KeyMgmt ;
48+ import android .os .Binder ;
4849import android .os .Handler ;
4950import android .os .INetworkManagementService ;
51+ import android .os .Process ;
5052import android .os .RemoteCallbackList ;
5153import android .os .RemoteException ;
5254import android .os .SystemClock ;
@@ -1436,7 +1438,7 @@ public void flushInterfaceDnsCache(String iface) {
14361438
14371439 @ Override
14381440 public void setFirewallEnabled (boolean enabled ) {
1439- mContext . enforceCallingOrSelfPermission ( CONNECTIVITY_INTERNAL , TAG );
1441+ enforceSystemUid ( );
14401442 try {
14411443 mConnector .execute ("firewall" , enabled ? "enable" : "disable" );
14421444 mFirewallEnabled = enabled ;
@@ -1447,13 +1449,13 @@ public void setFirewallEnabled(boolean enabled) {
14471449
14481450 @ Override
14491451 public boolean isFirewallEnabled () {
1450- mContext . enforceCallingOrSelfPermission ( CONNECTIVITY_INTERNAL , TAG );
1452+ enforceSystemUid ( );
14511453 return mFirewallEnabled ;
14521454 }
14531455
14541456 @ Override
14551457 public void setFirewallInterfaceRule (String iface , boolean allow ) {
1456- mContext . enforceCallingOrSelfPermission ( CONNECTIVITY_INTERNAL , TAG );
1458+ enforceSystemUid ( );
14571459 Preconditions .checkState (mFirewallEnabled );
14581460 final String rule = allow ? ALLOW : DENY ;
14591461 try {
@@ -1465,7 +1467,7 @@ public void setFirewallInterfaceRule(String iface, boolean allow) {
14651467
14661468 @ Override
14671469 public void setFirewallEgressSourceRule (String addr , boolean allow ) {
1468- mContext . enforceCallingOrSelfPermission ( CONNECTIVITY_INTERNAL , TAG );
1470+ enforceSystemUid ( );
14691471 Preconditions .checkState (mFirewallEnabled );
14701472 final String rule = allow ? ALLOW : DENY ;
14711473 try {
@@ -1477,7 +1479,7 @@ public void setFirewallEgressSourceRule(String addr, boolean allow) {
14771479
14781480 @ Override
14791481 public void setFirewallEgressDestRule (String addr , int port , boolean allow ) {
1480- mContext . enforceCallingOrSelfPermission ( CONNECTIVITY_INTERNAL , TAG );
1482+ enforceSystemUid ( );
14811483 Preconditions .checkState (mFirewallEnabled );
14821484 final String rule = allow ? ALLOW : DENY ;
14831485 try {
@@ -1489,7 +1491,7 @@ public void setFirewallEgressDestRule(String addr, int port, boolean allow) {
14891491
14901492 @ Override
14911493 public void setFirewallUidRule (int uid , boolean allow ) {
1492- mContext . enforceCallingOrSelfPermission ( CONNECTIVITY_INTERNAL , TAG );
1494+ enforceSystemUid ( );
14931495 Preconditions .checkState (mFirewallEnabled );
14941496 final String rule = allow ? ALLOW : DENY ;
14951497 try {
@@ -1499,6 +1501,13 @@ public void setFirewallUidRule(int uid, boolean allow) {
14991501 }
15001502 }
15011503
1504+ private static void enforceSystemUid () {
1505+ final int uid = Binder .getCallingUid ();
1506+ if (uid != Process .SYSTEM_UID ) {
1507+ throw new SecurityException ("Only available to AID_SYSTEM" );
1508+ }
1509+ }
1510+
15021511 @ Override
15031512 public void monitor () {
15041513 if (mConnector != null ) {
0 commit comments