1 /* 2 * Copyright (C) 2024 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.car.audio; 18 19 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.DUMP_INFO; 20 21 import android.annotation.IntDef; 22 23 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport; 24 import com.android.internal.util.Preconditions; 25 26 import java.util.Objects; 27 28 final class CarActivationVolumeConfig { 29 30 /** 31 * Activation volume type invoked for the first time after boot or switching 32 * {@link CarAudioZoneConfig} or user. 33 */ 34 static final int ACTIVATION_VOLUME_ON_BOOT = 1; 35 /** 36 * Activation volume type invoked when the source (represented bu uid) of the newly active 37 * {@link android.media.AudioPlaybackConfiguration} for each {@link CarVolumeGroup} is changed 38 */ 39 static final int ACTIVATION_VOLUME_ON_SOURCE_CHANGED = 1 << 1; 40 /** 41 * Activation volume type invoked for every newly active 42 * {@link android.media.AudioPlaybackConfiguration} for each {@link CarVolumeGroup} 43 */ 44 static final int ACTIVATION_VOLUME_ON_PLAYBACK_CHANGED = 1 << 2; 45 46 private final int mInvocationType; 47 private final int mMinActivationVolumePercentage; 48 private final int mMaxActivationVolumePercentage; 49 50 @IntDef(flag = true, value = { 51 ACTIVATION_VOLUME_ON_BOOT, 52 ACTIVATION_VOLUME_ON_SOURCE_CHANGED, 53 ACTIVATION_VOLUME_ON_PLAYBACK_CHANGED 54 }) 55 @interface ActivationVolumeInvocationType {} 56 CarActivationVolumeConfig(int invocationType, int minActivationVolumePercentage, int maxActivationVolumePercentage)57 CarActivationVolumeConfig(int invocationType, int minActivationVolumePercentage, 58 int maxActivationVolumePercentage) { 59 Preconditions.checkArgument(minActivationVolumePercentage < maxActivationVolumePercentage, 60 "Min activation volume percentage can not be higher than max"); 61 mInvocationType = invocationType; 62 mMinActivationVolumePercentage = minActivationVolumePercentage; 63 mMaxActivationVolumePercentage = maxActivationVolumePercentage; 64 } 65 66 int getInvocationType() { 67 return mInvocationType; 68 } 69 70 int getMinActivationVolumePercentage() { 71 return mMinActivationVolumePercentage; 72 } 73 74 int getMaxActivationVolumePercentage() { 75 return mMaxActivationVolumePercentage; 76 } 77 78 @Override 79 public boolean equals(Object o) { 80 if (this == o) { 81 return true; 82 } 83 84 if (!(o instanceof CarActivationVolumeConfig rhs)) { 85 return false; 86 } 87 88 return rhs.mInvocationType == mInvocationType 89 && rhs.mMaxActivationVolumePercentage == mMaxActivationVolumePercentage 90 && rhs.mMinActivationVolumePercentage == mMinActivationVolumePercentage; 91 } 92 93 @Override 94 public int hashCode() { 95 return Objects.hash(mInvocationType, mMinActivationVolumePercentage, 96 mMaxActivationVolumePercentage); 97 } 98 99 @Override 100 @ExcludeFromCodeCoverageGeneratedReport(reason = DUMP_INFO) 101 public String toString() { 102 return "CarActivationVolumeConfig {invocationType: " + mInvocationType 103 + ", minActivation: " + mMinActivationVolumePercentage 104 + ", maxActivation: " + mMaxActivationVolumePercentage + "}"; 105 } 106 } 107