Merge "Revert "Revert "Add a new logger for StatsLog"""
diff --git a/res/values/strings.xml b/res/values/strings.xml
index e86917c..f30c63d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -10276,6 +10276,6 @@
<!-- UI debug setting: force desktop mode [CHAR LIMIT=50] -->
<string name="force_desktop_mode">Force desktop mode</string>
- <!-- UI debug setting: force desktop mode summary [CHAR LIMIT=150] -->
+ <!-- UI debug setting: force desktop mode summary [CHAR LIMIT=NONE] -->
<string name="force_desktop_mode_summary">Force experimental desktop mode on secondary displays</string>
</resources>
diff --git a/src/com/android/settings/ResetNetworkConfirm.java b/src/com/android/settings/ResetNetworkConfirm.java
index 2044af5..270f22b 100644
--- a/src/com/android/settings/ResetNetworkConfirm.java
+++ b/src/com/android/settings/ResetNetworkConfirm.java
@@ -26,6 +26,7 @@
import android.net.NetworkPolicyManager;
import android.net.Uri;
import android.net.wifi.WifiManager;
+import android.net.wifi.p2p.WifiP2pManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.RecoverySystem;
@@ -129,6 +130,8 @@
wifiManager.factoryReset();
}
+ p2pFactoryReset(context);
+
TelephonyManager telephonyManager = (TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager != null) {
@@ -180,6 +183,20 @@
}
}
+ @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.
*/
diff --git a/tests/robotests/src/com/android/settings/ResetNetworkConfirmTest.java b/tests/robotests/src/com/android/settings/ResetNetworkConfirmTest.java
index a10a4a4..6286cb9 100644
--- a/tests/robotests/src/com/android/settings/ResetNetworkConfirmTest.java
+++ b/tests/robotests/src/com/android/settings/ResetNetworkConfirmTest.java
@@ -24,6 +24,7 @@
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowRecoverySystem;
+import com.android.settings.testutils.shadow.ShadowWifiP2pManager;
import org.junit.After;
import org.junit.Before;
@@ -35,7 +36,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(shadows = {ShadowRecoverySystem.class})
+@Config(shadows = {ShadowRecoverySystem.class, ShadowWifiP2pManager.class})
public class ResetNetworkConfirmTest {
private Activity mActivity;
@@ -52,6 +53,7 @@
@After
public void tearDown() {
ShadowRecoverySystem.reset();
+ ShadowWifiP2pManager.reset();
}
@Test
@@ -76,4 +78,16 @@
assertThat(ShadowRecoverySystem.getWipeEuiccCalledCount())
.isEqualTo(0);
}
+
+ /**
+ * Test for WifiP2pManager factoryReset method.
+ */
+ @Test
+ public void testResetNetworkData_resetP2p() {
+
+ mResetNetworkConfirm.p2pFactoryReset(mActivity);
+
+ assertThat(ShadowWifiP2pManager.getFactoryResetCount())
+ .isEqualTo(1);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowWifiP2pManager.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowWifiP2pManager.java
new file mode 100644
index 0000000..8c38347
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowWifiP2pManager.java
@@ -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;
+ }
+}