FileDocCategorySizeDatePackage
ZenModeControllerImpl.javaAPI DocAndroid 5.1 API9399Thu Mar 12 22:22:42 GMT 2015com.android.systemui.statusbar.policy

ZenModeControllerImpl

public class ZenModeControllerImpl extends Object implements ZenModeController
Platform implementation of the zen mode controller.

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private final ArrayList
mCallbacks
private final android.content.Context
mContext
private final com.android.systemui.qs.GlobalSetting
mModeSetting
private final com.android.systemui.qs.GlobalSetting
mConfigSetting
private final android.app.INotificationManager
mNoMan
private final LinkedHashMap
mConditions
private final android.app.AlarmManager
mAlarmManager
private final SetupObserver
mSetupObserver
private int
mUserId
private boolean
mRequesting
private boolean
mRegistered
private final android.service.notification.IConditionListener
mListener
private final android.content.BroadcastReceiver
mReceiver
Constructors Summary
public ZenModeControllerImpl(android.content.Context context, android.os.Handler handler)


         
        mContext = context;
        mModeSetting = new GlobalSetting(mContext, handler, Global.ZEN_MODE) {
            @Override
            protected void handleValueChanged(int value) {
                fireZenChanged(value);
            }
        };
        mConfigSetting = new GlobalSetting(mContext, handler, Global.ZEN_MODE_CONFIG_ETAG) {
            @Override
            protected void handleValueChanged(int value) {
                fireExitConditionChanged();
            }
        };
        mModeSetting.setListening(true);
        mConfigSetting.setListening(true);
        mNoMan = INotificationManager.Stub.asInterface(
                ServiceManager.getService(Context.NOTIFICATION_SERVICE));
        mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        mSetupObserver = new SetupObserver(handler);
        mSetupObserver.register();
    
Methods Summary
public voidaddCallback(Callback callback)

        mCallbacks.add(callback);
    
private voidfireConditionsChanged(android.service.notification.Condition[] conditions)

        for (Callback cb : mCallbacks) {
            cb.onConditionsChanged(conditions);
        }
    
private voidfireEffectsSuppressorChanged()

        for (Callback cb : mCallbacks) {
            cb.onEffectsSupressorChanged();
        }
    
private voidfireExitConditionChanged()

        final Condition exitCondition = getExitCondition();
        if (DEBUG) Slog.d(TAG, "exitCondition changed: " + exitCondition);
        for (Callback cb : mCallbacks) {
            cb.onExitConditionChanged(exitCondition);
        }
    
private voidfireNextAlarmChanged()

        for (Callback cb : mCallbacks) {
            cb.onNextAlarmChanged();
        }
    
private voidfireZenAvailableChanged(boolean available)

        for (Callback cb : mCallbacks) {
            cb.onZenAvailableChanged(available);
        }
    
private voidfireZenChanged(int zen)

        for (Callback cb : mCallbacks) {
            cb.onZenChanged(zen);
        }
    
public android.content.ComponentNamegetEffectsSuppressor()

        return NotificationManager.from(mContext).getEffectsSuppressor();
    
public android.service.notification.ConditiongetExitCondition()

        try {
            final ZenModeConfig config = mNoMan.getZenModeConfig();
            if (config != null) {
                return config.exitCondition;
            }
        } catch (RemoteException e) {
            // noop
        }
        return null;
    
public longgetNextAlarm()

        final AlarmManager.AlarmClockInfo info = mAlarmManager.getNextAlarmClock(mUserId);
        return info != null ? info.getTriggerTime() : 0;
    
public intgetZen()

        return mModeSetting.getValue();
    
public booleanisZenAvailable()

        return mSetupObserver.isDeviceProvisioned() && mSetupObserver.isUserSetup();
    
public voidremoveCallback(Callback callback)

        mCallbacks.remove(callback);
    
public voidrequestConditions(boolean request)

        mRequesting = request;
        try {
            mNoMan.requestZenModeConditions(mListener, request ? Condition.FLAG_RELEVANT_NOW : 0);
        } catch (RemoteException e) {
            // noop
        }
        if (!mRequesting) {
            mConditions.clear();
        }
    
public voidsetExitCondition(android.service.notification.Condition exitCondition)

        try {
            mNoMan.setZenModeCondition(exitCondition);
        } catch (RemoteException e) {
            // noop
        }
    
public voidsetUserId(int userId)

        mUserId = userId;
        if (mRegistered) {
            mContext.unregisterReceiver(mReceiver);
        }
        final IntentFilter filter = new IntentFilter(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED);
        filter.addAction(NotificationManager.ACTION_EFFECTS_SUPPRESSOR_CHANGED);
        mContext.registerReceiverAsUser(mReceiver, new UserHandle(mUserId), filter, null, null);
        mRegistered = true;
        mSetupObserver.register();
    
public voidsetZen(int zen)

        mModeSetting.setValue(zen);
    
private voidupdateConditions(android.service.notification.Condition[] conditions)

        if (conditions == null || conditions.length == 0) return;
        for (Condition c : conditions) {
            if ((c.flags & Condition.FLAG_RELEVANT_NOW) == 0) continue;
            mConditions.put(c.id, c);
        }
        fireConditionsChanged(
                mConditions.values().toArray(new Condition[mConditions.values().size()]));