Search in sources :

Example 31 with LocationRequest

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

the class LocationManagerService method requestGeofence.

@Override
public void requestGeofence(LocationRequest request, Geofence geofence, PendingIntent intent, String packageName) {
    if (request == null)
        request = DEFAULT_LOCATION_REQUEST;
    int allowedResolutionLevel = getCallerAllowedResolutionLevel();
    checkResolutionLevelIsSufficientForGeofenceUse(allowedResolutionLevel);
    checkPendingIntent(intent);
    checkPackageName(packageName);
    checkResolutionLevelIsSufficientForProviderUse(allowedResolutionLevel, request.getProvider());
    LocationRequest sanitizedRequest = createSanitizedRequest(request, allowedResolutionLevel);
    if (D)
        Log.d(TAG, "requestGeofence: " + sanitizedRequest + " " + geofence + " " + intent);
    // geo-fence manager uses the public location API, need to clear identity
    int uid = Binder.getCallingUid();
    // TODO: http://b/23822629
    if (UserHandle.getUserId(uid) != UserHandle.USER_SYSTEM) {
        // temporary measure until geofences work for secondary users
        Log.w(TAG, "proximity alerts are currently available only to the primary user");
        return;
    }
    long identity = Binder.clearCallingIdentity();
    try {
        mGeofenceManager.addFence(sanitizedRequest, geofence, intent, allowedResolutionLevel, uid, packageName);
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
Also used : LocationRequest(android.location.LocationRequest)

Example 32 with LocationRequest

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

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 33 with LocationRequest

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

the class LocationManagerService method applyRequirementsLocked.

private void applyRequirementsLocked(String provider) {
    LocationProviderInterface p = mProvidersByName.get(provider);
    if (p == null)
        return;
    ArrayList<UpdateRecord> records = mRecordsByProvider.get(provider);
    WorkSource worksource = new WorkSource();
    ProviderRequest providerRequest = new ProviderRequest();
    if (records != null) {
        for (UpdateRecord record : records) {
            if (isCurrentProfile(UserHandle.getUserId(record.mReceiver.mUid))) {
                if (checkLocationAccess(record.mReceiver.mPid, record.mReceiver.mUid, record.mReceiver.mPackageName, record.mReceiver.mAllowedResolutionLevel)) {
                    LocationRequest locationRequest = record.mRequest;
                    providerRequest.locationRequests.add(locationRequest);
                    if (locationRequest.getInterval() < providerRequest.interval) {
                        providerRequest.reportLocation = true;
                        providerRequest.interval = locationRequest.getInterval();
                    }
                }
            }
        }
        if (providerRequest.reportLocation) {
            // calculate who to blame for power
            // This is somewhat arbitrary. We pick a threshold interval
            // that is slightly higher that the minimum interval, and
            // spread the blame across all applications with a request
            // under that threshold.
            long thresholdInterval = (providerRequest.interval + 1000) * 3 / 2;
            for (UpdateRecord record : records) {
                if (isCurrentProfile(UserHandle.getUserId(record.mReceiver.mUid))) {
                    LocationRequest locationRequest = record.mRequest;
                    // client has no permission to receive location data.
                    if (!providerRequest.locationRequests.contains(locationRequest)) {
                        continue;
                    }
                    if (locationRequest.getInterval() <= thresholdInterval) {
                        if (record.mReceiver.mWorkSource != null && record.mReceiver.mWorkSource.size() > 0 && record.mReceiver.mWorkSource.getName(0) != null) {
                            // Assign blame to another work source.
                            // Can only assign blame if the WorkSource contains names.
                            worksource.add(record.mReceiver.mWorkSource);
                        } else {
                            // Assign blame to caller.
                            worksource.add(record.mReceiver.mUid, record.mReceiver.mPackageName);
                        }
                    }
                }
            }
        }
    }
    if (D)
        Log.d(TAG, "provider request: " + provider + " " + providerRequest);
    p.setRequest(providerRequest, worksource);
}
Also used : LocationRequest(android.location.LocationRequest) WorkSource(android.os.WorkSource) LocationProviderInterface(com.android.server.location.LocationProviderInterface) ProviderRequest(com.android.internal.location.ProviderRequest)

Example 34 with LocationRequest

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

the class LocationManagerService method requestLocationUpdates.

@Override
public void requestLocationUpdates(LocationRequest request, ILocationListener listener, PendingIntent intent, String packageName) {
    if (request == null)
        request = DEFAULT_LOCATION_REQUEST;
    checkPackageName(packageName);
    int allowedResolutionLevel = getCallerAllowedResolutionLevel();
    checkResolutionLevelIsSufficientForProviderUse(allowedResolutionLevel, request.getProvider());
    WorkSource workSource = request.getWorkSource();
    if (workSource != null && workSource.size() > 0) {
        checkDeviceStatsAllowed();
    }
    boolean hideFromAppOps = request.getHideFromAppOps();
    if (hideFromAppOps) {
        checkUpdateAppOpsAllowed();
    }
    LocationRequest sanitizedRequest = createSanitizedRequest(request, allowedResolutionLevel);
    final int pid = Binder.getCallingPid();
    final int uid = Binder.getCallingUid();
    // providers may use public location API's, need to clear identity
    long identity = Binder.clearCallingIdentity();
    try {
        // We don't check for MODE_IGNORED here; we will do that when we go to deliver
        // a location.
        checkLocationAccess(pid, uid, packageName, allowedResolutionLevel);
        synchronized (mLock) {
            Receiver recevier = checkListenerOrIntentLocked(listener, intent, pid, uid, packageName, workSource, hideFromAppOps);
            requestLocationUpdatesLocked(sanitizedRequest, recevier, pid, uid, packageName);
        }
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
Also used : LocationRequest(android.location.LocationRequest) BroadcastReceiver(android.content.BroadcastReceiver) WorkSource(android.os.WorkSource)

Example 35 with LocationRequest

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

the class LocationManagerService method requestLocationUpdates.

@Override
public void requestLocationUpdates(LocationRequest request, ILocationListener listener, PendingIntent intent, String packageName) {
    if (request == null)
        request = DEFAULT_LOCATION_REQUEST;
    checkPackageName(packageName);
    int allowedResolutionLevel = getCallerAllowedResolutionLevel();
    checkResolutionLevelIsSufficientForProviderUse(allowedResolutionLevel, request.getProvider());
    WorkSource workSource = request.getWorkSource();
    if (workSource != null && workSource.size() > 0) {
        checkDeviceStatsAllowed();
    }
    boolean hideFromAppOps = request.getHideFromAppOps();
    if (hideFromAppOps) {
        checkUpdateAppOpsAllowed();
    }
    LocationRequest sanitizedRequest = createSanitizedRequest(request, allowedResolutionLevel);
    final int pid = Binder.getCallingPid();
    final int uid = Binder.getCallingUid();
    // providers may use public location API's, need to clear identity
    long identity = Binder.clearCallingIdentity();
    try {
        // We don't check for MODE_IGNORED here; we will do that when we go to deliver
        // a location.
        checkLocationAccess(pid, uid, packageName, allowedResolutionLevel);
        synchronized (mLock) {
            Receiver recevier = checkListenerOrIntentLocked(listener, intent, pid, uid, packageName, workSource, hideFromAppOps);
            requestLocationUpdatesLocked(sanitizedRequest, recevier, pid, uid, packageName);
        }
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
Also used : LocationRequest(android.location.LocationRequest) BroadcastReceiver(android.content.BroadcastReceiver) WorkSource(android.os.WorkSource)

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