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 wifi.bssid = bssid(); |
| 217 wifi.levelDbm = level(); |
| 218 |
| 219 visibleNetwork.wifi = wifi; |
| 220 visibleNetwork.timestampMs = timestampMs(); |
| 221 visibleNetwork.connected = connected; |
| 222 |
| 223 return visibleNetwork; |
204 } | 224 } |
205 } | 225 } |
206 | 226 |
207 /** | 227 /** |
208 * Specification of a visible cell. | 228 * Specification of a visible cell. |
209 */ | 229 */ |
210 public static class VisibleCell { | 230 public static class VisibleCell { |
211 public static final VisibleCell UNKNOWN_VISIBLE_CELL = | 231 public static final VisibleCell UNKNOWN_VISIBLE_CELL = |
212 VisibleCell.builder(VisibleCell.UNKNOWN_RADIO_TYPE).build(); | 232 VisibleCell.builder(VisibleCell.UNKNOWN_RADIO_TYPE).build(); |
213 public static final VisibleCell UNKNOWN_MISSING_LOCATION_PERMISSION_VISI
BLE_CELL = | 233 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 | 265 @Nullable |
246 private final Integer mPrimaryScramblingCode; | 266 private final Integer mPrimaryScramblingCode; |
247 @Nullable | 267 @Nullable |
248 private final Integer mPhysicalCellId; | 268 private final Integer mPhysicalCellId; |
249 @Nullable | 269 @Nullable |
250 private final Integer mTrackingAreaCode; | 270 private final Integer mTrackingAreaCode; |
251 @Nullable | 271 @Nullable |
252 private Long mTimestampMs; | 272 private Long mTimestampMs; |
253 | 273 |
254 private VisibleCell(Builder builder) { | 274 private VisibleCell(Builder builder) { |
255 this.mRadioType = builder.mRadioType; | 275 mRadioType = builder.mRadioType; |
256 this.mCellId = builder.mCellId; | 276 mCellId = builder.mCellId; |
257 this.mLocationAreaCode = builder.mLocationAreaCode; | 277 mLocationAreaCode = builder.mLocationAreaCode; |
258 this.mMobileCountryCode = builder.mMobileCountryCode; | 278 mMobileCountryCode = builder.mMobileCountryCode; |
259 this.mMobileNetworkCode = builder.mMobileNetworkCode; | 279 mMobileNetworkCode = builder.mMobileNetworkCode; |
260 this.mPrimaryScramblingCode = builder.mPrimaryScramblingCode; | 280 mPrimaryScramblingCode = builder.mPrimaryScramblingCode; |
261 this.mPhysicalCellId = builder.mPhysicalCellId; | 281 mPhysicalCellId = builder.mPhysicalCellId; |
262 this.mTrackingAreaCode = builder.mTrackingAreaCode; | 282 mTrackingAreaCode = builder.mTrackingAreaCode; |
263 this.mTimestampMs = builder.mTimestampMs; | 283 mTimestampMs = builder.mTimestampMs; |
264 } | 284 } |
265 | 285 |
266 /** | 286 /** |
267 * Returns the radio type of the visible cell. | 287 * Returns the radio type of the visible cell. |
268 */ | 288 */ |
269 @RadioType | 289 @RadioType |
270 public int radioType() { | 290 public int radioType() { |
271 return mRadioType; | 291 return mRadioType; |
272 } | 292 } |
273 | 293 |
(...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 | 360 * 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 | 361 * {@code true} if the given object is a VisibleWifi and has identical v
alues for |
342 * all of its fields except timestampMs. | 362 * all of its fields except timestampMs. |
343 */ | 363 */ |
344 @Override | 364 @Override |
345 public boolean equals(Object object) { | 365 public boolean equals(Object object) { |
346 if (!(object instanceof VisibleCell)) { | 366 if (!(object instanceof VisibleCell)) { |
347 return false; | 367 return false; |
348 } | 368 } |
349 VisibleCell that = (VisibleCell) object; | 369 VisibleCell that = (VisibleCell) object; |
350 return ApiCompatibilityUtils.objectEquals(this.mRadioType, that.radi
oType()) | 370 return ApiCompatibilityUtils.objectEquals(mRadioType, that.radioType
()) |
351 && ApiCompatibilityUtils.objectEquals(this.mCellId, that.cel
lId()) | 371 && ApiCompatibilityUtils.objectEquals(mCellId, that.cellId()
) |
352 && ApiCompatibilityUtils.objectEquals( | 372 && ApiCompatibilityUtils.objectEquals( |
353 this.mLocationAreaCode, that.locationAreaCode()) | 373 mLocationAreaCode, that.locationAreaCode()) |
354 && ApiCompatibilityUtils.objectEquals( | 374 && ApiCompatibilityUtils.objectEquals( |
355 this.mMobileCountryCode, that.mobileCountryCode()
) | 375 mMobileCountryCode, that.mobileCountryCode()) |
356 && ApiCompatibilityUtils.objectEquals( | 376 && ApiCompatibilityUtils.objectEquals( |
357 this.mMobileNetworkCode, that.mobileNetworkCode()
) | 377 mMobileNetworkCode, that.mobileNetworkCode()) |
358 && ApiCompatibilityUtils.objectEquals( | 378 && ApiCompatibilityUtils.objectEquals( |
359 this.mPrimaryScramblingCode, that.primaryScrambli
ngCode()) | 379 mPrimaryScramblingCode, that.primaryScramblingCod
e()) |
| 380 && ApiCompatibilityUtils.objectEquals(mPhysicalCellId, that.
physicalCellId()) |
360 && ApiCompatibilityUtils.objectEquals( | 381 && ApiCompatibilityUtils.objectEquals( |
361 this.mPhysicalCellId, that.physicalCellId()) | 382 mTrackingAreaCode, that.trackingAreaCode()); |
362 && ApiCompatibilityUtils.objectEquals( | |
363 this.mTrackingAreaCode, that.trackingAreaCode()); | |
364 } | 383 } |
365 | 384 |
366 @Override | 385 @Override |
367 public int hashCode() { | 386 public int hashCode() { |
368 return VisibleNetworks.objectsHash(this.mRadioType, this.mCellId, | 387 return VisibleNetworks.objectsHash(mRadioType, mCellId, mLocationAre
aCode, |
369 this.mLocationAreaCode, this.mMobileCountryCode, this.mMobil
eNetworkCode, | 388 mMobileCountryCode, mMobileNetworkCode, mPrimaryScramblingCo
de, mPhysicalCellId, |
370 this.mPrimaryScramblingCode, this.mPhysicalCellId, this.mTra
ckingAreaCode); | 389 mTrackingAreaCode); |
371 } | 390 } |
372 | 391 |
373 /** | 392 /** |
| 393 * Encodes a VisibleCell into its corresponding PartnerLocationDescripto
r.VisibleNetwork |
| 394 * proto. |
| 395 */ |
| 396 public PartnerLocationDescriptor.VisibleNetwork toProto(boolean connecte
d) { |
| 397 PartnerLocationDescriptor.VisibleNetwork visibleNetwork = |
| 398 new PartnerLocationDescriptor.VisibleNetwork(); |
| 399 |
| 400 PartnerLocationDescriptor.VisibleNetwork.Cell cell = |
| 401 new PartnerLocationDescriptor.VisibleNetwork.Cell(); |
| 402 |
| 403 switch (radioType()) { |
| 404 case VisibleCell.CDMA_RADIO_TYPE: |
| 405 cell.type = PartnerLocationDescriptor.VisibleNetwork.Cell.CD
MA; |
| 406 break; |
| 407 case VisibleCell.GSM_RADIO_TYPE: |
| 408 cell.type = PartnerLocationDescriptor.VisibleNetwork.Cell.GS
M; |
| 409 break; |
| 410 case VisibleCell.LTE_RADIO_TYPE: |
| 411 cell.type = PartnerLocationDescriptor.VisibleNetwork.Cell.LT
E; |
| 412 break; |
| 413 case VisibleCell.WCDMA_RADIO_TYPE: |
| 414 cell.type = PartnerLocationDescriptor.VisibleNetwork.Cell.WC
DMA; |
| 415 break; |
| 416 case VisibleCell.UNKNOWN_RADIO_TYPE: |
| 417 case VisibleCell.UNKNOWN_MISSING_LOCATION_PERMISSION_RADIO_TYPE: |
| 418 default: |
| 419 cell.type = PartnerLocationDescriptor.VisibleNetwork.Cell.UN
KNOWN; |
| 420 break; |
| 421 } |
| 422 cell.cellId = cellId(); |
| 423 cell.locationAreaCode = locationAreaCode(); |
| 424 cell.mobileCountryCode = mobileCountryCode(); |
| 425 cell.mobileNetworkCode = mobileNetworkCode(); |
| 426 cell.primaryScramblingCode = primaryScramblingCode(); |
| 427 cell.physicalCellId = physicalCellId(); |
| 428 cell.trackingAreaCode = trackingAreaCode(); |
| 429 |
| 430 visibleNetwork.cell = cell; |
| 431 visibleNetwork.timestampMs = timestampMs(); |
| 432 visibleNetwork.connected = connected; |
| 433 |
| 434 return visibleNetwork; |
| 435 } |
| 436 |
| 437 /** |
374 * A {@link VisibleCell} builder. | 438 * A {@link VisibleCell} builder. |
375 */ | 439 */ |
376 public static class Builder { | 440 public static class Builder { |
377 @RadioType | 441 @RadioType |
378 private int mRadioType; | 442 private int mRadioType; |
379 @Nullable | 443 @Nullable |
380 private Integer mCellId; | 444 private Integer mCellId; |
381 @Nullable | 445 @Nullable |
382 private Integer mLocationAreaCode; | 446 private Integer mLocationAreaCode; |
383 @Nullable | 447 @Nullable |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 mTimestampMs = timestampMs; | 501 mTimestampMs = timestampMs; |
438 return this; | 502 return this; |
439 } | 503 } |
440 | 504 |
441 public VisibleCell build() { | 505 public VisibleCell build() { |
442 return new VisibleCell(this); | 506 return new VisibleCell(this); |
443 } | 507 } |
444 } | 508 } |
445 } | 509 } |
446 } | 510 } |
OLD | NEW |