From b7c333ba6d7480d7531a2db3e84ad934187204a5 Mon Sep 17 00:00:00 2001 From: Rebecca Silberstein Date: Thu, 23 Mar 2017 01:49:14 -0700 Subject: WifiServiceImpl: add new methods to start softap Add the implementations for two new methods to control softap mode. These methods will be called by other methods in WifiServiceImpl and also by ConnectivityService. The calls are not intended to be called by applications and will be protected by the NETWORK_STACK permission. Note: this CL is adding the calls, they will be used in an upcoming CL. Bug: 36540346 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Test: frameworks/base/wifi/tests/runtests.sh Change-Id: I6bc664a32c5df03db1dffb8db20330d9dc904113 --- .../com/android/server/wifi/WifiServiceImpl.java | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'service') diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index e39420941..c5f367561 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -16,6 +16,7 @@ package com.android.server.wifi; +import static com.android.server.connectivity.tethering.IControlsTethering.STATE_TETHERED; import static com.android.server.wifi.WifiController.CMD_AIRPLANE_TOGGLED; import static com.android.server.wifi.WifiController.CMD_BATTERY_CHANGED; import static com.android.server.wifi.WifiController.CMD_EMERGENCY_CALL_STATE_CHANGED; @@ -541,6 +542,11 @@ public class WifiServiceImpl extends IWifiManager.Stub { } } + private void enforceNetworkStackPermission() { + mContext.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_STACK, + "WifiService"); + } + private void enforceAccessPermission() { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_WIFI_STATE, "WifiService"); @@ -696,6 +702,66 @@ public class WifiServiceImpl extends IWifiManager.Stub { return mWifiStateMachine.syncGetWifiApState(); } + /** + * see {@link android.net.wifi.WifiManager#startSoftAp(WifiConfiguration)} + * @param wifiConfig SSID, security and channel details as + * part of WifiConfiguration + * @return {@code true} if softap start was triggered + * @throws SecurityException if the caller does not have permission to start softap + */ + @Override + public boolean startSoftAp(WifiConfiguration wifiConfig) { + // NETWORK_STACK is a signature only permission. + enforceNetworkStackPermission(); + + mLog.trace("startSoftAp uid=%").c(Binder.getCallingUid()).flush(); + + return startSoftApInternal(wifiConfig, STATE_TETHERED); + } + + private boolean startSoftApInternal(WifiConfiguration wifiConfig, int mode) { + mLog.trace("startSoftApInternal uid=% mode=%") + .c(Binder.getCallingUid()).c(mode).flush(); + + // null wifiConfig is a meaningful input for CMD_SET_AP + if (wifiConfig == null || isValid(wifiConfig)) { + // TODO: need a way to set the mode + mWifiController.sendMessage(CMD_SET_AP, 1, 0, wifiConfig); + return true; + } + Slog.e(TAG, "Invalid WifiConfiguration"); + return false; + } + + /** + * see {@link android.net.wifi.WifiManager#stopSoftAp()} + * @return {@code true} if softap stop was triggered + * @throws SecurityException if the caller does not have permission to stop softap + */ + @Override + public boolean stopSoftAp() { + // NETWORK_STACK is a signature only permission. + enforceNetworkStackPermission(); + + mLog.trace("stopSoftAp uid=%").c(Binder.getCallingUid()).flush(); + + // add checks here to make sure this is the proper caller - apps can't disable tethering or + // instances of local only hotspot that they didn't start. return false for those cases + + return stopSoftApInternal(); + } + + /** + * Internal method to stop softap mode. Callers of this method should have already checked + * proper permissions beyond the NetworkStack permission. + */ + private boolean stopSoftApInternal() { + mLog.trace("stopSoftApInternal uid=%").c(Binder.getCallingUid()).flush(); + + mWifiController.sendMessage(CMD_SET_AP, 0, 0); + return true; + } + /** * see {@link WifiManager#getWifiApConfiguration()} * @return soft access point configuration -- cgit v1.2.3