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) {
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;
UserProfiles userProfiles, ZenModeHelper zenModeHelper) {
super(context, handler, new Object(), userProfiles);
mZenModeHelper = zenModeHelper;
+ mZenModeHelper.addCallback(new ZenModeHelperCallback());
}
@Override
}
}
}
+
+ 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;
+ }
+ }
+ }
+ }
+ }
}
import java.io.IOException;
import java.io.PrintWriter;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
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;
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) {
return false;
}
+ public int getZenMode() {
+ return mZenMode;
+ }
+
public void setZenMode(int zenModeValue) {
Global.putInt(mContext.getContentResolver(), Global.ZEN_MODE, zenModeValue);
}
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) {
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();
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);
}
}
}
- public interface Callback {
- void onConfigChanged();
+ public static class Callback {
+ void onConfigChanged() {}
+ void onZenModeChanged() {}
}
}