John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 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 | |
| 17 | package com.android.server.notification; |
| 18 | |
| 19 | import android.content.ComponentName; |
| 20 | import android.content.Context; |
| 21 | import android.net.Uri; |
| 22 | import android.service.notification.ConditionProviderService; |
| 23 | import android.service.notification.IConditionProvider; |
John Spurlock | 2f096ed | 2015-05-04 11:58:26 -0400 | [diff] [blame] | 24 | import android.util.TimeUtils; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 25 | |
| 26 | import com.android.server.notification.NotificationManagerService.DumpFilter; |
| 27 | |
| 28 | import java.io.PrintWriter; |
John Spurlock | 2f096ed | 2015-05-04 11:58:26 -0400 | [diff] [blame] | 29 | import java.util.Date; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 30 | |
| 31 | public 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 Spurlock | d60258f | 2015-04-30 09:30:52 -0400 | [diff] [blame] | 37 | abstract public boolean isValidConditionId(Uri id); |
John Spurlock | 2f096ed | 2015-05-04 11:58:26 -0400 | [diff] [blame] | 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 | } |
John Spurlock | 1b8b22b | 2015-05-20 09:47:13 -0400 | [diff] [blame] | 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 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 59 | } |