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

Commit 92960bfc authored by William Escande's avatar William Escande
Browse files

Errorprone: StaticGuardedByInstance

Bug: 344658662
Test: m Bluetooth
Flag: exempt refactor
Change-Id: I5d3d81b7463bbe68532e9e535281723e000a8adb
parent 8fb5e169
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -357,6 +357,7 @@ android_app {
            "-Xep:OperatorPrecedence:ERROR",
            "-Xep:ReferenceEquality:ERROR",
            "-Xep:ReturnAtTheEndOfVoidFunction:ERROR",
            "-Xep:StaticGuardedByInstance:ERROR",
            "-Xep:StringCaseLocaleUsage:ERROR",
            "-Xep:StringCharset:ERROR",
            "-Xep:SynchronizeOnNonFinalField:ERROR",
+27 −35
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ import android.os.RemoteException;
import android.os.SystemProperties;
import android.sysprop.BluetoothProperties;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray;

@@ -126,10 +125,9 @@ public class BluetoothMapService extends ProfileService {
            new HashMap<BluetoothMapAccountItem, BluetoothMapMasInstance>(1);

    // The remote connected device - protect access
    private static BluetoothDevice sRemoteDevice = null;
    private BluetoothDevice mRemoteDevice = null;

    private List<BluetoothMapAccountItem> mEnabledAccounts = null;
    private static String sRemoteDeviceName = null;

    private int mState = BluetoothMap.STATE_DISCONNECTED;
    private BluetoothMapAppObserver mAppObserver = null;
@@ -184,7 +182,7 @@ public class BluetoothMapService extends ProfileService {
            mWakeLock = null;
        }

        sRemoteDevice = null;
        mRemoteDevice = null;
        // no need to invalidate cache here because setState did it above

        if (mSessionStatusHandler == null) {
@@ -240,7 +238,7 @@ public class BluetoothMapService extends ProfileService {

        if (mBluetoothMnsObexClient == null) {
            mBluetoothMnsObexClient =
                    new BluetoothMnsObexClient(sRemoteDevice, mMnsRecord, mSessionStatusHandler);
                    new BluetoothMnsObexClient(mRemoteDevice, mMnsRecord, mSessionStatusHandler);
        }

        boolean connected = false;
@@ -328,7 +326,7 @@ public class BluetoothMapService extends ProfileService {
        if (lastMasInst) {
            setState(BluetoothMap.STATE_DISCONNECTED);
            mPermission = BluetoothDevice.ACCESS_UNKNOWN;
            sRemoteDevice = null;
            mRemoteDevice = null;
            // no need to invalidate cache here because setState did it above
            if (mAccountChanged) {
                updateMasInstances(UPDATE_MAS_INSTANCES_ACCOUNT_DISCONNECT);
@@ -377,7 +375,7 @@ public class BluetoothMapService extends ProfileService {
                                SystemProperties.get(
                                        Utils.PAIRING_UI_PROPERTY,
                                        getString(R.string.pairing_ui_package)));
                        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, sRemoteDevice);
                        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mRemoteDevice);
                        intent.putExtra(
                                BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                                BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS);
@@ -433,9 +431,9 @@ public class BluetoothMapService extends ProfileService {
                    }
                    break;
                case MSG_MNS_SDP_SEARCH:
                    if (sRemoteDevice != null) {
                    if (mRemoteDevice != null) {
                        Log.d(TAG, "MNS SDP Initiate Search ..");
                        sRemoteDevice.sdpSearch(BluetoothMnsObexClient.BLUETOOTH_UUID_OBEX_MNS);
                        mRemoteDevice.sdpSearch(BluetoothMnsObexClient.BLUETOOTH_UUID_OBEX_MNS);
                    } else {
                        Log.w(TAG, "remoteDevice info not available");
                        ContentProfileErrorReportUtils.report(
@@ -479,7 +477,7 @@ public class BluetoothMapService extends ProfileService {
    }

    private void onConnectHandler(int masId) {
        if (mIsWaitingAuthorization || sRemoteDevice == null || mSdpSearchInitiated) {
        if (mIsWaitingAuthorization || mRemoteDevice == null || mSdpSearchInitiated) {
            return;
        }
        BluetoothMapMasInstance masInst = mMasInstances.get(masId);
@@ -490,7 +488,7 @@ public class BluetoothMapService extends ProfileService {
                Log.v(
                        TAG,
                        "incoming connection accepted from: "
                                + sRemoteDeviceName
                                + mRemoteDevice
                                + " automatically as trusted device");
                if (mBluetoothMnsObexClient != null && masInst != null) {
                    masInst.startObexServerSession(mBluetoothMnsObexClient);
@@ -520,7 +518,7 @@ public class BluetoothMapService extends ProfileService {
    }

    public BluetoothDevice getRemoteDevice() {
        return sRemoteDevice;
        return mRemoteDevice;
    }

    private void setState(int state) {
@@ -533,13 +531,13 @@ public class BluetoothMapService extends ProfileService {
            int prevState = mState;
            mState = state;
            mAdapterService.updateProfileConnectionAdapterProperties(
                    sRemoteDevice, BluetoothProfile.MAP, mState, prevState);
                    mRemoteDevice, BluetoothProfile.MAP, mState, prevState);

            BluetoothMap.invalidateBluetoothGetConnectionStateCache();
            Intent intent = new Intent(BluetoothMap.ACTION_CONNECTION_STATE_CHANGED);
            intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState);
            intent.putExtra(BluetoothProfile.EXTRA_STATE, mState);
            intent.putExtra(BluetoothDevice.EXTRA_DEVICE, sRemoteDevice);
            intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mRemoteDevice);
            sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempBroadcastOptions().toBundle());
        }
    }
@@ -571,8 +569,8 @@ public class BluetoothMapService extends ProfileService {
    List<BluetoothDevice> getConnectedDevices() {
        List<BluetoothDevice> devices = new ArrayList<>();
        synchronized (this) {
            if (mState == BluetoothMap.STATE_CONNECTED && sRemoteDevice != null) {
                devices.add(sRemoteDevice);
            if (mState == BluetoothMap.STATE_CONNECTED && mRemoteDevice != null) {
                devices.add(mRemoteDevice);
            }
        }
        return devices;
@@ -919,18 +917,13 @@ public class BluetoothMapService extends ProfileService {

        // As this can be called from each MasInstance, we need to lock access to member variables
        synchronized (this) {
            if (sRemoteDevice == null) {
                sRemoteDevice = remoteDevice;
            if (mRemoteDevice == null) {
                mRemoteDevice = remoteDevice;
                if (getState() == BluetoothMap.STATE_CONNECTED) {
                    BluetoothMap.invalidateBluetoothGetConnectionStateCache();
                }
                sRemoteDeviceName = Utils.getName(sRemoteDevice);
                // In case getRemoteName failed and return null
                if (TextUtils.isEmpty(sRemoteDeviceName)) {
                    sRemoteDeviceName = getString(R.string.defaultname);
                }

                mPermission = mAdapterService.getMessageAccessPermission(sRemoteDevice);
                mPermission = mAdapterService.getMessageAccessPermission(mRemoteDevice);
                if (mPermission == BluetoothDevice.ACCESS_UNKNOWN) {
                    sendIntent = true;
                    mIsWaitingAuthorization = true;
@@ -939,10 +932,10 @@ public class BluetoothMapService extends ProfileService {
                    cancelConnection = true;
                } else if (mPermission == BluetoothDevice.ACCESS_ALLOWED) {
                    mAdapterService.sdpSearch(
                            sRemoteDevice, BluetoothMnsObexClient.BLUETOOTH_UUID_OBEX_MNS);
                            mRemoteDevice, BluetoothMnsObexClient.BLUETOOTH_UUID_OBEX_MNS);
                    mSdpSearchInitiated = true;
                }
            } else if (!sRemoteDevice.equals(remoteDevice)) {
            } else if (!mRemoteDevice.equals(remoteDevice)) {
                Log.w(
                        TAG,
                        "Unexpected connection from a second Remote Device received. name: "
@@ -967,7 +960,7 @@ public class BluetoothMapService extends ProfileService {
            intent.putExtra(
                    BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                    BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS);
            intent.putExtra(BluetoothDevice.EXTRA_DEVICE, sRemoteDevice);
            intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mRemoteDevice);
            sendOrderedBroadcast(
                    intent,
                    BLUETOOTH_CONNECT,
@@ -978,7 +971,7 @@ public class BluetoothMapService extends ProfileService {
                    null,
                    null);

            Log.v(TAG, "waiting for authorization for connection from: " + sRemoteDeviceName);
            Log.v(TAG, "Waiting for authorization for connection from: " + mRemoteDevice);
            // Queue USER_TIMEOUT to disconnect MAP OBEX session. If user doesn't
            // accept or reject authorization request
        } else if (cancelConnection) {
@@ -1146,13 +1139,13 @@ public class BluetoothMapService extends ProfileService {
                    mPermission = BluetoothDevice.ACCESS_ALLOWED;
                    if (intent.getBooleanExtra(BluetoothDevice.EXTRA_ALWAYS_ALLOWED, false)) {
                        boolean result =
                                sRemoteDevice.setMessageAccessPermission(
                                mRemoteDevice.setMessageAccessPermission(
                                        BluetoothDevice.ACCESS_ALLOWED);
                        Log.d(TAG, "setMessageAccessPermission(ACCESS_ALLOWED) result=" + result);
                    }

                    mAdapterService.sdpSearch(
                            sRemoteDevice, BluetoothMnsObexClient.BLUETOOTH_UUID_OBEX_MNS);
                            mRemoteDevice, BluetoothMnsObexClient.BLUETOOTH_UUID_OBEX_MNS);
                    mSdpSearchInitiated = true;
                } else {
                    // Auth. declined by user, serverSession should not be running, but
@@ -1160,7 +1153,7 @@ public class BluetoothMapService extends ProfileService {
                    mPermission = BluetoothDevice.ACCESS_REJECTED;
                    if (intent.getBooleanExtra(BluetoothDevice.EXTRA_ALWAYS_ALLOWED, false)) {
                        boolean result =
                                sRemoteDevice.setMessageAccessPermission(
                                mRemoteDevice.setMessageAccessPermission(
                                        BluetoothDevice.ACCESS_REJECTED);
                        Log.d(TAG, "setMessageAccessPermission(ACCESS_REJECTED) result=" + result);
                    }
@@ -1194,7 +1187,7 @@ public class BluetoothMapService extends ProfileService {
        if (!mIsWaitingAuthorization) {
            return;
        }
        if (sRemoteDevice == null || device == null) {
        if (mRemoteDevice == null || device == null) {
            Log.e(TAG, "Unexpected error!");
            ContentProfileErrorReportUtils.report(
                    BluetoothProfile.MAP,
@@ -1206,7 +1199,7 @@ public class BluetoothMapService extends ProfileService {

        Log.v(TAG, "ACL disconnected for " + device);

        if (sRemoteDevice.equals(device)) {
        if (mRemoteDevice.equals(device)) {
            // Send any pending timeout now, since ACL got disconnected
            mSessionStatusHandler.removeMessages(USER_TIMEOUT);
            mSessionStatusHandler.obtainMessage(USER_TIMEOUT).sendToTarget();
@@ -1466,8 +1459,7 @@ public class BluetoothMapService extends ProfileService {
    @Override
    public void dump(StringBuilder sb) {
        super.dump(sb);
        println(sb, "mRemoteDevice: " + sRemoteDevice);
        println(sb, "sRemoteDeviceName: " + sRemoteDeviceName);
        println(sb, "mRemoteDevice: " + mRemoteDevice);
        println(sb, "mState: " + mState);
        println(sb, "mAppObserver: " + mAppObserver);
        println(sb, "mIsWaitingAuthorization: " + mIsWaitingAuthorization);