blob: 574f04ce670b854bc10c8a7bcee1c6895046251e [file] [log] [blame]
John Spurlockb2278d62015-04-07 12:47:12 -04001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.notification;
18
19import android.content.ComponentName;
20import android.content.Context;
21import android.net.Uri;
22import android.service.notification.ConditionProviderService;
23import android.service.notification.IConditionProvider;
John Spurlock2f096ed2015-05-04 11:58:26 -040024import android.util.TimeUtils;
John Spurlockb2278d62015-04-07 12:47:12 -040025
26import com.android.server.notification.NotificationManagerService.DumpFilter;
27
28import java.io.PrintWriter;
John Spurlock2f096ed2015-05-04 11:58:26 -040029import java.util.Date;
John Spurlockb2278d62015-04-07 12:47:12 -040030
31public abstract class SystemConditionProviderService extends ConditionProviderService {
32
33 abstract public void dump(PrintWriter pw, DumpFilter filter);
34 abstract public void attachBase(Context context);
35 abstract public IConditionProvider asInterface();
36 abstract public ComponentName getComponent();
John Spurlockd60258f2015-04-30 09:30:52 -040037 abstract public boolean isValidConditionId(Uri id);
John Spurlock2f096ed2015-05-04 11:58:26 -040038 abstract public void onBootComplete();
39
40 protected static String ts(long time) {
41 return new Date(time) + " (" + time + ")";
42 }
43
44 protected static String formatDuration(long millis) {
45 final StringBuilder sb = new StringBuilder();
46 TimeUtils.formatDuration(millis, sb);
47 return sb.toString();
48 }
John Spurlock1b8b22b2015-05-20 09:47:13 -040049
50 protected static void dumpUpcomingTime(PrintWriter pw, String var, long time, long now) {
51 pw.print(" "); pw.print(var); pw.print('=');
52 if (time > 0) {
53 pw.printf("%s, in %s, now=%s", ts(time), formatDuration(time - now), ts(now));
54 } else {
55 pw.print(time);
56 }
57 pw.println();
58 }
John Spurlockb2278d62015-04-07 12:47:12 -040059}