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