Answer by taking a quote from the following article:

Tilak was born in a Marathi Chitpavan Brahmin family in Ratnagiri as Keshav Gangadhar Tilak, as mentioned above. In headquarters of the eponymous district of present-day Maharashtra (then British India) on 23 July 1856. His ancestral village was Chikhali. His father, Gangadhar Tilak was a school teacher and a Sanskrit scholar who died when Tilak was sixteen.

On 30 April 1908, two Bengali youths, Prafulla Chaki and Khudiram Bose, threw a bomb on a carriage at Muzzafarpur, to kill the Chief Presidency Magistrate Douglas Kingsford of Calcutta fame, but erroneously killed two women traveling in it. While Chaki committed suicide when caught, Bose was hanged. Tilak, in his paper Kesari, defended the revolutionaries and called for immediate Swaraj or self-rule. The Government swiftly charged him with sedition. At the conclusion of the trial, a special jury convicted him by 7:2 majority. The judge, Dinshaw D. Davar gave him a six years jail sentence to be served in Mandalay, Burma and a fine of Rs 1,000. On being asked by the judge whether he had anything to say, Tilak said: All that I wish to say is that, in spite of the verdict of the jury, I still maintain that I am innocent. There are higher powers that rule the destinies of men and nations; and I think, it may be the will of Providence that the cause I represent may be benefited more by my suffering than by my pen and tongue. In passing sentence, the judge indulged in some scathing strictures against Tilak's conduct. He threw off the judicial restraint which, to some extent, was observable in his charge to the jury. He condemned the articles as "seething with sedition", as preaching violence, speaking of murders with approval. "You hail the advent of the bomb in India as if something had come to India for its good. I say, such journalism is a curse to the country". Tilak was sent to Mandalay from 1908 to 1914. While imprisoned, he continued to read and write, further developing his ideas on the Indian nationalist movement. While in the prison he wrote the Gita Rahasya. Many copies of which were sold, and the money was donated for the Indian Independence movement..

How was he treated in prison?
While imprisoned, he continued to read and write,