He did all of this before he went to face Bane in the tunnel. When Alfred speaks to him and leaves, Bruce gets the picture. He knows that he cannot and does not want to be the Batman, but he knows that he can't walk away, leaving the city without a hero. When, however, he meets Robin - John Blake - he knows that he can hang up the cape. That's when he changes the will and fixes the autopilot. In the eyes of the city, he has to be dead. Batman has to give them everything, so that Bruce can have something.