Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 60aee37b authored by Sungsoo Lim's avatar Sungsoo Lim Committed by Gerrit Code Review
Browse files

Merge "Apply system property on sSupportedProfile" into main

parents 880014ba ab840126
Loading
Loading
Loading
Loading
+31 −20
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class Config {
@@ -171,9 +172,14 @@ public class Config {
                profile.mSupported = enabled;
            }
        }
        if (enabled) {
            sSupportedProfiles.add(profileClass);
        } else {
            sSupportedProfiles.remove(profileClass);
        }
    }

    private static Class[] sSupportedProfiles = new Class[0];
    private static List<Class> sSupportedProfiles = new ArrayList<>();

    private static boolean sIsGdEnabledUptoScanningLayer = false;

@@ -211,15 +217,20 @@ public class Config {
            setProfileEnabled(HearingAidService.class, false);
        }

        ArrayList<Class> profiles = new ArrayList<>(PROFILE_SERVICES_AND_FLAGS.length);
        synchronized (sSupportedProfiles) {
            sSupportedProfiles.clear();
            for (ProfileConfig config : PROFILE_SERVICES_AND_FLAGS) {
            Log.i(TAG, "init: profile=" + config.mClass.getSimpleName() + ", enabled="
                Log.i(
                        TAG,
                        "init: profile="
                                + config.mClass.getSimpleName()
                                + ", enabled="
                                + config.mSupported);
                if (config.mSupported) {
                profiles.add(config.mClass);
                    sSupportedProfiles.add(config.mClass);
                }
            }
        }
        sSupportedProfiles = profiles.toArray(new Class[profiles.size()]);

        if (ctx == null) {
            return;
@@ -253,9 +264,8 @@ public class Config {
     * Remove the input profiles from the supported list.
     */
    static void removeProfileFromSupportedList(HashSet<Class> nonSupportedProfiles) {
        ArrayList<Class> profilesList = new ArrayList<Class>(Arrays.asList(sSupportedProfiles));
        Iterator<Class> iter = profilesList.iterator();

        synchronized (sSupportedProfiles) {
            Iterator<Class> iter = sSupportedProfiles.iterator();
            while (iter.hasNext()) {
                Class profileClass = iter.next();

@@ -264,8 +274,7 @@ public class Config {
                    Log.v(TAG, "Remove " + profileClass.getSimpleName() + " from supported list.");
                }
            }

        sSupportedProfiles = profilesList.toArray(new Class[profilesList.size()]);
        }
    }

    static void updateSupportedProfileMask(Boolean enable, Class profile, int supportedProfile) {
@@ -286,7 +295,9 @@ public class Config {
    }

    static Class[] getSupportedProfiles() {
        return sSupportedProfiles;
        synchronized (sSupportedProfiles) {
            return sSupportedProfiles.toArray(new Class[0]);
        }
    }

    static boolean isGdEnabledUpToScanningLayer() {
+51 −0
Original line number Diff line number Diff line
/*
 * Copyright 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.bluetooth.btservice;

import static com.google.common.truth.Truth.assertThat;

import com.android.bluetooth.csip.CsipSetCoordinatorService;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.util.Arrays;

@RunWith(JUnit4.class)
public final class ConfigTest {
    @Test
    public void setProfileEnabled() {
        boolean enabled =
                Arrays.stream(Config.getSupportedProfiles())
                        .anyMatch(cls -> cls == CsipSetCoordinatorService.class);

        Config.setProfileEnabled(CsipSetCoordinatorService.class, false);
        assertThat(
                        Arrays.stream(Config.getSupportedProfiles())
                                .anyMatch(cls -> cls == CsipSetCoordinatorService.class))
                .isFalse();

        Config.setProfileEnabled(CsipSetCoordinatorService.class, true);
        assertThat(
                        Arrays.stream(Config.getSupportedProfiles())
                                .anyMatch(cls -> cls == CsipSetCoordinatorService.class))
                .isTrue();

        Config.setProfileEnabled(CsipSetCoordinatorService.class, enabled);
    }
}