org.chromium.base.CollectionUtil Java Examples

The following examples show how to use org.chromium.base.CollectionUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InvalidationClientService.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void informRegistrationFailure(
        byte[] clientId, ObjectId objectId, boolean isTransient, String errorMessage) {
    Log.w(TAG, "Registration failure on " + objectId + " ; transient = " + isTransient
            + ": " + errorMessage);
    if (isTransient) {
      // Retry immediately on transient failures. The base AndroidListener will handle
      // exponential backoff if there are repeated failures.
        List<ObjectId> objectIdAsList = CollectionUtil.newArrayList(objectId);
        if (readRegistrationsFromPrefs().contains(objectId)) {
            register(clientId, objectIdAsList);
        } else {
            unregister(clientId, objectIdAsList);
        }
    }
}
 
Example #2
Source File: InvalidationClientService.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void informRegistrationStatus(
        byte[] clientId, ObjectId objectId, RegistrationState regState) {
    Log.d(TAG, "Registration status for " + objectId + ": " + regState);
    List<ObjectId> objectIdAsList = CollectionUtil.newArrayList(objectId);
    boolean registrationisDesired = readRegistrationsFromPrefs().contains(objectId);
    if (regState == RegistrationState.REGISTERED) {
        if (!registrationisDesired) {
            Log.i(TAG, "Unregistering for object we're no longer interested in");
            unregister(clientId, objectIdAsList);
        }
    } else {
        if (registrationisDesired) {
            Log.i(TAG, "Registering for an object");
            register(clientId, objectIdAsList);
        }
    }
}
 
Example #3
Source File: InvalidationIntentProtocol.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Create an Intent that will start the invalidation listener service and
 * register for the specified types.
 */
public static Intent createRegisterIntent(Account account,
                                          boolean allTypes, Set<ModelType> types) {
    Intent registerIntent = new Intent(ACTION_REGISTER);
    String[] selectedTypesArray;
    if (allTypes) {
        selectedTypesArray = new String[]{ModelType.ALL_TYPES_TYPE};
    } else {
        selectedTypesArray = new String[types.size()];
        int pos = 0;
        for (ModelType type : types) {
            selectedTypesArray[pos++] = type.name();
        }
    }
    registerIntent.putStringArrayListExtra(EXTRA_REGISTERED_TYPES,
            CollectionUtil.newArrayList(selectedTypesArray));
    registerIntent.putExtra(EXTRA_ACCOUNT, account);
    return registerIntent;
}
 
Example #4
Source File: InvalidationService.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void informRegistrationFailure(
        byte[] clientId, ObjectId objectId, boolean isTransient, String errorMessage) {
    Log.w(TAG, "Registration failure on " + objectId + " ; transient = " + isTransient
            + ": " + errorMessage);
    if (isTransient) {
      // Retry immediately on transient failures. The base AndroidListener will handle
      // exponential backoff if there are repeated failures.
      List<ObjectId> objectIdAsList = CollectionUtil.newArrayList(objectId);
      if (readRegistrationsFromPrefs().contains(objectId)) {
          register(clientId, objectIdAsList);
      } else {
          unregister(clientId, objectIdAsList);
      }
    }
}
 
Example #5
Source File: InvalidationService.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void informRegistrationStatus(
        byte[] clientId, ObjectId objectId, RegistrationState regState) {
    Log.d(TAG, "Registration status for " + objectId + ": " + regState);
    List<ObjectId> objectIdAsList = CollectionUtil.newArrayList(objectId);
    boolean registrationisDesired = readRegistrationsFromPrefs().contains(objectId);
    if (regState == RegistrationState.REGISTERED) {
      if (!registrationisDesired) {
        Log.i(TAG, "Unregistering for object we're no longer interested in");
        unregister(clientId, objectIdAsList);
      }
    } else {
      if (registrationisDesired) {
        Log.i(TAG, "Registering for an object");
        register(clientId, objectIdAsList);
      }
    }
}
 
Example #6
Source File: InvalidationIntentProtocol.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Create an Intent that will start the invalidation listener service and
 * register for the specified types.
 */
public static Intent createRegisterIntent(Account account,
                                          boolean allTypes, Set<ModelType> types) {
    Intent registerIntent = new Intent(ACTION_REGISTER);
    String[] selectedTypesArray;
    if (allTypes) {
        selectedTypesArray = new String[]{ModelType.ALL_TYPES_TYPE};
    } else {
        selectedTypesArray = new String[types.size()];
        int pos = 0;
        for (ModelType type : types) {
            selectedTypesArray[pos++] = type.name();
        }
    }
    registerIntent.putStringArrayListExtra(EXTRA_REGISTERED_TYPES,
            CollectionUtil.newArrayList(selectedTypesArray));
    registerIntent.putExtra(EXTRA_ACCOUNT, account);
    return registerIntent;
}
 
Example #7
Source File: InvalidationService.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void informRegistrationFailure(
        byte[] clientId, ObjectId objectId, boolean isTransient, String errorMessage) {
    Log.w(TAG, "Registration failure on " + objectId + " ; transient = " + isTransient
            + ": " + errorMessage);
    if (isTransient) {
      // Retry immediately on transient failures. The base AndroidListener will handle
      // exponential backoff if there are repeated failures.
      List<ObjectId> objectIdAsList = CollectionUtil.newArrayList(objectId);
      if (readRegistrationsFromPrefs().contains(objectId)) {
          register(clientId, objectIdAsList);
      } else {
          unregister(clientId, objectIdAsList);
      }
    }
}
 
Example #8
Source File: InvalidationService.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void informRegistrationStatus(
        byte[] clientId, ObjectId objectId, RegistrationState regState) {
    Log.d(TAG, "Registration status for " + objectId + ": " + regState);
    List<ObjectId> objectIdAsList = CollectionUtil.newArrayList(objectId);
    boolean registrationisDesired = readRegistrationsFromPrefs().contains(objectId);
    if (regState == RegistrationState.REGISTERED) {
      if (!registrationisDesired) {
        Log.i(TAG, "Unregistering for object we're no longer interested in");
        unregister(clientId, objectIdAsList);
      }
    } else {
      if (registrationisDesired) {
        Log.i(TAG, "Registering for an object");
        register(clientId, objectIdAsList);
      }
    }
}
 
Example #9
Source File: InvalidationIntentProtocol.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Create an Intent that will start the invalidation listener service and
 * register for the specified types.
 */
public static Intent createRegisterIntent(Account account, Set<Integer> types) {
    Intent registerIntent = new Intent(ACTION_REGISTER);
    String[] selectedTypesArray = new String[types.size()];
    int pos = 0;
    for (Integer type : types) {
        selectedTypesArray[pos++] = ModelTypeHelper.toNotificationType(type);
    }
    registerIntent.putStringArrayListExtra(
            EXTRA_REGISTERED_TYPES, CollectionUtil.newArrayList(selectedTypesArray));
    registerIntent.putExtra(EXTRA_ACCOUNT, account);
    return registerIntent;
}
 
Example #10
Source File: DeviceSensors.java    From 365browser with Apache License 2.0 4 votes vote down vote up
protected DeviceSensors() {
    mOrientationSensorSets = CollectionUtil.newArrayList(DEVICE_ORIENTATION_SENSORS_A,
            DEVICE_ORIENTATION_SENSORS_B, DEVICE_ORIENTATION_SENSORS_C);
}
 
Example #11
Source File: GeolocationHeader.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Nullable
@VisibleForTesting
static VisibleNetworks trimVisibleNetworks(@Nullable VisibleNetworks visibleNetworks) {
    if (visibleNetworks == null || visibleNetworks.isEmpty()) {
        return null;
    }
    // Trim visible networks to only include a limited number of visible not-conntected networks
    // based on flag.
    VisibleCell connectedCell = visibleNetworks.connectedCell();
    VisibleWifi connectedWifi = visibleNetworks.connectedWifi();
    Set<VisibleCell> visibleCells = visibleNetworks.allVisibleCells();
    Set<VisibleWifi> visibleWifis = visibleNetworks.allVisibleWifis();
    VisibleCell extraVisibleCell = null;
    VisibleWifi extraVisibleWifi = null;
    if (shouldExcludeVisibleWifi(connectedWifi)) {
        // Trim the connected wifi.
        connectedWifi = null;
    }
    // Select the extra visible cell.
    if (visibleCells != null) {
        for (VisibleCell candidateCell : visibleCells) {
            if (ApiCompatibilityUtils.objectEquals(connectedCell, candidateCell)) {
                // Do not include this candidate cell, since its already the connected one.
                continue;
            }
            // Add it and since we only want one, stop iterating over other cells.
            extraVisibleCell = candidateCell;
            break;
        }
    }
    // Select the extra visible wifi.
    if (visibleWifis != null) {
        for (VisibleWifi candidateWifi : visibleWifis) {
            if (shouldExcludeVisibleWifi(candidateWifi)) {
                // Do not include this candidate wifi.
                continue;
            }
            if (ApiCompatibilityUtils.objectEquals(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.
                connectedWifi = candidateWifi;
                // Do not include this candidate wifi, since its already the connected one.
                continue;
            }
            // Keep the one with stronger level (since it's negative, this is the smaller value)
            if (extraVisibleWifi == null || extraVisibleWifi.level() > candidateWifi.level()) {
                extraVisibleWifi = candidateWifi;
            }
        }
    }

    if (connectedCell == null && connectedWifi == null && extraVisibleCell == null
            && extraVisibleWifi == null) {
        return null;
    }

    return VisibleNetworks.create(connectedWifi, connectedCell,
            extraVisibleWifi != null ? CollectionUtil.newHashSet(extraVisibleWifi) : null,
            extraVisibleCell != null ? CollectionUtil.newHashSet(extraVisibleCell) : null);
}