Found the solution.
The problem is caused by some newer devices' default orientation is set landscape while the others' portrait. So the sensor manager behaves accordingly. In order to get sensor manager work as you expect you need to detect the defaultDisplayRotation of the device and change the remapCoordinateSystem() parameter logic.
I have changed
SensorManager.remapCoordinateSystem(Rmat, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, R2);
to
int rotation = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
if(rotation == 0) // Default display rotation is portrait
SensorManager.remapCoordinateSystem(Rmat, SensorManager.AXIS_MINUS_X, SensorManager.AXIS_Y, R2);
else // Default display rotation is landscape
SensorManager.remapCoordinateSystem(Rmat, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, R2);
now it works... Hope this will be useful for someone else!