A difficult question...
I guess it is related to lexical meaning of a verb, so there is no general rule.
This sentences look very similar for me:
Когда ты фильм смотрел? Когда ты фильм посмотрел?
Когда ты книгу читал? Когда ты книгу прочитал?
Когда ты машину чинил? Когда ты машину починил?
Here perfective is preferable, but imperfective isn't ungrammatical too:
Когда ты яблоко ел? Когда ты яблоко съел?
Когда ты телефон покупал? Когда ты телефон купил?
And here imperfective sounds awful:
Когда ты машину разбивал? Когда ты машину разбил?
I feel, that all these "когда смотрел/посмотрел, читал/прочитал, чинил/починил, ел/съел, купил/покупал" questions DO HAVE subtle differences in meaning and should be used in different contexts, but I have no idea what the difference actually is.