Search in sources :

Example 16 with WorkSource

use of android.os.WorkSource 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 17 with WorkSource

use of android.os.WorkSource in project android_frameworks_base by crdroidandroid.

the class AlarmManagerService method setWakelockWorkSource.

/**
     * Attribute blame for a WakeLock.
     * @param pi PendingIntent to attribute blame to if ws is null.
     * @param ws WorkSource to attribute blame.
     * @param knownUid attribution uid; < 0 if we need to derive it from the PendingIntent sender
     */
void setWakelockWorkSource(PendingIntent pi, WorkSource ws, int type, String tag, int knownUid, boolean first) {
    try {
        final boolean unimportant = pi == mTimeTickSender;
        mWakeLock.setUnimportantForLogging(unimportant);
        if (first || mLastWakeLockUnimportantForLogging) {
            mWakeLock.setHistoryTag(tag);
        } else {
            mWakeLock.setHistoryTag(null);
        }
        mLastWakeLockUnimportantForLogging = unimportant;
        if (ws != null) {
            mWakeLock.setWorkSource(ws);
            return;
        }
        final int uid = (knownUid >= 0) ? knownUid : ActivityManagerNative.getDefault().getUidForIntentSender(pi.getTarget());
        if (uid >= 0) {
            mWakeLock.setWorkSource(new WorkSource(uid));
            return;
        }
        // Something went wrong; fall back to attributing the lock to the OS
        mWakeLock.setWorkSource(null);
    } catch (Exception e) {
    }
}
Also used : WorkSource(android.os.WorkSource) RemoteException(android.os.RemoteException)

Example 18 with WorkSource

use of android.os.WorkSource in project android_frameworks_base by crdroidandroid.

the class LocationManagerService method removeUpdates.

@Override
public void removeUpdates(ILocationListener listener, PendingIntent intent, String packageName) {
    checkPackageName(packageName);
    final int pid = Binder.getCallingPid();
    final int uid = Binder.getCallingUid();
    synchronized (mLock) {
        WorkSource workSource = null;
        boolean hideFromAppOps = false;
        Receiver receiver = checkListenerOrIntentLocked(listener, intent, pid, uid, packageName, workSource, hideFromAppOps);
        // providers may use public location API's, need to clear identity
        long identity = Binder.clearCallingIdentity();
        try {
            removeUpdatesLocked(receiver);
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
    }
}
Also used : BroadcastReceiver(android.content.BroadcastReceiver) WorkSource(android.os.WorkSource)

Example 19 with WorkSource

use of android.os.WorkSource in project android_frameworks_base by crdroidandroid.

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 20 with WorkSource

use of android.os.WorkSource in project android_frameworks_base by AOSPA.

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

WorkSource (android.os.WorkSource)60 LocationRequest (android.location.LocationRequest)17 RemoteException (android.os.RemoteException)11 BroadcastReceiver (android.content.BroadcastReceiver)10 ProviderRequest (com.android.internal.location.ProviderRequest)6 LocationProviderInterface (com.android.server.location.LocationProviderInterface)6 PowerManager (android.os.PowerManager)5 JobStatus (com.android.server.job.controllers.JobStatus)5