Search in sources :

Example 1 with NotificationManagerService

use of com.android.server.NotificationManagerService in project android_frameworks_base by ParanoidAndroid.

the class ServiceRecord method postNotification.

public void postNotification() {
    final int appUid = appInfo.uid;
    final int appPid = app.pid;
    if (foregroundId != 0 && foregroundNoti != null) {
        // Do asynchronous communication with notification manager to
        // avoid deadlocks.
        final String localPackageName = packageName;
        final int localForegroundId = foregroundId;
        final Notification localForegroundNoti = foregroundNoti;
        ams.mHandler.post(new Runnable() {

            public void run() {
                NotificationManagerService nm = (NotificationManagerService) NotificationManager.getService();
                if (nm == null) {
                    return;
                }
                try {
                    if (localForegroundNoti.icon == 0) {
                        // It is not correct for the caller to supply a notification
                        // icon, but this used to be able to slip through, so for
                        // those dirty apps give it the app's icon.
                        localForegroundNoti.icon = appInfo.icon;
                        // Do not allow apps to present a sneaky invisible content view either.
                        localForegroundNoti.contentView = null;
                        localForegroundNoti.bigContentView = null;
                        CharSequence appName = appInfo.loadLabel(ams.mContext.getPackageManager());
                        if (appName == null) {
                            appName = appInfo.packageName;
                        }
                        Context ctx = null;
                        try {
                            ctx = ams.mContext.createPackageContext(appInfo.packageName, 0);
                            Intent runningIntent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            runningIntent.setData(Uri.fromParts("package", appInfo.packageName, null));
                            PendingIntent pi = PendingIntent.getActivity(ams.mContext, 0, runningIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                            localForegroundNoti.setLatestEventInfo(ctx, ams.mContext.getString(com.android.internal.R.string.app_running_notification_title, appName), ams.mContext.getString(com.android.internal.R.string.app_running_notification_text, appName), pi);
                        } catch (PackageManager.NameNotFoundException e) {
                            localForegroundNoti.icon = 0;
                        }
                    }
                    if (localForegroundNoti.icon == 0) {
                        // being foreground.
                        throw new RuntimeException("icon must be non-zero");
                    }
                    int[] outId = new int[1];
                    nm.enqueueNotificationInternal(localPackageName, localPackageName, appUid, appPid, null, localForegroundId, localForegroundNoti, outId, userId);
                } catch (RuntimeException e) {
                    Slog.w(ActivityManagerService.TAG, "Error showing notification for service", e);
                    // If it gave us a garbage notification, it doesn't
                    // get to be foreground.
                    ams.setServiceForeground(name, ServiceRecord.this, 0, null, true);
                    ams.crashApplication(appUid, appPid, localPackageName, "Bad notification for startForeground: " + e);
                }
            }
        });
    }
}
Also used : NotificationManagerService(com.android.server.NotificationManagerService) Context(android.content.Context) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Aggregations

Notification (android.app.Notification)1 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1 Intent (android.content.Intent)1 NotificationManagerService (com.android.server.NotificationManagerService)1