Skip to content

Commit

Permalink
[Android] Fixes for NoStreams lint errors
Browse files Browse the repository at this point in the history
For now we just suppress them as there is no uniform fix for all of them. Follow up issue is created to address this brave/brave-browser#42632

Chromium change:
https://chromium.googlesource.com/chromium/src/+/31928c984432e9d2f7c71438a716a417f378dff5

Reland "Android: Add Error Prone warning against Java stream() apis"

This reverts commit 8ff33dbc1ddcaabcf4da1b92868bfa26ae34ba8f.

Reason for reland: Internal fix landed

Original change's description:
> Revert "Android: Add Error Prone warning against Java stream() apis"
>
> This reverts commit e910d272c026bf1463f54ea17ce6fb16f55513cf.
>
> Reason for revert: crbug.com/344943957#comment13
>
> Original change's description:
> > Android: Add Error Prone warning against Java stream() apis
> >
> > And minor clarifying tweaks to style guide wrt streams
> >
> > Bug: 344943957
> > Change-Id: I90b976866c8f3f71826459b7d3097692e1f533b4
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6042674
> > Auto-Submit: Andrew Grieve <[email protected]>
> > Commit-Queue: Andrew Grieve <[email protected]>
> > Reviewed-by: Henrique Nakashima <[email protected]>
> > Cr-Commit-Position: refs/heads/main@{#1388426}
>
> Bug: 344943957
> Change-Id: Ib9b3d8db9f47383eaced5192a15e7cac6427da35
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6051419
> Reviewed-by: Henrique Nakashima <[email protected]>
> Auto-Submit: Keigo Oka <[email protected]>
> Commit-Queue: Henrique Nakashima <[email protected]>
> Bot-Commit: Rubber Stamper <[email protected]>
> Reviewed-by: Andrew Grieve <[email protected]>
> Cr-Commit-Position: refs/heads/main@{#1388467}

Bug: 344943957
  • Loading branch information
samartnik committed Dec 3, 2024
1 parent bcc81d1 commit f4bc408
Show file tree
Hide file tree
Showing 15 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.chromium.brave_wallet.mojom.JsonRpcService;
import org.chromium.brave_wallet.mojom.JsonRpcServiceObserver;
import org.chromium.brave_wallet.mojom.NetworkInfo;
import org.chromium.chrome.browser.app.domain.NetworkModel.NetworkLists;
import org.chromium.chrome.browser.crypto_wallet.util.AndroidUtils;
import org.chromium.chrome.browser.crypto_wallet.util.JavaUtils;
import org.chromium.chrome.browser.crypto_wallet.util.NetworkUtils;
Expand Down Expand Up @@ -65,6 +66,7 @@ public class NetworkModel implements JsonRpcServiceObserver {
public final LiveData<List<NetworkInfo>> mSecondaryNetworks;
public final LiveData<NetworkLists> mNetworkLists;

@SuppressWarnings("NoStreams")
public NetworkModel(
BraveWalletService braveWalletService,
@NonNull JsonRpcService jsonRpcService,
Expand Down Expand Up @@ -228,6 +230,7 @@ public void refreshNetworks() {
init();
}

@SuppressWarnings("NoStreams")
static void getAllNetworks(
JsonRpcService jsonRpcService, Callbacks.Callback1<List<NetworkInfo>> callback) {
if (jsonRpcService == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ private void initState() {
}

@NonNull
@SuppressWarnings("NoStreams")
private NetworkModel.NetworkLists filterSupportedDapp(
@NonNull final NetworkModel.NetworkLists networkLists) {
final Predicate<NetworkInfo> supportedNetworkFilter =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ public void filter(@NonNull final String text) {
mHandler.postDelayed(mFilteringRunnable, DEBOUNCE_SEARCH_MILLIS);
}

@SuppressWarnings("NoStreams")
private void performFiltering(
@NonNull final List<NetworkInfo> source,
@NonNull final List<NetworkInfo> filtered,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ private void updateDetails(String chainId, AccountId accountId) {
mTwoLineAdapter.notifyItemRangeChanged(0, items.size());
}

@SuppressWarnings("NoStreams")
private String getSiweResources(Url[] urls) {
if (urls == null || urls.length == 0) return "";
return Arrays.stream(urls)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public HashSet<AccountInfo> getAccountsWithPermissions() {
return mAccountsWithPermissions;
}

@SuppressWarnings("NoStreams")
private static boolean containsAccount(AccountId[] accounts, AccountId searchFor) {
return Arrays.stream(accounts)
.anyMatch(
Expand All @@ -39,6 +40,7 @@ private static boolean containsAccount(AccountId[] accounts, AccountId searchFor
});
}

@SuppressWarnings("NoStreams")
public void checkAccounts(Runnable runWhenDone) {
AccountId[] allAccountIds =
Arrays.stream(mAccounts).map(acc -> acc.accountId).toArray(AccountId[]::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public static boolean isSameToken(
}
}

@SuppressWarnings("NoStreams")
public static AccountInfo[] filterAccountsByNetwork(
AccountInfo[] accounts, @CoinType.EnumType int coinType, @Nullable String chainId) {
@KeyringId.EnumType int keyringId = AssetUtils.getKeyring(coinType, chainId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public static <T> T[] asArray(T... items) {
* @param items of string values.
* @return a combined or empty string.
*/
@SuppressWarnings("NoStreams")
public static String concatStrings(String separator, String... items) {
if (items == null) return "";
return Arrays.stream(items)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public static boolean isAllNetwork(@Nullable final NetworkInfo networkInfo) {
return networkInfo.chainId.equals("all");
}

@SuppressWarnings("NoStreams")
public static List<NetworkInfo> nonTestNetwork(List<NetworkInfo> networkInfos) {
if (networkInfos == null) return Collections.emptyList();
return networkInfos.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public enum TokenType {
*
* <p>See `refreshVisibleTokenInfo` in components/brave_wallet_ui/common/async/lib.ts.
*/
@SuppressWarnings("NoStreams")
private static BlockchainToken[] filterTokens(
NetworkInfo selectedNetwork,
BlockchainToken[] tokens,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ public static AccountInfo findAccount(AccountInfo[] accounts, AccountId accountI
return null;
}

@SuppressWarnings("NoStreams")
public static List<AccountInfo> filterAccountsByCoin(
AccountInfo[] accounts, @CoinType.EnumType int coinType) {
return Arrays.stream(accounts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public static String timeDeltaToDateString(TimeDelta timeDelta) {
return dateFormat.format(new Date(timeDelta.microseconds / 1000));
}

@SuppressWarnings("NoStreams")
public static String generateUniqueAccountName(
@CoinType.EnumType int coinType, AccountInfo[] accountInfos) {
Context context = ContextUtils.getApplicationContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public void updateNetworks() {
});
}

@SuppressWarnings("NoStreams")
private NetworkInfo[] filterNetworksByCoin(
@CoinType.EnumType final int coinType, NetworkInfo[] networks) {
return Arrays.stream(networks).filter(n -> n.coin == coinType).toArray(NetworkInfo[]::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void addDelegate(TouchDelegate delegate) {
}

/** Add a delegate by bounds and view. */
@SuppressWarnings("NoStreams")
public void addDelegate(Rect bounds, View view) {
mDelegates =
mDelegates.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.chromium.components.safe_browsing.SafeBrowsingApiHandler.LookupResult;

import java.util.List;
import java.util.Observer;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -84,6 +85,7 @@ public void setObserver(SafeBrowsingApiHandler.Observer observer) {
mObserver = observer;
}

@SuppressWarnings("NoStreams")
@Override
public void startUriLookup(long callbackId, String uri, int[] threatTypes, int protocol) {
if (mBraveSafeBrowsingApiHandlerDelegate == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private static int safeBrowsingToSafetyNetJavaThreatType(int safeBrowsingThreatT
}
}

@SuppressWarnings("NoStreams")
public static int[] safeBrowsingToSafetyNetThreatTypes(int[] safeBrowsingThreatTypes) {
List<Integer> arrSafetyNetThreatTypes = new ArrayList<Integer>();
for (int i = 0; i < safeBrowsingThreatTypes.length; ++i) {
Expand Down

0 comments on commit f4bc408

Please sign in to comment.