Search in sources :

Example 36 with PendingIntent

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);
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 37 with PendingIntent

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);
    }
}
Also used : LocationRequest(android.location.LocationRequest) PendingIntent(android.app.PendingIntent) LinkedList(java.util.LinkedList) Location(android.location.Location)

Example 38 with PendingIntent

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);
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 39 with PendingIntent

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);
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 40 with PendingIntent

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);
    }
}
Also used : Bundle(android.os.Bundle) PlaybackInfo(android.media.session.MediaController.PlaybackInfo) MediaMetadata(android.media.MediaMetadata) PlaybackState(android.media.session.PlaybackState) QueueItem(android.media.session.MediaSession.QueueItem) PendingIntent(android.app.PendingIntent)

Aggregations

PendingIntent (android.app.PendingIntent)1243 Intent (android.content.Intent)1043 Notification (android.app.Notification)233 NotificationCompat (android.support.v4.app.NotificationCompat)184 NotificationManager (android.app.NotificationManager)160 AlarmManager (android.app.AlarmManager)153 Bundle (android.os.Bundle)78 RemoteViews (android.widget.RemoteViews)67 RemoteException (android.os.RemoteException)64 Resources (android.content.res.Resources)63 Bitmap (android.graphics.Bitmap)62 Context (android.content.Context)59 ComponentName (android.content.ComponentName)56 Uri (android.net.Uri)45 Test (org.junit.Test)44 IntentFilter (android.content.IntentFilter)43 SharedPreferences (android.content.SharedPreferences)38 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)34 UserHandle (android.os.UserHandle)31 IOException (java.io.IOException)30