Moving manifest initialization to RoboApplication instead of a separate rule

This makes the behavior same as instrumentation test

Bug: 370080120
Test: Presubmit
Flag: EXEMPT test fix
Change-Id: Id4183c91f3951748b657b583fde8860abe55d3a8
This commit is contained in:
Sunny Goyal
2024-10-08 11:00:22 -07:00
parent 67ed920053
commit 6a207fc4f9
18 changed files with 46 additions and 183 deletions
@@ -16,70 +16,19 @@
package com.android.launcher3.util
import android.content.ComponentName
import android.content.ContentResolver
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.ApplicationInfo
import android.content.pm.LauncherActivityInfo
import android.content.pm.LauncherApps
import android.net.Uri
import android.os.Looper
import android.os.Process
import androidx.test.platform.app.InstrumentationRegistry
import java.io.InputStream
import java.util.function.Supplier
import org.mockito.Mockito
import org.mockito.kotlin.whenever
import org.robolectric.RuntimeEnvironment
import org.robolectric.Shadows
object RoboApiWrapper {
fun initialize() {
Shadows.shadowOf(
RuntimeEnvironment.getApplication().getSystemService(LauncherApps::class.java)
)
.addEnabledPackage(
Process.myUserHandle(),
InstrumentationRegistry.getInstrumentation().context.packageName
)
LauncherModelHelper.ACTIVITY_LIST.forEach {
installApp(ComponentName(InstrumentationRegistry.getInstrumentation().context, it))
}
}
private fun installApp(componentName: ComponentName) {
val app = RuntimeEnvironment.getApplication()
val user = Process.myUserHandle()
val pm = Shadows.shadowOf(app.packageManager)
val ai = pm.addActivityIfNotPresent(componentName)
pm.addIntentFilterForActivity(
componentName,
IntentFilter(Intent.ACTION_MAIN).apply { addCategory(Intent.CATEGORY_LAUNCHER) }
)
val li = Mockito.mock(LauncherActivityInfo::class.java)
val appInfo = ApplicationInfo().apply { flags = 0 }
Mockito.doReturn(ai).whenever(li).activityInfo
Mockito.doReturn(appInfo).whenever(li).applicationInfo
Mockito.doReturn(user).whenever(li).user
Mockito.doReturn(1f).whenever(li).loadingProgress
Mockito.doReturn(componentName).whenever(li).componentName
Shadows.shadowOf(app.getSystemService(LauncherApps::class.java)).apply {
addActivity(user, li)
addEnabledPackage(user, componentName.packageName)
setActivityEnabled(user, componentName)
addApplicationInfo(user, componentName.packageName, ai.applicationInfo)
}
}
fun registerInputStream(
contentResolver: ContentResolver,
uri: Uri,
inputStreamSupplier: Supplier<InputStream>
inputStreamSupplier: Supplier<InputStream>,
) {
Shadows.shadowOf(contentResolver).registerInputStreamSupplier(uri, inputStreamSupplier)
}