1/*
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;
24import android.util.TimeUtils;
25
26import com.android.server.notification.NotificationManagerService.DumpFilter;
27
28import java.io.PrintWriter;
29import java.util.Date;
30
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();
37    abstract public boolean isValidConditionId(Uri id);
38    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    }
49
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    }
59}
60