Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c4240a7c authored by Jimmy Chen's avatar Jimmy Chen
Browse files

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: Id487ebf4564b78b613b550c0f0266effb0ae793e
parent 8d45688b
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -3815,6 +3815,14 @@ package android.net.wifi.aware {

}

package android.net.wifi.p2p {

  public class WifiP2pManager {
    method public void factoryReset(android.net.wifi.p2p.WifiP2pManager.Channel, android.net.wifi.p2p.WifiP2pManager.ActionListener);
  }

}

package android.net.wifi.rtt {

  public static final class RangingRequest.Builder {
+10 −0
Original line number Diff line number Diff line
@@ -4892,6 +4892,7 @@ public final class Settings {
            MOVED_TO_GLOBAL.add(Settings.Global.WIFI_NETWORK_SHOW_RSSI);
            MOVED_TO_GLOBAL.add(Settings.Global.WIFI_WATCHDOG_ON);
            MOVED_TO_GLOBAL.add(Settings.Global.WIFI_WATCHDOG_POOR_NETWORK_TEST_ENABLED);
            MOVED_TO_GLOBAL.add(Settings.Global.WIFI_P2P_PENDING_FACTORY_RESET);
            MOVED_TO_GLOBAL.add(Settings.Global.WIMAX_NETWORKS_AVAILABLE_NOTIFICATION_ON);
            MOVED_TO_GLOBAL.add(Settings.Global.PACKAGE_VERIFIER_ENABLE);
            MOVED_TO_GLOBAL.add(Settings.Global.PACKAGE_VERIFIER_TIMEOUT);
@@ -9983,6 +9984,15 @@ public final class Settings {
        public static final String WIFI_RTT_BACKGROUND_EXEC_GAP_MS =
                "wifi_rtt_background_exec_gap_ms";
        /**
         * Indicate whether factory reset request is pending.
         *
         * Type: int (0 for false, 1 for true)
         * @hide
         */
        public static final String WIFI_P2P_PENDING_FACTORY_RESET =
                "wifi_p2p_pending_factory_reset";
        /**
         * Whether soft AP will shut down after a timeout period when no devices are connected.
         *
+1 −0
Original line number Diff line number Diff line
@@ -494,6 +494,7 @@ public class SettingsBackupTest {
                    Settings.Global.WIFI_NUM_OPEN_NETWORKS_KEPT,
                    Settings.Global.WIFI_ON,
                    Settings.Global.WIFI_P2P_DEVICE_NAME,
                    Settings.Global.WIFI_P2P_PENDING_FACTORY_RESET,
                    Settings.Global.WIFI_REENABLE_DELAY_MS,
                    Settings.Global.WIFI_RTT_BACKGROUND_EXEC_GAP_MS,
                    Settings.Global.WIFI_SAVED_STATE,
+30 −1
Original line number Diff line number Diff line
@@ -16,9 +16,13 @@

package android.net.wifi.p2p;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SystemService;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.net.wifi.WpsInfo;
@@ -480,6 +484,12 @@ public class WifiP2pManager {
    /** @hide */
    public static final int REPORT_NFC_HANDOVER_FAILED              = BASE + 81;

    /** @hide */
    public static final int FACTORY_RESET                           = BASE + 82;
    /** @hide */
    public static final int FACTORY_RESET_FAILED                    = BASE + 83;
    /** @hide */
    public static final int FACTORY_RESET_SUCCEEDED                 = BASE + 84;

    /**
     * Create a new WifiP2pManager instance. Applications use
@@ -776,6 +786,7 @@ public class WifiP2pManager {
                    case STOP_LISTEN_FAILED:
                    case SET_CHANNEL_FAILED:
                    case REPORT_NFC_HANDOVER_FAILED:
                    case FACTORY_RESET_FAILED:
                        if (listener != null) {
                            ((ActionListener) listener).onFailure(message.arg1);
                        }
@@ -802,6 +813,7 @@ public class WifiP2pManager {
                    case STOP_LISTEN_SUCCEEDED:
                    case SET_CHANNEL_SUCCEEDED:
                    case REPORT_NFC_HANDOVER_SUCCEEDED:
                    case FACTORY_RESET_SUCCEEDED:
                        if (listener != null) {
                            ((ActionListener) listener).onSuccess();
                        }
@@ -1521,4 +1533,21 @@ public class WifiP2pManager {
        c.mAsyncChannel.sendMessage(RESPONDER_REPORT_NFC_HANDOVER, 0,
                c.putListener(listener), bundle);
    }

    /**
     * Removes all saved p2p groups.
     * @param c is the channel created at {@link #initialize}.
     * @param listener for callback on success or failure. Can be null.
     * @hide
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS)
    public void factoryReset(@NonNull Channel c, @Nullable ActionListener listener) {
        checkChannel(c);
        Bundle callingPackage = new Bundle();
        callingPackage.putString(CALLING_PACKAGE, c.mContext.getOpPackageName());
        c.mAsyncChannel.sendMessage(FACTORY_RESET, 0, c.putListener(listener),
                callingPackage);
    }

}