1 /* 2 * Copyright (C) 2020 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 android.app.time; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.SystemApi; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 import java.util.Objects; 26 import java.util.concurrent.Executor; 27 28 /** 29 * An object containing a user's {@link TimeZoneCapabilities} and {@link TimeZoneConfiguration}. 30 * 31 * @hide 32 */ 33 @SystemApi 34 public final class TimeZoneCapabilitiesAndConfig implements Parcelable { 35 36 public static final @NonNull Creator<TimeZoneCapabilitiesAndConfig> CREATOR = new Creator<>() { 37 public TimeZoneCapabilitiesAndConfig createFromParcel(Parcel in) { 38 return TimeZoneCapabilitiesAndConfig.createFromParcel(in); 39 } 40 41 public TimeZoneCapabilitiesAndConfig[] newArray(int size) { 42 return new TimeZoneCapabilitiesAndConfig[size]; 43 } 44 }; 45 46 /** 47 * The time zone detector status. 48 * 49 * Implementation note for future platform engineers: This field is only needed by SettingsUI 50 * initially and so it has not been added to the SDK API. {@link TimeZoneDetectorStatus} 51 * contains details about the internals of the time zone detector so thought should be given to 52 * abstraction / exposing a lightweight version if something unbundled needs access to detector 53 * details. Also, that could be good time to add separate APIs for bundled components, or add 54 * new APIs that return something more extensible and generic like a Bundle or a less 55 * constraining name. See also {@link 56 * TimeManager#addTimeZoneDetectorListener(Executor, TimeManager.TimeZoneDetectorListener)}, 57 * which notified of changes to any fields in this class, including the detector status. 58 */ 59 @NonNull private final TimeZoneDetectorStatus mDetectorStatus; 60 @NonNull private final TimeZoneCapabilities mCapabilities; 61 @NonNull private final TimeZoneConfiguration mConfiguration; 62 63 /** 64 * Creates a new instance. 65 * 66 * @hide 67 */ TimeZoneCapabilitiesAndConfig( @onNull TimeZoneDetectorStatus detectorStatus, @NonNull TimeZoneCapabilities capabilities, @NonNull TimeZoneConfiguration configuration)68 public TimeZoneCapabilitiesAndConfig( 69 @NonNull TimeZoneDetectorStatus detectorStatus, 70 @NonNull TimeZoneCapabilities capabilities, 71 @NonNull TimeZoneConfiguration configuration) { 72 mDetectorStatus = Objects.requireNonNull(detectorStatus); 73 mCapabilities = Objects.requireNonNull(capabilities); 74 mConfiguration = Objects.requireNonNull(configuration); 75 } 76 77 @NonNull createFromParcel(Parcel in)78 private static TimeZoneCapabilitiesAndConfig createFromParcel(Parcel in) { 79 TimeZoneDetectorStatus detectorStatus = 80 in.readParcelable(null, TimeZoneDetectorStatus.class); 81 TimeZoneCapabilities capabilities = in.readParcelable(null, TimeZoneCapabilities.class); 82 TimeZoneConfiguration configuration = in.readParcelable(null, TimeZoneConfiguration.class); 83 return new TimeZoneCapabilitiesAndConfig(detectorStatus, capabilities, configuration); 84 } 85 86 @Override writeToParcel(@onNull Parcel dest, int flags)87 public void writeToParcel(@NonNull Parcel dest, int flags) { 88 dest.writeParcelable(mDetectorStatus, flags); 89 dest.writeParcelable(mCapabilities, flags); 90 dest.writeParcelable(mConfiguration, flags); 91 } 92 93 /** 94 * Returns the time zone detector's status. 95 * 96 * @hide 97 */ 98 @NonNull getDetectorStatus()99 public TimeZoneDetectorStatus getDetectorStatus() { 100 return mDetectorStatus; 101 } 102 103 /** 104 * Returns the user's time zone behavior capabilities. 105 */ 106 @NonNull getCapabilities()107 public TimeZoneCapabilities getCapabilities() { 108 return mCapabilities; 109 } 110 111 /** 112 * Returns the user's time zone behavior configuration. 113 */ 114 @NonNull getConfiguration()115 public TimeZoneConfiguration getConfiguration() { 116 return mConfiguration; 117 } 118 119 @Override describeContents()120 public int describeContents() { 121 return 0; 122 } 123 124 @Override equals(@ullable Object o)125 public boolean equals(@Nullable Object o) { 126 if (this == o) { 127 return true; 128 } 129 if (o == null || getClass() != o.getClass()) { 130 return false; 131 } 132 TimeZoneCapabilitiesAndConfig that = (TimeZoneCapabilitiesAndConfig) o; 133 return mDetectorStatus.equals(that.mDetectorStatus) 134 && mCapabilities.equals(that.mCapabilities) 135 && mConfiguration.equals(that.mConfiguration); 136 } 137 138 @Override hashCode()139 public int hashCode() { 140 return Objects.hash(mCapabilities, mConfiguration); 141 } 142 143 @Override toString()144 public String toString() { 145 return "TimeZoneCapabilitiesAndConfig{" 146 + "mDetectorStatus=" + mDetectorStatus 147 + ", mCapabilities=" + mCapabilities 148 + ", mConfiguration=" + mConfiguration 149 + '}'; 150 } 151 } 152