use of android.app.PendingIntent in project platform_frameworks_base by android.
the class GeofenceManager method sendIntentExit.
private void sendIntentExit(PendingIntent pendingIntent) {
if (D) {
Slog.d(TAG, "sendIntentExit: pendingIntent=" + pendingIntent);
}
Intent intent = new Intent();
intent.putExtra(LocationManager.KEY_PROXIMITY_ENTERING, false);
sendIntent(pendingIntent, intent);
}
use of android.app.PendingIntent in project platform_frameworks_base by android.
the class GeofenceManager method updateFences.
/**
* The geofence update loop. This function removes expired fences, then tests the most
* recently-received {@link Location} against each registered {@link GeofenceState}, sending
* {@link Intent}s for geofences that have been tripped. It also adjusts the active location
* update request with {@link LocationManager} as appropriate for any active geofences.
*/
// Runs on the handler.
private void updateFences() {
List<PendingIntent> enterIntents = new LinkedList<PendingIntent>();
List<PendingIntent> exitIntents = new LinkedList<PendingIntent>();
synchronized (mLock) {
mPendingUpdate = false;
// Remove expired fences.
removeExpiredFencesLocked();
// Get a location to work with, either received via onLocationChanged() or
// via LocationManager.getLastLocation().
Location location = getFreshLocationLocked();
// Update all fences.
// Keep track of the distance to the nearest fence.
double minFenceDistance = Double.MAX_VALUE;
boolean needUpdates = false;
for (GeofenceState state : mFences) {
if (mBlacklist.isBlacklisted(state.mPackageName)) {
if (D) {
Slog.d(TAG, "skipping geofence processing for blacklisted app: " + state.mPackageName);
}
continue;
}
int op = LocationManagerService.resolutionLevelToOp(state.mAllowedResolutionLevel);
if (op >= 0) {
if (mAppOps.noteOpNoThrow(AppOpsManager.OP_FINE_LOCATION, state.mUid, state.mPackageName) != AppOpsManager.MODE_ALLOWED) {
if (D) {
Slog.d(TAG, "skipping geofence processing for no op app: " + state.mPackageName);
}
continue;
}
}
needUpdates = true;
if (location != null) {
int event = state.processLocation(location);
if ((event & GeofenceState.FLAG_ENTER) != 0) {
enterIntents.add(state.mIntent);
}
if ((event & GeofenceState.FLAG_EXIT) != 0) {
exitIntents.add(state.mIntent);
}
// FIXME: Ideally this code should take into account the accuracy of the
// location fix that was used to calculate the distance in the first place.
// MAX_VALUE if unknown
double fenceDistance = state.getDistanceToBoundary();
if (fenceDistance < minFenceDistance) {
minFenceDistance = fenceDistance;
}
}
}
// Request or cancel location updates if needed.
if (needUpdates) {
// Request location updates.
// Compute a location update interval based on the distance to the nearest fence.
long intervalMs;
if (location != null && Double.compare(minFenceDistance, Double.MAX_VALUE) != 0) {
intervalMs = (long) Math.min(MAX_INTERVAL_MS, Math.max(MIN_INTERVAL_MS, minFenceDistance * 1000 / MAX_SPEED_M_S));
} else {
intervalMs = MIN_INTERVAL_MS;
}
if (!mReceivingLocationUpdates || mLocationUpdateInterval != intervalMs) {
mReceivingLocationUpdates = true;
mLocationUpdateInterval = intervalMs;
mLastLocationUpdate = location;
LocationRequest request = new LocationRequest();
request.setInterval(intervalMs).setFastestInterval(0);
mLocationManager.requestLocationUpdates(request, this, mHandler.getLooper());
}
} else {
// Cancel location updates.
if (mReceivingLocationUpdates) {
mReceivingLocationUpdates = false;
mLocationUpdateInterval = 0;
mLastLocationUpdate = null;
mLocationManager.removeUpdates(this);
}
}
if (D) {
Slog.d(TAG, "updateFences: location=" + location + ", mFences.size()=" + mFences.size() + ", mReceivingLocationUpdates=" + mReceivingLocationUpdates + ", mLocationUpdateInterval=" + mLocationUpdateInterval + ", mLastLocationUpdate=" + mLastLocationUpdate);
}
}
// release lock before sending intents
for (PendingIntent intent : exitIntents) {
sendIntentExit(intent);
}
for (PendingIntent intent : enterIntents) {
sendIntentEnter(intent);
}
}
use of android.app.PendingIntent in project platform_frameworks_base by android.
the class NotificationController method createRestartIntent.
private PendingIntent createRestartIntent(PrintJobId printJobId) {
Intent intent = new Intent(mContext, NotificationBroadcastReceiver.class);
intent.setAction(INTENT_ACTION_RESTART_PRINTJOB + "_" + printJobId.flattenToString());
intent.putExtra(EXTRA_PRINT_JOB_ID, printJobId);
return PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT);
}
use of android.app.PendingIntent in project platform_frameworks_base by android.
the class NotificationController method createCancelIntent.
private PendingIntent createCancelIntent(PrintJobInfo printJob) {
Intent intent = new Intent(mContext, NotificationBroadcastReceiver.class);
intent.setAction(INTENT_ACTION_CANCEL_PRINTJOB + "_" + printJob.getId().flattenToString());
intent.putExtra(EXTRA_PRINT_JOB_ID, printJob.getId());
return PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT);
}
use of android.app.PendingIntent in project platform_frameworks_base by android.
the class MediaSessions method dump.
private static void dump(int n, PrintWriter writer, MediaController c) {
writer.println(" Controller " + n + ": " + c.getPackageName());
final Bundle extras = c.getExtras();
final long flags = c.getFlags();
final MediaMetadata mm = c.getMetadata();
final PlaybackInfo pi = c.getPlaybackInfo();
final PlaybackState playbackState = c.getPlaybackState();
final List<QueueItem> queue = c.getQueue();
final CharSequence queueTitle = c.getQueueTitle();
final int ratingType = c.getRatingType();
final PendingIntent sessionActivity = c.getSessionActivity();
writer.println(" PlaybackState: " + Util.playbackStateToString(playbackState));
writer.println(" PlaybackInfo: " + Util.playbackInfoToString(pi));
if (mm != null) {
writer.println(" MediaMetadata.desc=" + mm.getDescription());
}
writer.println(" RatingType: " + ratingType);
writer.println(" Flags: " + flags);
if (extras != null) {
writer.println(" Extras:");
for (String key : extras.keySet()) {
writer.println(" " + key + "=" + extras.get(key));
}
}
if (queueTitle != null) {
writer.println(" QueueTitle: " + queueTitle);
}
if (queue != null && !queue.isEmpty()) {
writer.println(" Queue:");
for (QueueItem qi : queue) {
writer.println(" " + qi);
}
}
if (pi != null) {
writer.println(" sessionActivity: " + sessionActivity);
}
}
Aggregations