Search in sources :

Example 36 with WorkSource

use of android.os.WorkSource in project platform_frameworks_base by android.

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) {
            if (DEBUG_KEEP_SCREEN_ON) {
                Slog.d(TAG_KEEP_SCREEN_ON, "Acquiring screen wakelock due to " + mWindowPlacerLocked.mHoldScreenWindow);
            }
            mLastWakeLockHoldingWindow = mWindowPlacerLocked.mHoldScreenWindow;
            mLastWakeLockObscuringWindow = null;
            mHoldingScreenWakeLock.acquire();
            mPolicy.keepScreenOnStartedLw();
        } else {
            if (DEBUG_KEEP_SCREEN_ON) {
                Slog.d(TAG_KEEP_SCREEN_ON, "Releasing screen wakelock, obscured by " + mWindowPlacerLocked.mObsuringWindow);
            }
            mLastWakeLockHoldingWindow = null;
            mLastWakeLockObscuringWindow = mWindowPlacerLocked.mObsuringWindow;
            mPolicy.keepScreenOnStoppedLw();
            mHoldingScreenWakeLock.release();
        }
    }
}
Also used : WorkSource(android.os.WorkSource)

Example 37 with WorkSource

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

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

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

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

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

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

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