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

Commit d87d8c13 authored by William Escande's avatar William Escande
Browse files

SdpManager: Extract NativeInterface

Bug: 295237486
Test: atest DipTest
Change-Id: I7ce1e57436b5d5e932ab669189c05ad5755dfb04
parent 639be0e0
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -529,7 +529,8 @@ static JNINativeMethod sMethods[] = {
    {"sdpRemoveSdpRecordNative", "(I)Z", (void*)sdpRemoveSdpRecordNative}};

int register_com_android_bluetooth_sdp(JNIEnv* env) {
  return jniRegisterNativeMethods(env, "com/android/bluetooth/sdp/SdpManager",
                                  sMethods, NELEM(sMethods));
  return jniRegisterNativeMethods(
      env, "com/android/bluetooth/sdp/SdpManagerNativeInterface", sMethods,
      NELEM(sMethods));
}
}
+13 −6
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ import com.android.bluetooth.IObexConnectionHandler;
import com.android.bluetooth.ObexServerSockets;
import com.android.bluetooth.map.BluetoothMapContentObserver.Msg;
import com.android.bluetooth.map.BluetoothMapUtils.TYPE;
import com.android.bluetooth.sdp.SdpManager;
import com.android.bluetooth.sdp.SdpManagerNativeInterface;
import com.android.internal.annotations.VisibleForTesting;
import com.android.obex.ServerSession;

@@ -137,12 +137,13 @@ public class BluetoothMapMasInstance implements IObexConnectionHandler {
    }

    private void removeSdpRecord() {
        if (mAdapter != null && mSdpHandle >= 0 && SdpManager.getDefaultManager() != null) {
        SdpManagerNativeInterface nativeInterface = SdpManagerNativeInterface.getInstance();
        if (mAdapter != null && mSdpHandle >= 0 && nativeInterface.isAvailable()) {
            if (V) {
                Log.d(mTag, "Removing SDP record for MAS instance: " + mMasInstanceId
                        + " Object reference: " + this + "SDP handle: " + mSdpHandle);
            }
            boolean status = SdpManager.getDefaultManager().removeSdpRecord(mSdpHandle);
            boolean status = nativeInterface.removeSdpRecord(mSdpHandle);
            Log.d(mTag, "RemoveSDPrecord returns " + status);
            mSdpHandle = -1;
        }
@@ -371,9 +372,15 @@ public class BluetoothMapMasInstance implements IObexConnectionHandler {
                sFeatureMask = SDP_MAP_MAS_FEATURES_1_4;
        }

        return SdpManager.getDefaultManager()
                .createMapMasRecord(masName, mMasInstanceId, rfcommChannel, l2capPsm,
                        masVersion, messageTypeFlags, sFeatureMask);
        return SdpManagerNativeInterface.getInstance()
                .createMapMasRecord(
                        masName,
                        mMasInstanceId,
                        rfcommChannel,
                        l2capPsm,
                        masVersion,
                        messageTypeFlags,
                        sFeatureMask);
    }

    /* Called for all MAS instances for each instance when auth. is completed, hence
+19 −11
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ import com.android.bluetooth.BluetoothObexTransport;
import com.android.bluetooth.IObexConnectionHandler;
import com.android.bluetooth.ObexServerSockets;
import com.android.bluetooth.Utils;
import com.android.bluetooth.sdp.SdpManager;
import com.android.bluetooth.sdp.SdpManagerNativeInterface;
import com.android.obex.ServerSession;

import java.io.IOException;
@@ -61,13 +61,17 @@ public class MnsService {
        sContext = context;
        sAcceptThread = new SocketAcceptor();
        sServerSockets = ObexServerSockets.create(sAcceptThread);
        SdpManager sdpManager = SdpManager.getDefaultManager();
        if (sdpManager == null) {
            Log.e(TAG, "SdpManager is null");
        SdpManagerNativeInterface nativeInterface = SdpManagerNativeInterface.getInstance();
        if (!nativeInterface.isAvailable()) {
            Log.e(TAG, "SdpManagerNativeInterface is not available");
            return;
        }
        mSdpHandle = sdpManager.createMapMnsRecord("MAP Message Notification Service",
                sServerSockets.getRfcommChannel(), sServerSockets.getL2capPsm(), MNS_VERSION,
        mSdpHandle =
                nativeInterface.createMapMnsRecord(
                        "MAP Message Notification Service",
                        sServerSockets.getRfcommChannel(),
                        sServerSockets.getL2capPsm(),
                        MNS_VERSION,
                        MasClient.MAP_SUPPORTED_FEATURES);
    }

@@ -90,13 +94,17 @@ public class MnsService {
        }
        int sdpHandle = mSdpHandle;
        mSdpHandle = -1;
        SdpManager sdpManager = SdpManager.getDefaultManager();
        if (sdpManager == null) {
            Log.e(TAG, "cleanUpSdpRecord failed, sdpManager is null, sdpHandle=" + sdpHandle);
        SdpManagerNativeInterface nativeInterface = SdpManagerNativeInterface.getInstance();
        if (!nativeInterface.isAvailable()) {
            Log.e(
                    TAG,
                    "cleanUpSdpRecord failed, SdpManagerNativeInterface is not available,"
                            + " sdpHandle="
                            + sdpHandle);
            return;
        }
        Log.i(TAG, "cleanUpSdpRecord, mSdpHandle=" + sdpHandle);
        if (!sdpManager.removeSdpRecord(sdpHandle)) {
        if (!nativeInterface.removeSdpRecord(sdpHandle)) {
            Log.e(TAG, "cleanUpSdpRecord, removeSdpRecord failed, sdpHandle=" + sdpHandle);
        }
    }
+17 −10
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ import com.android.bluetooth.IObexConnectionHandler;
import com.android.bluetooth.ObexServerSockets;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.sdp.SdpManager;
import com.android.bluetooth.sdp.SdpManagerNativeInterface;
import com.android.internal.annotations.VisibleForTesting;
import com.android.obex.ObexTransport;

@@ -514,15 +514,22 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
        stopListeners();
        mServerSocket = ObexServerSockets.createInsecure(this);
        acceptNewConnections();
        SdpManager sdpManager = SdpManager.getDefaultManager();
        if (sdpManager == null || mServerSocket == null) {
            Log.e(TAG, "ERROR:serversocket object is NULL  sdp manager :" + sdpManager
                    + " mServerSocket:" + mServerSocket);
        SdpManagerNativeInterface nativeInterface = SdpManagerNativeInterface.getInstance();
        if (!nativeInterface.isAvailable()) {
            Log.e(TAG, "ERROR:serversocket: SdpManagerNativeInterface is not available");
            return;
        }
        if (mServerSocket == null) {
            Log.e(TAG, "ERROR:serversocket: mServerSocket is null");
            return;
        }
        mOppSdpHandle =
                sdpManager.createOppOpsRecord("OBEX Object Push", mServerSocket.getRfcommChannel(),
                        mServerSocket.getL2capPsm(), 0x0102, SUPPORTED_OPP_FORMAT);
                nativeInterface.createOppOpsRecord(
                        "OBEX Object Push",
                        mServerSocket.getRfcommChannel(),
                        mServerSocket.getL2capPsm(),
                        0x0102,
                        SUPPORTED_OPP_FORMAT);
        if (D) {
            Log.d(TAG, "mOppSdpHandle :" + mOppSdpHandle);
        }
@@ -1238,12 +1245,12 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
    }

    private void stopListeners() {
        if (mAdapterService != null && mOppSdpHandle >= 0
                && SdpManager.getDefaultManager() != null) {
        SdpManagerNativeInterface nativeInterface = SdpManagerNativeInterface.getInstance();
        if (mAdapterService != null && mOppSdpHandle >= 0 && nativeInterface.isAvailable()) {
            if (D) {
                Log.d(TAG, "Removing SDP record mOppSdpHandle :" + mOppSdpHandle);
            }
            boolean status = SdpManager.getDefaultManager().removeSdpRecord(mOppSdpHandle);
            boolean status = nativeInterface.removeSdpRecord(mOppSdpHandle);
            Log.d(TAG, "RemoveSDPrecord returns " + status);
            mOppSdpHandle = -1;
        }
+14 −10
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.InteropUtil;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.bluetooth.sdp.SdpManager;
import com.android.bluetooth.sdp.SdpManagerNativeInterface;
import com.android.bluetooth.util.DevicePolicyUtils;
import com.android.internal.annotations.VisibleForTesting;

@@ -376,10 +376,14 @@ public class BluetoothPbapService extends ProfileService implements IObexConnect
            return;
        }

        mSdpHandle = SdpManager.getDefaultManager()
                .createPbapPseRecord("OBEX Phonebook Access Server",
                       mServerSockets.getRfcommChannel(), mServerSockets.getL2capPsm(),
                       SDP_PBAP_SERVER_VERSION_1_2, SDP_PBAP_SUPPORTED_REPOSITORIES,
        mSdpHandle =
                SdpManagerNativeInterface.getInstance()
                        .createPbapPseRecord(
                                "OBEX Phonebook Access Server",
                                mServerSockets.getRfcommChannel(),
                                mServerSockets.getL2capPsm(),
                                SDP_PBAP_SERVER_VERSION_1_2,
                                SDP_PBAP_SUPPORTED_REPOSITORIES,
                                SDP_PBAP_SUPPORTED_FEATURES);

        if (DEBUG) {
@@ -395,13 +399,13 @@ public class BluetoothPbapService extends ProfileService implements IObexConnect
        }
        int sdpHandle = mSdpHandle;
        mSdpHandle = -1;
        SdpManager sdpManager = SdpManager.getDefaultManager();
        SdpManagerNativeInterface nativeInterface = SdpManagerNativeInterface.getInstance();
        if (DEBUG) {
            Log.d(TAG, "cleanUpSdpRecord, mSdpHandle=" + sdpHandle);
        }
        if (sdpManager == null) {
            Log.e(TAG, "sdpManager is null");
        } else if (!sdpManager.removeSdpRecord(sdpHandle)) {
        if (!nativeInterface.isAvailable()) {
            Log.e(TAG, "SdpManagerNativeInterface is not available");
        } else if (!nativeInterface.removeSdpRecord(sdpHandle)) {
            Log.w(TAG, "cleanUpSdpRecord, removeSdpRecord failed, sdpHandle=" + sdpHandle);
        }
    }
Loading