Remove broadcast tests for UID migration

These system broadcasts are removed from the system.

Test: m CtsSharedUserMigrationTestCases
Bug: 220015249
Change-Id: Iea6ef2ee05ec808621cc8ebe88ba1ce37d61b507
diff --git a/tests/tests/uidmigration/src/android/uidmigration/cts/AppIdMigrationTest.kt b/tests/tests/uidmigration/src/android/uidmigration/cts/AppIdMigrationTest.kt
index 6d1911b..cb84f3f 100644
--- a/tests/tests/uidmigration/src/android/uidmigration/cts/AppIdMigrationTest.kt
+++ b/tests/tests/uidmigration/src/android/uidmigration/cts/AppIdMigrationTest.kt
@@ -17,10 +17,7 @@
 
 import android.Manifest.permission.INTERNET
 import android.Manifest.permission.WRITE_EXTERNAL_STORAGE
-import android.content.BroadcastReceiver
 import android.content.Context
-import android.content.Intent
-import android.content.IntentFilter
 import android.content.pm.PackageManager
 import android.content.pm.PackageManager.PackageInfoFlags
 import android.permission.cts.PermissionUtils
@@ -32,16 +29,11 @@
 import org.junit.Assert.assertEquals
 import org.junit.Assert.assertFalse
 import org.junit.Assert.assertNotEquals
-import org.junit.Assert.assertNotNull
 import org.junit.Assert.assertTrue
-import org.junit.Assert.fail
 import org.junit.Before
 import org.junit.Ignore
 import org.junit.Test
 import org.junit.runner.RunWith
-import java.util.concurrent.ArrayBlockingQueue
-import java.util.concurrent.BlockingQueue
-import java.util.concurrent.TimeUnit
 
 // All tests ignored: appId migration is disabled (http://b/220015249)
 @RunWith(AndroidJUnit4::class)
@@ -49,7 +41,6 @@
 
     companion object {
         private const val RESULT_KEY = "result"
-        private val NOT_AN_ERROR = Throwable()
     }
 
     private lateinit var mContext: Context
@@ -140,118 +131,15 @@
         var result = resolver.call(authority, "data", null, null).assertNotNull()
         val oldUUID = result.getString(RESULT_KEY).assertNotNull()
 
-        val receiver = PackageBroadcastReceiver(oldUid)
-        IntentFilter().apply {
-            addAction(Intent.ACTION_PACKAGE_REMOVED)
-            addAction(Intent.ACTION_PACKAGE_ADDED)
-            addAction(Intent.ACTION_PACKAGE_REPLACED)
-            addDataScheme("package")
-            mContext.registerReceiver(receiver, this)
-        }
-        IntentFilter().apply {
-            addAction(Intent.ACTION_UID_REMOVED)
-            addAction(Const.ACTION_UPDATE_ACK)
-            mContext.registerReceiver(receiver, this)
-        }
-
         // Update the data test APK and make sure UID changed.
         assertTrue(installPackage(apk + "2.apk"))
         val newUid = mPm.getPackageUid(Const.DATA_TEST_PKG, PackageInfoFlags.of(0))
         assertNotEquals(oldUid, newUid)
 
-        // Ensure system broadcasts are delivered properly.
-        try {
-            val e = receiver.poll(30, TimeUnit.SECONDS)
-            if (e !== NOT_AN_ERROR) {
-                throw AssertionError(e)
-            }
-        } catch (e: InterruptedException) {
-            fail(e.message)
-        }
-        assertEquals(newUid, receiver.newUid)
-        mContext.unregisterReceiver(receiver)
-
         // Ask the app again for a UUID. If data migration is working, it shall be the same.
         result = resolver.call(authority, "data", null, null).assertNotNull()
         val newUUID = result.getString(RESULT_KEY)
         assertEquals(oldUUID, newUUID)
         uninstallPackage(Const.DATA_TEST_PKG)
     }
-
-    class PackageBroadcastReceiver(
-        private val mPreviousUid: Int
-    ) : BroadcastReceiver(), BlockingQueue<Throwable?> by ArrayBlockingQueue<Throwable?>(1) {
-
-        var newUid = -1
-            private set
-        private var mCounter = 0
-
-        override fun onReceive(context: Context?, intent: Intent) {
-            try {
-                verifyInternal(intent)
-            } catch (e: Throwable) {
-                offer(e)
-            }
-        }
-
-        private fun verifyInternal(intent: Intent) {
-            val action = intent.action
-            assertNotNull(action)
-            if (action == Intent.ACTION_UID_REMOVED) {
-                // Not the test package, none of our business.
-                if (intent.getIntExtra(Intent.EXTRA_UID, -1) != mPreviousUid) {
-                    return
-                }
-            }
-            val data = intent.data
-            if (data != null) {
-                assertEquals("package", data.scheme)
-                val pkg = data.schemeSpecificPart
-                assertNotNull(pkg)
-                // Not the test package, none of our business.
-                if (Const.DATA_TEST_PKG != pkg) {
-                    return
-                }
-            }
-
-            // Broadcasts must come in the following order:
-            // ACTION_PACKAGE_REMOVED -> ACTION_UID_REMOVED
-            // -> ACTION_PACKAGE_ADDED -> ACTION_UPDATE_ACK
-            mCounter++
-            when (action) {
-                Intent.ACTION_PACKAGE_REMOVED -> {
-                    assertEquals(1, mCounter)
-                    assertFalse(intent.hasExtra(Intent.EXTRA_REPLACING))
-                    assertTrue(intent.getBooleanExtra(Intent.EXTRA_UID_CHANGING, false))
-                    assertEquals(mPreviousUid, intent.getIntExtra(Intent.EXTRA_UID, -1))
-                    newUid = intent.getIntExtra(Intent.EXTRA_NEW_UID, -1)
-                    assertNotEquals(mPreviousUid, newUid)
-                }
-                Intent.ACTION_UID_REMOVED -> {
-                    assertEquals(2, mCounter)
-                    assertFalse(intent.hasExtra(Intent.EXTRA_REPLACING))
-                    assertTrue(intent.getBooleanExtra(Intent.EXTRA_UID_CHANGING, false))
-                    assertEquals(
-                        Const.DATA_TEST_PKG,
-                        intent.getStringExtra(Intent.EXTRA_PACKAGE_NAME)
-                    )
-                }
-                Intent.ACTION_PACKAGE_ADDED -> {
-                    assertEquals(3, mCounter)
-                    assertFalse(intent.hasExtra(Intent.EXTRA_REPLACING))
-                    assertTrue(intent.getBooleanExtra(Intent.EXTRA_UID_CHANGING, false))
-                    assertEquals(newUid, intent.getIntExtra(Intent.EXTRA_UID, mPreviousUid))
-                    assertEquals(mPreviousUid, intent.getIntExtra(Intent.EXTRA_PREVIOUS_UID, -1))
-                }
-                Const.ACTION_UPDATE_ACK -> {
-                    assertEquals(4, mCounter)
-                    assertEquals(newUid, intent.getIntExtra(Intent.EXTRA_UID, -2))
-                    // End of actions
-                    offer(NOT_AN_ERROR)
-                }
-                Intent.ACTION_PACKAGE_REPLACED -> fail("PACKAGE_REPLACED should not be called!")
-                else -> fail("Unknown action received")
-            }
-        }
-    }
-}
\ No newline at end of file
+}