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 {
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.
* @param textView The {@link TextView} that should have its classifier disabled.
......
......@@ -12,6 +12,7 @@ import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.v4.util.ObjectsCompat;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.Gravity;
......@@ -29,7 +30,6 @@ import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.util.MathUtils;
......@@ -226,7 +226,7 @@ public class ItemChooserDialog {
addToDescriptionsMap(oldItem.mDescription);
}
if (!ApiCompatibilityUtils.objectEquals(icon, oldItem.mIcon)) {
if (!ObjectsCompat.equals(icon, oldItem.mIcon)) {
oldItem.mIcon = icon;
oldItem.mIconDescription = iconDescription;
}
......
......@@ -10,8 +10,8 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.util.ObjectsCompat;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
......@@ -134,8 +134,7 @@ public class DelayedInvalidationsController {
PendingInvalidation invalidation =
PendingInvalidation.decodeToPendingInvalidation(encodedInvalidation);
if (invalidation == null) return false;
if (ApiCompatibilityUtils.objectEquals(
invalidation.mObjectId, newInvalidation.mObjectId)
if (ObjectsCompat.equals(invalidation.mObjectId, newInvalidation.mObjectId)
&& invalidation.mObjectSource == newInvalidation.mObjectSource) {
if (invalidation.mVersion >= newInvalidation.mVersion) return true;
iter.remove();
......
......@@ -14,6 +14,7 @@ import android.os.Process;
import android.os.SystemClock;
import android.provider.Settings;
import android.support.annotation.IntDef;
import android.support.v4.util.ObjectsCompat;
import android.util.Base64;
import org.chromium.base.ApiCompatibilityUtils;
......@@ -805,7 +806,7 @@ public class GeolocationHeader {
// Select the extra visible cell.
if (visibleCells != null) {
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.
continue;
}
......@@ -821,7 +822,7 @@ public class GeolocationHeader {
// Do not include this candidate wifi.
continue;
}
if (ApiCompatibilityUtils.objectEquals(connectedWifi, candidateWifi)) {
if (ObjectsCompat.equals(connectedWifi, candidateWifi)) {
// 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
// exposing visible wifis expose level.
......
......@@ -5,8 +5,7 @@
package org.chromium.chrome.browser.omnibox.geo;
import android.support.annotation.IntDef;
import org.chromium.base.ApiCompatibilityUtils;
import android.support.v4.util.ObjectsCompat;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
......@@ -101,10 +100,10 @@ class VisibleNetworks {
return false;
}
VisibleNetworks that = (VisibleNetworks) object;
return ApiCompatibilityUtils.objectEquals(mConnectedWifi, that.connectedWifi())
&& ApiCompatibilityUtils.objectEquals(mConnectedCell, that.connectedCell())
&& ApiCompatibilityUtils.objectEquals(mAllVisibleWifis, that.allVisibleWifis())
&& ApiCompatibilityUtils.objectEquals(mAllVisibleCells, that.allVisibleCells());
return ObjectsCompat.equals(mConnectedWifi, that.connectedWifi())
&& ObjectsCompat.equals(mConnectedCell, that.connectedCell())
&& ObjectsCompat.equals(mAllVisibleWifis, that.allVisibleWifis())
&& ObjectsCompat.equals(mAllVisibleCells, that.allVisibleCells());
}
private static int objectsHashCode(Object o) {
......@@ -193,8 +192,8 @@ class VisibleNetworks {
}
VisibleWifi that = (VisibleWifi) object;
return ApiCompatibilityUtils.objectEquals(mSsid, that.ssid())
&& ApiCompatibilityUtils.objectEquals(mBssid, that.bssid());
return ObjectsCompat.equals(mSsid, that.ssid())
&& ObjectsCompat.equals(mBssid, that.bssid());
}
@Override
......@@ -367,19 +366,14 @@ class VisibleNetworks {
return false;
}
VisibleCell that = (VisibleCell) object;
return ApiCompatibilityUtils.objectEquals(mRadioType, that.radioType())
&& ApiCompatibilityUtils.objectEquals(mCellId, that.cellId())
&& ApiCompatibilityUtils.objectEquals(
mLocationAreaCode, that.locationAreaCode())
&& ApiCompatibilityUtils.objectEquals(
mMobileCountryCode, that.mobileCountryCode())
&& ApiCompatibilityUtils.objectEquals(
mMobileNetworkCode, that.mobileNetworkCode())
&& ApiCompatibilityUtils.objectEquals(
mPrimaryScramblingCode, that.primaryScramblingCode())
&& ApiCompatibilityUtils.objectEquals(mPhysicalCellId, that.physicalCellId())
&& ApiCompatibilityUtils.objectEquals(
mTrackingAreaCode, that.trackingAreaCode());
return ObjectsCompat.equals(mRadioType, that.radioType())
&& ObjectsCompat.equals(mCellId, that.cellId())
&& ObjectsCompat.equals(mLocationAreaCode, that.locationAreaCode())
&& ObjectsCompat.equals(mMobileCountryCode, that.mobileCountryCode())
&& ObjectsCompat.equals(mMobileNetworkCode, that.mobileNetworkCode())
&& ObjectsCompat.equals(mPrimaryScramblingCode, that.primaryScramblingCode())
&& ObjectsCompat.equals(mPhysicalCellId, that.physicalCellId())
&& ObjectsCompat.equals(mTrackingAreaCode, that.trackingAreaCode());
}
@Override
......
......@@ -8,6 +8,7 @@ import android.app.Dialog;
import android.graphics.drawable.Drawable;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.test.filters.LargeTest;
import android.support.v4.util.ObjectsCompat;
import android.text.SpannableString;
import android.view.View;
import android.widget.Button;
......@@ -21,7 +22,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.RetryOnFailure;
......@@ -65,7 +65,7 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
mTestDrawable2 = getNewTestDrawable();
mTestDrawableDescription2 = "icon2 description";
Assert.assertFalse(ApiCompatibilityUtils.objectEquals(mTestDrawable1, mTestDrawable2));
Assert.assertFalse(ObjectsCompat.equals(mTestDrawable1, mTestDrawable2));
}
// 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