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

Commit d56b2fbe authored by Sal Savage's avatar Sal Savage
Browse files

Refactor ASHA 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: I7c007f60420b3fcfc1f4d3fe863043fe80327a49
parent 71bffd3d
Loading
Loading
Loading
Loading
+2 −7
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import com.android.internal.annotations.VisibleForTesting;
 */
public class HearingAidNativeInterface {
    private static final String TAG = "HearingAidNativeInterface";
    private static final boolean DBG = true;
    private BluetoothAdapter mAdapter;

    @GuardedBy("INSTANCE_LOCK")
@@ -162,9 +161,7 @@ public class HearingAidNativeInterface {
        event.device = getDevice(address);
        event.valueInt1 = state;

        if (DBG) {
        Log.d(TAG, "onConnectionStateChanged: " + event);
        }
        sendMessageToService(event);
    }

@@ -176,9 +173,7 @@ public class HearingAidNativeInterface {
        event.valueInt1 = capabilities;
        event.valueLong2 = hiSyncId;

        if (DBG) {
        Log.d(TAG, "onDeviceAvailable: " + event);
        }
        sendMessageToService(event);
    }

+20 −57
Original line number Diff line number Diff line
@@ -65,7 +65,6 @@ import java.util.concurrent.ConcurrentHashMap;
 * Provides Bluetooth HearingAid profile, as a service in the Bluetooth application.
 */
public class HearingAidService extends ProfileService {
    private static final boolean DBG = true;
    private static final String TAG = "HearingAidService";

    // Timeout for state machine thread join, to prevent potential ANR.
@@ -114,9 +113,7 @@ public class HearingAidService extends ProfileService {

    @Override
    public void start() {
        if (DBG) {
        Log.d(TAG, "start()");
        }
        if (sHearingAidService != null) {
            throw new IllegalStateException("start() called twice");
        }
@@ -150,9 +147,7 @@ public class HearingAidService extends ProfileService {

    @Override
    public void stop() {
        if (DBG) {
        Log.d(TAG, "stop()");
        }
        if (sHearingAidService == null) {
            Log.w(TAG, "stop() called before start()");
            return;
@@ -204,10 +199,8 @@ public class HearingAidService extends ProfileService {

    @Override
    public void cleanup() {
        if (DBG) {
        Log.d(TAG, "cleanup()");
    }
    }

    /**
     * Get the HearingAidService instance
@@ -228,9 +221,7 @@ public class HearingAidService extends ProfileService {

    @VisibleForTesting
    static synchronized void setHearingAidService(HearingAidService instance) {
        if (DBG) {
        Log.d(TAG, "setHearingAidService(): set to: " + instance);
        }
        sHearingAidService = instance;
    }

@@ -244,9 +235,7 @@ public class HearingAidService extends ProfileService {
    public boolean connect(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH_PRIVILEGED permission");
        if (DBG) {
        Log.d(TAG, "connect(): " + device);
        }
        if (device == null) {
            return false;
        }
@@ -312,9 +301,7 @@ public class HearingAidService extends ProfileService {
    public boolean disconnect(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH_PRIVILEGED permission");
        if (DBG) {
        Log.d(TAG, "disconnect(): " + device);
        }
        if (device == null) {
            return false;
        }
@@ -497,9 +484,7 @@ public class HearingAidService extends ProfileService {
    public boolean setConnectionPolicy(BluetoothDevice device, int connectionPolicy) {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH_PRIVILEGED permission");
        if (DBG) {
        Log.d(TAG, "Saved connectionPolicy " + device + " = " + connectionPolicy);
        }

        if (!mDatabaseManager.setProfileConnectionPolicy(device, BluetoothProfile.HEARING_AID,
                  connectionPolicy)) {
@@ -584,9 +569,7 @@ public class HearingAidService extends ProfileService {
     * @return true on success, otherwise false
     */
    public boolean removeActiveDevice(boolean stopAudio) {
        if (DBG) {
        Log.d(TAG, "removeActiveDevice: stopAudio=" + stopAudio);
        }
        synchronized (mStateMachines) {
            if (mActiveDeviceHiSyncId != BluetoothHearingAid.HI_SYNC_ID_INVALID) {
                reportActiveDevice(null, stopAudio);
@@ -607,15 +590,11 @@ public class HearingAidService extends ProfileService {
            Log.e(TAG, "setActiveDevice: device should not be null!");
            return removeActiveDevice(true);
        }
        if (DBG) {
        Log.d(TAG, "setActiveDevice: " + device);
        }
        synchronized (mStateMachines) {
            /* No action needed since this is the same device as previousely activated */
            if (device.equals(mActiveDevice)) {
                if (DBG) {
                Log.d(TAG, "setActiveDevice: The device is already active. Ignoring.");
                }
                return true;
            }

@@ -673,10 +652,8 @@ public class HearingAidService extends ProfileService {
            BluetoothDevice device = stackEvent.device;
            int capabilities = stackEvent.valueInt1;
            long hiSyncId = stackEvent.valueLong2;
            if (DBG) {
            Log.d(TAG, "Device available: device=" + device + " capabilities="
                    + capabilities + " hiSyncId=" + hiSyncId);
            }
            mDeviceCapabilitiesMap.put(device, capabilities);
            mDeviceHiSyncIdMap.put(device, hiSyncId);
            return;
@@ -720,9 +697,7 @@ public class HearingAidService extends ProfileService {
        public void onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices) {
            for (AudioDeviceInfo deviceInfo : removedDevices) {
                if (deviceInfo.getType() == AudioDeviceInfo.TYPE_HEARING_AID) {
                    if (DBG) {
                    Log.d(TAG, " onAudioDevicesRemoved: device type: " + deviceInfo.getType());
                    }
                    if (mAudioManager != null) {
                        notifyActiveDeviceChanged();
                        mAudioManager.unregisterAudioDeviceCallback(this);
@@ -740,9 +715,7 @@ public class HearingAidService extends ProfileService {
        public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) {
            for (AudioDeviceInfo deviceInfo : addedDevices) {
                if (deviceInfo.getType() == AudioDeviceInfo.TYPE_HEARING_AID) {
                    if (DBG) {
                    Log.d(TAG, " onAudioDevicesAdded: device type: " + deviceInfo.getType());
                    }
                    if (mAudioManager != null) {
                        notifyActiveDeviceChanged();
                        mAudioManager.unregisterAudioDeviceCallback(this);
@@ -770,9 +743,7 @@ public class HearingAidService extends ProfileService {
                        + MAX_HEARING_AID_STATE_MACHINES);
                return null;
            }
            if (DBG) {
            Log.d(TAG, "Creating a new state machine for " + device);
            }
            sm = HearingAidStateMachine.make(device, this,
                    mHearingAidNativeInterface, mStateMachinesThread.getLooper());
            mStateMachines.put(device, sm);
@@ -787,9 +758,7 @@ public class HearingAidService extends ProfileService {
     * @param stopAudio whether to stop audio when device is null.
     */
    private void reportActiveDevice(BluetoothDevice device, boolean stopAudio) {
        if (DBG) {
        Log.d(TAG, "reportActiveDevice: device=" + device + " stopAudio=" + stopAudio);
        }

        if (device != null && stopAudio) {
            Log.e(TAG, "Illegal arguments: stopAudio should be false when device is not null!");
@@ -812,10 +781,8 @@ public class HearingAidService extends ProfileService {
                BluetoothProfile.HEARING_AID, mAdapterService.obfuscateAddress(device),
                mAdapterService.getMetricId(device));

        if (DBG) {
        Log.d(TAG, "Hearing Aid audio: " + previousAudioDevice + " -> " + device
                + ". Stop audio: " + stopAudio);
        }

        if (device != null) {
            mAudioManager.registerAudioDeviceCallback(mAudioManagerOnAudioDevicesAddedCallback,
@@ -844,9 +811,7 @@ public class HearingAidService extends ProfileService {
     */
    @VisibleForTesting
    void bondStateChanged(BluetoothDevice device, int bondState) {
        if (DBG) {
        Log.d(TAG, "Bond state changed for device: " + device + " state: " + bondState);
        }
        // Remove state machine if the bonding for a device is removed
        if (bondState != BluetoothDevice.BOND_NONE) {
            return;
@@ -921,9 +886,7 @@ public class HearingAidService extends ProfileService {
        if (toState == BluetoothProfile.STATE_DISCONNECTED) {
            int bondState = mAdapterService.getBondState(device);
            if (bondState == BluetoothDevice.BOND_NONE) {
                if (DBG) {
                Log.d(TAG, device + " is unbond. Remove state machine");
                }
                removeStateMachine(device);
            }
        }
+2 −7
Original line number Diff line number Diff line
@@ -67,7 +67,6 @@ import java.io.StringWriter;
import java.util.Scanner;

final class HearingAidStateMachine extends StateMachine {
    private static final boolean DBG = false;
    private static final String TAG = "HearingAidStateMachine";

    static final int CONNECT = 1;
@@ -179,9 +178,7 @@ final class HearingAidStateMachine extends StateMachine {
                    break;
                case STACK_EVENT:
                    HearingAidStackEvent event = (HearingAidStackEvent) message.obj;
                    if (DBG) {
                    Log.d(TAG, "Disconnected: stack event: " + event);
                    }
                    if (!mDevice.equals(event.device)) {
                        Log.wtf(TAG, "Device(" + mDevice + "): event mismatch: " + event);
                    }
@@ -584,8 +581,6 @@ final class HearingAidStateMachine extends StateMachine {

    @Override
    protected void log(String msg) {
        if (DBG) {
        super.log(msg);
    }
}
}