Use Android ROTATION_VECTOR as HMD orientation

I’m trying to create a custom HMD plugin that will use android ROTATION_VECTOR as HDM’s orientation

I’ve successfully cloned SimpleHMD plugin, and get ROTATION_VECTOR values from Android using JNI,
But i can’t figure a correct way to convert Android coordinate system to Unreal.

I’ve update GetCurrentPose function to retrieve a quaternion using ROTATION_VECTOR values, but i can’t map them correctly to Unreal coordinate system.

It moves, but it moves wrong. For example: When i tilt head up/down it will go right/left instead, etc.
I tried all possible combinations, and i just can’t get it right.

I have this code running correctly on Unity:

  Quaternion orientation = new Quaternion(sensorValues[0],sensorValues[2],sensorValues[1],-sensorValues[3]);
    Quaternion fix = new Quaternion(0.7f,0,0,0.7f);
    Quaternion fix2 = new Quaternion(0,1,0,0);
    Quaternion final = orientation * fix * fix2;
    this.transform.rotation = new Quaternion(-final.x,final.y,-final.z,final.w);

I created a sample application, and tried to just control a regular Camera object, and i managed to make this work by translating Unity coordinate system to Unreal:

    //arot is float array from Android ROTATION_VECTOR
    FQuat q(arot[0],arot[2],arot[1],-arot[3]);
	FQuat fix(0.7, 0,0, 0.7);
	FQuat fix2(0,1,0,0);
	FQuat fQ = q * fix * fix2;
	FQuat rotation = FQuat(-fQ.X,fQ.Y, -fQ.Z, fQ.W);

	FVector axis;
	float angle;
	rotation.ToAxisAndAngle(axis,angle);
	axis = FVector(axis.Z,axis.X,axis.Y);
	FQuat q2 = FQuat(FVector::UpVector,FMath::DegreesToRadians(90.0)) * FQuat(axis,angle);

	APlayerController* pc = UGameplayStatics::GetPlayerController(this,0);
	if (pc) {
		if (pc->GetViewTarget() != Camera && Camera != nullptr) {
			pc->SetViewTarget(Camera);
		}
		if (Camera!=nullptr) {
			Camera->SetActorRotation(q2,ETeleportType::None);
		}
	}

And this works correctly, for every direction i get the expected result.
However, if i try to apply this code in my HMD plugin’s GetCurrentPose,
It just doesn’t work right.

This is my GetCurrentPose function:

    //rotation is float array from Android ROTATION_VECTOR
	FQuat q(rotation[0],rotation[2],rotation[1],-rotation[3]);
	FQuat fix(0.7, 0,0, 0.7);
	FQuat fix2(0,1,0,0);
	FQuat fQ = q * fix * fix2;
	FQuat fRotation = FQuat(-fQ.X,fQ.Y,-fQ.Z, fQ.W);
	FVector axis;
	float angle;
	fRotation.ToAxisAndAngle(axis,angle);
	axis = FVector(axis.Z,axis.X,axis.Y);
	FQuat q2 = FQuat(FVector::UpVector,FMath::DegreesToRadians(90.0)) * FQuat(axis,angle);
	CurrentOrientation = fRotation;