Merge "Inline Notification Controls to full spec"
This commit is contained in:
committed by
Android (Google) Code Review
commit
6388efb405
@@ -20,17 +20,17 @@
|
||||
android:id="@+id/notification_header"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="48dp"
|
||||
android:layout_height="@dimen/notification_header_height"
|
||||
android:clipChildren="false"
|
||||
android:paddingTop="10dp"
|
||||
android:paddingBottom="11dp"
|
||||
android:paddingTop="@dimen/notification_header_padding_top"
|
||||
android:paddingBottom="@dimen/notification_header_padding_bottom"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:paddingStart="@dimen/notification_content_margin_start"
|
||||
android:paddingEnd="16dp">
|
||||
<com.android.internal.widget.CachingIconView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="18dp"
|
||||
android:layout_height="18dp"
|
||||
android:layout_width="@dimen/notification_header_icon_size"
|
||||
android:layout_height="@dimen/notification_header_icon_size"
|
||||
android:layout_marginEnd="3dp"
|
||||
/>
|
||||
<TextView
|
||||
|
||||
@@ -174,9 +174,20 @@
|
||||
<!-- height of the content margin on the bottom -->
|
||||
<dimen name="notification_content_margin_bottom">16dp</dimen>
|
||||
|
||||
<!-- height of the notification header (for icon and package name) -->
|
||||
<dimen name="notification_header_height">48dp</dimen>
|
||||
|
||||
<!-- The height of the background for a notification header on a group -->
|
||||
<dimen name="notification_header_background_height">45.5dp</dimen>
|
||||
|
||||
<!-- The top padding for the notification header -->
|
||||
<dimen name="notification_header_padding_top">10dp</dimen>
|
||||
<!-- The bottom padding for the notification header -->
|
||||
<dimen name="notification_header_padding_bottom">11dp</dimen>
|
||||
|
||||
<!-- size (width and height) of the icon in the notification header -->
|
||||
<dimen name="notification_header_icon_size">18dp</dimen>
|
||||
|
||||
<!-- Height of a small notification in the status bar -->
|
||||
<dimen name="notification_min_height">92dp</dimen>
|
||||
|
||||
|
||||
@@ -21,110 +21,113 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/notification_guts"
|
||||
android:clickable="true"
|
||||
android:gravity="top|start"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="@*android:dimen/notification_content_margin_start"
|
||||
android:paddingEnd="8dp"
|
||||
android:background="@color/notification_guts_bg_color"
|
||||
android:theme="@*android:style/Theme.DeviceDefault.Light">
|
||||
|
||||
<!-- Package Info -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp" >
|
||||
android:layout_height="@*android:dimen/notification_header_height"
|
||||
android:clipChildren="false"
|
||||
android:paddingTop="@*android:dimen/notification_header_padding_top"
|
||||
android:paddingBottom="@*android:dimen/notification_header_padding_bottom"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal" >
|
||||
<ImageView
|
||||
android:id="@+id/pkgicon"
|
||||
android:layout_width="18dp"
|
||||
android:layout_height="18dp"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:contentDescription="@null"
|
||||
android:scaleType="fitCenter" />
|
||||
android:layout_width="@*android:dimen/notification_header_icon_size"
|
||||
android:layout_height="@*android:dimen/notification_header_icon_size"
|
||||
android:layout_marginEnd="3dp"/>
|
||||
<TextView
|
||||
android:id="@+id/pkgname"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/TextAppearance.NotificationGuts.Secondary" />
|
||||
android:textAppearance="@*android:style/TextAppearance.Material.Notification.Info"
|
||||
android:layout_marginStart="3dp"
|
||||
android:layout_marginEnd="2dp"
|
||||
android:singleLine="true"/>
|
||||
<TextView
|
||||
android:id="@+id/pkg_group_divider"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@*android:style/TextAppearance.Material.Notification.Info"
|
||||
android:layout_marginStart="2dp"
|
||||
android:layout_marginEnd="2dp"
|
||||
android:text="@string/notification_header_divider_symbol_with_spaces"/>
|
||||
android:text="@*android:string/notification_header_divider_symbol"/>
|
||||
<TextView
|
||||
android:id="@+id/group_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/TextAppearance.NotificationGuts.Secondary" />
|
||||
android:textAppearance="@*android:style/TextAppearance.Material.Notification.Info"
|
||||
android:layout_marginStart="2dp"
|
||||
android:layout_marginEnd="2dp"/>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Channel Info -->
|
||||
<!-- Channel Info Block -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="8dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_marginEnd="@*android:dimen/notification_content_margin_end"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:id="@+id/channel_name"
|
||||
<!-- Channel Text -->
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/pkgname"
|
||||
style="@style/TextAppearance.NotificationGuts.Header" />
|
||||
android:orientation="vertical">
|
||||
<!-- Channel Name -->
|
||||
<TextView
|
||||
android:id="@+id/channel_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="6dp"
|
||||
style="@style/TextAppearance.NotificationInfo.Primary" />
|
||||
<!-- Secondary Text - only one shows at a time -->
|
||||
<TextView
|
||||
android:id="@+id/channel_disabled"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/notification_channel_disabled"
|
||||
style="@style/TextAppearance.NotificationInfo.Secondary.Warning" />
|
||||
<TextView
|
||||
android:id="@+id/num_channels_desc"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/notification_channel_disabled"
|
||||
style="@style/TextAppearance.NotificationInfo.Secondary" />
|
||||
</LinearLayout>
|
||||
<!-- Ban Channel Switch -->
|
||||
<Switch
|
||||
android:id="@+id/channel_enabled_switch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:layout_gravity="end|center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:background="@null" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Secondary Text - only one shows at a time -->
|
||||
<TextView
|
||||
android:id="@+id/channel_disabled"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/notification_channel_disabled"
|
||||
style="@style/TextAppearance.NotificationGuts.SecondaryWarning" />
|
||||
<TextView
|
||||
android:id="@+id/num_channels_desc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/TextAppearance.NotificationGuts.Secondary" />
|
||||
|
||||
<!-- Settings and Done buttons -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="48dp"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="end"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="8dp" >
|
||||
|
||||
android:layout_marginBottom="8dp" >
|
||||
<TextView
|
||||
android:id="@+id/more_settings"
|
||||
android:text="@string/notification_more_settings"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="36dp"
|
||||
style="@style/TextAppearance.NotificationGuts.Button"
|
||||
android:background="@drawable/btn_borderless_rect"
|
||||
android:gravity="center"
|
||||
android:paddingEnd="8dp"
|
||||
android:paddingStart="8dp"
|
||||
android:focusable="true" />
|
||||
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginEnd="8dp"
|
||||
style="@style/TextAppearance.NotificationInfo.Button"/>
|
||||
<TextView
|
||||
android:id="@+id/done"
|
||||
android:text="@string/notification_done"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="36dp"
|
||||
style="@style/TextAppearance.NotificationGuts.Button"
|
||||
android:background="@drawable/btn_borderless_rect"
|
||||
android:gravity="center"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:focusable="true"/>
|
||||
style="@style/TextAppearance.NotificationInfo.Button"/>
|
||||
</LinearLayout>
|
||||
</com.android.systemui.statusbar.NotificationInfo>
|
||||
|
||||
@@ -1340,18 +1340,33 @@
|
||||
<!-- Notification Inline Controls: Header for apps that are not yet using notification channels. -->
|
||||
<string name="notification_header_default_channel">Notifications</string>
|
||||
|
||||
<!-- The divider symbol between different parts of the notification header including spaces. not translatable [CHAR LIMIT=3] -->
|
||||
<string name="notification_header_divider_symbol_with_spaces" translatable="false">" • "</string>
|
||||
|
||||
<!-- Notification Inline Controls: Shown when a channel's notifications are currently blocked -->
|
||||
<string name="notification_channel_disabled">You won\'t get these notifications anymore.</string>
|
||||
|
||||
<!-- Notification: Control panel: Label that shows how many channels are included in this bundle
|
||||
of notifications. Replaces the channel name and only appears when there is more than one channel. -->
|
||||
<string name="notification_num_channels"> <xliff:g id="number">%d</xliff:g> notification categories</string>
|
||||
|
||||
<!-- Notification: Control panel: Label that shows how many channels this application has
|
||||
defined, describing the current notification channel as "1 out of n". -->
|
||||
defined, describing the current notification channel as "1 out of n categories from this app". -->
|
||||
<plurals name="notification_num_channels_desc">
|
||||
<item quantity="one">1 out of <xliff:g id="number">%d</xliff:g> category from this app</item>
|
||||
<item quantity="other">1 out of <xliff:g id="number">%d</xliff:g> categories from this app</item>
|
||||
</plurals>
|
||||
|
||||
<!-- Notification: Control panel: For bundles of notifications, this label that lists the
|
||||
channels used by the contained notifications. The first two channels are listed by name,
|
||||
followed by "and N others"
|
||||
Example: "Friend requests, Friend confirmations"
|
||||
Example: "Friend requests, Friend confirmations, and 1 other"
|
||||
Example: "Friend requests, Friend confirmations, and 2 others"
|
||||
-->
|
||||
<string name="notification_channels_list_desc_2"><xliff:g id="channel_name_1">%1$s</xliff:g>, <xliff:g id="channel_name_2">%2$s</xliff:g></string>
|
||||
<plurals name="notification_channels_list_desc_2_and_others">
|
||||
<item quantity="one"><xliff:g id="channel_name_1">%1$s</xliff:g>, <xliff:g id="channel_name_2">%2$s</xliff:g>, and <xliff:g id="number">%3$d</xliff:g> other</item>
|
||||
<item quantity="other"><xliff:g id="channel_name_1">%1$s</xliff:g>, <xliff:g id="channel_name_2">%2$s</xliff:g>, and <xliff:g id="number">%3$d</xliff:g> others</item>
|
||||
</plurals>
|
||||
|
||||
<!-- Notification: Control panel: Label for button that launches notification settings. Used
|
||||
when this app has defined more than a single channel for notifications. -->
|
||||
<string name="notification_all_categories">All Categories</string>
|
||||
|
||||
@@ -349,38 +349,42 @@
|
||||
<item name="dropdownPreferenceStyle">@style/Preference.DropDown.Material</item>
|
||||
</style>
|
||||
|
||||
<style name="TextAppearance.NotificationGuts">
|
||||
<item name="android:textSize">14sp</item>
|
||||
<item name="android:fontFamily">roboto-regular</item>
|
||||
<style name="TextAppearance.NotificationInfo">
|
||||
<item name="android:fontFamily">sans-serif</item>
|
||||
<item name="android:textColor">@android:color/black</item>
|
||||
</style>
|
||||
|
||||
<style name="TextAppearance.NotificationGuts.Header">
|
||||
<style name="TextAppearance.NotificationInfo.Primary">
|
||||
<item name="android:textColor">?android:attr/textColorPrimary</item>
|
||||
<item name="android:textSize">20sp</item>
|
||||
<item name="android:textSize">16sp</item>
|
||||
<item name="android:alpha">0.87</item>
|
||||
</style>
|
||||
|
||||
<style name="TextAppearance.NotificationGuts.Secondary">
|
||||
<style name="TextAppearance.NotificationInfo.Secondary">
|
||||
<item name="android:textColor">?android:attr/textColorPrimary</item>
|
||||
<item name="android:textSize">12sp</item>
|
||||
<item name="android:textSize">14sp</item>
|
||||
<item name="android:alpha">0.54</item>
|
||||
</style>
|
||||
|
||||
<style name="TextAppearance.NotificationGuts.SecondaryWarning">
|
||||
<style name="TextAppearance.NotificationInfo.Secondary.Warning">
|
||||
<item name="android:textColor">?android:attr/colorError</item>
|
||||
<item name="android:textSize">12sp</item>
|
||||
</style>
|
||||
|
||||
<style name="TextAppearance.NotificationGuts.Button">
|
||||
<style name="TextAppearance.NotificationInfo.Button">
|
||||
<item name="android:fontFamily">sans-serif-medium</item>
|
||||
<item name="android:textSize">14sp</item>
|
||||
<item name="android:textAllCaps">true</item>
|
||||
<item name="android:fontFamily">sans-serif-medium</item>
|
||||
<item name="android:gravity">center</item>
|
||||
<item name="android:textColor">?android:attr/colorAccent</item>
|
||||
<item name="android:background">@drawable/btn_borderless_rect</item>
|
||||
<item name="android:gravity">center</item>
|
||||
<item name="android:focusable">true</item>
|
||||
<item name="android:paddingStart">8dp</item>
|
||||
<item name="android:paddingEnd">8dp</item>
|
||||
</style>
|
||||
|
||||
<style name="TextAppearance.SnoozeSnackBar">
|
||||
<item name="android:textSize">14sp</item>
|
||||
<item name="android:fontFamily">roboto-regular</item>
|
||||
<item name="android:fontFamily">sans-serif</item>
|
||||
<item name="android:textColor">@android:color/white</item>
|
||||
</style>
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ import android.os.Handler;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
@@ -59,6 +58,8 @@ import com.android.systemui.plugins.statusbar.NotificationMenuRowProvider.GutsIn
|
||||
import com.android.systemui.statusbar.NotificationGuts.OnSettingsClickListener;
|
||||
import com.android.systemui.statusbar.stack.StackStateAnimator;
|
||||
|
||||
import java.lang.IllegalArgumentException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -68,9 +69,11 @@ public class NotificationInfo extends LinearLayout implements GutsContent {
|
||||
private static final String TAG = "InfoGuts";
|
||||
|
||||
private INotificationManager mINotificationManager;
|
||||
private String mPkg;
|
||||
private int mAppUid;
|
||||
private List<NotificationChannel> mNotificationChannels;
|
||||
private NotificationChannel mSingleNotificationChannel;
|
||||
private int mStartingUserImportance;
|
||||
private StatusBarNotification mStatusBarNotification;
|
||||
private NotificationChannel mNotificationChannel;
|
||||
|
||||
private TextView mNumChannelsView;
|
||||
private View mChannelDisabledView;
|
||||
@@ -83,36 +86,42 @@ public class NotificationInfo extends LinearLayout implements GutsContent {
|
||||
}
|
||||
|
||||
public interface OnSettingsClickListener {
|
||||
void onClick(View v, int appUid);
|
||||
void onClick(View v, NotificationChannel channel, int appUid);
|
||||
}
|
||||
|
||||
public void bindNotification(final PackageManager pm,
|
||||
final INotificationManager iNotificationManager,
|
||||
final StatusBarNotification sbn, final NotificationChannel channel,
|
||||
final String pkg,
|
||||
final List<NotificationChannel> notificationChannels,
|
||||
OnSettingsClickListener onSettingsClick,
|
||||
OnClickListener onDoneClick, final Set<String> nonBlockablePkgs) {
|
||||
OnClickListener onDoneClick, final Set<String> nonBlockablePkgs)
|
||||
throws RemoteException {
|
||||
mINotificationManager = iNotificationManager;
|
||||
mNotificationChannel = channel;
|
||||
mStatusBarNotification = sbn;
|
||||
mStartingUserImportance = channel.getImportance();
|
||||
mPkg = pkg;
|
||||
mNotificationChannels = notificationChannels;
|
||||
if (mNotificationChannels.isEmpty()) {
|
||||
throw new IllegalArgumentException("bindNotification requires at least one channel");
|
||||
} else if (mNotificationChannels.size() == 1) {
|
||||
mSingleNotificationChannel = mNotificationChannels.get(0);
|
||||
mStartingUserImportance = mSingleNotificationChannel.getImportance();
|
||||
} else {
|
||||
mSingleNotificationChannel = null;
|
||||
}
|
||||
|
||||
final String pkg = sbn.getPackageName();
|
||||
int appUid = -1;
|
||||
String appName = pkg;
|
||||
String appName = mPkg;
|
||||
Drawable pkgicon = null;
|
||||
CharSequence channelNameText = "";
|
||||
ApplicationInfo info = null;
|
||||
try {
|
||||
info = pm.getApplicationInfo(pkg,
|
||||
info = pm.getApplicationInfo(mPkg,
|
||||
PackageManager.MATCH_UNINSTALLED_PACKAGES
|
||||
| PackageManager.MATCH_DISABLED_COMPONENTS
|
||||
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE
|
||||
| PackageManager.MATCH_DIRECT_BOOT_AWARE);
|
||||
if (info != null) {
|
||||
appUid = info.uid;
|
||||
mAppUid = info.uid;
|
||||
appName = String.valueOf(pm.getApplicationLabel(info));
|
||||
pkgicon = pm.getApplicationIcon(info);
|
||||
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
// app is gone, just show package name and generic icon
|
||||
@@ -121,38 +130,54 @@ public class NotificationInfo extends LinearLayout implements GutsContent {
|
||||
((ImageView) findViewById(R.id.pkgicon)).setImageDrawable(pkgicon);
|
||||
|
||||
int numChannels = 1;
|
||||
try {
|
||||
numChannels = iNotificationManager.getNumNotificationChannelsForPackage(
|
||||
pkg, appUid, false /* includeDeleted */);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, e.toString());
|
||||
}
|
||||
numChannels = iNotificationManager.getNumNotificationChannelsForPackage(
|
||||
pkg, mAppUid, false /* includeDeleted */);
|
||||
|
||||
String channelsDescText;
|
||||
mNumChannelsView = (TextView) (findViewById(R.id.num_channels_desc));
|
||||
mNumChannelsView.setText(String.format(mContext.getResources().getQuantityString(
|
||||
R.plurals.notification_num_channels_desc, numChannels), numChannels));
|
||||
switch (mNotificationChannels.size()) {
|
||||
case 1:
|
||||
channelsDescText = String.format(mContext.getResources().getQuantityString(
|
||||
R.plurals.notification_num_channels_desc, numChannels), numChannels);
|
||||
break;
|
||||
case 2:
|
||||
channelsDescText = mContext.getString(R.string.notification_channels_list_desc_2,
|
||||
mNotificationChannels.get(0).getName(),
|
||||
mNotificationChannels.get(1).getName());
|
||||
break;
|
||||
default:
|
||||
final int numOthers = mNotificationChannels.size() - 2;
|
||||
channelsDescText = String.format(
|
||||
mContext.getResources().getQuantityString(
|
||||
R.plurals.notification_channels_list_desc_2_and_others, numOthers),
|
||||
mNotificationChannels.get(0).getName(),
|
||||
mNotificationChannels.get(1).getName(),
|
||||
numOthers);
|
||||
}
|
||||
mNumChannelsView.setText(channelsDescText);
|
||||
|
||||
// If this is the placeholder channel, don't use our channel-specific text.
|
||||
if (channel.getId().equals(NotificationChannel.DEFAULT_CHANNEL_ID)) {
|
||||
if (mSingleNotificationChannel == null) {
|
||||
// Multiple channels don't use a channel name for the title.
|
||||
channelNameText = mContext.getString(R.string.notification_num_channels,
|
||||
mNotificationChannels.size());
|
||||
} else if (mSingleNotificationChannel.getId()
|
||||
.equals(NotificationChannel.DEFAULT_CHANNEL_ID)) {
|
||||
// If this is the placeholder channel, don't use our channel-specific text.
|
||||
channelNameText = mContext.getString(R.string.notification_header_default_channel);
|
||||
} else {
|
||||
channelNameText = channel.getName();
|
||||
channelNameText = mSingleNotificationChannel.getName();
|
||||
}
|
||||
((TextView) findViewById(R.id.pkgname)).setText(appName);
|
||||
((TextView) findViewById(R.id.channel_name)).setText(channelNameText);
|
||||
|
||||
// Set group information if this channel has an associated group.
|
||||
CharSequence groupName = null;
|
||||
if (channel.getGroup() != null) {
|
||||
try {
|
||||
final NotificationChannelGroup notificationChannelGroup =
|
||||
iNotificationManager.getNotificationChannelGroupForPackage(
|
||||
channel.getGroup(), pkg, appUid);
|
||||
if (notificationChannelGroup != null) {
|
||||
groupName = notificationChannelGroup.getName();
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, e.toString());
|
||||
if (mSingleNotificationChannel != null && mSingleNotificationChannel.getGroup() != null) {
|
||||
final NotificationChannelGroup notificationChannelGroup =
|
||||
iNotificationManager.getNotificationChannelGroupForPackage(
|
||||
mSingleNotificationChannel.getGroup(), pkg, mAppUid);
|
||||
if (notificationChannelGroup != null) {
|
||||
groupName = notificationChannelGroup.getName();
|
||||
}
|
||||
}
|
||||
TextView groupNameView = ((TextView) findViewById(R.id.group_name));
|
||||
@@ -181,15 +206,15 @@ public class NotificationInfo extends LinearLayout implements GutsContent {
|
||||
|
||||
// Top-level importance group
|
||||
mChannelDisabledView = findViewById(R.id.channel_disabled);
|
||||
updateImportanceDisplay();
|
||||
updateSecondaryText();
|
||||
|
||||
// Settings button.
|
||||
final TextView settingsButton = (TextView) findViewById(R.id.more_settings);
|
||||
if (appUid >= 0 && onSettingsClick != null) {
|
||||
final int appUidF = appUid;
|
||||
if (mAppUid >= 0 && onSettingsClick != null) {
|
||||
final int appUidF = mAppUid;
|
||||
settingsButton.setOnClickListener(
|
||||
(View view) -> {
|
||||
onSettingsClick.onClick(view, appUidF);
|
||||
onSettingsClick.onClick(view, mSingleNotificationChannel, appUidF);
|
||||
});
|
||||
if (numChannels > 1) {
|
||||
settingsButton.setText(R.string.notification_all_categories);
|
||||
@@ -208,21 +233,24 @@ public class NotificationInfo extends LinearLayout implements GutsContent {
|
||||
}
|
||||
|
||||
public boolean hasImportanceChanged() {
|
||||
return mStartingUserImportance != getSelectedImportance();
|
||||
return mSingleNotificationChannel != null &&
|
||||
mStartingUserImportance != getSelectedImportance();
|
||||
}
|
||||
|
||||
private void saveImportance() {
|
||||
if (mSingleNotificationChannel == null) {
|
||||
return;
|
||||
}
|
||||
int selectedImportance = getSelectedImportance();
|
||||
if (selectedImportance == mStartingUserImportance) {
|
||||
return;
|
||||
}
|
||||
MetricsLogger.action(mContext, MetricsEvent.ACTION_SAVE_IMPORTANCE,
|
||||
selectedImportance - mStartingUserImportance);
|
||||
mNotificationChannel.setImportance(selectedImportance);
|
||||
mSingleNotificationChannel.setImportance(selectedImportance);
|
||||
try {
|
||||
mINotificationManager.updateNotificationChannelForPackage(
|
||||
mStatusBarNotification.getPackageName(), mStatusBarNotification.getUid(),
|
||||
mNotificationChannel);
|
||||
mPkg, mAppUid, mSingleNotificationChannel);
|
||||
} catch (RemoteException e) {
|
||||
// :(
|
||||
}
|
||||
@@ -241,26 +269,32 @@ public class NotificationInfo extends LinearLayout implements GutsContent {
|
||||
mChannelEnabledSwitch = (Switch) findViewById(R.id.channel_enabled_switch);
|
||||
mChannelEnabledSwitch.setChecked(
|
||||
mStartingUserImportance != NotificationManager.IMPORTANCE_NONE);
|
||||
mChannelEnabledSwitch.setVisibility(nonBlockable ? View.INVISIBLE : View.VISIBLE);
|
||||
final boolean visible = !nonBlockable && mSingleNotificationChannel != null;
|
||||
mChannelEnabledSwitch.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
|
||||
|
||||
// Callback when checked.
|
||||
mChannelEnabledSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
if (mGutsInteractionListener != null) {
|
||||
mGutsInteractionListener.onInteraction(NotificationInfo.this);
|
||||
}
|
||||
updateImportanceDisplay();
|
||||
updateSecondaryText();
|
||||
});
|
||||
}
|
||||
|
||||
private void updateImportanceDisplay() {
|
||||
final boolean disabled = getSelectedImportance() == NotificationManager.IMPORTANCE_NONE;
|
||||
mChannelDisabledView.setVisibility(disabled ? View.VISIBLE : View.GONE);
|
||||
if (disabled) {
|
||||
// To be replaced by disabled text.
|
||||
private void updateSecondaryText() {
|
||||
final boolean defaultChannel = mSingleNotificationChannel != null &&
|
||||
mSingleNotificationChannel.getId().equals(NotificationChannel.DEFAULT_CHANNEL_ID);
|
||||
final boolean disabled = mSingleNotificationChannel != null &&
|
||||
getSelectedImportance() == NotificationManager.IMPORTANCE_NONE;
|
||||
if (defaultChannel) {
|
||||
// Don't show any secondary text if this is from the default channel.
|
||||
mChannelDisabledView.setVisibility(View.GONE);
|
||||
mNumChannelsView.setVisibility(View.GONE);
|
||||
} else if (disabled) {
|
||||
mChannelDisabledView.setVisibility(View.VISIBLE);
|
||||
mNumChannelsView.setVisibility(View.GONE);
|
||||
} else if (mNotificationChannel.getId().equals(NotificationChannel.DEFAULT_CHANNEL_ID)) {
|
||||
mNumChannelsView.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
mChannelDisabledView.setVisibility(View.GONE);
|
||||
mNumChannelsView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package com.android.systemui.statusbar.phone;
|
||||
|
||||
|
||||
import static android.app.StatusBarManager.WINDOW_STATE_HIDDEN;
|
||||
import static android.app.StatusBarManager.WINDOW_STATE_SHOWING;
|
||||
import static android.app.StatusBarManager.windowStateToString;
|
||||
@@ -196,8 +195,6 @@ import com.android.systemui.statusbar.policy.UserInfoControllerImpl;
|
||||
import com.android.systemui.statusbar.policy.UserSwitcherController;
|
||||
import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
|
||||
import com.android.systemui.statusbar.stack.NotificationStackScrollLayout.OnChildLocationsChangedListener;
|
||||
|
||||
|
||||
import com.android.systemui.util.leak.LeakDetector;
|
||||
import com.android.systemui.volume.VolumeComponent;
|
||||
|
||||
@@ -5719,11 +5716,13 @@ public class StatusBar extends SystemUI implements DemoMode,
|
||||
|
||||
// The (i) button in the guts that links to the system notification settings for that app
|
||||
private void startAppNotificationSettingsActivity(String packageName, final int appUid,
|
||||
final String channelId) {
|
||||
final NotificationChannel channel) {
|
||||
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
|
||||
intent.putExtra(Settings.EXTRA_APP_PACKAGE, packageName);
|
||||
intent.putExtra(Settings.EXTRA_APP_UID, appUid);
|
||||
intent.putExtra(EXTRA_FRAGMENT_ARG_KEY, channelId);
|
||||
if (channel != null) {
|
||||
intent.putExtra(EXTRA_FRAGMENT_ARG_KEY, channel.getId());
|
||||
}
|
||||
startNotificationGutsIntent(intent, appUid);
|
||||
}
|
||||
|
||||
@@ -5776,23 +5775,23 @@ public class StatusBar extends SystemUI implements DemoMode,
|
||||
}
|
||||
|
||||
if (item.gutsContent instanceof NotificationInfo) {
|
||||
final NotificationChannel channel = row.getEntry().channel;
|
||||
final UserHandle userHandle = sbn.getUser();
|
||||
PackageManager pmUser = getPackageManagerForUser(mContext,
|
||||
sbn.getUser().getIdentifier());
|
||||
userHandle.getIdentifier());
|
||||
final INotificationManager iNotificationManager = INotificationManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
|
||||
final String pkg = sbn.getPackageName();
|
||||
NotificationInfo info = (NotificationInfo) item.gutsContent;
|
||||
final NotificationInfo.OnSettingsClickListener onSettingsClick = (View v,
|
||||
int appUid) -> {
|
||||
NotificationChannel channel, int appUid) -> {
|
||||
mMetricsLogger.action(MetricsEvent.ACTION_NOTE_INFO);
|
||||
guts.resetFalsingCheck();
|
||||
startAppNotificationSettingsActivity(pkg, appUid, channel.getId());
|
||||
startAppNotificationSettingsActivity(pkg, appUid, channel);
|
||||
};
|
||||
final View.OnClickListener onDoneClick = (View v) -> {
|
||||
// If the user has security enabled, show challenge if the setting is changed.
|
||||
if (info.hasImportanceChanged()
|
||||
&& isLockscreenPublicMode(sbn.getUser().getIdentifier())
|
||||
&& isLockscreenPublicMode(userHandle.getIdentifier())
|
||||
&& (mState == StatusBarState.KEYGUARD
|
||||
|| mState == StatusBarState.SHADE_LOCKED)) {
|
||||
OnDismissAction dismissAction = new OnDismissAction() {
|
||||
@@ -5807,9 +5806,30 @@ public class StatusBar extends SystemUI implements DemoMode,
|
||||
saveAndCloseNotificationMenu(info, row, guts, v);
|
||||
}
|
||||
};
|
||||
info.bindNotification(pmUser, iNotificationManager, sbn, channel, onSettingsClick,
|
||||
onDoneClick,
|
||||
mNonBlockablePkgs);
|
||||
|
||||
ArraySet<NotificationChannel> channels = new ArraySet<NotificationChannel>();
|
||||
channels.add(row.getEntry().channel);
|
||||
if (row.isSummaryWithChildren()) {
|
||||
// If this is a summary, then add in the children notification channels for the
|
||||
// same user and pkg.
|
||||
final List<ExpandableNotificationRow> childrenRows = row.getNotificationChildren();
|
||||
final int numChildren = childrenRows.size();
|
||||
for (int i = 0; i < numChildren; i++) {
|
||||
final ExpandableNotificationRow childRow = childrenRows.get(i);
|
||||
final NotificationChannel childChannel = childRow.getEntry().channel;
|
||||
final StatusBarNotification childSbn = childRow.getStatusBarNotification();
|
||||
if (childSbn.getUser().equals(userHandle) &&
|
||||
childSbn.getPackageName().equals(pkg)) {
|
||||
channels.add(childChannel);
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
info.bindNotification(pmUser, iNotificationManager, pkg, new ArrayList(channels),
|
||||
onSettingsClick, onDoneClick, mNonBlockablePkgs);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,8 +56,9 @@ import com.android.systemui.SysuiTestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
@SmallTest
|
||||
@@ -72,14 +73,12 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
private final INotificationManager mMockINotificationManager = mock(INotificationManager.class);
|
||||
private final PackageManager mMockPackageManager = mock(PackageManager.class);
|
||||
private NotificationChannel mNotificationChannel;
|
||||
private final StatusBarNotification mMockStatusBarNotification =
|
||||
mock(StatusBarNotification.class);
|
||||
private NotificationChannel mDefaultNotificationChannel;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Inflate the layout
|
||||
final LayoutInflater layoutInflater =
|
||||
LayoutInflater.from(mContext);
|
||||
final LayoutInflater layoutInflater = LayoutInflater.from(mContext);
|
||||
mNotificationInfo = (NotificationInfo) layoutInflater.inflate(R.layout.notification_info,
|
||||
null);
|
||||
|
||||
@@ -92,30 +91,51 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
when(mMockPackageManager.getApplicationInfo(anyString(), anyInt())).thenReturn(
|
||||
applicationInfo);
|
||||
|
||||
// mMockStatusBarNotification with a test channel.
|
||||
mNotificationChannel = new NotificationChannel(
|
||||
TEST_CHANNEL, TEST_CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW);
|
||||
when(mMockStatusBarNotification.getPackageName()).thenReturn(TEST_PACKAGE_NAME);
|
||||
// Package has one channel by default.
|
||||
when(mMockINotificationManager.getNumNotificationChannelsForPackage(
|
||||
eq(TEST_PACKAGE_NAME), anyInt(), anyBoolean())).thenReturn(1);
|
||||
|
||||
// Some test channels.
|
||||
mNotificationChannel = new NotificationChannel(
|
||||
TEST_CHANNEL, TEST_CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW);
|
||||
mDefaultNotificationChannel = new NotificationChannel(
|
||||
NotificationChannel.DEFAULT_CHANNEL_ID, TEST_CHANNEL_NAME,
|
||||
NotificationManager.IMPORTANCE_LOW);
|
||||
}
|
||||
|
||||
private CharSequence getStringById(int resId) {
|
||||
return mContext.getString(resId);
|
||||
}
|
||||
|
||||
private CharSequence getNumChannelsString(int numChannels) {
|
||||
private CharSequence getNumChannelsDescString(int numChannels) {
|
||||
return String.format(
|
||||
mContext.getResources().getQuantityString(
|
||||
R.plurals.notification_num_channels_desc, numChannels),
|
||||
numChannels);
|
||||
}
|
||||
|
||||
private CharSequence getChannelsListDescString(NotificationChannel... channels) {
|
||||
if (channels.length == 2) {
|
||||
return mContext.getString(R.string.notification_channels_list_desc_2,
|
||||
channels[0].getName(), channels[1].getName());
|
||||
} else {
|
||||
final int numOthers = channels.length - 2;
|
||||
return String.format(
|
||||
mContext.getResources().getQuantityString(
|
||||
R.plurals.notification_channels_list_desc_2_and_others, numOthers),
|
||||
channels[0].getName(), channels[1].getName(), numOthers);
|
||||
}
|
||||
}
|
||||
|
||||
private CharSequence getNumChannelsString(int numChannels) {
|
||||
return mContext.getString(R.string.notification_num_channels, numChannels);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindNotification_SetsTextApplicationName() throws Exception {
|
||||
when(mMockPackageManager.getApplicationLabel(any())).thenReturn("App Name");
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null, null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null);
|
||||
final TextView textView = (TextView) mNotificationInfo.findViewById(R.id.pkgname);
|
||||
assertTrue(textView.getText().toString().contains("App Name"));
|
||||
}
|
||||
@@ -126,7 +146,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
when(mMockPackageManager.getApplicationIcon(any(ApplicationInfo.class)))
|
||||
.thenReturn(iconDrawable);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null, null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null);
|
||||
final ImageView iconView = (ImageView) mNotificationInfo.findViewById(R.id.pkgicon);
|
||||
assertEquals(iconDrawable, iconView.getDrawable());
|
||||
}
|
||||
@@ -134,7 +154,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void testBindNotification_GroupNameHiddenIfNoGroup() throws Exception {
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null, null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null);
|
||||
final TextView groupNameView = (TextView) mNotificationInfo.findViewById(R.id.group_name);
|
||||
assertEquals(View.GONE, groupNameView.getVisibility());
|
||||
final TextView groupDividerView =
|
||||
@@ -151,7 +171,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
eq("test_group_id"), eq(TEST_PACKAGE_NAME), anyInt()))
|
||||
.thenReturn(notificationChannelGroup);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null, null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null);
|
||||
final TextView groupNameView = (TextView) mNotificationInfo.findViewById(R.id.group_name);
|
||||
assertEquals(View.VISIBLE, groupNameView.getVisibility());
|
||||
assertEquals("Test Group Name", groupNameView.getText());
|
||||
@@ -163,7 +183,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void testBindNotification_SetsTextChannelName() throws Exception {
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null, null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null);
|
||||
final TextView textView = (TextView) mNotificationInfo.findViewById(R.id.channel_name);
|
||||
assertEquals(TEST_CHANNEL_NAME, textView.getText());
|
||||
}
|
||||
@@ -172,8 +192,29 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
public void testBindNotification_SetsOnClickListenerForSettings() throws Exception {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel,
|
||||
(View v, int appUid) -> { latch.countDown(); }, null, null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel),
|
||||
(View v, NotificationChannel c, int appUid) -> {
|
||||
assertEquals(mNotificationChannel, c);
|
||||
latch.countDown();
|
||||
}, null, null);
|
||||
|
||||
final TextView settingsButton =
|
||||
(TextView) mNotificationInfo.findViewById(R.id.more_settings);
|
||||
settingsButton.performClick();
|
||||
// Verify that listener was triggered.
|
||||
assertEquals(0, latch.getCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnClickListenerPassesNullChannelForBundle() throws Exception {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
TEST_PACKAGE_NAME,
|
||||
Arrays.asList(mNotificationChannel, mDefaultNotificationChannel),
|
||||
(View v, NotificationChannel c, int appUid) -> {
|
||||
assertEquals(null, c);
|
||||
latch.countDown();
|
||||
}, null, null);
|
||||
|
||||
final TextView settingsButton =
|
||||
(TextView) mNotificationInfo.findViewById(R.id.more_settings);
|
||||
@@ -185,8 +226,8 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void testBindNotification_SettingsTextWithOneChannel() throws Exception {
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, (View v, int appUid) -> {}, null,
|
||||
null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel),
|
||||
(View v, NotificationChannel c, int appUid) -> {}, null, null);
|
||||
final TextView settingsButton =
|
||||
(TextView) mNotificationInfo.findViewById(R.id.more_settings);
|
||||
assertEquals(getStringById(R.string.notification_more_settings), settingsButton.getText());
|
||||
@@ -197,8 +238,8 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
when(mMockINotificationManager.getNumNotificationChannelsForPackage(
|
||||
eq(TEST_PACKAGE_NAME), anyInt(), anyBoolean())).thenReturn(2);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, (View v, int appUid) -> {}, null,
|
||||
null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel),
|
||||
(View v, NotificationChannel c, int appUid) -> {}, null, null);
|
||||
final TextView settingsButton =
|
||||
(TextView) mNotificationInfo.findViewById(R.id.more_settings);
|
||||
assertEquals(getStringById(R.string.notification_all_categories), settingsButton.getText());
|
||||
@@ -208,7 +249,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
public void testBindNotification_SetsOnClickListenerForDone() throws Exception {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null,
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null,
|
||||
(View v) -> { latch.countDown(); },
|
||||
null);
|
||||
|
||||
@@ -220,11 +261,8 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void testBindNotification_NumChannelsTextHiddenWhenDefaultChannel() throws Exception {
|
||||
final NotificationChannel defaultChannel = new NotificationChannel(
|
||||
NotificationChannel.DEFAULT_CHANNEL_ID, TEST_CHANNEL_NAME,
|
||||
NotificationManager.IMPORTANCE_LOW);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, defaultChannel, null, null, null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel), null, null, null);
|
||||
final TextView numChannelsView =
|
||||
(TextView) mNotificationInfo.findViewById(R.id.num_channels_desc);
|
||||
assertTrue(numChannelsView.getVisibility() != View.VISIBLE);
|
||||
@@ -234,11 +272,11 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
public void testBindNotification_NumChannelsTextDisplaysWhenNotDefaultChannel()
|
||||
throws Exception {
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null, null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null);
|
||||
final TextView numChannelsView =
|
||||
(TextView) mNotificationInfo.findViewById(R.id.num_channels_desc);
|
||||
assertEquals(numChannelsView.getVisibility(), View.VISIBLE);
|
||||
assertEquals(getNumChannelsString(1), numChannelsView.getText());
|
||||
assertEquals(getNumChannelsDescString(1), numChannelsView.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -247,16 +285,90 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
when(mMockINotificationManager.getNumNotificationChannelsForPackage(
|
||||
eq(TEST_PACKAGE_NAME), anyInt(), anyBoolean())).thenReturn(2);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null, null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null);
|
||||
final TextView numChannelsView =
|
||||
(TextView) mNotificationInfo.findViewById(R.id.num_channels_desc);
|
||||
assertEquals(getNumChannelsString(2), numChannelsView.getText());
|
||||
assertEquals(getNumChannelsDescString(2), numChannelsView.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void testBindNotification_NumChannelsTextListsChannelsWhenTwoInBundle()
|
||||
throws Exception {
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel, mDefaultNotificationChannel),
|
||||
null, null, null);
|
||||
final TextView numChannelsView =
|
||||
(TextView) mNotificationInfo.findViewById(R.id.num_channels_desc);
|
||||
assertEquals(getChannelsListDescString(mNotificationChannel, mDefaultNotificationChannel),
|
||||
numChannelsView.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void testBindNotification_NumChannelsTextListsChannelsWhenThreeInBundle()
|
||||
throws Exception {
|
||||
NotificationChannel thirdChannel = new NotificationChannel(
|
||||
"third_channel", "third_channel", NotificationManager.IMPORTANCE_LOW);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
TEST_PACKAGE_NAME,
|
||||
Arrays.asList(mNotificationChannel, mDefaultNotificationChannel, thirdChannel),
|
||||
null, null, null);
|
||||
final TextView numChannelsView =
|
||||
(TextView) mNotificationInfo.findViewById(R.id.num_channels_desc);
|
||||
assertEquals(
|
||||
getChannelsListDescString(mNotificationChannel, mDefaultNotificationChannel,
|
||||
thirdChannel),
|
||||
numChannelsView.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void testBindNotification_NumChannelsTextListsChannelsWhenFourInBundle()
|
||||
throws Exception {
|
||||
NotificationChannel thirdChannel = new NotificationChannel(
|
||||
"third_channel", "third_channel", NotificationManager.IMPORTANCE_LOW);
|
||||
NotificationChannel fourthChannel = new NotificationChannel(
|
||||
"fourth_channel", "fourth_channel", NotificationManager.IMPORTANCE_LOW);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
TEST_PACKAGE_NAME,
|
||||
Arrays.asList(mNotificationChannel, mDefaultNotificationChannel, thirdChannel,
|
||||
fourthChannel),
|
||||
null, null, null);
|
||||
final TextView numChannelsView =
|
||||
(TextView) mNotificationInfo.findViewById(R.id.num_channels_desc);
|
||||
assertEquals(
|
||||
getChannelsListDescString(mNotificationChannel, mDefaultNotificationChannel,
|
||||
thirdChannel, fourthChannel),
|
||||
numChannelsView.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void testBindNotification_ChannelNameChangesWhenBundleFromDifferentChannels()
|
||||
throws Exception {
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel, mDefaultNotificationChannel),
|
||||
null, null, null);
|
||||
final TextView channelNameView =
|
||||
(TextView) mNotificationInfo.findViewById(R.id.channel_name);
|
||||
assertEquals(getNumChannelsString(2), channelNameView.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void testEnabledSwitchInvisibleIfBundleFromDifferentChannels() throws Exception {
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel, mDefaultNotificationChannel),
|
||||
null, null, null);
|
||||
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
|
||||
assertEquals(View.INVISIBLE, enabledSwitch.getVisibility());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testbindNotification_ChannelDisabledTextGoneWhenNotDisabled() throws Exception {
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null, null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null);
|
||||
final TextView channelDisabledView =
|
||||
(TextView) mNotificationInfo.findViewById(R.id.channel_disabled);
|
||||
assertEquals(channelDisabledView.getVisibility(), View.GONE);
|
||||
@@ -266,7 +378,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
public void testbindNotification_ChannelDisabledTextVisibleWhenDisabled() throws Exception {
|
||||
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_NONE);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null, null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null);
|
||||
final TextView channelDisabledView =
|
||||
(TextView) mNotificationInfo.findViewById(R.id.channel_disabled);
|
||||
assertEquals(channelDisabledView.getVisibility(), View.VISIBLE);
|
||||
@@ -277,9 +389,21 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void testBindNotification_ChannelDisabledTextHiddenWhenDefaultChannel()
|
||||
throws Exception {
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel), null, null, null);
|
||||
final TextView channelDisabledView =
|
||||
(TextView) mNotificationInfo.findViewById(R.id.channel_disabled);
|
||||
assertTrue(channelDisabledView.getVisibility() != View.VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void testHasImportanceChanged_DefaultsToFalse() throws Exception {
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null, null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null);
|
||||
assertFalse(mNotificationInfo.hasImportanceChanged());
|
||||
}
|
||||
|
||||
@@ -287,7 +411,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
public void testHasImportanceChanged_ReturnsTrueAfterChannelDisabled() throws Exception {
|
||||
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null, null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null);
|
||||
// Find the high button and check it.
|
||||
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
|
||||
enabledSwitch.setChecked(false);
|
||||
@@ -297,7 +421,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void testBindNotification_DoesNotUpdateNotificationChannel() throws Exception {
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null, null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null);
|
||||
verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
|
||||
anyString(), anyInt(), any());
|
||||
}
|
||||
@@ -306,7 +430,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
public void testDoesNotUpdateNotificationChannelAfterImportanceChanged() throws Exception {
|
||||
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null, null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null);
|
||||
|
||||
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
|
||||
enabledSwitch.setChecked(false);
|
||||
@@ -318,7 +442,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnchanged()
|
||||
throws Exception {
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null, null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null);
|
||||
|
||||
mNotificationInfo.handleCloseControls(true);
|
||||
verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
|
||||
@@ -330,7 +454,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
throws Exception {
|
||||
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_UNSPECIFIED);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null, null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null);
|
||||
|
||||
mNotificationInfo.handleCloseControls(true);
|
||||
verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
|
||||
@@ -341,7 +465,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
public void testEnabledSwitchOnByDefault() throws Exception {
|
||||
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null, null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null);
|
||||
|
||||
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
|
||||
assertTrue(enabledSwitch.isChecked());
|
||||
@@ -351,7 +475,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
public void testEnabledButtonOffWhenAlreadyBanned() throws Exception {
|
||||
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_NONE);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null, null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null);
|
||||
|
||||
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
|
||||
assertFalse(enabledSwitch.isChecked());
|
||||
@@ -361,7 +485,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
public void testEnabledSwitchVisibleByDefault() throws Exception {
|
||||
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null, null);
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null);
|
||||
|
||||
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
|
||||
assertEquals(View.VISIBLE, enabledSwitch.getVisibility());
|
||||
@@ -371,18 +495,29 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
public void testEnabledSwitchInvisibleIfNonBlockable() throws Exception {
|
||||
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null,
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null,
|
||||
Collections.singleton(TEST_PACKAGE_NAME));
|
||||
|
||||
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
|
||||
assertEquals(View.INVISIBLE, enabledSwitch.getVisibility());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonBlockableAppDoesNotBecomeBlocked() throws Exception {
|
||||
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null,
|
||||
Collections.singleton(TEST_PACKAGE_NAME));
|
||||
mNotificationInfo.handleCloseControls(true);
|
||||
verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
|
||||
anyString(), anyInt(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnabledSwitchChangedCallsUpdateNotificationChannel() throws Exception {
|
||||
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null,
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null,
|
||||
Collections.singleton(TEST_PACKAGE_NAME));
|
||||
|
||||
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
|
||||
@@ -396,7 +531,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
public void testCloseControlsDoesNotUpdateIfSaveIsFalse() throws Exception {
|
||||
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
mMockStatusBarNotification, mNotificationChannel, null, null,
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null,
|
||||
Collections.singleton(TEST_PACKAGE_NAME));
|
||||
|
||||
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
|
||||
|
||||
Reference in New Issue
Block a user