PasspointManager.java revision eaa6ff2e246151fe8f42d7111541225ee0e3f346
1/* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.server.wifi.hotspot2; 18 19import static android.net.wifi.WifiManager.EXTRA_PASSPOINT_ICON_BSSID; 20import static android.net.wifi.WifiManager.EXTRA_PASSPOINT_ICON_DATA; 21import static android.net.wifi.WifiManager.EXTRA_PASSPOINT_ICON_FILE; 22import static android.net.wifi.WifiManager.EXTRA_PASSPOINT_WNM_BSSID; 23import static android.net.wifi.WifiManager.EXTRA_PASSPOINT_WNM_DELAY; 24import static android.net.wifi.WifiManager.EXTRA_PASSPOINT_WNM_ESS; 25import static android.net.wifi.WifiManager.EXTRA_PASSPOINT_WNM_METHOD; 26import static android.net.wifi.WifiManager.EXTRA_PASSPOINT_WNM_URL; 27import static android.net.wifi.WifiManager.PASSPOINT_ICON_RECEIVED_ACTION; 28import static android.net.wifi.WifiManager.PASSPOINT_WNM_FRAME_RECEIVED_ACTION; 29 30import android.content.Context; 31import android.content.Intent; 32import android.os.UserHandle; 33 34import com.android.server.wifi.WifiInjector; 35import com.android.server.wifi.anqp.ANQPElement; 36import com.android.server.wifi.anqp.Constants; 37 38import java.util.Map; 39 40/** 41 * Responsible for managing passpoint networks. 42 */ 43public class PasspointManager { 44 private final Context mContext; 45 private final PasspointEventHandler mHandler; 46 47 private class CallbackHandler implements PasspointEventHandler.Callbacks { 48 private final Context mContext; 49 CallbackHandler(Context context) { 50 mContext = context; 51 } 52 53 @Override 54 public void onANQPResponse(long bssid, 55 Map<Constants.ANQPElementType, ANQPElement> anqpElements) { 56 // TO BE IMPLEMENTED. 57 } 58 59 @Override 60 public void onIconResponse(long bssid, String fileName, byte[] data) { 61 Intent intent = new Intent(PASSPOINT_ICON_RECEIVED_ACTION); 62 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); 63 intent.putExtra(EXTRA_PASSPOINT_ICON_BSSID, bssid); 64 intent.putExtra(EXTRA_PASSPOINT_ICON_FILE, fileName); 65 if (data != null) { 66 intent.putExtra(EXTRA_PASSPOINT_ICON_DATA, data); 67 } 68 mContext.sendBroadcastAsUser(intent, UserHandle.ALL); 69 } 70 71 @Override 72 public void onWnmFrameReceived(WnmData event) { 73 // %012x HS20-SUBSCRIPTION-REMEDIATION "%u %s", osu_method, url 74 // %012x HS20-DEAUTH-IMMINENT-NOTICE "%u %u %s", code, reauth_delay, url 75 Intent intent = new Intent(PASSPOINT_WNM_FRAME_RECEIVED_ACTION); 76 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); 77 78 intent.putExtra(EXTRA_PASSPOINT_WNM_BSSID, event.getBssid()); 79 intent.putExtra(EXTRA_PASSPOINT_WNM_URL, event.getUrl()); 80 81 if (event.isDeauthEvent()) { 82 intent.putExtra(EXTRA_PASSPOINT_WNM_ESS, event.isEss()); 83 intent.putExtra(EXTRA_PASSPOINT_WNM_DELAY, event.getDelay()); 84 } else { 85 intent.putExtra(EXTRA_PASSPOINT_WNM_METHOD, event.getMethod()); 86 // TODO(zqiu): set the passpoint matching status with the respect to the 87 // current connected network (e.g. HomeProvider, RoamingProvider, None, 88 // Declined). 89 } 90 mContext.sendBroadcastAsUser(intent, UserHandle.ALL); 91 } 92 } 93 94 public PasspointManager(Context context, WifiInjector wifiInjector) { 95 mContext = context; 96 mHandler = wifiInjector.makePasspointEventHandler(new CallbackHandler(context)); 97 } 98 99 /** 100 * Notify the completion of an ANQP request. 101 * TODO(zqiu): currently the notification is done through WifiMonitor, 102 * will no longer be the case once we switch over to use wificond. 103 */ 104 public void notifyANQPDone(long bssid, boolean success) { 105 mHandler.notifyANQPDone(bssid, success); 106 } 107 108 /** 109 * Notify the completion of an icon request. 110 * TODO(zqiu): currently the notification is done through WifiMonitor, 111 * will no longer be the case once we switch over to use wificond. 112 */ 113 public void notifyIconDone(long bssid, IconEvent iconEvent) { 114 mHandler.notifyIconDone(bssid, iconEvent); 115 } 116 117 /** 118 * Notify the reception of a Wireless Network Management (WNM) frame. 119 * TODO(zqiu): currently the notification is done through WifiMonitor, 120 * will no longer be the case once we switch over to use wificond. 121 */ 122 public void receivedWnmFrame(WnmData data) { 123 mHandler.notifyWnmFrameReceived(data); 124 } 125 126 /** 127 * Request the specified icon file |fileName| from the specified AP |bssid|. 128 * @return true if the request is sent successfully, false otherwise 129 */ 130 public boolean queryPasspointIcon(long bssid, String fileName) { 131 return mHandler.requestIcon(bssid, fileName); 132 } 133} 134