Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7b5ebe8e authored by Danesh M's avatar Danesh M Committed by Matt Garnes
Browse files

SystemUI : Add ability to disable notifications via long press

Change-Id: Iebbf93fe71a3e11eedd50d2d8f0aa931d9032176
parent cdeeb0a4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@
    <uses-permission android:name="android.permission.CONFIGURE_WIFI_DISPLAY" />
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
    <uses-permission android:name="android.permission.GET_APP_OPS_STATS" />
    <uses-permission android:name="android.permission.UPDATE_APP_OPS_STATS" />

    <!-- Networking and telephony -->
    <uses-permission android:name="android.permission.BLUETOOTH" />
+36 −0
Original line number Diff line number Diff line
<!--
Copyright (C) 2014 The Android Open Source Project

   Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24.0dp"
        android:height="24.0dp"
        android:viewportWidth="48.0"
        android:viewportHeight="48.0">
    <path
        android:pathData="M23,44c2.2,0,4-1.8,4-4h-8C19,42.2,20.8,44,23,44z"
        android:fillColor="#FFFFFF"/>
    <path
        android:pathData="M40,8.1l-2.4-2.4L25.4,17.9L36,28.5V21c0-2.6-0.7-5-2-6.9L40,8.1z"
        android:fillColor="#FFFFFF"/>
    <path
        android:pathData="M28.8,9.4C27.9,9,27,8.6,26,8.4V7c0-1.6-1.4-3-3-3s-3,1.4-3,3v1.4c-1.1,0.3-2,0.6-3,1.1l5.9,5.9L28.8,9.4z"
        android:fillColor="#FFFFFF"/>
    <path
        android:pathData="M10,21v7.2l10.4-10.4L8.5,6l0,0L8.1,5.6L5.6,8.1l6.3,6.3C10.7,16.3,10,18.5,10,21z"
        android:fillColor="#FFFFFF"/>
    <path
        android:pathData="M22.9,20.4L4.1 39.1 6.5 41.5 10.1 38 35.5 38 39 41.5 41.5 39 z"
        android:fillColor="#FFFFFF"/>
</vector>
+10 −0
Original line number Diff line number Diff line
@@ -76,6 +76,16 @@
                    />
        </LinearLayout>

        <ImageButton style="@android:style/Widget.Material.Light.Button.Borderless.Small"
                 android:id="@+id/notification_stop_notifications"
                 android:layout_width="52dp"
                 android:layout_height="match_parent"
                 android:layout_weight="0"
                 android:gravity="center"
                 android:src="@drawable/ic_stop_notifications"
                 android:visibility="gone"
                />

        <ImageButton style="@android:style/Widget.Material.Light.Button.Borderless.Small"
                 android:id="@+id/notification_inspect_app_provided_settings"
                 android:layout_width="52dp"
+7 −0
Original line number Diff line number Diff line
@@ -20,4 +20,11 @@
    <!-- The text for the button in the notification window-shade that clears
         all of the currently visible notifications. [CHAR LIMIT=10]-->
    <string name="clear_recents">Close all recent</string>

    <string name="stop_notification_dialog_positive">Yes</string>
    <string name="stop_notification_dialog_negative">No</string>
    <string name="stop_notification_dialog_title">Disable notifications</string>
    <string name="stop_notification_dialog_message">Are you sure you want to never show
        notifications from this application?</string>

</resources>
+52 −1
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.TimeInterpolator;
import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.AlertDialog;
import android.app.INotificationManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
@@ -29,6 +31,7 @@ import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
@@ -778,7 +781,7 @@ public abstract class BaseStatusBar extends SystemUI implements
            stub.inflate();
        }
        final StatusBarNotification sbn = row.getStatusBarNotification();
        PackageManager pmUser = getPackageManagerForUser(
        final PackageManager pmUser = getPackageManagerForUser(
                sbn.getUser().getIdentifier());
        row.setTag(sbn.getPackageName());
        final View guts = row.findViewById(R.id.notification_guts);
@@ -805,6 +808,8 @@ public abstract class BaseStatusBar extends SystemUI implements
        final View settingsButton = guts.findViewById(R.id.notification_inspect_item);
        final View appSettingsButton
                = guts.findViewById(R.id.notification_inspect_app_provided_settings);
        final View stopNotificationsButton
                = guts.findViewById(R.id.notification_stop_notifications);
        if (appUid >= 0) {
            final int appUidF = appUid;
            settingsButton.setOnClickListener(new View.OnClickListener() {
@@ -813,6 +818,24 @@ public abstract class BaseStatusBar extends SystemUI implements
                }
            });

            ApplicationInfo appInfo = null;
            try {
                appInfo = pmUser.getApplicationInfo(pkg, 0);
            } catch (NameNotFoundException nnfe) {
                // we'll check if it's null below
            }

            final ApplicationInfo info = appInfo;
            if (info != null && (info.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
                stopNotificationsButton.setVisibility(View.VISIBLE);
                stopNotificationsButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        showStopNotificationDialog(pkg, sbn, info.uid);
                    }
                });
            }

            final Intent appSettingsQueryIntent
                    = new Intent(Intent.ACTION_MAIN)
                    .addCategory(Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES)
@@ -845,6 +868,34 @@ public abstract class BaseStatusBar extends SystemUI implements

    }

    private void showStopNotificationDialog(final String pkg, final StatusBarNotification sbn,
                                            final int uid) {
        // Collapse statusbar
        animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE, true /* force */);
        // Show dialog
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setTitle(R.string.stop_notification_dialog_title);
        builder.setMessage(R.string.stop_notification_dialog_message);
        builder.setPositiveButton(R.string.stop_notification_dialog_positive,
                new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                INotificationManager nm = INotificationManager.Stub.asInterface(
                        ServiceManager.getService(Context.NOTIFICATION_SERVICE));
                try {
                    nm.setNotificationsEnabledForPackage(pkg, uid, false);
                    removeNotification(sbn.getKey(), null);
                } catch (Exception ex) {
                    Log.e(TAG, "Unable to stop notification for " + pkg, ex);
                }
            }
        });
        builder.setNegativeButton(R.string.stop_notification_dialog_negative, null);
        AlertDialog dialog = builder.create();
        dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);
        dialog.show();
    }

    protected SwipeHelper.LongPressListener getNotificationLongClicker() {
        return new SwipeHelper.LongPressListener() {
            @Override
Loading