CountdownConditionProviderpublic 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.IConditionProvider | asInterface()
return (IConditionProvider) onBind(null);
| public void | attachBase(android.content.Context base)
attachBaseContext(base);
| public void | dump(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.Condition | newCondition(long time, int state)
return new Condition(ZenModeConfig.toCountdownConditionId(time),
"", "", "", 0, state,Condition.FLAG_RELEVANT_NOW);
| public void | onConnected()
if (DEBUG) Slog.d(TAG, "onConnected");
mContext.registerReceiver(mReceiver, new IntentFilter(ACTION));
mConnected = true;
| public void | onDestroy()
super.onDestroy();
if (DEBUG) Slog.d(TAG, "onDestroy");
if (mConnected) {
mContext.unregisterReceiver(mReceiver);
}
mConnected = false;
| public void | onRequestConditions(int relevance)
// by convention
| public void | onSubscribe(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 void | onUnsubscribe(android.net.Uri conditionId)
// noop
| public static java.lang.String | tryParseDescription(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.String | ts(long time)
return new Date(time) + " (" + time + ")";
|
|