use of android.os.WorkSource in project android_frameworks_base by ParanoidAndroid.
the class WifiService method acquireWifiLock.
public boolean acquireWifiLock(IBinder binder, int lockMode, String tag, WorkSource ws) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WAKE_LOCK, null);
if (lockMode != WifiManager.WIFI_MODE_FULL && lockMode != WifiManager.WIFI_MODE_SCAN_ONLY && lockMode != WifiManager.WIFI_MODE_FULL_HIGH_PERF) {
Slog.e(TAG, "Illegal argument, lockMode= " + lockMode);
if (DBG)
throw new IllegalArgumentException("lockMode=" + lockMode);
return false;
}
if (ws != null && ws.size() == 0) {
ws = null;
}
if (ws != null) {
enforceWakeSourcePermission(Binder.getCallingUid(), Binder.getCallingPid());
}
if (ws == null) {
ws = new WorkSource(Binder.getCallingUid());
}
WifiLock wifiLock = new WifiLock(lockMode, tag, binder, ws);
synchronized (mLocks) {
return acquireWifiLockLocked(wifiLock);
}
}
use of android.os.WorkSource in project android_frameworks_base by ResurrectionRemix.
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) {
}
}
use of android.os.WorkSource in project android_frameworks_base by ResurrectionRemix.
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();
}
use of android.os.WorkSource in project android_frameworks_base by ResurrectionRemix.
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);
}
}
}
}
use of android.os.WorkSource in project android_frameworks_base by ResurrectionRemix.
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);
}
}
Aggregations