Search in sources :

Example 1 with NotificationManagerInternal

use of com.android.server.notification.NotificationManagerInternal in project platform_frameworks_base by android.

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 _foregroundNoti = foregroundNoti;
        ams.mHandler.post(new Runnable() {

            public void run() {
                NotificationManagerInternal nm = LocalServices.getService(NotificationManagerInternal.class);
                if (nm == null) {
                    return;
                }
                Notification localForegroundNoti = _foregroundNoti;
                try {
                    if (localForegroundNoti.getSmallIcon() == null) {
                        // It is not correct for the caller to not supply a notification
                        // icon, but this used to be able to slip through, so for
                        // those dirty apps we will create a notification clearly
                        // blaming the app.
                        Slog.v(TAG, "Attempted to start a foreground service (" + name + ") with a broken notification (no icon: " + localForegroundNoti + ")");
                        CharSequence appName = appInfo.loadLabel(ams.mContext.getPackageManager());
                        if (appName == null) {
                            appName = appInfo.packageName;
                        }
                        Context ctx = null;
                        try {
                            ctx = ams.mContext.createPackageContextAsUser(appInfo.packageName, 0, new UserHandle(userId));
                            Notification.Builder notiBuilder = new Notification.Builder(ctx);
                            // it's ugly, but it clearly identifies the app
                            notiBuilder.setSmallIcon(appInfo.icon);
                            // mark as foreground
                            notiBuilder.setFlag(Notification.FLAG_FOREGROUND_SERVICE, true);
                            // we are doing the app a kindness here
                            notiBuilder.setPriority(Notification.PRIORITY_MIN);
                            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);
                            notiBuilder.setColor(ams.mContext.getColor(com.android.internal.R.color.system_notification_accent_color));
                            notiBuilder.setContentTitle(ams.mContext.getString(com.android.internal.R.string.app_running_notification_title, appName));
                            notiBuilder.setContentText(ams.mContext.getString(com.android.internal.R.string.app_running_notification_text, appName));
                            notiBuilder.setContentIntent(pi);
                            localForegroundNoti = notiBuilder.build();
                        } catch (PackageManager.NameNotFoundException e) {
                        }
                    }
                    if (localForegroundNoti.getSmallIcon() == null) {
                        // being foreground.
                        throw new RuntimeException("invalid service notification: " + foregroundNoti);
                    }
                    int[] outId = new int[1];
                    nm.enqueueNotification(localPackageName, localPackageName, appUid, appPid, null, localForegroundId, localForegroundNoti, outId, userId);
                    // save it for amending next time
                    foregroundNoti = localForegroundNoti;
                } catch (RuntimeException e) {
                    Slog.w(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, 0);
                    ams.crashApplication(appUid, appPid, localPackageName, "Bad notification for startForeground: " + e);
                }
            }
        });
    }
}
Also used : NotificationManagerInternal(com.android.server.notification.NotificationManagerInternal) Context(android.content.Context) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) UserHandle(android.os.UserHandle) PendingIntent(android.app.PendingIntent)

Example 2 with NotificationManagerInternal

use of com.android.server.notification.NotificationManagerInternal in project android_frameworks_base by AOSPA.

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 _foregroundNoti = foregroundNoti;
        ams.mHandler.post(new Runnable() {

            public void run() {
                NotificationManagerInternal nm = LocalServices.getService(NotificationManagerInternal.class);
                if (nm == null) {
                    return;
                }
                Notification localForegroundNoti = _foregroundNoti;
                try {
                    if (localForegroundNoti.getSmallIcon() == null) {
                        // It is not correct for the caller to not supply a notification
                        // icon, but this used to be able to slip through, so for
                        // those dirty apps we will create a notification clearly
                        // blaming the app.
                        Slog.v(TAG, "Attempted to start a foreground service (" + name + ") with a broken notification (no icon: " + localForegroundNoti + ")");
                        CharSequence appName = appInfo.loadLabel(ams.mContext.getPackageManager());
                        if (appName == null) {
                            appName = appInfo.packageName;
                        }
                        Context ctx = null;
                        try {
                            ctx = ams.mContext.createPackageContextAsUser(appInfo.packageName, 0, new UserHandle(userId));
                            Notification.Builder notiBuilder = new Notification.Builder(ctx);
                            // it's ugly, but it clearly identifies the app
                            notiBuilder.setSmallIcon(appInfo.icon);
                            // mark as foreground
                            notiBuilder.setFlag(Notification.FLAG_FOREGROUND_SERVICE, true);
                            // we are doing the app a kindness here
                            notiBuilder.setPriority(Notification.PRIORITY_MIN);
                            Intent runningIntent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            runningIntent.setData(Uri.fromParts("package", appInfo.packageName, null));
                            PendingIntent pi = PendingIntent.getActivityAsUser(ams.mContext, 0, runningIntent, PendingIntent.FLAG_UPDATE_CURRENT, null, UserHandle.of(userId));
                            notiBuilder.setColor(ams.mContext.getColor(com.android.internal.R.color.system_notification_accent_color));
                            notiBuilder.setContentTitle(ams.mContext.getString(com.android.internal.R.string.app_running_notification_title, appName));
                            notiBuilder.setContentText(ams.mContext.getString(com.android.internal.R.string.app_running_notification_text, appName));
                            notiBuilder.setContentIntent(pi);
                            localForegroundNoti = notiBuilder.build();
                        } catch (PackageManager.NameNotFoundException e) {
                        }
                    }
                    if (localForegroundNoti.getSmallIcon() == null) {
                        // being foreground.
                        throw new RuntimeException("invalid service notification: " + foregroundNoti);
                    }
                    int[] outId = new int[1];
                    nm.enqueueNotification(localPackageName, localPackageName, appUid, appPid, null, localForegroundId, localForegroundNoti, outId, userId);
                    // save it for amending next time
                    foregroundNoti = localForegroundNoti;
                } catch (RuntimeException e) {
                    Slog.w(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, 0);
                    ams.crashApplication(appUid, appPid, localPackageName, "Bad notification for startForeground: " + e);
                }
            }
        });
    }
}
Also used : NotificationManagerInternal(com.android.server.notification.NotificationManagerInternal) Context(android.content.Context) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) UserHandle(android.os.UserHandle) PendingIntent(android.app.PendingIntent)

Example 3 with NotificationManagerInternal

use of com.android.server.notification.NotificationManagerInternal in project android_frameworks_base by DirtyUnicorns.

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 _foregroundNoti = foregroundNoti;
        ams.mHandler.post(new Runnable() {

            public void run() {
                NotificationManagerInternal nm = LocalServices.getService(NotificationManagerInternal.class);
                if (nm == null) {
                    return;
                }
                Notification localForegroundNoti = _foregroundNoti;
                try {
                    if (localForegroundNoti.getSmallIcon() == null) {
                        // It is not correct for the caller to not supply a notification
                        // icon, but this used to be able to slip through, so for
                        // those dirty apps we will create a notification clearly
                        // blaming the app.
                        Slog.v(TAG, "Attempted to start a foreground service (" + name + ") with a broken notification (no icon: " + localForegroundNoti + ")");
                        CharSequence appName = appInfo.loadLabel(ams.mContext.getPackageManager());
                        if (appName == null) {
                            appName = appInfo.packageName;
                        }
                        Context ctx = null;
                        try {
                            ctx = ams.mContext.createPackageContextAsUser(appInfo.packageName, 0, new UserHandle(userId));
                            Notification.Builder notiBuilder = new Notification.Builder(ctx);
                            // it's ugly, but it clearly identifies the app
                            notiBuilder.setSmallIcon(appInfo.icon);
                            // mark as foreground
                            notiBuilder.setFlag(Notification.FLAG_FOREGROUND_SERVICE, true);
                            // we are doing the app a kindness here
                            notiBuilder.setPriority(Notification.PRIORITY_MIN);
                            Intent runningIntent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            runningIntent.setData(Uri.fromParts("package", appInfo.packageName, null));
                            PendingIntent pi = PendingIntent.getActivityAsUser(ams.mContext, 0, runningIntent, PendingIntent.FLAG_UPDATE_CURRENT, null, UserHandle.of(userId));
                            notiBuilder.setColor(ams.mContext.getColor(com.android.internal.R.color.system_notification_accent_color));
                            notiBuilder.setContentTitle(ams.mContext.getString(com.android.internal.R.string.app_running_notification_title, appName));
                            notiBuilder.setContentText(ams.mContext.getString(com.android.internal.R.string.app_running_notification_text, appName));
                            notiBuilder.setContentIntent(pi);
                            localForegroundNoti = notiBuilder.build();
                        } catch (PackageManager.NameNotFoundException e) {
                        }
                    }
                    if (localForegroundNoti.getSmallIcon() == null) {
                        // being foreground.
                        throw new RuntimeException("invalid service notification: " + foregroundNoti);
                    }
                    int[] outId = new int[1];
                    nm.enqueueNotification(localPackageName, localPackageName, appUid, appPid, null, localForegroundId, localForegroundNoti, outId, userId);
                    // save it for amending next time
                    foregroundNoti = localForegroundNoti;
                } catch (RuntimeException e) {
                    Slog.w(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, 0);
                    ams.crashApplication(appUid, appPid, localPackageName, "Bad notification for startForeground: " + e);
                }
            }
        });
    }
}
Also used : NotificationManagerInternal(com.android.server.notification.NotificationManagerInternal) Context(android.content.Context) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) UserHandle(android.os.UserHandle) PendingIntent(android.app.PendingIntent)

Example 4 with NotificationManagerInternal

use of com.android.server.notification.NotificationManagerInternal in project android_frameworks_base by ResurrectionRemix.

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 _foregroundNoti = foregroundNoti;
        ams.mHandler.post(new Runnable() {

            public void run() {
                NotificationManagerInternal nm = LocalServices.getService(NotificationManagerInternal.class);
                if (nm == null) {
                    return;
                }
                Notification localForegroundNoti = _foregroundNoti;
                try {
                    if (localForegroundNoti.getSmallIcon() == null) {
                        // It is not correct for the caller to not supply a notification
                        // icon, but this used to be able to slip through, so for
                        // those dirty apps we will create a notification clearly
                        // blaming the app.
                        Slog.v(TAG, "Attempted to start a foreground service (" + name + ") with a broken notification (no icon: " + localForegroundNoti + ")");
                        CharSequence appName = appInfo.loadLabel(ams.mContext.getPackageManager());
                        if (appName == null) {
                            appName = appInfo.packageName;
                        }
                        Context ctx = null;
                        try {
                            ctx = ams.mContext.createPackageContextAsUser(appInfo.packageName, 0, new UserHandle(userId));
                            Notification.Builder notiBuilder = new Notification.Builder(ctx);
                            // it's ugly, but it clearly identifies the app
                            notiBuilder.setSmallIcon(appInfo.icon);
                            // mark as foreground
                            notiBuilder.setFlag(Notification.FLAG_FOREGROUND_SERVICE, true);
                            // we are doing the app a kindness here
                            notiBuilder.setPriority(Notification.PRIORITY_MIN);
                            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);
                            notiBuilder.setColor(ams.mContext.getColor(com.android.internal.R.color.system_notification_accent_color));
                            notiBuilder.setContentTitle(ams.mContext.getString(com.android.internal.R.string.app_running_notification_title, appName));
                            notiBuilder.setContentText(ams.mContext.getString(com.android.internal.R.string.app_running_notification_text, appName));
                            notiBuilder.setContentIntent(pi);
                            localForegroundNoti = notiBuilder.build();
                        } catch (PackageManager.NameNotFoundException e) {
                        }
                    }
                    if (localForegroundNoti.getSmallIcon() == null) {
                        // being foreground.
                        throw new RuntimeException("invalid service notification: " + foregroundNoti);
                    }
                    int[] outId = new int[1];
                    nm.enqueueNotification(localPackageName, localPackageName, appUid, appPid, null, localForegroundId, localForegroundNoti, outId, userId);
                    // save it for amending next time
                    foregroundNoti = localForegroundNoti;
                } catch (RuntimeException e) {
                    Slog.w(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, 0);
                    ams.crashApplication(appUid, appPid, localPackageName, "Bad notification for startForeground: " + e);
                }
            }
        });
    }
}
Also used : NotificationManagerInternal(com.android.server.notification.NotificationManagerInternal) Context(android.content.Context) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) UserHandle(android.os.UserHandle) PendingIntent(android.app.PendingIntent)

Example 5 with NotificationManagerInternal

use of com.android.server.notification.NotificationManagerInternal in project android_frameworks_base by crdroidandroid.

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 _foregroundNoti = foregroundNoti;
        ams.mHandler.post(new Runnable() {

            public void run() {
                NotificationManagerInternal nm = LocalServices.getService(NotificationManagerInternal.class);
                if (nm == null) {
                    return;
                }
                Notification localForegroundNoti = _foregroundNoti;
                try {
                    if (localForegroundNoti.getSmallIcon() == null) {
                        // It is not correct for the caller to not supply a notification
                        // icon, but this used to be able to slip through, so for
                        // those dirty apps we will create a notification clearly
                        // blaming the app.
                        Slog.v(TAG, "Attempted to start a foreground service (" + name + ") with a broken notification (no icon: " + localForegroundNoti + ")");
                        CharSequence appName = appInfo.loadLabel(ams.mContext.getPackageManager());
                        if (appName == null) {
                            appName = appInfo.packageName;
                        }
                        Context ctx = null;
                        try {
                            ctx = ams.mContext.createPackageContextAsUser(appInfo.packageName, 0, new UserHandle(userId));
                            Notification.Builder notiBuilder = new Notification.Builder(ctx);
                            // it's ugly, but it clearly identifies the app
                            notiBuilder.setSmallIcon(appInfo.icon);
                            // mark as foreground
                            notiBuilder.setFlag(Notification.FLAG_FOREGROUND_SERVICE, true);
                            // we are doing the app a kindness here
                            notiBuilder.setPriority(Notification.PRIORITY_MIN);
                            Intent runningIntent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            runningIntent.setData(Uri.fromParts("package", appInfo.packageName, null));
                            PendingIntent pi = PendingIntent.getActivityAsUser(ams.mContext, 0, runningIntent, PendingIntent.FLAG_UPDATE_CURRENT, null, new UserHandle(userId));
                            notiBuilder.setColor(ams.mContext.getColor(com.android.internal.R.color.system_notification_accent_color));
                            notiBuilder.setContentTitle(ams.mContext.getString(com.android.internal.R.string.app_running_notification_title, appName));
                            notiBuilder.setContentText(ams.mContext.getString(com.android.internal.R.string.app_running_notification_text, appName));
                            notiBuilder.setContentIntent(pi);
                            localForegroundNoti = notiBuilder.build();
                        } catch (PackageManager.NameNotFoundException e) {
                        }
                    }
                    if (localForegroundNoti.getSmallIcon() == null) {
                        // being foreground.
                        throw new RuntimeException("invalid service notification: " + foregroundNoti);
                    }
                    int[] outId = new int[1];
                    nm.enqueueNotification(localPackageName, localPackageName, appUid, appPid, null, localForegroundId, localForegroundNoti, outId, userId);
                    // save it for amending next time
                    foregroundNoti = localForegroundNoti;
                } catch (RuntimeException e) {
                    Slog.w(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, 0);
                    ams.crashApplication(appUid, appPid, localPackageName, "Bad notification for startForeground: " + e);
                }
            }
        });
    }
}
Also used : NotificationManagerInternal(com.android.server.notification.NotificationManagerInternal) Context(android.content.Context) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) UserHandle(android.os.UserHandle) PendingIntent(android.app.PendingIntent)

Aggregations

Notification (android.app.Notification)5 PendingIntent (android.app.PendingIntent)5 Context (android.content.Context)5 Intent (android.content.Intent)5 UserHandle (android.os.UserHandle)5 NotificationManagerInternal (com.android.server.notification.NotificationManagerInternal)5