• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.internal.compat;
18 
19 import android.annotation.Nullable;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 
23 /**
24  * This class is a parcelable version of {@link com.android.server.compat.Change}.
25  *
26  * @hide
27  */
28 public class CompatibilityChangeInfo implements Parcelable {
29     private final long mChangeId;
30     private final @Nullable String mName;
31     private final int mEnableSinceTargetSdk;
32     private final boolean mDisabled;
33     private final boolean mLoggingOnly;
34     private final @Nullable String mDescription;
35     private final boolean mOverridable;
36 
getId()37     public long getId() {
38         return mChangeId;
39     }
40 
41     @Nullable
getName()42     public String getName() {
43         return mName;
44     }
45 
getEnableSinceTargetSdk()46     public int getEnableSinceTargetSdk() {
47         return mEnableSinceTargetSdk;
48     }
49 
getDisabled()50     public boolean getDisabled() {
51         return mDisabled;
52     }
53 
getLoggingOnly()54     public boolean getLoggingOnly() {
55         return mLoggingOnly;
56     }
57 
getDescription()58     public String getDescription()  {
59         return mDescription;
60     }
61 
getOverridable()62     public boolean getOverridable() {
63         return mOverridable;
64     }
65 
CompatibilityChangeInfo( Long changeId, String name, int enableAfterTargetSdk, int enableSinceTargetSdk, boolean disabled, boolean loggingOnly, String description, boolean overridable)66     public CompatibilityChangeInfo(
67             Long changeId, String name, int enableAfterTargetSdk, int enableSinceTargetSdk,
68             boolean disabled, boolean loggingOnly, String description, boolean overridable) {
69         this.mChangeId = changeId;
70         this.mName = name;
71         if (enableAfterTargetSdk > 0) {
72             // Need to maintain support for @EnabledAfter(X), but make it equivalent to
73             // @EnabledSince(X+1)
74             this.mEnableSinceTargetSdk = enableAfterTargetSdk + 1;
75         } else if (enableSinceTargetSdk > 0) {
76             this.mEnableSinceTargetSdk = enableSinceTargetSdk;
77         } else {
78             this.mEnableSinceTargetSdk = -1;
79         }
80         this.mDisabled = disabled;
81         this.mLoggingOnly = loggingOnly;
82         this.mDescription = description;
83         this.mOverridable = overridable;
84     }
85 
CompatibilityChangeInfo(CompatibilityChangeInfo other)86     public CompatibilityChangeInfo(CompatibilityChangeInfo other) {
87         this.mChangeId = other.mChangeId;
88         this.mName = other.mName;
89         this.mEnableSinceTargetSdk = other.mEnableSinceTargetSdk;
90         this.mDisabled = other.mDisabled;
91         this.mLoggingOnly = other.mLoggingOnly;
92         this.mDescription = other.mDescription;
93         this.mOverridable = other.mOverridable;
94     }
95 
CompatibilityChangeInfo(Parcel in)96     private CompatibilityChangeInfo(Parcel in) {
97         mChangeId = in.readLong();
98         mName = in.readString();
99         mEnableSinceTargetSdk = in.readInt();
100         mDisabled = in.readBoolean();
101         mLoggingOnly = in.readBoolean();
102         mDescription = in.readString();
103         mOverridable = in.readBoolean();
104     }
105 
106     @Override
describeContents()107     public int describeContents() {
108         return 0;
109     }
110 
111     @Override
writeToParcel(Parcel dest, int flags)112     public void writeToParcel(Parcel dest, int flags) {
113         dest.writeLong(mChangeId);
114         dest.writeString(mName);
115         dest.writeInt(mEnableSinceTargetSdk);
116         dest.writeBoolean(mDisabled);
117         dest.writeBoolean(mLoggingOnly);
118         dest.writeString(mDescription);
119         dest.writeBoolean(mOverridable);
120     }
121 
122     @Override
toString()123     public String toString() {
124         StringBuilder sb = new StringBuilder("CompatibilityChangeInfo(")
125                 .append(getId());
126         if (getName() != null) {
127             sb.append("; name=").append(getName());
128         }
129         if (getEnableSinceTargetSdk() != -1) {
130             sb.append("; enableSinceTargetSdk=").append(getEnableSinceTargetSdk());
131         }
132         if (getDisabled()) {
133             sb.append("; disabled");
134         }
135         if (getLoggingOnly()) {
136             sb.append("; loggingOnly");
137         }
138         if (getOverridable()) {
139             sb.append("; overridable");
140         }
141         return sb.append(")").toString();
142     }
143 
144     @Override
equals(Object o)145     public boolean equals(Object o) {
146         if (this == o) {
147             return true;
148         }
149         if (o == null || !(o instanceof CompatibilityChangeInfo)) {
150             return false;
151         }
152         CompatibilityChangeInfo that = (CompatibilityChangeInfo) o;
153         return this.mChangeId == that.mChangeId
154                 && this.mName.equals(that.mName)
155                 && this.mEnableSinceTargetSdk == that.mEnableSinceTargetSdk
156                 && this.mDisabled == that.mDisabled
157                 && this.mLoggingOnly == that.mLoggingOnly
158                 && this.mDescription.equals(that.mDescription)
159                 && this.mOverridable == that.mOverridable;
160     }
161 
162     public static final Parcelable.Creator<CompatibilityChangeInfo> CREATOR =
163             new Parcelable.Creator<CompatibilityChangeInfo>() {
164 
165                 @Override
166                 public CompatibilityChangeInfo createFromParcel(Parcel in) {
167                     return new CompatibilityChangeInfo(in);
168                 }
169 
170                 @Override
171                 public CompatibilityChangeInfo[] newArray(int size) {
172                     return new CompatibilityChangeInfo[size];
173                 }
174             };
175 }
176