Merge "Check target api version before crashing apps." into oc-mr1-dev
am: 4e733f3074
Change-Id: I41d02093b1a471123e4dffd90da8cacffa23e769
This commit is contained in:
@@ -33,6 +33,7 @@ import android.content.pm.PackageManager;
|
|||||||
import android.content.pm.ServiceInfo;
|
import android.content.pm.ServiceInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
@@ -517,14 +518,27 @@ final class ServiceRecord extends Binder {
|
|||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (localForegroundNoti.getSmallIcon() == null
|
if (nm.getNotificationChannel(localPackageName, appUid,
|
||||||
|| nm.getNotificationChannel(localPackageName, appUid,
|
|
||||||
localForegroundNoti.getChannelId()) == null) {
|
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
|
// Notifications whose icon is 0 are defined to not show
|
||||||
// a notification, silently ignoring it. We don't want to
|
// a notification, silently ignoring it. We don't want to
|
||||||
// just ignore it, we want to prevent the service from
|
// just ignore it, we want to prevent the service from
|
||||||
// being foreground.
|
// being foreground.
|
||||||
// Also every notification needs a channel.
|
|
||||||
throw new RuntimeException("invalid service notification: "
|
throw new RuntimeException("invalid service notification: "
|
||||||
+ foregroundNoti);
|
+ foregroundNoti);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user