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