1# Copyright (C) 2023 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# 15# Licensed under the Apache License, Version 2.0 (the "License"); 16# you may not use this file except in compliance with the License. 17# You may obtain a copy of the License at 18# 19# http://www.apache.org/licenses/LICENSE-2.0 20# 21# Unless required by applicable law or agreed to in writing, software 22# distributed under the License is distributed on an "AS IS" BASIS, 23# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 24# See the License for the specific language governing permissions and 25# limitations under the License. 26 27# Lint as: python3 28 29import dataclasses 30import enum 31from typing import Optional, Union 32 33WIFI_DIRECT_SNIPPET_PACKAGE_NAME = 'com.google.snippet.wifi.direct' 34 35ACTION_LISTENER_ON_SUCCESS = 'onSuccess' 36ACTION_LISTENER_ON_FAILURE = 'onFailure' 37ACTION_LISTENER_FAILURE_REASON = 'reason' 38 39EXTRA_WIFI_P2P_GROUP = 'p2pGroupInfo' 40EXTRA_WIFI_STATE = 'wifi_p2p_state' 41 42WIFI_P2P_CREATING_GROUP = 'CREATING_GROUP' 43WIFI_P2P_CONNECTION_CHANGED_ACTION = ( 44 'android.net.wifi.p2p.CONNECTION_STATE_CHANGE' 45) 46WIFI_P2P_DISCOVERY_CHANGED_ACTION = ( 47 'android.net.wifi.p2p.DISCOVERY_STATE_CHANGE' 48) 49WIFI_P2P_PEERS_CHANGED_ACTION = 'android.net.wifi.p2p.PEERS_CHANGED' 50WIFI_P2P_STATE_CHANGED_ACTION = 'android.net.wifi.p2p.STATE_CHANGED' 51WIFI_P2P_THIS_DEVICE_CHANGED_ACTION = 'android.net.wifi.p2p.THIS_DEVICE_CHANGED' 52 53 54@enum.unique 55class ActionListenerOnFailure(enum.IntEnum): 56 """Indicates the failure reason of the initiation of the action. 57 58 https://developer.android.com/reference/android/net/wifi/p2p/WifiP2pManager.ActionListener#onFailure(int) 59 """ 60 61 ERROR = 0 62 P2P_UNSUPPORTED = 1 63 BUSY = 2 64 65 66@enum.unique 67class Band(enum.IntEnum): 68 """Indicates the band of the operating frequency. 69 70 https://developer.android.com/reference/android/net/wifi/p2p/WifiP2pConfig#getGroupOwnerBand() 71 """ 72 73 GROUP_OWNER_BAND_AUTO = 0 74 GROUP_OWNER_BAND_2GHZ = 1 75 GROUP_OWNER_BAND_5GHZ = 2 76 77 78@enum.unique 79class IpProvisioningMode(enum.IntEnum): 80 """Indicates the IP provisioning mode. 81 82 https://developer.android.com/reference/android/net/wifi/p2p/WifiP2pConfig#getGroupClientIpProvisioningMode() 83 """ 84 85 GROUP_CLIENT_IP_PROVISIONING_MODE_IPV4_DHCP = 0 86 GROUP_CLIENT_IP_PROVISIONING_MODE_IPV6_LINK_LOCAL = 1 87 88 89@enum.unique 90class ExtraWifiState(enum.IntEnum): 91 """Indicates whether Wi-Fi p2p is enabled or disabled. 92 93 https://developer.android.com/reference/android/net/wifi/p2p/WifiP2pManager#EXTRA_WIFI_STATE 94 """ 95 96 WIFI_P2P_STATE_UNKNOWN = 0 97 WIFI_P2P_STATE_DISABLED = 1 98 WIFI_P2P_STATE_ENABLED = 2 99 100 101@dataclasses.dataclass(frozen=True) 102class WifiP2pConfig: 103 """Represents a Wi-Fi P2p configuration for setting up a connection. 104 105 https://developer.android.com/reference/android/net/wifi/p2p/WifiP2pConfig 106 """ 107 108 persistent_mode: Optional[bool] = None 109 device_address: Optional[str] = None 110 group_client_ip_provisioning_mode: Optional[IpProvisioningMode] = None 111 group_operating_band: Optional[Band] = None 112 group_operating_frequency: Optional[int] = None 113 network_name: Optional[str] = None 114 passphrase: Optional[str] = None 115 116 def to_dict(self) -> dict[str, Union[bool, int, str]]: 117 """Converts this WifiP2pConfig to a dictionary.""" 118 return { 119 k: v.value if isinstance(v, enum.Enum) else v 120 for k, v in self.__dict__.items() 121 if v is not None 122 } 123 124