AccessPoint.java revision 9ee9b39eb4582f0e53b4f40738949c20e28630d4
1/*
2 * Copyright (C) 2015 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.settingslib.wifi;
18
19import android.annotation.IntDef;
20import android.annotation.Nullable;
21import android.app.AppGlobals;
22import android.content.Context;
23import android.content.pm.ApplicationInfo;
24import android.content.pm.IPackageManager;
25import android.content.pm.PackageManager;
26import android.net.ConnectivityManager;
27import android.net.NetworkCapabilities;
28import android.net.NetworkInfo;
29import android.net.NetworkInfo.DetailedState;
30import android.net.NetworkInfo.State;
31import android.net.NetworkKey;
32import android.net.NetworkScoreManager;
33import android.net.NetworkScorerAppData;
34import android.net.ScoredNetwork;
35import android.net.WifiKey;
36import android.net.wifi.IWifiManager;
37import android.net.wifi.ScanResult;
38import android.net.wifi.WifiConfiguration;
39import android.net.wifi.WifiConfiguration.KeyMgmt;
40import android.net.wifi.WifiEnterpriseConfig;
41import android.net.wifi.WifiInfo;
42import android.net.wifi.WifiManager;
43import android.net.wifi.WifiNetworkScoreCache;
44import android.net.wifi.hotspot2.PasspointConfiguration;
45import android.os.Bundle;
46import android.os.RemoteException;
47import android.os.ServiceManager;
48import android.os.SystemClock;
49import android.os.UserHandle;
50import android.support.annotation.NonNull;
51import android.text.Spannable;
52import android.text.SpannableString;
53import android.text.TextUtils;
54import android.text.style.TtsSpan;
55import android.util.Log;
56
57import com.android.internal.annotations.VisibleForTesting;
58import com.android.settingslib.R;
59
60import java.lang.annotation.Retention;
61import java.lang.annotation.RetentionPolicy;
62import java.util.ArrayList;
63import java.util.HashMap;
64import java.util.Iterator;
65import java.util.Map;
66import java.util.Objects;
67import java.util.concurrent.ConcurrentHashMap;
68import java.util.concurrent.atomic.AtomicInteger;
69
70
71public class AccessPoint implements Comparable<AccessPoint> {
72    static final String TAG = "SettingsLib.AccessPoint";
73
74    /**
75     * Lower bound on the 2.4 GHz (802.11b/g/n) WLAN channels
76     */
77    public static final int LOWER_FREQ_24GHZ = 2400;
78
79    /**
80     * Upper bound on the 2.4 GHz (802.11b/g/n) WLAN channels
81     */
82    public static final int HIGHER_FREQ_24GHZ = 2500;
83
84    /**
85     * Lower bound on the 5.0 GHz (802.11a/h/j/n/ac) WLAN channels
86     */
87    public static final int LOWER_FREQ_5GHZ = 4900;
88
89    /**
90     * Upper bound on the 5.0 GHz (802.11a/h/j/n/ac) WLAN channels
91     */
92    public static final int HIGHER_FREQ_5GHZ = 5900;
93
94    @IntDef({Speed.NONE, Speed.SLOW, Speed.MODERATE, Speed.FAST, Speed.VERY_FAST})
95    @Retention(RetentionPolicy.SOURCE)
96    public @interface Speed {
97        /**
98         * Constant value representing an unlabeled / unscored network.
99         */
100        int NONE = 0;
101        /**
102         * Constant value representing a slow speed network connection.
103         */
104        int SLOW = 5;
105        /**
106         * Constant value representing a medium speed network connection.
107         */
108        int MODERATE = 10;
109        /**
110         * Constant value representing a fast speed network connection.
111         */
112        int FAST = 20;
113        /**
114         * Constant value representing a very fast speed network connection.
115         */
116        int VERY_FAST = 30;
117    }
118
119    /**
120     * Experimental: we should be able to show the user the list of BSSIDs and bands
121     *  for that SSID.
122     *  For now this data is used only with Verbose Logging so as to show the band and number
123     *  of BSSIDs on which that network is seen.
124     */
125    private final ConcurrentHashMap<String, ScanResult> mScanResultCache =
126            new ConcurrentHashMap<String, ScanResult>(32);
127
128    /**
129     * Map of BSSIDs to scored networks for individual bssids.
130     *
131     * <p>This cache should not be evicted with scan results, as the values here are used to
132     * generate a fallback in the absence of scores for the visible APs.
133     */
134    private final Map<String, TimestampedScoredNetwork> mScoredNetworkCache = new HashMap<>();
135
136    /** Maximum age of scan results to hold onto while actively scanning. **/
137    private static final long MAX_SCAN_RESULT_AGE_MILLIS = 25000;
138
139    static final String KEY_NETWORKINFO = "key_networkinfo";
140    static final String KEY_WIFIINFO = "key_wifiinfo";
141    static final String KEY_SCANRESULT = "key_scanresult";
142    static final String KEY_SSID = "key_ssid";
143    static final String KEY_SECURITY = "key_security";
144    static final String KEY_SPEED = "key_speed";
145    static final String KEY_PSKTYPE = "key_psktype";
146    static final String KEY_SCANRESULTCACHE = "key_scanresultcache";
147    static final String KEY_SCOREDNETWORKCACHE = "key_scorednetworkcache";
148    static final String KEY_CONFIG = "key_config";
149    static final String KEY_FQDN = "key_fqdn";
150    static final String KEY_PROVIDER_FRIENDLY_NAME = "key_provider_friendly_name";
151    static final String KEY_IS_CARRIER_AP = "key_is_carrier_ap";
152    static final String KEY_CARRIER_AP_EAP_TYPE = "key_carrier_ap_eap_type";
153    static final String KEY_CARRIER_NAME = "key_carrier_name";
154    static final AtomicInteger sLastId = new AtomicInteger(0);
155
156    /**
157     * These values are matched in string arrays -- changes must be kept in sync
158     */
159    public static final int SECURITY_NONE = 0;
160    public static final int SECURITY_WEP = 1;
161    public static final int SECURITY_PSK = 2;
162    public static final int SECURITY_EAP = 3;
163
164    private static final int PSK_UNKNOWN = 0;
165    private static final int PSK_WPA = 1;
166    private static final int PSK_WPA2 = 2;
167    private static final int PSK_WPA_WPA2 = 3;
168
169    /**
170     * The number of distinct wifi levels.
171     *
172     * <p>Must keep in sync with {@link R.array.wifi_signal} and {@link WifiManager#RSSI_LEVELS}.
173     */
174    public static final int SIGNAL_LEVELS = 5;
175
176    public static final int UNREACHABLE_RSSI = Integer.MIN_VALUE;
177
178    private final Context mContext;
179
180    private String ssid;
181    private String bssid;
182    private int security;
183    private int networkId = WifiConfiguration.INVALID_NETWORK_ID;
184
185    private int pskType = PSK_UNKNOWN;
186
187    private WifiConfiguration mConfig;
188
189    private int mRssi = UNREACHABLE_RSSI;
190
191    private WifiInfo mInfo;
192    private NetworkInfo mNetworkInfo;
193    AccessPointListener mAccessPointListener;
194
195    private Object mTag;
196
197    @Speed private int mSpeed = Speed.NONE;
198    private boolean mIsScoredNetworkMetered = false;
199
200    // used to co-relate internal vs returned accesspoint.
201    int mId;
202
203    /**
204     * Information associated with the {@link PasspointConfiguration}.  Only maintaining
205     * the relevant info to preserve spaces.
206     */
207    private String mFqdn;
208    private String mProviderFriendlyName;
209
210    private boolean mIsCarrierAp = false;
211    /**
212     * The EAP type {@link WifiEnterpriseConfig.Eap} associated with this AP if it is a carrier AP.
213     */
214    private int mCarrierApEapType = WifiEnterpriseConfig.Eap.NONE;
215    private String mCarrierName = null;
216
217    public AccessPoint(Context context, Bundle savedState) {
218        mContext = context;
219        mConfig = savedState.getParcelable(KEY_CONFIG);
220        if (mConfig != null) {
221            loadConfig(mConfig);
222        }
223        if (savedState.containsKey(KEY_SSID)) {
224            ssid = savedState.getString(KEY_SSID);
225        }
226        if (savedState.containsKey(KEY_SECURITY)) {
227            security = savedState.getInt(KEY_SECURITY);
228        }
229        if (savedState.containsKey(KEY_SPEED)) {
230            mSpeed = savedState.getInt(KEY_SPEED);
231        }
232        if (savedState.containsKey(KEY_PSKTYPE)) {
233            pskType = savedState.getInt(KEY_PSKTYPE);
234        }
235        mInfo = savedState.getParcelable(KEY_WIFIINFO);
236        if (savedState.containsKey(KEY_NETWORKINFO)) {
237            mNetworkInfo = savedState.getParcelable(KEY_NETWORKINFO);
238        }
239        if (savedState.containsKey(KEY_SCANRESULTCACHE)) {
240            ArrayList<ScanResult> scanResultArrayList =
241                    savedState.getParcelableArrayList(KEY_SCANRESULTCACHE);
242            mScanResultCache.clear();
243            for (ScanResult result : scanResultArrayList) {
244                mScanResultCache.put(result.BSSID, result);
245            }
246        }
247        if (savedState.containsKey(KEY_SCOREDNETWORKCACHE)) {
248            ArrayList<TimestampedScoredNetwork> scoredNetworkArrayList =
249                    savedState.getParcelableArrayList(KEY_SCOREDNETWORKCACHE);
250            for (TimestampedScoredNetwork timedScore : scoredNetworkArrayList) {
251                mScoredNetworkCache.put(timedScore.getScore().networkKey.wifiKey.bssid, timedScore);
252            }
253        }
254        if (savedState.containsKey(KEY_FQDN)) {
255            mFqdn = savedState.getString(KEY_FQDN);
256        }
257        if (savedState.containsKey(KEY_PROVIDER_FRIENDLY_NAME)) {
258            mProviderFriendlyName = savedState.getString(KEY_PROVIDER_FRIENDLY_NAME);
259        }
260        if (savedState.containsKey(KEY_IS_CARRIER_AP)) {
261            mIsCarrierAp = savedState.getBoolean(KEY_IS_CARRIER_AP);
262        }
263        if (savedState.containsKey(KEY_CARRIER_AP_EAP_TYPE)) {
264            mCarrierApEapType = savedState.getInt(KEY_CARRIER_AP_EAP_TYPE);
265        }
266        if (savedState.containsKey(KEY_CARRIER_NAME)) {
267            mCarrierName = savedState.getString(KEY_CARRIER_NAME);
268        }
269        update(mConfig, mInfo, mNetworkInfo);
270
271        // Do not evict old scan results on initial creation
272        updateRssi();
273        mId = sLastId.incrementAndGet();
274    }
275
276    public AccessPoint(Context context, WifiConfiguration config) {
277        mContext = context;
278        loadConfig(config);
279        mId = sLastId.incrementAndGet();
280    }
281
282    /**
283     * Initialize an AccessPoint object for a {@link PasspointConfiguration}.  This is mainly
284     * used by "Saved Networks" page for managing the saved {@link PasspointConfiguration}.
285     */
286    public AccessPoint(Context context, PasspointConfiguration config) {
287        mContext = context;
288        mFqdn = config.getHomeSp().getFqdn();
289        mProviderFriendlyName = config.getHomeSp().getFriendlyName();
290        mId = sLastId.incrementAndGet();
291    }
292
293    AccessPoint(Context context, AccessPoint other) {
294        mContext = context;
295        copyFrom(other);
296    }
297
298    AccessPoint(Context context, ScanResult result) {
299        mContext = context;
300        initWithScanResult(result);
301        mId = sLastId.incrementAndGet();
302    }
303
304    /**
305     * Copy accesspoint information. NOTE: We do not copy tag information because that is never
306     * set on the internal copy.
307     * @param that
308     */
309    void copyFrom(AccessPoint that) {
310        that.evictOldScanResults();
311        this.ssid = that.ssid;
312        this.bssid = that.bssid;
313        this.security = that.security;
314        this.networkId = that.networkId;
315        this.pskType = that.pskType;
316        this.mConfig = that.mConfig; //TODO: Watch out, this object is mutated.
317        this.mRssi = that.mRssi;
318        this.mInfo = that.mInfo;
319        this.mNetworkInfo = that.mNetworkInfo;
320        this.mScanResultCache.clear();
321        this.mScanResultCache.putAll(that.mScanResultCache);
322        this.mScoredNetworkCache.clear();
323        this.mScoredNetworkCache.putAll(that.mScoredNetworkCache);
324        this.mId = that.mId;
325        this.mSpeed = that.mSpeed;
326        this.mIsScoredNetworkMetered = that.mIsScoredNetworkMetered;
327        this.mIsCarrierAp = that.mIsCarrierAp;
328        this.mCarrierApEapType = that.mCarrierApEapType;
329        this.mCarrierName = that.mCarrierName;
330    }
331
332    /**
333    * Returns a negative integer, zero, or a positive integer if this AccessPoint is less than,
334    * equal to, or greater than the other AccessPoint.
335    *
336    * Sort order rules for AccessPoints:
337    *   1. Active before inactive
338    *   2. Reachable before unreachable
339    *   3. Saved before unsaved
340    *   4. Network speed value
341    *   5. Stronger signal before weaker signal
342    *   6. SSID alphabetically
343    *
344    * Note that AccessPoints with a signal are usually also Reachable,
345    * and will thus appear before unreachable saved AccessPoints.
346    */
347    @Override
348    public int compareTo(@NonNull AccessPoint other) {
349        // Active one goes first.
350        if (isActive() && !other.isActive()) return -1;
351        if (!isActive() && other.isActive()) return 1;
352
353        // Reachable one goes before unreachable one.
354        if (isReachable() && !other.isReachable()) return -1;
355        if (!isReachable() && other.isReachable()) return 1;
356
357        // Configured (saved) one goes before unconfigured one.
358        if (isSaved() && !other.isSaved()) return -1;
359        if (!isSaved() && other.isSaved()) return 1;
360
361        // Faster speeds go before slower speeds - but only if visible change in speed label
362        if (getSpeed() != other.getSpeed()) {
363            return other.getSpeed() - getSpeed();
364        }
365
366        // Sort by signal strength, bucketed by level
367        int difference = WifiManager.calculateSignalLevel(other.mRssi, SIGNAL_LEVELS)
368                - WifiManager.calculateSignalLevel(mRssi, SIGNAL_LEVELS);
369        if (difference != 0) {
370            return difference;
371        }
372
373        // Sort by ssid.
374        difference = getSsidStr().compareToIgnoreCase(other.getSsidStr());
375        if (difference != 0) {
376            return difference;
377        }
378
379        // Do a case sensitive comparison to distinguish SSIDs that differ in case only
380        return getSsidStr().compareTo(other.getSsidStr());
381    }
382
383    @Override
384    public boolean equals(Object other) {
385        if (!(other instanceof AccessPoint)) return false;
386        return (this.compareTo((AccessPoint) other) == 0);
387    }
388
389    @Override
390    public int hashCode() {
391        int result = 0;
392        if (mInfo != null) result += 13 * mInfo.hashCode();
393        result += 19 * mRssi;
394        result += 23 * networkId;
395        result += 29 * ssid.hashCode();
396        return result;
397    }
398
399    @Override
400    public String toString() {
401        StringBuilder builder = new StringBuilder().append("AccessPoint(")
402                .append(ssid);
403        if (bssid != null) {
404            builder.append(":").append(bssid);
405        }
406        if (isSaved()) {
407            builder.append(',').append("saved");
408        }
409        if (isActive()) {
410            builder.append(',').append("active");
411        }
412        if (isEphemeral()) {
413            builder.append(',').append("ephemeral");
414        }
415        if (isConnectable()) {
416            builder.append(',').append("connectable");
417        }
418        if (security != SECURITY_NONE) {
419            builder.append(',').append(securityToString(security, pskType));
420        }
421        builder.append(",level=").append(getLevel());
422        if (mSpeed != Speed.NONE) {
423            builder.append(",speed=").append(mSpeed);
424        }
425        builder.append(",metered=").append(isMetered());
426
427        if (WifiTracker.sVerboseLogging) {
428            builder.append(",rssi=").append(mRssi);
429            builder.append(",scan cache size=").append(mScanResultCache.size());
430        }
431
432        return builder.append(')').toString();
433    }
434
435    /**
436     * Updates the AccessPoint rankingScore, metering, and speed, returning true if the data has
437     * changed.
438     *
439     * @param scoreCache The score cache to use to retrieve scores
440     * @param scoringUiEnabled Whether to show scoring and badging UI
441     * @param maxScoreCacheAgeMillis the maximum age in milliseconds of scores to consider when
442     *         generating speed labels
443     */
444    boolean update(
445            WifiNetworkScoreCache scoreCache,
446            boolean scoringUiEnabled,
447            long maxScoreCacheAgeMillis) {
448        boolean scoreChanged = false;
449        if (scoringUiEnabled) {
450            scoreChanged = updateScores(scoreCache, maxScoreCacheAgeMillis);
451        }
452        return updateMetered(scoreCache) || scoreChanged;
453    }
454
455    /**
456     * Updates the AccessPoint rankingScore and speed, returning true if the data has changed.
457     *
458     * <p>Any cached {@link TimestampedScoredNetwork} objects older than the given max age in millis
459     * will be removed when this method is invoked.
460     *
461     * <p>Precondition: {@link #mRssi} is up to date before invoking this method.
462     *
463     * @param scoreCache The score cache to use to retrieve scores
464     * @param maxScoreCacheAgeMillis the maximum age in milliseconds of scores to consider when
465     *         generating speed labels
466     *
467     * @return true if the set speed has changed
468     */
469    private boolean updateScores(WifiNetworkScoreCache scoreCache, long maxScoreCacheAgeMillis) {
470        long nowMillis = SystemClock.elapsedRealtime();
471        for (ScanResult result : mScanResultCache.values()) {
472            ScoredNetwork score = scoreCache.getScoredNetwork(result);
473            if (score == null) {
474                continue;
475            }
476            TimestampedScoredNetwork timedScore = mScoredNetworkCache.get(result.BSSID);
477            if (timedScore == null) {
478                mScoredNetworkCache.put(
479                        result.BSSID, new TimestampedScoredNetwork(score, nowMillis));
480            } else {
481                // Update data since the has been seen in the score cache
482                timedScore.update(score, nowMillis);
483            }
484        }
485
486        // Remove old cached networks
487        long evictionCutoff = nowMillis - maxScoreCacheAgeMillis;
488        Iterator<TimestampedScoredNetwork> iterator = mScoredNetworkCache.values().iterator();
489        iterator.forEachRemaining(timestampedScoredNetwork -> {
490            if (timestampedScoredNetwork.getUpdatedTimestampMillis() < evictionCutoff) {
491                iterator.remove();
492            }
493        });
494
495        return updateSpeed();
496    }
497
498    /**
499     * Updates the internal speed, returning true if the update resulted in a speed label change.
500     */
501    private boolean updateSpeed() {
502        int oldSpeed = mSpeed;
503        mSpeed = generateAverageSpeedForSsid();
504
505        boolean changed = oldSpeed != mSpeed;
506        if(WifiTracker.sVerboseLogging && changed) {
507            Log.i(TAG, String.format("%s: Set speed to %d", ssid, mSpeed));
508        }
509        return changed;
510    }
511
512    /** Creates a speed value for the current {@link #mRssi} by averaging all non zero badges. */
513    @Speed private int generateAverageSpeedForSsid() {
514        if (mScoredNetworkCache.isEmpty()) {
515            return Speed.NONE;
516        }
517
518        if (Log.isLoggable(TAG, Log.DEBUG)) {
519            Log.d(TAG, String.format("Generating fallbackspeed for %s using cache: %s",
520                    getSsidStr(), mScoredNetworkCache));
521        }
522
523        // TODO(b/63073866): If flickering issues persist, consider mapping using getLevel rather
524        // than specific rssi value so score doesn't change without a visible wifi bar change. This
525        // issue is likely to be more evident for the active AP whose RSSI value is not half-lifed.
526
527        int count = 0;
528        int totalSpeed = 0;
529        for (TimestampedScoredNetwork timedScore : mScoredNetworkCache.values()) {
530            int speed = timedScore.getScore().calculateBadge(mRssi);
531            if (speed != Speed.NONE) {
532                count++;
533                totalSpeed += speed;
534            }
535        }
536        int speed = count == 0 ? Speed.NONE : totalSpeed / count;
537        if (WifiTracker.sVerboseLogging) {
538            Log.i(TAG, String.format("%s generated fallback speed is: %d", getSsidStr(), speed));
539        }
540        return roundToClosestSpeedEnum(speed);
541    }
542
543    /**
544     * Updates the AccessPoint's metering based on {@link ScoredNetwork#meteredHint}, returning
545     * true if the metering changed.
546     */
547    private boolean updateMetered(WifiNetworkScoreCache scoreCache) {
548        boolean oldMetering = mIsScoredNetworkMetered;
549        mIsScoredNetworkMetered = false;
550
551        if (isActive() && mInfo != null) {
552            NetworkKey key = NetworkKey.createFromWifiInfo(mInfo);
553            ScoredNetwork score = scoreCache.getScoredNetwork(key);
554            if (score != null) {
555                mIsScoredNetworkMetered |= score.meteredHint;
556            }
557        } else {
558            for (ScanResult result : mScanResultCache.values()) {
559                ScoredNetwork score = scoreCache.getScoredNetwork(result);
560                if (score == null) {
561                    continue;
562                }
563                mIsScoredNetworkMetered |= score.meteredHint;
564            }
565        }
566        return oldMetering == mIsScoredNetworkMetered;
567    }
568
569    private void evictOldScanResults() {
570        long nowMs = SystemClock.elapsedRealtime();
571        for (Iterator<ScanResult> iter = mScanResultCache.values().iterator(); iter.hasNext(); ) {
572            ScanResult result = iter.next();
573            // result timestamp is in microseconds
574            if (nowMs - result.timestamp / 1000 > MAX_SCAN_RESULT_AGE_MILLIS) {
575                iter.remove();
576            }
577        }
578    }
579
580    public boolean matches(ScanResult result) {
581        return ssid.equals(result.SSID) && security == getSecurity(result);
582    }
583
584    public boolean matches(WifiConfiguration config) {
585        if (config.isPasspoint() && mConfig != null && mConfig.isPasspoint()) {
586            return ssid.equals(removeDoubleQuotes(config.SSID)) && config.FQDN.equals(mConfig.FQDN);
587        } else {
588            return ssid.equals(removeDoubleQuotes(config.SSID))
589                    && security == getSecurity(config)
590                    && (mConfig == null || mConfig.shared == config.shared);
591        }
592    }
593
594    public WifiConfiguration getConfig() {
595        return mConfig;
596    }
597
598    public String getPasspointFqdn() {
599        return mFqdn;
600    }
601
602    public void clearConfig() {
603        mConfig = null;
604        networkId = WifiConfiguration.INVALID_NETWORK_ID;
605    }
606
607    public WifiInfo getInfo() {
608        return mInfo;
609    }
610
611    /**
612     * Returns the number of levels to show for a Wifi icon, from 0 to {@link #SIGNAL_LEVELS}-1.
613     *
614     * <p>Use {@#isReachable()} to determine if an AccessPoint is in range, as this method will
615     * always return at least 0.
616     */
617    public int getLevel() {
618        return WifiManager.calculateSignalLevel(mRssi, SIGNAL_LEVELS);
619    }
620
621    public int getRssi() {
622        return mRssi;
623    }
624
625    public ConcurrentHashMap<String, ScanResult> getScanResults() {
626        return mScanResultCache;
627    }
628
629    public Map<String, TimestampedScoredNetwork> getScoredNetworkCache() {
630        return mScoredNetworkCache;
631    }
632
633    /**
634     * Updates {@link #mRssi}.
635     *
636     * <p>If the given connection is active, the existing value of {@link #mRssi} will be returned.
637     * If the given AccessPoint is not active, a value will be calculated from previous scan
638     * results, returning the best RSSI for all matching AccessPoints averaged with the previous
639     * value. If the access point is not connected and there are no scan results, the rssi will be
640     * set to {@link #UNREACHABLE_RSSI}.
641     */
642    private void updateRssi() {
643        if (this.isActive()) {
644            return;
645        }
646
647        int rssi = UNREACHABLE_RSSI;
648        for (ScanResult result : mScanResultCache.values()) {
649            if (result.level > rssi) {
650                rssi = result.level;
651            }
652        }
653
654        if (rssi != UNREACHABLE_RSSI && mRssi != UNREACHABLE_RSSI) {
655            mRssi = (mRssi + rssi) / 2; // half-life previous value
656        } else {
657            mRssi = rssi;
658        }
659    }
660
661    /**
662     * Returns if the network should be considered metered.
663     */
664    public boolean isMetered() {
665        return mIsScoredNetworkMetered
666                || WifiConfiguration.isMetered(mConfig, mInfo);
667    }
668
669    public NetworkInfo getNetworkInfo() {
670        return mNetworkInfo;
671    }
672
673    public int getSecurity() {
674        return security;
675    }
676
677    public String getSecurityString(boolean concise) {
678        Context context = mContext;
679        if (isPasspoint() || isPasspointConfig()) {
680            return concise ? context.getString(R.string.wifi_security_short_eap) :
681                context.getString(R.string.wifi_security_eap);
682        }
683        switch(security) {
684            case SECURITY_EAP:
685                return concise ? context.getString(R.string.wifi_security_short_eap) :
686                    context.getString(R.string.wifi_security_eap);
687            case SECURITY_PSK:
688                switch (pskType) {
689                    case PSK_WPA:
690                        return concise ? context.getString(R.string.wifi_security_short_wpa) :
691                            context.getString(R.string.wifi_security_wpa);
692                    case PSK_WPA2:
693                        return concise ? context.getString(R.string.wifi_security_short_wpa2) :
694                            context.getString(R.string.wifi_security_wpa2);
695                    case PSK_WPA_WPA2:
696                        return concise ? context.getString(R.string.wifi_security_short_wpa_wpa2) :
697                            context.getString(R.string.wifi_security_wpa_wpa2);
698                    case PSK_UNKNOWN:
699                    default:
700                        return concise ? context.getString(R.string.wifi_security_short_psk_generic)
701                                : context.getString(R.string.wifi_security_psk_generic);
702                }
703            case SECURITY_WEP:
704                return concise ? context.getString(R.string.wifi_security_short_wep) :
705                    context.getString(R.string.wifi_security_wep);
706            case SECURITY_NONE:
707            default:
708                return concise ? "" : context.getString(R.string.wifi_security_none);
709        }
710    }
711
712    public String getSsidStr() {
713        return ssid;
714    }
715
716    public String getBssid() {
717        return bssid;
718    }
719
720    public CharSequence getSsid() {
721        final SpannableString str = new SpannableString(ssid);
722        str.setSpan(new TtsSpan.TelephoneBuilder(ssid).build(), 0, ssid.length(),
723                Spannable.SPAN_INCLUSIVE_INCLUSIVE);
724        return str;
725    }
726
727    public String getConfigName() {
728        if (mConfig != null && mConfig.isPasspoint()) {
729            return mConfig.providerFriendlyName;
730        } else if (mFqdn != null) {
731            return mProviderFriendlyName;
732        } else {
733            return ssid;
734        }
735    }
736
737    public DetailedState getDetailedState() {
738        if (mNetworkInfo != null) {
739            return mNetworkInfo.getDetailedState();
740        }
741        Log.w(TAG, "NetworkInfo is null, cannot return detailed state");
742        return null;
743    }
744
745    public boolean isCarrierAp() {
746        return mIsCarrierAp;
747    }
748
749    public int getCarrierApEapType() {
750        return mCarrierApEapType;
751    }
752
753    public String getCarrierName() {
754        return mCarrierName;
755    }
756
757    public String getSavedNetworkSummary() {
758        WifiConfiguration config = mConfig;
759        if (config != null) {
760            PackageManager pm = mContext.getPackageManager();
761            String systemName = pm.getNameForUid(android.os.Process.SYSTEM_UID);
762            int userId = UserHandle.getUserId(config.creatorUid);
763            ApplicationInfo appInfo = null;
764            if (config.creatorName != null && config.creatorName.equals(systemName)) {
765                appInfo = mContext.getApplicationInfo();
766            } else {
767                try {
768                    IPackageManager ipm = AppGlobals.getPackageManager();
769                    appInfo = ipm.getApplicationInfo(config.creatorName, 0 /* flags */, userId);
770                } catch (RemoteException rex) {
771                }
772            }
773            if (appInfo != null &&
774                    !appInfo.packageName.equals(mContext.getString(R.string.settings_package)) &&
775                    !appInfo.packageName.equals(
776                    mContext.getString(R.string.certinstaller_package))) {
777                return mContext.getString(R.string.saved_network, appInfo.loadLabel(pm));
778            }
779        }
780        return "";
781    }
782
783    public String getSummary() {
784        return getSettingsSummary(mConfig);
785    }
786
787    public String getSettingsSummary() {
788        return getSettingsSummary(mConfig);
789    }
790
791    private String getSettingsSummary(WifiConfiguration config) {
792        // Update to new summary
793        StringBuilder summary = new StringBuilder();
794
795        if (isActive() && config != null && config.isPasspoint()) {
796            // This is the active connection on passpoint
797            summary.append(getSummary(mContext, getDetailedState(),
798                    false, config.providerFriendlyName));
799        } else if (isActive() && config != null && getDetailedState() == DetailedState.CONNECTED
800                && mIsCarrierAp) {
801            summary.append(String.format(mContext.getString(R.string.connected_via_carrier), mCarrierName));
802        } else if (isActive()) {
803            // This is the active connection on non-passpoint network
804            summary.append(getSummary(mContext, getDetailedState(),
805                    mInfo != null && mInfo.isEphemeral()));
806        } else if (config != null && config.isPasspoint()
807                && config.getNetworkSelectionStatus().isNetworkEnabled()) {
808            String format = mContext.getString(R.string.available_via_passpoint);
809            summary.append(String.format(format, config.providerFriendlyName));
810        } else if (config != null && config.hasNoInternetAccess()) {
811            int messageID = config.getNetworkSelectionStatus().isNetworkPermanentlyDisabled()
812                    ? R.string.wifi_no_internet_no_reconnect
813                    : R.string.wifi_no_internet;
814            summary.append(mContext.getString(messageID));
815        } else if (config != null && !config.getNetworkSelectionStatus().isNetworkEnabled()) {
816            WifiConfiguration.NetworkSelectionStatus networkStatus =
817                    config.getNetworkSelectionStatus();
818            switch (networkStatus.getNetworkSelectionDisableReason()) {
819                case WifiConfiguration.NetworkSelectionStatus.DISABLED_AUTHENTICATION_FAILURE:
820                    summary.append(mContext.getString(R.string.wifi_disabled_password_failure));
821                    break;
822                case WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD:
823                    summary.append(mContext.getString(R.string.wifi_check_password_try_again));
824                    break;
825                case WifiConfiguration.NetworkSelectionStatus.DISABLED_DHCP_FAILURE:
826                case WifiConfiguration.NetworkSelectionStatus.DISABLED_DNS_FAILURE:
827                    summary.append(mContext.getString(R.string.wifi_disabled_network_failure));
828                    break;
829                case WifiConfiguration.NetworkSelectionStatus.DISABLED_ASSOCIATION_REJECTION:
830                    summary.append(mContext.getString(R.string.wifi_disabled_generic));
831                    break;
832            }
833        } else if (config != null && config.getNetworkSelectionStatus().isNotRecommended()) {
834            summary.append(mContext.getString(R.string.wifi_disabled_by_recommendation_provider));
835        } else if (mIsCarrierAp) {
836            summary.append(String.format(mContext.getString(R.string.available_via_carrier), mCarrierName));
837        } else if (!isReachable()) { // Wifi out of range
838            summary.append(mContext.getString(R.string.wifi_not_in_range));
839        } else { // In range, not disabled.
840            if (config != null) { // Is saved network
841                // Last attempt to connect to this failed. Show reason why
842                switch (config.recentFailure.getAssociationStatus()) {
843                    case WifiConfiguration.RecentFailure.STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
844                        summary.append(mContext.getString(
845                                R.string.wifi_ap_unable_to_handle_new_sta));
846                        break;
847                    default:
848                        // "Saved"
849                        summary.append(mContext.getString(R.string.wifi_remembered));
850                        break;
851                }
852            }
853        }
854
855        if (WifiTracker.sVerboseLogging) {
856            evictOldScanResults();
857            summary.append(WifiUtils.buildLoggingSummary(this, config));
858        }
859
860        // If Speed label and summary are both present, use the preference combination to combine
861        // the two, else return the non-null one.
862        if (getSpeedLabel() != null && summary.length() != 0) {
863            return mContext.getResources().getString(
864                    R.string.preference_summary_default_combination,
865                    getSpeedLabel(),
866                    summary.toString());
867        } else if (getSpeedLabel() != null) {
868            return getSpeedLabel();
869        } else {
870            return summary.toString();
871        }
872    }
873
874    /**
875     * Return whether this is the active connection.
876     * For ephemeral connections (networkId is invalid), this returns false if the network is
877     * disconnected.
878     */
879    public boolean isActive() {
880        return mNetworkInfo != null &&
881                (networkId != WifiConfiguration.INVALID_NETWORK_ID ||
882                 mNetworkInfo.getState() != State.DISCONNECTED);
883    }
884
885    public boolean isConnectable() {
886        return getLevel() != -1 && getDetailedState() == null;
887    }
888
889    public boolean isEphemeral() {
890        return mInfo != null && mInfo.isEphemeral() &&
891                mNetworkInfo != null && mNetworkInfo.getState() != State.DISCONNECTED;
892    }
893
894    /**
895     * Return true if this AccessPoint represents a Passpoint AP.
896     */
897    public boolean isPasspoint() {
898        return mConfig != null && mConfig.isPasspoint();
899    }
900
901    /**
902     * Return true if this AccessPoint represents a Passpoint provider configuration.
903     */
904    public boolean isPasspointConfig() {
905        return mFqdn != null;
906    }
907
908    /**
909     * Return whether the given {@link WifiInfo} is for this access point.
910     * If the current AP does not have a network Id then the config is used to
911     * match based on SSID and security.
912     */
913    private boolean isInfoForThisAccessPoint(WifiConfiguration config, WifiInfo info) {
914        if (isPasspoint() == false && networkId != WifiConfiguration.INVALID_NETWORK_ID) {
915            return networkId == info.getNetworkId();
916        } else if (config != null) {
917            return matches(config);
918        }
919        else {
920            // Might be an ephemeral connection with no WifiConfiguration. Try matching on SSID.
921            // (Note that we only do this if the WifiConfiguration explicitly equals INVALID).
922            // TODO: Handle hex string SSIDs.
923            return ssid.equals(removeDoubleQuotes(info.getSSID()));
924        }
925    }
926
927    public boolean isSaved() {
928        return networkId != WifiConfiguration.INVALID_NETWORK_ID;
929    }
930
931    public Object getTag() {
932        return mTag;
933    }
934
935    public void setTag(Object tag) {
936        mTag = tag;
937    }
938
939    /**
940     * Generate and save a default wifiConfiguration with common values.
941     * Can only be called for unsecured networks.
942     */
943    public void generateOpenNetworkConfig() {
944        if (security != SECURITY_NONE)
945            throw new IllegalStateException();
946        if (mConfig != null)
947            return;
948        mConfig = new WifiConfiguration();
949        mConfig.SSID = AccessPoint.convertToQuotedString(ssid);
950        mConfig.allowedKeyManagement.set(KeyMgmt.NONE);
951    }
952
953    void loadConfig(WifiConfiguration config) {
954        ssid = (config.SSID == null ? "" : removeDoubleQuotes(config.SSID));
955        bssid = config.BSSID;
956        security = getSecurity(config);
957        networkId = config.networkId;
958        mConfig = config;
959    }
960
961    private void initWithScanResult(ScanResult result) {
962        ssid = result.SSID;
963        bssid = result.BSSID;
964        security = getSecurity(result);
965        if (security == SECURITY_PSK)
966            pskType = getPskType(result);
967
968        mScanResultCache.put(result.BSSID, result);
969        updateRssi();
970        mIsCarrierAp = result.isCarrierAp;
971        mCarrierApEapType = result.carrierApEapType;
972        mCarrierName = result.carrierName;
973    }
974
975    public void saveWifiState(Bundle savedState) {
976        if (ssid != null) savedState.putString(KEY_SSID, getSsidStr());
977        savedState.putInt(KEY_SECURITY, security);
978        savedState.putInt(KEY_SPEED, mSpeed);
979        savedState.putInt(KEY_PSKTYPE, pskType);
980        if (mConfig != null) savedState.putParcelable(KEY_CONFIG, mConfig);
981        savedState.putParcelable(KEY_WIFIINFO, mInfo);
982        evictOldScanResults();
983        savedState.putParcelableArrayList(KEY_SCANRESULTCACHE,
984                new ArrayList<ScanResult>(mScanResultCache.values()));
985        savedState.putParcelableArrayList(KEY_SCOREDNETWORKCACHE,
986                new ArrayList<>(mScoredNetworkCache.values()));
987        if (mNetworkInfo != null) {
988            savedState.putParcelable(KEY_NETWORKINFO, mNetworkInfo);
989        }
990        if (mFqdn != null) {
991            savedState.putString(KEY_FQDN, mFqdn);
992        }
993        if (mProviderFriendlyName != null) {
994            savedState.putString(KEY_PROVIDER_FRIENDLY_NAME, mProviderFriendlyName);
995        }
996        savedState.putBoolean(KEY_IS_CARRIER_AP, mIsCarrierAp);
997        savedState.putInt(KEY_CARRIER_AP_EAP_TYPE, mCarrierApEapType);
998        savedState.putString(KEY_CARRIER_NAME, mCarrierName);
999    }
1000
1001    public void setListener(AccessPointListener listener) {
1002        mAccessPointListener = listener;
1003    }
1004
1005    /**
1006     * Update the AP with the given scan result.
1007     *
1008     * @param result the ScanResult to add to the AccessPoint scan cache
1009     * @param evictOldScanResults whether stale scan results should be removed
1010     *         from the cache during this update process
1011     * @return true if the scan result update caused a change in state which would impact ranking
1012     *     or AccessPoint rendering (e.g. wifi level, security)
1013     */
1014    boolean update(ScanResult result, boolean evictOldScanResults) {
1015        if (matches(result)) {
1016            int oldLevel = getLevel();
1017
1018            /* Add or update the scan result for the BSSID */
1019            mScanResultCache.put(result.BSSID, result);
1020            if (evictOldScanResults) evictOldScanResults();
1021            updateRssi();
1022            int newLevel = getLevel();
1023
1024            if (newLevel > 0 && newLevel != oldLevel) {
1025                // Only update labels on visible rssi changes
1026                updateSpeed();
1027                if (mAccessPointListener != null) {
1028                    mAccessPointListener.onLevelChanged(this);
1029                }
1030            }
1031            // This flag only comes from scans, is not easily saved in config
1032            if (security == SECURITY_PSK) {
1033                pskType = getPskType(result);
1034            }
1035
1036            if (mAccessPointListener != null) {
1037                mAccessPointListener.onAccessPointChanged(this);
1038            }
1039
1040            // The carrier info in the ScanResult is set by the platform based on the SSID and will
1041            // always be the same for all matching scan results.
1042            mIsCarrierAp = result.isCarrierAp;
1043            mCarrierApEapType = result.carrierApEapType;
1044            mCarrierName = result.carrierName;
1045
1046            return true;
1047        }
1048        return false;
1049    }
1050
1051    /** Attempt to update the AccessPoint and return true if an update occurred. */
1052    public boolean update(
1053            @Nullable WifiConfiguration config, WifiInfo info, NetworkInfo networkInfo) {
1054
1055        boolean updated = false;
1056        final int oldLevel = getLevel();
1057        if (info != null && isInfoForThisAccessPoint(config, info)) {
1058            updated = (mInfo == null);
1059            if (mConfig != config) {
1060                // We do not set updated = true as we do not want to increase the amount of sorting
1061                // and copying performed in WifiTracker at this time. If issues involving refresh
1062                // are still seen, we will investigate further.
1063                update(config); // Notifies the AccessPointListener of the change
1064            }
1065            if (mRssi != info.getRssi() && info.getRssi() != WifiInfo.INVALID_RSSI) {
1066                mRssi = info.getRssi();
1067                updated = true;
1068            } else if (mNetworkInfo != null && networkInfo != null
1069                    && mNetworkInfo.getDetailedState() != networkInfo.getDetailedState()) {
1070                updated = true;
1071            }
1072            mInfo = info;
1073            mNetworkInfo = networkInfo;
1074        } else if (mInfo != null) {
1075            updated = true;
1076            mInfo = null;
1077            mNetworkInfo = null;
1078        }
1079        if (updated && mAccessPointListener != null) {
1080            mAccessPointListener.onAccessPointChanged(this);
1081
1082            if (oldLevel != getLevel() /* current level */) {
1083                mAccessPointListener.onLevelChanged(this);
1084            }
1085        }
1086
1087        return updated;
1088    }
1089
1090    void update(@Nullable WifiConfiguration config) {
1091        mConfig = config;
1092        networkId = config != null ? config.networkId : WifiConfiguration.INVALID_NETWORK_ID;
1093        if (mAccessPointListener != null) {
1094            mAccessPointListener.onAccessPointChanged(this);
1095        }
1096    }
1097
1098    @VisibleForTesting
1099    void setRssi(int rssi) {
1100        mRssi = rssi;
1101    }
1102
1103    /** Sets the rssi to {@link #UNREACHABLE_RSSI}. */
1104    void setUnreachable() {
1105        setRssi(AccessPoint.UNREACHABLE_RSSI);
1106    }
1107
1108    int getSpeed() { return mSpeed;}
1109
1110    @Nullable
1111    String getSpeedLabel() {
1112        return getSpeedLabel(mSpeed);
1113    }
1114
1115    @Nullable
1116    @Speed
1117    private int roundToClosestSpeedEnum(int speed) {
1118        if (speed < Speed.SLOW) {
1119            return Speed.NONE;
1120        } else if (speed < (Speed.SLOW + Speed.MODERATE) / 2) {
1121            return Speed.SLOW;
1122        } else if (speed < (Speed.MODERATE + Speed.FAST) / 2) {
1123            return Speed.MODERATE;
1124        } else if (speed < (Speed.FAST + Speed.VERY_FAST) / 2) {
1125            return Speed.FAST;
1126        } else {
1127            return Speed.VERY_FAST;
1128        }
1129    }
1130
1131    @Nullable
1132    String getSpeedLabel(@Speed int speed) {
1133        switch (speed) {
1134            case Speed.VERY_FAST:
1135                return mContext.getString(R.string.speed_label_very_fast);
1136            case Speed.FAST:
1137                return mContext.getString(R.string.speed_label_fast);
1138            case Speed.MODERATE:
1139                return mContext.getString(R.string.speed_label_okay);
1140            case Speed.SLOW:
1141                return mContext.getString(R.string.speed_label_slow);
1142            case Speed.NONE:
1143            default:
1144                return null;
1145        }
1146    }
1147
1148    /** Return true if the current RSSI is reachable, and false otherwise. */
1149    public boolean isReachable() {
1150        return mRssi != UNREACHABLE_RSSI;
1151    }
1152
1153    public static String getSummary(Context context, String ssid, DetailedState state,
1154            boolean isEphemeral, String passpointProvider) {
1155        if (state == DetailedState.CONNECTED && ssid == null) {
1156            if (TextUtils.isEmpty(passpointProvider) == false) {
1157                // Special case for connected + passpoint networks.
1158                String format = context.getString(R.string.connected_via_passpoint);
1159                return String.format(format, passpointProvider);
1160            } else if (isEphemeral) {
1161                // Special case for connected + ephemeral networks.
1162                final NetworkScoreManager networkScoreManager = context.getSystemService(
1163                        NetworkScoreManager.class);
1164                NetworkScorerAppData scorer = networkScoreManager.getActiveScorer();
1165                if (scorer != null && scorer.getRecommendationServiceLabel() != null) {
1166                    String format = context.getString(R.string.connected_via_network_scorer);
1167                    return String.format(format, scorer.getRecommendationServiceLabel());
1168                } else {
1169                    return context.getString(R.string.connected_via_network_scorer_default);
1170                }
1171            }
1172        }
1173
1174        // Case when there is wifi connected without internet connectivity.
1175        final ConnectivityManager cm = (ConnectivityManager)
1176                context.getSystemService(Context.CONNECTIVITY_SERVICE);
1177        if (state == DetailedState.CONNECTED) {
1178            IWifiManager wifiManager = IWifiManager.Stub.asInterface(
1179                    ServiceManager.getService(Context.WIFI_SERVICE));
1180            NetworkCapabilities nc = null;
1181
1182            try {
1183                nc = cm.getNetworkCapabilities(wifiManager.getCurrentNetwork());
1184            } catch (RemoteException e) {}
1185
1186            if (nc != null) {
1187                if (nc.hasCapability(nc.NET_CAPABILITY_CAPTIVE_PORTAL)) {
1188                    int id = context.getResources()
1189                            .getIdentifier("network_available_sign_in", "string", "android");
1190                    return context.getString(id);
1191                } else if (!nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)) {
1192                    return context.getString(R.string.wifi_connected_no_internet);
1193                }
1194            }
1195        }
1196        if (state == null) {
1197            Log.w(TAG, "state is null, returning empty summary");
1198            return "";
1199        }
1200        String[] formats = context.getResources().getStringArray((ssid == null)
1201                ? R.array.wifi_status : R.array.wifi_status_with_ssid);
1202        int index = state.ordinal();
1203
1204        if (index >= formats.length || formats[index].length() == 0) {
1205            return "";
1206        }
1207        return String.format(formats[index], ssid);
1208    }
1209
1210    public static String getSummary(Context context, DetailedState state, boolean isEphemeral) {
1211        return getSummary(context, null, state, isEphemeral, null);
1212    }
1213
1214    public static String getSummary(Context context, DetailedState state, boolean isEphemeral,
1215            String passpointProvider) {
1216        return getSummary(context, null, state, isEphemeral, passpointProvider);
1217    }
1218
1219    public static String convertToQuotedString(String string) {
1220        return "\"" + string + "\"";
1221    }
1222
1223    private static int getPskType(ScanResult result) {
1224        boolean wpa = result.capabilities.contains("WPA-PSK");
1225        boolean wpa2 = result.capabilities.contains("WPA2-PSK");
1226        if (wpa2 && wpa) {
1227            return PSK_WPA_WPA2;
1228        } else if (wpa2) {
1229            return PSK_WPA2;
1230        } else if (wpa) {
1231            return PSK_WPA;
1232        } else {
1233            Log.w(TAG, "Received abnormal flag string: " + result.capabilities);
1234            return PSK_UNKNOWN;
1235        }
1236    }
1237
1238    private static int getSecurity(ScanResult result) {
1239        if (result.capabilities.contains("WEP")) {
1240            return SECURITY_WEP;
1241        } else if (result.capabilities.contains("PSK")) {
1242            return SECURITY_PSK;
1243        } else if (result.capabilities.contains("EAP")) {
1244            return SECURITY_EAP;
1245        }
1246        return SECURITY_NONE;
1247    }
1248
1249    static int getSecurity(WifiConfiguration config) {
1250        if (config.allowedKeyManagement.get(KeyMgmt.WPA_PSK)) {
1251            return SECURITY_PSK;
1252        }
1253        if (config.allowedKeyManagement.get(KeyMgmt.WPA_EAP) ||
1254                config.allowedKeyManagement.get(KeyMgmt.IEEE8021X)) {
1255            return SECURITY_EAP;
1256        }
1257        return (config.wepKeys[0] != null) ? SECURITY_WEP : SECURITY_NONE;
1258    }
1259
1260    public static String securityToString(int security, int pskType) {
1261        if (security == SECURITY_WEP) {
1262            return "WEP";
1263        } else if (security == SECURITY_PSK) {
1264            if (pskType == PSK_WPA) {
1265                return "WPA";
1266            } else if (pskType == PSK_WPA2) {
1267                return "WPA2";
1268            } else if (pskType == PSK_WPA_WPA2) {
1269                return "WPA_WPA2";
1270            }
1271            return "PSK";
1272        } else if (security == SECURITY_EAP) {
1273            return "EAP";
1274        }
1275        return "NONE";
1276    }
1277
1278    static String removeDoubleQuotes(String string) {
1279        if (TextUtils.isEmpty(string)) {
1280            return "";
1281        }
1282        int length = string.length();
1283        if ((length > 1) && (string.charAt(0) == '"')
1284                && (string.charAt(length - 1) == '"')) {
1285            return string.substring(1, length - 1);
1286        }
1287        return string;
1288    }
1289
1290    public interface AccessPointListener {
1291        void onAccessPointChanged(AccessPoint accessPoint);
1292        void onLevelChanged(AccessPoint accessPoint);
1293    }
1294}
1295