[Satellite Settings] Add a new API to SatelliteRepository
Flag: com.android.internal.telephony.flags.satellite_25q4_apis Bug: b/395813844 Test: atest pass Change-Id: Ife9e370dbcb3694adfd0bfbcc2ec2a742fbc4434
This commit is contained in:
@@ -23,6 +23,7 @@ import android.telephony.satellite.SatelliteModemStateCallback
|
||||
import android.util.Log
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.concurrent.futures.CallbackToFutureAdapter
|
||||
import com.android.internal.telephony.flags.Flags
|
||||
import com.google.common.util.concurrent.Futures.immediateFuture
|
||||
import com.google.common.util.concurrent.ListenableFuture
|
||||
import java.util.concurrent.Executor
|
||||
@@ -40,7 +41,7 @@ import kotlinx.coroutines.flow.flowOn
|
||||
/**
|
||||
* A repository class for interacting with the SatelliteManager API.
|
||||
*/
|
||||
class SatelliteRepository(
|
||||
open class SatelliteRepository(
|
||||
private val context: Context,
|
||||
) {
|
||||
|
||||
@@ -196,6 +197,28 @@ class SatelliteRepository(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A list with application package names which support Satellite service.
|
||||
* e.g. "com.android.settings"
|
||||
*/
|
||||
open fun getSatelliteDataOptimizedApps(): List<String> {
|
||||
if (!Flags.satellite25q4Apis()) {
|
||||
return emptyList()
|
||||
}
|
||||
val satelliteManager: SatelliteManager? =
|
||||
context.getSystemService(SatelliteManager::class.java)
|
||||
if (satelliteManager == null) {
|
||||
Log.d(TAG, "SatelliteManager is null")
|
||||
return emptyList()
|
||||
}
|
||||
try {
|
||||
return satelliteManager.getSatelliteDataOptimizedApps();
|
||||
} catch (e: IllegalStateException) {
|
||||
Log.w(TAG, "IllegalStateException $e")
|
||||
}
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG: String = "SatelliteRepository"
|
||||
|
||||
|
@@ -18,10 +18,12 @@ package com.android.settings.network
|
||||
|
||||
import android.content.Context
|
||||
import android.os.OutcomeReceiver
|
||||
import android.platform.test.annotations.EnableFlags
|
||||
import android.telephony.satellite.SatelliteManager
|
||||
import android.telephony.satellite.SatelliteManager.SatelliteException
|
||||
import android.telephony.satellite.SatelliteModemStateCallback
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import com.android.internal.telephony.flags.Flags
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.google.common.util.concurrent.ListenableFuture
|
||||
import kotlinx.coroutines.flow.first
|
||||
@@ -38,10 +40,10 @@ import org.mockito.Mockito.*
|
||||
import org.mockito.Spy
|
||||
import org.mockito.junit.MockitoJUnit
|
||||
import org.mockito.junit.MockitoRule
|
||||
import org.mockito.kotlin.whenever
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import java.util.concurrent.Executor
|
||||
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class SatelliteRepositoryTest {
|
||||
|
||||
@@ -267,4 +269,35 @@ class SatelliteRepositoryTest {
|
||||
|
||||
assertThat(flow.first()).isFalse()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_SATELLITE_25Q4_APIS)
|
||||
fun getSatelliteDataOptimizedApps_returnPackageNameList() = runBlocking {
|
||||
whenever(
|
||||
mockSatelliteManager.getSatelliteDataOptimizedApps()
|
||||
).thenReturn(
|
||||
listOf(
|
||||
"com.android.settings",
|
||||
"com.android.apps.messaging",
|
||||
"com.android.dialer",
|
||||
"com.android.systemui"
|
||||
)
|
||||
)
|
||||
|
||||
val result = repository.getSatelliteDataOptimizedApps()
|
||||
|
||||
assertThat(result.size == 4).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_SATELLITE_25Q4_APIS)
|
||||
fun getSatelliteDataOptimizedApps_noTelephony_returnEmptyList() = runBlocking {
|
||||
whenever(
|
||||
mockSatelliteManager.getSatelliteDataOptimizedApps()
|
||||
).thenThrow(IllegalStateException("Telephony is null"))
|
||||
|
||||
val result = repository.getSatelliteDataOptimizedApps()
|
||||
|
||||
assertThat(result.isEmpty()).isTrue()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user