1 /*
2  * Copyright (C) 2023 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.google.android.car.kitchensink.audio;
18 
19 import android.car.media.CarAudioManager;
20 import android.car.media.CarAudioZoneConfigInfo;
21 import android.content.Context;
22 import android.content.pm.ApplicationInfo;
23 
24 import androidx.annotation.Nullable;
25 
26 import java.util.List;
27 
28 final class AudioUtils {
29 
AudioUtils()30     private AudioUtils() {
31         throw new UnsupportedOperationException();
32     }
33 
getCurrentZoneId(Context context, CarAudioManager manager)34     static int getCurrentZoneId(Context context, CarAudioManager manager) throws Exception {
35         ApplicationInfo info = context.getPackageManager().getApplicationInfo(
36                 context.getPackageName(), /* flags= */ 0);
37         return manager.getZoneIdForUid(info.uid);
38     }
39 
40     @Nullable
getCarAudioZoneConfigInfoOrNull( List<CarAudioZoneConfigInfo> configs, int zoneId, int configId)41     static CarAudioZoneConfigInfo getCarAudioZoneConfigInfoOrNull(
42             List<CarAudioZoneConfigInfo> configs, int zoneId, int configId) {
43         CarAudioZoneConfigInfo info = configs.stream()
44                 .filter(c -> c.getZoneId() == zoneId && c.getConfigId() == configId)
45                 .findFirst().orElse(null);
46         return info;
47     }
48 }
49