Search in sources :

Example 11 with LocationRequest

use of android.location.LocationRequest in project android_frameworks_base by AOSPA.

the class ProviderRequest method writeToParcel.

@Override
public void writeToParcel(Parcel parcel, int flags) {
    parcel.writeInt(reportLocation ? 1 : 0);
    parcel.writeLong(interval);
    parcel.writeInt(locationRequests.size());
    for (LocationRequest request : locationRequests) {
        request.writeToParcel(parcel, flags);
    }
}
Also used : LocationRequest(android.location.LocationRequest)

Example 12 with LocationRequest

use of android.location.LocationRequest in project android_frameworks_base by AOSPA.

the class DeviceIdleController method onBootPhase.

@Override
public void onBootPhase(int phase) {
    if (phase == PHASE_SYSTEM_SERVICES_READY) {
        synchronized (this) {
            mAlarmManager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
            mBatteryStats = BatteryStatsService.getService();
            mLocalPowerManager = getLocalService(PowerManagerInternal.class);
            mPowerManager = getContext().getSystemService(PowerManager.class);
            mActiveIdleWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "deviceidle_maint");
            mActiveIdleWakeLock.setReferenceCounted(false);
            mGoingIdleWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "deviceidle_going_idle");
            mGoingIdleWakeLock.setReferenceCounted(true);
            mConnectivityService = (ConnectivityService) ServiceManager.getService(Context.CONNECTIVITY_SERVICE);
            mLocalAlarmManager = getLocalService(AlarmManagerService.LocalService.class);
            mNetworkPolicyManager = INetworkPolicyManager.Stub.asInterface(ServiceManager.getService(Context.NETWORK_POLICY_SERVICE));
            mDisplayManager = (DisplayManager) getContext().getSystemService(Context.DISPLAY_SERVICE);
            mSensorManager = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE);
            int sigMotionSensorId = getContext().getResources().getInteger(com.android.internal.R.integer.config_autoPowerModeAnyMotionSensor);
            if (sigMotionSensorId > 0) {
                mMotionSensor = mSensorManager.getDefaultSensor(sigMotionSensorId, true);
            }
            if (mMotionSensor == null && getContext().getResources().getBoolean(com.android.internal.R.bool.config_autoPowerModePreferWristTilt)) {
                mMotionSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_WRIST_TILT_GESTURE, true);
            }
            if (mMotionSensor == null) {
                // As a last ditch, fall back to SMD.
                mMotionSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION, true);
            }
            if (getContext().getResources().getBoolean(com.android.internal.R.bool.config_autoPowerModePrefetchLocation)) {
                mLocationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
                mLocationRequest = new LocationRequest().setQuality(LocationRequest.ACCURACY_FINE).setInterval(0).setFastestInterval(0).setNumUpdates(1);
            }
            float angleThreshold = getContext().getResources().getInteger(com.android.internal.R.integer.config_autoPowerModeThresholdAngle) / 100f;
            mAnyMotionDetector = new AnyMotionDetector((PowerManager) getContext().getSystemService(Context.POWER_SERVICE), mHandler, mSensorManager, this, angleThreshold);
            mIdleIntent = new Intent(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
            mIdleIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);
            mLightIdleIntent = new Intent(PowerManager.ACTION_LIGHT_DEVICE_IDLE_MODE_CHANGED);
            mLightIdleIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);
            IntentFilter filter = new IntentFilter();
            filter.addAction(Intent.ACTION_BATTERY_CHANGED);
            getContext().registerReceiver(mReceiver, filter);
            filter = new IntentFilter();
            filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
            filter.addDataScheme("package");
            getContext().registerReceiver(mReceiver, filter);
            filter = new IntentFilter();
            filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
            getContext().registerReceiver(mReceiver, filter);
            mLocalPowerManager.setDeviceIdleWhitelist(mPowerSaveWhitelistAllAppIdArray);
            mLocalAlarmManager.setDeviceIdleUserWhitelist(mPowerSaveWhitelistUserAppIdArray);
            mDisplayManager.registerDisplayListener(mDisplayListener, null);
            updateDisplayLocked();
        }
        updateConnectivityState(null);
    }
}
Also used : PowerManager(android.os.PowerManager) IntentFilter(android.content.IntentFilter) LocationRequest(android.location.LocationRequest) PowerManagerInternal(android.os.PowerManagerInternal) Intent(android.content.Intent)

Example 13 with LocationRequest

use of android.location.LocationRequest in project android_frameworks_base by crdroidandroid.

the class GeofenceManager method updateFences.

/**
     * The geofence update loop. This function removes expired fences, then tests the most
     * recently-received {@link Location} against each registered {@link GeofenceState}, sending
     * {@link Intent}s for geofences that have been tripped. It also adjusts the active location
     * update request with {@link LocationManager} as appropriate for any active geofences.
     */
// Runs on the handler.
private void updateFences() {
    List<PendingIntent> enterIntents = new LinkedList<PendingIntent>();
    List<PendingIntent> exitIntents = new LinkedList<PendingIntent>();
    synchronized (mLock) {
        mPendingUpdate = false;
        // Remove expired fences.
        removeExpiredFencesLocked();
        // Get a location to work with, either received via onLocationChanged() or
        // via LocationManager.getLastLocation().
        Location location = getFreshLocationLocked();
        // Update all fences.
        // Keep track of the distance to the nearest fence.
        double minFenceDistance = Double.MAX_VALUE;
        boolean needUpdates = false;
        for (GeofenceState state : mFences) {
            if (mBlacklist.isBlacklisted(state.mPackageName)) {
                if (D) {
                    Slog.d(TAG, "skipping geofence processing for blacklisted app: " + state.mPackageName);
                }
                continue;
            }
            int op = LocationManagerService.resolutionLevelToOp(state.mAllowedResolutionLevel);
            if (op >= 0) {
                if (mAppOps.noteOpNoThrow(AppOpsManager.OP_FINE_LOCATION, state.mUid, state.mPackageName) != AppOpsManager.MODE_ALLOWED) {
                    if (D) {
                        Slog.d(TAG, "skipping geofence processing for no op app: " + state.mPackageName);
                    }
                    continue;
                }
            }
            needUpdates = true;
            if (location != null) {
                int event = state.processLocation(location);
                if ((event & GeofenceState.FLAG_ENTER) != 0) {
                    enterIntents.add(state.mIntent);
                }
                if ((event & GeofenceState.FLAG_EXIT) != 0) {
                    exitIntents.add(state.mIntent);
                }
                // FIXME: Ideally this code should take into account the accuracy of the
                // location fix that was used to calculate the distance in the first place.
                // MAX_VALUE if unknown
                double fenceDistance = state.getDistanceToBoundary();
                if (fenceDistance < minFenceDistance) {
                    minFenceDistance = fenceDistance;
                }
            }
        }
        // Request or cancel location updates if needed.
        if (needUpdates) {
            // Request location updates.
            // Compute a location update interval based on the distance to the nearest fence.
            long intervalMs;
            if (location != null && Double.compare(minFenceDistance, Double.MAX_VALUE) != 0) {
                intervalMs = (long) Math.min(MAX_INTERVAL_MS, Math.max(MIN_INTERVAL_MS, minFenceDistance * 1000 / MAX_SPEED_M_S));
            } else {
                intervalMs = MIN_INTERVAL_MS;
            }
            if (!mReceivingLocationUpdates || mLocationUpdateInterval != intervalMs) {
                mReceivingLocationUpdates = true;
                mLocationUpdateInterval = intervalMs;
                mLastLocationUpdate = location;
                LocationRequest request = new LocationRequest();
                request.setInterval(intervalMs).setFastestInterval(0);
                mLocationManager.requestLocationUpdates(request, this, mHandler.getLooper());
            }
        } else {
            // Cancel location updates.
            if (mReceivingLocationUpdates) {
                mReceivingLocationUpdates = false;
                mLocationUpdateInterval = 0;
                mLastLocationUpdate = null;
                mLocationManager.removeUpdates(this);
            }
        }
        if (D) {
            Slog.d(TAG, "updateFences: location=" + location + ", mFences.size()=" + mFences.size() + ", mReceivingLocationUpdates=" + mReceivingLocationUpdates + ", mLocationUpdateInterval=" + mLocationUpdateInterval + ", mLastLocationUpdate=" + mLastLocationUpdate);
        }
    }
    // release lock before sending intents
    for (PendingIntent intent : exitIntents) {
        sendIntentExit(intent);
    }
    for (PendingIntent intent : enterIntents) {
        sendIntentEnter(intent);
    }
}
Also used : LocationRequest(android.location.LocationRequest) PendingIntent(android.app.PendingIntent) LinkedList(java.util.LinkedList) Location(android.location.Location)

Example 14 with LocationRequest

use of android.location.LocationRequest in project android_frameworks_base by crdroidandroid.

the class GnssLocationProvider method updateRequirements.

// Called when the requirements for GPS may have changed
private void updateRequirements() {
    if (mProviderRequest == null || mWorkSource == null) {
        return;
    }
    boolean singleShot = false;
    // see if the request is for a single update
    if (mProviderRequest.locationRequests != null && mProviderRequest.locationRequests.size() > 0) {
        // if any request has zero or more than one updates
        // requested, then this is not single-shot mode
        singleShot = true;
        for (LocationRequest lr : mProviderRequest.locationRequests) {
            if (lr.getNumUpdates() != 1) {
                singleShot = false;
            }
        }
    }
    if (DEBUG)
        Log.d(TAG, "setRequest " + mProviderRequest);
    if (mProviderRequest.reportLocation && !mDisableGps && isEnabled()) {
        // update client uids
        updateClientUids(mWorkSource);
        mFixInterval = (int) mProviderRequest.interval;
        // check for overflow
        if (mFixInterval != mProviderRequest.interval) {
            Log.w(TAG, "interval overflow: " + mProviderRequest.interval);
            mFixInterval = Integer.MAX_VALUE;
        }
        // apply request to GPS engine
        if (mStarted && hasCapability(GPS_CAPABILITY_SCHEDULING)) {
            // change period
            if (!native_set_position_mode(mPositionMode, GPS_POSITION_RECURRENCE_PERIODIC, mFixInterval, 0, 0)) {
                Log.e(TAG, "set_position_mode failed in setMinTime()");
            }
        } else if (!mStarted) {
            // start GPS
            startNavigating(singleShot);
        }
    } else {
        updateClientUids(new WorkSource());
        stopNavigating();
        mAlarmManager.cancel(mWakeupIntent);
        mAlarmManager.cancel(mTimeoutIntent);
    }
}
Also used : LocationRequest(android.location.LocationRequest) WorkSource(android.os.WorkSource)

Example 15 with LocationRequest

use of android.location.LocationRequest in project android_frameworks_base by crdroidandroid.

the class DeviceIdleController method onBootPhase.

@Override
public void onBootPhase(int phase) {
    if (phase == PHASE_SYSTEM_SERVICES_READY) {
        synchronized (this) {
            mAlarmManager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
            mBatteryStats = BatteryStatsService.getService();
            mLocalPowerManager = getLocalService(PowerManagerInternal.class);
            mPowerManager = getContext().getSystemService(PowerManager.class);
            mActiveIdleWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "deviceidle_maint");
            mActiveIdleWakeLock.setReferenceCounted(false);
            mGoingIdleWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "deviceidle_going_idle");
            mGoingIdleWakeLock.setReferenceCounted(true);
            mConnectivityService = (ConnectivityService) ServiceManager.getService(Context.CONNECTIVITY_SERVICE);
            mLocalAlarmManager = getLocalService(AlarmManagerService.LocalService.class);
            mNetworkPolicyManager = INetworkPolicyManager.Stub.asInterface(ServiceManager.getService(Context.NETWORK_POLICY_SERVICE));
            mDisplayManager = (DisplayManager) getContext().getSystemService(Context.DISPLAY_SERVICE);
            mSensorManager = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE);
            int sigMotionSensorId = getContext().getResources().getInteger(com.android.internal.R.integer.config_autoPowerModeAnyMotionSensor);
            if (sigMotionSensorId > 0) {
                mMotionSensor = mSensorManager.getDefaultSensor(sigMotionSensorId, true);
            }
            if (mMotionSensor == null && getContext().getResources().getBoolean(com.android.internal.R.bool.config_autoPowerModePreferWristTilt)) {
                mMotionSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_WRIST_TILT_GESTURE, true);
            }
            if (mMotionSensor == null) {
                // As a last ditch, fall back to SMD.
                mMotionSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION, true);
            }
            if (getContext().getResources().getBoolean(com.android.internal.R.bool.config_autoPowerModePrefetchLocation)) {
                mLocationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
                mLocationRequest = new LocationRequest().setQuality(LocationRequest.ACCURACY_FINE).setInterval(0).setFastestInterval(0).setNumUpdates(1);
            }
            float angleThreshold = getContext().getResources().getInteger(com.android.internal.R.integer.config_autoPowerModeThresholdAngle) / 100f;
            mAnyMotionDetector = new AnyMotionDetector((PowerManager) getContext().getSystemService(Context.POWER_SERVICE), mHandler, mSensorManager, this, angleThreshold);
            mIdleIntent = new Intent(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
            mIdleIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);
            mLightIdleIntent = new Intent(PowerManager.ACTION_LIGHT_DEVICE_IDLE_MODE_CHANGED);
            mLightIdleIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);
            IntentFilter filter = new IntentFilter();
            filter.addAction(Intent.ACTION_BATTERY_CHANGED);
            getContext().registerReceiver(mReceiver, filter);
            filter = new IntentFilter();
            filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
            filter.addDataScheme("package");
            getContext().registerReceiver(mReceiver, filter);
            filter = new IntentFilter();
            filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
            getContext().registerReceiver(mReceiver, filter);
            mLocalPowerManager.setDeviceIdleWhitelist(mPowerSaveWhitelistAllAppIdArray);
            mLocalAlarmManager.setDeviceIdleUserWhitelist(mPowerSaveWhitelistUserAppIdArray);
            mDisplayManager.registerDisplayListener(mDisplayListener, null);
            updateDisplayLocked();
        }
        updateConnectivityState(null);
    }
}
Also used : PowerManager(android.os.PowerManager) IntentFilter(android.content.IntentFilter) LocationRequest(android.location.LocationRequest) PowerManagerInternal(android.os.PowerManagerInternal) Intent(android.content.Intent)

Aggregations

LocationRequest (android.location.LocationRequest)41 WorkSource (android.os.WorkSource)17 PendingIntent (android.app.PendingIntent)6 BroadcastReceiver (android.content.BroadcastReceiver)6 Location (android.location.Location)6 ProviderRequest (com.android.internal.location.ProviderRequest)6 LocationProviderInterface (com.android.server.location.LocationProviderInterface)6 LinkedList (java.util.LinkedList)6 Intent (android.content.Intent)5 IntentFilter (android.content.IntentFilter)5 PowerManager (android.os.PowerManager)5 PowerManagerInternal (android.os.PowerManagerInternal)5 GeoFenceParams (android.location.GeoFenceParams)1