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

Commit 312d1d01 authored by John Spurlock's avatar John Spurlock
Browse files

Zen: Use default phone app api in call filter.

Remove hardcoded list of packages (for calls).

Use the TelecommManager version until the PhoneManager version
is ready.

Change-Id: I4488f4ea3f0c03f009c84f519eb533e0ea1e07d5
parent 4c8d3149
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@ import android.service.notification.StatusBarNotification;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Arrays;
import java.util.Objects;


/**
/**
 * Holds data about notifications that should not be shared with the
 * Holds data about notifications that should not be shared with the
@@ -201,6 +202,10 @@ public final class NotificationRecord {
        return mIntercept;
        return mIntercept;
    }
    }


    public boolean isCategory(String category) {
        return Objects.equals(category, getNotification().category);
    }

    /**
    /**
     * Returns the timestamp to use for time-based sorting in the ranker.
     * Returns the timestamp to use for time-based sorting in the ranker.
     */
     */
+19 −8
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import android.app.AppOpsManager;
import android.app.Notification;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
@@ -34,6 +35,7 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.IBinder;
import android.provider.Settings.Global;
import android.provider.Settings.Global;
import android.service.notification.ZenModeConfig;
import android.service.notification.ZenModeConfig;
import android.telecomm.TelecommManager;
import android.util.Slog;
import android.util.Slog;


import com.android.internal.R;
import com.android.internal.R;
@@ -72,17 +74,13 @@ public class ZenModeHelper {
    private final ZenModeConfig mDefaultConfig;
    private final ZenModeConfig mDefaultConfig;
    private final ArrayList<Callback> mCallbacks = new ArrayList<Callback>();
    private final ArrayList<Callback> mCallbacks = new ArrayList<Callback>();


    private ComponentName mDefaultPhoneApp;
    private int mZenMode;
    private int mZenMode;
    private ZenModeConfig mConfig;
    private ZenModeConfig mConfig;
    private AudioManager mAudioManager;
    private AudioManager mAudioManager;
    private int mPreviousRingerMode = -1;
    private int mPreviousRingerMode = -1;


    // temporary, until we update apps to provide metadata
    // temporary, until we update apps to provide metadata
    private static final Set<String> CALL_PACKAGES = new HashSet<String>(Arrays.asList(
            "com.google.android.dialer",
            "com.android.phone",
            "com.android.example.notificationshowcase"
            ));
    private static final Set<String> MESSAGE_PACKAGES = new HashSet<String>(Arrays.asList(
    private static final Set<String> MESSAGE_PACKAGES = new HashSet<String>(Arrays.asList(
            "com.google.android.talk",
            "com.google.android.talk",
            "com.android.mms",
            "com.android.mms",
@@ -224,7 +222,7 @@ public class ZenModeHelper {


    public boolean allowDisable(int what, IBinder token, String pkg) {
    public boolean allowDisable(int what, IBinder token, String pkg) {
        // TODO(cwren): delete this API before the next release. Bug:15344099
        // TODO(cwren): delete this API before the next release. Bug:15344099
        if (CALL_PACKAGES.contains(pkg)) {
        if (isDefaultPhoneApp(pkg)) {
            return mZenMode == Global.ZEN_MODE_OFF || mConfig.allowCalls;
            return mZenMode == Global.ZEN_MODE_OFF || mConfig.allowCalls;
        }
        }
        return true;
        return true;
@@ -236,6 +234,7 @@ public class ZenModeHelper {
        pw.print(prefix); pw.print("mConfig="); pw.println(mConfig);
        pw.print(prefix); pw.print("mConfig="); pw.println(mConfig);
        pw.print(prefix); pw.print("mDefaultConfig="); pw.println(mDefaultConfig);
        pw.print(prefix); pw.print("mDefaultConfig="); pw.println(mDefaultConfig);
        pw.print(prefix); pw.print("mPreviousRingerMode="); pw.println(mPreviousRingerMode);
        pw.print(prefix); pw.print("mPreviousRingerMode="); pw.println(mPreviousRingerMode);
        pw.print(prefix); pw.print("mDefaultPhoneApp="); pw.println(mDefaultPhoneApp);
    }
    }


    public void readXml(XmlPullParser parser) throws XmlPullParserException, IOException {
    public void readXml(XmlPullParser parser) throws XmlPullParserException, IOException {
@@ -280,7 +279,7 @@ public class ZenModeHelper {


    private boolean isSystem(NotificationRecord record) {
    private boolean isSystem(NotificationRecord record) {
        return SYSTEM_PACKAGES.contains(record.sbn.getPackageName())
        return SYSTEM_PACKAGES.contains(record.sbn.getPackageName())
                && Notification.CATEGORY_SYSTEM.equals(record.getNotification().category);
                && record.isCategory(Notification.CATEGORY_SYSTEM);
    }
    }


    private boolean isAlarm(NotificationRecord record) {
    private boolean isAlarm(NotificationRecord record) {
@@ -288,7 +287,19 @@ public class ZenModeHelper {
    }
    }


    private boolean isCall(NotificationRecord record) {
    private boolean isCall(NotificationRecord record) {
        return CALL_PACKAGES.contains(record.sbn.getPackageName());
        return isDefaultPhoneApp(record.sbn.getPackageName())
                || record.isCategory(Notification.CATEGORY_CALL);
    }

    private boolean isDefaultPhoneApp(String pkg) {
        if (mDefaultPhoneApp == null) {
            final TelecommManager telecomm =
                    (TelecommManager) mContext.getSystemService(Context.TELECOMM_SERVICE);
            mDefaultPhoneApp = telecomm != null ? telecomm.getDefaultPhoneApp() : null;
            Slog.d(TAG, "Default phone app: " + mDefaultPhoneApp);
        }
        return pkg != null && mDefaultPhoneApp != null
                && pkg.equals(mDefaultPhoneApp.getPackageName());
    }
    }


    private boolean isMessage(NotificationRecord record) {
    private boolean isMessage(NotificationRecord record) {