@Override protected void tearDown() throws Exception { if (mDevicePolicyManager.isDeviceOwnerApp(PACKAGE_NAME) || mDevicePolicyManager.isProfileOwnerApp(PACKAGE_NAME)) { mDevicePolicyManager.setUninstallBlocked(getWho(), TEST_APP_PKG, false); } try { mContext.unregisterReceiver(mBroadcastReceiver); } catch (IllegalArgumentException e) { // ignore } if (mSession != null) { mSession.abandon(); } super.tearDown(); }