Bug 1885329 - Add logs to MockLocationUpdatesRule

fenix/125.0
AndiAJ 2 months ago committed by mergify[bot]
parent cf9cd2a86c
commit d62b7a1edf

@ -12,6 +12,7 @@ import android.os.SystemClock
import android.util.Log
import androidx.test.core.app.ApplicationProvider
import org.junit.rules.ExternalResource
import org.mozilla.fenix.helpers.Constants.TAG
import org.mozilla.fenix.helpers.TestHelper.mDevice
import java.util.Date
import kotlin.random.Random
@ -36,15 +37,17 @@ class MockLocationUpdatesRule : ExternalResource() {
}
override fun before() {
Log.i(TAG, "MockLocationUpdatesRule: Trying to enable the mock location setting on the device")
/* ADB command to enable the mock location setting on the device.
* Will not be turned back off due to limitations on knowing its initial state.
*/
Log.i(TAG, "MockLocationUpdatesRule: Trying to execute cmd \"appops set ${appContext.packageName} android:mock_location allow\"")
mDevice.executeShellCommand(
"appops set " +
appContext.packageName +
" android:mock_location allow",
)
Log.i(TAG, "MockLocationUpdatesRule: Executed cmd \"appops set ${appContext.packageName} android:mock_location allow\"")
// To mock locations we need a location provider, so we generate and set it here.
try {
locationManager.addTestProvider(
@ -61,15 +64,18 @@ class MockLocationUpdatesRule : ExternalResource() {
)
} catch (ex: Exception) {
// unstable
Log.w("MockLocationUpdatesRule", "addTestProvider failed")
Log.i(TAG, "MockLocationUpdatesRule: Exception $ex caught, addTestProvider failed")
}
locationManager.setTestProviderEnabled(mockProviderName, true)
Log.i(TAG, "MockLocationUpdatesRule: Enabled the mock location setting on the device")
}
// Cleaning up the location provider after the test.
override fun after() {
Log.i(TAG, "MockLocationUpdatesRule: Trying to clean up the location provider")
locationManager.setTestProviderEnabled(mockProviderName, false)
locationManager.removeTestProvider(mockProviderName)
Log.i(TAG, "MockLocationUpdatesRule: Cleaned up the location provider")
}
/**
@ -78,6 +84,7 @@ class MockLocationUpdatesRule : ExternalResource() {
* @param modifyLocation optional callback for modifying the constructed location before setting it.
*/
fun setMockLocation(modifyLocation: (Location.() -> Unit)? = null) {
Log.i(TAG, "setMockLocation: Trying to set the mock location")
check(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
"MockLocationUpdatesRule is supported only on Android devices " +
"running version >= Build.VERSION_CODES.M"
@ -107,5 +114,6 @@ class MockLocationUpdatesRule : ExternalResource() {
}
locationManager.setTestProviderLocation(mockProviderName, location)
Log.i(TAG, "setMockLocation: The mock location was successfully set")
}
}

Loading…
Cancel
Save