1 /*
2  * Copyright (C) 2017 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.timezone;
18 
19 import android.annotation.IntDef;
20 
21 import java.lang.annotation.Retention;
22 import java.lang.annotation.RetentionPolicy;
23 
24 /**
25  * Information about the status of the time zone update / data packages that are persisted by the
26  * Android system.
27  */
28 final class PackageStatus {
29 
30     @Retention(RetentionPolicy.SOURCE)
31     @IntDef({ CHECK_STARTED, CHECK_COMPLETED_SUCCESS, CHECK_COMPLETED_FAILURE })
32     @interface CheckStatus {}
33 
34     /** A time zone update check has been started but not yet completed. */
35     static final int CHECK_STARTED = 1;
36     /** A time zone update check has been completed and succeeded. */
37     static final int CHECK_COMPLETED_SUCCESS = 2;
38     /** A time zone update check has been completed and failed. */
39     static final int CHECK_COMPLETED_FAILURE = 3;
40 
41     @CheckStatus
42     final int mCheckStatus;
43 
44     // Non-null
45     final PackageVersions mVersions;
46 
PackageStatus(@heckStatus int checkStatus, PackageVersions versions)47     PackageStatus(@CheckStatus int checkStatus, PackageVersions versions) {
48         this.mCheckStatus = checkStatus;
49         if (checkStatus < 1 || checkStatus > 3) {
50             throw new IllegalArgumentException("Unknown checkStatus " + checkStatus);
51         }
52         if (versions == null) {
53             throw new NullPointerException("versions == null");
54         }
55         this.mVersions = versions;
56     }
57 
58     @Override
equals(Object o)59     public boolean equals(Object o) {
60         if (this == o) {
61             return true;
62         }
63         if (o == null || getClass() != o.getClass()) {
64             return false;
65         }
66 
67         PackageStatus that = (PackageStatus) o;
68 
69         if (mCheckStatus != that.mCheckStatus) {
70             return false;
71         }
72         return mVersions.equals(that.mVersions);
73     }
74 
75     @Override
hashCode()76     public int hashCode() {
77         int result = mCheckStatus;
78         result = 31 * result + mVersions.hashCode();
79         return result;
80     }
81 
82     @Override
toString()83     public String toString() {
84         return "PackageStatus{" +
85                 "mCheckStatus=" + mCheckStatus +
86                 ", mVersions=" + mVersions +
87                 '}';
88     }
89 }
90