Improving activity and package auto-detect logic