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

Commit b10e4113 authored by Jing (Mia) Wang's avatar Jing (Mia) Wang
Browse files

SystemUI: Support disabling app notification

Add disabling notification menu item into notification long click menu.
Send broadcast to Settings to disable app notification, since
setNotificationsEnabledForPackage() checks if caller has system uid.

Change-Id: Ie7c9aebddfa0869f02aaaeef2514c0f133ee21d8
parent 42dd925a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -81,6 +81,8 @@
    <!-- Add for switch the APN -->
    <uses-permission android:name="android.permission.WRITE_APN_SETTINGS" />

    <uses-permission android:name="android.permission.ACCESS_NOTIFICATIONS" />

    <application
        android:persistent="true"
        android:allowClearUserData="false"
+1 −0
Original line number Diff line number Diff line
@@ -170,6 +170,7 @@
    <string name="accessibility_location_active" msgid="2427290146138169014">"应用发出了有效位置信息请求"</string>
    <string name="accessibility_clear_all" msgid="5235938559247164925">"清除所有通知。"</string>
    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"应用信息"</string>
    <string name="status_bar_notification_disable_item_title">"不再显示通知"</string>
    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"屏幕会自动旋转。"</string>
    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"屏幕锁定为横向模式。"</string>
    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"屏幕锁定为纵向模式。"</string>
+1 −0
Original line number Diff line number Diff line
@@ -149,5 +149,6 @@
    <bool name="config_showDdsSwitch">false</bool>
    <bool name="config_showRingerModeSwitch">false</bool>
    <bool name="config_showAlternateRsrpSignalLevelforLTE">false</bool>
    <bool name="config_showDisableNotificaton">true</bool>
</resources>
+1 −0
Original line number Diff line number Diff line
@@ -427,6 +427,7 @@
    <!-- Title shown in notification popup for inspecting the responsible
         application -->
    <string name="status_bar_notification_inspect_item_title">App info</string>
    <string name="status_bar_notification_disable_item_title">Do not show notifications</string>

    <!-- Description of the button in the phone-style notification panel that controls auto-rotation, when auto-rotation is on. [CHAR LIMIT=NONE] -->
    <string name="accessibility_rotation_lock_off">Screen will rotate automatically.</string>
+40 −3
Original line number Diff line number Diff line
@@ -26,12 +26,15 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.database.ContentObserver;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
@@ -389,18 +392,33 @@ public abstract class BaseStatusBar extends SystemUI implements
        return new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                final String packageNameF = (String) v.getTag();
                final Bundle bundle = (Bundle) v.getTag();
                if (bundle == null) return false;
                final String packageNameF = bundle.getString("pkg");
                if (packageNameF == null) return false;
                if (v.getWindowToken() == null) return false;
                mNotificationBlamePopup = new PopupMenu(mContext, v);
                mNotificationBlamePopup.getMenuInflater().inflate(
                        R.menu.notification_popup_menu,
                        mNotificationBlamePopup.getMenu());
                if (mContext.getResources().getBoolean(R.bool.config_showDisableNotificaton)
                        && !isSystemPackage(packageNameF)) {
                    mNotificationBlamePopup.getMenu().add(0,
                            R.string.status_bar_notification_disable_item_title, 0,
                            R.string.status_bar_notification_disable_item_title);
                }
                mNotificationBlamePopup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    public boolean onMenuItemClick(MenuItem item) {
                        if (item.getItemId() == R.id.notification_inspect_item) {
                            startApplicationDetailsActivity(packageNameF);
                            animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE);
                        } else if (item.getItemId()
                                    == R.string.status_bar_notification_disable_item_title) {
                            int uid = bundle.getInt("uid");
                            Intent intent = new Intent("action.disable.notification");
                            intent.putExtra("extra.package.name", packageNameF);
                            intent.putExtra("extra.uid", uid);
                            mContext.sendBroadcast(intent);
                         } else {
                            return false;
                        }
@@ -414,6 +432,22 @@ public abstract class BaseStatusBar extends SystemUI implements
        };
    }

    private boolean isSystemPackage(String packageName) {
        PackageInfo pkgInfo = null;
        PackageManager pm = mContext.getPackageManager();
        try {
            pkgInfo = pm.getPackageInfo(packageName,
                    PackageManager.GET_DISABLED_COMPONENTS |
                    PackageManager.GET_UNINSTALLED_PACKAGES |
                    PackageManager.GET_SIGNATURES);
            PackageInfo sys = pm.getPackageInfo("android", PackageManager.GET_SIGNATURES);
            return (pkgInfo != null && pkgInfo.signatures != null &&
                    sys.signatures[0].equals(pkgInfo.signatures[0]));
        } catch (PackageManager.NameNotFoundException e) {
            return false;
        }
    }

    public void dismissPopups() {
        if (mNotificationBlamePopup != null) {
            mNotificationBlamePopup.dismiss();
@@ -632,7 +666,10 @@ public abstract class BaseStatusBar extends SystemUI implements
                R.layout.status_bar_notification_row, parent, false);

        // for blaming (see SwipeHelper.setLongPressListener)
        row.setTag(sbn.getPackageName());
        Bundle bundle = new Bundle();
        bundle.putString("pkg", sbn.getPackageName());
        bundle.putInt("uid", sbn.getUid());
        row.setTag(bundle);

        workAroundBadLayerDrawableOpacity(row);
        View vetoButton = updateNotificationVetoButton(row, sbn);