• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.os.UserHandle;
23 import android.service.notification.ConditionProviderService;
24 import android.service.notification.IConditionProvider;
25 import android.util.TimeUtils;
26 
27 import com.android.server.notification.NotificationManagerService.DumpFilter;
28 
29 import java.io.PrintWriter;
30 import java.util.Date;
31 
32 public abstract class SystemConditionProviderService extends ConditionProviderService {
33 
dump(PrintWriter pw, DumpFilter filter)34     public abstract void dump(PrintWriter pw, DumpFilter filter);
isValidConditionId(Uri id)35     public abstract boolean isValidConditionId(Uri id);
onBootComplete()36     public abstract void onBootComplete();
onUserSwitched(UserHandle user)37     public abstract void onUserSwitched(UserHandle user);
38 
getComponent()39     final ComponentName getComponent() {
40         return new ComponentName("android", this.getClass().getName());
41     }
42 
asInterface()43     final IConditionProvider asInterface() {
44         return (IConditionProvider) onBind(null);
45     }
46 
attachBase(Context context)47     final void attachBase(Context context) {
48         attachBaseContext(context);
49     }
50 
ts(long time)51     protected static String ts(long time) {
52         return new Date(time) + " (" + time + ")";
53     }
54 
formatDuration(long millis)55     protected static String formatDuration(long millis) {
56         final StringBuilder sb = new StringBuilder();
57         TimeUtils.formatDuration(millis, sb);
58         return sb.toString();
59     }
60 
dumpUpcomingTime(PrintWriter pw, String var, long time, long now)61     protected static void dumpUpcomingTime(PrintWriter pw, String var, long time, long now) {
62         pw.print("      "); pw.print(var); pw.print('=');
63         if (time > 0) {
64             pw.printf("%s, in %s, now=%s", ts(time), formatDuration(time - now), ts(now));
65         } else {
66             pw.print(time);
67         }
68         pw.println();
69     }
70 }
71