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

Commit 76c74ccf authored by William Escande's avatar William Escande
Browse files

AdapterService: Re-order variable

Order is as follow:
* static final
* final
* non final

Private are being put before non-private

Bug: 311772251
Test: m Bluetooth | no-op change
Flag: Exempt, no-op
Change-Id: I7da0a4e18cfa0e7287dfab6222f0b58198613725
parent d70af6f2
Loading
Loading
Loading
Loading
+132 −142
Original line number Diff line number Diff line
@@ -185,50 +185,31 @@ public class AdapterService extends Service {
    private static final boolean DBG = true;
    private static final boolean VERBOSE = false;

    static {
        if (DBG) {
            Log.d(TAG, "Loading JNI Library");
        }
        if (Utils.isInstrumentationTestMode()) {
            Log.w(TAG, "App is instrumented. Skip loading the native");
        } else {
            System.loadLibrary("bluetooth_jni");
        }
    }
    private static final int MESSAGE_PROFILE_SERVICE_STATE_CHANGED = 1;
    private static final int MESSAGE_PROFILE_SERVICE_REGISTERED = 2;
    private static final int MESSAGE_PROFILE_SERVICE_UNREGISTERED = 3;
    private static final int MESSAGE_PREFERRED_AUDIO_PROFILES_AUDIO_FRAMEWORK_TIMEOUT = 4;

    private static final int CONTROLLER_ENERGY_UPDATE_TIMEOUT_MILLIS = 30;
    private static final int MIN_ADVT_INSTANCES_FOR_MA = 5;
    private static final int MIN_OFFLOADED_FILTERS = 10;
    private static final int MIN_OFFLOADED_SCAN_STORAGE_BYTES = 1024;

    private static final Duration PENDING_SOCKET_HANDOFF_TIMEOUT = Duration.ofMinutes(1);
    private static final Duration GENERATE_LOCAL_OOB_DATA_TIMEOUT = Duration.ofSeconds(2);
    private static final Duration PREFERRED_AUDIO_PROFILE_CHANGE_TIMEOUT = Duration.ofSeconds(10);

    private final Object mEnergyInfoLock = new Object();
    private int mStackReportedState;
    private long mTxTimeTotalMs;
    private long mRxTimeTotalMs;
    private long mIdleTimeTotalMs;
    private long mEnergyUsedTotalVoltAmpSecMicro;
    private final SparseArray<UidTraffic> mUidTraffic = new SparseArray<>();

    private final Map<Integer, ProfileService> mStartedProfiles = new HashMap<>();
    private final ArrayList<ProfileService> mRegisteredProfiles = new ArrayList<>();
    private final ArrayList<ProfileService> mRunningProfiles = new ArrayList<>();
    private HashSet<String> mLeAudioAllowDevices = new HashSet<>();

    public static final String ACTION_LOAD_ADAPTER_PROPERTIES =
            "com.android.bluetooth.btservice.action.LOAD_ADAPTER_PROPERTIES";
    public static final String ACTION_SERVICE_STATE_CHANGED =
            "com.android.bluetooth.btservice.action.STATE_CHANGED";
    public static final String EXTRA_ACTION = "action";
    public static final int PROFILE_CONN_REJECTED = 2;
    static final String PHONEBOOK_ACCESS_PERMISSION_PREFERENCE_FILE = "phonebook_access_permission";
    static final String MESSAGE_ACCESS_PERMISSION_PREFERENCE_FILE = "message_access_permission";
    static final String SIM_ACCESS_PERMISSION_PREFERENCE_FILE = "sim_access_permission";

    private static BluetoothProperties.snoop_log_mode_values sSnoopLogSettingAtEnable =
            BluetoothProperties.snoop_log_mode_values.EMPTY;
    private static String sDefaultSnoopLogSettingAtEnable = "empty";
    private static Boolean sSnoopLogFilterHeadersSettingAtEnable = false;
    private static Boolean sSnoopLogFilterProfileA2dpSettingAtEnable = false;
    private static Boolean sSnoopLogFilterProfileRfcommSettingAtEnable = false;
    private static boolean sSnoopLogFilterHeadersSettingAtEnable = false;
    private static boolean sSnoopLogFilterProfileA2dpSettingAtEnable = false;
    private static boolean sSnoopLogFilterProfileRfcommSettingAtEnable = false;

    private static BluetoothProperties.snoop_log_filter_profile_pbap_values
            sSnoopLogFilterProfilePbapModeSettingAtEnable =
                    BluetoothProperties.snoop_log_filter_profile_pbap_values.EMPTY;
@@ -236,19 +217,110 @@ public class AdapterService extends Service {
            sSnoopLogFilterProfileMapModeSettingAtEnable =
                    BluetoothProperties.snoop_log_filter_profile_map_values.EMPTY;

    public static final String BLUETOOTH_PRIVILEGED =
            android.Manifest.permission.BLUETOOTH_PRIVILEGED;
    static final String BLUETOOTH_PERM = android.Manifest.permission.BLUETOOTH;
    static final String LOCAL_MAC_ADDRESS_PERM = android.Manifest.permission.LOCAL_MAC_ADDRESS;
    static final String RECEIVE_MAP_PERM = android.Manifest.permission.RECEIVE_BLUETOOTH_MAP;
    static final String BLUETOOTH_LE_AUDIO_ALLOW_LIST = "persist.bluetooth.leaudio.allow_list";
    private static AdapterService sAdapterService;

    private final Object mEnergyInfoLock = new Object();
    private final SparseArray<UidTraffic> mUidTraffic = new SparseArray<>();

    static final String PHONEBOOK_ACCESS_PERMISSION_PREFERENCE_FILE = "phonebook_access_permission";
    static final String MESSAGE_ACCESS_PERMISSION_PREFERENCE_FILE = "message_access_permission";
    static final String SIM_ACCESS_PERMISSION_PREFERENCE_FILE = "sim_access_permission";
    private final Map<Integer, ProfileService> mStartedProfiles = new HashMap<>();
    private final List<ProfileService> mRegisteredProfiles = new ArrayList<>();
    private final List<ProfileService> mRunningProfiles = new ArrayList<>();

    private static final int CONTROLLER_ENERGY_UPDATE_TIMEOUT_MILLIS = 30;
    private final List<DiscoveringPackage> mDiscoveringPackages = new ArrayList<>();

    private final AdapterNativeInterface mNativeInterface = AdapterNativeInterface.getInstance();

    private final Map<BluetoothDevice, List<IBluetoothMetadataListener>> mMetadataListeners =
            new HashMap<>();

    // Map<groupId, PendingAudioProfilePreferenceRequest>
    @GuardedBy("mCsipGroupsPendingAudioProfileChanges")
    private final Map<Integer, PendingAudioProfilePreferenceRequest>
            mCsipGroupsPendingAudioProfileChanges = new HashMap<>();

    private final Map<BluetoothStateCallback, Executor> mLocalCallbacks = new ConcurrentHashMap<>();
    private final Map<UUID, RfcommListenerData> mBluetoothServerSockets = new ConcurrentHashMap<>();
    private final ArrayDeque<IBluetoothOobDataCallback> mOobDataCallbackQueue = new ArrayDeque<>();

    private final RemoteCallbackList<IBluetoothPreferredAudioProfilesCallback>
            mPreferredAudioProfilesCallbacks = new RemoteCallbackList<>();
    private final RemoteCallbackList<IBluetoothQualityReportReadyCallback>
            mBluetoothQualityReportReadyCallbacks = new RemoteCallbackList<>();
    private final RemoteCallbackList<IBluetoothCallback> mRemoteCallbacks =
            new RemoteCallbackList<>();

    private final DeviceConfigListener mDeviceConfigListener = new DeviceConfigListener();

    private int mStackReportedState;
    private long mTxTimeTotalMs;
    private long mRxTimeTotalMs;
    private long mIdleTimeTotalMs;
    private long mEnergyUsedTotalVoltAmpSecMicro;
    private HashSet<String> mLeAudioAllowDevices = new HashSet<>();

    private BluetoothAdapter mAdapter;
    @VisibleForTesting AdapterProperties mAdapterProperties;
    private AdapterState mAdapterStateMachine;
    private BondStateMachine mBondStateMachine;
    private RemoteDevices mRemoteDevices;

    /* TODO: Consider to remove the search API from this class, if changed to use call-back */
    private SdpManager mSdpManager = null;

    private boolean mNativeAvailable;
    private boolean mCleaningUp;
    private Set<IBluetoothConnectionCallback> mBluetoothConnectionCallbacks = new HashSet<>();
    private boolean mQuietmode = false;
    private Map<String, CallerInfo> mBondAttemptCallerInfo = new HashMap<>();

    private BatteryStatsManager mBatteryStatsManager;
    private PowerManager mPowerManager;
    private PowerManager.WakeLock mWakeLock;
    private UserManager mUserManager;
    private CompanionDeviceManager mCompanionDeviceManager;

    // Phone Policy is not used on all devices. Ensure you null check before using it
    @Nullable private PhonePolicy mPhonePolicy;

    private ActiveDeviceManager mActiveDeviceManager;
    private DatabaseManager mDatabaseManager;
    private SilenceDeviceManager mSilenceDeviceManager;
    private CompanionManager mBtCompanionManager;
    private AppOpsManager mAppOps;

    private BluetoothSocketManagerBinder mBluetoothSocketManagerBinder;

    private BluetoothKeystoreService mBluetoothKeystoreService;
    private A2dpService mA2dpService;
    private A2dpSinkService mA2dpSinkService;
    private HeadsetService mHeadsetService;
    private HeadsetClientService mHeadsetClientService;
    private BluetoothMapService mMapService;
    private MapClientService mMapClientService;
    private HidDeviceService mHidDeviceService;
    private HidHostService mHidHostService;
    private PanService mPanService;
    private BluetoothPbapService mPbapService;
    private PbapClientService mPbapClientService;
    private HearingAidService mHearingAidService;
    private HapClientService mHapClientService;
    private SapService mSapService;
    private VolumeControlService mVolumeControlService;
    private CsipSetCoordinatorService mCsipSetCoordinatorService;
    private LeAudioService mLeAudioService;
    private BassClientService mBassClientService;
    private BatteryService mBatteryService;
    private BluetoothQualityReportNativeInterface mBluetoothQualityReportNativeInterface;
    private GattService mGattService;

    private volatile boolean mTestModeEnabled = false;

    private MetricsLogger mMetricsLogger;
    private Looper mLooper;
    private AdapterServiceHandler mHandler;

    /** Handlers for incoming service calls */
    private AdapterServiceBinder mBinder;

    // Report ID definition
    public enum BqrQualityReportId {
@@ -262,21 +334,27 @@ public class AdapterService extends Service {
        QUALITY_REPORT_ID_BT_SCHEDULING_TRACE(0x12),
        QUALITY_REPORT_ID_CONTROLLER_DBG_INFO(0x13);

        private final int value;
        private final int mValue;

        private BqrQualityReportId(int value) {
            this.value = value;
        BqrQualityReportId(int value) {
            mValue = value;
        }

        public int getValue() {
            return value;
            return mValue;
        }
    };

    private final ArrayList<DiscoveringPackage> mDiscoveringPackages = new ArrayList<>();

    private static AdapterService sAdapterService;
    private final AdapterNativeInterface mNativeInterface = AdapterNativeInterface.getInstance();
    static {
        if (DBG) {
            Log.d(TAG, "Loading JNI Library");
        }
        if (Utils.isInstrumentationTestMode()) {
            Log.w(TAG, "App is instrumented. Skip loading the native");
        } else {
            System.loadLibrary("bluetooth_jni");
        }
    }

    // Keep a constructor for ActivityThread.handleCreateService
    AdapterService() {}
@@ -325,79 +403,6 @@ public class AdapterService extends Service {
        }
    }

    private BluetoothAdapter mAdapter;
    @VisibleForTesting AdapterProperties mAdapterProperties;
    private AdapterState mAdapterStateMachine;
    private BondStateMachine mBondStateMachine;
    private RemoteDevices mRemoteDevices;

    /* TODO: Consider to remove the search API from this class, if changed to use call-back */
    private SdpManager mSdpManager = null;

    private boolean mNativeAvailable;
    private boolean mCleaningUp;
    private final HashMap<BluetoothDevice, ArrayList<IBluetoothMetadataListener>>
            mMetadataListeners = new HashMap<>();
    private Set<IBluetoothConnectionCallback> mBluetoothConnectionCallbacks = new HashSet<>();
    private final RemoteCallbackList<IBluetoothPreferredAudioProfilesCallback>
            mPreferredAudioProfilesCallbacks = new RemoteCallbackList<>();
    private final RemoteCallbackList<IBluetoothQualityReportReadyCallback>
            mBluetoothQualityReportReadyCallbacks = new RemoteCallbackList<>();
    // Map<groupId, PendingAudioProfilePreferenceRequest>
    private final Map<Integer, PendingAudioProfilePreferenceRequest>
            mCsipGroupsPendingAudioProfileChanges = new HashMap<>();
    private final RemoteCallbackList<IBluetoothCallback>
            mRemoteCallbacks = new RemoteCallbackList<>();
    private final Map<BluetoothStateCallback, Executor> mLocalCallbacks = new ConcurrentHashMap<>();
    private boolean mQuietmode = false;
    private HashMap<String, CallerInfo> mBondAttemptCallerInfo = new HashMap<>();

    private final Map<UUID, RfcommListenerData> mBluetoothServerSockets = new ConcurrentHashMap<>();

    private BatteryStatsManager mBatteryStatsManager;
    private PowerManager mPowerManager;
    private PowerManager.WakeLock mWakeLock;
    private UserManager mUserManager;
    private CompanionDeviceManager mCompanionDeviceManager;

    // Phone Policy is not used on all devices. Ensure you null check before using it
    @Nullable private PhonePolicy mPhonePolicy;

    private ActiveDeviceManager mActiveDeviceManager;
    private DatabaseManager mDatabaseManager;
    private SilenceDeviceManager mSilenceDeviceManager;
    private CompanionManager mBtCompanionManager;
    private AppOpsManager mAppOps;

    private BluetoothSocketManagerBinder mBluetoothSocketManagerBinder;

    private BluetoothKeystoreService mBluetoothKeystoreService;
    private A2dpService mA2dpService;
    private A2dpSinkService mA2dpSinkService;
    private HeadsetService mHeadsetService;
    private HeadsetClientService mHeadsetClientService;
    private BluetoothMapService mMapService;
    private MapClientService mMapClientService;
    private HidDeviceService mHidDeviceService;
    private HidHostService mHidHostService;
    private PanService mPanService;
    private BluetoothPbapService mPbapService;
    private PbapClientService mPbapClientService;
    private HearingAidService mHearingAidService;
    private HapClientService mHapClientService;
    private SapService mSapService;
    private VolumeControlService mVolumeControlService;
    private CsipSetCoordinatorService mCsipSetCoordinatorService;
    private LeAudioService mLeAudioService;
    private BassClientService mBassClientService;
    private BatteryService mBatteryService;
    private BluetoothQualityReportNativeInterface mBluetoothQualityReportNativeInterface;
    private GattService mGattService;

    private volatile boolean mTestModeEnabled = false;

    private MetricsLogger mMetricsLogger;

    /**
     * Register a {@link ProfileService} with AdapterService.
     *
@@ -442,11 +447,6 @@ public class AdapterService extends Service {
        return mStartedProfiles.containsKey(profileId);
    }

    private static final int MESSAGE_PROFILE_SERVICE_STATE_CHANGED = 1;
    private static final int MESSAGE_PROFILE_SERVICE_REGISTERED = 2;
    private static final int MESSAGE_PROFILE_SERVICE_UNREGISTERED = 3;
    private static final int MESSAGE_PREFERRED_AUDIO_PROFILES_AUDIO_FRAMEWORK_TIMEOUT = 4;

    class AdapterServiceHandler extends Handler {
        AdapterServiceHandler(Looper looper) {
            super(looper);
@@ -565,9 +565,6 @@ public class AdapterService extends Service {
        }
    }

    private Looper mLooper;
    private AdapterServiceHandler mHandler;

    /**
     * Stores information about requests made to the audio framework arising from calls to {@link
     * BluetoothAdapter#setPreferredAudioProfiles(BluetoothDevice, Bundle)}.
@@ -1684,7 +1681,7 @@ public class AdapterService extends Service {
    }

    /**
     * Checks if the connectino policy of all profiles are unknown for the given device
     * Checks if the connection policy of all profiles are unknown for the given device
     *
     * @param device is the device for which we are checking if the connection policy of all
     *     profiles are unknown
@@ -2183,9 +2180,6 @@ public class AdapterService extends Service {
        mAdapterProperties.updateOnProfileConnectionChanged(device, profile, state, prevState);
    }

    /** Handlers for incoming service calls */
    private AdapterServiceBinder mBinder;

    /**
     * The Binder implementation must be declared to be a static class, with the AdapterService
     * instance passed in the constructor. Furthermore, when the AdapterService shuts down, the
@@ -4617,7 +4611,7 @@ public class AdapterService extends Service {

            enforceBluetoothPrivilegedPermission(service);

            ArrayList<IBluetoothMetadataListener> list = service.mMetadataListeners.get(device);
            List<IBluetoothMetadataListener> list = service.mMetadataListeners.get(device);
            if (list == null) {
                list = new ArrayList<>();
            } else if (list.contains(listener)) {
@@ -5933,7 +5927,7 @@ public class AdapterService extends Service {
        return true;
    }

    ArrayList<DiscoveringPackage> getDiscoveringPackages() {
    List<DiscoveringPackage> getDiscoveringPackages() {
        return mDiscoveringPackages;
    }

@@ -6086,8 +6080,6 @@ public class AdapterService extends Service {
        return true;
    }

    private final ArrayDeque<IBluetoothOobDataCallback> mOobDataCallbackQueue = new ArrayDeque<>();

    /**
     * Fetches the local OOB data to give out to remote.
     *
@@ -7472,7 +7464,7 @@ public class AdapterService extends Service {
        }

        if (mMetadataListeners.containsKey(device)) {
            ArrayList<IBluetoothMetadataListener> list = mMetadataListeners.get(device);
            List<IBluetoothMetadataListener> list = mMetadataListeners.get(device);
            for (IBluetoothMetadataListener listener : list) {
                try {
                    listener.onMetadataChanged(device, key, value);
@@ -7774,8 +7766,6 @@ public class AdapterService extends Service {
        }
    }

    private final DeviceConfigListener mDeviceConfigListener = new DeviceConfigListener();

    private class DeviceConfigListener implements DeviceConfig.OnPropertiesChangedListener {
        private static final String LOCATION_DENYLIST_NAME = "location_denylist_name";
        private static final String LOCATION_DENYLIST_MAC = "location_denylist_mac";
+2 −1
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
@@ -1032,7 +1033,7 @@ public class RemoteDevices {
        intent.putExtra(BluetoothDevice.EXTRA_IS_COORDINATED_SET_MEMBER,
                deviceProp.isCoordinatedSetMember());

        final ArrayList<DiscoveringPackage> packages = mAdapterService.getDiscoveringPackages();
        final List<DiscoveringPackage> packages = mAdapterService.getDiscoveringPackages();
        synchronized (packages) {
            for (DiscoveringPackage pkg : packages) {
                if (pkg.hasDisavowedLocation()) {