Refactor applyPermission out of the Test

Change-Id: Icb881141144fb940d7d1dc2857fdfad6e8638733
Merge "Refactor applyPermission out of the Test"