187d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor/*
287d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor * Copyright (C) 2017 The Android Open Source Project
387d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor *
487d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor * Licensed under the Apache License, Version 2.0 (the "License");
587d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor * you may not use this file except in compliance with the License.
687d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor * You may obtain a copy of the License at
787d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor *
887d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor *      http://www.apache.org/licenses/LICENSE-2.0
987d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor *
1087d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor * Unless required by applicable law or agreed to in writing, software
1187d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor * distributed under the License is distributed on an "AS IS" BASIS,
1287d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1387d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor * See the License for the specific language governing permissions and
1487d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor * limitations under the License
1587d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor */
1687d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
17df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitschpackage com.android.systemui.statusbar;
18df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch
193aeddedc179db6921547e6bd652b0195102f4449Julia Reynoldsimport static android.app.NotificationManager.IMPORTANCE_NONE;
203aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds
2187d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellorimport android.app.INotificationManager;
223aeddedc179db6921547e6bd652b0195102f4449Julia Reynoldsimport android.app.Notification;
2387d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellorimport android.app.NotificationChannel;
24df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitschimport android.app.NotificationChannelGroup;
2587d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellorimport android.content.Context;
263aeddedc179db6921547e6bd652b0195102f4449Julia Reynoldsimport android.content.Intent;
273aeddedc179db6921547e6bd652b0195102f4449Julia Reynoldsimport android.content.pm.ActivityInfo;
2887d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellorimport android.content.pm.ApplicationInfo;
2987d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellorimport android.content.pm.PackageInfo;
3087d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellorimport android.content.pm.PackageManager;
313aeddedc179db6921547e6bd652b0195102f4449Julia Reynoldsimport android.content.pm.ResolveInfo;
3287d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellorimport android.graphics.drawable.Drawable;
3387d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellorimport android.os.RemoteException;
343aeddedc179db6921547e6bd652b0195102f4449Julia Reynoldsimport android.service.notification.StatusBarNotification;
353aeddedc179db6921547e6bd652b0195102f4449Julia Reynoldsimport android.text.TextUtils;
3687d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellorimport android.util.AttributeSet;
3787d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellorimport android.view.View;
38d94e788318002dfb70545173773393ac1b389d20Geoffrey Pitschimport android.view.accessibility.AccessibilityEvent;
3987d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellorimport android.widget.ImageView;
4087d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellorimport android.widget.LinearLayout;
4187d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellorimport android.widget.Switch;
4287d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellorimport android.widget.TextView;
4387d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
4487d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellorimport com.android.internal.logging.MetricsLogger;
4587d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellorimport com.android.internal.logging.nano.MetricsProto.MetricsEvent;
4687d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellorimport com.android.settingslib.Utils;
4787d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellorimport com.android.systemui.R;
4887d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
49d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitschimport java.lang.IllegalArgumentException;
50d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitschimport java.util.List;
5187d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellorimport java.util.Set;
5287d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
5387d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor/**
5487d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor * The guts of a notification revealed when performing a long press.
5587d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor */
5695d743c38c919dd500d9dcacf9f998500d403d9eMady Mellorpublic class NotificationInfo extends LinearLayout implements NotificationGuts.GutsContent {
5787d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    private static final String TAG = "InfoGuts";
5887d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
5987d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    private INotificationManager mINotificationManager;
60d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch    private String mPkg;
61d94e788318002dfb70545173773393ac1b389d20Geoffrey Pitsch    private String mAppName;
62d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch    private int mAppUid;
63d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch    private List<NotificationChannel> mNotificationChannels;
64d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch    private NotificationChannel mSingleNotificationChannel;
651fbf66e3ca3a900ab1093b1986d197d83db9ff9cGeoffrey Pitsch    private boolean mIsSingleDefaultChannel;
663aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds    private StatusBarNotification mSbn;
6787d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    private int mStartingUserImportance;
6887d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
69df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch    private TextView mNumChannelsView;
70df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch    private View mChannelDisabledView;
713aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds    private TextView mSettingsLinkView;
7287d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    private Switch mChannelEnabledSwitch;
735278d3d38c3c674a987bab18dd5f971d19244861Geoffrey Pitsch    private CheckSaveListener mCheckSaveListener;
743aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds    private OnAppSettingsClickListener mAppSettingsClickListener;
753aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds    private PackageManager mPm;
7687d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
7795d743c38c919dd500d9dcacf9f998500d403d9eMady Mellor    private NotificationGuts mGutsContainer;
7887d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
7987d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    public NotificationInfo(Context context, AttributeSet attrs) {
8087d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        super(context, attrs);
8187d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    }
8287d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
835278d3d38c3c674a987bab18dd5f971d19244861Geoffrey Pitsch    // Specify a CheckSaveListener to override when/if the user's changes are committed.
845278d3d38c3c674a987bab18dd5f971d19244861Geoffrey Pitsch    public interface CheckSaveListener {
855278d3d38c3c674a987bab18dd5f971d19244861Geoffrey Pitsch        // Invoked when importance has changed and the NotificationInfo wants to try to save it.
865278d3d38c3c674a987bab18dd5f971d19244861Geoffrey Pitsch        // Listener should run saveImportance unless the change should be canceled.
875278d3d38c3c674a987bab18dd5f971d19244861Geoffrey Pitsch        void checkSave(Runnable saveImportance);
885278d3d38c3c674a987bab18dd5f971d19244861Geoffrey Pitsch    }
895278d3d38c3c674a987bab18dd5f971d19244861Geoffrey Pitsch
902a6ea9c2a1b52b0386270ec73e1e6d6a9b614a34Jason Monk    public interface OnSettingsClickListener {
91d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch        void onClick(View v, NotificationChannel channel, int appUid);
9287d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    }
9387d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
943aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds    public interface OnAppSettingsClickListener {
953aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        void onClick(View v, Intent intent);
963aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds    }
973aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds
982a6ea9c2a1b52b0386270ec73e1e6d6a9b614a34Jason Monk    public void bindNotification(final PackageManager pm,
992a6ea9c2a1b52b0386270ec73e1e6d6a9b614a34Jason Monk            final INotificationManager iNotificationManager,
100d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch            final String pkg,
101d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch            final List<NotificationChannel> notificationChannels,
1023aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds            int startingUserImportance,
1033aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds            final StatusBarNotification sbn,
10487d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor            OnSettingsClickListener onSettingsClick,
1053aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds            OnAppSettingsClickListener onAppSettingsClick,
1065278d3d38c3c674a987bab18dd5f971d19244861Geoffrey Pitsch            OnClickListener onDoneClick,
1075278d3d38c3c674a987bab18dd5f971d19244861Geoffrey Pitsch            CheckSaveListener checkSaveListener,
1085278d3d38c3c674a987bab18dd5f971d19244861Geoffrey Pitsch            final Set<String> nonBlockablePkgs)
109d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch            throws RemoteException {
11087d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        mINotificationManager = iNotificationManager;
111d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch        mPkg = pkg;
112d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch        mNotificationChannels = notificationChannels;
1135278d3d38c3c674a987bab18dd5f971d19244861Geoffrey Pitsch        mCheckSaveListener = checkSaveListener;
1143aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        mSbn = sbn;
1153aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        mPm = pm;
1163aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        mAppSettingsClickListener = onAppSettingsClick;
1173aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        mStartingUserImportance = startingUserImportance;
118d94e788318002dfb70545173773393ac1b389d20Geoffrey Pitsch        mAppName = mPkg;
11987d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        Drawable pkgicon = null;
1205a31193497fa923e24bc5c9796b40fdfae604d31Julia Reynolds        CharSequence channelNameText = "";
1215a31193497fa923e24bc5c9796b40fdfae604d31Julia Reynolds        ApplicationInfo info = null;
12287d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        try {
123d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch            info = pm.getApplicationInfo(mPkg,
12487d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor                    PackageManager.MATCH_UNINSTALLED_PACKAGES
12587d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor                            | PackageManager.MATCH_DISABLED_COMPONENTS
12687d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor                            | PackageManager.MATCH_DIRECT_BOOT_UNAWARE
12787d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor                            | PackageManager.MATCH_DIRECT_BOOT_AWARE);
12887d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor            if (info != null) {
129d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch                mAppUid = info.uid;
130d94e788318002dfb70545173773393ac1b389d20Geoffrey Pitsch                mAppName = String.valueOf(pm.getApplicationLabel(info));
13187d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor                pkgicon = pm.getApplicationIcon(info);
13287d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor            }
13387d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        } catch (PackageManager.NameNotFoundException e) {
13487d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor            // app is gone, just show package name and generic icon
13587d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor            pkgicon = pm.getDefaultActivityIcon();
13687d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        }
137df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch        ((ImageView) findViewById(R.id.pkgicon)).setImageDrawable(pkgicon);
138df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch
139d034d29acb000f48778f1bbfeb31cb9934644081Geoffrey Pitsch        int numTotalChannels = iNotificationManager.getNumNotificationChannelsForPackage(
140d034d29acb000f48778f1bbfeb31cb9934644081Geoffrey Pitsch                pkg, mAppUid, false /* includeDeleted */);
141d034d29acb000f48778f1bbfeb31cb9934644081Geoffrey Pitsch        if (mNotificationChannels.isEmpty()) {
142d034d29acb000f48778f1bbfeb31cb9934644081Geoffrey Pitsch            throw new IllegalArgumentException("bindNotification requires at least one channel");
143d034d29acb000f48778f1bbfeb31cb9934644081Geoffrey Pitsch        } else  {
144d034d29acb000f48778f1bbfeb31cb9934644081Geoffrey Pitsch            if (mNotificationChannels.size() == 1) {
145d034d29acb000f48778f1bbfeb31cb9934644081Geoffrey Pitsch                mSingleNotificationChannel = mNotificationChannels.get(0);
146d034d29acb000f48778f1bbfeb31cb9934644081Geoffrey Pitsch                // Special behavior for the Default channel if no other channels have been defined.
147d034d29acb000f48778f1bbfeb31cb9934644081Geoffrey Pitsch                mIsSingleDefaultChannel =
148d034d29acb000f48778f1bbfeb31cb9934644081Geoffrey Pitsch                        (mSingleNotificationChannel.getId()
149d034d29acb000f48778f1bbfeb31cb9934644081Geoffrey Pitsch                                .equals(NotificationChannel.DEFAULT_CHANNEL_ID) &&
150d034d29acb000f48778f1bbfeb31cb9934644081Geoffrey Pitsch                        numTotalChannels <= 1);
151d034d29acb000f48778f1bbfeb31cb9934644081Geoffrey Pitsch            } else {
152d034d29acb000f48778f1bbfeb31cb9934644081Geoffrey Pitsch                mSingleNotificationChannel = null;
153d034d29acb000f48778f1bbfeb31cb9934644081Geoffrey Pitsch                mIsSingleDefaultChannel = false;
154d034d29acb000f48778f1bbfeb31cb9934644081Geoffrey Pitsch            }
155d034d29acb000f48778f1bbfeb31cb9934644081Geoffrey Pitsch        }
156d034d29acb000f48778f1bbfeb31cb9934644081Geoffrey Pitsch
157d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch        String channelsDescText;
15851efddbd3bb304de2dd47fa8cd1114ac555958bbAlan Viverette        mNumChannelsView = findViewById(R.id.num_channels_desc);
1591fbf66e3ca3a900ab1093b1986d197d83db9ff9cGeoffrey Pitsch        if (mIsSingleDefaultChannel) {
160ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch            channelsDescText = mContext.getString(R.string.notification_default_channel_desc);
161ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch        } else {
162ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch            switch (mNotificationChannels.size()) {
163ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch                case 1:
164ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch                    channelsDescText = String.format(mContext.getResources().getQuantityString(
1651fbf66e3ca3a900ab1093b1986d197d83db9ff9cGeoffrey Pitsch                            R.plurals.notification_num_channels_desc, numTotalChannels),
1661fbf66e3ca3a900ab1093b1986d197d83db9ff9cGeoffrey Pitsch                            numTotalChannels);
167ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch                    break;
168ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch                case 2:
169ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch                    channelsDescText = mContext.getString(
170ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch                            R.string.notification_channels_list_desc_2,
171ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch                            mNotificationChannels.get(0).getName(),
172ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch                            mNotificationChannels.get(1).getName());
173ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch                    break;
174ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch                default:
175ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch                    final int numOthers = mNotificationChannels.size() - 2;
176ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch                    channelsDescText = String.format(
177ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch                            mContext.getResources().getQuantityString(
178ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch                                    R.plurals.notification_channels_list_desc_2_and_others,
179ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch                                    numOthers),
180ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch                            mNotificationChannels.get(0).getName(),
181ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch                            mNotificationChannels.get(1).getName(),
182ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch                            numOthers);
183ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch            }
184d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch        }
185d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch        mNumChannelsView.setText(channelsDescText);
186d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch
187d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch        if (mSingleNotificationChannel == null) {
188d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch            // Multiple channels don't use a channel name for the title.
189d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch            channelNameText = mContext.getString(R.string.notification_num_channels,
190d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch                    mNotificationChannels.size());
1911fbf66e3ca3a900ab1093b1986d197d83db9ff9cGeoffrey Pitsch        } else if (mIsSingleDefaultChannel) {
192ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch            // If this is the default channel, don't use our channel-specific text.
19387d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor            channelNameText = mContext.getString(R.string.notification_header_default_channel);
19487d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        } else {
195d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch            channelNameText = mSingleNotificationChannel.getName();
19687d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        }
197d94e788318002dfb70545173773393ac1b389d20Geoffrey Pitsch        ((TextView) findViewById(R.id.pkgname)).setText(mAppName);
19887d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        ((TextView) findViewById(R.id.channel_name)).setText(channelNameText);
19987d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
200df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch        // Set group information if this channel has an associated group.
201df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch        CharSequence groupName = null;
202d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch        if (mSingleNotificationChannel != null && mSingleNotificationChannel.getGroup() != null) {
203d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch            final NotificationChannelGroup notificationChannelGroup =
204d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch                    iNotificationManager.getNotificationChannelGroupForPackage(
205d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch                            mSingleNotificationChannel.getGroup(), pkg, mAppUid);
206d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch            if (notificationChannelGroup != null) {
207d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch                groupName = notificationChannelGroup.getName();
208df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch            }
209df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch        }
210df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch        TextView groupNameView = ((TextView) findViewById(R.id.group_name));
211df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch        TextView groupDividerView = ((TextView) findViewById(R.id.pkg_group_divider));
212df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch        if (groupName != null) {
213df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch            groupNameView.setText(groupName);
214df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch            groupNameView.setVisibility(View.VISIBLE);
215df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch            groupDividerView.setVisibility(View.VISIBLE);
21687d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        } else {
217df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch            groupNameView.setVisibility(View.GONE);
218df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch            groupDividerView.setVisibility(View.GONE);
21987d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        }
22087d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
22187d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        boolean nonBlockable = false;
22287d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        try {
2235a31193497fa923e24bc5c9796b40fdfae604d31Julia Reynolds            final PackageInfo pkgInfo = pm.getPackageInfo(pkg, PackageManager.GET_SIGNATURES);
224f732159cf8d6a4e1cd17542a3a2cf020ad6919a3Julia Reynolds            nonBlockable = Utils.isSystemPackage(getResources(), pm, pkgInfo)
225f732159cf8d6a4e1cd17542a3a2cf020ad6919a3Julia Reynolds                    && (mSingleNotificationChannel == null
226f732159cf8d6a4e1cd17542a3a2cf020ad6919a3Julia Reynolds                    || !mSingleNotificationChannel.isBlockableSystem());
22787d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        } catch (PackageManager.NameNotFoundException e) {
22887d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor            // unlikely.
22987d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        }
23087d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        if (nonBlockablePkgs != null) {
23187d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor            nonBlockable |= nonBlockablePkgs.contains(pkg);
23287d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        }
23387d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
234df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch        bindButtons(nonBlockable);
235df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch
236df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch        // Top-level importance group
237df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch        mChannelDisabledView = findViewById(R.id.channel_disabled);
238d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch        updateSecondaryText();
239df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch
240df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch        // Settings button.
241df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch        final TextView settingsButton = (TextView) findViewById(R.id.more_settings);
242d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch        if (mAppUid >= 0 && onSettingsClick != null) {
243029a3fa6dbad5b191bfb712166aa504a47ed8328Geoffrey Pitsch            settingsButton.setVisibility(View.VISIBLE);
244d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch            final int appUidF = mAppUid;
245df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch            settingsButton.setOnClickListener(
246df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch                    (View view) -> {
247d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch                        onSettingsClick.onClick(view, mSingleNotificationChannel, appUidF);
248df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch                    });
2491fbf66e3ca3a900ab1093b1986d197d83db9ff9cGeoffrey Pitsch            if (numTotalChannels > 1) {
250df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch                settingsButton.setText(R.string.notification_all_categories);
251df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch            } else {
252df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch                settingsButton.setText(R.string.notification_more_settings);
25387d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor            }
254df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch
255df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch        } else {
256df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch            settingsButton.setVisibility(View.GONE);
25787d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        }
25887d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
259df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch        // Done button.
260df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch        final TextView doneButton = (TextView) findViewById(R.id.done);
261df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch        doneButton.setText(R.string.notification_done);
262df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch        doneButton.setOnClickListener(onDoneClick);
2633aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds
2643aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        // Optional settings link
2653aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        updateAppSettingsLink();
26687d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    }
26787d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
2685278d3d38c3c674a987bab18dd5f971d19244861Geoffrey Pitsch    private boolean hasImportanceChanged() {
269d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch        return mSingleNotificationChannel != null &&
2708c8dbdef5f3ce20bdb335fcda9b5c6687d24d833Geoffrey Pitsch                mChannelEnabledSwitch != null &&
271d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch                mStartingUserImportance != getSelectedImportance();
27287d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    }
27387d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
274df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch    private void saveImportance() {
2758c8dbdef5f3ce20bdb335fcda9b5c6687d24d833Geoffrey Pitsch        if (!hasImportanceChanged()) {
27687d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor            return;
27787d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        }
2788c8dbdef5f3ce20bdb335fcda9b5c6687d24d833Geoffrey Pitsch        final int selectedImportance = getSelectedImportance();
27987d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        MetricsLogger.action(mContext, MetricsEvent.ACTION_SAVE_IMPORTANCE,
28087d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor                selectedImportance - mStartingUserImportance);
281d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch        mSingleNotificationChannel.setImportance(selectedImportance);
2828ceb579ec7684ca1a38eb617ec54d3e1d6074558Julia Reynolds        mSingleNotificationChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
28387d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        try {
28487d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor            mINotificationManager.updateNotificationChannelForPackage(
285d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch                    mPkg, mAppUid, mSingleNotificationChannel);
28687d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        } catch (RemoteException e) {
28787d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor            // :(
28887d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        }
28987d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    }
29087d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
29187d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    private int getSelectedImportance() {
29287d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        if (!mChannelEnabledSwitch.isChecked()) {
2933aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds            return IMPORTANCE_NONE;
29487d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        } else {
295df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch            return mStartingUserImportance;
29687d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        }
29787d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    }
29887d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
299df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch    private void bindButtons(final boolean nonBlockable) {
30087d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        // Enabled Switch
30187d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        mChannelEnabledSwitch = (Switch) findViewById(R.id.channel_enabled_switch);
302df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch        mChannelEnabledSwitch.setChecked(
3033aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds                mStartingUserImportance != IMPORTANCE_NONE);
304d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch        final boolean visible = !nonBlockable && mSingleNotificationChannel != null;
305d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch        mChannelEnabledSwitch.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
30687d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
30787d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        // Callback when checked.
30887d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        mChannelEnabledSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
30995d743c38c919dd500d9dcacf9f998500d403d9eMady Mellor            if (mGutsContainer != null) {
31095d743c38c919dd500d9dcacf9f998500d403d9eMady Mellor                mGutsContainer.resetFalsingCheck();
311df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch            }
312d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch            updateSecondaryText();
3133aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds            updateAppSettingsLink();
31487d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        });
31587d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    }
31687d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
317d94e788318002dfb70545173773393ac1b389d20Geoffrey Pitsch    @Override
318d94e788318002dfb70545173773393ac1b389d20Geoffrey Pitsch    public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
319d94e788318002dfb70545173773393ac1b389d20Geoffrey Pitsch        super.onInitializeAccessibilityEvent(event);
320d94e788318002dfb70545173773393ac1b389d20Geoffrey Pitsch        if (mGutsContainer != null &&
321d94e788318002dfb70545173773393ac1b389d20Geoffrey Pitsch                event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
322d94e788318002dfb70545173773393ac1b389d20Geoffrey Pitsch            if (mGutsContainer.isExposed()) {
323d94e788318002dfb70545173773393ac1b389d20Geoffrey Pitsch                event.getText().add(mContext.getString(
324d94e788318002dfb70545173773393ac1b389d20Geoffrey Pitsch                        R.string.notification_channel_controls_opened_accessibility, mAppName));
325d94e788318002dfb70545173773393ac1b389d20Geoffrey Pitsch            } else {
326d94e788318002dfb70545173773393ac1b389d20Geoffrey Pitsch                event.getText().add(mContext.getString(
327d94e788318002dfb70545173773393ac1b389d20Geoffrey Pitsch                        R.string.notification_channel_controls_closed_accessibility, mAppName));
328d94e788318002dfb70545173773393ac1b389d20Geoffrey Pitsch            }
329d94e788318002dfb70545173773393ac1b389d20Geoffrey Pitsch        }
330d94e788318002dfb70545173773393ac1b389d20Geoffrey Pitsch    }
331d94e788318002dfb70545173773393ac1b389d20Geoffrey Pitsch
332d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch    private void updateSecondaryText() {
333d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch        final boolean disabled = mSingleNotificationChannel != null &&
3343aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds                getSelectedImportance() == IMPORTANCE_NONE;
335ee8c81ee56d7315a6e2403788fe261d2399a6a54Geoffrey Pitsch        if (disabled) {
336d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch            mChannelDisabledView.setVisibility(View.VISIBLE);
337df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch            mNumChannelsView.setVisibility(View.GONE);
338df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch        } else {
339d0856f00c748b598eee3106ae7d3f85ea8c91fdcGeoffrey Pitsch            mChannelDisabledView.setVisibility(View.GONE);
3401fbf66e3ca3a900ab1093b1986d197d83db9ff9cGeoffrey Pitsch            mNumChannelsView.setVisibility(mIsSingleDefaultChannel ? View.INVISIBLE : View.VISIBLE);
34187d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        }
34287d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    }
34387d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
3443aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds    private void updateAppSettingsLink() {
3453aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        mSettingsLinkView = findViewById(R.id.app_settings);
3463aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        Intent settingsIntent = getAppSettingsIntent(mPm, mPkg, mSingleNotificationChannel,
3473aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds                mSbn.getId(), mSbn.getTag());
3483aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        if (settingsIntent != null && getSelectedImportance() != IMPORTANCE_NONE
3493aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds                && !TextUtils.isEmpty(mSbn.getNotification().getSettingsText())) {
3503aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds            mSettingsLinkView.setVisibility(View.VISIBLE);
3513aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds            mSettingsLinkView.setText(mContext.getString(R.string.notification_app_settings,
3523aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds                    mSbn.getNotification().getSettingsText()));
3533aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds            mSettingsLinkView.setOnClickListener((View view) -> {
3543aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds                mAppSettingsClickListener.onClick(view, settingsIntent);
3553aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds            });
3563aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        } else {
3573aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds            mSettingsLinkView.setVisibility(View.GONE);
3583aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        }
3593aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds    }
3603aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds
3613aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds    private Intent getAppSettingsIntent(PackageManager pm, String packageName,
3623aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds            NotificationChannel channel, int id, String tag) {
3633aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        Intent intent = new Intent(Intent.ACTION_MAIN)
3643aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds                .addCategory(Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES)
3653aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds                .setPackage(packageName);
3663aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        final List<ResolveInfo> resolveInfos = pm.queryIntentActivities(
3673aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds                intent,
3683aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds                PackageManager.MATCH_DEFAULT_ONLY
3693aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        );
3703aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        if (resolveInfos == null || resolveInfos.size() == 0 || resolveInfos.get(0) == null) {
3713aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds            return null;
3723aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        }
3733aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        final ActivityInfo activityInfo = resolveInfos.get(0).activityInfo;
3743aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        intent.setClassName(activityInfo.packageName, activityInfo.name);
3753aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        if (channel != null) {
3763aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds            intent.putExtra(Notification.EXTRA_CHANNEL_ID, channel.getId());
3773aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        }
3783aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        intent.putExtra(Notification.EXTRA_NOTIFICATION_ID, id);
3793aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        intent.putExtra(Notification.EXTRA_NOTIFICATION_TAG, tag);
3803aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds        return intent;
3813aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds    }
3823aeddedc179db6921547e6bd652b0195102f4449Julia Reynolds
38387d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    @Override
38495d743c38c919dd500d9dcacf9f998500d403d9eMady Mellor    public void setGutsParent(NotificationGuts guts) {
38595d743c38c919dd500d9dcacf9f998500d403d9eMady Mellor        mGutsContainer = guts;
38687d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    }
38787d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
38887d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    @Override
389434180ce5155f0c405080698031f05e9eab3dd4cMady Mellor    public boolean willBeRemoved() {
3908c8dbdef5f3ce20bdb335fcda9b5c6687d24d833Geoffrey Pitsch        return mChannelEnabledSwitch != null && !mChannelEnabledSwitch.isChecked();
391434180ce5155f0c405080698031f05e9eab3dd4cMady Mellor    }
392434180ce5155f0c405080698031f05e9eab3dd4cMady Mellor
393434180ce5155f0c405080698031f05e9eab3dd4cMady Mellor    @Override
39487d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    public View getContentView() {
39587d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        return this;
39687d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    }
39787d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor
39887d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    @Override
399c2dbe49bdcd487cb18bc97f5d4942224f64e8540Mady Mellor    public boolean handleCloseControls(boolean save, boolean force) {
4005278d3d38c3c674a987bab18dd5f971d19244861Geoffrey Pitsch        if (save && hasImportanceChanged()) {
4015278d3d38c3c674a987bab18dd5f971d19244861Geoffrey Pitsch            if (mCheckSaveListener != null) {
4025278d3d38c3c674a987bab18dd5f971d19244861Geoffrey Pitsch                mCheckSaveListener.checkSave(() -> { saveImportance(); });
4035278d3d38c3c674a987bab18dd5f971d19244861Geoffrey Pitsch            } else {
4045278d3d38c3c674a987bab18dd5f971d19244861Geoffrey Pitsch                saveImportance();
4055278d3d38c3c674a987bab18dd5f971d19244861Geoffrey Pitsch            }
406df44b606f357bb67e7a3b44e58f551c1c731ce42Geoffrey Pitsch        }
40787d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor        return false;
40887d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor    }
409e09fb7029ac29f337b8d3b9e564e5b994a9ed927Mady Mellor
410e09fb7029ac29f337b8d3b9e564e5b994a9ed927Mady Mellor    @Override
411e09fb7029ac29f337b8d3b9e564e5b994a9ed927Mady Mellor    public int getActualHeight() {
412e09fb7029ac29f337b8d3b9e564e5b994a9ed927Mady Mellor        return getHeight();
413e09fb7029ac29f337b8d3b9e564e5b994a9ed927Mady Mellor    }
41487d7945f0693d3ca943bfb6491d4eba3a8d7cc75Mady Mellor}
415