Updated alert window notification to new UX spec.

- Updated strings
- Removed action button
- Clicking on notification takes user to alert window permissions
  activity

Bug: 36069437
Test: Manual
Change-Id: I32e59ed3faa7fba1641660095d59f5ebf9acec43
This commit is contained in:
Wale Ogunwale
2017-03-10 13:17:56 -08:00
parent 77aac13d33
commit d76881e002
4 changed files with 17 additions and 37 deletions

View File

@@ -3167,13 +3167,13 @@
<skip />
<!-- Name of notification channel the system post notification to inform the use about apps
that are drawing ui on-top of other apps (alert-windows) [CHAR LIMIT=NONE] -->
<string name="alert_windows_notification_channel_name"><xliff:g id="name" example="Google Maps">%s</xliff:g> draw over other apps</string>
<string name="alert_windows_notification_channel_name"><xliff:g id="name" example="Google Maps">%s</xliff:g> displaying over other apps</string>
<!-- Notification title when an application is displaying ui on-top of other apps
[CHAR LIMIT=30] -->
<string name="alert_windows_notification_title"><xliff:g id="name" example="Google Maps">%s</xliff:g> app displaying on top.</string>
<string name="alert_windows_notification_title"><xliff:g id="name" example="Google Maps">%s</xliff:g> is displaying over other apps.</string>
<!-- Notification body when an application is displaying ui on-top of other apps
[CHAR LIMIT=NONE] -->
<string name="alert_windows_notification_message">Parts of this app may remain visible at all times. If this feature isn\'t working correctly, turn it off.</string>
<string name="alert_windows_notification_message">If you don’t want <xliff:g id="name" example="Google Maps">%s</xliff:g> to use this feature, tap to open settings and turn it off.</string>
<!-- Notification action to turn-off app displaying on-top of other apps. [CHAR LIMIT=20] -->
<string name="alert_windows_notification_turn_off_action">TURN OFF</string>

View File

@@ -19,9 +19,9 @@ package com.android.server.wm;
import static android.app.NotificationManager.IMPORTANCE_MIN;
import static android.app.PendingIntent.FLAG_CANCEL_CURRENT;
import static android.content.Context.NOTIFICATION_SERVICE;
import static android.content.Intent.EXTRA_PACKAGE_NAME;
import static android.content.Intent.EXTRA_UID;
import static com.android.server.wm.WindowManagerService.ACTION_REVOKE_SYSTEM_ALERT_WINDOW_PERMISSION;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.provider.Settings.ACTION_MANAGE_OVERLAY_PERMISSION;
import android.app.Notification;
import android.app.NotificationChannel;
@@ -35,6 +35,7 @@ import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import com.android.internal.R;
import com.android.server.policy.IconUtilities;
@@ -49,14 +50,12 @@ class AlertWindowNotification {
private String mNotificationTag;
private final NotificationManager mNotificationManager;
private final String mPackageName;
private final int mUid;
private boolean mCancelled;
private IconUtilities mIconUtilities;
AlertWindowNotification(WindowManagerService service, String packageName, int uid) {
AlertWindowNotification(WindowManagerService service, String packageName) {
mService = service;
mPackageName = packageName;
mUid = uid;
mNotificationManager =
(NotificationManager) mService.mContext.getSystemService(NOTIFICATION_SERVICE);
mNotificationTag = CHANNEL_PREFIX + mPackageName;
@@ -96,7 +95,8 @@ class AlertWindowNotification {
createNotificationChannelIfNeeded(context, appName);
final String message = context.getString(R.string.alert_windows_notification_message);
final String message = context.getString(R.string.alert_windows_notification_message,
appName);
final Notification.Builder builder = new Notification.Builder(context, mNotificationTag)
.setOngoing(true)
.setContentTitle(
@@ -106,7 +106,7 @@ class AlertWindowNotification {
.setColor(context.getColor(R.color.system_notification_accent_color))
.setStyle(new Notification.BigTextStyle().bigText(message))
.setLocalOnly(true)
.addAction(getTurnOffAction(context, mPackageName, mUid));
.setContentIntent(getContentIntent(context, mPackageName));
if (aInfo != null) {
final Drawable drawable = pm.getApplicationIcon(aInfo);
@@ -119,17 +119,12 @@ class AlertWindowNotification {
mNotificationManager.notify(mNotificationTag, NOTIFICATION_ID, builder.build());
}
private Notification.Action getTurnOffAction(Context context, String packageName, int uid) {
final Intent intent = new Intent(ACTION_REVOKE_SYSTEM_ALERT_WINDOW_PERMISSION);
intent.putExtra(EXTRA_PACKAGE_NAME, packageName);
intent.putExtra(EXTRA_UID, uid);
private PendingIntent getContentIntent(Context context, String packageName) {
final Intent intent = new Intent(ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.fromParts("package", packageName, null));
intent.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK);
// Calls into activity manager...
final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, mRequestCode,
intent, FLAG_CANCEL_CURRENT);
return new Notification.Action.Builder(R.drawable.alert_window_layer,
context.getString(R.string.alert_windows_notification_turn_off_action),
pendingIntent).build();
return PendingIntent.getActivity(context, mRequestCode, intent, FLAG_CANCEL_CURRENT);
}
private void createNotificationChannelIfNeeded(Context context, String appName) {

View File

@@ -601,8 +601,7 @@ public class Session extends IWindowSession.Stub
if (mAlertWindowSurfaces.isEmpty()) {
cancelAlertWindowNotification();
} else if (mAlertWindowNotification == null){
mAlertWindowNotification = new AlertWindowNotification(
mService, mPackageName, mUid);
mAlertWindowNotification = new AlertWindowNotification(mService, mPackageName);
}
}
}

View File

@@ -346,9 +346,6 @@ public class WindowManagerService extends IWindowManager.Stub
final private KeyguardDisableHandler mKeyguardDisableHandler;
static final String ACTION_REVOKE_SYSTEM_ALERT_WINDOW_PERMISSION =
"com.android.server.wm.ACTION_REVOKE_SYSTEM_ALERT_WINDOW_PERMISSION";
private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -364,16 +361,6 @@ public class WindowManagerService extends IWindowManager.Stub
}
}
break;
case ACTION_REVOKE_SYSTEM_ALERT_WINDOW_PERMISSION:
final String packageName = intent.getStringExtra(EXTRA_PACKAGE_NAME);
final int uid = intent.getIntExtra(EXTRA_UID, -1);
if (packageName != null && uid != -1) {
synchronized (mWindowMap) {
// Revoke permission.
mAppOps.setMode(OP_SYSTEM_ALERT_WINDOW, uid, packageName, MODE_IGNORED);
}
}
break;
}
}
};
@@ -1070,7 +1057,6 @@ public class WindowManagerService extends IWindowManager.Stub
filter.addAction(ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
// Listen to user removal broadcasts so that we can remove the user-specific data.
filter.addAction(Intent.ACTION_USER_REMOVED);
filter.addAction(ACTION_REVOKE_SYSTEM_ALERT_WINDOW_PERMISSION);
mContext.registerReceiver(mBroadcastReceiver, filter);
mSettingsObserver = new SettingsObserver();