p2p: do P2P factory reset for Network Reset
Bug: 109866998 Test: * 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: RobotTest - make ROBOTEST_FILTER=ResetNetworkConfirmTest Change-Id: If5292e34cb9702d4319a4c9bbd867e0e5ed716a2
This commit is contained in:
@@ -26,6 +26,7 @@ import android.net.ConnectivityManager;
|
|||||||
import android.net.NetworkPolicyManager;
|
import android.net.NetworkPolicyManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.net.wifi.p2p.WifiP2pManager;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.RecoverySystem;
|
import android.os.RecoverySystem;
|
||||||
@@ -129,6 +130,8 @@ public class ResetNetworkConfirm extends InstrumentedFragment {
|
|||||||
wifiManager.factoryReset();
|
wifiManager.factoryReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p2pFactoryReset(context);
|
||||||
|
|
||||||
TelephonyManager telephonyManager = (TelephonyManager)
|
TelephonyManager telephonyManager = (TelephonyManager)
|
||||||
context.getSystemService(Context.TELEPHONY_SERVICE);
|
context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
if (telephonyManager != null) {
|
if (telephonyManager != null) {
|
||||||
@@ -180,6 +183,20 @@ public class ResetNetworkConfirm extends InstrumentedFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void p2pFactoryReset(Context context) {
|
||||||
|
WifiP2pManager wifiP2pManager = (WifiP2pManager)
|
||||||
|
context.getSystemService(Context.WIFI_P2P_SERVICE);
|
||||||
|
if (wifiP2pManager != null) {
|
||||||
|
WifiP2pManager.Channel channel = wifiP2pManager.initialize(
|
||||||
|
context.getApplicationContext(), context.getMainLooper(),
|
||||||
|
null /* listener */);
|
||||||
|
if (channel != null) {
|
||||||
|
wifiP2pManager.factoryReset(channel, null /* listener */);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restore APN settings to default.
|
* Restore APN settings to default.
|
||||||
*/
|
*/
|
||||||
|
@@ -24,6 +24,7 @@ import android.app.Activity;
|
|||||||
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.testutils.shadow.ShadowRecoverySystem;
|
import com.android.settings.testutils.shadow.ShadowRecoverySystem;
|
||||||
|
import com.android.settings.testutils.shadow.ShadowWifiP2pManager;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -35,7 +36,7 @@ import org.robolectric.Robolectric;
|
|||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(shadows = {ShadowRecoverySystem.class})
|
@Config(shadows = {ShadowRecoverySystem.class, ShadowWifiP2pManager.class})
|
||||||
public class ResetNetworkConfirmTest {
|
public class ResetNetworkConfirmTest {
|
||||||
|
|
||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
@@ -52,6 +53,7 @@ public class ResetNetworkConfirmTest {
|
|||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
ShadowRecoverySystem.reset();
|
ShadowRecoverySystem.reset();
|
||||||
|
ShadowWifiP2pManager.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -76,4 +78,16 @@ public class ResetNetworkConfirmTest {
|
|||||||
assertThat(ShadowRecoverySystem.getWipeEuiccCalledCount())
|
assertThat(ShadowRecoverySystem.getWipeEuiccCalledCount())
|
||||||
.isEqualTo(0);
|
.isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for WifiP2pManager factoryReset method.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testResetNetworkData_resetP2p() {
|
||||||
|
|
||||||
|
mResetNetworkConfirm.p2pFactoryReset(mActivity);
|
||||||
|
|
||||||
|
assertThat(ShadowWifiP2pManager.getFactoryResetCount())
|
||||||
|
.isEqualTo(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.testutils.shadow;
|
||||||
|
|
||||||
|
import android.net.wifi.p2p.WifiP2pManager;
|
||||||
|
|
||||||
|
import org.robolectric.annotation.Implementation;
|
||||||
|
import org.robolectric.annotation.Implements;
|
||||||
|
import org.robolectric.annotation.Resetter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shadown class for WifiP2pManager.
|
||||||
|
*/
|
||||||
|
@Implements(value = WifiP2pManager.class)
|
||||||
|
public class ShadowWifiP2pManager extends org.robolectric.shadows.ShadowWifiP2pManager {
|
||||||
|
|
||||||
|
private static int sFactoryResetCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* factoryReset mock method.
|
||||||
|
*/
|
||||||
|
@Implementation
|
||||||
|
public void factoryReset(WifiP2pManager.Channel c, WifiP2pManager.ActionListener listener) {
|
||||||
|
if (c != null) {
|
||||||
|
sFactoryResetCount++;
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("channel must be non-null.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset variables in shadow class.
|
||||||
|
*/
|
||||||
|
@Resetter
|
||||||
|
public static void reset() {
|
||||||
|
sFactoryResetCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the count of factoryReset called.
|
||||||
|
*
|
||||||
|
* @return the count of factoryReset called.
|
||||||
|
*/
|
||||||
|
public static int getFactoryResetCount() {
|
||||||
|
return sFactoryResetCount;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user