use of android.os.WorkSource in project platform_frameworks_base by android.
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);
}
use of android.os.WorkSource in project platform_frameworks_base by android.
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);
}
}
use of android.os.WorkSource in project android_frameworks_base by ParanoidAndroid.
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 (UserHandle.getUserId(record.mReceiver.mUid) == mCurrentUserId) {
if (checkLocationAccess(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 (UserHandle.getUserId(record.mReceiver.mUid) == mCurrentUserId) {
LocationRequest locationRequest = record.mRequest;
if (locationRequest.getInterval() <= thresholdInterval) {
worksource.add(record.mReceiver.mUid, record.mReceiver.mPackageName);
}
}
}
}
}
if (D)
Log.d(TAG, "provider request: " + provider + " " + providerRequest);
p.setRequest(providerRequest, worksource);
}
use of android.os.WorkSource in project android_frameworks_base by ParanoidAndroid.
the class GpsLocationProvider method handleSetRequest.
private void handleSetRequest(ProviderRequest request, WorkSource source) {
boolean singleShot = false;
// see if the request is for a single update
if (request.locationRequests != null && request.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 : request.locationRequests) {
if (lr.getNumUpdates() != 1) {
singleShot = false;
}
}
}
if (DEBUG)
Log.d(TAG, "setRequest " + request);
if (request.reportLocation) {
// update client uids
updateClientUids(source);
mFixInterval = (int) request.interval;
// check for overflow
if (mFixInterval != request.interval) {
Log.w(TAG, "interval overflow: " + request.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);
}
}
use of android.os.WorkSource in project android_frameworks_base by ParanoidAndroid.
the class WindowManagerService method setHoldScreenLocked.
void setHoldScreenLocked(final Session newHoldScreen) {
final boolean hold = newHoldScreen != null;
if (hold && mHoldingScreenOn != newHoldScreen) {
mHoldingScreenWakeLock.setWorkSource(new WorkSource(newHoldScreen.mUid));
}
mHoldingScreenOn = newHoldScreen;
final boolean state = mHoldingScreenWakeLock.isHeld();
if (hold != state) {
if (hold) {
mHoldingScreenWakeLock.acquire();
mPolicy.keepScreenOnStartedLw();
} else {
mPolicy.keepScreenOnStoppedLw();
mHoldingScreenWakeLock.release();
}
}
}
Aggregations