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

Commit 4521ee46 authored by Sal Savage's avatar Sal Savage
Browse files

Refactor GATT logging to be unguarded

With the recent addition of a process minimum default log level, the
Android Log framework will now enforce the set log level against the
various log invocations we make in code. We no longer need to guard log
invocations on our own.

Tag: #refactor
Flag: EXEMPT, logging only change
Bug: 315046089
Test: atest BluetoothInstrumentationTests
Change-Id: I6cbc58ac0cac30d9bf28dc2ea88499d04544f373
parent 3ee7d057
Loading
Loading
Loading
Loading
+26 −55
Original line number Diff line number Diff line
@@ -45,7 +45,6 @@ import java.util.Map;
 */
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
public class AdvertiseManager {
    private static final boolean DBG = GattServiceConfig.DBG;
    private static final String TAG = GattServiceConfig.TAG_PREFIX + "AdvertiseManager";

    private final GattService mService;
@@ -60,9 +59,7 @@ public class AdvertiseManager {
            GattService service,
            AdvertiseManagerNativeInterface nativeInterface,
            AdvertiserMap advertiserMap) {
        if (DBG) {
        Log.d(TAG, "advertise manager created");
        }
        mService = service;
        mNativeInterface = nativeInterface;
        mAdvertiserMap = advertiserMap;
@@ -75,9 +72,7 @@ public class AdvertiseManager {
    }

    void cleanup() {
        if (DBG) {
        Log.d(TAG, "cleanup()");
        }
        mNativeInterface.cleanup();
        mAdvertisers.clear();
        sTempRegistrationId = -1;
@@ -123,11 +118,9 @@ public class AdvertiseManager {

        @Override
        public void binderDied() {
            if (DBG) {
            Log.d(
                    TAG,
                    "Binder is dead - unregistering advertising set (" + mPackageName + ")!");
            }
            stopAdvertisingSet(callback);
        }
    }
@@ -145,11 +138,9 @@ public class AdvertiseManager {

    void onAdvertisingSetStarted(int regId, int advertiserId, int txPower, int status)
            throws Exception {
        if (DBG) {
        Log.d(TAG,
                "onAdvertisingSetStarted() - regId=" + regId + ", advertiserId=" + advertiserId
                        + ", status=" + status);
        }

        Map.Entry<IBinder, AdvertiserInfo> entry = findAdvertiser(regId);

@@ -184,10 +175,8 @@ public class AdvertiseManager {
    }

    void onAdvertisingEnabled(int advertiserId, boolean enable, int status) throws Exception {
        if (DBG) {
        Log.d(TAG, "onAdvertisingSetEnabled() - advertiserId=" + advertiserId + ", enable="
                + enable + ", status=" + status);
        }

        Map.Entry<IBinder, AdvertiserInfo> entry = findAdvertiser(advertiserId);
        if (entry == null) {
@@ -254,9 +243,7 @@ public class AdvertiseManager {
            int cbId = --sTempRegistrationId;
            mAdvertisers.put(binder, new AdvertiserInfo(cbId, deathRecipient, callback));

            if (DBG) {
            Log.d(TAG, "startAdvertisingSet() - reg_id=" + cbId + ", callback: " + binder);
            }

            mAdvertiserMap.add(cbId, callback, mService);
            mAdvertiserMap.recordAdvertiseStart(cbId, parameters, advertiseData,
@@ -287,9 +274,7 @@ public class AdvertiseManager {

    void onOwnAddressRead(int advertiserId, int addressType, String address)
            throws RemoteException {
        if (DBG) {
        Log.d(TAG, "onOwnAddressRead() advertiserId=" + advertiserId);
        }

        Map.Entry<IBinder, AdvertiserInfo> entry = findAdvertiser(advertiserId);
        if (entry == null) {
@@ -312,9 +297,7 @@ public class AdvertiseManager {

    void stopAdvertisingSet(IAdvertisingSetCallback callback) {
        IBinder binder = toBinder(callback);
        if (DBG) {
        Log.d(TAG, "stopAdvertisingSet() " + binder);
        }

        AdvertiserInfo adv = mAdvertisers.remove(binder);
        if (adv == null) {
@@ -453,10 +436,8 @@ public class AdvertiseManager {
    }

    void onAdvertisingDataSet(int advertiserId, int status) throws Exception {
        if (DBG) {
        Log.d(TAG,
                "onAdvertisingDataSet() advertiserId=" + advertiserId + ", status=" + status);
        }

        Map.Entry<IBinder, AdvertiserInfo> entry = findAdvertiser(advertiserId);
        if (entry == null) {
@@ -469,10 +450,8 @@ public class AdvertiseManager {
    }

    void onScanResponseDataSet(int advertiserId, int status) throws Exception {
        if (DBG) {
        Log.d(TAG,
                "onScanResponseDataSet() advertiserId=" + advertiserId + ", status=" + status);
        }

        Map.Entry<IBinder, AdvertiserInfo> entry = findAdvertiser(advertiserId);
        if (entry == null) {
@@ -486,11 +465,9 @@ public class AdvertiseManager {

    void onAdvertisingParametersUpdated(int advertiserId, int txPower, int status)
            throws Exception {
        if (DBG) {
        Log.d(TAG,
                "onAdvertisingParametersUpdated() advertiserId=" + advertiserId + ", txPower="
                        + txPower + ", status=" + status);
        }

        Map.Entry<IBinder, AdvertiserInfo> entry = findAdvertiser(advertiserId);
        if (entry == null) {
@@ -503,10 +480,8 @@ public class AdvertiseManager {
    }

    void onPeriodicAdvertisingParametersUpdated(int advertiserId, int status) throws Exception {
        if (DBG) {
        Log.d(TAG, "onPeriodicAdvertisingParametersUpdated() advertiserId=" + advertiserId
                + ", status=" + status);
        }

        Map.Entry<IBinder, AdvertiserInfo> entry = findAdvertiser(advertiserId);
        if (entry == null) {
@@ -520,10 +495,8 @@ public class AdvertiseManager {
    }

    void onPeriodicAdvertisingDataSet(int advertiserId, int status) throws Exception {
        if (DBG) {
        Log.d(TAG, "onPeriodicAdvertisingDataSet() advertiserId=" + advertiserId + ", status="
                + status);
        }

        Map.Entry<IBinder, AdvertiserInfo> entry = findAdvertiser(advertiserId);
        if (entry == null) {
@@ -537,10 +510,8 @@ public class AdvertiseManager {

    void onPeriodicAdvertisingEnabled(int advertiserId, boolean enable, int status)
            throws Exception {
        if (DBG) {
        Log.d(TAG, "onPeriodicAdvertisingEnabled() advertiserId=" + advertiserId + ", status="
                + status);
        }

        Map.Entry<IBinder, AdvertiserInfo> entry = findAdvertiser(advertiserId);
        if (entry == null) {
+2 −5
Original line number Diff line number Diff line
@@ -40,8 +40,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
 */
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
public class DistanceMeasurementManager {
    private static final boolean DBG = GattServiceConfig.DBG;
    private static final String TAG = "DistanceMeasurementManager";
    private static final String TAG = DistanceMeasurementManager.class.getSimpleName();

    private static final int RSSI_LOW_FREQUENCY_INTERVAL_MS = 3000;
    private static final int RSSI_MEDIUM_FREQUENCY_INTERVAL_MS = 1000;
@@ -468,8 +467,6 @@ public class DistanceMeasurementManager {

    /** Logs the message in debug ROM. */
    private static void logd(String msg) {
        if (DBG) {
        Log.d(TAG, msg);
    }
}
}
+143 −325

File changed.

Preview size limit exceeded, changes collapsed.

+0 −4
Original line number Diff line number Diff line
@@ -16,14 +16,10 @@

package com.android.bluetooth.gatt;

import android.os.Build;

/**
 * GattService configuration.
 */
public class GattServiceConfig {
    public static final boolean DBG = Build.TYPE.equals("userdebug") || Build.TYPE.equals("eng");
    public static final boolean VDBG = false;
    public static final String TAG_PREFIX = "BtGatt.";
    public static final boolean DEBUG_ADMIN = false;
}
+15 −32
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ import java.util.concurrent.ConcurrentHashMap;
 */
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
public class PeriodicScanManager {
    private static final boolean DBG = GattServiceConfig.DBG;
    private static final String TAG = GattServiceConfig.TAG_PREFIX + "SyncManager";

    private final BluetoothAdapter mAdapter;
@@ -52,18 +51,14 @@ public class PeriodicScanManager {

    /** Constructor of {@link PeriodicScanManager}. */
    public PeriodicScanManager(AdapterService adapterService) {
        if (DBG) {
        Log.d(TAG, "periodic scan manager created");
        }
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        mNativeInterface = PeriodicScanNativeInterface.getInstance();
        mNativeInterface.init(this);
    }

    public void cleanup() {
        if (DBG) {
        Log.d(TAG, "cleanup()");
        }
        mNativeInterface.cleanup();
        mSyncs.clear();
        sTempRegistrationId = -1;
@@ -128,9 +123,7 @@ public class PeriodicScanManager {

        @Override
        public void binderDied() {
            if (DBG) {
            Log.d(TAG, "Binder is dead - unregistering advertising set");
            }
            stopSync(callback);
        }
    }
@@ -274,7 +267,6 @@ public class PeriodicScanManager {
        String address = scanResult.getDevice().getAddress();
        int addressType = scanResult.getDevice().getAddressType();
        int sid = scanResult.getAdvertisingSid();
        if (DBG) {
        Log.d(
                TAG,
                "startSync for Device: "
@@ -283,14 +275,11 @@ public class PeriodicScanManager {
                        + addressType
                        + " sid: "
                        + sid);
        }
        synchronized (mSyncs) {
            Map.Entry<IBinder, SyncInfo> entry = findMatchingSync(sid, address);
            if (entry != null) {
                //Found matching sync. Copy sync handle
                if (DBG) {
                Log.d(TAG, "startSync: Matching entry found");
                }
                mSyncs.put(binder, new SyncInfo(entry.getValue().id, sid, address,
                        entry.getValue().skip, entry.getValue().timeout, deathRecipient,
                        callback));
@@ -317,17 +306,13 @@ public class PeriodicScanManager {
        mSyncs.put(binder, new SyncInfo(cbId, sid, address, skip, timeout,
                deathRecipient, callback));

        if (DBG) {
        Log.d(TAG, "startSync() - reg_id=" + cbId + ", callback: " + binder);
        }
        mNativeInterface.startSync(sid, address, skip, timeout, cbId);
    }

    public void stopSync(IPeriodicAdvertisingCallback callback) {
        IBinder binder = toBinder(callback);
        if (DBG) {
        Log.d(TAG, "stopSync() " + binder);
        }
        SyncInfo sync = null;
        synchronized (mSyncs) {
            sync = mSyncs.remove(binder);
@@ -387,9 +372,7 @@ public class PeriodicScanManager {
                  int advHandle, IPeriodicAdvertisingCallback callback) {
        SyncDeathRecipient deathRecipient = new SyncDeathRecipient(callback);
        IBinder binder = toBinder(callback);
        if (DBG) {
        Log.d(TAG, "transferSetInfo() " + binder);
        }
        try {
            binder.linkToDeath(deathRecipient, 0);
        } catch (RemoteException e) {
Loading