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.car.hardware.power; 18 19 import static android.car.hardware.power.PowerComponentUtil.powerComponentsToString; 20 21 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE; 22 23 import android.annotation.NonNull; 24 import android.os.Parcelable; 25 26 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport; 27 import com.android.car.internal.util.AnnotationValidations; 28 import com.android.car.internal.util.DataClass; 29 import com.android.car.internal.util.Lists; 30 31 /** 32 * Car power policy definition. 33 */ 34 @DataClass(genHiddenConstructor = true) 35 public final class CarPowerPolicy implements Parcelable { 36 /** 37 * ID of power policy. 38 */ 39 private @NonNull String mPolicyId = ""; 40 41 /** 42 * List of enabled components. Components are one of 43 * {@code android.frameworks.automotive.powerpolicy.PowerComponent}. 44 */ 45 private @NonNull int[] mEnabledComponents = new int[]{}; 46 47 /** 48 * List of disabled components. Components are one of 49 * {@code android.frameworks.automotive.powerpolicy.PowerComponent}. 50 */ 51 private @NonNull int[] mDisabledComponents = new int[]{}; 52 53 /** 54 * Returns {@code true} if the given component is enabled in the power policy. Otherwise, 55 * {@code false}. 56 */ isComponentEnabled(int component)57 public boolean isComponentEnabled(int component) { 58 for (int i = 0; i < mEnabledComponents.length; i++) { 59 if (component == mEnabledComponents[i]) { 60 return true; 61 } 62 } 63 return false; 64 } 65 66 @Override 67 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) toString()68 public String toString() { 69 return String.format("%s(enabledComponents: %s, disabledComponents: %s)", mPolicyId, 70 powerComponentsToString(Lists.asImmutableList(mEnabledComponents)), 71 powerComponentsToString(Lists.asImmutableList(mDisabledComponents))); 72 } 73 74 75 76 // Code below generated by codegen v1.0.23. 77 // 78 // DO NOT MODIFY! 79 // CHECKSTYLE:OFF Generated code 80 // 81 // To regenerate run: 82 // $ codegen $ANDROID_BUILD_TOP/packages/services/Car/car-lib/src/android/car/hardware/power/CarPowerPolicy.java 83 // Added AddedInOrBefore or ApiRequirement Annotation manually 84 // 85 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 86 // Settings > Editor > Code Style > Formatter Control 87 //@formatter:off 88 89 90 /** 91 * Creates a new CarPowerPolicy. 92 * 93 * @param policyId 94 * ID of power policy. 95 * @param enabledComponents 96 * List of enabled componentst. Components are one of 97 * {@code android.frameworks.automotive.powerpolicy.PowerComponent}. 98 * @param disabledComponents 99 * List of disabled componentst. Components are one of 100 * {@code android.frameworks.automotive.powerpolicy.PowerComponent}. 101 * @hide 102 */ 103 @DataClass.Generated.Member CarPowerPolicy( @onNull String policyId, @NonNull int[] enabledComponents, @NonNull int[] disabledComponents)104 public CarPowerPolicy( 105 @NonNull String policyId, 106 @NonNull int[] enabledComponents, 107 @NonNull int[] disabledComponents) { 108 this.mPolicyId = policyId; 109 AnnotationValidations.validate( 110 NonNull.class, null, mPolicyId); 111 this.mEnabledComponents = enabledComponents; 112 AnnotationValidations.validate( 113 NonNull.class, null, mEnabledComponents); 114 this.mDisabledComponents = disabledComponents; 115 AnnotationValidations.validate( 116 NonNull.class, null, mDisabledComponents); 117 118 // onConstructed(); // You can define this method to get a callback 119 } 120 121 /** 122 * ID of power policy. 123 */ 124 @DataClass.Generated.Member getPolicyId()125 public @NonNull String getPolicyId() { 126 return mPolicyId; 127 } 128 129 /** 130 * List of enabled componentst. Components are one of 131 * {@code android.frameworks.automotive.powerpolicy.PowerComponent}. 132 */ 133 @DataClass.Generated.Member getEnabledComponents()134 public @NonNull int[] getEnabledComponents() { 135 return mEnabledComponents; 136 } 137 138 /** 139 * List of disabled componentst. Components are one of 140 * {@code android.frameworks.automotive.powerpolicy.PowerComponent}. 141 */ 142 @DataClass.Generated.Member getDisabledComponents()143 public @NonNull int[] getDisabledComponents() { 144 return mDisabledComponents; 145 } 146 147 @Override 148 @DataClass.Generated.Member writeToParcel(@onNull android.os.Parcel dest, int flags)149 public void writeToParcel(@NonNull android.os.Parcel dest, int flags) { 150 // You can override field parcelling by defining methods like: 151 // void parcelFieldName(Parcel dest, int flags) { ... } 152 153 dest.writeString(mPolicyId); 154 dest.writeIntArray(mEnabledComponents); 155 dest.writeIntArray(mDisabledComponents); 156 } 157 158 @Override 159 @DataClass.Generated.Member 160 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) describeContents()161 public int describeContents() { return 0; } 162 163 /** @hide */ 164 @SuppressWarnings({"unchecked", "RedundantCast"}) 165 @DataClass.Generated.Member CarPowerPolicy(@onNull android.os.Parcel in)166 /* package-private */ CarPowerPolicy(@NonNull android.os.Parcel in) { 167 // You can override field unparcelling by defining methods like: 168 // static FieldType unparcelFieldName(Parcel in) { ... } 169 170 String policyId = in.readString(); 171 int[] enabledComponents = in.createIntArray(); 172 int[] disabledComponents = in.createIntArray(); 173 174 this.mPolicyId = policyId; 175 AnnotationValidations.validate( 176 NonNull.class, null, mPolicyId); 177 this.mEnabledComponents = enabledComponents; 178 AnnotationValidations.validate( 179 NonNull.class, null, mEnabledComponents); 180 this.mDisabledComponents = disabledComponents; 181 AnnotationValidations.validate( 182 NonNull.class, null, mDisabledComponents); 183 184 // onConstructed(); // You can define this method to get a callback 185 } 186 187 @DataClass.Generated.Member 188 public static final @NonNull Parcelable.Creator<CarPowerPolicy> CREATOR 189 = new Parcelable.Creator<CarPowerPolicy>() { 190 @Override 191 public CarPowerPolicy[] newArray(int size) { 192 return new CarPowerPolicy[size]; 193 } 194 195 @Override 196 public CarPowerPolicy createFromParcel(@NonNull android.os.Parcel in) { 197 return new CarPowerPolicy(in); 198 } 199 }; 200 201 @DataClass.Generated( 202 time = 1628098490687L, 203 codegenVersion = "1.0.23", 204 sourceFile = "packages/services/Car/car-lib/src/android/car/hardware/power/CarPowerPolicy.java", 205 inputSignatures = "private final @android.annotation.NonNull java.lang.String mPolicyId\nprivate final @android.annotation.NonNull int[] mEnabledComponents\nprivate final @android.annotation.NonNull int[] mDisabledComponents\npublic boolean isComponentEnabled(int)\nclass CarPowerPolicy extends java.lang.Object implements [android.os.Parcelable]\n@com.android.car.internal.util.DataClass(genHiddenConstructor=true)") 206 @Deprecated 207 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) __metadata()208 private void __metadata() {} 209 210 211 //@formatter:on 212 // End of generated code 213 214 } 215