Loading src/com/android/settings/ResetNetworkConfirm.java +17 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import android.net.ConnectivityManager; 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; Loading Loading @@ -129,6 +130,8 @@ public class ResetNetworkConfirm extends InstrumentedFragment { wifiManager.factoryReset(); } p2pFactoryReset(context); TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager != null) { Loading Loading @@ -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. */ Loading tests/robotests/src/com/android/settings/ResetNetworkConfirmTest.java +15 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.app.Activity; 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; Loading @@ -35,7 +36,7 @@ import org.robolectric.Robolectric; import org.robolectric.annotation.Config; @RunWith(SettingsRobolectricTestRunner.class) @Config(shadows = {ShadowRecoverySystem.class}) @Config(shadows = {ShadowRecoverySystem.class, ShadowWifiP2pManager.class}) public class ResetNetworkConfirmTest { private Activity mActivity; Loading @@ -52,6 +53,7 @@ public class ResetNetworkConfirmTest { @After public void tearDown() { ShadowRecoverySystem.reset(); ShadowWifiP2pManager.reset(); } @Test Loading @@ -76,4 +78,16 @@ public class ResetNetworkConfirmTest { assertThat(ShadowRecoverySystem.getWipeEuiccCalledCount()) .isEqualTo(0); } /** * Test for WifiP2pManager factoryReset method. */ @Test public void testResetNetworkData_resetP2p() { mResetNetworkConfirm.p2pFactoryReset(mActivity); assertThat(ShadowWifiP2pManager.getFactoryResetCount()) .isEqualTo(1); } } tests/robotests/src/com/android/settings/testutils/shadow/ShadowWifiP2pManager.java 0 → 100644 +61 −0 Original line number Diff line number Diff line /* * 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; } } Loading
src/com/android/settings/ResetNetworkConfirm.java +17 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import android.net.ConnectivityManager; 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; Loading Loading @@ -129,6 +130,8 @@ public class ResetNetworkConfirm extends InstrumentedFragment { wifiManager.factoryReset(); } p2pFactoryReset(context); TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager != null) { Loading Loading @@ -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. */ Loading
tests/robotests/src/com/android/settings/ResetNetworkConfirmTest.java +15 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.app.Activity; 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; Loading @@ -35,7 +36,7 @@ import org.robolectric.Robolectric; import org.robolectric.annotation.Config; @RunWith(SettingsRobolectricTestRunner.class) @Config(shadows = {ShadowRecoverySystem.class}) @Config(shadows = {ShadowRecoverySystem.class, ShadowWifiP2pManager.class}) public class ResetNetworkConfirmTest { private Activity mActivity; Loading @@ -52,6 +53,7 @@ public class ResetNetworkConfirmTest { @After public void tearDown() { ShadowRecoverySystem.reset(); ShadowWifiP2pManager.reset(); } @Test Loading @@ -76,4 +78,16 @@ public class ResetNetworkConfirmTest { assertThat(ShadowRecoverySystem.getWipeEuiccCalledCount()) .isEqualTo(0); } /** * Test for WifiP2pManager factoryReset method. */ @Test public void testResetNetworkData_resetP2p() { mResetNetworkConfirm.p2pFactoryReset(mActivity); assertThat(ShadowWifiP2pManager.getFactoryResetCount()) .isEqualTo(1); } }
tests/robotests/src/com/android/settings/testutils/shadow/ShadowWifiP2pManager.java 0 → 100644 +61 −0 Original line number Diff line number Diff line /* * 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; } }