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