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

Commit 85a2c045 authored by Jakub Tyszkowski's avatar Jakub Tyszkowski Committed by Jakub Pawlowski
Browse files

mcp: Remove usage of android.util.MathUtils

Bug: 150670922
Bug: 197723745
Tag: #feature
Test: atest MediaControlGattServiceTest
Sponsor: jpawlowski@
Change-Id: I82607655593f0709a74dcef3d0cde59840159a85
parent 48e500e3
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.util.Log;
import android.util.MathUtils;

import com.android.internal.annotations.VisibleForTesting;

@@ -808,7 +807,7 @@ public class MediaControlGattService implements MediaControlGattServiceInterface
    }

    private void handlePlaybackSpeedRequest(int speed) {
        float floatingSpeed = MathUtils.pow(2, speed / 64);
        float floatingSpeed = (float) Math.pow(2, speed / 64);
        mCallbacks.onPlaybackSpeedSetRequest(floatingSpeed);
    }

@@ -1312,11 +1311,11 @@ public class MediaControlGattService implements MediaControlGattServiceInterface
            speed = PLAY_SPEED_MAX;
        }

        return new Float(64 * MathUtils.log(speed) / MathUtils.log(2)).intValue();
        return new Float(64 * Math.log(speed) / Math.log(2)).intValue();
    }

    private static float CharacteristicSpeedIntValueToSpeedFloat(Integer speed) {
        return new Float(MathUtils.pow(2, (speed.floatValue() / 64.0f)));
        return new Float(Math.pow(2, (speed.floatValue() / 64.0f)));
    }

    @VisibleForTesting
+2 −3
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.content.Context;
import android.os.Looper;
import android.util.MathUtils;

import androidx.test.InstrumentationRegistry;
import androidx.test.filters.MediumTest;
@@ -548,7 +547,7 @@ public class MediaControlGattServiceTest {
                mCurrentDevice, 1, characteristic, false, true, 0, bb.array());

        verify(mMockMcsCallbacks)
                .onPlaybackSpeedSetRequest(eq(MathUtils.pow(2, playback_speed / 64)));
                .onPlaybackSpeedSetRequest(eq((float) Math.pow(2, playback_speed / 64)));

        verify(mMockGattServer)
                .sendResponse(eq(mCurrentDevice), eq(1), eq(BluetoothGatt.GATT_SUCCESS), eq(0),
@@ -955,7 +954,7 @@ public class MediaControlGattServiceTest {
                mCurrentDevice, 1, characteristic, false, true, 0, bb.array());

        verify(mMockMcsCallbacks)
                .onPlaybackSpeedSetRequest(eq(MathUtils.pow(2, playback_speed / 64)));
                .onPlaybackSpeedSetRequest(eq((float) Math.pow(2, playback_speed / 64)));

        // Fake characteristic write - this is done by player status update
        characteristic.setValue(playback_speed, BluetoothGattCharacteristic.FORMAT_SINT8, 0);