ZenModeConfig.java revision 4dd81467e33a694138da6916fc68ca79501a9429
1/**
2 * Copyright (c) 2014, 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 android.service.notification;
18
19import android.content.ComponentName;
20import android.content.res.Resources;
21import android.net.Uri;
22import android.os.Parcel;
23import android.os.Parcelable;
24import android.text.TextUtils;
25import android.util.Slog;
26
27import org.xmlpull.v1.XmlPullParser;
28import org.xmlpull.v1.XmlPullParserException;
29import org.xmlpull.v1.XmlSerializer;
30
31import java.io.IOException;
32import java.util.ArrayList;
33import java.util.Arrays;
34import java.util.Calendar;
35import java.util.Objects;
36
37/**
38 * Persisted configuration for zen mode.
39 *
40 * @hide
41 */
42public class ZenModeConfig implements Parcelable {
43    private static String TAG = "ZenModeConfig";
44
45    public static final String SLEEP_MODE_NIGHTS = "nights";
46    public static final String SLEEP_MODE_WEEKNIGHTS = "weeknights";
47    public static final String SLEEP_MODE_DAYS_PREFIX = "days:";
48
49    public static final int SOURCE_ANYONE = 0;
50    public static final int SOURCE_CONTACT = 1;
51    public static final int SOURCE_STAR = 2;
52    public static final int MAX_SOURCE = SOURCE_STAR;
53
54    public static final int[] ALL_DAYS = { Calendar.SUNDAY, Calendar.MONDAY, Calendar.TUESDAY,
55            Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY, Calendar.SATURDAY };
56    public static final int[] WEEKNIGHT_DAYS = { Calendar.SUNDAY, Calendar.MONDAY, Calendar.TUESDAY,
57            Calendar.WEDNESDAY, Calendar.THURSDAY };
58
59    public static final int[] MINUTE_BUCKETS = new int[] { 15, 30, 45, 60, 120, 180, 240, 480 };
60    private static final int SECONDS_MS = 1000;
61    private static final int MINUTES_MS = 60 * SECONDS_MS;
62    private static final int ZERO_VALUE_MS = 20 * SECONDS_MS;
63
64    private static final int XML_VERSION = 1;
65    private static final String ZEN_TAG = "zen";
66    private static final String ZEN_ATT_VERSION = "version";
67    private static final String ALLOW_TAG = "allow";
68    private static final String ALLOW_ATT_CALLS = "calls";
69    private static final String ALLOW_ATT_MESSAGES = "messages";
70    private static final String ALLOW_ATT_FROM = "from";
71    private static final String SLEEP_TAG = "sleep";
72    private static final String SLEEP_ATT_MODE = "mode";
73
74    private static final String SLEEP_ATT_START_HR = "startHour";
75    private static final String SLEEP_ATT_START_MIN = "startMin";
76    private static final String SLEEP_ATT_END_HR = "endHour";
77    private static final String SLEEP_ATT_END_MIN = "endMin";
78
79    private static final String CONDITION_TAG = "condition";
80    private static final String CONDITION_ATT_COMPONENT = "component";
81    private static final String CONDITION_ATT_ID = "id";
82    private static final String CONDITION_ATT_SUMMARY = "summary";
83    private static final String CONDITION_ATT_LINE1 = "line1";
84    private static final String CONDITION_ATT_LINE2 = "line2";
85    private static final String CONDITION_ATT_ICON = "icon";
86    private static final String CONDITION_ATT_STATE = "state";
87    private static final String CONDITION_ATT_FLAGS = "flags";
88
89    private static final String EXIT_CONDITION_TAG = "exitCondition";
90    private static final String EXIT_CONDITION_ATT_COMPONENT = "component";
91
92    public boolean allowCalls;
93    public boolean allowMessages;
94    public int allowFrom = SOURCE_ANYONE;
95
96    public String sleepMode;
97    public int sleepStartHour;   // 0-23
98    public int sleepStartMinute; // 0-59
99    public int sleepEndHour;
100    public int sleepEndMinute;
101    public ComponentName[] conditionComponents;
102    public Uri[] conditionIds;
103    public Condition exitCondition;
104    public ComponentName exitConditionComponent;
105
106    public ZenModeConfig() { }
107
108    public ZenModeConfig(Parcel source) {
109        allowCalls = source.readInt() == 1;
110        allowMessages = source.readInt() == 1;
111        if (source.readInt() == 1) {
112            sleepMode = source.readString();
113        }
114        sleepStartHour = source.readInt();
115        sleepStartMinute = source.readInt();
116        sleepEndHour = source.readInt();
117        sleepEndMinute = source.readInt();
118        int len = source.readInt();
119        if (len > 0) {
120            conditionComponents = new ComponentName[len];
121            source.readTypedArray(conditionComponents, ComponentName.CREATOR);
122        }
123        len = source.readInt();
124        if (len > 0) {
125            conditionIds = new Uri[len];
126            source.readTypedArray(conditionIds, Uri.CREATOR);
127        }
128        allowFrom = source.readInt();
129        exitCondition = source.readParcelable(null);
130        exitConditionComponent = source.readParcelable(null);
131    }
132
133    @Override
134    public void writeToParcel(Parcel dest, int flags) {
135        dest.writeInt(allowCalls ? 1 : 0);
136        dest.writeInt(allowMessages ? 1 : 0);
137        if (sleepMode != null) {
138            dest.writeInt(1);
139            dest.writeString(sleepMode);
140        } else {
141            dest.writeInt(0);
142        }
143        dest.writeInt(sleepStartHour);
144        dest.writeInt(sleepStartMinute);
145        dest.writeInt(sleepEndHour);
146        dest.writeInt(sleepEndMinute);
147        if (conditionComponents != null && conditionComponents.length > 0) {
148            dest.writeInt(conditionComponents.length);
149            dest.writeTypedArray(conditionComponents, 0);
150        } else {
151            dest.writeInt(0);
152        }
153        if (conditionIds != null && conditionIds.length > 0) {
154            dest.writeInt(conditionIds.length);
155            dest.writeTypedArray(conditionIds, 0);
156        } else {
157            dest.writeInt(0);
158        }
159        dest.writeInt(allowFrom);
160        dest.writeParcelable(exitCondition, 0);
161        dest.writeParcelable(exitConditionComponent, 0);
162    }
163
164    @Override
165    public String toString() {
166        return new StringBuilder(ZenModeConfig.class.getSimpleName()).append('[')
167            .append("allowCalls=").append(allowCalls)
168            .append(",allowMessages=").append(allowMessages)
169            .append(",allowFrom=").append(sourceToString(allowFrom))
170            .append(",sleepMode=").append(sleepMode)
171            .append(",sleepStart=").append(sleepStartHour).append('.').append(sleepStartMinute)
172            .append(",sleepEnd=").append(sleepEndHour).append('.').append(sleepEndMinute)
173            .append(",conditionComponents=")
174            .append(conditionComponents == null ? null : TextUtils.join(",", conditionComponents))
175            .append(",conditionIds=")
176            .append(conditionIds == null ? null : TextUtils.join(",", conditionIds))
177            .append(",exitCondition=").append(exitCondition)
178            .append(",exitConditionComponent=").append(exitConditionComponent)
179            .append(']').toString();
180    }
181
182    public static String sourceToString(int source) {
183        switch (source) {
184            case SOURCE_ANYONE:
185                return "anyone";
186            case SOURCE_CONTACT:
187                return "contacts";
188            case SOURCE_STAR:
189                return "stars";
190            default:
191                return "UNKNOWN";
192        }
193    }
194
195    @Override
196    public boolean equals(Object o) {
197        if (!(o instanceof ZenModeConfig)) return false;
198        if (o == this) return true;
199        final ZenModeConfig other = (ZenModeConfig) o;
200        return other.allowCalls == allowCalls
201                && other.allowMessages == allowMessages
202                && other.allowFrom == allowFrom
203                && Objects.equals(other.sleepMode, sleepMode)
204                && other.sleepStartHour == sleepStartHour
205                && other.sleepStartMinute == sleepStartMinute
206                && other.sleepEndHour == sleepEndHour
207                && other.sleepEndMinute == sleepEndMinute
208                && Objects.deepEquals(other.conditionComponents, conditionComponents)
209                && Objects.deepEquals(other.conditionIds, conditionIds)
210                && Objects.equals(other.exitCondition, exitCondition)
211                && Objects.equals(other.exitConditionComponent, exitConditionComponent);
212    }
213
214    @Override
215    public int hashCode() {
216        return Objects.hash(allowCalls, allowMessages, allowFrom, sleepMode,
217                sleepStartHour, sleepStartMinute, sleepEndHour, sleepEndMinute,
218                Arrays.hashCode(conditionComponents), Arrays.hashCode(conditionIds),
219                exitCondition, exitConditionComponent);
220    }
221
222    public boolean isValid() {
223        return isValidHour(sleepStartHour) && isValidMinute(sleepStartMinute)
224                && isValidHour(sleepEndHour) && isValidMinute(sleepEndMinute)
225                && isValidSleepMode(sleepMode);
226    }
227
228    public static boolean isValidSleepMode(String sleepMode) {
229        return sleepMode == null || sleepMode.equals(SLEEP_MODE_NIGHTS)
230                || sleepMode.equals(SLEEP_MODE_WEEKNIGHTS) || tryParseDays(sleepMode) != null;
231    }
232
233    public static int[] tryParseDays(String sleepMode) {
234        if (sleepMode == null) return null;
235        sleepMode = sleepMode.trim();
236        if (SLEEP_MODE_NIGHTS.equals(sleepMode)) return ALL_DAYS;
237        if (SLEEP_MODE_WEEKNIGHTS.equals(sleepMode)) return WEEKNIGHT_DAYS;
238        if (!sleepMode.startsWith(SLEEP_MODE_DAYS_PREFIX)) return null;
239        if (sleepMode.equals(SLEEP_MODE_DAYS_PREFIX)) return null;
240        final String[] tokens = sleepMode.substring(SLEEP_MODE_DAYS_PREFIX.length()).split(",");
241        if (tokens.length == 0) return null;
242        final int[] rt = new int[tokens.length];
243        for (int i = 0; i < tokens.length; i++) {
244            final int day = tryParseInt(tokens[i], -1);
245            if (day == -1) return null;
246            rt[i] = day;
247        }
248        return rt;
249    }
250
251    private static int tryParseInt(String value, int defValue) {
252        if (TextUtils.isEmpty(value)) return defValue;
253        try {
254            return Integer.valueOf(value);
255        } catch (NumberFormatException e) {
256            return defValue;
257        }
258    }
259
260    public static ZenModeConfig readXml(XmlPullParser parser)
261            throws XmlPullParserException, IOException {
262        int type = parser.getEventType();
263        if (type != XmlPullParser.START_TAG) return null;
264        String tag = parser.getName();
265        if (!ZEN_TAG.equals(tag)) return null;
266        final ZenModeConfig rt = new ZenModeConfig();
267        final int version = safeInt(parser, ZEN_ATT_VERSION, XML_VERSION);
268        final ArrayList<ComponentName> conditionComponents = new ArrayList<ComponentName>();
269        final ArrayList<Uri> conditionIds = new ArrayList<Uri>();
270        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) {
271            tag = parser.getName();
272            if (type == XmlPullParser.END_TAG && ZEN_TAG.equals(tag)) {
273                if (!conditionComponents.isEmpty()) {
274                    rt.conditionComponents = conditionComponents
275                            .toArray(new ComponentName[conditionComponents.size()]);
276                    rt.conditionIds = conditionIds.toArray(new Uri[conditionIds.size()]);
277                }
278                return rt;
279            }
280            if (type == XmlPullParser.START_TAG) {
281                if (ALLOW_TAG.equals(tag)) {
282                    rt.allowCalls = safeBoolean(parser, ALLOW_ATT_CALLS, false);
283                    rt.allowMessages = safeBoolean(parser, ALLOW_ATT_MESSAGES, false);
284                    rt.allowFrom = safeInt(parser, ALLOW_ATT_FROM, SOURCE_ANYONE);
285                    if (rt.allowFrom < SOURCE_ANYONE || rt.allowFrom > MAX_SOURCE) {
286                        throw new IndexOutOfBoundsException("bad source in config:" + rt.allowFrom);
287                    }
288                } else if (SLEEP_TAG.equals(tag)) {
289                    final String mode = parser.getAttributeValue(null, SLEEP_ATT_MODE);
290                    rt.sleepMode = isValidSleepMode(mode)? mode : null;
291                    final int startHour = safeInt(parser, SLEEP_ATT_START_HR, 0);
292                    final int startMinute = safeInt(parser, SLEEP_ATT_START_MIN, 0);
293                    final int endHour = safeInt(parser, SLEEP_ATT_END_HR, 0);
294                    final int endMinute = safeInt(parser, SLEEP_ATT_END_MIN, 0);
295                    rt.sleepStartHour = isValidHour(startHour) ? startHour : 0;
296                    rt.sleepStartMinute = isValidMinute(startMinute) ? startMinute : 0;
297                    rt.sleepEndHour = isValidHour(endHour) ? endHour : 0;
298                    rt.sleepEndMinute = isValidMinute(endMinute) ? endMinute : 0;
299                } else if (CONDITION_TAG.equals(tag)) {
300                    final ComponentName component =
301                            safeComponentName(parser, CONDITION_ATT_COMPONENT);
302                    final Uri conditionId = safeUri(parser, CONDITION_ATT_ID);
303                    if (component != null && conditionId != null) {
304                        conditionComponents.add(component);
305                        conditionIds.add(conditionId);
306                    }
307                } else if (EXIT_CONDITION_TAG.equals(tag)) {
308                    rt.exitCondition = readConditionXml(parser);
309                    if (rt.exitCondition != null) {
310                        rt.exitConditionComponent =
311                                safeComponentName(parser, EXIT_CONDITION_ATT_COMPONENT);
312                    }
313                }
314            }
315        }
316        throw new IllegalStateException("Failed to reach END_DOCUMENT");
317    }
318
319    public void writeXml(XmlSerializer out) throws IOException {
320        out.startTag(null, ZEN_TAG);
321        out.attribute(null, ZEN_ATT_VERSION, Integer.toString(XML_VERSION));
322
323        out.startTag(null, ALLOW_TAG);
324        out.attribute(null, ALLOW_ATT_CALLS, Boolean.toString(allowCalls));
325        out.attribute(null, ALLOW_ATT_MESSAGES, Boolean.toString(allowMessages));
326        out.attribute(null, ALLOW_ATT_FROM, Integer.toString(allowFrom));
327        out.endTag(null, ALLOW_TAG);
328
329        out.startTag(null, SLEEP_TAG);
330        if (sleepMode != null) {
331            out.attribute(null, SLEEP_ATT_MODE, sleepMode);
332        }
333        out.attribute(null, SLEEP_ATT_START_HR, Integer.toString(sleepStartHour));
334        out.attribute(null, SLEEP_ATT_START_MIN, Integer.toString(sleepStartMinute));
335        out.attribute(null, SLEEP_ATT_END_HR, Integer.toString(sleepEndHour));
336        out.attribute(null, SLEEP_ATT_END_MIN, Integer.toString(sleepEndMinute));
337        out.endTag(null, SLEEP_TAG);
338
339        if (conditionComponents != null && conditionIds != null
340                && conditionComponents.length == conditionIds.length) {
341            for (int i = 0; i < conditionComponents.length; i++) {
342                out.startTag(null, CONDITION_TAG);
343                out.attribute(null, CONDITION_ATT_COMPONENT,
344                        conditionComponents[i].flattenToString());
345                out.attribute(null, CONDITION_ATT_ID, conditionIds[i].toString());
346                out.endTag(null, CONDITION_TAG);
347            }
348        }
349        if (exitCondition != null && exitConditionComponent != null) {
350            out.startTag(null, EXIT_CONDITION_TAG);
351            out.attribute(null, EXIT_CONDITION_ATT_COMPONENT,
352                    exitConditionComponent.flattenToString());
353            writeConditionXml(exitCondition, out);
354            out.endTag(null, EXIT_CONDITION_TAG);
355        }
356        out.endTag(null, ZEN_TAG);
357    }
358
359    public static Condition readConditionXml(XmlPullParser parser) {
360        final Uri id = safeUri(parser, CONDITION_ATT_ID);
361        final String summary = parser.getAttributeValue(null, CONDITION_ATT_SUMMARY);
362        final String line1 = parser.getAttributeValue(null, CONDITION_ATT_LINE1);
363        final String line2 = parser.getAttributeValue(null, CONDITION_ATT_LINE2);
364        final int icon = safeInt(parser, CONDITION_ATT_ICON, -1);
365        final int state = safeInt(parser, CONDITION_ATT_STATE, -1);
366        final int flags = safeInt(parser, CONDITION_ATT_FLAGS, -1);
367        try {
368            return new Condition(id, summary, line1, line2, icon, state, flags);
369        } catch (IllegalArgumentException e) {
370            Slog.w(TAG, "Unable to read condition xml", e);
371            return null;
372        }
373    }
374
375    public static void writeConditionXml(Condition c, XmlSerializer out) throws IOException {
376        out.attribute(null, CONDITION_ATT_ID, c.id.toString());
377        out.attribute(null, CONDITION_ATT_SUMMARY, c.summary);
378        out.attribute(null, CONDITION_ATT_LINE1, c.line1);
379        out.attribute(null, CONDITION_ATT_LINE2, c.line2);
380        out.attribute(null, CONDITION_ATT_ICON, Integer.toString(c.icon));
381        out.attribute(null, CONDITION_ATT_STATE, Integer.toString(c.state));
382        out.attribute(null, CONDITION_ATT_FLAGS, Integer.toString(c.flags));
383    }
384
385    public static boolean isValidHour(int val) {
386        return val >= 0 && val < 24;
387    }
388
389    public static boolean isValidMinute(int val) {
390        return val >= 0 && val < 60;
391    }
392
393    private static boolean safeBoolean(XmlPullParser parser, String att, boolean defValue) {
394        final String val = parser.getAttributeValue(null, att);
395        if (TextUtils.isEmpty(val)) return defValue;
396        return Boolean.valueOf(val);
397    }
398
399    private static int safeInt(XmlPullParser parser, String att, int defValue) {
400        final String val = parser.getAttributeValue(null, att);
401        return tryParseInt(val, defValue);
402    }
403
404    private static ComponentName safeComponentName(XmlPullParser parser, String att) {
405        final String val = parser.getAttributeValue(null, att);
406        if (TextUtils.isEmpty(val)) return null;
407        return ComponentName.unflattenFromString(val);
408    }
409
410    private static Uri safeUri(XmlPullParser parser, String att) {
411        final String val = parser.getAttributeValue(null, att);
412        if (TextUtils.isEmpty(val)) return null;
413        return Uri.parse(val);
414    }
415
416    @Override
417    public int describeContents() {
418        return 0;
419    }
420
421    public ZenModeConfig copy() {
422        final Parcel parcel = Parcel.obtain();
423        try {
424            writeToParcel(parcel, 0);
425            parcel.setDataPosition(0);
426            return new ZenModeConfig(parcel);
427        } finally {
428            parcel.recycle();
429        }
430    }
431
432    public static final Parcelable.Creator<ZenModeConfig> CREATOR
433            = new Parcelable.Creator<ZenModeConfig>() {
434        @Override
435        public ZenModeConfig createFromParcel(Parcel source) {
436            return new ZenModeConfig(source);
437        }
438
439        @Override
440        public ZenModeConfig[] newArray(int size) {
441            return new ZenModeConfig[size];
442        }
443    };
444
445    public DowntimeInfo toDowntimeInfo() {
446        final DowntimeInfo downtime = new DowntimeInfo();
447        downtime.startHour = sleepStartHour;
448        downtime.startMinute = sleepStartMinute;
449        downtime.endHour = sleepEndHour;
450        downtime.endMinute = sleepEndMinute;
451        return downtime;
452    }
453
454    public static Condition toTimeCondition(int minutesFromNow) {
455        final long now = System.currentTimeMillis();
456        final long millis = minutesFromNow == 0 ? ZERO_VALUE_MS : minutesFromNow * MINUTES_MS;
457        return toTimeCondition(now + millis, minutesFromNow);
458    }
459
460    public static Condition toTimeCondition(long time, int minutes) {
461        final int num = minutes < 60 ? minutes : Math.round(minutes / 60f);
462        final int resId = minutes < 60
463                ? com.android.internal.R.plurals.zen_mode_duration_minutes
464                : com.android.internal.R.plurals.zen_mode_duration_hours;
465        final String caption = Resources.getSystem().getQuantityString(resId, num, num);
466        final Uri id = toCountdownConditionId(time);
467        return new Condition(id, caption, "", "", 0, Condition.STATE_TRUE,
468                Condition.FLAG_RELEVANT_NOW);
469    }
470
471    // For built-in conditions
472    private static final String SYSTEM_AUTHORITY = "android";
473
474    // Built-in countdown conditions, e.g. condition://android/countdown/1399917958951
475    private static final String COUNTDOWN_PATH = "countdown";
476
477    public static Uri toCountdownConditionId(long time) {
478        return new Uri.Builder().scheme(Condition.SCHEME)
479                .authority(SYSTEM_AUTHORITY)
480                .appendPath(COUNTDOWN_PATH)
481                .appendPath(Long.toString(time))
482                .build();
483    }
484
485    public static long tryParseCountdownConditionId(Uri conditionId) {
486        if (!Condition.isValidId(conditionId, SYSTEM_AUTHORITY)) return 0;
487        if (conditionId.getPathSegments().size() != 2
488                || !COUNTDOWN_PATH.equals(conditionId.getPathSegments().get(0))) return 0;
489        try {
490            return Long.parseLong(conditionId.getPathSegments().get(1));
491        } catch (RuntimeException e) {
492            Slog.w(TAG, "Error parsing countdown condition: " + conditionId, e);
493            return 0;
494        }
495    }
496
497    public static boolean isValidCountdownConditionId(Uri conditionId) {
498        return tryParseCountdownConditionId(conditionId) != 0;
499    }
500
501    // Built-in downtime conditions, e.g. condition://android/downtime?start=10.00&end=7.00
502    private static final String DOWNTIME_PATH = "downtime";
503
504    public static Uri toDowntimeConditionId(DowntimeInfo downtime) {
505        return new Uri.Builder().scheme(Condition.SCHEME)
506                .authority(SYSTEM_AUTHORITY)
507                .appendPath(DOWNTIME_PATH)
508                .appendQueryParameter("start", downtime.startHour + "." + downtime.startMinute)
509                .appendQueryParameter("end", downtime.endHour + "." + downtime.endMinute)
510                .build();
511    }
512
513    public static DowntimeInfo tryParseDowntimeConditionId(Uri conditionId) {
514        if (!Condition.isValidId(conditionId, SYSTEM_AUTHORITY)
515                || conditionId.getPathSegments().size() != 1
516                || !DOWNTIME_PATH.equals(conditionId.getPathSegments().get(0))) {
517            return null;
518        }
519        final int[] start = tryParseHourAndMinute(conditionId.getQueryParameter("start"));
520        final int[] end = tryParseHourAndMinute(conditionId.getQueryParameter("end"));
521        if (start == null || end == null) return null;
522        final DowntimeInfo downtime = new DowntimeInfo();
523        downtime.startHour = start[0];
524        downtime.startMinute = start[1];
525        downtime.endHour = end[0];
526        downtime.endMinute = end[1];
527        return downtime;
528    }
529
530    private static int[] tryParseHourAndMinute(String value) {
531        if (TextUtils.isEmpty(value)) return null;
532        final int i = value.indexOf('.');
533        if (i < 1 || i >= value.length() - 1) return null;
534        final int hour = tryParseInt(value.substring(0, i), -1);
535        final int minute = tryParseInt(value.substring(i + 1), -1);
536        return isValidHour(hour) && isValidMinute(minute) ? new int[] { hour, minute } : null;
537    }
538
539    public static boolean isValidDowntimeConditionId(Uri conditionId) {
540        return tryParseDowntimeConditionId(conditionId) != null;
541    }
542
543    public static class DowntimeInfo {
544        public int startHour;   // 0-23
545        public int startMinute; // 0-59
546        public int endHour;
547        public int endMinute;
548
549        @Override
550        public int hashCode() {
551            return 0;
552        }
553
554        @Override
555        public boolean equals(Object o) {
556            if (!(o instanceof DowntimeInfo)) return false;
557            final DowntimeInfo other = (DowntimeInfo) o;
558            return startHour == other.startHour
559                    && startMinute == other.startMinute
560                    && endHour == other.endHour
561                    && endMinute == other.endMinute;
562        }
563    }
564}
565