Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.omnibox.geo; | 5 package org.chromium.chrome.browser.omnibox.geo; |
| 6 | 6 |
| 7 import android.support.annotation.IntDef; | 7 import android.support.annotation.IntDef; |
| 8 | 8 |
| 9 import org.chromium.base.ApiCompatibilityUtils; | 9 import org.chromium.base.ApiCompatibilityUtils; |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 @Nullable | 26 @Nullable |
| 27 private final VisibleCell mConnectedCell; | 27 private final VisibleCell mConnectedCell; |
| 28 @Nullable | 28 @Nullable |
| 29 private final Set<VisibleWifi> mAllVisibleWifis; | 29 private final Set<VisibleWifi> mAllVisibleWifis; |
| 30 @Nullable | 30 @Nullable |
| 31 private final Set<VisibleCell> mAllVisibleCells; | 31 private final Set<VisibleCell> mAllVisibleCells; |
| 32 | 32 |
| 33 private VisibleNetworks(@Nullable VisibleWifi connectedWifi, | 33 private VisibleNetworks(@Nullable VisibleWifi connectedWifi, |
| 34 @Nullable VisibleCell connectedCell, @Nullable Set<VisibleWifi> allV isibleWifis, | 34 @Nullable VisibleCell connectedCell, @Nullable Set<VisibleWifi> allV isibleWifis, |
| 35 @Nullable Set<VisibleCell> allVisibleCells) { | 35 @Nullable Set<VisibleCell> allVisibleCells) { |
| 36 this.mConnectedWifi = connectedWifi; | 36 mConnectedWifi = connectedWifi; |
| 37 this.mConnectedCell = connectedCell; | 37 mConnectedCell = connectedCell; |
| 38 this.mAllVisibleWifis = allVisibleWifis; | 38 mAllVisibleWifis = allVisibleWifis; |
| 39 this.mAllVisibleCells = allVisibleCells; | 39 mAllVisibleCells = allVisibleCells; |
| 40 } | 40 } |
| 41 | 41 |
| 42 public static VisibleNetworks create(@Nullable VisibleWifi connectedWifi, | 42 public static VisibleNetworks create(@Nullable VisibleWifi connectedWifi, |
| 43 @Nullable VisibleCell connectedCell, @Nullable Set<VisibleWifi> allV isibleWifis, | 43 @Nullable VisibleCell connectedCell, @Nullable Set<VisibleWifi> allV isibleWifis, |
| 44 @Nullable Set<VisibleCell> allVisibleCells) { | 44 @Nullable Set<VisibleCell> allVisibleCells) { |
| 45 return new VisibleNetworks(connectedWifi, connectedCell, allVisibleWifis , allVisibleCells); | 45 return new VisibleNetworks(connectedWifi, connectedCell, allVisibleWifis , allVisibleCells); |
| 46 } | 46 } |
| 47 | 47 |
| 48 /** | 48 /** |
| 49 * Returns the connected {@link VisibleWifi} or null if the connected wifi i s unknown. | 49 * Returns the connected {@link VisibleWifi} or null if the connected wifi i s unknown. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 * Compares the specified object with this VisibleNetworks for equality. Re turns | 94 * Compares the specified object with this VisibleNetworks for equality. Re turns |
| 95 * {@code true} if the given object is a VisibleNetworks and has identical v alues for | 95 * {@code true} if the given object is a VisibleNetworks and has identical v alues for |
| 96 * all of its fields. | 96 * all of its fields. |
| 97 */ | 97 */ |
| 98 @Override | 98 @Override |
| 99 public boolean equals(Object object) { | 99 public boolean equals(Object object) { |
| 100 if (!(object instanceof VisibleNetworks)) { | 100 if (!(object instanceof VisibleNetworks)) { |
| 101 return false; | 101 return false; |
| 102 } | 102 } |
| 103 VisibleNetworks that = (VisibleNetworks) object; | 103 VisibleNetworks that = (VisibleNetworks) object; |
| 104 return ApiCompatibilityUtils.objectEquals(this.mConnectedWifi, that.conn ectedWifi()) | 104 return ApiCompatibilityUtils.objectEquals(mConnectedWifi, that.connected Wifi()) |
| 105 && ApiCompatibilityUtils.objectEquals(this.mConnectedCell, that. connectedCell()) | 105 && ApiCompatibilityUtils.objectEquals(mConnectedCell, that.conne ctedCell()) |
| 106 && ApiCompatibilityUtils.objectEquals(this.mAllVisibleWifis, tha t.allVisibleWifis()) | 106 && ApiCompatibilityUtils.objectEquals(mAllVisibleWifis, that.all VisibleWifis()) |
| 107 && ApiCompatibilityUtils.objectEquals( | 107 && ApiCompatibilityUtils.objectEquals(mAllVisibleCells, that.all VisibleCells()); |
| 108 this.mAllVisibleCells, that.allVisibleCells()); | |
| 109 } | 108 } |
| 110 | 109 |
| 111 private static int objectsHashCode(Object o) { | 110 private static int objectsHashCode(Object o) { |
| 112 return o != null ? o.hashCode() : 0; | 111 return o != null ? o.hashCode() : 0; |
| 113 } | 112 } |
| 114 | 113 |
| 115 private static int objectsHash(Object... a) { | 114 private static int objectsHash(Object... a) { |
| 116 return Arrays.hashCode(a); | 115 return Arrays.hashCode(a); |
| 117 } | 116 } |
| 118 | 117 |
| 119 @Override | 118 @Override |
| 120 public int hashCode() { | 119 public int hashCode() { |
| 121 return objectsHash(this.mConnectedWifi, this.mConnectedCell, | 120 return objectsHash(mConnectedWifi, mConnectedCell, objectsHashCode(mAllV isibleWifis), |
| 122 objectsHashCode(this.mAllVisibleWifis), objectsHashCode(this.mAl lVisibleCells)); | 121 objectsHashCode(mAllVisibleCells)); |
| 123 } | 122 } |
| 124 | 123 |
| 125 /** | 124 /** |
| 126 * Specification of a visible wifi. | 125 * Specification of a visible wifi. |
| 127 */ | 126 */ |
| 128 public static class VisibleWifi { | 127 public static class VisibleWifi { |
| 129 public static final VisibleWifi NO_WIFI_INFO = VisibleWifi.create(null, null, null, null); | 128 public static final VisibleWifi NO_WIFI_INFO = VisibleWifi.create(null, null, null, null); |
| 130 | 129 |
| 131 @Nullable | 130 @Nullable |
| 132 private final String mSsid; | 131 private final String mSsid; |
| 133 @Nullable | 132 @Nullable |
| 134 private final String mBssid; | 133 private final String mBssid; |
| 135 @Nullable | 134 @Nullable |
| 136 private final Integer mLevel; | 135 private final Integer mLevel; |
| 137 @Nullable | 136 @Nullable |
| 138 private final Long mTimestampMs; | 137 private final Long mTimestampMs; |
| 139 | 138 |
| 140 private VisibleWifi(@Nullable String ssid, @Nullable String bssid, @Null able Integer level, | 139 private VisibleWifi(@Nullable String ssid, @Nullable String bssid, @Null able Integer level, |
| 141 @Nullable Long timestampMs) { | 140 @Nullable Long timestampMs) { |
| 142 this.mSsid = ssid; | 141 mSsid = ssid; |
| 143 this.mBssid = bssid; | 142 mBssid = bssid; |
| 144 this.mLevel = level; | 143 mLevel = level; |
| 145 this.mTimestampMs = timestampMs; | 144 mTimestampMs = timestampMs; |
| 146 } | 145 } |
| 147 | 146 |
| 148 public static VisibleWifi create(@Nullable String ssid, @Nullable String bssid, | 147 public static VisibleWifi create(@Nullable String ssid, @Nullable String bssid, |
| 149 @Nullable Integer level, @Nullable Long timestampMs) { | 148 @Nullable Integer level, @Nullable Long timestampMs) { |
| 150 return new VisibleWifi(ssid, bssid, level, timestampMs); | 149 return new VisibleWifi(ssid, bssid, level, timestampMs); |
| 151 } | 150 } |
| 152 | 151 |
| 153 /** | 152 /** |
| 154 * Returns the SSID of the visible Wifi, or null if unknown. | 153 * Returns the SSID of the visible Wifi, or null if unknown. |
| 155 */ | 154 */ |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 * {@code true} if the given object is a VisibleWifi and has identical v alues for | 186 * {@code true} if the given object is a VisibleWifi and has identical v alues for |
| 188 * all of its fields except level and timestampMs. | 187 * all of its fields except level and timestampMs. |
| 189 */ | 188 */ |
| 190 @Override | 189 @Override |
| 191 public boolean equals(Object object) { | 190 public boolean equals(Object object) { |
| 192 if (!(object instanceof VisibleWifi)) { | 191 if (!(object instanceof VisibleWifi)) { |
| 193 return false; | 192 return false; |
| 194 } | 193 } |
| 195 | 194 |
| 196 VisibleWifi that = (VisibleWifi) object; | 195 VisibleWifi that = (VisibleWifi) object; |
| 197 return ApiCompatibilityUtils.objectEquals(this.mSsid, that.ssid()) | 196 return ApiCompatibilityUtils.objectEquals(mSsid, that.ssid()) |
| 198 && ApiCompatibilityUtils.objectEquals(this.mBssid, that.bssi d()); | 197 && ApiCompatibilityUtils.objectEquals(mBssid, that.bssid()); |
| 199 } | 198 } |
| 200 | 199 |
| 201 @Override | 200 @Override |
| 202 public int hashCode() { | 201 public int hashCode() { |
| 203 return VisibleNetworks.objectsHash(this.mSsid, this.mBssid); | 202 return VisibleNetworks.objectsHash(mSsid, mBssid); |
| 203 } | |
| 204 | |
| 205 /** | |
| 206 * Encodes a VisibleWifi into its corresponding PartnerLocationDescripto r.VisibleNetwork | |
| 207 * proto. | |
| 208 */ | |
| 209 public PartnerLocationDescriptor.VisibleNetwork toProto(boolean connecte d) { | |
| 210 PartnerLocationDescriptor.VisibleNetwork visibleNetwork = | |
| 211 new PartnerLocationDescriptor.VisibleNetwork(); | |
| 212 | |
| 213 PartnerLocationDescriptor.VisibleNetwork.WiFi wifi = | |
| 214 new PartnerLocationDescriptor.VisibleNetwork.WiFi(); | |
| 215 | |
| 216 String bssid = bssid(); | |
| 217 if (bssid != null) { | |
| 218 wifi.bssid = bssid(); | |
|
Ted C
2017/05/17 17:44:25
what is the default value for wifi.bssid? Is it n
lbargu
2017/05/18 12:42:48
Sorry, forgot this is nano protos. Should be ok to
| |
| 219 } | |
| 220 Integer level = level(); | |
| 221 if (level != null) { | |
| 222 wifi.levelDbm = level(); | |
| 223 } | |
| 224 visibleNetwork.wifi = wifi; | |
| 225 | |
| 226 Long timestampMs = timestampMs(); | |
| 227 if (timestampMs != null) { | |
| 228 visibleNetwork.timestampMs = timestampMs; | |
| 229 } | |
| 230 visibleNetwork.connected = connected; | |
| 231 return visibleNetwork; | |
|
dougt
2017/05/17 20:51:17
two questions:
Can any of these accessors return
lbargu
2017/05/18 12:42:48
Done.
| |
| 204 } | 232 } |
| 205 } | 233 } |
| 206 | 234 |
| 207 /** | 235 /** |
| 208 * Specification of a visible cell. | 236 * Specification of a visible cell. |
| 209 */ | 237 */ |
| 210 public static class VisibleCell { | 238 public static class VisibleCell { |
| 211 public static final VisibleCell UNKNOWN_VISIBLE_CELL = | 239 public static final VisibleCell UNKNOWN_VISIBLE_CELL = |
| 212 VisibleCell.builder(VisibleCell.UNKNOWN_RADIO_TYPE).build(); | 240 VisibleCell.builder(VisibleCell.UNKNOWN_RADIO_TYPE).build(); |
| 213 public static final VisibleCell UNKNOWN_MISSING_LOCATION_PERMISSION_VISI BLE_CELL = | 241 public static final VisibleCell UNKNOWN_MISSING_LOCATION_PERMISSION_VISI BLE_CELL = |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 @Nullable | 273 @Nullable |
| 246 private final Integer mPrimaryScramblingCode; | 274 private final Integer mPrimaryScramblingCode; |
| 247 @Nullable | 275 @Nullable |
| 248 private final Integer mPhysicalCellId; | 276 private final Integer mPhysicalCellId; |
| 249 @Nullable | 277 @Nullable |
| 250 private final Integer mTrackingAreaCode; | 278 private final Integer mTrackingAreaCode; |
| 251 @Nullable | 279 @Nullable |
| 252 private Long mTimestampMs; | 280 private Long mTimestampMs; |
| 253 | 281 |
| 254 private VisibleCell(Builder builder) { | 282 private VisibleCell(Builder builder) { |
| 255 this.mRadioType = builder.mRadioType; | 283 mRadioType = builder.mRadioType; |
| 256 this.mCellId = builder.mCellId; | 284 mCellId = builder.mCellId; |
| 257 this.mLocationAreaCode = builder.mLocationAreaCode; | 285 mLocationAreaCode = builder.mLocationAreaCode; |
| 258 this.mMobileCountryCode = builder.mMobileCountryCode; | 286 mMobileCountryCode = builder.mMobileCountryCode; |
| 259 this.mMobileNetworkCode = builder.mMobileNetworkCode; | 287 mMobileNetworkCode = builder.mMobileNetworkCode; |
| 260 this.mPrimaryScramblingCode = builder.mPrimaryScramblingCode; | 288 mPrimaryScramblingCode = builder.mPrimaryScramblingCode; |
| 261 this.mPhysicalCellId = builder.mPhysicalCellId; | 289 mPhysicalCellId = builder.mPhysicalCellId; |
| 262 this.mTrackingAreaCode = builder.mTrackingAreaCode; | 290 mTrackingAreaCode = builder.mTrackingAreaCode; |
| 263 this.mTimestampMs = builder.mTimestampMs; | 291 mTimestampMs = builder.mTimestampMs; |
| 264 } | 292 } |
| 265 | 293 |
| 266 /** | 294 /** |
| 267 * Returns the radio type of the visible cell. | 295 * Returns the radio type of the visible cell. |
| 268 */ | 296 */ |
| 269 @RadioType | 297 @RadioType |
| 270 public int radioType() { | 298 public int radioType() { |
| 271 return mRadioType; | 299 return mRadioType; |
| 272 } | 300 } |
| 273 | 301 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 * Compares the specified object with this VisibleCell for equality. Re turns | 368 * Compares the specified object with this VisibleCell for equality. Re turns |
| 341 * {@code true} if the given object is a VisibleWifi and has identical v alues for | 369 * {@code true} if the given object is a VisibleWifi and has identical v alues for |
| 342 * all of its fields except timestampMs. | 370 * all of its fields except timestampMs. |
| 343 */ | 371 */ |
| 344 @Override | 372 @Override |
| 345 public boolean equals(Object object) { | 373 public boolean equals(Object object) { |
| 346 if (!(object instanceof VisibleCell)) { | 374 if (!(object instanceof VisibleCell)) { |
| 347 return false; | 375 return false; |
| 348 } | 376 } |
| 349 VisibleCell that = (VisibleCell) object; | 377 VisibleCell that = (VisibleCell) object; |
| 350 return ApiCompatibilityUtils.objectEquals(this.mRadioType, that.radi oType()) | 378 return ApiCompatibilityUtils.objectEquals(mRadioType, that.radioType ()) |
| 351 && ApiCompatibilityUtils.objectEquals(this.mCellId, that.cel lId()) | 379 && ApiCompatibilityUtils.objectEquals(mCellId, that.cellId() ) |
| 352 && ApiCompatibilityUtils.objectEquals( | 380 && ApiCompatibilityUtils.objectEquals( |
| 353 this.mLocationAreaCode, that.locationAreaCode()) | 381 mLocationAreaCode, that.locationAreaCode()) |
| 354 && ApiCompatibilityUtils.objectEquals( | 382 && ApiCompatibilityUtils.objectEquals( |
| 355 this.mMobileCountryCode, that.mobileCountryCode() ) | 383 mMobileCountryCode, that.mobileCountryCode()) |
| 356 && ApiCompatibilityUtils.objectEquals( | 384 && ApiCompatibilityUtils.objectEquals( |
| 357 this.mMobileNetworkCode, that.mobileNetworkCode() ) | 385 mMobileNetworkCode, that.mobileNetworkCode()) |
| 358 && ApiCompatibilityUtils.objectEquals( | 386 && ApiCompatibilityUtils.objectEquals( |
| 359 this.mPrimaryScramblingCode, that.primaryScrambli ngCode()) | 387 mPrimaryScramblingCode, that.primaryScramblingCod e()) |
| 388 && ApiCompatibilityUtils.objectEquals(mPhysicalCellId, that. physicalCellId()) | |
| 360 && ApiCompatibilityUtils.objectEquals( | 389 && ApiCompatibilityUtils.objectEquals( |
| 361 this.mPhysicalCellId, that.physicalCellId()) | 390 mTrackingAreaCode, that.trackingAreaCode()); |
| 362 && ApiCompatibilityUtils.objectEquals( | |
| 363 this.mTrackingAreaCode, that.trackingAreaCode()); | |
| 364 } | 391 } |
| 365 | 392 |
| 366 @Override | 393 @Override |
| 367 public int hashCode() { | 394 public int hashCode() { |
| 368 return VisibleNetworks.objectsHash(this.mRadioType, this.mCellId, | 395 return VisibleNetworks.objectsHash(mRadioType, mCellId, mLocationAre aCode, |
| 369 this.mLocationAreaCode, this.mMobileCountryCode, this.mMobil eNetworkCode, | 396 mMobileCountryCode, mMobileNetworkCode, mPrimaryScramblingCo de, mPhysicalCellId, |
| 370 this.mPrimaryScramblingCode, this.mPhysicalCellId, this.mTra ckingAreaCode); | 397 mTrackingAreaCode); |
| 371 } | 398 } |
| 372 | 399 |
| 373 /** | 400 /** |
| 401 * Encodes a VisibleCell into its corresponding PartnerLocationDescripto r.VisibleNetwork | |
| 402 * proto. | |
| 403 */ | |
| 404 public PartnerLocationDescriptor.VisibleNetwork toProto(boolean connecte d) { | |
| 405 PartnerLocationDescriptor.VisibleNetwork visibleNetwork = | |
| 406 new PartnerLocationDescriptor.VisibleNetwork(); | |
| 407 | |
| 408 PartnerLocationDescriptor.VisibleNetwork.Cell cell = | |
| 409 new PartnerLocationDescriptor.VisibleNetwork.Cell(); | |
| 410 | |
| 411 switch (radioType()) { | |
| 412 case VisibleCell.CDMA_RADIO_TYPE: | |
| 413 cell.type = PartnerLocationDescriptor.VisibleNetwork.Cell.CD MA; | |
| 414 break; | |
| 415 case VisibleCell.GSM_RADIO_TYPE: | |
| 416 cell.type = PartnerLocationDescriptor.VisibleNetwork.Cell.GS M; | |
| 417 break; | |
| 418 case VisibleCell.LTE_RADIO_TYPE: | |
| 419 cell.type = PartnerLocationDescriptor.VisibleNetwork.Cell.LT E; | |
| 420 break; | |
| 421 case VisibleCell.WCDMA_RADIO_TYPE: | |
| 422 cell.type = PartnerLocationDescriptor.VisibleNetwork.Cell.WC DMA; | |
| 423 break; | |
| 424 case VisibleCell.UNKNOWN_RADIO_TYPE: | |
| 425 cell.type = PartnerLocationDescriptor.VisibleNetwork.Cell.UN KNOWN; | |
| 426 break; | |
| 427 case VisibleCell.UNKNOWN_MISSING_LOCATION_PERMISSION_RADIO_TYPE: | |
| 428 cell.type = PartnerLocationDescriptor.VisibleNetwork.Cell.UN KNOWN; | |
| 429 break; | |
| 430 default: | |
|
Ted C
2017/05/17 17:44:25
should we just fall through these?
case VisibleCe
lbargu
2017/05/18 12:42:48
Done.
| |
| 431 cell.type = PartnerLocationDescriptor.VisibleNetwork.Cell.UN KNOWN; | |
| 432 break; | |
| 433 } | |
| 434 | |
| 435 Integer cellId = cellId(); | |
| 436 if (cellId != null) { | |
| 437 cell.cellId = cellId; | |
|
dougt
2017/05/17 20:51:17
same nullable question here.
lbargu
2017/05/18 12:42:48
Done.
| |
| 438 } | |
| 439 Integer locationAreaCode = locationAreaCode(); | |
| 440 if (locationAreaCode != null) { | |
| 441 cell.locationAreaCode = locationAreaCode; | |
| 442 } | |
| 443 Integer mobileCountryCode = mobileCountryCode(); | |
| 444 if (mobileCountryCode != null) { | |
| 445 cell.mobileCountryCode = mobileCountryCode; | |
| 446 } | |
| 447 Integer mobileNetworkCode = mobileNetworkCode(); | |
| 448 if (mobileNetworkCode != null) { | |
| 449 cell.mobileNetworkCode = mobileNetworkCode; | |
| 450 } | |
| 451 Integer primaryScramblingCode = primaryScramblingCode(); | |
| 452 if (primaryScramblingCode != null) { | |
| 453 cell.primaryScramblingCode = primaryScramblingCode; | |
| 454 } | |
| 455 Integer physicalCellId = physicalCellId(); | |
| 456 if (physicalCellId != null) { | |
| 457 cell.physicalCellId = physicalCellId; | |
| 458 } | |
| 459 Integer trackingAreaCode = trackingAreaCode(); | |
| 460 if (trackingAreaCode != null) { | |
| 461 cell.trackingAreaCode = trackingAreaCode; | |
| 462 } | |
| 463 | |
| 464 visibleNetwork.cell = cell; | |
| 465 | |
| 466 Long timestampMs = timestampMs(); | |
| 467 if (timestampMs != null) { | |
| 468 visibleNetwork.timestampMs = timestampMs; | |
| 469 } | |
| 470 visibleNetwork.connected = connected; | |
| 471 return visibleNetwork; | |
| 472 } | |
| 473 | |
| 474 /** | |
| 374 * A {@link VisibleCell} builder. | 475 * A {@link VisibleCell} builder. |
| 375 */ | 476 */ |
| 376 public static class Builder { | 477 public static class Builder { |
| 377 @RadioType | 478 @RadioType |
| 378 private int mRadioType; | 479 private int mRadioType; |
| 379 @Nullable | 480 @Nullable |
| 380 private Integer mCellId; | 481 private Integer mCellId; |
| 381 @Nullable | 482 @Nullable |
| 382 private Integer mLocationAreaCode; | 483 private Integer mLocationAreaCode; |
| 383 @Nullable | 484 @Nullable |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 mTimestampMs = timestampMs; | 538 mTimestampMs = timestampMs; |
| 438 return this; | 539 return this; |
| 439 } | 540 } |
| 440 | 541 |
| 441 public VisibleCell build() { | 542 public VisibleCell build() { |
| 442 return new VisibleCell(this); | 543 return new VisibleCell(this); |
| 443 } | 544 } |
| 444 } | 545 } |
| 445 } | 546 } |
| 446 } | 547 } |
| OLD | NEW |