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

Commit 1c923a38 authored by John Spurlock's avatar John Spurlock
Browse files

Force condition provider unsubscribe when exiting zen mode.

Bug:13743109
Change-Id: I3c205067498a86e2862a0c545bc38e41682693d5
parent e77bb36d
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -69,8 +69,13 @@ public abstract class ConditionProviderService extends Service {
        return mNoMan;
    }

    public final void notifyConditions(Condition[] conditions) {
        if (!isBound()) return;
    public final void notifyCondition(Condition condition) {
        if (condition == null) return;
        notifyConditions(new Condition[]{ condition });
    }

    public final void notifyConditions(Condition... conditions) {
        if (!isBound() || conditions == null) return;
        try {
            getNotificationInterface().notifyConditions(getPackageName(), mProvider, conditions);
        } catch (android.os.RemoteException ex) {
+19 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.os.IBinder;
import android.os.IInterface;
import android.os.RemoteException;
import android.provider.Settings;
import android.provider.Settings.Global;
import android.service.notification.Condition;
import android.service.notification.ConditionProviderService;
import android.service.notification.IConditionListener;
@@ -51,6 +52,7 @@ public class ConditionProviders extends ManagedServices {
            UserProfiles userProfiles, ZenModeHelper zenModeHelper) {
        super(context, handler, new Object(), userProfiles);
        mZenModeHelper = zenModeHelper;
        mZenModeHelper.addCallback(new ZenModeHelperCallback());
    }

    @Override
@@ -235,4 +237,21 @@ public class ConditionProviders extends ManagedServices {
            }
        }
    }

    private class ZenModeHelperCallback extends ZenModeHelper.Callback {
        @Override
        void onZenModeChanged() {
            final int mode = mZenModeHelper.getZenMode();
            if (mode == Global.ZEN_MODE_OFF) {
                synchronized (mMutex) {
                    if (mCurrentConditionId != null) {
                        if (DEBUG) Slog.d(TAG, "Zen mode off, forcing unsubscribe from "
                                + mCurrentConditionId);
                        unsubscribeLocked(mCurrentConditionId);
                        mCurrentConditionId = null;
                    }
                }
            }
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -840,7 +840,7 @@ public class NotificationManagerService extends SystemService {

        mHandler = new WorkerHandler();
        mZenModeHelper = new ZenModeHelper(getContext(), mHandler);
        mZenModeHelper.setCallback(new ZenModeHelper.Callback() {
        mZenModeHelper.addCallback(new ZenModeHelper.Callback() {
            @Override
            public void onConfigChanged() {
                savePolicyFile();
+25 −6
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import org.xmlpull.v1.XmlSerializer;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
@@ -69,8 +70,8 @@ public class ZenModeHelper {
    private final SettingsObserver mSettingsObserver;
    private final AppOpsManager mAppOps;
    private final ZenModeConfig mDefaultConfig;
    private final ArrayList<Callback> mCallbacks = new ArrayList<Callback>();

    private Callback mCallback;
    private int mZenMode;
    private ZenModeConfig mConfig;

@@ -115,8 +116,8 @@ public class ZenModeHelper {
        return new ZenModeConfig();
    }

    public void setCallback(Callback callback) {
        mCallback = callback;
    public void addCallback(Callback callback) {
        mCallbacks.add(callback);
    }

    public boolean shouldIntercept(String pkg, Notification n) {
@@ -132,6 +133,10 @@ public class ZenModeHelper {
        return false;
    }

    public int getZenMode() {
        return mZenMode;
    }

    public void setZenMode(int zenModeValue) {
        Global.putInt(mContext.getContentResolver(), Global.ZEN_MODE, zenModeValue);
    }
@@ -161,6 +166,7 @@ public class ZenModeHelper {
        mAppOps.setRestriction(AppOpsManager.OP_VIBRATE, AudioManager.USE_DEFAULT_STREAM_TYPE,
                zen ? AppOpsManager.MODE_IGNORED : AppOpsManager.MODE_ALLOWED,
                exceptionPackages);
        dispatchOnZenModeChanged();
    }

    public boolean allowDisable(int what, IBinder token, String pkg) {
@@ -197,7 +203,7 @@ public class ZenModeHelper {
        if (config.equals(mConfig)) return true;
        mConfig = config;
        Slog.d(TAG, "mConfig=" + mConfig);
        if (mCallback != null) mCallback.onConfigChanged();
        dispatchOnConfigChanged();
        final String val = Integer.toString(mConfig.hashCode());
        Global.putString(mContext.getContentResolver(), Global.ZEN_MODE_CONFIG_ETAG, val);
        updateAlarms();
@@ -205,6 +211,18 @@ public class ZenModeHelper {
        return true;
    }

    private void dispatchOnConfigChanged() {
        for (Callback callback : mCallbacks) {
            callback.onConfigChanged();
        }
    }

    private void dispatchOnZenModeChanged() {
        for (Callback callback : mCallbacks) {
            callback.onZenModeChanged();
        }
    }

    private boolean isCall(String pkg, Notification n) {
        return CALL_PACKAGES.contains(pkg);
    }
@@ -310,7 +328,8 @@ public class ZenModeHelper {
        }
    }

    public interface Callback {
        void onConfigChanged();
    public static class Callback {
        void onConfigChanged() {}
        void onZenModeChanged() {}
    }
}