Search in sources :

Example 71 with Location

use of android.location.Location in project android_frameworks_base by ResurrectionRemix.

the class FusedPrintersProvider method computeAndDeliverResult.

/**
     * Compute the printers, order them appropriately and deliver the printers to the clients. We
     * prefer printers that have been previously used (favorites) and printers that have been used
     * previously close to the current location (near printers).
     *
     * @param discoveredPrinters All printers currently discovered by the print discovery session.
     * @param favoritePrinters The ordered list of printers. The earlier in the list, the more
     *            preferred.
     */
private void computeAndDeliverResult(Map<PrinterId, PrinterInfo> discoveredPrinters, List<Pair<PrinterInfo, Location>> favoritePrinters) {
    List<PrinterInfo> printers = new ArrayList<>();
    // Store the printerIds that have already been added. We cannot compare the printerInfos in
    // "printers" as they might have been taken from discoveredPrinters and the printerInfo does
    // not equals() anymore
    HashSet<PrinterId> alreadyAddedPrinter = new HashSet<>(MAX_FAVORITE_PRINTER_COUNT);
    Location location = getCurrentLocation();
    // Add the favorite printers that have last been used close to the current location
    final int favoritePrinterCount = favoritePrinters.size();
    if (location != null) {
        for (int i = 0; i < favoritePrinterCount; i++) {
            // Only add a certain amount of favorite printers
            if (printers.size() == MAX_FAVORITE_PRINTER_COUNT) {
                break;
            }
            PrinterInfo favoritePrinter = favoritePrinters.get(i).first;
            Location printerLocation = favoritePrinters.get(i).second;
            if (printerLocation != null && !alreadyAddedPrinter.contains(favoritePrinter.getId())) {
                if (printerLocation.distanceTo(location) <= MAX_PRINTER_DISTANCE) {
                    updateAndAddPrinter(printers, favoritePrinter, discoveredPrinters);
                    alreadyAddedPrinter.add(favoritePrinter.getId());
                }
            }
        }
    }
    // Add the other favorite printers
    for (int i = 0; i < favoritePrinterCount; i++) {
        // Only add a certain amount of favorite printers
        if (printers.size() == MAX_FAVORITE_PRINTER_COUNT) {
            break;
        }
        PrinterInfo favoritePrinter = favoritePrinters.get(i).first;
        if (!alreadyAddedPrinter.contains(favoritePrinter.getId())) {
            updateAndAddPrinter(printers, favoritePrinter, discoveredPrinters);
            alreadyAddedPrinter.add(favoritePrinter.getId());
        }
    }
    // Add other updated printers. Printers that have already been added have been removed from
    // discoveredPrinters in the calls to updateAndAddPrinter
    final int printerCount = mPrinters.size();
    for (int i = 0; i < printerCount; i++) {
        PrinterInfo printer = mPrinters.get(i);
        PrinterInfo updatedPrinter = discoveredPrinters.remove(printer.getId());
        if (updatedPrinter != null) {
            printers.add(updatedPrinter);
        }
    }
    // Add the new printers, i.e. what is left.
    printers.addAll(discoveredPrinters.values());
    // Update the list of printers.
    mPrinters.clear();
    mPrinters.addAll(printers);
    if (isStarted()) {
        // If stated deliver the new printers.
        deliverResult(printers);
    } else {
        // Otherwise, take a note for the change.
        onContentChanged();
    }
}
Also used : ArrayList(java.util.ArrayList) PrinterId(android.print.PrinterId) PrinterInfo(android.print.PrinterInfo) HashSet(java.util.HashSet) Location(android.location.Location)

Example 72 with Location

use of android.location.Location in project android_frameworks_base by ResurrectionRemix.

the class DeviceIdleController method receivedGpsLocationLocked.

void receivedGpsLocationLocked(Location location) {
    if (mState != STATE_LOCATING) {
        cancelLocatingLocked();
        return;
    }
    if (DEBUG)
        Slog.d(TAG, "GPS location: " + location);
    mLastGpsLocation = new Location(location);
    if (location.getAccuracy() > mConstants.LOCATION_ACCURACY) {
        return;
    }
    mLocated = true;
    if (mNotMoving) {
        stepIdleStateLocked("s:gps");
    }
}
Also used : Location(android.location.Location)

Example 73 with Location

use of android.location.Location in project android_frameworks_base by ResurrectionRemix.

the class CameraMetadataNative method getGpsLocation.

private Location getGpsLocation() {
    String processingMethod = get(CaptureResult.JPEG_GPS_PROCESSING_METHOD);
    double[] coords = get(CaptureResult.JPEG_GPS_COORDINATES);
    Long timeStamp = get(CaptureResult.JPEG_GPS_TIMESTAMP);
    if (areValuesAllNull(processingMethod, coords, timeStamp)) {
        return null;
    }
    Location l = new Location(translateProcessToLocationProvider(processingMethod));
    if (timeStamp != null) {
        l.setTime(timeStamp);
    } else {
        Log.w(TAG, "getGpsLocation - No timestamp for GPS location.");
    }
    if (coords != null) {
        l.setLatitude(coords[0]);
        l.setLongitude(coords[1]);
        l.setAltitude(coords[2]);
    } else {
        Log.w(TAG, "getGpsLocation - No coordinates for GPS location");
    }
    return l;
}
Also used : MarshalQueryableString(android.hardware.camera2.marshal.impl.MarshalQueryableString) Location(android.location.Location)

Example 74 with Location

use of android.location.Location in project android_frameworks_base by ResurrectionRemix.

the class TwilightServiceTest method createMockLocation.

private Location createMockLocation(double latitude, double longitude) {
    // There's no empty constructor, so we initialize with a string and quickly reset it.
    final Location location = new Location("");
    location.reset();
    location.setLatitude(latitude);
    location.setLongitude(longitude);
    return location;
}
Also used : Location(android.location.Location)

Example 75 with Location

use of android.location.Location in project android_frameworks_base by ResurrectionRemix.

the class TwilightServiceTest method testInvalidLocation_ignoreLocationUpdate.

public void testInvalidLocation_ignoreLocationUpdate() {
    final TwilightState priorState = mTwilightService.mLastTwilightState;
    final Location invalidLocation = createMockLocation(0.0, 0.0);
    mTwilightService.onLocationChanged(invalidLocation);
    assertEquals(mTwilightService.mLastLocation, mInitialLocation);
    assertEquals(priorState, mTwilightService.mLastTwilightState);
}
Also used : Location(android.location.Location)

Aggregations

Location (android.location.Location)290 Bundle (android.os.Bundle)50 LocationListener (android.location.LocationListener)38 LocationManager (android.location.LocationManager)33 ArrayList (java.util.ArrayList)29 Criteria (android.location.Criteria)20 LocationProviderInterface (com.android.server.location.LocationProviderInterface)18 GsmCellLocation (android.telephony.gsm.GsmCellLocation)17 BluetoothAdapter (android.bluetooth.BluetoothAdapter)12 BroadcastReceiver (android.content.BroadcastReceiver)12 Handler (android.os.Handler)10 MockProvider (com.android.server.location.MockProvider)9 Intent (android.content.Intent)8 Timer (java.util.Timer)8 Test (org.junit.Test)8 PendingIntent (android.app.PendingIntent)7 IOException (java.io.IOException)7 LocationProviderProxy (com.android.server.location.LocationProviderProxy)6 HashMap (java.util.HashMap)6 List (java.util.List)6