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

Commit 34f5abd5 authored by Jack He's avatar Jack He Committed by android-build-merger
Browse files

Merge "HFP: Remove dead code in HFP profile" am: da4bbbab am: c1f900a4

am: 3cb3e9b3

Change-Id: I74d31bf185c45e6e14fd2582182650073a9cbb1c
parents ec60e33d 3cb3e9b3
Loading
Loading
Loading
Loading
+0 −47
Original line number Diff line number Diff line
@@ -668,31 +668,6 @@ static jboolean cindResponseNative(JNIEnv* env, jobject object, jint service,
  return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}

static jboolean bindResponseNative(JNIEnv* env, jobject object, jint ind_id,
                                   jboolean ind_status, jbyteArray address) {
  ALOGI("%s: sBluetoothHfpInterface: %p", __func__, sBluetoothHfpInterface);

  std::shared_lock<std::shared_timed_mutex> lock(interface_mutex);
  if (!sBluetoothHfpInterface) return JNI_FALSE;

  jbyte* addr = env->GetByteArrayElements(address, NULL);
  if (!addr) {
    jniThrowIOException(env, EINVAL);
    return JNI_FALSE;
  }

  bt_status_t status = sBluetoothHfpInterface->bind_response(
      (bthf_hf_ind_type_t)ind_id,
      ind_status ? BTHF_HF_IND_ENABLED : BTHF_HF_IND_DISABLED,
      (RawAddress*)addr);

  if (status != BT_STATUS_SUCCESS)
    ALOGE("%s: Failed bind_response, status: %d", __func__, status);

  env->ReleaseByteArrayElements(address, addr, 0);
  return (status == BT_STATUS_SUCCESS ? JNI_TRUE : JNI_FALSE);
}

static jboolean atResponseStringNative(JNIEnv* env, jobject object,
                                       jstring response_str,
                                       jbyteArray address) {
@@ -786,26 +761,6 @@ static jboolean phoneStateChangeNative(JNIEnv* env, jobject object,
  return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}

static jboolean configureWBSNative(JNIEnv* env, jobject object,
                                   jbyteArray address, jint codec_config) {
  std::shared_lock<std::shared_timed_mutex> lock(interface_mutex);
  if (!sBluetoothHfpInterface) return JNI_FALSE;

  jbyte* addr = env->GetByteArrayElements(address, NULL);
  if (!addr) {
    jniThrowIOException(env, EINVAL);
    return JNI_FALSE;
  }

  bt_status_t status = sBluetoothHfpInterface->configure_wbs(
      (RawAddress*)addr, (bthf_wbs_config_t)codec_config);
  if (status != BT_STATUS_SUCCESS) {
    ALOGE("Failed HF WBS codec config, status: %d", status);
  }
  env->ReleaseByteArrayElements(address, addr, 0);
  return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}

static jboolean setScoAllowedNative(JNIEnv* env, jobject object,
                                    jboolean value) {
  if (!sBluetoothHfpInterface) return JNI_FALSE;
@@ -834,7 +789,6 @@ static JNINativeMethod sMethods[] = {
    {"copsResponseNative", "(Ljava/lang/String;[B)Z",
     (void*)copsResponseNative},
    {"cindResponseNative", "(IIIIIII[B)Z", (void*)cindResponseNative},
    {"bindResponseNative", "(IZ[B)Z", (void*)bindResponseNative},
    {"atResponseStringNative", "(Ljava/lang/String;[B)Z",
     (void*)atResponseStringNative},
    {"atResponseCodeNative", "(II[B)Z", (void*)atResponseCodeNative},
@@ -842,7 +796,6 @@ static JNINativeMethod sMethods[] = {
     (void*)clccResponseNative},
    {"phoneStateChangeNative", "(IIILjava/lang/String;I)Z",
     (void*)phoneStateChangeNative},
    {"configureWBSNative", "([BI)Z", (void*)configureWBSNative},
    {"setScoAllowedNative", "(Z)Z", (void*)setScoAllowedNative},
};

+0 −29
Original line number Diff line number Diff line
@@ -343,19 +343,6 @@ public class HeadsetNativeInterface {
                batteryCharge, Utils.getByteAddress(device));
    }

    /**
     * Response for BIND command
     *
     * @param device target device
     * @param indId indicator id
     * @param indStatus indicator value
     * @return True on success, False on failure
     */
    @VisibleForTesting
    public boolean bindResponse(BluetoothDevice device, int indId, boolean indStatus) {
        return bindResponseNative(indId, indStatus, Utils.getByteAddress(device));
    }

    /**
     * Combined device status change notification
     *
@@ -423,18 +410,6 @@ public class HeadsetNativeInterface {
                callState.mCallState, callState.mNumber, callState.mType);
    }

    /**
     * Configure Wid-Band-Speech codec for HFP audio (SCO)
     *
     * @param device target device
     * @param codecConfig codec configuration
     * @return True on success, False on failure
     */
    @VisibleForTesting
    public boolean configureWBS(BluetoothDevice device, int codecConfig) {
        return configureWBSNative(Utils.getByteAddress(device), codecConfig);
    }

    /**
     * Set whether we will initiate SCO or not
     *
@@ -474,8 +449,6 @@ public class HeadsetNativeInterface {
    private native boolean cindResponseNative(int service, int numActive, int numHeld,
            int callState, int signal, int roam, int batteryCharge, byte[] address);

    private native boolean bindResponseNative(int indId, boolean indStatus, byte[] address);

    private native boolean notifyDeviceStatusNative(int networkState, int serviceType, int signal,
            int batteryCharge);

@@ -487,7 +460,5 @@ public class HeadsetNativeInterface {
    private native boolean phoneStateChangeNative(int numActive, int numHeld, int callState,
            String number, int type);

    private native boolean configureWBSNative(byte[] address, int codecConfig);

    private native boolean setScoAllowedNative(boolean value);
}
+0 −121
Original line number Diff line number Diff line
@@ -286,33 +286,6 @@ public class HeadsetService extends ProfileService {
            return service.isAudioConnected(device);
        }

        @Override
        public int getBatteryUsageHint(BluetoothDevice device) {
            HeadsetService service = getService();
            if (service == null) {
                return 0;
            }
            return service.getBatteryUsageHint(device);
        }

        @Override
        public boolean acceptIncomingConnect(BluetoothDevice device) {
            HeadsetService service = getService();
            if (service == null) {
                return false;
            }
            return service.acceptIncomingConnect(device);
        }

        @Override
        public boolean rejectIncomingConnect(BluetoothDevice device) {
            HeadsetService service = getService();
            if (service == null) {
                return false;
            }
            return service.rejectIncomingConnect(device);
        }

        @Override
        public int getAudioState(BluetoothDevice device) {
            HeadsetService service = getService();
@@ -414,33 +387,6 @@ public class HeadsetService extends ProfileService {
            }
            return service.sendVendorSpecificResultCode(device, command, arg);
        }

        @Override
        public boolean enableWBS() {
            HeadsetService service = getService();
            if (service == null) {
                return false;
            }
            return service.enableWBS();
        }

        @Override
        public boolean disableWBS() {
            HeadsetService service = getService();
            if (service == null) {
                return false;
            }
            return service.disableWBS();
        }

        @Override
        public void bindResponse(int indId, boolean indStatus) {
            HeadsetService service = getService();
            if (service == null) {
                return;
            }
            service.bindResponse(indId, indStatus);
        }
    }

    // API methods
@@ -569,21 +515,6 @@ public class HeadsetService extends ProfileService {
        return mStateMachine.isAudioConnected(device);
    }

    int getBatteryUsageHint(BluetoothDevice device) {
        // TODO(BT) ask for BT stack support?
        return 0;
    }

    boolean acceptIncomingConnect(BluetoothDevice device) {
        // TODO(BT) remove it if stack does access control
        return false;
    }

    boolean rejectIncomingConnect(BluetoothDevice device) {
        // TODO(BT) remove it if stack does access control
        return false;
    }

    int getAudioState(BluetoothDevice device) {
        return mStateMachine.getAudioState(device);
    }
@@ -676,58 +607,6 @@ public class HeadsetService extends ProfileService {
        return true;
    }

    boolean enableWBS() {
        // TODO(BT) BLUETOOTH or BLUETOOTH_ADMIN permission
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        if (!mStateMachine.isConnected()) {
            return false;
        }
        if (mStateMachine.isAudioOn()) {
            return false;
        }

        for (BluetoothDevice device : getConnectedDevices()) {
            mStateMachine.sendMessage(HeadsetStateMachine.ENABLE_WBS, device);
        }

        return true;
    }

    boolean disableWBS() {
        // TODO(BT) BLUETOOTH or BLUETOOTH_ADMIN permission
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        if (!mStateMachine.isConnected()) {
            return false;
        }
        if (mStateMachine.isAudioOn()) {
            return false;
        }
        for (BluetoothDevice device : getConnectedDevices()) {
            mStateMachine.sendMessage(HeadsetStateMachine.DISABLE_WBS, device);
        }
        return true;
    }

    private boolean bindResponse(int indId, boolean indStatus) {
        for (BluetoothDevice device : getConnectedDevices()) {
            int connectionState = mStateMachine.getConnectionState(device);
            if (connectionState != BluetoothProfile.STATE_CONNECTED
                    && connectionState != BluetoothProfile.STATE_CONNECTING) {
                continue;
            }
            if (DBG) {
                Log.d("Bind Response sent for", device.getAddress());
            }
            Message msg = mStateMachine.obtainMessage(HeadsetStateMachine.BIND_RESPONSE);
            msg.obj = device;
            msg.arg1 = indId;
            msg.arg2 = indStatus ? 1 : 0;
            mStateMachine.sendMessage(msg);
            return true;
        }
        return false;
    }

    @Override
    public void dump(StringBuilder sb) {
        super.dump(sb);
+0 −25
Original line number Diff line number Diff line
@@ -106,11 +106,6 @@ final class HeadsetStateMachine extends StateMachine {
    static final int VIRTUAL_CALL_START = 14;
    static final int VIRTUAL_CALL_STOP = 15;

    static final int ENABLE_WBS = 16;
    static final int DISABLE_WBS = 17;

    static final int BIND_RESPONSE = 18;

    static final int STACK_EVENT = 101;
    private static final int DIALING_OUT_TIMEOUT = 102;
    private static final int START_VR_TIMEOUT = 103;
@@ -513,11 +508,6 @@ final class HeadsetStateMachine extends StateMachine {
                case CALL_STATE_CHANGED:
                    processCallState((HeadsetCallState) message.obj, message.arg1 == 1);
                    break;
                case BIND_RESPONSE: {
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    mNativeInterface.bindResponse(device, message.arg1, message.arg2 == 1);
                    break;
                }
                case DEVICE_STATE_CHANGED:
                    log("Pending: ignoring DEVICE_STATE_CHANGED event");
                    break;
@@ -947,21 +937,6 @@ final class HeadsetStateMachine extends StateMachine {
                case VIRTUAL_CALL_STOP:
                    terminateScoUsingVirtualVoiceCall();
                    break;
                case ENABLE_WBS: {
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    mNativeInterface.configureWBS(device, WBS_CODEC);
                    break;
                }
                case DISABLE_WBS: {
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    mNativeInterface.configureWBS(device, NBS_CODEC);
                    break;
                }
                case BIND_RESPONSE: {
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    mNativeInterface.bindResponse(device, message.arg1, message.arg2 == 1);
                    break;
                }
                case START_VR_TIMEOUT: {
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    if (mWaitingForVoiceRecognition) {