Search in sources :

Example 11 with WorkSource

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

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

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

the class GnssLocationProvider method handleDisable.

private void handleDisable() {
    if (DEBUG)
        Log.d(TAG, "handleDisable");
    updateClientUids(new WorkSource());
    stopNavigating();
    mAlarmManager.cancel(mWakeupIntent);
    mAlarmManager.cancel(mTimeoutIntent);
    // do this before releasing wakelock
    native_cleanup();
    mGnssMeasurementsProvider.onGpsEnabledChanged();
    mGnssNavigationMessageProvider.onGpsEnabledChanged();
}
Also used : WorkSource(android.os.WorkSource)

Example 13 with WorkSource

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

the class GnssLocationProvider method updateClientUids.

private void updateClientUids(WorkSource source) {
    // Update work source.
    WorkSource[] changes = mClientSource.setReturningDiffs(source);
    if (changes == null) {
        return;
    }
    WorkSource newWork = changes[0];
    WorkSource goneWork = changes[1];
    // Update sources that were not previously tracked.
    if (newWork != null) {
        int lastuid = -1;
        for (int i = 0; i < newWork.size(); i++) {
            try {
                int uid = newWork.get(i);
                mAppOpsService.startOperation(AppOpsManager.getToken(mAppOpsService), AppOpsManager.OP_GPS, uid, newWork.getName(i));
                if (uid != lastuid) {
                    lastuid = uid;
                    mBatteryStats.noteStartGps(uid);
                }
            } catch (RemoteException e) {
                Log.w(TAG, "RemoteException", e);
            }
        }
    }
    // Update sources that are no longer tracked.
    if (goneWork != null) {
        int lastuid = -1;
        for (int i = 0; i < goneWork.size(); i++) {
            try {
                int uid = goneWork.get(i);
                mAppOpsService.finishOperation(AppOpsManager.getToken(mAppOpsService), AppOpsManager.OP_GPS, uid, goneWork.getName(i));
                if (uid != lastuid) {
                    lastuid = uid;
                    mBatteryStats.noteStopGps(uid);
                }
            } catch (RemoteException e) {
                Log.w(TAG, "RemoteException", e);
            }
        }
    }
}
Also used : WorkSource(android.os.WorkSource) RemoteException(android.os.RemoteException)

Example 14 with WorkSource

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

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 WorkSource

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

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)

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