Time-dependent injection strategies for multilayer Hele-Shaw and porous media flows