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

Commit cfb64759 authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge changes I5d3d81b7,I9a58d56a into main

* changes:
  Errorprone: StaticGuardedByInstance
  MAP: toward removing StaticGuardedByInstance error
parents 1180281d 92960bfc
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -360,6 +360,7 @@ android_app {
            "-Xep:OperatorPrecedence:ERROR",
            "-Xep:ReferenceEquality:ERROR",
            "-Xep:ReturnAtTheEndOfVoidFunction:ERROR",
            "-Xep:StaticGuardedByInstance:ERROR",
            "-Xep:StringCaseLocaleUsage:ERROR",
            "-Xep:StringCharset:ERROR",
            "-Xep:SynchronizeOnNonFinalField:ERROR",
+3 −1
Original line number Diff line number Diff line
@@ -1259,7 +1259,9 @@ public class BluetoothMapContent {
        } else {
            isHondaCarkit =
                    DeviceWorkArounds.addressStartsWith(
                            BluetoothMapService.getRemoteDevice().getAddress(),
                            BluetoothMapService.getBluetoothMapService()
                                    .getRemoteDevice()
                                    .getAddress(),
                            DeviceWorkArounds.HONDA_CARKIT);
        }
        if (isHondaCarkit || (ap.getParameterMask() & MASK_SUBJECT) != 0) {
+4 −2
Original line number Diff line number Diff line
@@ -100,7 +100,9 @@ public class BluetoothMapMessageListing {
        } else {
            isBenzCarkit =
                    DeviceWorkArounds.addressStartsWith(
                            BluetoothMapService.getRemoteDevice().getAddress(),
                            BluetoothMapService.getBluetoothMapService()
                                    .getRemoteDevice()
                                    .getAddress(),
                            DeviceWorkArounds.MERCEDES_BENZ_CARKIT);
        }
        try {
@@ -147,7 +149,7 @@ public class BluetoothMapMessageListing {
        /* Fix IOT issue to replace '&amp;' by '&', &lt; by < and '&gt; by '>' in MessageListing */
        if (!Utils.isInstrumentationTestMode()
                && DeviceWorkArounds.addressStartsWith(
                        BluetoothMapService.getRemoteDevice().getAddress(),
                        BluetoothMapService.getBluetoothMapService().getRemoteDevice().getAddress(),
                        DeviceWorkArounds.BREZZA_ZDI_CARKIT)) {
            return sw.toString()
                    .replaceAll("&amp;", "&")
+2 −2
Original line number Diff line number Diff line
@@ -267,14 +267,14 @@ public class BluetoothMapMessageListingElement
     * */
    public void encode(XmlSerializer xmlMsgElement, boolean includeThreadId)
            throws IllegalArgumentException, IllegalStateException, IOException {
        // contruct the XML tag for a single msg in the msglisting
        // construct the XML tag for a single msg in the msglisting
        xmlMsgElement.startTag(null, "msg");
        xmlMsgElement.attribute(null, "handle", BluetoothMapUtils.getMapHandle(mCpHandle, mType));
        if (mSubject != null) {
            String stripped = BluetoothMapUtils.stripInvalidChars(mSubject);

            if (DeviceWorkArounds.addressStartsWith(
                    BluetoothMapService.getRemoteDevice().getAddress(),
                    BluetoothMapService.getBluetoothMapService().getRemoteDevice().getAddress(),
                    DeviceWorkArounds.MERCEDES_BENZ_CARKIT)) {
                stripped = stripped.replaceAll("[\\P{ASCII}&\"><]", "");
                if (stripped.isEmpty()) {
+29 −37
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);
@@ -519,8 +517,8 @@ public class BluetoothMapService extends ProfileService {
        return mState;
    }

    public static BluetoothDevice getRemoteDevice() {
        return sRemoteDevice;
    public BluetoothDevice getRemoteDevice() {
        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();
@@ -1307,7 +1300,7 @@ public class BluetoothMapService extends ProfileService {
                    Log.v(TAG, "getClient() - no service - returning " + null);
                    return null;
                }
                BluetoothDevice client = BluetoothMapService.getRemoteDevice();
                BluetoothDevice client = service.getRemoteDevice();
                Log.v(TAG, "getClient() - returning " + client);
                return client;
            } catch (RuntimeException e) {
@@ -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);
Loading