Search in sources :

Example 56 with WorkSource

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

the class JobServiceContext method onServiceConnected.

/**
     * We acquire/release a wakelock on onServiceConnected/unbindService. This mirrors the work
     * we intend to send to the client - we stop sending work when the service is unbound so until
     * then we keep the wakelock.
     * @param name The concrete component name of the service that has been connected.
     * @param service The IBinder of the Service's communication channel,
     */
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
    JobStatus runningJob;
    synchronized (mLock) {
        // This isn't strictly necessary b/c the JobServiceHandler is running on the main
        // looper and at this point we can't get any binder callbacks from the client. Better
        // safe than sorry.
        runningJob = mRunningJob;
    }
    if (runningJob == null || !name.equals(runningJob.getServiceComponent())) {
        mCallbackHandler.obtainMessage(MSG_SHUTDOWN_EXECUTION).sendToTarget();
        return;
    }
    this.service = IJobService.Stub.asInterface(service);
    final PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, runningJob.getTag());
    wl.setWorkSource(new WorkSource(runningJob.getSourceUid()));
    wl.setReferenceCounted(false);
    wl.acquire();
    synchronized (mLock) {
        // explicitly fast-forward the release if we're in that situation.
        if (mWakeLock != null) {
            Slog.w(TAG, "Bound new job " + runningJob + " but live wakelock " + mWakeLock + " tag=" + mWakeLock.getTag());
            mWakeLock.release();
        }
        mWakeLock = wl;
    }
    mCallbackHandler.obtainMessage(MSG_SERVICE_BOUND).sendToTarget();
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus) PowerManager(android.os.PowerManager) WorkSource(android.os.WorkSource)

Example 57 with WorkSource

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

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

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

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

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

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

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

the class WindowState method pokeDrawLockLw.

public void pokeDrawLockLw(long timeout) {
    if (isVisibleOrAdding()) {
        if (mDrawLock == null) {
            // We want the tag name to be somewhat stable so that it is easier to correlate
            // in wake lock statistics.  So in particular, we don't want to include the
            // window's hash code as in toString().
            final CharSequence tag = getWindowTag();
            mDrawLock = mService.mPowerManager.newWakeLock(PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
            mDrawLock.setReferenceCounted(false);
            mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
        }
        // Each call to acquire resets the timeout.
        if (DEBUG_POWER) {
            Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by " + mAttrs.packageName);
        }
        mDrawLock.acquire(timeout);
    } else if (DEBUG_POWER) {
        Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window " + "owned by " + mAttrs.packageName);
    }
}
Also used : 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