diff options
author | Sohani Rao <sohanirao@google.com> | 2016-11-14 19:21:57 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-11-14 19:21:58 +0000 |
commit | 37d2c635d6d3ede95893f2d425b9508b878287a4 (patch) | |
tree | 1e783b894d670b9c504cd4ced8a9ffd7def512f3 /service | |
parent | 4f4d1b8c3c38e66ed142d29bd162827b56745c40 (diff) | |
parent | f42abad834d95e716d8e423bcfc0d17bce90d021 (diff) |
Merge "Permissions check for Wifi Display configuration"
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java index e3e56c8d3..e27b473a3 100644 --- a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java +++ b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java @@ -84,6 +84,7 @@ import com.android.server.wifi.WifiNative; import com.android.server.wifi.WifiStateMachine; import com.android.server.wifi.util.WifiAsyncChannel; import com.android.server.wifi.util.WifiPermissionsUtil; +import com.android.server.wifi.util.WifiPermissionsWrapper; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -117,6 +118,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { private P2pStateMachine mP2pStateMachine; private AsyncChannel mReplyChannel = new WifiAsyncChannel(TAG); private AsyncChannel mWifiChannel; + private WifiInjector mWifiInjector; private static final Boolean JOIN_GROUP = true; private static final Boolean FORM_GROUP = false; @@ -496,10 +498,29 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { @Override public void setMiracastMode(int mode) { enforceConnectivityInternalPermission(); + checkConfigureWifiDisplayPermission(); mP2pStateMachine.sendMessage(SET_MIRACAST_MODE, mode); } @Override + public void checkConfigureWifiDisplayPermission() { + if (!getWfdPermission(Binder.getCallingUid())) { + throw new SecurityException("Wifi Display Permission denied for uid = " + + Binder.getCallingUid()); + } + } + + private boolean getWfdPermission(int uid) { + if (mWifiInjector == null) { + mWifiInjector = WifiInjector.getInstance(); + } + WifiPermissionsWrapper wifiPermissionsWrapper = mWifiInjector.getWifiPermissionsWrapper(); + return wifiPermissionsWrapper.getUidPermission( + android.Manifest.permission.CONFIGURE_WIFI_DISPLAY, uid) + != PackageManager.PERMISSION_DENIED; + } + + @Override protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) { @@ -780,8 +801,13 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { WifiP2pManager.BUSY); break; case WifiP2pManager.SET_WFD_INFO: - replyToMessage(message, WifiP2pManager.SET_WFD_INFO_FAILED, - WifiP2pManager.BUSY); + if (!getWfdPermission(message.sendingUid)) { + replyToMessage(message, WifiP2pManager.SET_WFD_INFO_FAILED, + WifiP2pManager.ERROR); + } else { + replyToMessage(message, WifiP2pManager.SET_WFD_INFO_FAILED, + WifiP2pManager.BUSY); + } break; case WifiP2pManager.REQUEST_PEERS: replyToMessage(message, WifiP2pManager.RESPONSE_PEERS, @@ -940,8 +966,13 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { WifiP2pManager.P2P_UNSUPPORTED); break; case WifiP2pManager.SET_WFD_INFO: - replyToMessage(message, WifiP2pManager.SET_WFD_INFO_FAILED, - WifiP2pManager.P2P_UNSUPPORTED); + if (!getWfdPermission(message.sendingUid)) { + replyToMessage(message, WifiP2pManager.SET_WFD_INFO_FAILED, + WifiP2pManager.ERROR); + } else { + replyToMessage(message, WifiP2pManager.SET_WFD_INFO_FAILED, + WifiP2pManager.P2P_UNSUPPORTED); + } break; case WifiP2pManager.START_WPS: replyToMessage(message, WifiP2pManager.START_WPS_FAILED, @@ -1103,7 +1134,10 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { case WifiP2pManager.SET_WFD_INFO: { WifiP2pWfdInfo d = (WifiP2pWfdInfo) message.obj; - if (d != null && setWfdInfo(d)) { + if (!getWfdPermission(message.sendingUid)) { + replyToMessage(message, WifiP2pManager.SET_WFD_INFO_FAILED, + WifiP2pManager.ERROR); + } else if (d != null && setWfdInfo(d)) { replyToMessage(message, WifiP2pManager.SET_WFD_INFO_SUCCEEDED); } else { replyToMessage(message, WifiP2pManager.SET_WFD_INFO_FAILED, |