diff options
3 files changed, 31 insertions, 18 deletions
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index 0d6cd804cdf2..4f1754a8045f 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -2398,8 +2398,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { * permission to add alert windows that aren't * {@link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY}. */ - return (mContext.checkCallingPermission(INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED) - ? ADD_OKAY : ADD_PERMISSION_DENIED; + return (mContext.checkCallingOrSelfPermission(INTERNAL_SYSTEM_WINDOW) + == PERMISSION_GRANTED) ? ADD_OKAY : ADD_PERMISSION_DENIED; } // check if user has enabled this operation. SecurityException will be thrown if this app @@ -2420,8 +2420,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { default: // in the default mode, we will make a decision here based on // checkCallingPermission() - return (mContext.checkCallingPermission(SYSTEM_ALERT_WINDOW) == PERMISSION_GRANTED) - ? ADD_OKAY : ADD_PERMISSION_DENIED; + return (mContext.checkCallingOrSelfPermission(SYSTEM_ALERT_WINDOW) + == PERMISSION_GRANTED) ? ADD_OKAY : ADD_PERMISSION_DENIED; } } diff --git a/services/core/java/com/android/server/wm/AlertWindowNotification.java b/services/core/java/com/android/server/wm/AlertWindowNotification.java index 0d282ef3f8d6..b7b419bf1b41 100644 --- a/services/core/java/com/android/server/wm/AlertWindowNotification.java +++ b/services/core/java/com/android/server/wm/AlertWindowNotification.java @@ -16,7 +16,6 @@ package com.android.server.wm; -import static android.app.Notification.VISIBILITY_PRIVATE; import static android.app.NotificationManager.IMPORTANCE_MIN; import static android.app.PendingIntent.FLAG_CANCEL_CURRENT; import static android.content.Context.NOTIFICATION_SERVICE; @@ -34,8 +33,10 @@ import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.graphics.Bitmap; -import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; + import com.android.internal.R; +import com.android.server.policy.IconUtilities; /** Displays an ongoing notification for a process displaying an alert window */ class AlertWindowNotification { @@ -50,6 +51,7 @@ class AlertWindowNotification { private final String mPackageName; private final int mUid; private boolean mCancelled; + private IconUtilities mIconUtilities; AlertWindowNotification(WindowManagerService service, String packageName, int uid) { mService = service; @@ -59,20 +61,33 @@ class AlertWindowNotification { (NotificationManager) mService.mContext.getSystemService(NOTIFICATION_SERVICE); mNotificationTag = CHANNEL_PREFIX + mPackageName; mRequestCode = sNextRequestCode++; + mIconUtilities = new IconUtilities(mService.mContext); // We can't create/post the notification while the window manager lock is held since it will // end up calling into activity manager. So, we post a message to do it later. - mService.mH.post(this::postNotification); + mService.mH.post(this::onPostNotification); } /** Cancels the notification */ void cancel() { + // We can't call into NotificationManager with WM lock held since it might call into AM. + // So, we post a message to do it later. + mService.mH.post(this::onCancelNotification); + } + + /** Don't call with the window manager lock held! */ + private void onCancelNotification() { mNotificationManager.cancel(mNotificationTag, NOTIFICATION_ID); mCancelled = true; } /** Don't call with the window manager lock held! */ - private void postNotification() { + private void onPostNotification() { + if (mCancelled) { + // Notification was cancelled, so nothing more to do... + return; + } + final Context context = mService.mContext; final PackageManager pm = context.getPackageManager(); final ApplicationInfo aInfo = getApplicationInfo(pm, mPackageName); @@ -94,17 +109,14 @@ class AlertWindowNotification { .addAction(getTurnOffAction(context, mPackageName, mUid)); if (aInfo != null) { - final Bitmap bitmap = ((BitmapDrawable) pm.getApplicationIcon(aInfo)).getBitmap(); - builder.setLargeIcon(bitmap); - } - - synchronized (mService.mWindowMap) { - if (mCancelled) { - // Notification was cancelled, so nothing more to do... - return; + final Drawable drawable = pm.getApplicationIcon(aInfo); + if (drawable != null) { + final Bitmap bitmap = mIconUtilities.createIconBitmap(drawable); + builder.setLargeIcon(bitmap); } - mNotificationManager.notify(mNotificationTag, NOTIFICATION_ID, builder.build()); } + + mNotificationManager.notify(mNotificationTag, NOTIFICATION_ID, builder.build()); } private Notification.Action getTurnOffAction(Context context, String packageName, int uid) { diff --git a/services/core/java/com/android/server/wm/Session.java b/services/core/java/com/android/server/wm/Session.java index 5355f3159c86..720a4544259e 100644 --- a/services/core/java/com/android/server/wm/Session.java +++ b/services/core/java/com/android/server/wm/Session.java @@ -93,7 +93,7 @@ public class Session extends IWindowSession.Stub mUid = Binder.getCallingUid(); mPid = Binder.getCallingPid(); mLastReportedAnimatorScale = service.getCurrentAnimatorScale(); - mCanAddInternalSystemWindow = service.mContext.checkCallingPermission( + mCanAddInternalSystemWindow = service.mContext.checkCallingOrSelfPermission( INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED; StringBuilder sb = new StringBuilder(); sb.append("Session{"); @@ -664,6 +664,7 @@ public class Session extends IWindowSession.Stub void dump(PrintWriter pw, String prefix) { pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); + pw.print(" mCanAddInternalSystemWindow="); pw.print(mCanAddInternalSystemWindow); pw.print(" mAppOverlaySurfaces="); pw.print(mAppOverlaySurfaces); pw.print(" mAlertWindowSurfaces="); pw.print(mAlertWindowSurfaces); pw.print(" mClientDead="); pw.print(mClientDead); |