FileDocCategorySizeDatePackage
CountdownConditionProvider.javaAPI DocAndroid 5.1 API6226Thu Mar 12 22:22:42 GMT 2015com.android.server.notification

CountdownConditionProvider

public class CountdownConditionProvider extends android.service.notification.ConditionProviderService
Built-in zen condition provider for simple time-based conditions

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
public static final android.content.ComponentName
COMPONENT
private static final String
ACTION
private static final int
REQUEST_CODE
private static final String
EXTRA_CONDITION_ID
private final android.content.Context
mContext
private final Receiver
mReceiver
private boolean
mConnected
private long
mTime
Constructors Summary
public CountdownConditionProvider()


      
        if (DEBUG) Slog.d(TAG, "new CountdownConditionProvider()");
    
Methods Summary
public android.service.notification.IConditionProviderasInterface()

        return (IConditionProvider) onBind(null);
    
public voidattachBase(android.content.Context base)

        attachBaseContext(base);
    
public voiddump(java.io.PrintWriter pw, com.android.server.notification.NotificationManagerService.DumpFilter filter)

        pw.println("    CountdownConditionProvider:");
        pw.print("      mConnected="); pw.println(mConnected);
        pw.print("      mTime="); pw.println(mTime);
    
private static final android.service.notification.ConditionnewCondition(long time, int state)

        return new Condition(ZenModeConfig.toCountdownConditionId(time),
                "", "", "", 0, state,Condition.FLAG_RELEVANT_NOW);
    
public voidonConnected()

        if (DEBUG) Slog.d(TAG, "onConnected");
        mContext.registerReceiver(mReceiver, new IntentFilter(ACTION));
        mConnected = true;
    
public voidonDestroy()

        super.onDestroy();
        if (DEBUG) Slog.d(TAG, "onDestroy");
        if (mConnected) {
            mContext.unregisterReceiver(mReceiver);
        }
        mConnected = false;
    
public voidonRequestConditions(int relevance)

        // by convention
    
public voidonSubscribe(android.net.Uri conditionId)

        if (DEBUG) Slog.d(TAG, "onSubscribe " + conditionId);
        mTime = ZenModeConfig.tryParseCountdownConditionId(conditionId);
        final AlarmManager alarms = (AlarmManager)
                mContext.getSystemService(Context.ALARM_SERVICE);
        final Intent intent = new Intent(ACTION).putExtra(EXTRA_CONDITION_ID, conditionId)
                .setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
        final PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, REQUEST_CODE,
                intent, PendingIntent.FLAG_UPDATE_CURRENT);
        alarms.cancel(pendingIntent);
        if (mTime > 0) {
            final long now = System.currentTimeMillis();
            final CharSequence span =
                    DateUtils.getRelativeTimeSpanString(mTime, now, DateUtils.MINUTE_IN_MILLIS);
            if (mTime <= now) {
                // in the past, already false
                notifyCondition(newCondition(mTime, Condition.STATE_FALSE));
            } else {
                // in the future, set an alarm
                alarms.setExact(AlarmManager.RTC_WAKEUP, mTime, pendingIntent);
            }
            if (DEBUG) Slog.d(TAG, String.format(
                    "%s %s for %s, %s in the future (%s), now=%s",
                    (mTime <= now ? "Not scheduling" : "Scheduling"),
                    ACTION, ts(mTime), mTime - now, span, ts(now)));
        }
    
public voidonUnsubscribe(android.net.Uri conditionId)

        // noop
    
public static java.lang.StringtryParseDescription(android.net.Uri conditionUri)

        final long time = ZenModeConfig.tryParseCountdownConditionId(conditionUri);
        if (time == 0) return null;
        final long now = System.currentTimeMillis();
        final CharSequence span =
                DateUtils.getRelativeTimeSpanString(time, now, DateUtils.MINUTE_IN_MILLIS);
        return String.format("Scheduled for %s, %s in the future (%s), now=%s",
                ts(time), time - now, span, ts(now));
    
private static java.lang.Stringts(long time)

        return new Date(time) + " (" + time + ")";