Commit aa797062 authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Android] Use ObjectsCompat.equals from support lib

This CL replaces ApiCompatibilityUtils.objectEquals and it's usages with
ObjectsCompat.equals method from Android support library. It also fixes
VisibleNetworksTest that had VisibleWifi objects in static field, as
it doesn't work well with Robolectric (ObjectsCompat.equals was
triggering a crash in that test, because it uses Build.VERSION.SDK_INT).

Bug: 782824
Change-Id: Ifba3325b2dd0102c3097e9dfcf0676d7a2c75fc6
Reviewed-on: https://chromium-review.googlesource.com/964663Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543848}
parent 168f828c
...@@ -699,15 +699,6 @@ public class ApiCompatibilityUtils { ...@@ -699,15 +699,6 @@ public class ApiCompatibilityUtils {
return activity.isInMultiWindowMode(); return activity.isInMultiWindowMode();
} }
/**
* Null-safe equivalent of {@code a.equals(b)}.
*
* @see Objects#equals(Object, Object)
*/
public static boolean objectEquals(Object a, Object b) {
return (a == null) ? (b == null) : a.equals(b);
}
/** /**
* Disables the Smart Select {@link TextClassifier} for the given {@link TextView} instance. * Disables the Smart Select {@link TextClassifier} for the given {@link TextView} instance.
* @param textView The {@link TextView} that should have its classifier disabled. * @param textView The {@link TextView} that should have its classifier disabled.
......
...@@ -12,6 +12,7 @@ import android.graphics.drawable.ColorDrawable; ...@@ -12,6 +12,7 @@ import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.util.ObjectsCompat;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.view.Gravity; import android.view.Gravity;
...@@ -29,7 +30,6 @@ import android.widget.ListView; ...@@ -29,7 +30,6 @@ import android.widget.ListView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.util.MathUtils; import org.chromium.chrome.browser.util.MathUtils;
...@@ -226,7 +226,7 @@ public class ItemChooserDialog { ...@@ -226,7 +226,7 @@ public class ItemChooserDialog {
addToDescriptionsMap(oldItem.mDescription); addToDescriptionsMap(oldItem.mDescription);
} }
if (!ApiCompatibilityUtils.objectEquals(icon, oldItem.mIcon)) { if (!ObjectsCompat.equals(icon, oldItem.mIcon)) {
oldItem.mIcon = icon; oldItem.mIcon = icon;
oldItem.mIconDescription = iconDescription; oldItem.mIconDescription = iconDescription;
} }
......
...@@ -10,8 +10,8 @@ import android.content.Context; ...@@ -10,8 +10,8 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.util.ObjectsCompat;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ApplicationStatus; import org.chromium.base.ApplicationStatus;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
...@@ -134,8 +134,7 @@ public class DelayedInvalidationsController { ...@@ -134,8 +134,7 @@ public class DelayedInvalidationsController {
PendingInvalidation invalidation = PendingInvalidation invalidation =
PendingInvalidation.decodeToPendingInvalidation(encodedInvalidation); PendingInvalidation.decodeToPendingInvalidation(encodedInvalidation);
if (invalidation == null) return false; if (invalidation == null) return false;
if (ApiCompatibilityUtils.objectEquals( if (ObjectsCompat.equals(invalidation.mObjectId, newInvalidation.mObjectId)
invalidation.mObjectId, newInvalidation.mObjectId)
&& invalidation.mObjectSource == newInvalidation.mObjectSource) { && invalidation.mObjectSource == newInvalidation.mObjectSource) {
if (invalidation.mVersion >= newInvalidation.mVersion) return true; if (invalidation.mVersion >= newInvalidation.mVersion) return true;
iter.remove(); iter.remove();
......
...@@ -14,6 +14,7 @@ import android.os.Process; ...@@ -14,6 +14,7 @@ import android.os.Process;
import android.os.SystemClock; import android.os.SystemClock;
import android.provider.Settings; import android.provider.Settings;
import android.support.annotation.IntDef; import android.support.annotation.IntDef;
import android.support.v4.util.ObjectsCompat;
import android.util.Base64; import android.util.Base64;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
...@@ -805,7 +806,7 @@ public class GeolocationHeader { ...@@ -805,7 +806,7 @@ public class GeolocationHeader {
// Select the extra visible cell. // Select the extra visible cell.
if (visibleCells != null) { if (visibleCells != null) {
for (VisibleCell candidateCell : visibleCells) { for (VisibleCell candidateCell : visibleCells) {
if (ApiCompatibilityUtils.objectEquals(connectedCell, candidateCell)) { if (ObjectsCompat.equals(connectedCell, candidateCell)) {
// Do not include this candidate cell, since its already the connected one. // Do not include this candidate cell, since its already the connected one.
continue; continue;
} }
...@@ -821,7 +822,7 @@ public class GeolocationHeader { ...@@ -821,7 +822,7 @@ public class GeolocationHeader {
// Do not include this candidate wifi. // Do not include this candidate wifi.
continue; continue;
} }
if (ApiCompatibilityUtils.objectEquals(connectedWifi, candidateWifi)) { if (ObjectsCompat.equals(connectedWifi, candidateWifi)) {
// Replace the connected, since the candidate will have level. This is because // Replace the connected, since the candidate will have level. This is because
// the android APIs exposing connected WIFI do not expose level, while the ones // the android APIs exposing connected WIFI do not expose level, while the ones
// exposing visible wifis expose level. // exposing visible wifis expose level.
......
...@@ -5,8 +5,7 @@ ...@@ -5,8 +5,7 @@
package org.chromium.chrome.browser.omnibox.geo; package org.chromium.chrome.browser.omnibox.geo;
import android.support.annotation.IntDef; import android.support.annotation.IntDef;
import android.support.v4.util.ObjectsCompat;
import org.chromium.base.ApiCompatibilityUtils;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
...@@ -101,10 +100,10 @@ class VisibleNetworks { ...@@ -101,10 +100,10 @@ class VisibleNetworks {
return false; return false;
} }
VisibleNetworks that = (VisibleNetworks) object; VisibleNetworks that = (VisibleNetworks) object;
return ApiCompatibilityUtils.objectEquals(mConnectedWifi, that.connectedWifi()) return ObjectsCompat.equals(mConnectedWifi, that.connectedWifi())
&& ApiCompatibilityUtils.objectEquals(mConnectedCell, that.connectedCell()) && ObjectsCompat.equals(mConnectedCell, that.connectedCell())
&& ApiCompatibilityUtils.objectEquals(mAllVisibleWifis, that.allVisibleWifis()) && ObjectsCompat.equals(mAllVisibleWifis, that.allVisibleWifis())
&& ApiCompatibilityUtils.objectEquals(mAllVisibleCells, that.allVisibleCells()); && ObjectsCompat.equals(mAllVisibleCells, that.allVisibleCells());
} }
private static int objectsHashCode(Object o) { private static int objectsHashCode(Object o) {
...@@ -193,8 +192,8 @@ class VisibleNetworks { ...@@ -193,8 +192,8 @@ class VisibleNetworks {
} }
VisibleWifi that = (VisibleWifi) object; VisibleWifi that = (VisibleWifi) object;
return ApiCompatibilityUtils.objectEquals(mSsid, that.ssid()) return ObjectsCompat.equals(mSsid, that.ssid())
&& ApiCompatibilityUtils.objectEquals(mBssid, that.bssid()); && ObjectsCompat.equals(mBssid, that.bssid());
} }
@Override @Override
...@@ -367,19 +366,14 @@ class VisibleNetworks { ...@@ -367,19 +366,14 @@ class VisibleNetworks {
return false; return false;
} }
VisibleCell that = (VisibleCell) object; VisibleCell that = (VisibleCell) object;
return ApiCompatibilityUtils.objectEquals(mRadioType, that.radioType()) return ObjectsCompat.equals(mRadioType, that.radioType())
&& ApiCompatibilityUtils.objectEquals(mCellId, that.cellId()) && ObjectsCompat.equals(mCellId, that.cellId())
&& ApiCompatibilityUtils.objectEquals( && ObjectsCompat.equals(mLocationAreaCode, that.locationAreaCode())
mLocationAreaCode, that.locationAreaCode()) && ObjectsCompat.equals(mMobileCountryCode, that.mobileCountryCode())
&& ApiCompatibilityUtils.objectEquals( && ObjectsCompat.equals(mMobileNetworkCode, that.mobileNetworkCode())
mMobileCountryCode, that.mobileCountryCode()) && ObjectsCompat.equals(mPrimaryScramblingCode, that.primaryScramblingCode())
&& ApiCompatibilityUtils.objectEquals( && ObjectsCompat.equals(mPhysicalCellId, that.physicalCellId())
mMobileNetworkCode, that.mobileNetworkCode()) && ObjectsCompat.equals(mTrackingAreaCode, that.trackingAreaCode());
&& ApiCompatibilityUtils.objectEquals(
mPrimaryScramblingCode, that.primaryScramblingCode())
&& ApiCompatibilityUtils.objectEquals(mPhysicalCellId, that.physicalCellId())
&& ApiCompatibilityUtils.objectEquals(
mTrackingAreaCode, that.trackingAreaCode());
} }
@Override @Override
......
...@@ -8,6 +8,7 @@ import android.app.Dialog; ...@@ -8,6 +8,7 @@ import android.app.Dialog;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.graphics.drawable.VectorDrawableCompat; import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.test.filters.LargeTest; import android.support.test.filters.LargeTest;
import android.support.v4.util.ObjectsCompat;
import android.text.SpannableString; import android.text.SpannableString;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
...@@ -21,7 +22,6 @@ import org.junit.Rule; ...@@ -21,7 +22,6 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.RetryOnFailure; import org.chromium.base.test.util.RetryOnFailure;
...@@ -65,7 +65,7 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -65,7 +65,7 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
mTestDrawable2 = getNewTestDrawable(); mTestDrawable2 = getNewTestDrawable();
mTestDrawableDescription2 = "icon2 description"; mTestDrawableDescription2 = "icon2 description";
Assert.assertFalse(ApiCompatibilityUtils.objectEquals(mTestDrawable1, mTestDrawable2)); Assert.assertFalse(ObjectsCompat.equals(mTestDrawable1, mTestDrawable2));
} }
// ItemChooserDialog.ItemSelectedCallback: // ItemChooserDialog.ItemSelectedCallback:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment