summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJimmy Chen <jimmycmchen@google.com>2018-10-11 18:03:38 +0800
committerJimmy Chen <jimmycmchen@google.com>2018-11-06 15:36:34 +0800
commitc071d94076418a39f70cb442d1f1635286a5ce29 (patch)
tree5532bd1a2afbd66620d4452948268d8795cb67fb
parent894960003ef7ccb181dee54da59fe787f471e406 (diff)
p2p: support factory reset for P2P group
provide system API for Settings Bug: 109866998 Test: Manual tests * manual trigger network reset in below conditions: * trigger network reset with P2P on * trigger network reset with WiFi on, P2P off * trigger network reset with WiFi off * trigger network reset with WiFi off then do reboot * check groups shown in WiFi Direct page * use wpa_cli -i p2p0 list_network Test: CtsVerifier - WiFi Direct category Test: Unit tests - atest frameworks/opt/net/wifi/tests/wifitests Test: Permission check * call factoryReset as Guest * call factoryReset from 3rd-party application Change-Id: I20fd1cc6728c84961e10cbc82b9b5d934e93be81
-rw-r--r--service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java82
1 files changed, 82 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java
index 1a1ec8c4e..499c6d5b3 100644
--- a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java
+++ b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java
@@ -58,9 +58,11 @@ import android.os.INetworkManagementService;
import android.os.Looper;
import android.os.Message;
import android.os.Messenger;
+import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
+import android.os.UserManager;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
@@ -79,6 +81,7 @@ import com.android.internal.util.AsyncChannel;
import com.android.internal.util.Protocol;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
+import com.android.server.wifi.FrameworkFacade;
import com.android.server.wifi.WifiInjector;
import com.android.server.wifi.util.WifiAsyncChannel;
import com.android.server.wifi.util.WifiHandler;
@@ -355,6 +358,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
case WifiP2pManager.REQUEST_GROUP_INFO:
case WifiP2pManager.DELETE_PERSISTENT_GROUP:
case WifiP2pManager.REQUEST_PERSISTENT_GROUP_INFO:
+ case WifiP2pManager.FACTORY_RESET:
mP2pStateMachine.sendMessage(Message.obtain(msg));
break;
default:
@@ -993,6 +997,14 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
// a group removed event. Flushing things at group formation
// failure causes supplicant issues. Ignore right now.
break;
+ case WifiP2pManager.FACTORY_RESET:
+ if (factoryReset((Bundle) message.obj, message.sendingUid)) {
+ replyToMessage(message, WifiP2pManager.FACTORY_RESET_SUCCEEDED);
+ } else {
+ replyToMessage(message, WifiP2pManager.FACTORY_RESET_FAILED,
+ WifiP2pManager.ERROR);
+ }
+ break;
default:
loge("Unhandled message " + message);
return NOT_HANDLED;
@@ -1088,6 +1100,10 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
replyToMessage(message, WifiP2pManager.STOP_LISTEN_FAILED,
WifiP2pManager.P2P_UNSUPPORTED);
break;
+ case WifiP2pManager.FACTORY_RESET:
+ replyToMessage(message, WifiP2pManager.FACTORY_RESET_FAILED,
+ WifiP2pManager.P2P_UNSUPPORTED);
+ break;
default:
return NOT_HANDLED;
@@ -1173,6 +1189,14 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
public void enter() {
if (DBG) logd(getName());
mNetworkInfo.setIsAvailable(true);
+
+ if (isPendingFactoryReset()) {
+ Bundle callingPackage = new Bundle();
+ callingPackage.putString(WifiP2pManager.CALLING_PACKAGE,
+ mContext.getOpPackageName());
+ factoryReset(callingPackage, Process.SYSTEM_UID);
+ }
+
sendP2pConnectionChangedBroadcast();
initializeP2pSettings();
}
@@ -3514,6 +3538,64 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
return new WifiP2pDeviceList();
}
}
+
+ private void setPendingFactoryReset(boolean pending) {
+ if (mWifiInjector == null) {
+ mWifiInjector = WifiInjector.getInstance();
+ }
+ FrameworkFacade facade = mWifiInjector.getFrameworkFacade();
+ facade.setIntegerSetting(mContext,
+ Settings.Global.WIFI_P2P_PENDING_FACTORY_RESET,
+ pending ? 1 : 0);
+ }
+
+ private boolean isPendingFactoryReset() {
+ if (mWifiInjector == null) {
+ mWifiInjector = WifiInjector.getInstance();
+ }
+ FrameworkFacade facade = mWifiInjector.getFrameworkFacade();
+ int val = facade.getIntegerSetting(mContext,
+ Settings.Global.WIFI_P2P_PENDING_FACTORY_RESET,
+ 0);
+ return (val != 0);
+ }
+
+ /**
+ * Enforces permissions on the caller who is requesting factory reset.
+ * @param pkg Bundle containing the calling package string.
+ * @param uid The caller uid.
+ */
+ private boolean factoryReset(Bundle pkg, int uid) {
+ String pkgName = pkg.getString(WifiP2pManager.CALLING_PACKAGE);
+ if (mWifiInjector == null) {
+ mWifiInjector = WifiInjector.getInstance();
+ }
+ WifiPermissionsUtil wifiPermissionsUtil = mWifiInjector.getWifiPermissionsUtil();
+ UserManager userManager = mWifiInjector.getUserManager();
+
+ if (!wifiPermissionsUtil.checkNetworkSettingsPermission(uid)) return false;
+
+ if (userManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) return false;
+
+ if (userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_WIFI)) return false;
+
+ Log.i(TAG, "factoryReset uid=" + uid + " pkg=" + pkgName);
+
+ if (mNetworkInfo.isAvailable()) {
+ if (mWifiNative.p2pListNetworks(mGroups)) {
+ for (WifiP2pGroup group : mGroups.getGroupList()) {
+ mWifiNative.removeP2pNetwork(group.getNetworkId());
+ }
+ }
+ // reload will save native config and broadcast changed event.
+ updatePersistentNetworks(true);
+ setPendingFactoryReset(false);
+ } else {
+ setPendingFactoryReset(true);
+ }
+ return true;
+ }
+
}
/**