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

Commit 8b5c13ab authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Do not call SystemConfig.getInstance() from Bluetooth (2/3)

Move call to SystemConfig.getInstance into BluetoothManagerService

Bug: 145297991
Change-Id: I6edd91b831a240117757cb6683d8a373e861db99
parent 7047f8cd
Loading
Loading
Loading
Loading
+25 −10
Original line number Original line Diff line number Diff line
@@ -16,14 +16,18 @@


package com.android.bluetooth.btservice;
package com.android.bluetooth.btservice;


import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.IBluetoothManager;
import android.content.ContentResolver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.Resources;
import android.os.SystemProperties;
import android.os.SystemProperties;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.provider.Settings;
import android.provider.Settings;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Log;


import com.android.bluetooth.R;
import com.android.bluetooth.R;
@@ -44,9 +48,9 @@ import com.android.bluetooth.pan.PanService;
import com.android.bluetooth.pbap.BluetoothPbapService;
import com.android.bluetooth.pbap.BluetoothPbapService;
import com.android.bluetooth.pbapclient.PbapClientService;
import com.android.bluetooth.pbapclient.PbapClientService;
import com.android.bluetooth.sap.SapService;
import com.android.bluetooth.sap.SapService;
import com.android.server.SystemConfig;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;


public class Config {
public class Config {
    private static final String TAG = "AdapterServiceConfig";
    private static final String TAG = "AdapterServiceConfig";
@@ -115,11 +119,8 @@ public class Config {
        if (resources == null) {
        if (resources == null) {
            return;
            return;
        }
        }
        SystemConfig systemConfig = SystemConfig.getInstance();
        List<String> enabledProfiles =
        ArrayMap<String, Boolean> componentEnabledStates = null;
                getSystemConfigEnabledProfilesForPackage(ctx.getPackageName());
        if (systemConfig != null) {
            componentEnabledStates = systemConfig.getComponentsEnabledStates(ctx.getPackageName());
        }


        ArrayList<Class> profiles = new ArrayList<>(PROFILE_SERVICES_AND_FLAGS.length);
        ArrayList<Class> profiles = new ArrayList<>(PROFILE_SERVICES_AND_FLAGS.length);
        for (ProfileConfig config : PROFILE_SERVICES_AND_FLAGS) {
        for (ProfileConfig config : PROFILE_SERVICES_AND_FLAGS) {
@@ -130,9 +131,8 @@ public class Config {
                supported = true;
                supported = true;
            }
            }


            if (componentEnabledStates != null
            if (enabledProfiles != null && enabledProfiles.contains(config.mClass.getName())) {
                    && componentEnabledStates.containsKey(config.mClass.getName())) {
                supported = true;
                supported = componentEnabledStates.get(config.mClass.getName());
                Log.v(TAG, config.mClass.getSimpleName() + " Feature Flag set to " + supported
                Log.v(TAG, config.mClass.getSimpleName() + " Feature Flag set to " + supported
                        + " by components configuration");
                        + " by components configuration");
            }
            }
@@ -200,4 +200,19 @@ public class Config {
        // Step 3: return default value.
        // Step 3: return default value.
        return false;
        return false;
    }
    }

    private static List<String> getSystemConfigEnabledProfilesForPackage(String packageName) {
        IBinder b = ServiceManager.getService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE);
        if (b == null) {
            Log.e(TAG, "Bluetooth binder is null");
        }

        IBluetoothManager managerService = IBluetoothManager.Stub.asInterface(b);
        try {
            return managerService.getSystemConfigEnabledProfilesForPackage(packageName);
        } catch (RemoteException e) {
            return null;
        }

    }
}
}