Search in sources :

Example 1 with CheckEventResult

use of com.android.server.notification.CalendarTracker.CheckEventResult in project platform_frameworks_base by android.

the class EventConditionProvider method evaluateSubscriptionsW.

private void evaluateSubscriptionsW() {
    if (DEBUG)
        Slog.d(TAG, "evaluateSubscriptions");
    if (!mBootComplete) {
        if (DEBUG)
            Slog.d(TAG, "Skipping evaluate before boot complete");
        return;
    }
    final long now = System.currentTimeMillis();
    List<Condition> conditionsToNotify = new ArrayList<>();
    synchronized (mSubscriptions) {
        for (int i = 0; i < mTrackers.size(); i++) {
            mTrackers.valueAt(i).setCallback(mSubscriptions.isEmpty() ? null : mTrackerCallback);
        }
        setRegistered(!mSubscriptions.isEmpty());
        long reevaluateAt = 0;
        for (Uri conditionId : mSubscriptions) {
            final EventInfo event = ZenModeConfig.tryParseEventConditionId(conditionId);
            if (event == null) {
                conditionsToNotify.add(createCondition(conditionId, Condition.STATE_FALSE));
                continue;
            }
            CheckEventResult result = null;
            if (event.calendar == null) {
                // event could exist on any tracker
                for (int i = 0; i < mTrackers.size(); i++) {
                    final CalendarTracker tracker = mTrackers.valueAt(i);
                    final CheckEventResult r = tracker.checkEvent(event, now);
                    if (result == null) {
                        result = r;
                    } else {
                        result.inEvent |= r.inEvent;
                        result.recheckAt = Math.min(result.recheckAt, r.recheckAt);
                    }
                }
            } else {
                // event should exist on one tracker
                final int userId = EventInfo.resolveUserId(event.userId);
                final CalendarTracker tracker = mTrackers.get(userId);
                if (tracker == null) {
                    Slog.w(TAG, "No calendar tracker found for user " + userId);
                    conditionsToNotify.add(createCondition(conditionId, Condition.STATE_FALSE));
                    continue;
                }
                result = tracker.checkEvent(event, now);
            }
            if (result.recheckAt != 0 && (reevaluateAt == 0 || result.recheckAt < reevaluateAt)) {
                reevaluateAt = result.recheckAt;
            }
            if (!result.inEvent) {
                conditionsToNotify.add(createCondition(conditionId, Condition.STATE_FALSE));
                continue;
            }
            conditionsToNotify.add(createCondition(conditionId, Condition.STATE_TRUE));
        }
        rescheduleAlarm(now, reevaluateAt);
    }
    for (Condition condition : conditionsToNotify) {
        if (condition != null) {
            notifyCondition(condition);
        }
    }
    if (DEBUG)
        Slog.d(TAG, "evaluateSubscriptions took " + (System.currentTimeMillis() - now));
}
Also used : Condition(android.service.notification.Condition) EventInfo(android.service.notification.ZenModeConfig.EventInfo) ArrayList(java.util.ArrayList) Uri(android.net.Uri) CheckEventResult(com.android.server.notification.CalendarTracker.CheckEventResult)

Example 2 with CheckEventResult

use of com.android.server.notification.CalendarTracker.CheckEventResult in project android_frameworks_base by AOSPA.

the class EventConditionProvider method evaluateSubscriptionsW.

private void evaluateSubscriptionsW() {
    if (DEBUG)
        Slog.d(TAG, "evaluateSubscriptions");
    if (!mBootComplete) {
        if (DEBUG)
            Slog.d(TAG, "Skipping evaluate before boot complete");
        return;
    }
    final long now = System.currentTimeMillis();
    List<Condition> conditionsToNotify = new ArrayList<>();
    synchronized (mSubscriptions) {
        for (int i = 0; i < mTrackers.size(); i++) {
            mTrackers.valueAt(i).setCallback(mSubscriptions.isEmpty() ? null : mTrackerCallback);
        }
        setRegistered(!mSubscriptions.isEmpty());
        long reevaluateAt = 0;
        for (Uri conditionId : mSubscriptions) {
            final EventInfo event = ZenModeConfig.tryParseEventConditionId(conditionId);
            if (event == null) {
                conditionsToNotify.add(createCondition(conditionId, Condition.STATE_FALSE));
                continue;
            }
            CheckEventResult result = null;
            if (event.calendar == null) {
                // event could exist on any tracker
                for (int i = 0; i < mTrackers.size(); i++) {
                    final CalendarTracker tracker = mTrackers.valueAt(i);
                    final CheckEventResult r = tracker.checkEvent(event, now);
                    if (result == null) {
                        result = r;
                    } else {
                        result.inEvent |= r.inEvent;
                        result.recheckAt = Math.min(result.recheckAt, r.recheckAt);
                    }
                }
            } else {
                // event should exist on one tracker
                final int userId = EventInfo.resolveUserId(event.userId);
                final CalendarTracker tracker = mTrackers.get(userId);
                if (tracker == null) {
                    Slog.w(TAG, "No calendar tracker found for user " + userId);
                    conditionsToNotify.add(createCondition(conditionId, Condition.STATE_FALSE));
                    continue;
                }
                result = tracker.checkEvent(event, now);
            }
            if (result.recheckAt != 0 && (reevaluateAt == 0 || result.recheckAt < reevaluateAt)) {
                reevaluateAt = result.recheckAt;
            }
            if (!result.inEvent) {
                conditionsToNotify.add(createCondition(conditionId, Condition.STATE_FALSE));
                continue;
            }
            conditionsToNotify.add(createCondition(conditionId, Condition.STATE_TRUE));
        }
        rescheduleAlarm(now, reevaluateAt);
    }
    for (Condition condition : conditionsToNotify) {
        if (condition != null) {
            notifyCondition(condition);
        }
    }
    if (DEBUG)
        Slog.d(TAG, "evaluateSubscriptions took " + (System.currentTimeMillis() - now));
}
Also used : Condition(android.service.notification.Condition) EventInfo(android.service.notification.ZenModeConfig.EventInfo) ArrayList(java.util.ArrayList) Uri(android.net.Uri) CheckEventResult(com.android.server.notification.CalendarTracker.CheckEventResult)

Example 3 with CheckEventResult

use of com.android.server.notification.CalendarTracker.CheckEventResult in project android_frameworks_base by DirtyUnicorns.

the class EventConditionProvider method evaluateSubscriptionsW.

private void evaluateSubscriptionsW() {
    if (DEBUG)
        Slog.d(TAG, "evaluateSubscriptions");
    if (!mBootComplete) {
        if (DEBUG)
            Slog.d(TAG, "Skipping evaluate before boot complete");
        return;
    }
    final long now = System.currentTimeMillis();
    List<Condition> conditionsToNotify = new ArrayList<>();
    synchronized (mSubscriptions) {
        for (int i = 0; i < mTrackers.size(); i++) {
            mTrackers.valueAt(i).setCallback(mSubscriptions.isEmpty() ? null : mTrackerCallback);
        }
        setRegistered(!mSubscriptions.isEmpty());
        long reevaluateAt = 0;
        for (Uri conditionId : mSubscriptions) {
            final EventInfo event = ZenModeConfig.tryParseEventConditionId(conditionId);
            if (event == null) {
                conditionsToNotify.add(createCondition(conditionId, Condition.STATE_FALSE));
                continue;
            }
            CheckEventResult result = null;
            if (event.calendar == null) {
                // event could exist on any tracker
                for (int i = 0; i < mTrackers.size(); i++) {
                    final CalendarTracker tracker = mTrackers.valueAt(i);
                    final CheckEventResult r = tracker.checkEvent(event, now);
                    if (result == null) {
                        result = r;
                    } else {
                        result.inEvent |= r.inEvent;
                        result.recheckAt = Math.min(result.recheckAt, r.recheckAt);
                    }
                }
            } else {
                // event should exist on one tracker
                final int userId = EventInfo.resolveUserId(event.userId);
                final CalendarTracker tracker = mTrackers.get(userId);
                if (tracker == null) {
                    Slog.w(TAG, "No calendar tracker found for user " + userId);
                    conditionsToNotify.add(createCondition(conditionId, Condition.STATE_FALSE));
                    continue;
                }
                result = tracker.checkEvent(event, now);
            }
            if (result.recheckAt != 0 && (reevaluateAt == 0 || result.recheckAt < reevaluateAt)) {
                reevaluateAt = result.recheckAt;
            }
            if (!result.inEvent) {
                conditionsToNotify.add(createCondition(conditionId, Condition.STATE_FALSE));
                continue;
            }
            conditionsToNotify.add(createCondition(conditionId, Condition.STATE_TRUE));
        }
        rescheduleAlarm(now, reevaluateAt);
    }
    for (Condition condition : conditionsToNotify) {
        if (condition != null) {
            notifyCondition(condition);
        }
    }
    if (DEBUG)
        Slog.d(TAG, "evaluateSubscriptions took " + (System.currentTimeMillis() - now));
}
Also used : Condition(android.service.notification.Condition) EventInfo(android.service.notification.ZenModeConfig.EventInfo) ArrayList(java.util.ArrayList) Uri(android.net.Uri) CheckEventResult(com.android.server.notification.CalendarTracker.CheckEventResult)

Example 4 with CheckEventResult

use of com.android.server.notification.CalendarTracker.CheckEventResult in project android_frameworks_base by ResurrectionRemix.

the class EventConditionProvider method evaluateSubscriptionsW.

private void evaluateSubscriptionsW() {
    if (DEBUG)
        Slog.d(TAG, "evaluateSubscriptions");
    if (!mBootComplete) {
        if (DEBUG)
            Slog.d(TAG, "Skipping evaluate before boot complete");
        return;
    }
    final long now = System.currentTimeMillis();
    List<Condition> conditionsToNotify = new ArrayList<>();
    synchronized (mSubscriptions) {
        for (int i = 0; i < mTrackers.size(); i++) {
            mTrackers.valueAt(i).setCallback(mSubscriptions.isEmpty() ? null : mTrackerCallback);
        }
        setRegistered(!mSubscriptions.isEmpty());
        long reevaluateAt = 0;
        for (Uri conditionId : mSubscriptions) {
            final EventInfo event = ZenModeConfig.tryParseEventConditionId(conditionId);
            if (event == null) {
                conditionsToNotify.add(createCondition(conditionId, Condition.STATE_FALSE));
                continue;
            }
            CheckEventResult result = null;
            if (event.calendar == null) {
                // event could exist on any tracker
                for (int i = 0; i < mTrackers.size(); i++) {
                    final CalendarTracker tracker = mTrackers.valueAt(i);
                    final CheckEventResult r = tracker.checkEvent(event, now);
                    if (result == null) {
                        result = r;
                    } else {
                        result.inEvent |= r.inEvent;
                        result.recheckAt = Math.min(result.recheckAt, r.recheckAt);
                    }
                }
            } else {
                // event should exist on one tracker
                final int userId = EventInfo.resolveUserId(event.userId);
                final CalendarTracker tracker = mTrackers.get(userId);
                if (tracker == null) {
                    Slog.w(TAG, "No calendar tracker found for user " + userId);
                    conditionsToNotify.add(createCondition(conditionId, Condition.STATE_FALSE));
                    continue;
                }
                result = tracker.checkEvent(event, now);
            }
            if (result.recheckAt != 0 && (reevaluateAt == 0 || result.recheckAt < reevaluateAt)) {
                reevaluateAt = result.recheckAt;
            }
            if (!result.inEvent) {
                conditionsToNotify.add(createCondition(conditionId, Condition.STATE_FALSE));
                continue;
            }
            conditionsToNotify.add(createCondition(conditionId, Condition.STATE_TRUE));
        }
        rescheduleAlarm(now, reevaluateAt);
    }
    for (Condition condition : conditionsToNotify) {
        if (condition != null) {
            notifyCondition(condition);
        }
    }
    if (DEBUG)
        Slog.d(TAG, "evaluateSubscriptions took " + (System.currentTimeMillis() - now));
}
Also used : Condition(android.service.notification.Condition) EventInfo(android.service.notification.ZenModeConfig.EventInfo) ArrayList(java.util.ArrayList) Uri(android.net.Uri) CheckEventResult(com.android.server.notification.CalendarTracker.CheckEventResult)

Example 5 with CheckEventResult

use of com.android.server.notification.CalendarTracker.CheckEventResult in project android_frameworks_base by crdroidandroid.

the class EventConditionProvider method evaluateSubscriptionsW.

private void evaluateSubscriptionsW() {
    if (DEBUG)
        Slog.d(TAG, "evaluateSubscriptions");
    if (!mBootComplete) {
        if (DEBUG)
            Slog.d(TAG, "Skipping evaluate before boot complete");
        return;
    }
    final long now = System.currentTimeMillis();
    List<Condition> conditionsToNotify = new ArrayList<>();
    synchronized (mSubscriptions) {
        for (int i = 0; i < mTrackers.size(); i++) {
            mTrackers.valueAt(i).setCallback(mSubscriptions.isEmpty() ? null : mTrackerCallback);
        }
        setRegistered(!mSubscriptions.isEmpty());
        long reevaluateAt = 0;
        for (Uri conditionId : mSubscriptions) {
            final EventInfo event = ZenModeConfig.tryParseEventConditionId(conditionId);
            if (event == null) {
                conditionsToNotify.add(createCondition(conditionId, Condition.STATE_FALSE));
                continue;
            }
            CheckEventResult result = null;
            if (event.calendar == null) {
                // event could exist on any tracker
                for (int i = 0; i < mTrackers.size(); i++) {
                    final CalendarTracker tracker = mTrackers.valueAt(i);
                    final CheckEventResult r = tracker.checkEvent(event, now);
                    if (result == null) {
                        result = r;
                    } else {
                        result.inEvent |= r.inEvent;
                        result.recheckAt = Math.min(result.recheckAt, r.recheckAt);
                    }
                }
            } else {
                // event should exist on one tracker
                final int userId = EventInfo.resolveUserId(event.userId);
                final CalendarTracker tracker = mTrackers.get(userId);
                if (tracker == null) {
                    Slog.w(TAG, "No calendar tracker found for user " + userId);
                    conditionsToNotify.add(createCondition(conditionId, Condition.STATE_FALSE));
                    continue;
                }
                result = tracker.checkEvent(event, now);
            }
            if (result.recheckAt != 0 && (reevaluateAt == 0 || result.recheckAt < reevaluateAt)) {
                reevaluateAt = result.recheckAt;
            }
            if (!result.inEvent) {
                conditionsToNotify.add(createCondition(conditionId, Condition.STATE_FALSE));
                continue;
            }
            conditionsToNotify.add(createCondition(conditionId, Condition.STATE_TRUE));
        }
        rescheduleAlarm(now, reevaluateAt);
    }
    for (Condition condition : conditionsToNotify) {
        if (condition != null) {
            notifyCondition(condition);
        }
    }
    if (DEBUG)
        Slog.d(TAG, "evaluateSubscriptions took " + (System.currentTimeMillis() - now));
}
Also used : Condition(android.service.notification.Condition) EventInfo(android.service.notification.ZenModeConfig.EventInfo) ArrayList(java.util.ArrayList) Uri(android.net.Uri) CheckEventResult(com.android.server.notification.CalendarTracker.CheckEventResult)

Aggregations

Uri (android.net.Uri)5 Condition (android.service.notification.Condition)5 EventInfo (android.service.notification.ZenModeConfig.EventInfo)5 CheckEventResult (com.android.server.notification.CalendarTracker.CheckEventResult)5 ArrayList (java.util.ArrayList)5