blob: 7062216ad771386127cb06f36ea21f509aec6060 [file] [log] [blame]
Mady Mellor87d79452017-01-10 11:52:52 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050017package com.android.systemui.statusbar;
18
Julia Reynolds3aedded2017-03-31 14:42:09 -040019import static android.app.NotificationManager.IMPORTANCE_NONE;
20
Mady Mellor87d79452017-01-10 11:52:52 -080021import android.app.INotificationManager;
Julia Reynolds3aedded2017-03-31 14:42:09 -040022import android.app.Notification;
Mady Mellor87d79452017-01-10 11:52:52 -080023import android.app.NotificationChannel;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050024import android.app.NotificationChannelGroup;
Mady Mellor87d79452017-01-10 11:52:52 -080025import android.content.Context;
Julia Reynolds3aedded2017-03-31 14:42:09 -040026import android.content.Intent;
27import android.content.pm.ActivityInfo;
Mady Mellor87d79452017-01-10 11:52:52 -080028import android.content.pm.ApplicationInfo;
29import android.content.pm.PackageInfo;
30import android.content.pm.PackageManager;
Julia Reynolds3aedded2017-03-31 14:42:09 -040031import android.content.pm.ResolveInfo;
Mady Mellor87d79452017-01-10 11:52:52 -080032import android.graphics.drawable.Drawable;
Mady Mellor87d79452017-01-10 11:52:52 -080033import android.os.RemoteException;
Julia Reynolds3aedded2017-03-31 14:42:09 -040034import android.service.notification.StatusBarNotification;
35import android.text.TextUtils;
Mady Mellor87d79452017-01-10 11:52:52 -080036import android.util.AttributeSet;
Mady Mellor87d79452017-01-10 11:52:52 -080037import android.view.View;
Geoffrey Pitschd94e7882017-04-06 09:52:11 -040038import android.view.accessibility.AccessibilityEvent;
Mady Mellor87d79452017-01-10 11:52:52 -080039import android.widget.ImageView;
40import android.widget.LinearLayout;
Mady Mellor87d79452017-01-10 11:52:52 -080041import android.widget.Switch;
42import android.widget.TextView;
43
44import com.android.internal.logging.MetricsLogger;
45import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
46import com.android.settingslib.Utils;
Mady Mellor87d79452017-01-10 11:52:52 -080047import com.android.systemui.R;
Mady Mellor87d79452017-01-10 11:52:52 -080048
Geoffrey Pitschd0856f02017-02-16 10:51:18 -050049import java.lang.IllegalArgumentException;
50import java.util.List;
Mady Mellor87d79452017-01-10 11:52:52 -080051import java.util.Set;
52
53/**
54 * The guts of a notification revealed when performing a long press.
55 */
Mady Mellor95d743c2017-01-10 12:05:27 -080056public class NotificationInfo extends LinearLayout implements NotificationGuts.GutsContent {
Mady Mellor87d79452017-01-10 11:52:52 -080057 private static final String TAG = "InfoGuts";
58
59 private INotificationManager mINotificationManager;
Geoffrey Pitschd0856f02017-02-16 10:51:18 -050060 private String mPkg;
Geoffrey Pitschd94e7882017-04-06 09:52:11 -040061 private String mAppName;
Geoffrey Pitschd0856f02017-02-16 10:51:18 -050062 private int mAppUid;
63 private List<NotificationChannel> mNotificationChannels;
64 private NotificationChannel mSingleNotificationChannel;
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -040065 private boolean mIsSingleDefaultChannel;
Julia Reynolds3aedded2017-03-31 14:42:09 -040066 private StatusBarNotification mSbn;
Mady Mellor87d79452017-01-10 11:52:52 -080067 private int mStartingUserImportance;
Mady Mellor87d79452017-01-10 11:52:52 -080068
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050069 private TextView mNumChannelsView;
70 private View mChannelDisabledView;
Julia Reynolds3aedded2017-03-31 14:42:09 -040071 private TextView mSettingsLinkView;
Mady Mellor87d79452017-01-10 11:52:52 -080072 private Switch mChannelEnabledSwitch;
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -040073 private CheckSaveListener mCheckSaveListener;
Julia Reynolds3aedded2017-03-31 14:42:09 -040074 private OnAppSettingsClickListener mAppSettingsClickListener;
75 private PackageManager mPm;
Mady Mellor87d79452017-01-10 11:52:52 -080076
Mady Mellor95d743c2017-01-10 12:05:27 -080077 private NotificationGuts mGutsContainer;
Mady Mellor87d79452017-01-10 11:52:52 -080078
79 public NotificationInfo(Context context, AttributeSet attrs) {
80 super(context, attrs);
81 }
82
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -040083 // Specify a CheckSaveListener to override when/if the user's changes are committed.
84 public interface CheckSaveListener {
85 // Invoked when importance has changed and the NotificationInfo wants to try to save it.
86 // Listener should run saveImportance unless the change should be canceled.
87 void checkSave(Runnable saveImportance);
88 }
89
Jason Monk2a6ea9c2017-01-26 11:14:51 -050090 public interface OnSettingsClickListener {
Geoffrey Pitschd0856f02017-02-16 10:51:18 -050091 void onClick(View v, NotificationChannel channel, int appUid);
Mady Mellor87d79452017-01-10 11:52:52 -080092 }
93
Julia Reynolds3aedded2017-03-31 14:42:09 -040094 public interface OnAppSettingsClickListener {
95 void onClick(View v, Intent intent);
96 }
97
Jason Monk2a6ea9c2017-01-26 11:14:51 -050098 public void bindNotification(final PackageManager pm,
99 final INotificationManager iNotificationManager,
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500100 final String pkg,
101 final List<NotificationChannel> notificationChannels,
Julia Reynolds3aedded2017-03-31 14:42:09 -0400102 int startingUserImportance,
103 final StatusBarNotification sbn,
Mady Mellor87d79452017-01-10 11:52:52 -0800104 OnSettingsClickListener onSettingsClick,
Julia Reynolds3aedded2017-03-31 14:42:09 -0400105 OnAppSettingsClickListener onAppSettingsClick,
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400106 OnClickListener onDoneClick,
107 CheckSaveListener checkSaveListener,
108 final Set<String> nonBlockablePkgs)
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500109 throws RemoteException {
Mady Mellor87d79452017-01-10 11:52:52 -0800110 mINotificationManager = iNotificationManager;
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500111 mPkg = pkg;
112 mNotificationChannels = notificationChannels;
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400113 mCheckSaveListener = checkSaveListener;
Julia Reynolds3aedded2017-03-31 14:42:09 -0400114 mSbn = sbn;
115 mPm = pm;
116 mAppSettingsClickListener = onAppSettingsClick;
Julia Reynolds3aedded2017-03-31 14:42:09 -0400117 mStartingUserImportance = startingUserImportance;
Geoffrey Pitschd94e7882017-04-06 09:52:11 -0400118 mAppName = mPkg;
Mady Mellor87d79452017-01-10 11:52:52 -0800119 Drawable pkgicon = null;
Julia Reynolds5a311932017-03-01 16:33:44 -0500120 CharSequence channelNameText = "";
121 ApplicationInfo info = null;
Mady Mellor87d79452017-01-10 11:52:52 -0800122 try {
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500123 info = pm.getApplicationInfo(mPkg,
Mady Mellor87d79452017-01-10 11:52:52 -0800124 PackageManager.MATCH_UNINSTALLED_PACKAGES
125 | PackageManager.MATCH_DISABLED_COMPONENTS
126 | PackageManager.MATCH_DIRECT_BOOT_UNAWARE
127 | PackageManager.MATCH_DIRECT_BOOT_AWARE);
128 if (info != null) {
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500129 mAppUid = info.uid;
Geoffrey Pitschd94e7882017-04-06 09:52:11 -0400130 mAppName = String.valueOf(pm.getApplicationLabel(info));
Mady Mellor87d79452017-01-10 11:52:52 -0800131 pkgicon = pm.getApplicationIcon(info);
132 }
133 } catch (PackageManager.NameNotFoundException e) {
134 // app is gone, just show package name and generic icon
135 pkgicon = pm.getDefaultActivityIcon();
136 }
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500137 ((ImageView) findViewById(R.id.pkgicon)).setImageDrawable(pkgicon);
138
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400139 int numTotalChannels = iNotificationManager.getNumNotificationChannelsForPackage(
140 pkg, mAppUid, false /* includeDeleted */);
141 if (mNotificationChannels.isEmpty()) {
142 throw new IllegalArgumentException("bindNotification requires at least one channel");
143 } else {
144 if (mNotificationChannels.size() == 1) {
145 mSingleNotificationChannel = mNotificationChannels.get(0);
146 // Special behavior for the Default channel if no other channels have been defined.
147 mIsSingleDefaultChannel =
148 (mSingleNotificationChannel.getId()
149 .equals(NotificationChannel.DEFAULT_CHANNEL_ID) &&
150 numTotalChannels <= 1);
151 } else {
152 mSingleNotificationChannel = null;
153 mIsSingleDefaultChannel = false;
154 }
155 }
156
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500157 String channelsDescText;
Alan Viverette51efddb2017-04-05 10:00:01 -0400158 mNumChannelsView = findViewById(R.id.num_channels_desc);
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -0400159 if (mIsSingleDefaultChannel) {
Geoffrey Pitschee8c81e2017-03-23 11:38:56 -0400160 channelsDescText = mContext.getString(R.string.notification_default_channel_desc);
161 } else {
162 switch (mNotificationChannels.size()) {
163 case 1:
164 channelsDescText = String.format(mContext.getResources().getQuantityString(
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -0400165 R.plurals.notification_num_channels_desc, numTotalChannels),
166 numTotalChannels);
Geoffrey Pitschee8c81e2017-03-23 11:38:56 -0400167 break;
168 case 2:
169 channelsDescText = mContext.getString(
170 R.string.notification_channels_list_desc_2,
171 mNotificationChannels.get(0).getName(),
172 mNotificationChannels.get(1).getName());
173 break;
174 default:
175 final int numOthers = mNotificationChannels.size() - 2;
176 channelsDescText = String.format(
177 mContext.getResources().getQuantityString(
178 R.plurals.notification_channels_list_desc_2_and_others,
179 numOthers),
180 mNotificationChannels.get(0).getName(),
181 mNotificationChannels.get(1).getName(),
182 numOthers);
183 }
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500184 }
185 mNumChannelsView.setText(channelsDescText);
Mady Mellor87d79452017-01-10 11:52:52 -0800186
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500187 if (mSingleNotificationChannel == null) {
188 // Multiple channels don't use a channel name for the title.
189 channelNameText = mContext.getString(R.string.notification_num_channels,
190 mNotificationChannels.size());
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -0400191 } else if (mIsSingleDefaultChannel) {
Geoffrey Pitschee8c81e2017-03-23 11:38:56 -0400192 // If this is the default channel, don't use our channel-specific text.
Mady Mellor87d79452017-01-10 11:52:52 -0800193 channelNameText = mContext.getString(R.string.notification_header_default_channel);
194 } else {
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500195 channelNameText = mSingleNotificationChannel.getName();
Mady Mellor87d79452017-01-10 11:52:52 -0800196 }
Geoffrey Pitschd94e7882017-04-06 09:52:11 -0400197 ((TextView) findViewById(R.id.pkgname)).setText(mAppName);
Mady Mellor87d79452017-01-10 11:52:52 -0800198 ((TextView) findViewById(R.id.channel_name)).setText(channelNameText);
199
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500200 // Set group information if this channel has an associated group.
201 CharSequence groupName = null;
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500202 if (mSingleNotificationChannel != null && mSingleNotificationChannel.getGroup() != null) {
203 final NotificationChannelGroup notificationChannelGroup =
204 iNotificationManager.getNotificationChannelGroupForPackage(
205 mSingleNotificationChannel.getGroup(), pkg, mAppUid);
206 if (notificationChannelGroup != null) {
207 groupName = notificationChannelGroup.getName();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500208 }
Mady Mellor87d79452017-01-10 11:52:52 -0800209 }
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500210 TextView groupNameView = ((TextView) findViewById(R.id.group_name));
211 TextView groupDividerView = ((TextView) findViewById(R.id.pkg_group_divider));
212 if (groupName != null) {
213 groupNameView.setText(groupName);
214 groupNameView.setVisibility(View.VISIBLE);
215 groupDividerView.setVisibility(View.VISIBLE);
216 } else {
217 groupNameView.setVisibility(View.GONE);
218 groupDividerView.setVisibility(View.GONE);
219 }
Mady Mellor87d79452017-01-10 11:52:52 -0800220
221 boolean nonBlockable = false;
222 try {
Julia Reynolds5a311932017-03-01 16:33:44 -0500223 final PackageInfo pkgInfo = pm.getPackageInfo(pkg, PackageManager.GET_SIGNATURES);
224 nonBlockable = Utils.isSystemPackage(getResources(), pm, pkgInfo);
Mady Mellor87d79452017-01-10 11:52:52 -0800225 } catch (PackageManager.NameNotFoundException e) {
226 // unlikely.
227 }
228 if (nonBlockablePkgs != null) {
229 nonBlockable |= nonBlockablePkgs.contains(pkg);
230 }
231
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500232 bindButtons(nonBlockable);
Mady Mellor87d79452017-01-10 11:52:52 -0800233
234 // Top-level importance group
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500235 mChannelDisabledView = findViewById(R.id.channel_disabled);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500236 updateSecondaryText();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500237
238 // Settings button.
239 final TextView settingsButton = (TextView) findViewById(R.id.more_settings);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500240 if (mAppUid >= 0 && onSettingsClick != null) {
Geoffrey Pitsch029a3fa2017-03-30 13:01:57 -0400241 settingsButton.setVisibility(View.VISIBLE);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500242 final int appUidF = mAppUid;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500243 settingsButton.setOnClickListener(
244 (View view) -> {
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500245 onSettingsClick.onClick(view, mSingleNotificationChannel, appUidF);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500246 });
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -0400247 if (numTotalChannels > 1) {
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500248 settingsButton.setText(R.string.notification_all_categories);
249 } else {
250 settingsButton.setText(R.string.notification_more_settings);
251 }
252
253 } else {
254 settingsButton.setVisibility(View.GONE);
255 }
256
257 // Done button.
258 final TextView doneButton = (TextView) findViewById(R.id.done);
259 doneButton.setText(R.string.notification_done);
260 doneButton.setOnClickListener(onDoneClick);
Julia Reynolds3aedded2017-03-31 14:42:09 -0400261
262 // Optional settings link
263 updateAppSettingsLink();
Mady Mellor87d79452017-01-10 11:52:52 -0800264 }
265
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400266 private boolean hasImportanceChanged() {
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500267 return mSingleNotificationChannel != null &&
Geoffrey Pitsch8c8dbde2017-04-20 11:44:33 -0400268 mChannelEnabledSwitch != null &&
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500269 mStartingUserImportance != getSelectedImportance();
Mady Mellor87d79452017-01-10 11:52:52 -0800270 }
271
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500272 private void saveImportance() {
Geoffrey Pitsch8c8dbde2017-04-20 11:44:33 -0400273 if (!hasImportanceChanged()) {
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500274 return;
275 }
Geoffrey Pitsch8c8dbde2017-04-20 11:44:33 -0400276 final int selectedImportance = getSelectedImportance();
Mady Mellor87d79452017-01-10 11:52:52 -0800277 MetricsLogger.action(mContext, MetricsEvent.ACTION_SAVE_IMPORTANCE,
278 selectedImportance - mStartingUserImportance);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500279 mSingleNotificationChannel.setImportance(selectedImportance);
Julia Reynolds8ceb5792017-04-11 11:32:44 -0400280 mSingleNotificationChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
Mady Mellor87d79452017-01-10 11:52:52 -0800281 try {
282 mINotificationManager.updateNotificationChannelForPackage(
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500283 mPkg, mAppUid, mSingleNotificationChannel);
Mady Mellor87d79452017-01-10 11:52:52 -0800284 } catch (RemoteException e) {
285 // :(
286 }
287 }
288
289 private int getSelectedImportance() {
290 if (!mChannelEnabledSwitch.isChecked()) {
Julia Reynolds3aedded2017-03-31 14:42:09 -0400291 return IMPORTANCE_NONE;
Mady Mellor87d79452017-01-10 11:52:52 -0800292 } else {
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500293 return mStartingUserImportance;
Mady Mellor87d79452017-01-10 11:52:52 -0800294 }
295 }
296
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500297 private void bindButtons(final boolean nonBlockable) {
Mady Mellor87d79452017-01-10 11:52:52 -0800298 // Enabled Switch
299 mChannelEnabledSwitch = (Switch) findViewById(R.id.channel_enabled_switch);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500300 mChannelEnabledSwitch.setChecked(
Julia Reynolds3aedded2017-03-31 14:42:09 -0400301 mStartingUserImportance != IMPORTANCE_NONE);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500302 final boolean visible = !nonBlockable && mSingleNotificationChannel != null;
303 mChannelEnabledSwitch.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
Mady Mellor87d79452017-01-10 11:52:52 -0800304
Mady Mellor87d79452017-01-10 11:52:52 -0800305 // Callback when checked.
306 mChannelEnabledSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
Mady Mellor95d743c2017-01-10 12:05:27 -0800307 if (mGutsContainer != null) {
308 mGutsContainer.resetFalsingCheck();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500309 }
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500310 updateSecondaryText();
Julia Reynolds3aedded2017-03-31 14:42:09 -0400311 updateAppSettingsLink();
Mady Mellor87d79452017-01-10 11:52:52 -0800312 });
Mady Mellor87d79452017-01-10 11:52:52 -0800313 }
314
Geoffrey Pitschd94e7882017-04-06 09:52:11 -0400315 @Override
316 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
317 super.onInitializeAccessibilityEvent(event);
318 if (mGutsContainer != null &&
319 event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
320 if (mGutsContainer.isExposed()) {
321 event.getText().add(mContext.getString(
322 R.string.notification_channel_controls_opened_accessibility, mAppName));
323 } else {
324 event.getText().add(mContext.getString(
325 R.string.notification_channel_controls_closed_accessibility, mAppName));
326 }
327 }
328 }
329
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500330 private void updateSecondaryText() {
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500331 final boolean disabled = mSingleNotificationChannel != null &&
Julia Reynolds3aedded2017-03-31 14:42:09 -0400332 getSelectedImportance() == IMPORTANCE_NONE;
Geoffrey Pitschee8c81e2017-03-23 11:38:56 -0400333 if (disabled) {
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500334 mChannelDisabledView.setVisibility(View.VISIBLE);
335 mNumChannelsView.setVisibility(View.GONE);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500336 } else {
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500337 mChannelDisabledView.setVisibility(View.GONE);
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -0400338 mNumChannelsView.setVisibility(mIsSingleDefaultChannel ? View.INVISIBLE : View.VISIBLE);
Mady Mellor87d79452017-01-10 11:52:52 -0800339 }
340 }
341
Julia Reynolds3aedded2017-03-31 14:42:09 -0400342 private void updateAppSettingsLink() {
343 mSettingsLinkView = findViewById(R.id.app_settings);
344 Intent settingsIntent = getAppSettingsIntent(mPm, mPkg, mSingleNotificationChannel,
345 mSbn.getId(), mSbn.getTag());
346 if (settingsIntent != null && getSelectedImportance() != IMPORTANCE_NONE
347 && !TextUtils.isEmpty(mSbn.getNotification().getSettingsText())) {
348 mSettingsLinkView.setVisibility(View.VISIBLE);
349 mSettingsLinkView.setText(mContext.getString(R.string.notification_app_settings,
350 mSbn.getNotification().getSettingsText()));
351 mSettingsLinkView.setOnClickListener((View view) -> {
352 mAppSettingsClickListener.onClick(view, settingsIntent);
353 });
354 } else {
355 mSettingsLinkView.setVisibility(View.GONE);
356 }
357 }
358
359 private Intent getAppSettingsIntent(PackageManager pm, String packageName,
360 NotificationChannel channel, int id, String tag) {
361 Intent intent = new Intent(Intent.ACTION_MAIN)
362 .addCategory(Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES)
363 .setPackage(packageName);
364 final List<ResolveInfo> resolveInfos = pm.queryIntentActivities(
365 intent,
366 PackageManager.MATCH_DEFAULT_ONLY
367 );
368 if (resolveInfos == null || resolveInfos.size() == 0 || resolveInfos.get(0) == null) {
369 return null;
370 }
371 final ActivityInfo activityInfo = resolveInfos.get(0).activityInfo;
372 intent.setClassName(activityInfo.packageName, activityInfo.name);
373 if (channel != null) {
374 intent.putExtra(Notification.EXTRA_CHANNEL_ID, channel.getId());
375 }
376 intent.putExtra(Notification.EXTRA_NOTIFICATION_ID, id);
377 intent.putExtra(Notification.EXTRA_NOTIFICATION_TAG, tag);
378 return intent;
379 }
380
Mady Mellor87d79452017-01-10 11:52:52 -0800381 @Override
Mady Mellor95d743c2017-01-10 12:05:27 -0800382 public void setGutsParent(NotificationGuts guts) {
383 mGutsContainer = guts;
Mady Mellor87d79452017-01-10 11:52:52 -0800384 }
385
386 @Override
Mady Mellor434180c2017-02-13 11:29:42 -0800387 public boolean willBeRemoved() {
Geoffrey Pitsch8c8dbde2017-04-20 11:44:33 -0400388 return mChannelEnabledSwitch != null && !mChannelEnabledSwitch.isChecked();
Mady Mellor434180c2017-02-13 11:29:42 -0800389 }
390
391 @Override
Mady Mellor87d79452017-01-10 11:52:52 -0800392 public View getContentView() {
393 return this;
394 }
395
396 @Override
Mady Mellorc2dbe492017-03-30 13:22:03 -0700397 public boolean handleCloseControls(boolean save, boolean force) {
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400398 if (save && hasImportanceChanged()) {
399 if (mCheckSaveListener != null) {
400 mCheckSaveListener.checkSave(() -> { saveImportance(); });
401 } else {
402 saveImportance();
403 }
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500404 }
Mady Mellor87d79452017-01-10 11:52:52 -0800405 return false;
406 }
Mady Mellore09fb702017-03-30 13:23:29 -0700407
408 @Override
409 public int getActualHeight() {
410 return getHeight();
411 }
Mady Mellor87d79452017-01-10 11:52:52 -0800412}