X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=services%2Fcore%2Fjava%2Fcom%2Fandroid%2Fserver%2Fam%2FServiceRecord.java;h=f87ba716926e8bfff16ae4b5bc4db6944763cc68;hb=c6fd63a7a80f06a89b34aa1894694922c3af9f20;hp=ac85e6b132bf1d98d6a83e75f1814fbe172bd1d9;hpb=ad545464c2d543a7847cf2cacea11dc604d1c919;p=android-x86%2Fframeworks-base.git diff --git a/services/core/java/com/android/server/am/ServiceRecord.java b/services/core/java/com/android/server/am/ServiceRecord.java index ac85e6b132bf..f87ba716926e 100644 --- a/services/core/java/com/android/server/am/ServiceRecord.java +++ b/services/core/java/com/android/server/am/ServiceRecord.java @@ -33,6 +33,7 @@ import android.content.pm.PackageManager; import android.content.pm.ServiceInfo; import android.net.Uri; import android.os.Binder; +import android.os.Build; import android.os.IBinder; import android.os.RemoteException; import android.os.SystemClock; @@ -452,6 +453,7 @@ final class ServiceRecord extends Binder { final String localPackageName = packageName; final int localForegroundId = foregroundId; final Notification _foregroundNoti = foregroundNoti; + final ServiceRecord record = this; ams.mHandler.post(new Runnable() { public void run() { NotificationManagerInternal nm = LocalServices.getService( @@ -517,14 +519,27 @@ final class ServiceRecord extends Binder { } catch (PackageManager.NameNotFoundException e) { } } - if (localForegroundNoti.getSmallIcon() == null - || nm.getNotificationChannel(localPackageName, appUid, + if (nm.getNotificationChannel(localPackageName, appUid, localForegroundNoti.getChannelId()) == null) { + int targetSdkVersion = Build.VERSION_CODES.O_MR1; + try { + final ApplicationInfo applicationInfo = + ams.mContext.getPackageManager().getApplicationInfoAsUser( + appInfo.packageName, 0, userId); + targetSdkVersion = applicationInfo.targetSdkVersion; + } catch (PackageManager.NameNotFoundException e) { + } + if (targetSdkVersion >= Build.VERSION_CODES.O_MR1) { + throw new RuntimeException( + "invalid channel for service notification: " + + foregroundNoti); + } + } + if (localForegroundNoti.getSmallIcon() == null) { // Notifications whose icon is 0 are defined to not show // a notification, silently ignoring it. We don't want to // just ignore it, we want to prevent the service from // being foreground. - // Also every notification needs a channel. throw new RuntimeException("invalid service notification: " + foregroundNoti); } @@ -537,10 +552,8 @@ final class ServiceRecord extends Binder { 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, -1, - "Bad notification for startForeground: " + e); + ams.mServices.killMisbehavingService(record, + appUid, appPid, localPackageName); } } });