summaryrefslogtreecommitdiffstats
path: root/service/java/com/android
diff options
context:
space:
mode:
authorJimmy Chen <jimmycmchen@google.com>2019-05-10 10:17:48 +0800
committerJimmy Chen <jimmycmchen@google.com>2019-05-15 14:12:42 +0800
commit8a78aefb576b45f40c96892cc7c391c23a0ad5b6 (patch)
tree9d450f572aeb247c7236b06f16e32cf6b6f91a9d /service/java/com/android
parentb70a500802ff55d13c71f7431e0c32d0220e9d04 (diff)
downloadandroid_frameworks_opt_net_wifi-8a78aefb576b45f40c96892cc7c391c23a0ad5b6.tar.gz
android_frameworks_opt_net_wifi-8a78aefb576b45f40c96892cc7c391c23a0ad5b6.tar.bz2
android_frameworks_opt_net_wifi-8a78aefb576b45f40c96892cc7c391c23a0ad5b6.zip
p2p: only gate sensitive API by location settings
Gating the whole P2P by location settings is over-killed, Remove location setting gate for p2p enablement and gate sensitive API by location settings. Bug: 132414202 Test: atest FrameworksWifiTests Change-Id: I310c82e4d115a6e59fc7ed9d13d8a9eb021a9155
Diffstat (limited to 'service/java/com/android')
-rw-r--r--service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java56
-rw-r--r--service/java/com/android/server/wifi/util/WifiPermissionsUtil.java8
2 files changed, 29 insertions, 35 deletions
diff --git a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java
index adc863ba9..3f3745664 100644
--- a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java
+++ b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java
@@ -829,12 +829,15 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
mContext.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- if (isLocationModeEnabled()) {
- checkAndReEnableP2p();
- } else {
- sendMessage(DISABLE_P2P);
+ /* if location mode is off, ongoing discovery should be stopped.
+ * possible ongoing discovery:
+ * - peer discovery
+ * - service discovery
+ * - group joining scan in native service
+ */
+ if (!mWifiPermissionsUtil.isLocationModeEnabled()) {
+ sendMessage(WifiP2pManager.STOP_DISCOVERY);
}
- checkAndSendP2pStateChangedBroadcast();
}
}, new IntentFilter(LocationManager.MODE_CHANGED_ACTION));
// Register for interface availability from HalDeviceManager
@@ -1047,7 +1050,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
case WifiP2pManager.REQUEST_GROUP_INFO:
if (!mWifiPermissionsUtil.checkCanAccessWifiDirect(
getCallingPkgName(message.sendingUid, message.replyTo),
- message.sendingUid)) {
+ message.sendingUid, false)) {
replyToMessage(message, WifiP2pManager.RESPONSE_GROUP_INFO, null);
// remain at this state.
break;
@@ -1063,8 +1066,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
break;
case WifiP2pManager.REQUEST_P2P_STATE:
replyToMessage(message, WifiP2pManager.RESPONSE_P2P_STATE,
- (mIsWifiEnabled && isHalInterfaceAvailable()
- && isLocationModeEnabled())
+ (mIsWifiEnabled && isHalInterfaceAvailable())
? WifiP2pManager.WIFI_P2P_STATE_ENABLED
: WifiP2pManager.WIFI_P2P_STATE_DISABLED);
break;
@@ -1198,7 +1200,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
case WifiP2pManager.REQUEST_DEVICE_INFO:
if (!mWifiPermissionsUtil.checkCanAccessWifiDirect(
getCallingPkgName(message.sendingUid, message.replyTo),
- message.sendingUid)) {
+ message.sendingUid, false)) {
replyToMessage(message, WifiP2pManager.RESPONSE_DEVICE_INFO, null);
break;
}
@@ -1367,10 +1369,8 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
if (mVerboseLoggingEnabled) logd(getName() + message.toString());
switch (message.what) {
case ENABLE_P2P:
- boolean isLocationEnabled = isLocationModeEnabled();
- if (!mIsWifiEnabled || !isLocationEnabled) {
- Log.e(TAG, "Ignore P2P enable since wifi is " + mIsWifiEnabled
- + " and location is " + isLocationEnabled);
+ if (!mIsWifiEnabled) {
+ Log.e(TAG, "Ignore P2P enable since wifi is " + mIsWifiEnabled);
break;
}
mInterfaceName = mWifiNative.setupInterface((String ifaceName) -> {
@@ -1511,7 +1511,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
case WifiP2pManager.DISCOVER_PEERS:
if (!mWifiPermissionsUtil.checkCanAccessWifiDirect(
getCallingPkgName(message.sendingUid, message.replyTo),
- message.sendingUid)) {
+ message.sendingUid, true)) {
replyToMessage(message, WifiP2pManager.DISCOVER_PEERS_FAILED,
WifiP2pManager.ERROR);
// remain at this state.
@@ -1547,7 +1547,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
case WifiP2pManager.DISCOVER_SERVICES:
if (!mWifiPermissionsUtil.checkCanAccessWifiDirect(
getCallingPkgName(message.sendingUid, message.replyTo),
- message.sendingUid)) {
+ message.sendingUid, true)) {
replyToMessage(message, WifiP2pManager.DISCOVER_SERVICES_FAILED,
WifiP2pManager.ERROR);
// remain at this state.
@@ -1597,7 +1597,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
case WifiP2pManager.ADD_LOCAL_SERVICE:
if (!mWifiPermissionsUtil.checkCanAccessWifiDirect(
getCallingPkgName(message.sendingUid, message.replyTo),
- message.sendingUid)) {
+ message.sendingUid, false)) {
replyToMessage(message, WifiP2pManager.ADD_LOCAL_SERVICE_FAILED);
// remain at this state.
break;
@@ -1750,7 +1750,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
case WifiP2pManager.CONNECT:
if (!mWifiPermissionsUtil.checkCanAccessWifiDirect(
getCallingPkgName(message.sendingUid, message.replyTo),
- message.sendingUid)) {
+ message.sendingUid, false)) {
replyToMessage(message, WifiP2pManager.CONNECT_FAILED);
// remain at this state.
break;
@@ -1909,7 +1909,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
case WifiP2pManager.CREATE_GROUP:
if (!mWifiPermissionsUtil.checkCanAccessWifiDirect(
getCallingPkgName(message.sendingUid, message.replyTo),
- message.sendingUid)) {
+ message.sendingUid, false)) {
replyToMessage(message, WifiP2pManager.CREATE_GROUP_FAILED,
WifiP2pManager.ERROR);
// remain at this state.
@@ -2754,7 +2754,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
case WifiP2pManager.CONNECT:
if (!mWifiPermissionsUtil.checkCanAccessWifiDirect(
getCallingPkgName(message.sendingUid, message.replyTo),
- message.sendingUid)) {
+ message.sendingUid, false)) {
replyToMessage(message, WifiP2pManager.CONNECT_FAILED);
// remain at this state.
break;
@@ -2924,35 +2924,27 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
// a) Wifi is enabled.
// b) HAL (HIDL) interface is available.
// c) There is atleast 1 client app which invoked initialize().
- // d) Location is enabled.
private void checkAndReEnableP2p() {
- boolean isLocationEnabled = isLocationModeEnabled();
boolean isHalInterfaceAvailable = isHalInterfaceAvailable();
Log.d(TAG, "Wifi enabled=" + mIsWifiEnabled + ", P2P Interface availability="
+ isHalInterfaceAvailable + ", Number of clients="
- + mDeathDataByBinder.size() + ", Location enabled=" + isLocationEnabled);
+ + mDeathDataByBinder.size());
if (mIsWifiEnabled && isHalInterfaceAvailable
- && isLocationEnabled && !mDeathDataByBinder.isEmpty()) {
+ && !mDeathDataByBinder.isEmpty()) {
sendMessage(ENABLE_P2P);
}
}
- private boolean isLocationModeEnabled() {
- return mWifiPermissionsUtil.isLocationModeEnabled();
- }
-
// Ignore judgement if the device do not support HAL (HIDL) interface
private boolean isHalInterfaceAvailable() {
return mWifiNative.isHalInterfaceSupported() ? mIsHalInterfaceAvailable : true;
}
private void checkAndSendP2pStateChangedBroadcast() {
- boolean isLocationEnabled = isLocationModeEnabled();
boolean isHalInterfaceAvailable = isHalInterfaceAvailable();
Log.d(TAG, "Wifi enabled=" + mIsWifiEnabled + ", P2P Interface availability="
- + isHalInterfaceAvailable + ", Location enabled=" + isLocationEnabled);
- sendP2pStateChangedBroadcast(mIsWifiEnabled && isHalInterfaceAvailable
- && isLocationEnabled);
+ + isHalInterfaceAvailable);
+ sendP2pStateChangedBroadcast(mIsWifiEnabled && isHalInterfaceAvailable);
}
private void sendP2pStateChangedBroadcast(boolean enabled) {
@@ -4081,7 +4073,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
private WifiP2pDeviceList getPeers(String pkgName, int uid) {
// getPeers() is guaranteed to be invoked after Wifi Service is up
// This ensures getInstance() will return a non-null object now
- if (mWifiPermissionsUtil.checkCanAccessWifiDirect(pkgName, uid)) {
+ if (mWifiPermissionsUtil.checkCanAccessWifiDirect(pkgName, uid, true)) {
return new WifiP2pDeviceList(mPeers);
} else {
return new WifiP2pDeviceList();
diff --git a/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java b/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java
index bfb509305..2834ad765 100644
--- a/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java
+++ b/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java
@@ -317,10 +317,12 @@ public class WifiPermissionsUtil {
*
* @param pkgName package name of the application requesting access
* @param uid The uid of the package
+ * @param needLocationModeEnabled indicates location mode must be enabled.
*
* @return true if caller has permission, false otherwise
*/
- public boolean checkCanAccessWifiDirect(String pkgName, int uid) {
+ public boolean checkCanAccessWifiDirect(String pkgName, int uid,
+ boolean needLocationModeEnabled) {
try {
checkPackage(uid, pkgName);
} catch (SecurityException se) {
@@ -333,8 +335,8 @@ public class WifiPermissionsUtil {
return true;
}
- // Location mode must be enabled
- if (!isLocationModeEnabled()) {
+ // Location mode must be enabled if needed.
+ if (needLocationModeEnabled && !isLocationModeEnabled()) {
Slog.e(TAG, "Location mode is disabled for the device");
return false;
}