content
stringlengths 0
3.9M
| path
stringlengths 4
242
| contentHash
stringlengths 1
10
|
---|---|---|
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.datastore.di
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.core.DataStoreFactory
import androidx.datastore.dataStoreFile
import com.android.geto.core.common.Dispatcher
import com.android.geto.core.common.GetoDispatchers.IO
import com.android.geto.core.common.di.ApplicationScope
import com.android.geto.core.datastore.UserPreferences
import com.android.geto.datastore.UserPreferencesSerializer
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
object DataStoreModule {
@Provides
@Singleton
internal fun providesUserPreferencesDataStore(
@ApplicationContext context: Context,
@Dispatcher(IO) ioDispatcher: CoroutineDispatcher,
@ApplicationScope scope: CoroutineScope,
userPreferencesSerializer: UserPreferencesSerializer,
): DataStore<UserPreferences> = DataStoreFactory.create(
serializer = userPreferencesSerializer,
scope = CoroutineScope(scope.coroutineContext + ioDispatcher),
) {
context.dataStoreFile("user_preferences.pb")
}
}
| Geto/core/datastore/src/main/kotlin/com/android/geto/datastore/di/DataStoreModule.kt | 3802583829 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.datastore
import androidx.datastore.core.DataStore
import com.android.geto.core.datastore.DarkThemeConfigProto
import com.android.geto.core.datastore.ThemeBrandProto
import com.android.geto.core.datastore.UserPreferences
import com.android.geto.core.datastore.copy
import com.android.geto.core.model.DarkThemeConfig
import com.android.geto.core.model.ThemeBrand
import com.android.geto.core.model.UserData
import kotlinx.coroutines.flow.map
import javax.inject.Inject
class GetoPreferencesDataSource @Inject constructor(
private val userPreferences: DataStore<UserPreferences>,
) {
val userData = userPreferences.data.map {
UserData(
themeBrand = when (it.themeBrand) {
null,
ThemeBrandProto.THEME_BRAND_UNSPECIFIED,
ThemeBrandProto.UNRECOGNIZED,
ThemeBrandProto.THEME_BRAND_DEFAULT,
-> ThemeBrand.DEFAULT
ThemeBrandProto.THEME_BRAND_ANDROID -> ThemeBrand.ANDROID
},
darkThemeConfig = when (it.darkThemeConfig) {
null,
DarkThemeConfigProto.DARK_THEME_CONFIG_UNSPECIFIED,
DarkThemeConfigProto.UNRECOGNIZED,
DarkThemeConfigProto.DARK_THEME_CONFIG_FOLLOW_SYSTEM,
-> DarkThemeConfig.FOLLOW_SYSTEM
DarkThemeConfigProto.DARK_THEME_CONFIG_LIGHT -> DarkThemeConfig.LIGHT
DarkThemeConfigProto.DARK_THEME_CONFIG_DARK -> DarkThemeConfig.DARK
},
useDynamicColor = it.useDynamicColor,
useAutoLaunch = it.useAutoLaunch,
)
}
suspend fun setThemeBrand(themeBrand: ThemeBrand) {
userPreferences.updateData {
it.copy {
this.themeBrand = when (themeBrand) {
ThemeBrand.DEFAULT -> ThemeBrandProto.THEME_BRAND_DEFAULT
ThemeBrand.ANDROID -> ThemeBrandProto.THEME_BRAND_ANDROID
}
}
}
}
suspend fun setDynamicColorPreference(useDynamicColor: Boolean) {
userPreferences.updateData {
it.copy { this.useDynamicColor = useDynamicColor }
}
}
suspend fun setDarkThemeConfig(darkThemeConfig: DarkThemeConfig) {
userPreferences.updateData {
it.copy {
this.darkThemeConfig = when (darkThemeConfig) {
DarkThemeConfig.FOLLOW_SYSTEM -> DarkThemeConfigProto.DARK_THEME_CONFIG_FOLLOW_SYSTEM
DarkThemeConfig.LIGHT -> DarkThemeConfigProto.DARK_THEME_CONFIG_LIGHT
DarkThemeConfig.DARK -> DarkThemeConfigProto.DARK_THEME_CONFIG_DARK
}
}
}
}
suspend fun setAutoLaunchPreference(useAutoLaunch: Boolean) {
userPreferences.updateData {
it.copy { this.useAutoLaunch = useAutoLaunch }
}
}
}
| Geto/core/datastore/src/main/kotlin/com/android/geto/datastore/GetoPreferencesDataSource.kt | 3600694345 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.common.di
import com.android.geto.core.common.Dispatcher
import com.android.geto.core.common.GetoDispatchers.Default
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import javax.inject.Qualifier
import javax.inject.Singleton
@Retention(AnnotationRetention.RUNTIME)
@Qualifier
annotation class ApplicationScope
@Module
@InstallIn(SingletonComponent::class)
internal object CoroutineScopesModule {
@Provides
@Singleton
@ApplicationScope
fun providesCoroutineScope(
@Dispatcher(Default) dispatcher: CoroutineDispatcher,
): CoroutineScope = CoroutineScope(SupervisorJob() + dispatcher)
}
| Geto/core/common/src/main/kotlin/com/android/geto/core/common/di/CoroutineScopesModule.kt | 2944454166 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.common.di
import com.android.geto.core.common.Dispatcher
import com.android.geto.core.common.GetoDispatchers
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
@Module
@InstallIn(SingletonComponent::class)
object DispatchersModule {
@Provides
@Dispatcher(GetoDispatchers.IO)
fun providesIODispatcher(): CoroutineDispatcher = Dispatchers.IO
@Provides
@Dispatcher(GetoDispatchers.Default)
fun providesDefaultDispatcher(): CoroutineDispatcher = Dispatchers.Default
}
| Geto/core/common/src/main/kotlin/com/android/geto/core/common/di/DispatchersModule.kt | 3033615832 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.common
import javax.inject.Qualifier
import kotlin.annotation.AnnotationRetention.RUNTIME
@Qualifier
@Retention(RUNTIME)
annotation class Dispatcher(val getoDispatcher: GetoDispatchers)
enum class GetoDispatchers {
Default,
IO,
}
| Geto/core/common/src/main/kotlin/com/android/geto/core/common/GetoDispatcher.kt | 3768007085 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.model
data class UserData(
val themeBrand: ThemeBrand,
val darkThemeConfig: DarkThemeConfig,
val useDynamicColor: Boolean,
val useAutoLaunch: Boolean,
)
| Geto/core/model/src/main/kotlin/com/android/geto/core/model/UserData.kt | 4191764517 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.model
enum class DarkThemeConfig(val title: String) {
FOLLOW_SYSTEM("Follow System"),
LIGHT("Light"),
DARK("Dark"),
}
| Geto/core/model/src/main/kotlin/com/android/geto/core/model/DarkThemeConfig.kt | 3882911336 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.model
enum class ThemeBrand(val title: String) {
DEFAULT("Default"),
ANDROID("Android"),
}
| Geto/core/model/src/main/kotlin/com/android/geto/core/model/ThemeBrand.kt | 1868104367 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.model
import android.graphics.Bitmap
data class TargetShortcutInfoCompat(
val id: String,
val icon: Bitmap? = null,
val shortLabel: String,
val longLabel: String,
)
| Geto/core/model/src/main/kotlin/com/android/geto/core/model/TargetShortcutInfoCompat.kt | 338543926 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.model
data class SecureSetting(
val settingType: SettingType,
val id: Long? = null,
val name: String? = null,
val value: String? = null,
)
| Geto/core/model/src/main/kotlin/com/android/geto/core/model/SecureSetting.kt | 2628784854 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.model
import android.graphics.drawable.Drawable
data class TargetApplicationInfo(
val flags: Int,
val icon: Drawable? = null,
val packageName: String,
val label: String,
)
| Geto/core/model/src/main/kotlin/com/android/geto/core/model/TargetApplicationInfo.kt | 1272513374 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.model
data class AppSetting(
val id: Int? = null,
val enabled: Boolean,
val settingType: SettingType,
val packageName: String,
val label: String,
val key: String,
val valueOnLaunch: String,
val valueOnRevert: String,
)
enum class SettingType(val label: String) {
SYSTEM("System"),
SECURE("Secure"),
GLOBAL("Global"),
}
| Geto/core/model/src/main/kotlin/com/android/geto/core/model/AppSetting.kt | 1888366891 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.repository
import com.android.geto.core.data.testdoubles.TestShortcutManagerCompatWrapper
import com.android.geto.core.model.TargetShortcutInfoCompat
import org.junit.Before
import org.junit.Test
import kotlin.test.assertIs
class ShortcutRepositoryTest {
private val shortcutManagerCompatWrapper = TestShortcutManagerCompatWrapper()
private lateinit var subject: ShortcutRepository
private val shortcuts = List(10) {
TargetShortcutInfoCompat(
id = "com.android.geto",
shortLabel = "Geto",
longLabel = "Geto",
)
}
@Before
fun setup() {
subject = DefaultShortcutRepository(
shortcutManagerCompatWrapper = shortcutManagerCompatWrapper,
)
}
@Test
fun requestPinShortcut_isSupportedLauncher() {
shortcutManagerCompatWrapper.setRequestPinShortcutSupported(true)
shortcutManagerCompatWrapper.setRequestPinShortcut(true)
assertIs<ShortcutResult.SupportedLauncher>(
subject.requestPinShortcut(
packageName = "com.android.geto",
appName = "Geto",
targetShortcutInfoCompat = TargetShortcutInfoCompat(
id = "com.android.geto",
shortLabel = "Geto",
longLabel = "Geto",
),
),
)
}
@Test
fun requestPinShortcut_isUnSupportedLauncher() {
shortcutManagerCompatWrapper.setRequestPinShortcutSupported(false)
assertIs<ShortcutResult.UnsupportedLauncher>(
subject.requestPinShortcut(
packageName = "com.android.geto",
appName = "Geto",
targetShortcutInfoCompat = TargetShortcutInfoCompat(
id = "com.android.geto",
shortLabel = "Geto",
longLabel = "Geto",
),
),
)
}
@Test
fun updateRequestPinShortcut_isShortcutUpdateImmutableShortcuts() {
shortcutManagerCompatWrapper.setUpdateImmutableShortcuts(true)
shortcutManagerCompatWrapper.setShortcuts(shortcuts)
assertIs<ShortcutResult.ShortcutUpdateImmutableShortcuts>(
subject.updateRequestPinShortcut(
packageName = "com.android.geto",
appName = "Geto",
targetShortcutInfoCompat = TargetShortcutInfoCompat(
id = "com.android.geto",
shortLabel = "Geto",
longLabel = "Geto",
),
),
)
}
@Test
fun updateRequestPinShortcut_isShortcutUpdateSuccess() {
shortcutManagerCompatWrapper.setUpdateImmutableShortcuts(false)
shortcutManagerCompatWrapper.setRequestPinShortcutSupported(true)
shortcutManagerCompatWrapper.setShortcuts(shortcuts)
assertIs<ShortcutResult.ShortcutUpdateSuccess>(
subject.updateRequestPinShortcut(
packageName = "com.android.geto",
appName = "Geto",
targetShortcutInfoCompat = TargetShortcutInfoCompat(
id = "com.android.geto",
shortLabel = "Geto",
longLabel = "Geto",
),
),
)
}
@Test
fun updateRequestPinShortcut_isShortcutUpdateFailed() {
shortcutManagerCompatWrapper.setUpdateImmutableShortcuts(false)
shortcutManagerCompatWrapper.setRequestPinShortcutSupported(false)
shortcutManagerCompatWrapper.setShortcuts(shortcuts)
assertIs<ShortcutResult.ShortcutUpdateFailed>(
subject.updateRequestPinShortcut(
packageName = "com.android.geto",
appName = "Geto",
targetShortcutInfoCompat = TargetShortcutInfoCompat(
id = "com.android.geto",
shortLabel = "Geto",
longLabel = "Geto",
),
),
)
}
@Test
fun getShortcut_isNoShortcutFound() {
shortcutManagerCompatWrapper.setRequestPinShortcutSupported(true)
shortcutManagerCompatWrapper.setShortcuts(shortcuts)
assertIs<ShortcutResult.NoShortcutFound>(subject.getShortcut("com.android.sample"))
}
@Test
fun getShortcut_isShortcutFound() {
shortcutManagerCompatWrapper.setRequestPinShortcutSupported(true)
shortcutManagerCompatWrapper.setShortcuts(shortcuts)
assertIs<ShortcutResult.ShortcutFound>(subject.getShortcut("com.android.geto"))
}
}
| Geto/core/data/src/test/kotlin/com/android/geto/core/data/repository/ShortcutRepositoryTest.kt | 1121916181 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.repository
import com.android.geto.core.data.testdoubles.TestClipboardManagerWrapper
import org.junit.Before
import org.junit.Test
import kotlin.test.assertIs
class ClipboardRepositoryTest {
private lateinit var clipboardManagerWrapper: TestClipboardManagerWrapper
private lateinit var subject: DefaultClipboardRepository
@Before
fun setup() {
clipboardManagerWrapper = TestClipboardManagerWrapper()
subject = DefaultClipboardRepository(
clipboardManagerWrapper = clipboardManagerWrapper,
)
}
@Test
fun setPrimaryClip_isNoResult() {
clipboardManagerWrapper.setAtLeastApi32(true)
assertIs<ClipboardResult.NoResult>(subject.setPrimaryClip(label = "label", text = "text"))
}
@Test
fun setPrimaryClip_isNotify() {
clipboardManagerWrapper.setAtLeastApi32(false)
assertIs<ClipboardResult.Notify>(subject.setPrimaryClip(label = "label", text = "text"))
}
}
| Geto/core/data/src/test/kotlin/com/android/geto/core/data/repository/ClipboardRepositoryTest.kt | 3327227423 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.repository
import com.android.geto.core.data.testdoubles.TestSecureSettingsWrapper
import com.android.geto.core.model.AppSetting
import com.android.geto.core.model.SecureSetting
import com.android.geto.core.model.SettingType
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue
class SecureSettingsRepositoryTest {
private val testDispatcher = StandardTestDispatcher()
private lateinit var secureSettingsPermissionWrapper: TestSecureSettingsWrapper
private lateinit var subject: SecureSettingsRepository
@Before
fun setup() {
secureSettingsPermissionWrapper = TestSecureSettingsWrapper()
subject = DefaultSecureSettingsRepository(secureSettingsPermissionWrapper)
}
@Test
fun applyGlobalSettings() = runTest(testDispatcher) {
secureSettingsPermissionWrapper.setWriteSecureSettings(true)
val appSettings = List(5) { index ->
AppSetting(
enabled = true,
settingType = SettingType.GLOBAL,
packageName = "com.android.geto",
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
assertTrue(subject.applySecureSettings(appSettings))
}
@Test
fun applySecureSettings() = runTest(testDispatcher) {
secureSettingsPermissionWrapper.setWriteSecureSettings(true)
val appSettings = List(5) { index ->
AppSetting(
enabled = true,
settingType = SettingType.SECURE,
packageName = "com.android.geto",
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
assertTrue(subject.applySecureSettings(appSettings))
}
@Test
fun applySystemSettings() = runTest(testDispatcher) {
secureSettingsPermissionWrapper.setWriteSecureSettings(true)
val appSettings = List(5) { index ->
AppSetting(
enabled = true,
settingType = SettingType.SYSTEM,
packageName = "com.android.geto",
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
assertTrue(subject.applySecureSettings(appSettings))
}
@Test
fun revertGlobalSettings() = runTest(testDispatcher) {
secureSettingsPermissionWrapper.setWriteSecureSettings(true)
val appSettings = List(5) { index ->
AppSetting(
enabled = true,
settingType = SettingType.GLOBAL,
packageName = "com.android.geto",
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
assertTrue(subject.revertSecureSettings(appSettings))
}
@Test
fun revertSecureSettings() = runTest(testDispatcher) {
secureSettingsPermissionWrapper.setWriteSecureSettings(true)
val appSettings = List(5) { index ->
AppSetting(
enabled = true,
settingType = SettingType.SECURE,
packageName = "com.android.geto",
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
assertTrue(subject.revertSecureSettings(appSettings))
}
@Test
fun revertSystemSettings() = runTest(testDispatcher) {
secureSettingsPermissionWrapper.setWriteSecureSettings(true)
val appSettings = List(5) { index ->
AppSetting(
enabled = true,
settingType = SettingType.SYSTEM,
packageName = "com.android.geto",
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
assertTrue(subject.revertSecureSettings(appSettings))
}
@Test
fun applyGlobalSettings_isFailure() = runTest(testDispatcher) {
secureSettingsPermissionWrapper.setWriteSecureSettings(false)
val appSettings = List(5) { index ->
AppSetting(
enabled = true,
settingType = SettingType.GLOBAL,
packageName = "com.android.geto",
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
assertFailsWith<SecurityException> { subject.applySecureSettings(appSettings) }
}
@Test
fun applySecureSettings_isFailure() = runTest(testDispatcher) {
secureSettingsPermissionWrapper.setWriteSecureSettings(false)
val appSettings = List(5) { index ->
AppSetting(
enabled = true,
settingType = SettingType.SECURE,
packageName = "com.android.geto",
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
assertFailsWith<SecurityException> { subject.applySecureSettings(appSettings) }
}
@Test
fun applySystemSettings_isFailure() = runTest(testDispatcher) {
secureSettingsPermissionWrapper.setWriteSecureSettings(false)
val appSettings = List(5) { index ->
AppSetting(
enabled = true,
settingType = SettingType.SYSTEM,
packageName = "com.android.geto",
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
assertFailsWith<SecurityException> { subject.applySecureSettings(appSettings) }
}
@Test
fun revertGlobalSettings_isFailure() = runTest(testDispatcher) {
secureSettingsPermissionWrapper.setWriteSecureSettings(false)
val appSettings = List(5) { index ->
AppSetting(
enabled = true,
settingType = SettingType.GLOBAL,
packageName = "com.android.geto",
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
assertFailsWith<SecurityException> { subject.revertSecureSettings(appSettings) }
}
@Test
fun revertSecureSettings_isFailure() = runTest(testDispatcher) {
secureSettingsPermissionWrapper.setWriteSecureSettings(false)
val appSettings = List(5) { index ->
AppSetting(
enabled = true,
settingType = SettingType.SECURE,
packageName = "com.android.geto",
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
assertFailsWith<SecurityException> { subject.revertSecureSettings(appSettings) }
}
@Test
fun revertSystemSettings_isFailure() = runTest(testDispatcher) {
secureSettingsPermissionWrapper.setWriteSecureSettings(false)
val appSettings = List(5) { index ->
AppSetting(
enabled = true,
settingType = SettingType.SYSTEM,
packageName = "com.android.geto",
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
assertFailsWith<SecurityException> { subject.revertSecureSettings(appSettings) }
}
@Test
fun getSecureSettingsBySettingTypeSystemName_isNotEmpty() = runTest(testDispatcher) {
val secureSettings = List(5) { index ->
SecureSetting(
settingType = SettingType.SYSTEM,
id = index.toLong(),
name = "SecureSetting",
value = "$index",
)
}
secureSettingsPermissionWrapper.setSecureSettings(secureSettings)
assertTrue(
subject.getSecureSettingsByName(
settingType = SettingType.SYSTEM,
text = "SecureSetting",
).isNotEmpty(),
)
}
@Test
fun getSecureSettingsBySettingTypeSecureName_isNotEmpty() = runTest(testDispatcher) {
val secureSettings = List(5) { index ->
SecureSetting(
settingType = SettingType.SECURE,
id = index.toLong(),
name = "SecureSetting",
value = "$index",
)
}
secureSettingsPermissionWrapper.setSecureSettings(secureSettings)
assertTrue(
subject.getSecureSettingsByName(
settingType = SettingType.SECURE,
text = "SecureSetting",
).isNotEmpty(),
)
}
@Test
fun getSecureSettingsBySettingTypeGlobalName_isNotEmpty() = runTest(testDispatcher) {
val secureSettings = List(5) { index ->
SecureSetting(
settingType = SettingType.GLOBAL,
id = index.toLong(),
name = "SecureSetting",
value = "$index",
)
}
secureSettingsPermissionWrapper.setSecureSettings(secureSettings)
assertTrue(
subject.getSecureSettingsByName(
settingType = SettingType.GLOBAL,
text = "SecureSetting",
).isNotEmpty(),
)
}
@Test
fun getSecureSettingsBySettingTypeSystemName_isEmpty() = runTest(testDispatcher) {
val secureSettings = List(5) { index ->
SecureSetting(
settingType = SettingType.SYSTEM,
id = index.toLong(),
name = "SecureSetting",
value = "$index",
)
}
secureSettingsPermissionWrapper.setSecureSettings(secureSettings)
assertTrue(
subject.getSecureSettingsByName(
settingType = SettingType.SYSTEM,
text = "text",
).isEmpty(),
)
}
@Test
fun getSecureSettingsBySettingTypeSecureName_isEmpty() = runTest(testDispatcher) {
val secureSettings = List(5) { index ->
SecureSetting(
settingType = SettingType.SECURE,
id = index.toLong(),
name = "SecureSetting",
value = "$index",
)
}
secureSettingsPermissionWrapper.setSecureSettings(secureSettings)
assertTrue(
subject.getSecureSettingsByName(
settingType = SettingType.SECURE,
text = "text",
).isEmpty(),
)
}
@Test
fun getSecureSettingsBySettingTypeGlobalName_isEmpty() = runTest(testDispatcher) {
val secureSettings = List(5) { index ->
SecureSetting(
settingType = SettingType.GLOBAL,
id = index.toLong(),
name = "SecureSetting",
value = "$index",
)
}
secureSettingsPermissionWrapper.setSecureSettings(secureSettings)
assertTrue(
subject.getSecureSettingsByName(
settingType = SettingType.GLOBAL,
text = "text",
).isEmpty(),
)
}
}
| Geto/core/data/src/test/kotlin/com/android/geto/core/data/repository/SecureSettingsRepositoryTest.kt | 2007405253 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.repository
import com.android.geto.core.datastore.test.testUserPreferencesDataStore
import com.android.geto.datastore.GetoPreferencesDataSource
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import org.junit.Before
import org.junit.Rule
import org.junit.rules.TemporaryFolder
class UserDataRepositoryTest {
private val testScope = TestScope(UnconfinedTestDispatcher())
private lateinit var subject: DefaultUserDataRepository
private lateinit var getoPreferencesDataSource: GetoPreferencesDataSource
@get:Rule
val tmpFolder: TemporaryFolder = TemporaryFolder.builder().assureDeletion().build()
@Before
fun setup() {
getoPreferencesDataSource = GetoPreferencesDataSource(
tmpFolder.testUserPreferencesDataStore(testScope),
)
subject = DefaultUserDataRepository(
getoPreferencesDataSource = getoPreferencesDataSource,
)
}
// @Test
// fun userDataRepository_set_theme_brand_delegates_to_geto_preferences() =
// testScope.runTest {
// subject.setThemeBrand(ThemeBrand.ANDROID)
//
// assertEquals(
// ThemeBrand.ANDROID,
// subject.userData.map { it.themeBrand }.first(),
// )
// assertEquals(
// ThemeBrand.ANDROID,
// getoPreferencesDataSource.userData.map { it.themeBrand }.first(),
// )
// }
//
// @Test
// fun userDataRepository_set_dynamic_color_delegates_to_geto_preferences() =
// testScope.runTest {
// subject.setDynamicColorPreference(true)
//
// assertEquals(
// true,
// subject.userData.map { it.useDynamicColor }.first(),
// )
// assertEquals(
// true,
// getoPreferencesDataSource.userData.map { it.useDynamicColor }.first(),
// )
// }
//
// @Test
// fun userDataRepository_set_dark_theme_config_delegates_to_geto_preferences() =
// testScope.runTest {
// subject.setDarkThemeConfig(DarkThemeConfig.DARK)
//
// assertEquals(
// DarkThemeConfig.DARK,
// subject.userData.map { it.darkThemeConfig }.first(),
// )
// assertEquals(
// DarkThemeConfig.DARK,
// getoPreferencesDataSource.userData.map { it.darkThemeConfig }.first(),
// )
// }
}
| Geto/core/data/src/test/kotlin/com/android/geto/core/data/repository/UserDataRepositoryTest.kt | 896492730 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.repository
import com.android.geto.core.data.testdoubles.TestAppSettingsDao
import com.android.geto.core.database.model.AppSettingEntity
import com.android.geto.core.database.model.asExternalModel
import com.android.geto.core.model.AppSetting
import com.android.geto.core.model.SettingType
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runTest
import org.junit.Before
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class AppSettingsRepositoryTest {
private lateinit var appSettingsDao: TestAppSettingsDao
private lateinit var subject: AppSettingsRepository
@Before
fun setup() {
appSettingsDao = TestAppSettingsDao()
subject = DefaultAppSettingsRepository(appSettingsDao = appSettingsDao)
}
@Test
fun upsertAppSetting() = runTest {
val appSetting = AppSetting(
id = 0,
enabled = true,
settingType = SettingType.SECURE,
packageName = "com.android.geto",
label = "Geto",
key = "Geto",
valueOnLaunch = "0",
valueOnRevert = "1",
)
subject.upsertAppSetting(appSetting)
assertTrue {
appSetting in subject.getAppSettingsByPackageName("com.android.geto").first()
}
}
@Test
fun deleteAppSetting() = runTest {
val collectJob = launch(UnconfinedTestDispatcher()) { subject.appSettings.collect() }
val appSettingEntities = List(10) { index ->
AppSettingEntity(
id = index,
enabled = false,
settingType = SettingType.GLOBAL,
packageName = "com.android.geto",
label = "Geto",
key = "Geto",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
appSettingsDao.upsertAppSettingEntities(appSettingEntities)
subject.deleteAppSetting(appSettingEntities.first().asExternalModel())
assertTrue { subject.appSettings.first().size == appSettingEntities.size - 1 }
collectJob.cancel()
}
@Test
fun deleteAppSettingsByPackageName() = runTest {
val collectJob = launch(UnconfinedTestDispatcher()) { subject.appSettings.collect() }
val oldAppSettingEntities = List(10) { index ->
AppSettingEntity(
id = index,
enabled = false,
settingType = SettingType.GLOBAL,
packageName = "com.android.geto",
label = "Geto",
key = "Geto",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
val newAppSettingEntities = List(10) { index ->
AppSettingEntity(
id = index + 11,
enabled = false,
settingType = SettingType.GLOBAL,
packageName = "com.android.sample",
label = "Sample",
key = "Sample",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
appSettingsDao.upsertAppSettingEntities(oldAppSettingEntities + newAppSettingEntities)
subject.deleteAppSettingsByPackageName(listOf("com.android.geto"))
assertFalse {
subject.appSettings.first()
.containsAll(oldAppSettingEntities.map(AppSettingEntity::asExternalModel))
}
assertTrue {
subject.appSettings.first()
.containsAll(newAppSettingEntities.map(AppSettingEntity::asExternalModel))
}
collectJob.cancel()
}
@Test
fun getAppSettingsByPackageName() = runTest {
val appSettingEntities = List(10) { index ->
AppSettingEntity(
id = index,
enabled = false,
settingType = SettingType.GLOBAL,
packageName = "com.android.geto",
label = "Geto",
key = "Geto",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
appSettingsDao.upsertAppSettingEntities(appSettingEntities)
assertTrue {
subject.getAppSettingsByPackageName("com.android.geto").first()
.containsAll(appSettingEntities.map(AppSettingEntity::asExternalModel))
}
}
}
| Geto/core/data/src/test/kotlin/com/android/geto/core/data/repository/AppSettingsRepositoryTest.kt | 2679969369 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.repository
import com.android.geto.core.data.testdoubles.TestPackageManagerWrapper
import com.android.geto.core.model.TargetApplicationInfo
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.assertTrue
class PackageRepositoryTest {
private lateinit var packageManagerWrapper: TestPackageManagerWrapper
private lateinit var subject: PackageRepository
private val testDispatcher = StandardTestDispatcher()
@Before
fun setup() {
packageManagerWrapper = TestPackageManagerWrapper()
subject = DefaultPackageRepository(
packageManagerWrapper = packageManagerWrapper,
ioDispatcher = testDispatcher,
)
}
@Test
fun getInstalledApplications_isNotEmpty() = runTest(testDispatcher) {
val installedApplications = List(20) { index ->
TargetApplicationInfo(
flags = 0,
packageName = "com.android.geto$index",
label = "Geto $index",
)
}
packageManagerWrapper.setInstalledApplications(installedApplications)
assertTrue(subject.getInstalledApplications().isNotEmpty())
}
@Test
fun getInstalledApplications_isEmpty() = runTest(testDispatcher) {
val installedApplications = List(20) { index ->
TargetApplicationInfo(
flags = 1,
packageName = "com.android.geto$index",
label = "Geto $index",
)
}
packageManagerWrapper.setInstalledApplications(installedApplications)
assertTrue(subject.getInstalledApplications().isEmpty())
}
@Test
fun getApplicationIcon_isNull() = runTest(testDispatcher) {
val installedApplications = List(20) { index ->
TargetApplicationInfo(
flags = 0,
packageName = "com.android.geto$index",
label = "Geto $index",
)
}
packageManagerWrapper.setInstalledApplications(installedApplications)
assertNull(subject.getApplicationIcon(""))
}
@Test
fun getApplicationIcon_isNotNull() = runTest(testDispatcher) {
val installedApplications = List(20) { index ->
TargetApplicationInfo(
flags = 0,
packageName = "com.android.geto$index",
label = "Geto $index",
)
}
packageManagerWrapper.setInstalledApplications(installedApplications)
assertNotNull(subject.getApplicationIcon("com.android.geto1"))
}
@Test
fun getLaunchIntentForPackage_isNull() = runTest(testDispatcher) {
val installedApplications = List(20) { index ->
TargetApplicationInfo(
flags = 0,
packageName = "com.android.geto$index",
label = "Geto $index",
)
}
packageManagerWrapper.setInstalledApplications(installedApplications)
assertNull(subject.getLaunchIntentForPackage(""))
}
@Test
fun getLaunchIntentForPackage_isNotNull() = runTest(testDispatcher) {
val installedApplications = List(20) { index ->
TargetApplicationInfo(
flags = 0,
packageName = "com.android.geto$index",
label = "Geto $index",
)
}
packageManagerWrapper.setInstalledApplications(installedApplications)
assertNotNull(subject.getLaunchIntentForPackage("com.android.geto1"))
}
}
| Geto/core/data/src/test/kotlin/com/android/geto/core/data/repository/PackageRepositoryTest.kt | 3023883844 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.testdoubles
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import com.android.geto.core.model.TargetApplicationInfo
import com.android.geto.core.packagemanager.PackageManagerWrapper
class TestPackageManagerWrapper : PackageManagerWrapper {
private var _installedApplications = emptyList<TargetApplicationInfo>()
override fun getInstalledApplications(): List<TargetApplicationInfo> {
return _installedApplications
}
override fun getApplicationIcon(packageName: String): Drawable {
return if (packageName in _installedApplications.map { it.packageName }) ColorDrawable() else throw PackageManager.NameNotFoundException()
}
override fun getLaunchIntentForPackage(packageName: String): Intent? {
return if (packageName in _installedApplications.map { it.packageName }) Intent() else null
}
fun setInstalledApplications(value: List<TargetApplicationInfo>) {
_installedApplications = value
}
}
| Geto/core/data/src/test/kotlin/com/android/geto/core/data/testdoubles/TestPackageManagerWrapper.kt | 3626766474 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.testdoubles
import com.android.geto.core.model.TargetShortcutInfoCompat
import com.android.geto.core.shortcutmanager.ShortcutManagerCompatWrapper
class TestShortcutManagerCompatWrapper : ShortcutManagerCompatWrapper {
private var requestPinShortcutSupported = false
private var requestPinShortcut = false
private var updateImmutableShortcuts = false
private var targetShortcutInfoCompats = emptyList<TargetShortcutInfoCompat>()
override fun isRequestPinShortcutSupported(): Boolean {
return requestPinShortcutSupported
}
override fun requestPinShortcut(
packageName: String,
appName: String,
targetShortcutInfoCompat: TargetShortcutInfoCompat,
): Boolean {
return requestPinShortcut
}
override fun updateShortcuts(
packageName: String,
appName: String,
targetShortcutInfoCompat: TargetShortcutInfoCompat,
): Boolean {
return if (updateImmutableShortcuts) {
throw IllegalArgumentException()
} else {
requestPinShortcutSupported
}
}
override fun getShortcuts(matchFlags: Int): List<TargetShortcutInfoCompat> {
return targetShortcutInfoCompats
}
fun setRequestPinShortcutSupported(value: Boolean) {
requestPinShortcutSupported = value
}
fun setRequestPinShortcut(value: Boolean) {
requestPinShortcut = value
}
fun setShortcuts(value: List<TargetShortcutInfoCompat>) {
targetShortcutInfoCompats = value
}
fun setUpdateImmutableShortcuts(value: Boolean) {
updateImmutableShortcuts = value
}
}
| Geto/core/data/src/test/kotlin/com/android/geto/core/data/testdoubles/TestShortcutManagerCompatWrapper.kt | 4181122610 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.testdoubles
import com.android.geto.core.packagemanager.ClipboardManagerWrapper
class TestClipboardManagerWrapper : ClipboardManagerWrapper {
private var _atLeastApi32 = false
override val atLeastApi32
get() = _atLeastApi32
override fun setPrimaryClip(label: String, text: String) {}
fun setAtLeastApi32(value: Boolean) {
_atLeastApi32 = value
}
}
| Geto/core/data/src/test/kotlin/com/android/geto/core/data/testdoubles/TestClipboardManagerWrapper.kt | 378798712 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.testdoubles
import com.android.geto.core.model.SecureSetting
import com.android.geto.core.model.SettingType
import com.android.geto.core.securesettings.SecureSettingsWrapper
class TestSecureSettingsWrapper : SecureSettingsWrapper {
private var writeSecureSettings = false
private var secureSettings = emptyList<SecureSetting>()
override suspend fun canWriteSecureSettings(
settingType: SettingType,
key: String,
value: String,
): Boolean {
return if (!writeSecureSettings) throw SecurityException() else true
}
override suspend fun getSecureSettings(settingType: SettingType): List<SecureSetting> {
return secureSettings
}
fun setWriteSecureSettings(value: Boolean) {
writeSecureSettings = value
}
fun setSecureSettings(value: List<SecureSetting>) {
secureSettings = value
}
}
| Geto/core/data/src/test/kotlin/com/android/geto/core/data/testdoubles/TestSecureSettingsWrapper.kt | 767352069 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.testdoubles
import com.android.geto.core.database.dao.AppSettingsDao
import com.android.geto.core.database.model.AppSettingEntity
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.map
class TestAppSettingsDao : AppSettingsDao {
private val _appSettingEntitiesFlow = MutableSharedFlow<List<AppSettingEntity>>(
replay = 1,
onBufferOverflow = BufferOverflow.DROP_OLDEST,
)
private val currentAppSettingEntities get() = _appSettingEntitiesFlow.replayCache.firstOrNull() ?: emptyList()
override suspend fun upsertAppSettingEntity(entity: AppSettingEntity) {
_appSettingEntitiesFlow.tryEmit((currentAppSettingEntities + entity).distinct())
}
override suspend fun deleteAppSettingEntity(entity: AppSettingEntity) {
_appSettingEntitiesFlow.tryEmit(currentAppSettingEntities - entity)
}
override fun getAppSettingEntities(): Flow<List<AppSettingEntity>> {
return _appSettingEntitiesFlow.asSharedFlow()
}
override suspend fun deleteAppSettingEntitiesByPackageName(packageNames: List<String>) {
_appSettingEntitiesFlow.tryEmit(currentAppSettingEntities.filterNot { it.packageName in packageNames })
}
override suspend fun upsertAppSettingEntities(entities: List<AppSettingEntity>) {
_appSettingEntitiesFlow.tryEmit((currentAppSettingEntities + entities).distinct())
}
override fun getAppSettingEntitiesByPackageName(packageName: String): Flow<List<AppSettingEntity>> {
return _appSettingEntitiesFlow.map { entities ->
entities.filter { it.packageName == packageName }
}
}
}
| Geto/core/data/src/test/kotlin/com/android/geto/core/data/testdoubles/TestAppSettingsDao.kt | 2789481819 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.model
import com.android.geto.core.database.model.asEntity
import com.android.geto.core.model.AppSetting
import com.android.geto.core.model.SettingType
import org.junit.Test
import kotlin.test.assertEquals
class AppSettingEntityTest {
@Test
fun appSetting_asEntity() {
val appSetting = AppSetting(
id = 0,
enabled = false,
settingType = SettingType.SECURE,
packageName = "com.android.geto",
label = "Geto",
key = "Geto",
valueOnLaunch = "0",
valueOnRevert = "1",
)
val entity = appSetting.asEntity()
assertEquals(0, entity.id)
assertEquals(false, entity.enabled)
assertEquals(SettingType.SECURE, entity.settingType)
assertEquals("com.android.geto", entity.packageName)
assertEquals("Geto", entity.label)
assertEquals("Geto", entity.key)
assertEquals("0", entity.valueOnLaunch)
assertEquals("1", entity.valueOnRevert)
}
}
| Geto/core/data/src/test/kotlin/com/android/geto/core/data/model/AppSettingEntityTest.kt | 3297148142 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.repository
import com.android.geto.core.packagemanager.ClipboardManagerWrapper
import javax.inject.Inject
internal class DefaultClipboardRepository @Inject constructor(
private val clipboardManagerWrapper: ClipboardManagerWrapper,
) : ClipboardRepository {
override fun setPrimaryClip(label: String, text: String): ClipboardResult {
clipboardManagerWrapper.setPrimaryClip(label = label, text = text)
return if (clipboardManagerWrapper.atLeastApi32) {
ClipboardResult.NoResult
} else {
ClipboardResult.Notify(
text,
)
}
}
}
| Geto/core/data/src/main/kotlin/com/android/geto/core/data/repository/DefaultClipboardRepository.kt | 365132901 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.repository
import com.android.geto.core.model.DarkThemeConfig
import com.android.geto.core.model.ThemeBrand
import com.android.geto.core.model.UserData
import kotlinx.coroutines.flow.Flow
interface UserDataRepository {
val userData: Flow<UserData>
suspend fun setThemeBrand(themeBrand: ThemeBrand)
suspend fun setDarkThemeConfig(darkThemeConfig: DarkThemeConfig)
suspend fun setDynamicColorPreference(useDynamicColor: Boolean)
suspend fun setAutoLaunchPreference(useAutoLaunch: Boolean)
}
| Geto/core/data/src/main/kotlin/com/android/geto/core/data/repository/UserDataRepository.kt | 1903692272 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.repository
import com.android.geto.core.model.AppSetting
import com.android.geto.core.model.SecureSetting
import com.android.geto.core.model.SettingType
import com.android.geto.core.securesettings.SecureSettingsWrapper
import javax.inject.Inject
internal class DefaultSecureSettingsRepository @Inject constructor(
private val secureSettingsWrapper: SecureSettingsWrapper,
) : SecureSettingsRepository {
override suspend fun applySecureSettings(appSettings: List<AppSetting>): Boolean {
return appSettings.all { appSetting ->
secureSettingsWrapper.canWriteSecureSettings(
settingType = appSetting.settingType,
key = appSetting.key,
value = appSetting.valueOnLaunch,
)
}
}
override suspend fun revertSecureSettings(appSettings: List<AppSetting>): Boolean {
return appSettings.all { appSetting ->
secureSettingsWrapper.canWriteSecureSettings(
settingType = appSetting.settingType,
key = appSetting.key,
value = appSetting.valueOnRevert,
)
}
}
override suspend fun getSecureSettings(settingType: SettingType): List<SecureSetting> {
return secureSettingsWrapper.getSecureSettings(settingType)
}
override suspend fun getSecureSettingsByName(
settingType: SettingType,
text: String,
): List<SecureSetting> {
return secureSettingsWrapper.getSecureSettings(settingType)
.filter { it.name!!.contains(text) }.take(20)
}
}
| Geto/core/data/src/main/kotlin/com/android/geto/core/data/repository/DefaultSecureSettingsRepository.kt | 1262781774 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.repository
import com.android.geto.core.model.TargetShortcutInfoCompat
interface ShortcutRepository {
fun requestPinShortcut(
packageName: String,
appName: String,
targetShortcutInfoCompat: TargetShortcutInfoCompat,
): ShortcutResult
fun updateRequestPinShortcut(
packageName: String,
appName: String,
targetShortcutInfoCompat: TargetShortcutInfoCompat,
): ShortcutResult
fun getShortcut(id: String): ShortcutResult
}
sealed interface ShortcutResult {
data object UnsupportedLauncher : ShortcutResult
data object SupportedLauncher : ShortcutResult
data object IDNotFound : ShortcutResult
data object ShortcutUpdateSuccess : ShortcutResult
data object ShortcutUpdateFailed : ShortcutResult
data object ShortcutUpdateImmutableShortcuts : ShortcutResult
data object ShortcutDisableImmutableShortcuts : ShortcutResult
data object UserIsLocked : ShortcutResult
data class ShortcutFound(
val targetShortcutInfoCompat: TargetShortcutInfoCompat,
) : ShortcutResult
data object NoShortcutFound : ShortcutResult
data object NoResult : ShortcutResult
}
| Geto/core/data/src/main/kotlin/com/android/geto/core/data/repository/ShortcutRepository.kt | 2304579269 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.repository
import com.android.geto.core.model.DarkThemeConfig
import com.android.geto.core.model.ThemeBrand
import com.android.geto.core.model.UserData
import com.android.geto.datastore.GetoPreferencesDataSource
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject
internal class DefaultUserDataRepository @Inject constructor(
private val getoPreferencesDataSource: GetoPreferencesDataSource,
) : UserDataRepository {
override val userData: Flow<UserData> = getoPreferencesDataSource.userData
override suspend fun setThemeBrand(themeBrand: ThemeBrand) {
getoPreferencesDataSource.setThemeBrand(themeBrand)
}
override suspend fun setDarkThemeConfig(darkThemeConfig: DarkThemeConfig) {
getoPreferencesDataSource.setDarkThemeConfig(darkThemeConfig)
}
override suspend fun setDynamicColorPreference(useDynamicColor: Boolean) {
getoPreferencesDataSource.setDynamicColorPreference(useDynamicColor)
}
override suspend fun setAutoLaunchPreference(useAutoLaunch: Boolean) {
getoPreferencesDataSource.setAutoLaunchPreference(useAutoLaunch)
}
}
| Geto/core/data/src/main/kotlin/com/android/geto/core/data/repository/DefaultUserDataRepository.kt | 2512754622 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.repository
import com.android.geto.core.model.AppSetting
import com.android.geto.core.model.SecureSetting
import com.android.geto.core.model.SettingType
interface SecureSettingsRepository {
suspend fun applySecureSettings(appSettings: List<AppSetting>): Boolean
suspend fun revertSecureSettings(appSettings: List<AppSetting>): Boolean
suspend fun getSecureSettings(settingType: SettingType): List<SecureSetting>
suspend fun getSecureSettingsByName(settingType: SettingType, text: String): List<SecureSetting>
}
| Geto/core/data/src/main/kotlin/com/android/geto/core/data/repository/SecureSettingsRepository.kt | 133032326 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.repository
import com.android.geto.core.model.AppSetting
import kotlinx.coroutines.flow.Flow
interface AppSettingsRepository {
val appSettings: Flow<List<AppSetting>>
suspend fun upsertAppSetting(appSetting: AppSetting)
suspend fun deleteAppSetting(appSetting: AppSetting)
fun getAppSettingsByPackageName(packageName: String): Flow<List<AppSetting>>
suspend fun deleteAppSettingsByPackageName(packageNames: List<String>)
}
| Geto/core/data/src/main/kotlin/com/android/geto/core/data/repository/AppSettingsRepository.kt | 4240498091 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.repository
import android.content.Intent
import android.graphics.drawable.Drawable
import com.android.geto.core.model.TargetApplicationInfo
interface PackageRepository {
suspend fun getInstalledApplications(): List<TargetApplicationInfo>
suspend fun getApplicationIcon(packageName: String): Drawable?
fun getLaunchIntentForPackage(packageName: String): Intent?
}
| Geto/core/data/src/main/kotlin/com/android/geto/core/data/repository/PackageRepository.kt | 3379933619 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.repository
import com.android.geto.core.database.dao.AppSettingsDao
import com.android.geto.core.database.model.AppSettingEntity
import com.android.geto.core.database.model.asEntity
import com.android.geto.core.database.model.asExternalModel
import com.android.geto.core.model.AppSetting
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import javax.inject.Inject
internal class DefaultAppSettingsRepository @Inject constructor(
private val appSettingsDao: AppSettingsDao,
) : AppSettingsRepository {
override val appSettings: Flow<List<AppSetting>> =
appSettingsDao.getAppSettingEntities().distinctUntilChanged().map { entities ->
entities.map(AppSettingEntity::asExternalModel)
}
override suspend fun upsertAppSetting(appSetting: AppSetting) {
appSettingsDao.upsertAppSettingEntity(appSetting.asEntity())
}
override suspend fun deleteAppSetting(appSetting: AppSetting) {
appSettingsDao.deleteAppSettingEntity(appSetting.asEntity())
}
override fun getAppSettingsByPackageName(packageName: String): Flow<List<AppSetting>> {
return appSettingsDao.getAppSettingEntitiesByPackageName(packageName).distinctUntilChanged()
.map { entities ->
entities.map(AppSettingEntity::asExternalModel)
}
}
override suspend fun deleteAppSettingsByPackageName(packageNames: List<String>) {
appSettingsDao.deleteAppSettingEntitiesByPackageName(packageNames)
}
}
| Geto/core/data/src/main/kotlin/com/android/geto/core/data/repository/DefaultAppSettingsRepository.kt | 735548779 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.repository
import androidx.core.content.pm.ShortcutManagerCompat
import com.android.geto.core.model.TargetShortcutInfoCompat
import com.android.geto.core.shortcutmanager.ShortcutManagerCompatWrapper
import javax.inject.Inject
internal class DefaultShortcutRepository @Inject constructor(
private val shortcutManagerCompatWrapper: ShortcutManagerCompatWrapper,
) : ShortcutRepository {
override fun requestPinShortcut(
packageName: String,
appName: String,
targetShortcutInfoCompat: TargetShortcutInfoCompat,
): ShortcutResult {
if (shortcutManagerCompatWrapper.isRequestPinShortcutSupported().not()) {
return ShortcutResult.UnsupportedLauncher
}
val requestPinShortcutSuccess = shortcutManagerCompatWrapper.requestPinShortcut(
packageName = packageName,
appName = appName,
targetShortcutInfoCompat = targetShortcutInfoCompat,
)
return if (requestPinShortcutSuccess) {
ShortcutResult.SupportedLauncher
} else {
ShortcutResult.UnsupportedLauncher
}
}
override fun updateRequestPinShortcut(
packageName: String,
appName: String,
targetShortcutInfoCompat: TargetShortcutInfoCompat,
): ShortcutResult {
val shortcutIds =
shortcutManagerCompatWrapper.getShortcuts(ShortcutManagerCompat.FLAG_MATCH_PINNED)
.map { it.id }
if (shortcutIds.contains(targetShortcutInfoCompat.id).not()) {
return ShortcutResult.IDNotFound
}
return try {
val updateShortcutsSuccess = shortcutManagerCompatWrapper.updateShortcuts(
packageName = packageName,
appName = appName,
targetShortcutInfoCompat = targetShortcutInfoCompat,
)
if (updateShortcutsSuccess) {
ShortcutResult.ShortcutUpdateSuccess
} else {
ShortcutResult.ShortcutUpdateFailed
}
} catch (e: IllegalArgumentException) {
ShortcutResult.ShortcutUpdateImmutableShortcuts
}
}
override fun getShortcut(id: String): ShortcutResult {
val targetShortcutInfoCompat =
shortcutManagerCompatWrapper.getShortcuts(ShortcutManagerCompat.FLAG_MATCH_PINNED)
.find { it.id == id }
return if (targetShortcutInfoCompat != null) {
ShortcutResult.ShortcutFound(
targetShortcutInfoCompat = targetShortcutInfoCompat,
)
} else {
ShortcutResult.NoShortcutFound
}
}
}
| Geto/core/data/src/main/kotlin/com/android/geto/core/data/repository/DefaultShortcutRepository.kt | 3757526455 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.repository
import android.content.Intent
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import com.android.geto.core.common.Dispatcher
import com.android.geto.core.common.GetoDispatchers.IO
import com.android.geto.core.model.TargetApplicationInfo
import com.android.geto.core.packagemanager.PackageManagerWrapper
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext
import javax.inject.Inject
internal class DefaultPackageRepository @Inject constructor(
private val packageManagerWrapper: PackageManagerWrapper,
@Dispatcher(IO) private val ioDispatcher: CoroutineDispatcher,
) : PackageRepository {
override suspend fun getInstalledApplications(): List<TargetApplicationInfo> {
return withContext(ioDispatcher) {
packageManagerWrapper.getInstalledApplications().filter { applicationInfo ->
(applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM) == 0
}.sortedBy { it.label }
}
}
override suspend fun getApplicationIcon(packageName: String): Drawable? {
return withContext(ioDispatcher) {
try {
packageManagerWrapper.getApplicationIcon(packageName)
} catch (e: PackageManager.NameNotFoundException) {
null
}
}
}
override fun getLaunchIntentForPackage(packageName: String): Intent? {
return packageManagerWrapper.getLaunchIntentForPackage(packageName)
}
}
| Geto/core/data/src/main/kotlin/com/android/geto/core/data/repository/DefaultPackageRepository.kt | 2504652398 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.repository
interface ClipboardRepository {
fun setPrimaryClip(label: String, text: String): ClipboardResult
}
sealed interface ClipboardResult {
data class Notify(val text: String) : ClipboardResult
data object NoResult : ClipboardResult
}
| Geto/core/data/src/main/kotlin/com/android/geto/core/data/repository/ClipboardRepository.kt | 1417459971 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.data.di
import com.android.geto.core.data.repository.AppSettingsRepository
import com.android.geto.core.data.repository.ClipboardRepository
import com.android.geto.core.data.repository.DefaultAppSettingsRepository
import com.android.geto.core.data.repository.DefaultClipboardRepository
import com.android.geto.core.data.repository.DefaultPackageRepository
import com.android.geto.core.data.repository.DefaultSecureSettingsRepository
import com.android.geto.core.data.repository.DefaultShortcutRepository
import com.android.geto.core.data.repository.DefaultUserDataRepository
import com.android.geto.core.data.repository.PackageRepository
import com.android.geto.core.data.repository.SecureSettingsRepository
import com.android.geto.core.data.repository.ShortcutRepository
import com.android.geto.core.data.repository.UserDataRepository
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
abstract class DataModule {
@Binds
@Singleton
internal abstract fun appSettingsRepository(impl: DefaultAppSettingsRepository): AppSettingsRepository
@Binds
@Singleton
internal abstract fun secureSettingsRepository(impl: DefaultSecureSettingsRepository): SecureSettingsRepository
@Binds
@Singleton
internal abstract fun packageRepository(impl: DefaultPackageRepository): PackageRepository
@Binds
@Singleton
internal abstract fun clipboardRepository(impl: DefaultClipboardRepository): ClipboardRepository
@Binds
@Singleton
internal abstract fun shortcutRepository(impl: DefaultShortcutRepository): ShortcutRepository
@Binds
@Singleton
internal abstract fun userDataRepository(impl: DefaultUserDataRepository): UserDataRepository
}
| Geto/core/data/src/main/kotlin/com/android/geto/core/data/di/DataModule.kt | 1713089580 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.domain
import com.android.geto.core.model.AppSetting
import com.android.geto.core.model.DarkThemeConfig
import com.android.geto.core.model.SettingType
import com.android.geto.core.model.TargetApplicationInfo
import com.android.geto.core.model.ThemeBrand
import com.android.geto.core.model.UserData
import com.android.geto.core.testing.repository.TestAppSettingsRepository
import com.android.geto.core.testing.repository.TestPackageRepository
import com.android.geto.core.testing.repository.TestSecureSettingsRepository
import com.android.geto.core.testing.repository.TestUserDataRepository
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import kotlin.test.assertIs
import kotlin.test.assertNotNull
class AutoLaunchUseCaseTest {
private lateinit var autoLaunchUseCase: AutoLaunchUseCase
private val packageRepository = TestPackageRepository()
private val appSettingsRepository = TestAppSettingsRepository()
private val userDataRepository = TestUserDataRepository()
private val secureSettingsRepository = TestSecureSettingsRepository()
private val packageName = "com.android.geto"
@Before
fun setup() {
autoLaunchUseCase = AutoLaunchUseCase(
packageRepository = packageRepository,
userDataRepository = userDataRepository,
appSettingsRepository = appSettingsRepository,
secureSettingsRepository = secureSettingsRepository,
)
}
@Test
fun autoLaunchAppUseCase_isIgnore_whenAppSettings_isEmpty() = runTest {
appSettingsRepository.setAppSettings(emptyList())
userDataRepository.setUserData(
userData = UserData(
themeBrand = ThemeBrand.DEFAULT,
darkThemeConfig = DarkThemeConfig.DARK,
useDynamicColor = false,
useAutoLaunch = false,
),
)
assertIs<AutoLaunchResult.Ignore>(autoLaunchUseCase(packageName = packageName))
}
@Test
fun autoLaunchAppUseCase_isIgnore_whenAppSettings_isDisabled() = runTest {
val appSettings = List(5) { index ->
AppSetting(
id = index,
enabled = false,
settingType = SettingType.SYSTEM,
packageName = packageName,
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
appSettingsRepository.setAppSettings(appSettings)
userDataRepository.setUserData(
userData = UserData(
themeBrand = ThemeBrand.DEFAULT,
darkThemeConfig = DarkThemeConfig.DARK,
useDynamicColor = false,
useAutoLaunch = false,
),
)
assertIs<AutoLaunchResult.Ignore>(autoLaunchUseCase(packageName = packageName))
}
@Test
fun autoLaunchAppUseCase_isSuccess() = runTest {
val appSettings = List(5) { index ->
AppSetting(
id = index,
enabled = true,
settingType = SettingType.SYSTEM,
packageName = packageName,
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
val installedApplications = List(5) { index ->
TargetApplicationInfo(flags = 0, packageName = packageName, label = "Geto $index")
}
packageRepository.setInstalledApplications(installedApplications)
secureSettingsRepository.setWriteSecureSettings(true)
userDataRepository.setUserData(
userData = UserData(
themeBrand = ThemeBrand.DEFAULT,
darkThemeConfig = DarkThemeConfig.DARK,
useDynamicColor = false,
useAutoLaunch = true,
),
)
appSettingsRepository.setAppSettings(appSettings)
val result = autoLaunchUseCase(packageName = packageName)
assertIs<AppSettingsResult.Success>(result)
assertNotNull(result.launchIntent)
}
@Test
fun autoLaunchAppUseCase_isSecurityException() = runTest {
val appSettings = List(5) { index ->
AppSetting(
id = index,
enabled = true,
settingType = SettingType.SYSTEM,
packageName = packageName,
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
secureSettingsRepository.setWriteSecureSettings(false)
userDataRepository.setUserData(
userData = UserData(
themeBrand = ThemeBrand.DEFAULT,
darkThemeConfig = DarkThemeConfig.DARK,
useDynamicColor = false,
useAutoLaunch = true,
),
)
appSettingsRepository.setAppSettings(appSettings)
assertIs<AppSettingsResult.SecurityException>(autoLaunchUseCase(packageName = packageName))
}
@Test
fun autoLaunchAppUseCase_isIllegalArgumentException() = runTest {
val appSettings = List(5) { index ->
AppSetting(
id = index,
enabled = true,
settingType = SettingType.SYSTEM,
packageName = packageName,
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
secureSettingsRepository.setWriteSecureSettings(true)
secureSettingsRepository.setInvalidValues(true)
userDataRepository.setUserData(
userData = UserData(
themeBrand = ThemeBrand.DEFAULT,
darkThemeConfig = DarkThemeConfig.DARK,
useDynamicColor = false,
useAutoLaunch = true,
),
)
appSettingsRepository.setAppSettings(appSettings)
assertIs<AppSettingsResult.IllegalArgumentException>(autoLaunchUseCase(packageName = packageName))
}
@Test
fun autoLaunchAppUseCase_isIgnore_whenUseAutoLaunch_isFalse() = runTest {
val appSettings = List(5) { index ->
AppSetting(
id = index,
enabled = true,
settingType = SettingType.SYSTEM,
packageName = packageName,
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
secureSettingsRepository.setWriteSecureSettings(true)
userDataRepository.setUserData(
userData = UserData(
themeBrand = ThemeBrand.DEFAULT,
darkThemeConfig = DarkThemeConfig.DARK,
useDynamicColor = false,
useAutoLaunch = false,
),
)
appSettingsRepository.setAppSettings(appSettings)
assertIs<AutoLaunchResult.Ignore>(autoLaunchUseCase(packageName = packageName))
}
}
| Geto/core/domain/src/test/kotlin/com/android/geto/core/domain/AutoLaunchUseCaseTest.kt | 3445626058 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.domain
import com.android.geto.core.model.AppSetting
import com.android.geto.core.model.SettingType
import com.android.geto.core.model.TargetApplicationInfo
import com.android.geto.core.testing.repository.TestAppSettingsRepository
import com.android.geto.core.testing.repository.TestPackageRepository
import com.android.geto.core.testing.repository.TestSecureSettingsRepository
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import kotlin.test.assertIs
import kotlin.test.assertNotNull
class ApplyAppSettingsUseCaseTest {
private lateinit var applyAppSettingsUseCase: ApplyAppSettingsUseCase
private val packageRepository = TestPackageRepository()
private val appSettingsRepository = TestAppSettingsRepository()
private val secureSettingsRepository = TestSecureSettingsRepository()
private val packageName = "com.android.geto"
@Before
fun setup() {
applyAppSettingsUseCase = ApplyAppSettingsUseCase(
packageRepository = packageRepository,
appSettingsRepository = appSettingsRepository,
secureSettingsRepository = secureSettingsRepository,
)
}
@Test
fun applyAppSettingsUseCase_isEmptyAppSettings() = runTest {
appSettingsRepository.setAppSettings(emptyList())
assertIs<AppSettingsResult.EmptyAppSettings>(applyAppSettingsUseCase(packageName = packageName))
}
@Test
fun applyAppSettingsUseCase_isDisabledAppSettings() = runTest {
val appSettings = List(5) { index ->
AppSetting(
id = index,
enabled = false,
settingType = SettingType.SYSTEM,
packageName = packageName,
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
appSettingsRepository.setAppSettings(appSettings)
assertIs<AppSettingsResult.DisabledAppSettings>(applyAppSettingsUseCase(packageName = packageName))
}
@Test
fun applyAppSettingsUseCase_isSuccess() = runTest {
val appSettings = List(5) { index ->
AppSetting(
id = index,
enabled = true,
settingType = SettingType.SYSTEM,
packageName = packageName,
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
val installedApplications = List(5) { index ->
TargetApplicationInfo(flags = 0, packageName = packageName, label = "Geto $index")
}
packageRepository.setInstalledApplications(installedApplications)
secureSettingsRepository.setWriteSecureSettings(true)
appSettingsRepository.setAppSettings(appSettings)
val result = applyAppSettingsUseCase(packageName = packageName)
assertIs<AppSettingsResult.Success>(result)
assertNotNull(result.launchIntent)
}
@Test
fun applyAppSettingsUseCase_isSecurityException() = runTest {
val appSettings = List(5) { index ->
AppSetting(
id = index,
enabled = true,
settingType = SettingType.SYSTEM,
packageName = packageName,
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
secureSettingsRepository.setWriteSecureSettings(false)
appSettingsRepository.setAppSettings(appSettings)
assertIs<AppSettingsResult.SecurityException>(applyAppSettingsUseCase(packageName = packageName))
}
@Test
fun applyAppSettingsUseCase_isIllegalArgumentException() = runTest {
val appSettings = List(5) { index ->
AppSetting(
id = index,
enabled = true,
settingType = SettingType.SYSTEM,
packageName = packageName,
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
secureSettingsRepository.setWriteSecureSettings(true)
secureSettingsRepository.setInvalidValues(true)
appSettingsRepository.setAppSettings(appSettings)
assertIs<AppSettingsResult.IllegalArgumentException>(applyAppSettingsUseCase(packageName = packageName))
}
}
| Geto/core/domain/src/test/kotlin/com/android/geto/core/domain/ApplyAppSettingsUseCaseTest.kt | 1909507635 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.domain
import com.android.geto.core.model.AppSetting
import com.android.geto.core.model.SettingType
import com.android.geto.core.testing.repository.TestAppSettingsRepository
import com.android.geto.core.testing.repository.TestSecureSettingsRepository
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import kotlin.test.assertIs
class RevertAppSettingsUseCaseTest {
private lateinit var revertAppSettingsUseCase: RevertAppSettingsUseCase
private val appSettingsRepository = TestAppSettingsRepository()
private val secureSettingsRepository = TestSecureSettingsRepository()
private val packageName = "com.android.geto"
@Before
fun setup() {
revertAppSettingsUseCase = RevertAppSettingsUseCase(
appSettingsRepository = appSettingsRepository,
secureSettingsRepository = secureSettingsRepository,
)
}
@Test
fun revertAppSettingsUseCase_isEmptyAppSettings() = runTest {
appSettingsRepository.setAppSettings(emptyList())
assertIs<AppSettingsResult.EmptyAppSettings>(revertAppSettingsUseCase(packageName = packageName))
}
@Test
fun revertAppSettingsUseCase_isDisabledAppSettings() = runTest {
val appSettings = List(5) { index ->
AppSetting(
id = index,
enabled = false,
settingType = SettingType.SYSTEM,
packageName = packageName,
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
appSettingsRepository.setAppSettings(appSettings)
assertIs<AppSettingsResult.DisabledAppSettings>(revertAppSettingsUseCase(packageName = packageName))
}
@Test
fun revertAppSettingsUseCase_isSuccess() = runTest {
val appSettings = List(5) { index ->
AppSetting(
id = index,
enabled = true,
settingType = SettingType.SYSTEM,
packageName = packageName,
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
secureSettingsRepository.setWriteSecureSettings(true)
appSettingsRepository.setAppSettings(appSettings)
assertIs<AppSettingsResult.Success>(revertAppSettingsUseCase(packageName = packageName))
}
@Test
fun revertAppSettingsUseCase_isSecurityException() = runTest {
val appSettings = List(5) { index ->
AppSetting(
id = index,
enabled = true,
settingType = SettingType.SYSTEM,
packageName = packageName,
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
secureSettingsRepository.setWriteSecureSettings(false)
appSettingsRepository.setAppSettings(appSettings)
assertIs<AppSettingsResult.SecurityException>(revertAppSettingsUseCase(packageName = packageName))
}
@Test
fun revertAppSettingsUseCase_isIllegalArgumentException() = runTest {
val appSettings = List(5) { index ->
AppSetting(
id = index,
enabled = true,
settingType = SettingType.SYSTEM,
packageName = packageName,
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
secureSettingsRepository.setWriteSecureSettings(true)
secureSettingsRepository.setInvalidValues(true)
appSettingsRepository.setAppSettings(appSettings)
assertIs<AppSettingsResult.IllegalArgumentException>(revertAppSettingsUseCase(packageName = packageName))
}
}
| Geto/core/domain/src/test/kotlin/com/android/geto/core/domain/RevertAppSettingsUseCaseTest.kt | 2576156208 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.domain
sealed interface AutoLaunchResult : AppSettingsResult {
data object Ignore : AutoLaunchResult
}
| Geto/core/domain/src/main/kotlin/com/android/geto/core/domain/AutoLaunchResult.kt | 1073731822 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.domain
import com.android.geto.core.data.repository.AppSettingsRepository
import com.android.geto.core.data.repository.PackageRepository
import com.android.geto.core.model.AppSetting
import com.android.geto.core.model.TargetApplicationInfo
import kotlinx.coroutines.flow.first
import javax.inject.Inject
class CleanAppSettingsUseCase @Inject constructor(
private val packageRepository: PackageRepository,
private val appSettingsRepository: AppSettingsRepository,
) {
suspend operator fun invoke() {
val packageNamesFromInstalledApplications =
packageRepository.getInstalledApplications().map(TargetApplicationInfo::packageName)
val packageNamesFromAppSettings =
appSettingsRepository.appSettings.first().map(AppSetting::packageName)
val oldPackageNames = packageNamesFromAppSettings.filterNot { packageName ->
packageName in packageNamesFromInstalledApplications
}
appSettingsRepository.deleteAppSettingsByPackageName(packageNames = oldPackageNames)
}
}
| Geto/core/domain/src/main/kotlin/com/android/geto/core/domain/CleanAppSettingsUseCase.kt | 2449724472 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.domain
import com.android.geto.core.data.repository.AppSettingsRepository
import com.android.geto.core.data.repository.PackageRepository
import com.android.geto.core.data.repository.SecureSettingsRepository
import com.android.geto.core.data.repository.UserDataRepository
import kotlinx.coroutines.flow.first
import javax.inject.Inject
class AutoLaunchUseCase @Inject constructor(
private val packageRepository: PackageRepository,
private val userDataRepository: UserDataRepository,
private val appSettingsRepository: AppSettingsRepository,
private val secureSettingsRepository: SecureSettingsRepository,
) {
suspend operator fun invoke(packageName: String): AppSettingsResult {
val launchIntent = packageRepository.getLaunchIntentForPackage(packageName)
val userData = userDataRepository.userData.first()
val appSettings = appSettingsRepository.getAppSettingsByPackageName(packageName).first()
if (userData.useAutoLaunch.not() || appSettings.isEmpty() || appSettings.any { it.enabled.not() }) return AutoLaunchResult.Ignore
return try {
val applySecureSettingsSuccess =
secureSettingsRepository.applySecureSettings(appSettings)
if (applySecureSettingsSuccess) {
AppSettingsResult.Success(launchIntent = launchIntent)
} else {
AppSettingsResult.Failure
}
} catch (e: SecurityException) {
AppSettingsResult.SecurityException
} catch (e: IllegalArgumentException) {
AppSettingsResult.IllegalArgumentException
}
}
}
| Geto/core/domain/src/main/kotlin/com/android/geto/core/domain/AutoLaunchUseCase.kt | 1682173100 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.domain
import com.android.geto.core.data.repository.AppSettingsRepository
import com.android.geto.core.data.repository.SecureSettingsRepository
import kotlinx.coroutines.flow.first
import javax.inject.Inject
class RevertAppSettingsUseCase @Inject constructor(
private val appSettingsRepository: AppSettingsRepository,
private val secureSettingsRepository: SecureSettingsRepository,
) {
suspend operator fun invoke(packageName: String): AppSettingsResult {
val appSettings = appSettingsRepository.getAppSettingsByPackageName(packageName).first()
if (appSettings.isEmpty()) return AppSettingsResult.EmptyAppSettings
if (appSettings.any { it.enabled.not() }) return AppSettingsResult.DisabledAppSettings
return try {
val revertSecureSettingsSuccess =
secureSettingsRepository.revertSecureSettings(appSettings)
if (revertSecureSettingsSuccess) {
AppSettingsResult.Success(null)
} else {
AppSettingsResult.Failure
}
} catch (e: SecurityException) {
AppSettingsResult.SecurityException
} catch (e: IllegalArgumentException) {
AppSettingsResult.IllegalArgumentException
}
}
}
| Geto/core/domain/src/main/kotlin/com/android/geto/core/domain/RevertAppSettingsUseCase.kt | 3537108935 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.domain
import android.content.Intent
sealed interface AppSettingsResult {
data class Success(val launchIntent: Intent?) : AppSettingsResult
data object Failure : AppSettingsResult
data object SecurityException : AppSettingsResult
data object IllegalArgumentException : AppSettingsResult
data object EmptyAppSettings : AppSettingsResult
data object DisabledAppSettings : AppSettingsResult
data object NoResult : AppSettingsResult
}
| Geto/core/domain/src/main/kotlin/com/android/geto/core/domain/AppSettingsResult.kt | 1212342373 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.core.domain
import com.android.geto.core.data.repository.AppSettingsRepository
import com.android.geto.core.data.repository.PackageRepository
import com.android.geto.core.data.repository.SecureSettingsRepository
import kotlinx.coroutines.flow.first
import javax.inject.Inject
class ApplyAppSettingsUseCase @Inject constructor(
private val packageRepository: PackageRepository,
private val appSettingsRepository: AppSettingsRepository,
private val secureSettingsRepository: SecureSettingsRepository,
) {
suspend operator fun invoke(packageName: String): AppSettingsResult {
val launchIntent = packageRepository.getLaunchIntentForPackage(packageName)
val appSettings = appSettingsRepository.getAppSettingsByPackageName(packageName).first()
if (appSettings.isEmpty()) return AppSettingsResult.EmptyAppSettings
if (appSettings.any { it.enabled.not() }) return AppSettingsResult.DisabledAppSettings
return try {
val applySecureSettingsSuccess =
secureSettingsRepository.applySecureSettings(appSettings)
if (applySecureSettingsSuccess) {
AppSettingsResult.Success(launchIntent = launchIntent)
} else {
AppSettingsResult.Failure
}
} catch (e: SecurityException) {
AppSettingsResult.SecurityException
} catch (e: IllegalArgumentException) {
AppSettingsResult.IllegalArgumentException
}
}
}
| Geto/core/domain/src/main/kotlin/com/android/geto/core/domain/ApplyAppSettingsUseCase.kt | 941424776 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.getocatalog
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.core.view.WindowCompat
class GetoCatalogActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)
setContent { }
}
}
| Geto/app-geto-catalog/src/main/kotlin/com/android/geto/getocatalog/GetoCatalogActivity.kt | 397089313 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.navigation
import androidx.activity.compose.setContent
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.navigation.compose.ComposeNavigator
import androidx.navigation.testing.TestNavHostController
import com.android.geto.MainActivity
import com.android.geto.feature.apps.navigation.APPS_NAVIGATION_ROUTE
import com.android.geto.feature.settings.navigation.SETTINGS_NAVIGATION_ROUTE
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import kotlin.test.assertEquals
@HiltAndroidTest
class NavigationTest {
@get:Rule(order = 0)
val hiltRule = HiltAndroidRule(this)
@get:Rule(order = 1)
val composeTestRule = createAndroidComposeRule<MainActivity>()
private lateinit var navController: TestNavHostController
@Before
fun setup() {
composeTestRule.activity.setContent {
navController = TestNavHostController(LocalContext.current)
navController.navigatorProvider.addNavigator(ComposeNavigator())
GetoNavHost(navController = navController)
}
}
@Test
fun appsScreen_isDisplayed_whenStarted() {
composeTestRule.onNodeWithTag("apps").assertIsDisplayed()
}
@Test
fun appSettingsScreen_isDisplayed_whenTargetApplicationInfoItem_isClicked() {
composeTestRule.onAllNodes(hasTestTag("apps:appItem"))[0].performClick()
val appSettingsRoute = navController.currentBackStackEntry?.destination?.route
assertEquals(
expected = "app_settings_route/{package_name}/{app_name}",
actual = appSettingsRoute,
)
}
@Test
fun appsScreen_isDisplayed_whenNavigateBackFromAppSettingsScreen() {
composeTestRule.onAllNodes(hasTestTag("apps:appItem"))[0].performClick()
composeTestRule.onNodeWithContentDescription(
label = "Navigation icon",
useUnmergedTree = true,
).performClick()
val appListRoute = navController.currentBackStackEntry?.destination?.route
assertEquals(
expected = APPS_NAVIGATION_ROUTE,
actual = appListRoute,
)
}
@Test
fun settingsScreen_isDisplayed_whenSettingsIcon_isClicked() {
composeTestRule.onNodeWithContentDescription("Settings icon").performClick()
val settingsRoute = navController.currentBackStackEntry?.destination?.route
assertEquals(
expected = SETTINGS_NAVIGATION_ROUTE,
actual = settingsRoute,
)
}
@Test
fun appsScreen_isDisplayed_whenNavigateBackFromSettingsScreen() {
composeTestRule.onNodeWithContentDescription("Settings icon").performClick()
composeTestRule.onNodeWithContentDescription(
label = "Navigation icon",
useUnmergedTree = true,
).performClick()
val appListRoute = navController.currentBackStackEntry?.destination?.route
assertEquals(
expected = APPS_NAVIGATION_ROUTE,
actual = appListRoute,
)
}
}
| Geto/app/src/androidTest/kotlin/com/android/geto/navigation/NavigationTest.kt | 1375811293 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto
import android.app.Application
import dagger.hilt.android.HiltAndroidApp
@HiltAndroidApp
class GetoApplication : Application()
| Geto/app/src/main/kotlin/com/android/geto/GetoApplication.kt | 2514889312 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.compose.rememberNavController
import com.android.geto.core.designsystem.component.GetoBackground
import com.android.geto.core.designsystem.theme.GetoTheme
import com.android.geto.core.model.DarkThemeConfig
import com.android.geto.core.model.ThemeBrand
import com.android.geto.navigation.GetoNavHost
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
private val viewModel: MainActivityViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
val splashScreen = installSplashScreen()
super.onCreate(savedInstanceState)
var uiState: MainActivityUiState by mutableStateOf(MainActivityUiState.Loading)
// Update the uiState
lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.uiState.onEach { uiState = it }.collect()
}
}
// Keep the splash screen on-screen until the UI state is loaded. This condition is
// evaluated each time the app needs to be redrawn so it should be fast to avoid blocking
// the UI.
splashScreen.setKeepOnScreenCondition {
when (uiState) {
MainActivityUiState.Loading -> true
is MainActivityUiState.Success -> false
}
}
// Turn off the decor fitting system windows, which allows us to handle insets,
// including IME animations, and go edge-to-edge
// This also sets up the initial system bar style based on the platform theme
enableEdgeToEdge()
setContent {
val darkTheme = shouldUseDarkTheme(uiState)
val navController = rememberNavController()
// Update the edge to edge configuration to match the theme
// This is the same parameters as the default enableEdgeToEdge call, but we manually
// resolve whether or not to show dark theme using uiState, since it can be different
// than the configuration's dark theme value based on the user preference.
DisposableEffect(darkTheme) {
enableEdgeToEdge(
statusBarStyle = SystemBarStyle.auto(
android.graphics.Color.TRANSPARENT,
android.graphics.Color.TRANSPARENT,
) { darkTheme },
navigationBarStyle = SystemBarStyle.auto(
lightScrim,
darkScrim,
) { darkTheme },
)
onDispose {}
}
GetoTheme(
darkTheme = darkTheme,
androidTheme = shouldUseAndroidTheme(uiState),
disableDynamicTheming = shouldDisableDynamicTheming(uiState),
) {
GetoBackground {
GetoNavHost(navController = navController)
}
}
}
}
}
/**
* Returns `true` if the Android theme should be used, as a function of the [uiState].
*/
@Composable
private fun shouldUseAndroidTheme(
uiState: MainActivityUiState,
): Boolean = when (uiState) {
MainActivityUiState.Loading -> false
is MainActivityUiState.Success -> when (uiState.userData.themeBrand) {
ThemeBrand.DEFAULT -> false
ThemeBrand.ANDROID -> true
}
}
/**
* Returns `true` if the dynamic color is disabled, as a function of the [uiState].
*/
@Composable
private fun shouldDisableDynamicTheming(
uiState: MainActivityUiState,
): Boolean = when (uiState) {
MainActivityUiState.Loading -> false
is MainActivityUiState.Success -> !uiState.userData.useDynamicColor
}
/**
* Returns `true` if dark theme should be used, as a function of the [uiState] and the
* current system context.
*/
@Composable
private fun shouldUseDarkTheme(
uiState: MainActivityUiState,
): Boolean = when (uiState) {
MainActivityUiState.Loading -> isSystemInDarkTheme()
is MainActivityUiState.Success -> when (uiState.userData.darkThemeConfig) {
DarkThemeConfig.FOLLOW_SYSTEM -> isSystemInDarkTheme()
DarkThemeConfig.LIGHT -> false
DarkThemeConfig.DARK -> true
}
}
/**
* The default light scrim, as defined by androidx and the platform:
* https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:activity/activity/src/main/java/androidx/activity/EdgeToEdge.kt;l=35-38;drc=27e7d52e8604a080133e8b842db10c89b4482598
*/
private val lightScrim = android.graphics.Color.argb(0xe6, 0xFF, 0xFF, 0xFF)
/**
* The default dark scrim, as defined by androidx and the platform:
* https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:activity/activity/src/main/java/androidx/activity/EdgeToEdge.kt;l=40-44;drc=27e7d52e8604a080133e8b842db10c89b4482598
*/
private val darkScrim = android.graphics.Color.argb(0x80, 0x1b, 0x1b, 0x1b)
| Geto/app/src/main/kotlin/com/android/geto/MainActivity.kt | 4069198315 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.android.geto.core.data.repository.UserDataRepository
import com.android.geto.core.model.UserData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import javax.inject.Inject
@HiltViewModel
class MainActivityViewModel @Inject constructor(
userDataRepository: UserDataRepository,
) : ViewModel() {
val uiState: StateFlow<MainActivityUiState> =
userDataRepository.userData.map(MainActivityUiState::Success).stateIn(
scope = viewModelScope,
initialValue = MainActivityUiState.Loading,
started = SharingStarted.WhileSubscribed(5_000),
)
}
sealed interface MainActivityUiState {
data object Loading : MainActivityUiState
data class Success(val userData: UserData) : MainActivityUiState
}
| Geto/app/src/main/kotlin/com/android/geto/MainActivityViewModel.kt | 1573423507 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.navigation
import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import com.android.geto.feature.apps.navigation.APPS_NAVIGATION_ROUTE
import com.android.geto.feature.apps.navigation.appsScreen
import com.android.geto.feature.appsettings.navigation.appSettingsScreen
import com.android.geto.feature.appsettings.navigation.navigateToAppSettings
import com.android.geto.feature.settings.navigation.navigateToSettings
import com.android.geto.feature.settings.navigation.settingsScreen
@Composable
fun GetoNavHost(navController: NavHostController) {
NavHost(
navController = navController,
startDestination = APPS_NAVIGATION_ROUTE,
) {
appsScreen(
onItemClick = navController::navigateToAppSettings,
onSettingsClick = navController::navigateToSettings,
)
appSettingsScreen(onNavigationIconClick = navController::popBackStack)
settingsScreen(onNavigationIconClick = navController::popBackStack)
}
}
| Geto/app/src/main/kotlin/com/android/geto/navigation/GetoNavHost.kt | 882970165 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/ | Geto/spotless/copyright.kt | 446143291 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import com.android.build.gradle.LibraryExtension
import com.android.geto.configureGradleManagedDevices
import com.android.geto.libs
import com.android.geto.pluginId
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
class AndroidFeatureConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply(libs.plugins.com.android.geto.library.pluginId)
apply(libs.plugins.com.android.geto.hilt.pluginId)
}
extensions.configure<LibraryExtension> {
defaultConfig {
testInstrumentationRunner = "com.android.geto.core.testing.GetoTestRunner"
}
configureGradleManagedDevices(this)
}
dependencies {
add("implementation", project(":core:designsystem"))
add("implementation", project(":core:ui"))
add("implementation", libs.androidx.hilt.navigation.compose)
add("implementation", libs.androidx.lifecycle.runtime.compose)
add("implementation", libs.androidx.lifecycle.viewmodel.compose)
}
}
}
} | Geto/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt | 1005880638 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import com.android.geto.libs
import com.android.geto.pluginId
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
class AndroidHiltConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply(libs.plugins.ksp.pluginId)
apply(libs.plugins.hilt.pluginId)
}
dependencies {
add("implementation", libs.hilt.android)
add("implementation", libs.androidx.hilt.navigation.compose)
add("ksp", libs.hilt.compiler)
add("ksp", libs.dagger.compiler)
add("kspAndroidTest", libs.hilt.compiler)
add("ksp", libs.hilt.compiler)
}
}
}
} | Geto/build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt | 817742304 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import com.android.build.api.dsl.ApplicationExtension
import com.android.geto.configureGradleManagedDevices
import com.android.geto.configureKotlinAndroid
import com.android.geto.libs
import com.android.geto.pluginId
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
class AndroidApplicationConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply(libs.plugins.android.application.pluginId)
apply(libs.plugins.kotlin.android.pluginId)
apply(libs.plugins.com.android.geto.lint.pluginId)
apply(libs.plugins.dependencyGuard.pluginId)
}
extensions.configure<ApplicationExtension> {
configureKotlinAndroid(this)
defaultConfig.targetSdk = 34
configureGradleManagedDevices(this)
}
}
}
} | Geto/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt | 3168683358 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import com.android.build.api.dsl.ApplicationExtension
import com.android.geto.configureAndroidCompose
import com.android.geto.libs
import com.android.geto.pluginId
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType
class AndroidApplicationComposeConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply(libs.plugins.android.application.pluginId)
}
val extension = extensions.getByType<ApplicationExtension>()
configureAndroidCompose(extension)
}
}
} | Geto/build-logic/convention/src/main/kotlin/AndroidApplicationComposeConventionPlugin.kt | 1506383363 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import com.android.geto.configureJacoco
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType
class AndroidApplicationJacocoConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
pluginManager.apply("jacoco")
val androidExtension = extensions.getByType<BaseAppModuleExtension>()
androidExtension.buildTypes.configureEach {
enableAndroidTestCoverage = true
enableUnitTestCoverage = true
}
configureJacoco(extensions.getByType<ApplicationAndroidComponentsExtension>())
}
}
} | Geto/build-logic/convention/src/main/kotlin/AndroidApplicationJacocoConventionPlugin.kt | 1048004213 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import androidx.room.gradle.RoomExtension
import com.android.geto.libs
import com.android.geto.pluginId
import com.google.devtools.ksp.gradle.KspExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
class AndroidRoomConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply(libs.plugins.room.pluginId)
apply(libs.plugins.ksp.pluginId)
}
extensions.configure<KspExtension> {
arg("room.generateKotlin", "true")
}
extensions.configure<RoomExtension> {
// The schemas directory contains a schema file for each version of the Room database.
// This is required to enable Room auto migrations.
// See https://developer.android.com/reference/kotlin/androidx/room/AutoMigration.
schemaDirectory("$projectDir/schemas")
}
dependencies {
add("implementation", libs.room.runtime)
add("implementation", libs.room.ktx)
add("ksp", libs.room.compiler)
}
}
}
} | Geto/build-logic/convention/src/main/kotlin/AndroidRoomConventionPlugin.kt | 2096776487 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import com.android.build.gradle.TestExtension
import com.android.geto.configureGradleManagedDevices
import com.android.geto.configureKotlinAndroid
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
class AndroidTestConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.android.test")
apply("org.jetbrains.kotlin.android")
}
extensions.configure<TestExtension> {
configureKotlinAndroid(this)
defaultConfig.targetSdk = 34
configureGradleManagedDevices(this)
}
}
}
} | Geto/build-logic/convention/src/main/kotlin/AndroidTestConventionPlugin.kt | 379516573 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import com.android.build.api.dsl.ApplicationExtension
import com.android.build.api.dsl.LibraryExtension
import com.android.build.api.dsl.Lint
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
class AndroidLintConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
when {
pluginManager.hasPlugin("com.android.application") -> configure<ApplicationExtension> {
lint(
Lint::configure,
)
}
pluginManager.hasPlugin("com.android.library") -> configure<LibraryExtension> {
lint(
Lint::configure,
)
}
else -> {
pluginManager.apply("com.android.lint")
configure<Lint>(Lint::configure)
}
}
}
}
}
private fun Lint.configure() {
xmlReport = true
checkDependencies = true
} | Geto/build-logic/convention/src/main/kotlin/AndroidLintConventionPlugin.kt | 4057281908 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import com.android.build.api.dsl.LibraryExtension
import com.android.build.api.variant.LibraryAndroidComponentsExtension
import com.android.geto.configureJacoco
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType
class AndroidLibraryJacocoConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
pluginManager.apply("jacoco")
val androidExtension = extensions.getByType<LibraryExtension>()
androidExtension.buildTypes.configureEach {
enableAndroidTestCoverage = true
enableUnitTestCoverage = true
}
configureJacoco(extensions.getByType<LibraryAndroidComponentsExtension>())
}
}
} | Geto/build-logic/convention/src/main/kotlin/AndroidLibraryJacocoConventionPlugin.kt | 27638690 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import com.android.build.api.dsl.LibraryExtension
import com.android.build.api.variant.LibraryAndroidComponentsExtension
import com.android.geto.configureGradleManagedDevices
import com.android.geto.configureKotlinAndroid
import com.android.geto.disableUnnecessaryAndroidTests
import com.android.geto.libs
import com.android.geto.pluginId
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.kotlin
class AndroidLibraryConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply(libs.plugins.android.library.pluginId)
apply(libs.plugins.kotlin.android.pluginId)
apply(libs.plugins.com.android.geto.lint.pluginId)
}
extensions.configure<LibraryExtension> {
configureKotlinAndroid(this)
testOptions.targetSdk = 34
configureGradleManagedDevices(this)
}
extensions.configure<LibraryAndroidComponentsExtension> {
disableUnnecessaryAndroidTests(target)
}
dependencies {
add("testImplementation", kotlin("test"))
}
}
}
} | Geto/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt | 478605298 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import com.android.build.gradle.LibraryExtension
import com.android.geto.configureAndroidCompose
import com.android.geto.libs
import com.android.geto.pluginId
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
class AndroidLibraryComposeConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply(libs.plugins.android.library.pluginId)
}
extensions.configure<LibraryExtension> {
configureAndroidCompose(this)
}
}
}
} | Geto/build-logic/convention/src/main/kotlin/AndroidLibraryComposeConventionPlugin.kt | 2026327968 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto
import com.android.build.api.dsl.CommonExtension
import com.android.build.api.dsl.ManagedVirtualDevice
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.invoke
/**
* Configure project for Gradle managed devices
*/
internal fun configureGradleManagedDevices(
commonExtension: CommonExtension<*, *, *, *, *, *>,
) {
val pixel4 = DeviceConfig("Pixel 4", 30, "aosp-atd")
val pixel6 = DeviceConfig("Pixel 6", 31, "aosp")
val pixelC = DeviceConfig("Pixel C", 30, "aosp-atd")
val allDevices = listOf(pixel4, pixel6, pixelC)
val ciDevices = listOf(pixel4, pixelC)
commonExtension.testOptions {
managedDevices {
devices {
allDevices.forEach { deviceConfig ->
maybeCreate(deviceConfig.taskName, ManagedVirtualDevice::class.java).apply {
device = deviceConfig.device
apiLevel = deviceConfig.apiLevel
systemImageSource = deviceConfig.systemImageSource
}
}
}
groups {
maybeCreate("ci").apply {
ciDevices.forEach { deviceConfig ->
targetDevices.add(devices[deviceConfig.taskName])
}
}
}
}
}
}
private data class DeviceConfig(
val device: String,
val apiLevel: Int,
val systemImageSource: String,
) {
val taskName = buildString {
append(device.lowercase().replace(" ", ""))
append("api")
append(apiLevel.toString())
append(systemImageSource.replace("-", ""))
}
} | Geto/build-logic/convention/src/main/kotlin/com/android/geto/GradleManagedDevices.kt | 2189590605 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto
import com.android.build.api.dsl.CommonExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
internal fun Project.configureAndroidCompose(
commonExtension: CommonExtension<*, *, *, *, *, *>,
) {
commonExtension.apply {
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.androidxComposeCompiler.get()
}
dependencies {
val bom = libs.androidx.compose.bom
add("implementation", platform(bom))
add("androidTestImplementation", platform(bom))
add("implementation", libs.androidx.compose.ui.tooling.preview)
add("debugImplementation", libs.androidx.compose.ui.tooling)
}
testOptions {
unitTests {
// For Robolectric
isIncludeAndroidResources = true
}
}
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
freeCompilerArgs += buildComposeMetricsParameters()
freeCompilerArgs += stabilityConfiguration()
}
}
}
private fun Project.buildComposeMetricsParameters(): List<String> {
val metricParameters = mutableListOf<String>()
val enableMetricsProvider = project.providers.gradleProperty("enableComposeCompilerMetrics")
val relativePath = projectDir.relativeTo(rootDir)
val buildDir = layout.buildDirectory.get().asFile
val enableMetrics = (enableMetricsProvider.orNull == "true")
if (enableMetrics) {
val metricsFolder = buildDir.resolve("compose-metrics").resolve(relativePath)
metricParameters.add("-P")
metricParameters.add(
"plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=" + metricsFolder.absolutePath,
)
}
val enableReportsProvider = project.providers.gradleProperty("enableComposeCompilerReports")
val enableReports = (enableReportsProvider.orNull == "true")
if (enableReports) {
val reportsFolder = buildDir.resolve("compose-reports").resolve(relativePath)
metricParameters.add("-P")
metricParameters.add(
"plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" + reportsFolder.absolutePath,
)
}
return metricParameters.toList()
}
private fun Project.stabilityConfiguration() = listOf(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:stabilityConfigurationPath=${project.rootDir.absolutePath}/compose_compiler_config.conf",
) | Geto/build-logic/convention/src/main/kotlin/com/android/geto/AndroidCompose.kt | 279622612 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto
import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.api.Project
import org.gradle.api.provider.Provider
import org.gradle.plugin.use.PluginDependency
val Project.libs
get(): LibrariesForLibs = extensions.getByName("libs") as LibrariesForLibs
val Provider<PluginDependency>.pluginId
get(): String = get().pluginId | Geto/build-logic/convention/src/main/kotlin/com/android/geto/ProjectExtensions.kt | 469330474 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto
import com.android.build.api.dsl.CommonExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
internal fun Project.configureKotlinAndroid(
commonExtension: CommonExtension<*, *, *, *, *, *>,
) {
commonExtension.apply {
compileSdk = 34
defaultConfig {
minSdk = 21
}
compileOptions {
isCoreLibraryDesugaringEnabled = true
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}
extensions.configure<KotlinAndroidProjectExtension> {
jvmToolchain(17)
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
// Treat all Kotlin warnings as errors (disabled by default)
// Override by setting warningsAsErrors=true in your ~/.gradle/gradle.properties
val warningsAsErrors: String? by project
allWarningsAsErrors = warningsAsErrors.toBoolean()
freeCompilerArgs = freeCompilerArgs + listOf(
// Enable experimental coroutines APIs, including Flow
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
)
}
}
dependencies {
add("coreLibraryDesugaring", libs.android.desugarJdkLibs)
}
} | Geto/build-logic/convention/src/main/kotlin/com/android/geto/KotlinAndroid.kt | 3596868766 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto
import com.android.build.api.variant.LibraryAndroidComponentsExtension
import org.gradle.api.Project
/**
* Disable unnecessary Android instrumented tests for the [project] if there is no `androidTest` folder.
* Otherwise, these projects would be compiled, packaged, installed and ran only to end-up with the following message:
*
* > Starting 0 tests on AVD
*
* Note: this could be improved by checking other potential sourceSets based on buildTypes and flavors.
*/
internal fun LibraryAndroidComponentsExtension.disableUnnecessaryAndroidTests(
project: Project,
) = beforeVariants {
it.androidTest.enable =
it.androidTest.enable && project.projectDir.resolve("src/androidTest").exists()
} | Geto/build-logic/convention/src/main/kotlin/com/android/geto/AndroidInstrumentedTests.kt | 685129198 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto
/**
* This is shared between :app and :benchmarks module to provide configurations type safety.
*/
enum class GetoBuildType(val applicationIdSuffix: String? = null) {
DEBUG(".debug"), RELEASE,
} | Geto/build-logic/convention/src/main/kotlin/com/android/geto/GetoBuildType.kt | 2587307470 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto
import com.android.build.api.artifact.ScopedArtifact
import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.api.variant.ScopedArtifacts
import org.gradle.api.Project
import org.gradle.api.file.Directory
import org.gradle.api.file.RegularFile
import org.gradle.api.provider.ListProperty
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.withType
import org.gradle.testing.jacoco.plugins.JacocoPluginExtension
import org.gradle.testing.jacoco.plugins.JacocoTaskExtension
import org.gradle.testing.jacoco.tasks.JacocoReport
import java.util.Locale
private val coverageExclusions = listOf(
// Android
"**/R.class",
"**/R\$*.class",
"**/BuildConfig.*",
"**/Manifest*.*",
"**/*_Hilt*.class",
"**/Hilt_*.class",
)
private fun String.capitalize() = replaceFirstChar {
if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString()
}
/**
* Creates a new task that generates a combined coverage report with data from local and
* instrumented tests.
*
* `create{variant}CombinedCoverageReport`
*
* Note that coverage data must exist before running the task. This allows us to run device
* tests on CI using a different Github Action or an external device farm.
*/
internal fun Project.configureJacoco(
androidComponentsExtension: AndroidComponentsExtension<*, *, *>,
) {
configure<JacocoPluginExtension> {
toolVersion = libs.versions.jacoco.get()
}
androidComponentsExtension.onVariants { variant ->
val myObjFactory = project.objects
val buildDir = layout.buildDirectory.get().asFile
val allJars: ListProperty<RegularFile> = myObjFactory.listProperty(RegularFile::class.java)
val allDirectories: ListProperty<Directory> =
myObjFactory.listProperty(Directory::class.java)
val reportTask = tasks.register(
"create${variant.name.capitalize()}CombinedCoverageReport",
JacocoReport::class,
) {
classDirectories.setFrom(
allJars,
allDirectories.map { dirs ->
dirs.map { dir ->
myObjFactory.fileTree().setDir(dir).exclude(coverageExclusions)
}
},
)
reports {
xml.required.set(true)
html.required.set(true)
}
// TODO: This is missing files in src/debug/, src/prod, src/demo, src/demoDebug...
sourceDirectories.setFrom(
files(
"$projectDir/src/main/java",
"$projectDir/src/main/kotlin",
),
)
executionData.setFrom(
project.fileTree("$buildDir/outputs/unit_test_code_coverage/${variant.name}UnitTest")
.matching { include("**/*.exec") },
project.fileTree("$buildDir/outputs/code_coverage/${variant.name}AndroidTest")
.matching { include("**/*.ec") },
)
}
variant.artifacts.forScope(ScopedArtifacts.Scope.PROJECT).use(reportTask).toGet(
ScopedArtifact.CLASSES,
{ _ -> allJars },
{ _ -> allDirectories },
)
}
tasks.withType<Test>().configureEach {
configure<JacocoTaskExtension> {
// Required for JaCoCo + Robolectric
// https://github.com/robolectric/robolectric/issues/2230
isIncludeNoLocationClasses = true
// Required for JDK 11 with the above
// https://github.com/gradle/gradle/issues/5184#issuecomment-391982009
excludes = listOf("jdk.internal.*")
}
}
}
| Geto/build-logic/convention/src/main/kotlin/com/android/geto/Jacoco.kt | 2737086719 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.benchmarks.settings
import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.test.uiautomator.By
import com.android.geto.benchmarks.waitForLoadingWheelToDisappear
fun MacrobenchmarkScope.goToSettingsScreen() {
waitForLoadingWheelToDisappear()
clickSettingsIcon()
device.waitForIdle()
}
private fun MacrobenchmarkScope.clickSettingsIcon() {
val settingsIcon = device.findObject(By.desc("Settings icon"))
settingsIcon.click()
}
| Geto/benchmarks/src/main/kotlin/com/android/geto/benchmarks/settings/SettingsAction.kt | 884885734 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.benchmarks.baselineprofile
import androidx.benchmark.macro.junit4.BaselineProfileRule
import com.android.geto.benchmarks.PACKAGE_NAME
import com.android.geto.benchmarks.appsettings.goToAppSettingsScreen
import org.junit.Rule
import org.junit.Test
class AppSettingsBaselineProfile {
@get:Rule
val baselineProfileRule = BaselineProfileRule()
@Test
fun generate() = baselineProfileRule.collect(PACKAGE_NAME) {
startActivityAndWait()
goToAppSettingsScreen()
}
}
| Geto/benchmarks/src/main/kotlin/com/android/geto/benchmarks/baselineprofile/AppSettingsBaselineProfile.kt | 2250442003 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.benchmarks.baselineprofile
import androidx.benchmark.macro.junit4.BaselineProfileRule
import com.android.geto.benchmarks.PACKAGE_NAME
import com.android.geto.benchmarks.apps.appsScrollDownUp
import com.android.geto.benchmarks.waitForLoadingWheelToDisappear
import org.junit.Rule
import org.junit.Test
class AppsBaselineProfile {
@get:Rule
val baselineProfileRule = BaselineProfileRule()
@Test
fun generate() = baselineProfileRule.collect(PACKAGE_NAME) {
startActivityAndWait()
waitForLoadingWheelToDisappear()
appsScrollDownUp()
}
}
| Geto/benchmarks/src/main/kotlin/com/android/geto/benchmarks/baselineprofile/AppsBaselineProfile.kt | 2384742512 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.benchmarks.baselineprofile
import androidx.benchmark.macro.junit4.BaselineProfileRule
import com.android.geto.benchmarks.PACKAGE_NAME
import com.android.geto.benchmarks.settings.goToSettingsScreen
import org.junit.Rule
import org.junit.Test
class SettingsBaselineProfile {
@get:Rule
val baselineProfileRule = BaselineProfileRule()
@Test
fun generate() = baselineProfileRule.collect(PACKAGE_NAME) {
goToSettingsScreen()
}
}
| Geto/benchmarks/src/main/kotlin/com/android/geto/benchmarks/baselineprofile/SettingsBaselineProfile.kt | 881741957 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.benchmarks.baselineprofile
import androidx.benchmark.macro.junit4.BaselineProfileRule
import com.android.geto.benchmarks.PACKAGE_NAME
import org.junit.Rule
import org.junit.Test
/**
* Baseline Profile for app startup. This profile also enables using [Dex Layout Optimizations](https://developer.android.com/topic/performance/baselineprofiles/dex-layout-optimizations)
* via the `includeInStartupProfile` parameter.
*/
class StartupBaselineProfile {
@get:Rule
val baselineProfileRule = BaselineProfileRule()
@Test
fun generate() = baselineProfileRule.collect(
PACKAGE_NAME,
includeInStartupProfile = true,
profileBlock = {
startActivityAndWait()
},
)
}
| Geto/benchmarks/src/main/kotlin/com/android/geto/benchmarks/baselineprofile/StartupBaselineProfile.kt | 3011225103 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.benchmarks
import androidx.test.uiautomator.Direction
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiObject2
const val PACKAGE_NAME = "com.android.geto"
fun UiDevice.flingElementDownUp(element: UiObject2) {
// Set some margin from the sides to prevent triggering system navigation
element.setGestureMargin(displayWidth / 5)
element.fling(Direction.DOWN)
waitForIdle()
element.fling(Direction.UP)
}
| Geto/benchmarks/src/main/kotlin/com/android/geto/benchmarks/Utils.kt | 1882837595 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.benchmarks
import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Until
fun MacrobenchmarkScope.waitForLoadingWheelToDisappear() {
device.wait(Until.gone(By.res("loadingWheel")), 5_000)
}
| Geto/benchmarks/src/main/kotlin/com/android/geto/benchmarks/GeneralActions.kt | 368438477 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.benchmarks.appsettings
import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.test.uiautomator.By
import com.android.geto.benchmarks.apps.appsClickFirstItem
import com.android.geto.benchmarks.waitForLoadingWheelToDisappear
import org.junit.Assert.fail
fun MacrobenchmarkScope.goToAppSettingsScreen() {
waitForLoadingWheelToDisappear()
appsClickFirstItem()
device.waitForIdle()
getTopAppBar()
waitForLoadingWheelToDisappear()
openAppSettingsDialog()
openShortcutDialog()
}
private fun MacrobenchmarkScope.getTopAppBar() {
val topAppBar = device.findObject(By.res("appSettings:topAppBar"))
if (topAppBar.text.isNullOrEmpty()) fail("No application found.")
}
private fun MacrobenchmarkScope.openAppSettingsDialog() {
val settingsIcon = device.findObject(By.desc("Settings icon"))
settingsIcon.click()
device.waitForIdle()
val dialog = device.findObject(By.desc("Add App Settings Dialog"))
val dialogCancelButton = dialog.findObject(By.text("Cancel"))
dialogCancelButton.click()
device.waitForIdle()
}
private fun MacrobenchmarkScope.openShortcutDialog() {
val settingsIcon = device.findObject(By.desc("Shortcut icon"))
settingsIcon.click()
device.waitForIdle()
val dialog = device.findObject(By.desc("Add Shortcut Dialog"))
val dialogCancelButton = dialog.findObject(By.text("Cancel"))
dialogCancelButton.click()
device.waitForIdle()
}
| Geto/benchmarks/src/main/kotlin/com/android/geto/benchmarks/appsettings/AppSettingsAction.kt | 3531992145 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.benchmarks.startup
import androidx.benchmark.macro.BaselineProfileMode.Disable
import androidx.benchmark.macro.BaselineProfileMode.Require
import androidx.benchmark.macro.CompilationMode
import androidx.benchmark.macro.StartupMode.COLD
import androidx.benchmark.macro.StartupTimingMetric
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import com.android.geto.benchmarks.PACKAGE_NAME
import com.android.geto.benchmarks.waitForLoadingWheelToDisappear
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
/**
* Enables app startups from various states of baseline profile or [CompilationMode]s.
* Run this benchmark from Studio to see startup measurements, and captured system traces
* for investigating your app's performance from a cold state.
*/
@RunWith(AndroidJUnit4ClassRunner::class)
class StartupBenchmark {
@get:Rule
val benchmarkRule = MacrobenchmarkRule()
@Test
fun startupWithoutPreCompilation() = startup(CompilationMode.None())
@Test
fun startupWithPartialCompilationAndDisabledBaselineProfile() = startup(
CompilationMode.Partial(baselineProfileMode = Disable, warmupIterations = 1),
)
@Test
fun startupPrecompiledWithBaselineProfile() =
startup(CompilationMode.Partial(baselineProfileMode = Require))
@Test
fun startupFullyPrecompiled() = startup(CompilationMode.Full())
private fun startup(compilationMode: CompilationMode) = benchmarkRule.measureRepeated(
packageName = PACKAGE_NAME,
metrics = listOf(StartupTimingMetric()),
compilationMode = compilationMode,
// More iterations result in higher statistical significance.
iterations = 20,
startupMode = COLD,
setupBlock = {
pressHome()
},
) {
startActivityAndWait()
// Waits until the content is ready to capture Time To Full Display
waitForLoadingWheelToDisappear()
}
}
| Geto/benchmarks/src/main/kotlin/com/android/geto/benchmarks/startup/StartupBenchmark.kt | 1836874252 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.benchmarks.apps
import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.test.uiautomator.By
import com.android.geto.benchmarks.flingElementDownUp
fun MacrobenchmarkScope.appsScrollDownUp() {
val appList = device.findObject(By.res("apps:lazyColumn"))
device.flingElementDownUp(appList)
}
fun MacrobenchmarkScope.appsClickFirstItem() {
val appList = device.findObject(By.res("apps:lazyColumn"))
val firstItem = appList.findObject(By.res("apps:appItem"))
firstItem.click()
}
| Geto/benchmarks/src/main/kotlin/com/android/geto/benchmarks/apps/AppsActions.kt | 1396884521 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.benchmarks.apps
import androidx.benchmark.macro.CompilationMode
import androidx.benchmark.macro.FrameTimingMetric
import androidx.benchmark.macro.StartupMode
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import com.android.geto.benchmarks.PACKAGE_NAME
import com.android.geto.benchmarks.waitForLoadingWheelToDisappear
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4ClassRunner::class)
class ScrollAppListBenchmark {
@get:Rule
val benchmarkRule = MacrobenchmarkRule()
@Test
fun scrollAppListCompilationNone() = scrollAppList(CompilationMode.None())
@Test
fun scrollAppListCompilationBaselineProfile() = scrollAppList(CompilationMode.Partial())
@Test
fun scrollAppListCompilationFull() = scrollAppList(CompilationMode.Full())
private fun scrollAppList(compilationMode: CompilationMode) = benchmarkRule.measureRepeated(
packageName = PACKAGE_NAME,
metrics = listOf(FrameTimingMetric()),
compilationMode = compilationMode,
iterations = 10,
startupMode = StartupMode.WARM,
setupBlock = {
pressHome()
startActivityAndWait()
},
) {
waitForLoadingWheelToDisappear()
appsScrollDownUp()
}
}
| Geto/benchmarks/src/main/kotlin/com/android/geto/benchmarks/apps/ScrollAppListBenchmark.kt | 1670973667 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.feature.settings
import androidx.activity.ComponentActivity
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsNotDisplayed
import androidx.compose.ui.test.assertIsOff
import androidx.compose.ui.test.assertIsOn
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithTag
import com.android.geto.core.model.DarkThemeConfig
import com.android.geto.core.model.ThemeBrand
import com.android.geto.core.model.UserData
import org.junit.Rule
import org.junit.Test
class SettingsScreenTest {
@get:Rule
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
@Test
fun getoLoadingWheel_isDisplayed_whenSettingsUiState_isLoading() {
composeTestRule.setContent {
SettingsScreen(
settingsUiState = SettingsUiState.Loading,
supportDynamicColor = false,
onUpdateThemeBrand = {},
onUpdateDarkThemeConfig = {},
onCleanAppSettings = {},
onChangeDynamicColorPreference = {},
onChangeAutoLaunchPreference = {},
onNavigationIconClick = {},
)
}
composeTestRule.onNodeWithContentDescription("GetoLoadingWheel").assertIsDisplayed()
}
@Test
fun settings_isDisplayed_whenSettingsUiState_isSuccess() {
composeTestRule.setContent {
SettingsScreen(
settingsUiState = SettingsUiState.Success(
UserData(
themeBrand = ThemeBrand.DEFAULT,
useDynamicColor = true,
darkThemeConfig = DarkThemeConfig.FOLLOW_SYSTEM,
useAutoLaunch = false,
),
),
supportDynamicColor = false,
onUpdateThemeBrand = {},
onUpdateDarkThemeConfig = {},
onCleanAppSettings = {},
onChangeDynamicColorPreference = {},
onChangeAutoLaunchPreference = {},
onNavigationIconClick = {},
)
}
composeTestRule.onNodeWithTag("settings:success").assertIsDisplayed()
}
@Test
fun dynamicColorSwitch_isOn_whenUseDynamicColor_isTrue() {
composeTestRule.setContent {
SettingsScreen(
settingsUiState = SettingsUiState.Success(
UserData(
themeBrand = ThemeBrand.DEFAULT,
useDynamicColor = true,
darkThemeConfig = DarkThemeConfig.FOLLOW_SYSTEM,
useAutoLaunch = false,
),
),
supportDynamicColor = true,
onUpdateThemeBrand = {},
onUpdateDarkThemeConfig = {},
onCleanAppSettings = {},
onChangeDynamicColorPreference = {},
onChangeAutoLaunchPreference = {},
onNavigationIconClick = {},
)
}
composeTestRule.onNodeWithTag("settings:dynamicSwitch").assertIsOn()
}
@Test
fun dynamicColorSwitch_isOff_whenUseDynamicColor_isFalse() {
composeTestRule.setContent {
SettingsScreen(
settingsUiState = SettingsUiState.Success(
UserData(
themeBrand = ThemeBrand.DEFAULT,
useDynamicColor = false,
darkThemeConfig = DarkThemeConfig.FOLLOW_SYSTEM,
useAutoLaunch = false,
),
),
supportDynamicColor = true,
onUpdateThemeBrand = {},
onUpdateDarkThemeConfig = {},
onCleanAppSettings = {},
onChangeDynamicColorPreference = {},
onChangeAutoLaunchPreference = {},
onNavigationIconClick = {},
)
}
composeTestRule.onNodeWithTag("settings:dynamicSwitch").assertIsOff()
}
@Test
fun dynamicRow_isDisplayed_whenThemeBrand_isDefault() {
composeTestRule.setContent {
SettingsScreen(
settingsUiState = SettingsUiState.Success(
UserData(
themeBrand = ThemeBrand.DEFAULT,
useDynamicColor = true,
darkThemeConfig = DarkThemeConfig.FOLLOW_SYSTEM,
useAutoLaunch = false,
),
),
supportDynamicColor = true,
onUpdateThemeBrand = {},
onUpdateDarkThemeConfig = {},
onCleanAppSettings = {},
onChangeDynamicColorPreference = {},
onChangeAutoLaunchPreference = {},
onNavigationIconClick = {},
)
}
composeTestRule.onNodeWithTag("settings:dynamic").assertIsDisplayed()
}
@Test
fun dynamicRow_isNotDisplayed_whenThemeBrand_isAndroid() {
composeTestRule.setContent {
SettingsScreen(
settingsUiState = SettingsUiState.Success(
UserData(
themeBrand = ThemeBrand.ANDROID,
useDynamicColor = true,
darkThemeConfig = DarkThemeConfig.FOLLOW_SYSTEM,
useAutoLaunch = false,
),
),
supportDynamicColor = false,
onUpdateThemeBrand = {},
onUpdateDarkThemeConfig = {},
onCleanAppSettings = {},
onChangeDynamicColorPreference = {},
onChangeAutoLaunchPreference = {},
onNavigationIconClick = {},
)
}
composeTestRule.onNodeWithTag("settings:dynamic").assertIsNotDisplayed()
}
@Test
fun dynamicRow_isNotDisplayed_whenUnSupportDynamicColor() {
composeTestRule.setContent {
SettingsScreen(
settingsUiState = SettingsUiState.Success(
UserData(
themeBrand = ThemeBrand.DEFAULT,
useDynamicColor = true,
darkThemeConfig = DarkThemeConfig.FOLLOW_SYSTEM,
useAutoLaunch = false,
),
),
supportDynamicColor = false,
onUpdateThemeBrand = {},
onUpdateDarkThemeConfig = {},
onCleanAppSettings = {},
onChangeDynamicColorPreference = {},
onChangeAutoLaunchPreference = {},
onNavigationIconClick = {},
)
}
composeTestRule.onNodeWithTag("settings:dynamic").assertIsNotDisplayed()
}
@Test
fun autoLaunchSwitch_isOff_whenUseAutoLaunch_isFalse() {
composeTestRule.setContent {
SettingsScreen(
settingsUiState = SettingsUiState.Success(
UserData(
themeBrand = ThemeBrand.DEFAULT,
useDynamicColor = true,
darkThemeConfig = DarkThemeConfig.FOLLOW_SYSTEM,
useAutoLaunch = false,
),
),
supportDynamicColor = true,
onUpdateThemeBrand = {},
onUpdateDarkThemeConfig = {},
onCleanAppSettings = {},
onChangeDynamicColorPreference = {},
onChangeAutoLaunchPreference = {},
onNavigationIconClick = {},
)
}
composeTestRule.onNodeWithTag("settings:autoLaunchSwitch").assertIsOff()
}
@Test
fun autoLaunchSwitch_isOn_whenUseAutoLaunch_isTrue() {
composeTestRule.setContent {
SettingsScreen(
settingsUiState = SettingsUiState.Success(
UserData(
themeBrand = ThemeBrand.DEFAULT,
useDynamicColor = true,
darkThemeConfig = DarkThemeConfig.FOLLOW_SYSTEM,
useAutoLaunch = true,
),
),
supportDynamicColor = true,
onUpdateThemeBrand = {},
onUpdateDarkThemeConfig = {},
onCleanAppSettings = {},
onChangeDynamicColorPreference = {},
onChangeAutoLaunchPreference = {},
onNavigationIconClick = {},
)
}
composeTestRule.onNodeWithTag("settings:autoLaunchSwitch").assertIsOn()
}
}
| Geto/feature/settings/src/androidTest/kotlin/com/android/geto/feature/settings/SettingsScreenTest.kt | 1402419866 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.feature.settings
import androidx.activity.ComponentActivity
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsNotDisplayed
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.android.geto.core.model.DarkThemeConfig
import com.android.geto.core.model.ThemeBrand
import com.android.geto.core.model.UserData
import org.junit.Rule
import org.junit.Test
class SettingsScreenDialogsTest {
@get:Rule
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
@Test
fun themeDialog_isDisplayed_whenThemeSetting_isClicked_thenDismissed() {
composeTestRule.setContent {
SettingsScreen(
settingsUiState = SettingsUiState.Success(
UserData(
themeBrand = ThemeBrand.DEFAULT,
useDynamicColor = true,
darkThemeConfig = DarkThemeConfig.FOLLOW_SYSTEM,
useAutoLaunch = true,
),
),
supportDynamicColor = true,
onUpdateThemeBrand = {},
onUpdateDarkThemeConfig = {},
onCleanAppSettings = {},
onChangeDynamicColorPreference = {},
onChangeAutoLaunchPreference = {},
onNavigationIconClick = {},
)
}
composeTestRule.onNodeWithTag("settings:theme").performClick()
composeTestRule.onNodeWithContentDescription("Theme Dialog").assertIsDisplayed()
composeTestRule.onNodeWithText("Cancel").performClick()
composeTestRule.onNodeWithContentDescription("Theme Dialog").assertIsNotDisplayed()
}
@Test
fun darkDialog_isDisplayed_whenDarkSetting_isClicked_thenDismissed() {
composeTestRule.setContent {
SettingsScreen(
settingsUiState = SettingsUiState.Success(
UserData(
themeBrand = ThemeBrand.DEFAULT,
useDynamicColor = true,
darkThemeConfig = DarkThemeConfig.FOLLOW_SYSTEM,
useAutoLaunch = true,
),
),
supportDynamicColor = true,
onUpdateThemeBrand = {},
onUpdateDarkThemeConfig = {},
onCleanAppSettings = {},
onChangeDynamicColorPreference = {},
onChangeAutoLaunchPreference = {},
onNavigationIconClick = {},
)
}
composeTestRule.onNodeWithTag("settings:dark").performClick()
composeTestRule.onNodeWithContentDescription("Dark Dialog").assertIsDisplayed()
composeTestRule.onNodeWithText("Cancel").performClick()
composeTestRule.onNodeWithContentDescription("Dark Dialog").assertIsNotDisplayed()
}
@Test
fun cleanDialog_isDisplayed_whenCleanSetting_isClicked_thenDismissed() {
composeTestRule.setContent {
SettingsScreen(
settingsUiState = SettingsUiState.Success(
UserData(
themeBrand = ThemeBrand.DEFAULT,
useDynamicColor = true,
darkThemeConfig = DarkThemeConfig.FOLLOW_SYSTEM,
useAutoLaunch = true,
),
),
supportDynamicColor = true,
onUpdateThemeBrand = {},
onUpdateDarkThemeConfig = {},
onCleanAppSettings = {},
onChangeDynamicColorPreference = {},
onChangeAutoLaunchPreference = {},
onNavigationIconClick = {},
)
}
composeTestRule.onNodeWithTag("settings:clean").performClick()
composeTestRule.onNodeWithContentDescription("Clean Dialog").assertIsDisplayed()
composeTestRule.onNodeWithText("Cancel").performClick()
composeTestRule.onNodeWithContentDescription("Clean Dialog").assertIsNotDisplayed()
}
}
| Geto/feature/settings/src/androidTest/kotlin/com/android/geto/feature/settings/SettingsScreenDialogsTest.kt | 507414926 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.feature.settings
import com.android.geto.core.domain.CleanAppSettingsUseCase
import com.android.geto.core.model.DarkThemeConfig
import com.android.geto.core.model.ThemeBrand
import com.android.geto.core.model.UserData
import com.android.geto.core.testing.repository.TestAppSettingsRepository
import com.android.geto.core.testing.repository.TestPackageRepository
import com.android.geto.core.testing.repository.TestUserDataRepository
import com.android.geto.core.testing.util.MainDispatcherRule
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import kotlin.test.assertEquals
class SettingsViewModelTest {
@get:Rule
val mainDispatcherRule = MainDispatcherRule()
private val userDataRepository = TestUserDataRepository()
private val packageRepository = TestPackageRepository()
private val appSettingsRepository = TestAppSettingsRepository()
private lateinit var viewModel: SettingsViewModel
@Before
fun setUp() {
viewModel = SettingsViewModel(
userDataRepository = userDataRepository,
cleanAppSettingsUseCase = CleanAppSettingsUseCase(
packageRepository = packageRepository,
appSettingsRepository = appSettingsRepository,
),
)
}
@Test
fun settingsUiState_isLoading_whenStarted() {
assertEquals(SettingsUiState.Loading, viewModel.settingsUiState.value)
}
@Test
fun settingsUiState_isSuccess() = runTest {
userDataRepository.setThemeBrand(ThemeBrand.ANDROID)
userDataRepository.setDarkThemeConfig(DarkThemeConfig.DARK)
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.settingsUiState.collect() }
assertEquals(
SettingsUiState.Success(
UserData(
themeBrand = ThemeBrand.ANDROID,
darkThemeConfig = DarkThemeConfig.DARK,
useDynamicColor = false,
useAutoLaunch = false,
),
),
viewModel.settingsUiState.value,
)
collectJob.cancel()
}
}
| Geto/feature/settings/src/test/kotlin/com/android/geto/feature/settings/SettingsViewModelTest.kt | 4233284894 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.feature.settings
import androidx.activity.ComponentActivity
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import com.android.geto.core.designsystem.component.GetoBackground
import com.android.geto.core.designsystem.theme.GetoTheme
import com.android.geto.core.model.DarkThemeConfig
import com.android.geto.core.model.ThemeBrand
import com.android.geto.core.model.UserData
import com.android.geto.core.screenshot.testing.util.DefaultTestDevices
import com.android.geto.core.screenshot.testing.util.captureForDevice
import dagger.hilt.android.testing.HiltTestApplication
import org.junit.Rule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode
import org.robolectric.annotation.LooperMode
import kotlin.test.Test
@RunWith(RobolectricTestRunner::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
@Config(application = HiltTestApplication::class)
@LooperMode(LooperMode.Mode.PAUSED)
class SettingsScreenScreenshotTest {
@get:Rule
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
@Test
fun settingsScreen_populated() {
composeTestRule.captureForDevice(
deviceName = "tablet",
deviceSpec = DefaultTestDevices.TABLET.spec,
fileName = "SettingsScreenPopulated",
) {
GetoTheme {
SettingsScreen(
settingsUiState = SettingsUiState.Success(
userData = UserData(
themeBrand = ThemeBrand.DEFAULT,
useDynamicColor = false,
darkThemeConfig = DarkThemeConfig.DARK,
useAutoLaunch = false,
),
),
supportDynamicColor = true,
onUpdateThemeBrand = {},
onUpdateDarkThemeConfig = {},
onCleanAppSettings = {},
onChangeDynamicColorPreference = {},
onChangeAutoLaunchPreference = {},
onNavigationIconClick = {},
)
}
}
}
@Test
fun settingsScreen_loading() {
composeTestRule.captureForDevice(
deviceName = "tablet",
deviceSpec = DefaultTestDevices.TABLET.spec,
fileName = "SettingsScreenLoading",
) {
GetoTheme {
SettingsScreen(
settingsUiState = SettingsUiState.Loading,
supportDynamicColor = true,
onUpdateThemeBrand = {},
onUpdateDarkThemeConfig = {},
onCleanAppSettings = {},
onChangeDynamicColorPreference = {},
onChangeAutoLaunchPreference = {},
onNavigationIconClick = {},
)
}
}
}
@Test
fun settingsScreen_populated_dark() {
composeTestRule.captureForDevice(
deviceName = "tablet_dark",
deviceSpec = DefaultTestDevices.TABLET.spec,
fileName = "SettingsScreenPopulated",
darkMode = true,
) {
GetoTheme {
GetoBackground {
SettingsScreen(
settingsUiState = SettingsUiState.Success(
userData = UserData(
themeBrand = ThemeBrand.DEFAULT,
useDynamicColor = false,
darkThemeConfig = DarkThemeConfig.DARK,
useAutoLaunch = false,
),
),
supportDynamicColor = true,
onUpdateThemeBrand = {},
onUpdateDarkThemeConfig = {},
onCleanAppSettings = {},
onChangeDynamicColorPreference = {},
onChangeAutoLaunchPreference = {},
onNavigationIconClick = {},
)
}
}
}
}
@Test
fun settingsScreen_loading_dark() {
composeTestRule.captureForDevice(
deviceName = "tablet_dark",
deviceSpec = DefaultTestDevices.TABLET.spec,
fileName = "SettingsScreenLoading",
darkMode = true,
) {
GetoTheme {
GetoBackground {
SettingsScreen(
settingsUiState = SettingsUiState.Loading,
supportDynamicColor = true,
onUpdateThemeBrand = {},
onUpdateDarkThemeConfig = {},
onCleanAppSettings = {},
onChangeDynamicColorPreference = {},
onChangeAutoLaunchPreference = {},
onNavigationIconClick = {},
)
}
}
}
}
}
| Geto/feature/settings/src/test/kotlin/com/android/geto/feature/settings/SettingsScreenScreenshotTest.kt | 1704906585 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.feature.settings
import com.android.geto.core.model.UserData
sealed interface SettingsUiState {
data object Loading : SettingsUiState
data class Success(val userData: UserData) : SettingsUiState
}
| Geto/feature/settings/src/main/kotlin/com/android/geto/feature/settings/SettingsUiState.kt | 1858656401 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.feature.settings.navigation
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import com.android.geto.feature.settings.SettingsRoute
const val SETTINGS_NAVIGATION_ROUTE = "settings_route"
fun NavController.navigateToSettings() {
navigate(SETTINGS_NAVIGATION_ROUTE)
}
fun NavGraphBuilder.settingsScreen(
onNavigationIconClick: () -> Unit,
) {
composable(
route = SETTINGS_NAVIGATION_ROUTE,
) {
SettingsRoute(
onNavigationIconClick = onNavigationIconClick,
)
}
}
| Geto/feature/settings/src/main/kotlin/com/android/geto/feature/settings/navigation/SettingsNavigation.kt | 3693901615 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.feature.settings
import androidx.annotation.VisibleForTesting
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.consumeWindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.android.geto.core.designsystem.component.GetoLoadingWheel
import com.android.geto.core.designsystem.component.SimpleDialog
import com.android.geto.core.designsystem.component.SingleSelectionDialog
import com.android.geto.core.designsystem.icon.GetoIcons
import com.android.geto.core.designsystem.theme.GetoTheme
import com.android.geto.core.designsystem.theme.supportsDynamicTheming
import com.android.geto.core.model.DarkThemeConfig
import com.android.geto.core.model.ThemeBrand
import com.android.geto.core.model.UserData
import com.android.geto.core.ui.DevicePreviews
@Composable
internal fun SettingsRoute(
modifier: Modifier = Modifier,
viewModel: SettingsViewModel = hiltViewModel(),
onNavigationIconClick: () -> Unit,
) {
val settingsUiState = viewModel.settingsUiState.collectAsStateWithLifecycle().value
SettingsScreen(
modifier = modifier,
settingsUiState = settingsUiState,
onUpdateThemeBrand = viewModel::updateThemeBrand,
onUpdateDarkThemeConfig = viewModel::updateDarkThemeConfig,
onCleanAppSettings = viewModel::cleanAppSettings,
onChangeDynamicColorPreference = viewModel::updateDynamicColorPreference,
onChangeAutoLaunchPreference = viewModel::updateAutoLaunchPreference,
onNavigationIconClick = onNavigationIconClick,
)
}
@VisibleForTesting
@Composable
internal fun SettingsScreen(
modifier: Modifier = Modifier,
settingsUiState: SettingsUiState,
scrollState: ScrollState = rememberScrollState(),
supportDynamicColor: Boolean = supportsDynamicTheming(),
onUpdateThemeBrand: (ThemeBrand) -> Unit,
onUpdateDarkThemeConfig: (DarkThemeConfig) -> Unit,
onCleanAppSettings: () -> Unit,
onChangeDynamicColorPreference: (useDynamicColor: Boolean) -> Unit,
onChangeAutoLaunchPreference: (useAutoLaunch: Boolean) -> Unit,
onNavigationIconClick: () -> Unit,
) {
var showThemeDialog by rememberSaveable { mutableStateOf(false) }
var showDarkDialog by rememberSaveable { mutableStateOf(false) }
var showCleanDialog by rememberSaveable { mutableStateOf(false) }
Scaffold(
topBar = {
SettingsTopAppBAr(onNavigationIconClick = onNavigationIconClick)
},
) { innerPadding ->
Box(
modifier = modifier
.fillMaxSize()
.consumeWindowInsets(innerPadding)
.verticalScroll(scrollState)
.testTag("applist"),
) {
when (settingsUiState) {
SettingsUiState.Loading -> LoadingState(
modifier = Modifier.align(Alignment.Center),
)
is SettingsUiState.Success -> {
SettingsScreenDialogs(
settingsUiState = settingsUiState,
showThemeDialog = showThemeDialog,
showDarkDialog = showDarkDialog,
showCleanDialog = showCleanDialog,
onUpdateThemeBrand = onUpdateThemeBrand,
onUpdateDarkThemeConfig = onUpdateDarkThemeConfig,
onCleanAppSettings = onCleanAppSettings,
onThemeDialogDismissRequest = {
showThemeDialog = false
},
onDarkDialogDismissRequest = {
showDarkDialog = false
},
onCleanDialogDismissRequest = {
showCleanDialog = false
},
)
SuccessState(
contentPadding = innerPadding,
settingsUiState = settingsUiState,
supportDynamicColor = supportDynamicColor,
onShowThemeDialog = { showThemeDialog = true },
onShowDarkDialog = { showDarkDialog = true },
onShowCleanDialog = { showCleanDialog = true },
onChangeDynamicColorPreference = onChangeDynamicColorPreference,
onChangeAutoLaunchPreference = onChangeAutoLaunchPreference,
)
}
}
}
}
}
@Composable
private fun SettingsScreenDialogs(
settingsUiState: SettingsUiState.Success,
showThemeDialog: Boolean,
showDarkDialog: Boolean,
showCleanDialog: Boolean,
onUpdateThemeBrand: (ThemeBrand) -> Unit,
onUpdateDarkThemeConfig: (DarkThemeConfig) -> Unit,
onCleanAppSettings: () -> Unit,
onThemeDialogDismissRequest: () -> Unit,
onDarkDialogDismissRequest: () -> Unit,
onCleanDialogDismissRequest: () -> Unit,
) {
var themeDialogSelected by remember {
mutableIntStateOf(
ThemeBrand.entries.indexOf(
settingsUiState.userData.themeBrand,
),
)
}
var darkDialogSelected by remember {
mutableIntStateOf(
DarkThemeConfig.entries.indexOf(
settingsUiState.userData.darkThemeConfig,
),
)
}
if (showThemeDialog) {
SingleSelectionDialog(
title = stringResource(id = R.string.theme),
items = arrayOf(
stringResource(R.string.default_theme),
stringResource(R.string.android_theme),
),
onDismissRequest = onThemeDialogDismissRequest,
selected = themeDialogSelected,
onSelect = { themeDialogSelected = it },
negativeButtonText = stringResource(id = R.string.cancel),
positiveButtonText = stringResource(id = R.string.change),
onNegativeButtonClick = onThemeDialogDismissRequest,
onPositiveButtonClick = {
onUpdateThemeBrand(ThemeBrand.entries[themeDialogSelected])
onThemeDialogDismissRequest()
},
contentDescription = "Theme Dialog",
)
}
if (showDarkDialog) {
SingleSelectionDialog(
title = stringResource(id = R.string.theme),
items = arrayOf(
stringResource(id = R.string.follow_system),
stringResource(id = R.string.light),
stringResource(id = R.string.dark),
),
onDismissRequest = onDarkDialogDismissRequest,
selected = darkDialogSelected,
onSelect = { darkDialogSelected = it },
negativeButtonText = stringResource(id = R.string.cancel),
positiveButtonText = stringResource(id = R.string.change),
onNegativeButtonClick = onDarkDialogDismissRequest,
onPositiveButtonClick = {
onUpdateDarkThemeConfig(DarkThemeConfig.entries[darkDialogSelected])
onDarkDialogDismissRequest()
},
contentDescription = "Dark Dialog",
)
}
if (showCleanDialog) {
SimpleDialog(
title = stringResource(id = R.string.clean_app_settings),
text = stringResource(id = R.string.are_you_sure_you_want_to_clean_app_settings_from_the_uninstalled_applications),
onDismissRequest = onCleanDialogDismissRequest,
negativeButtonText = stringResource(id = R.string.cancel),
positiveButtonText = stringResource(id = R.string.clean),
onNegativeButtonClick = onCleanDialogDismissRequest,
onPositiveButtonClick = {
onCleanAppSettings()
onCleanDialogDismissRequest()
},
contentDescription = "Clean Dialog",
)
}
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun SettingsTopAppBAr(onNavigationIconClick: () -> Unit) {
TopAppBar(
title = {
Text(text = stringResource(id = R.string.settings))
},
navigationIcon = {
IconButton(onClick = onNavigationIconClick) {
Icon(imageVector = GetoIcons.Back, contentDescription = "Navigation icon")
}
},
)
}
@Composable
private fun LoadingState(modifier: Modifier = Modifier) {
GetoLoadingWheel(
modifier = modifier,
contentDescription = "GetoLoadingWheel",
)
}
@Composable
private fun SuccessState(
modifier: Modifier = Modifier,
contentPadding: PaddingValues,
settingsUiState: SettingsUiState.Success,
supportDynamicColor: Boolean = supportsDynamicTheming(),
onShowThemeDialog: () -> Unit,
onShowDarkDialog: () -> Unit,
onShowCleanDialog: () -> Unit,
onChangeDynamicColorPreference: (useDynamicColor: Boolean) -> Unit,
onChangeAutoLaunchPreference: (useAutoLaunch: Boolean) -> Unit,
) {
Column(
modifier = modifier
.consumeWindowInsets(contentPadding)
.padding(contentPadding)
.testTag("settings:success"),
) {
ThemeSetting(
settingsUiState = settingsUiState,
onThemeDialog = onShowThemeDialog,
)
DynamicSetting(
settingsUiState = settingsUiState,
supportDynamicColor = supportDynamicColor,
onChangeDynamicColorPreference = onChangeDynamicColorPreference,
)
DarkSetting(
settingsUiState = settingsUiState,
onDarkDialog = onShowDarkDialog,
)
SettingHorizontalDivider(categoryTitle = stringResource(R.string.application))
AutoLaunchSetting(
settingsUiState = settingsUiState,
onChangeAutoLaunchPreference = onChangeAutoLaunchPreference,
)
CleanSetting(onCleanDialog = onShowCleanDialog)
}
}
@Composable
private fun ThemeSetting(
modifier: Modifier = Modifier,
settingsUiState: SettingsUiState.Success,
onThemeDialog: () -> Unit,
) {
Column(
modifier = modifier
.fillMaxWidth()
.clickable { onThemeDialog() }
.padding(10.dp)
.testTag("settings:theme"),
) {
Text(text = stringResource(R.string.theme), style = MaterialTheme.typography.bodyLarge)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = settingsUiState.userData.themeBrand.title,
style = MaterialTheme.typography.bodySmall,
)
}
}
@Composable
private fun DynamicSetting(
modifier: Modifier = Modifier,
settingsUiState: SettingsUiState.Success,
supportDynamicColor: Boolean = supportsDynamicTheming(),
onChangeDynamicColorPreference: (Boolean) -> Unit,
) {
if (settingsUiState.userData.themeBrand == ThemeBrand.DEFAULT && supportDynamicColor) {
Spacer(modifier = Modifier.height(8.dp))
Row(
modifier = modifier
.fillMaxWidth()
.padding(10.dp)
.testTag("settings:dynamic"),
verticalAlignment = Alignment.CenterVertically,
) {
Column(modifier = Modifier.weight(1f)) {
Text(
text = stringResource(R.string.dynamic_color),
style = MaterialTheme.typography.bodyLarge,
)
Spacer(modifier = Modifier.height(4.dp))
Text(
text = stringResource(R.string.available_on_android_12),
style = MaterialTheme.typography.bodySmall,
)
}
Switch(
modifier = Modifier.testTag("settings:dynamicSwitch"),
checked = settingsUiState.userData.useDynamicColor,
onCheckedChange = onChangeDynamicColorPreference,
)
}
}
}
@Composable
private fun DarkSetting(
modifier: Modifier = Modifier,
settingsUiState: SettingsUiState.Success,
onDarkDialog: () -> Unit,
) {
Spacer(modifier = Modifier.height(8.dp))
Column(
modifier = modifier
.fillMaxWidth()
.clickable { onDarkDialog() }
.padding(10.dp)
.testTag("settings:dark"),
) {
Text(
text = stringResource(R.string.dark_mode),
style = MaterialTheme.typography.bodyLarge,
)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = settingsUiState.userData.darkThemeConfig.title,
style = MaterialTheme.typography.bodySmall,
)
}
}
@Composable
private fun SettingHorizontalDivider(modifier: Modifier = Modifier, categoryTitle: String) {
Spacer(modifier = Modifier.height(8.dp))
HorizontalDivider(
modifier = modifier
.fillMaxWidth()
.padding(horizontal = 10.dp),
)
Spacer(modifier = Modifier.height(8.dp))
Text(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 10.dp),
text = categoryTitle,
color = MaterialTheme.colorScheme.primary,
style = MaterialTheme.typography.bodySmall,
)
}
@Composable
private fun AutoLaunchSetting(
modifier: Modifier = Modifier,
settingsUiState: SettingsUiState.Success,
onChangeAutoLaunchPreference: (useAutoLaunch: Boolean) -> Unit,
) {
Spacer(modifier = Modifier.height(8.dp))
Row(
modifier = modifier
.fillMaxWidth()
.padding(10.dp)
.testTag("settings:autoLaunch"),
verticalAlignment = Alignment.CenterVertically,
) {
Column(modifier = Modifier.weight(1f)) {
Text(
text = stringResource(R.string.auto_launch),
style = MaterialTheme.typography.bodyLarge,
)
Spacer(modifier = Modifier.height(4.dp))
Text(
text = stringResource(R.string.automatically_launch_the_selected_application),
style = MaterialTheme.typography.bodySmall,
)
}
Switch(
modifier = Modifier.testTag("settings:autoLaunchSwitch"),
checked = settingsUiState.userData.useAutoLaunch,
onCheckedChange = onChangeAutoLaunchPreference,
)
}
}
@Composable
private fun CleanSetting(
modifier: Modifier = Modifier,
onCleanDialog: () -> Unit,
) {
Spacer(modifier = Modifier.height(8.dp))
Column(
modifier = modifier
.fillMaxWidth()
.clickable { onCleanDialog() }
.padding(10.dp)
.testTag("settings:clean"),
) {
Text(text = "Clean App Settings", style = MaterialTheme.typography.bodyLarge)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = "Remove all app settings from the uninstalled applications",
style = MaterialTheme.typography.bodySmall,
)
}
}
@DevicePreviews
@Composable
private fun SettingsScreenLoadingStatePreview() {
GetoTheme {
SettingsScreen(
settingsUiState = SettingsUiState.Loading,
supportDynamicColor = false,
onUpdateThemeBrand = {},
onUpdateDarkThemeConfig = {},
onCleanAppSettings = {},
onChangeDynamicColorPreference = {},
onChangeAutoLaunchPreference = {},
onNavigationIconClick = {},
)
}
}
@DevicePreviews
@Composable
private fun SettingsScreenSuccessStatePreview() {
GetoTheme {
SettingsScreen(
settingsUiState = SettingsUiState.Success(
userData = UserData(
themeBrand = ThemeBrand.DEFAULT,
useDynamicColor = true,
darkThemeConfig = DarkThemeConfig.DARK,
useAutoLaunch = false,
),
),
supportDynamicColor = false,
onUpdateThemeBrand = {},
onUpdateDarkThemeConfig = {},
onCleanAppSettings = {},
onChangeDynamicColorPreference = {},
onChangeAutoLaunchPreference = {},
onNavigationIconClick = {},
)
}
}
| Geto/feature/settings/src/main/kotlin/com/android/geto/feature/settings/SettingsScreen.kt | 2011433281 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.feature.settings
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.android.geto.core.data.repository.UserDataRepository
import com.android.geto.core.domain.CleanAppSettingsUseCase
import com.android.geto.core.model.DarkThemeConfig
import com.android.geto.core.model.ThemeBrand
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.SharingStarted.Companion.WhileSubscribed
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import javax.inject.Inject
@HiltViewModel
class SettingsViewModel @Inject constructor(
private val userDataRepository: UserDataRepository,
private val cleanAppSettingsUseCase: CleanAppSettingsUseCase,
) : ViewModel() {
val settingsUiState: StateFlow<SettingsUiState> =
userDataRepository.userData.map(SettingsUiState::Success).stateIn(
scope = viewModelScope,
started = WhileSubscribed(5_000),
initialValue = SettingsUiState.Loading,
)
fun updateThemeBrand(themeBrand: ThemeBrand) {
viewModelScope.launch {
userDataRepository.setThemeBrand(themeBrand)
}
}
fun updateDarkThemeConfig(darkThemeConfig: DarkThemeConfig) {
viewModelScope.launch {
userDataRepository.setDarkThemeConfig(darkThemeConfig)
}
}
fun updateDynamicColorPreference(useDynamicColor: Boolean) {
viewModelScope.launch {
userDataRepository.setDynamicColorPreference(useDynamicColor)
}
}
fun updateAutoLaunchPreference(useAutoLaunch: Boolean) {
viewModelScope.launch {
userDataRepository.setAutoLaunchPreference(useAutoLaunch)
}
}
fun cleanAppSettings() {
viewModelScope.launch {
cleanAppSettingsUseCase()
}
}
}
| Geto/feature/settings/src/main/kotlin/com/android/geto/feature/settings/SettingsViewModel.kt | 693399952 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.feature.appsettings
import androidx.activity.ComponentActivity
import androidx.compose.material3.SnackbarHostState
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithTag
import com.android.geto.core.data.repository.ClipboardResult
import com.android.geto.core.data.repository.ShortcutResult
import com.android.geto.core.domain.AppSettingsResult
import com.android.geto.core.model.AppSetting
import com.android.geto.core.model.SettingType
import org.junit.Rule
import org.junit.Test
class AppSettingsScreenTest {
@get:Rule
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
private val appSettings = List(5) { index ->
AppSetting(
id = index,
enabled = true,
settingType = SettingType.SYSTEM,
packageName = "com.android.geto",
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
@Test
fun getoLoadingWheel_isDisplayed_whenAppSettingsUiState_isLoading() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Loading,
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.NoResult,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.NoResult,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithContentDescription("GetoLoadingWheel").assertIsDisplayed()
}
@Test
fun emptyListPlaceHolderScreen_isDisplayed_whenAppSettings_isEmpty() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Success(emptyList()),
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.NoResult,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.NoResult,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithTag("appSettings:emptyListPlaceHolderScreen").assertIsDisplayed()
}
@Test
fun lazyColumn_isDisplayed_whenAppSettingsUiState_isSuccess() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Success(appSettings),
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.NoResult,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.NoResult,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithTag("appSettings:lazyColumn").assertIsDisplayed()
}
}
| Geto/feature/appsettings/src/androidTest/kotlin/com/android/geto/feature/appsettings/AppSettingsScreenTest.kt | 1501855653 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.feature.appsettings
import androidx.activity.ComponentActivity
import androidx.compose.material3.SnackbarHostState
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsNotDisplayed
import androidx.compose.ui.test.assertIsSelected
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.hasAnyAncestor
import androidx.compose.ui.test.hasContentDescription
import androidx.compose.ui.test.hasParent
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.isDialog
import androidx.compose.ui.test.junit4.StateRestorationTester
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput
import com.android.geto.core.data.repository.ClipboardResult
import com.android.geto.core.data.repository.ShortcutResult
import com.android.geto.core.domain.AppSettingsResult
import com.android.geto.core.model.TargetShortcutInfoCompat
import org.junit.Rule
import org.junit.Test
class AppSettingsScreenDialogsTest {
@get:Rule
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
@Test
fun appSettingDialog_isDisplayed_whenSettingsIcon_isClicked_thenDismissed() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Loading,
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.NoResult,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.NoResult,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithContentDescription(
label = "Settings icon",
useUnmergedTree = true,
).performClick()
composeTestRule.onNodeWithContentDescription("Add App Settings Dialog").assertIsDisplayed()
composeTestRule.onNodeWithText("Cancel").performClick()
composeTestRule.onNodeWithContentDescription("Add App Settings Dialog")
.assertIsNotDisplayed()
}
@Test
fun copyPermissionCommandDialog_isDisplayed_whenApplyAppSettingsResult_isSecurityException_thenDismissed() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Loading,
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.SecurityException,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.NoResult,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithContentDescription("Copy Permission Command Dialog")
.assertIsDisplayed()
composeTestRule.onNodeWithText("Cancel").performClick()
composeTestRule.onNodeWithContentDescription("Copy Permission Command Dialog")
.assertIsNotDisplayed()
}
@Test
fun copyPermissionCommandDialog_isDisplayed_whenRevertAppSettingsResult_isSecurityException_thenDismissed() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Loading,
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.NoResult,
revertAppSettingsResult = AppSettingsResult.SecurityException,
shortcutResult = ShortcutResult.NoResult,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithContentDescription("Copy Permission Command Dialog")
.assertIsDisplayed()
composeTestRule.onNodeWithText("Cancel").performClick()
composeTestRule.onNodeWithContentDescription("Copy Permission Command Dialog")
.assertIsNotDisplayed()
}
@Test
fun addShortcutDialog_isDisplayed_whenShortcutResult_isNoShortcutFound_thenDismissed() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Loading,
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.NoResult,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.NoShortcutFound,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithContentDescription("Add Shortcut Dialog").assertIsDisplayed()
composeTestRule.onNodeWithText("Cancel").performClick()
composeTestRule.onNodeWithContentDescription("Add Shortcut Dialog").assertIsNotDisplayed()
}
@Test
fun updateShortcutDialog_isDisplayed_whenShortcutResult_isShortcutFound_thenDismissed() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Loading,
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.NoResult,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.ShortcutFound(
targetShortcutInfoCompat = TargetShortcutInfoCompat(
id = "0",
shortLabel = "Geto",
longLabel = "Geto",
),
),
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithContentDescription("Update Shortcut Dialog").assertIsDisplayed()
composeTestRule.onNodeWithText("Cancel").performClick()
composeTestRule.onNodeWithContentDescription("Update Shortcut Dialog")
.assertIsNotDisplayed()
}
@Test
fun appSettingDialog_stateRestoration() {
val restorationTester = StateRestorationTester(composeTestRule)
restorationTester.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Loading,
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.NoResult,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.NoResult,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithContentDescription("Settings icon").performClick()
composeTestRule.onNode(
matcher = hasAnyAncestor(isDialog()) and hasContentDescription("Secure"),
useUnmergedTree = true,
).performClick()
composeTestRule.onNode(
matcher = hasAnyAncestor(isDialog()) and hasTestTag("appSettingDialog:labelTextField"),
useUnmergedTree = true,
).performTextInput("Geto")
composeTestRule.onNode(
matcher = hasAnyAncestor(isDialog()) and hasTestTag("appSettingDialog:keyTextField"),
useUnmergedTree = true,
).performTextInput("Geto")
composeTestRule.onNode(
matcher = hasAnyAncestor(isDialog()) and hasTestTag("appSettingDialog:valueOnLaunchTextField"),
useUnmergedTree = true,
).performTextInput("Geto")
composeTestRule.onNode(
matcher = hasAnyAncestor(isDialog()) and hasTestTag("appSettingDialog:valueOnRevertTextField"),
useUnmergedTree = true,
).performTextInput("Geto")
restorationTester.emulateSavedInstanceStateRestore()
composeTestRule.onNode(matcher = hasParent(isDialog()) and hasContentDescription("Add App Settings Dialog"))
.assertIsDisplayed()
composeTestRule.onNode(
matcher = hasAnyAncestor(isDialog()) and hasContentDescription("Secure"),
useUnmergedTree = true,
).assertIsSelected()
composeTestRule.onNode(
matcher = hasAnyAncestor(isDialog()) and hasTestTag("appSettingDialog:labelTextField"),
useUnmergedTree = true,
).assertTextEquals("Geto")
composeTestRule.onNode(
matcher = hasAnyAncestor(isDialog()) and hasTestTag("appSettingDialog:keyTextField"),
useUnmergedTree = true,
).assertTextEquals("Geto")
composeTestRule.onNode(
matcher = hasAnyAncestor(isDialog()) and hasTestTag("appSettingDialog:valueOnLaunchTextField"),
useUnmergedTree = true,
).assertTextEquals("Geto")
composeTestRule.onNode(
matcher = hasAnyAncestor(isDialog()) and hasTestTag("appSettingDialog:valueOnRevertTextField"),
useUnmergedTree = true,
).assertTextEquals("Geto")
}
@Test
fun shortcutDialog_stateRestoration() {
val restorationTester = StateRestorationTester(composeTestRule)
restorationTester.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Loading,
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.NoResult,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.NoShortcutFound,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNode(
matcher = hasAnyAncestor(isDialog()) and hasTestTag("shortcutDialog:shortLabelTextField"),
useUnmergedTree = true,
).performTextInput("Geto")
composeTestRule.onNode(
matcher = hasAnyAncestor(isDialog()) and hasTestTag("shortcutDialog:longLabelTextField"),
useUnmergedTree = true,
).performTextInput("Geto")
restorationTester.emulateSavedInstanceStateRestore()
composeTestRule.onNode(matcher = hasParent(isDialog()) and hasContentDescription("Add Shortcut Dialog"))
.assertIsDisplayed()
composeTestRule.onNode(
matcher = hasAnyAncestor(isDialog()) and hasTestTag("shortcutDialog:shortLabelTextField"),
useUnmergedTree = true,
).assertTextEquals("Geto")
composeTestRule.onNode(
matcher = hasAnyAncestor(isDialog()) and hasTestTag("shortcutDialog:longLabelTextField"),
useUnmergedTree = true,
).assertTextEquals("Geto")
}
}
| Geto/feature/appsettings/src/androidTest/kotlin/com/android/geto/feature/appsettings/AppSettingsScreenDialogsTest.kt | 2956402218 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.feature.appsettings
import androidx.activity.ComponentActivity
import androidx.compose.material3.SnackbarHostState
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithTag
import com.android.geto.core.data.repository.ClipboardResult
import com.android.geto.core.data.repository.ShortcutResult
import com.android.geto.core.domain.AppSettingsResult
import org.junit.Rule
import org.junit.Test
class AppSettingsScreenSnackbarTest {
@get:Rule
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
@Test
fun snackbar_isShown_whenApplyAppSettingsResult_isDisabledAppSettings() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Success(emptyList()),
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.DisabledAppSettings,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.NoResult,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithTag("appSettings:snackbar").assertExists()
}
@Test
fun snackbar_isShown_whenApplyAppSettingsResult_isEmptyAppSettings() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Success(emptyList()),
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.EmptyAppSettings,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.NoResult,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithTag("appSettings:snackbar").assertExists()
}
@Test
fun snackbar_isShown_whenApplyAppSettingsResult_isFailure() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Success(emptyList()),
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.Failure,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.NoResult,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithTag("appSettings:snackbar").assertExists()
}
@Test
fun snackbar_isShown_whenApplyAppSettingsResult_isIllegalArgumentException() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Success(emptyList()),
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.IllegalArgumentException,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.NoResult,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithTag("appSettings:snackbar").assertExists()
}
@Test
fun snackbar_isShown_whenShortcutResult_isIDNotFound() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Success(emptyList()),
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.NoResult,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.IDNotFound,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithTag("appSettings:snackbar").assertExists()
}
@Test
fun snackbar_isShown_whenShortcutResult_isShortcutDisableImmutableShortcuts() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Success(emptyList()),
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.NoResult,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.ShortcutDisableImmutableShortcuts,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithTag("appSettings:snackbar").assertExists()
}
@Test
fun snackbar_isShown_whenShortcutResult_isShortcutUpdateFailed() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Success(emptyList()),
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.NoResult,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.ShortcutUpdateFailed,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithTag("appSettings:snackbar").assertExists()
}
@Test
fun snackbar_isShown_whenShortcutResult_isShortcutUpdateImmutableShortcuts() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Success(emptyList()),
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.NoResult,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.ShortcutUpdateImmutableShortcuts,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithTag("appSettings:snackbar").assertExists()
}
@Test
fun snackbar_isShown_whenShortcutResult_isShortcutUpdateSuccess() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Success(emptyList()),
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.NoResult,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.ShortcutUpdateSuccess,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithTag("appSettings:snackbar").assertExists()
}
@Test
fun snackbar_isShown_whenShortcutResult_isSupportedLauncher() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Success(emptyList()),
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.NoResult,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.SupportedLauncher,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithTag("appSettings:snackbar").assertExists()
}
@Test
fun snackbar_isShown_whenShortcutResult_isUnSupportedLauncher() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Success(emptyList()),
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.NoResult,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.UnsupportedLauncher,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithTag("appSettings:snackbar").assertExists()
}
@Test
fun snackbar_isShown_whenShortcutResult_isUserIsLocked() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Success(emptyList()),
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.NoResult,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.UserIsLocked,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithTag("appSettings:snackbar").assertExists()
}
@Test
fun snackbar_isShown_whenClipboardResult_isNotify() {
composeTestRule.setContent {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Success(emptyList()),
snackbarHostState = SnackbarHostState(),
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.NoResult,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.NoResult,
clipboardResult = ClipboardResult.Notify("Text is copied to clipboard"),
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
composeTestRule.onNodeWithTag("appSettings:snackbar").assertExists()
}
}
| Geto/feature/appsettings/src/androidTest/kotlin/com/android/geto/feature/appsettings/AppSettingsScreenSnackbarTest.kt | 2691236136 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.feature.appsettings.dialog.shortcut
import androidx.activity.ComponentActivity
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.android.geto.feature.appsettings.R
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue
@HiltAndroidTest
class ShortcutDialogTest {
@get:Rule
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
private lateinit var shortcutDialogState: ShortcutDialogState
@Before
fun setup() {
shortcutDialogState = ShortcutDialogState()
}
@Test
fun counterSupportingTexts_areDisplayed_withEmptyCharacters() {
shortcutDialogState.updateShortLabel("")
shortcutDialogState.updateLongLabel("")
composeTestRule.setContent {
ShortcutDialog(
shortcutDialogState = shortcutDialogState,
packageName = "com.android.geto",
contentDescription = "Shortcut Dialog",
title = stringResource(id = R.string.add_shortcut),
negativeButtonText = stringResource(id = R.string.cancel),
positiveButtonText = stringResource(id = R.string.add),
onPositiveButtonClick = {
assertTrue(shortcutDialogState.showDialog)
},
)
}
composeTestRule.onNodeWithTag(
testTag = "shortcutDialog:shortLabelCounterSupportingText",
useUnmergedTree = true,
).assertTextEquals("0/${shortcutDialogState.shortLabelMaxLength}")
composeTestRule.onNodeWithTag(
testTag = "shortcutDialog:longLabelCounterSupportingText",
useUnmergedTree = true,
).assertTextEquals("0/${shortcutDialogState.longLabelMaxLength}")
}
@Test
fun shortLabelSupportingText_isDisplayed_whenShortLabelTextField_isBlank() {
shortcutDialogState.updateShortLabel("")
shortcutDialogState.updateLongLabel("Geto")
composeTestRule.setContent {
ShortcutDialog(
shortcutDialogState = shortcutDialogState,
packageName = "com.android.geto",
contentDescription = "Shortcut Dialog",
title = stringResource(id = R.string.add_shortcut),
negativeButtonText = stringResource(id = R.string.cancel),
positiveButtonText = stringResource(id = R.string.add),
onPositiveButtonClick = {
assertTrue(shortcutDialogState.showDialog)
},
)
}
composeTestRule.onNodeWithText("Add").performClick()
composeTestRule.onNodeWithTag(
testTag = "shortcutDialog:shortLabelSupportingText",
useUnmergedTree = true,
).assertIsDisplayed()
}
@Test
fun shortLabelCounterSupportingText_isDisplayed_whenShortLabelTextField_isFilledWithCharacters() {
composeTestRule.setContent {
shortcutDialogState.updateShortLabel("qwerty")
shortcutDialogState.updateLongLabel("")
ShortcutDialog(
shortcutDialogState = shortcutDialogState,
packageName = "com.android.geto",
contentDescription = "Shortcut Dialog",
title = stringResource(id = R.string.add_shortcut),
negativeButtonText = stringResource(id = R.string.cancel),
positiveButtonText = stringResource(id = R.string.add),
onPositiveButtonClick = {
assertTrue(shortcutDialogState.showDialog)
},
)
}
composeTestRule.onNodeWithTag(
testTag = "shortcutDialog:shortLabelCounterSupportingText",
useUnmergedTree = true,
)
.assertTextEquals("${shortcutDialogState.shortLabel.length}/${shortcutDialogState.shortLabelMaxLength}")
}
@Test
fun longLabelCounterSupportingText_isDisplayed_whenLongLabelTextField_isFilledWithCharacters() {
shortcutDialogState.updateShortLabel("")
shortcutDialogState.updateLongLabel("qwerty")
composeTestRule.setContent {
ShortcutDialog(
shortcutDialogState = shortcutDialogState,
packageName = "com.android.geto",
contentDescription = "Shortcut Dialog",
title = stringResource(id = R.string.add_shortcut),
negativeButtonText = stringResource(id = R.string.cancel),
positiveButtonText = stringResource(id = R.string.add),
onPositiveButtonClick = {
assertTrue(shortcutDialogState.showDialog)
},
)
}
composeTestRule.onNodeWithTag(
testTag = "shortcutDialog:longLabelCounterSupportingText",
useUnmergedTree = true,
)
.assertTextEquals("${shortcutDialogState.longLabel.length}/${shortcutDialogState.longLabelMaxLength}")
}
@Test
fun longLabelSupportingText_isDisplayed_whenLongLabelTextField_isBlank() {
shortcutDialogState.updateShortLabel("Geto")
shortcutDialogState.updateLongLabel("")
composeTestRule.setContent {
ShortcutDialog(
shortcutDialogState = shortcutDialogState,
packageName = "com.android.geto",
contentDescription = "Shortcut Dialog",
title = stringResource(id = R.string.add_shortcut),
negativeButtonText = stringResource(id = R.string.cancel),
positiveButtonText = stringResource(id = R.string.add),
onPositiveButtonClick = {
assertTrue(shortcutDialogState.showDialog)
},
)
}
composeTestRule.onNodeWithText("Add").performClick()
composeTestRule.onNodeWithTag(
testTag = "shortcutDialog:longLabelSupportingText",
useUnmergedTree = true,
).assertIsDisplayed()
}
@Test
fun shortcutDialog_isDismissed() {
shortcutDialogState.updateShortLabel("Geto")
shortcutDialogState.updateLongLabel("Geto")
composeTestRule.setContent {
ShortcutDialog(
shortcutDialogState = shortcutDialogState,
packageName = "com.android.geto",
contentDescription = "Shortcut Dialog",
title = stringResource(id = R.string.add_shortcut),
negativeButtonText = stringResource(id = R.string.cancel),
positiveButtonText = stringResource(id = R.string.add),
onPositiveButtonClick = {
assertFalse(shortcutDialogState.showDialog)
},
)
}
composeTestRule.onNodeWithText("Add").performClick()
}
}
| Geto/feature/appsettings/src/androidTest/kotlin/com/android/geto/feature/appsettings/dialog/shortcut/ShortcutDialogTest.kt | 3855468178 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.feature.appsettings.dialog.appsetting
import androidx.activity.ComponentActivity
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.android.geto.core.model.SecureSetting
import com.android.geto.core.model.SettingType
import org.junit.Rule
import org.junit.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class AppSettingDialogTest {
@get:Rule
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
private val secureSettings = List(5) { index ->
SecureSetting(
settingType = SettingType.SYSTEM,
id = index.toLong(),
name = "Geto $index",
value = "0",
)
}
@Test
fun labelSupportingText_isDisplayed_whenLabelTextField_isBlank() {
composeTestRule.setContent {
val appSettingDialogState = rememberAppSettingDialogState()
appSettingDialogState.updateSecureSettings(secureSettings)
appSettingDialogState.updateSelectedRadioOptionIndex(1)
appSettingDialogState.updateKey("Geto 1")
appSettingDialogState.updateLabel("")
appSettingDialogState.updateValueOnLaunch("Geto")
appSettingDialogState.updateValueOnRevert("Geto")
AppSettingDialog(
appSettingDialogState = appSettingDialogState,
packageName = "com.android.geto",
onAddSetting = {
assertTrue(appSettingDialogState.showDialog)
},
contentDescription = "Add App Setting Dialog",
)
}
composeTestRule.onNodeWithText("Add").performClick()
composeTestRule.onNodeWithTag(
testTag = "appSettingDialog:labelSupportingText",
useUnmergedTree = true,
).assertIsDisplayed()
}
@Test
fun keySupportingText_isDisplayed_whenKeyTextField_isBlank() {
composeTestRule.setContent {
val appSettingDialogState = rememberAppSettingDialogState()
appSettingDialogState.updateSecureSettings(secureSettings)
appSettingDialogState.updateSelectedRadioOptionIndex(1)
appSettingDialogState.updateLabel("Geto")
appSettingDialogState.updateKey("")
appSettingDialogState.updateValueOnLaunch("Geto")
appSettingDialogState.updateValueOnRevert("Geto")
AppSettingDialog(
appSettingDialogState = appSettingDialogState,
packageName = "com.android.geto",
onAddSetting = {
assertTrue(appSettingDialogState.showDialog)
},
contentDescription = "Add App Setting Dialog",
)
}
composeTestRule.onNodeWithText("Add").performClick()
composeTestRule.onNodeWithTag(
testTag = "appSettingDialog:keySupportingText",
useUnmergedTree = true,
).assertIsDisplayed()
}
@Test
fun settingsKeyNotFoundSupportingText_isDisplayed_whenSettingsKey_notFound() {
composeTestRule.setContent {
val appSettingDialogState = rememberAppSettingDialogState()
appSettingDialogState.updateSecureSettings(secureSettings)
appSettingDialogState.updateSelectedRadioOptionIndex(1)
appSettingDialogState.updateLabel("Geto")
appSettingDialogState.updateKey("_")
appSettingDialogState.updateValueOnLaunch("Geto")
appSettingDialogState.updateValueOnRevert("Geto")
AppSettingDialog(
appSettingDialogState = appSettingDialogState,
packageName = "com.android.geto",
onAddSetting = {
assertTrue(appSettingDialogState.showDialog)
},
contentDescription = "Add App Setting Dialog",
)
}
composeTestRule.onNodeWithText("Add").performClick()
composeTestRule.onNodeWithTag(
testTag = "appSettingDialog:settingsKeyNotFoundSupportingText",
useUnmergedTree = true,
).assertIsDisplayed()
}
@Test
fun valueOnLaunchSupportingText_isDisplayed_whenValueOnLaunchTextField_isBlank() {
composeTestRule.setContent {
val appSettingDialogState = rememberAppSettingDialogState()
appSettingDialogState.updateSecureSettings(secureSettings)
appSettingDialogState.updateSelectedRadioOptionIndex(1)
appSettingDialogState.updateKey("Geto 1")
appSettingDialogState.updateLabel("Geto")
appSettingDialogState.updateValueOnLaunch("")
appSettingDialogState.updateValueOnRevert("Geto")
AppSettingDialog(
appSettingDialogState = appSettingDialogState,
packageName = "com.android.geto",
onAddSetting = {
assertTrue(appSettingDialogState.showDialog)
},
contentDescription = "Add App Setting Dialog",
)
}
composeTestRule.onNodeWithText("Add").performClick()
composeTestRule.onNodeWithTag(
testTag = "appSettingDialog:valueOnLaunchSupportingText",
useUnmergedTree = true,
).assertIsDisplayed()
}
@Test
fun valueOnRevertSupportingText_isDisplayed_whenValueOnRevertTextField_isBlank() {
composeTestRule.setContent {
val appSettingDialogState = rememberAppSettingDialogState()
appSettingDialogState.updateSecureSettings(secureSettings)
appSettingDialogState.updateSelectedRadioOptionIndex(1)
appSettingDialogState.updateKey("Geto 1")
appSettingDialogState.updateLabel("Geto")
appSettingDialogState.updateValueOnLaunch("Geto")
appSettingDialogState.updateValueOnRevert("")
AppSettingDialog(
appSettingDialogState = appSettingDialogState,
packageName = "com.android.geto",
onAddSetting = {
assertTrue(appSettingDialogState.showDialog)
},
contentDescription = "Add App Setting Dialog",
)
}
composeTestRule.onNodeWithText("Add").performClick()
composeTestRule.onNodeWithTag(
testTag = "appSettingDialog:valueOnRevertSupportingText",
useUnmergedTree = true,
).assertIsDisplayed()
}
@Test
fun exposedDropdownMenuBox_isDisplayed_whenSecureSettingsListExpanded_isTrue() {
composeTestRule.setContent {
val appSettingDialogState = rememberAppSettingDialogState()
appSettingDialogState.updateSecureSettings(secureSettings)
AppSettingDialog(
appSettingDialogState = appSettingDialogState,
packageName = "com.android.geto",
onAddSetting = {
assertTrue(appSettingDialogState.showDialog)
},
contentDescription = "Add App Setting Dialog",
)
}
composeTestRule.onNodeWithTag("appSettingDialog:keyTextField").performClick()
composeTestRule.onNodeWithTag(
testTag = "appSettingDialog:exposedDropdownMenuBox",
).assertIsDisplayed()
}
@Test
fun keyTextField_has_value_whenSecureSettingsListItem_isClicked() {
composeTestRule.setContent {
val appSettingDialogState = rememberAppSettingDialogState()
appSettingDialogState.updateSecureSettings(secureSettings)
AppSettingDialog(
appSettingDialogState = appSettingDialogState,
packageName = "com.android.geto",
onAddSetting = {
assertTrue(appSettingDialogState.showDialog)
},
contentDescription = "Add App Setting Dialog",
)
}
composeTestRule.onNodeWithTag("appSettingDialog:keyTextField").performClick()
composeTestRule.onNodeWithText("Geto 1").performClick()
composeTestRule.waitForIdle()
composeTestRule.onNodeWithTag(
testTag = "appSettingDialog:keyTextField",
).assertTextEquals("Setting key", "Geto 1")
composeTestRule.onNodeWithTag(
testTag = "appSettingDialog:valueOnRevertTextField",
).assertTextEquals("Setting value on revert", "0")
}
@Test
fun appSettingDialog_isDismissed() {
composeTestRule.setContent {
val appSettingDialogState = rememberAppSettingDialogState()
appSettingDialogState.updateSecureSettings(secureSettings)
appSettingDialogState.updateSelectedRadioOptionIndex(1)
appSettingDialogState.updateKey("Geto 1")
appSettingDialogState.updateLabel("Geto")
appSettingDialogState.updateValueOnLaunch("1")
appSettingDialogState.updateValueOnRevert("0")
AppSettingDialog(
appSettingDialogState = appSettingDialogState,
packageName = "com.android.geto",
onAddSetting = {
assertFalse(appSettingDialogState.showDialog)
},
contentDescription = "Add App Setting Dialog",
)
}
composeTestRule.onNodeWithText("Add").performClick()
}
}
| Geto/feature/appsettings/src/androidTest/kotlin/com/android/geto/feature/appsettings/dialog/appsetting/AppSettingDialogTest.kt | 3642184294 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.feature.appsettings.dialog.shortcut
import androidx.activity.ComponentActivity
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import com.android.geto.core.designsystem.component.GetoBackground
import com.android.geto.core.designsystem.theme.GetoTheme
import com.android.geto.core.screenshot.testing.util.DefaultTestDevices
import com.android.geto.core.screenshot.testing.util.captureDialogForDevice
import com.android.geto.feature.appsettings.R
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.HiltTestApplication
import org.junit.Before
import org.junit.Rule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode
import org.robolectric.annotation.LooperMode
import kotlin.test.Test
@HiltAndroidTest
@RunWith(RobolectricTestRunner::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
@Config(application = HiltTestApplication::class)
@LooperMode(LooperMode.Mode.PAUSED)
class ShortcutDialogScreenshotTest {
@get:Rule
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
private lateinit var shortcutDialogState: ShortcutDialogState
@Before
fun setUp() {
shortcutDialogState = ShortcutDialogState()
}
@Test
fun shortcutDialog_empty() {
composeTestRule.captureDialogForDevice(
name = "ShortcutDialog",
fileName = "ShortcutDialogEmpty",
deviceName = "tablet",
deviceSpec = DefaultTestDevices.TABLET.spec,
) {
GetoTheme {
ShortcutDialog(
shortcutDialogState = shortcutDialogState,
packageName = "com.android.geto",
contentDescription = "Shortcut Dialog",
title = stringResource(id = R.string.add_shortcut),
negativeButtonText = stringResource(id = R.string.cancel),
positiveButtonText = stringResource(id = R.string.add),
onPositiveButtonClick = {},
)
}
}
}
@Test
fun shortcutDialog_filled_textfields() {
shortcutDialogState.updateShortLabel("Short Label")
shortcutDialogState.updateLongLabel("Long Label")
composeTestRule.captureDialogForDevice(
name = "ShortcutDialog",
fileName = "ShortcutDialogFilledTextFields",
deviceName = "tablet",
deviceSpec = DefaultTestDevices.TABLET.spec,
) {
GetoTheme {
ShortcutDialog(
shortcutDialogState = shortcutDialogState,
packageName = "com.android.geto",
contentDescription = "Shortcut Dialog",
title = stringResource(id = R.string.add_shortcut),
negativeButtonText = stringResource(id = R.string.cancel),
positiveButtonText = stringResource(id = R.string.add),
onPositiveButtonClick = {},
)
}
}
}
@Test
fun shortcutDialog_error_textfields() {
shortcutDialogState.getShortcut(packageName = "Test")
composeTestRule.captureDialogForDevice(
name = "ShortcutDialog",
fileName = "ShortcutDialogErrorTextFields",
deviceName = "tablet",
deviceSpec = DefaultTestDevices.TABLET.spec,
) {
GetoTheme {
ShortcutDialog(
shortcutDialogState = shortcutDialogState,
packageName = "com.android.geto",
contentDescription = "Shortcut Dialog",
title = stringResource(id = R.string.add_shortcut),
negativeButtonText = stringResource(id = R.string.cancel),
positiveButtonText = stringResource(id = R.string.add),
onPositiveButtonClick = {},
)
}
}
}
@Test
fun shortcutDialog_empty_dark() {
composeTestRule.captureDialogForDevice(
name = "ShortcutDialog",
fileName = "ShortcutDialogEmpty",
deviceName = "tablet_dark",
deviceSpec = DefaultTestDevices.TABLET.spec,
darkMode = true,
) {
GetoTheme {
GetoBackground {
ShortcutDialog(
shortcutDialogState = shortcutDialogState,
packageName = "com.android.geto",
contentDescription = "Shortcut Dialog",
title = stringResource(id = R.string.add_shortcut),
negativeButtonText = stringResource(id = R.string.cancel),
positiveButtonText = stringResource(id = R.string.add),
onPositiveButtonClick = {},
)
}
}
}
}
@Test
fun shortcutDialog_filled_textfields_dark() {
shortcutDialogState.updateShortLabel("Short Label")
shortcutDialogState.updateLongLabel("Long Label")
composeTestRule.captureDialogForDevice(
name = "ShortcutDialog",
fileName = "ShortcutDialogFilledTextFields",
deviceName = "tablet_dark",
deviceSpec = DefaultTestDevices.TABLET.spec,
darkMode = true,
) {
GetoTheme {
GetoBackground {
ShortcutDialog(
shortcutDialogState = shortcutDialogState,
packageName = "com.android.geto",
contentDescription = "Add Shortcut Dialog",
title = stringResource(id = R.string.add_shortcut),
negativeButtonText = stringResource(id = R.string.cancel),
positiveButtonText = stringResource(id = R.string.add),
onPositiveButtonClick = {},
)
}
}
}
}
@Test
fun shortcutDialog_error_textfields_dark() {
shortcutDialogState.getShortcut(packageName = "Test")
composeTestRule.captureDialogForDevice(
name = "ShortcutDialog",
fileName = "ShortcutDialogErrorTextFields",
deviceName = "tablet_dark",
deviceSpec = DefaultTestDevices.TABLET.spec,
darkMode = true,
) {
GetoTheme {
GetoBackground {
ShortcutDialog(
shortcutDialogState = shortcutDialogState,
packageName = "com.android.geto",
contentDescription = "Add Shortcut Dialog",
title = stringResource(id = R.string.add_shortcut),
negativeButtonText = stringResource(id = R.string.cancel),
positiveButtonText = stringResource(id = R.string.add),
onPositiveButtonClick = {},
)
}
}
}
}
}
| Geto/feature/appsettings/src/test/kotlin/com/android/geto/feature/appsettings/dialog/shortcut/ShortcutDialogScreenshotTest.kt | 3555323076 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.feature.appsettings.dialog.shortcut
import org.junit.Before
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
class ShortcutDialogStateTest {
private lateinit var shortcutDialogState: ShortcutDialogState
private val packageName = "com.android.geto"
@Before
fun setup() {
shortcutDialogState = ShortcutDialogState()
}
@Test
fun shortLabelError_isNotBlank_whenShortLabel_isBlank() {
shortcutDialogState.updateShortLabel("")
shortcutDialogState.getShortcut(packageName = packageName)
assertTrue(shortcutDialogState.showShortLabelError)
}
@Test
fun shortLabelError_isBlank_whenShortLabel_isNotBlank() {
shortcutDialogState.updateShortLabel("Geto")
shortcutDialogState.getShortcut(packageName = packageName)
assertFalse(shortcutDialogState.showShortLabelError)
}
@Test
fun longLabelError_isNotBlank_whenLongLabel_isBlank() {
shortcutDialogState.updateLongLabel("")
shortcutDialogState.getShortcut(packageName = packageName)
assertTrue(shortcutDialogState.showLongLabelError)
}
@Test
fun longLabelError_isBlank_whenLongLabel_isNotBlank() {
shortcutDialogState.updateLongLabel("Geto")
shortcutDialogState.getShortcut(packageName = packageName)
assertFalse(shortcutDialogState.showLongLabelError)
}
@Test
fun getShortcut_isNotNull_whenAllProperties_areFilled() {
shortcutDialogState.updateShortLabel("Geto")
shortcutDialogState.updateLongLabel("Geto")
assertNotNull(
shortcutDialogState.getShortcut(
packageName = packageName,
),
)
}
@Test
fun shortLabel_isBlank_whenTextLength_exceedsShortLabelMaxLength() {
shortcutDialogState.updateShortLabel("This is a text that exceeds short label max length")
shortcutDialogState.updateLongLabel("")
assertTrue(shortcutDialogState.shortLabel.isBlank())
}
@Test
fun shortLabelLength_isEqualToShortLabelMaxLength_whenTextLength_exceedsShortLabelMaxLength() {
shortcutDialogState.updateShortLabel("Giraffeeee")
shortcutDialogState.updateLongLabel("")
assertEquals(
expected = shortcutDialogState.shortLabelMaxLength,
actual = shortcutDialogState.shortLabel.length,
)
}
@Test
fun longLabel_isBlank_whenTextLength_exceedsLongLabelMaxLength() {
shortcutDialogState.updateShortLabel("")
shortcutDialogState.updateLongLabel("qwertyuiopa")
assertTrue(shortcutDialogState.shortLabel.isBlank())
}
@Test
fun longLabelLength_isEqualToLongLabelMaxLength_whenTextLength_exceedsLongLabelMaxLength() {
shortcutDialogState.updateShortLabel("")
shortcutDialogState.updateLongLabel("qwertyuiopasdfghjklzxcvbn")
assertEquals(
expected = shortcutDialogState.longLabelMaxLength,
actual = shortcutDialogState.longLabel.length,
)
}
}
| Geto/feature/appsettings/src/test/kotlin/com/android/geto/feature/appsettings/dialog/shortcut/ShortcutDialogStateTest.kt | 1240345634 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.feature.appsettings.dialog.appsetting
import com.android.geto.core.model.SecureSetting
import com.android.geto.core.model.SettingType
import org.junit.Before
import org.junit.Test
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
class AppSettingsDialogStateTest {
private lateinit var appSettingDialogState: AppSettingDialogState
private val packageName = "com.android.geto"
@Before
fun setup() {
appSettingDialogState = AppSettingDialogState()
}
@Test
fun labelError_isNotBlank_whenLabel_isBlank() {
appSettingDialogState.updateLabel("")
appSettingDialogState.getAppSetting(packageName = packageName)
assertTrue(appSettingDialogState.showLabelError)
}
@Test
fun labelError_isBlank_whenLabel_isNotBlank() {
appSettingDialogState.updateLabel("Geto")
appSettingDialogState.getAppSetting(packageName = packageName)
assertFalse { appSettingDialogState.showLabelError }
}
@Test
fun keyError_isNotBlank_whenKey_isBlank() {
appSettingDialogState.updateKey("")
appSettingDialogState.getAppSetting(packageName = packageName)
assertTrue(appSettingDialogState.showKeyError)
}
@Test
fun keyError_isBlank_whenKey_isNotBlank() {
appSettingDialogState.updateKey("Geto")
appSettingDialogState.getAppSetting(packageName = packageName)
assertFalse { appSettingDialogState.showKeyError }
}
@Test
fun settingsKeyNotFoundError_isNotBlank_whenSettingsKey_notFound() {
val secureSettings = List(5) { index ->
SecureSetting(
settingType = SettingType.SYSTEM,
id = index.toLong(),
name = "Geto",
value = "0",
)
}
appSettingDialogState.updateSecureSettings(secureSettings)
appSettingDialogState.updateKey("_")
appSettingDialogState.getAppSetting(packageName = packageName)
assertTrue(appSettingDialogState.showKeyNotFoundError)
}
@Test
fun settingsKeyNotFoundError_isBlank_whenSettingsKey_found() {
val secureSettings = List(5) { index ->
SecureSetting(
settingType = SettingType.SYSTEM,
id = index.toLong(),
name = "Geto",
value = "0",
)
}
appSettingDialogState.updateSecureSettings(secureSettings)
appSettingDialogState.updateKey("Geto")
appSettingDialogState.getAppSetting(packageName = packageName)
assertFalse(appSettingDialogState.showKeyNotFoundError)
}
@Test
fun valueOnLaunchError_isNotBlank_whenValueOnLaunch_isBlank() {
appSettingDialogState.updateValueOnLaunch("")
appSettingDialogState.getAppSetting(packageName = packageName)
assertTrue { appSettingDialogState.showValueOnLaunchError }
}
@Test
fun valueOnLaunchError_isBlank_whenValueOnLaunch_isNotBlank() {
appSettingDialogState.updateValueOnLaunch("0")
appSettingDialogState.getAppSetting(packageName = packageName)
assertFalse(appSettingDialogState.showValueOnLaunchError)
}
@Test
fun valueOnRevertError_isNotBlank_whenValueOnRevert_isBlank() {
appSettingDialogState.updateValueOnRevert("")
appSettingDialogState.getAppSetting(packageName = packageName)
assertTrue(appSettingDialogState.showValueOnRevertError)
}
@Test
fun valueOnRevertError_isBlank_whenValueOnRevert_isNotBlank() {
appSettingDialogState.updateValueOnRevert("1")
appSettingDialogState.getAppSetting(packageName = packageName)
assertFalse(appSettingDialogState.showValueOnRevertError)
}
@Test
fun getAppSettings_isNotNull_whenAllProperties_areFilled() {
val secureSettings = List(5) { index ->
SecureSetting(
settingType = SettingType.SYSTEM,
id = index.toLong(),
name = "Geto",
value = "0",
)
}
appSettingDialogState.updateSecureSettings(secureSettings)
appSettingDialogState.updateSelectedRadioOptionIndex(1)
appSettingDialogState.updateKey("Geto")
appSettingDialogState.updateLabel("Geto")
appSettingDialogState.updateValueOnLaunch("0")
appSettingDialogState.updateValueOnRevert("1")
assertNotNull(appSettingDialogState.getAppSetting(packageName = packageName))
}
}
| Geto/feature/appsettings/src/test/kotlin/com/android/geto/feature/appsettings/dialog/appsetting/AppSettingsDialogStateTest.kt | 2104247975 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.feature.appsettings.dialog.appsetting
import androidx.activity.ComponentActivity
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import com.android.geto.core.designsystem.component.GetoBackground
import com.android.geto.core.designsystem.theme.GetoTheme
import com.android.geto.core.screenshot.testing.util.DefaultTestDevices
import com.android.geto.core.screenshot.testing.util.captureDialogForDevice
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.HiltTestApplication
import org.junit.Before
import org.junit.Rule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode
import org.robolectric.annotation.LooperMode
import kotlin.test.Test
@HiltAndroidTest
@RunWith(RobolectricTestRunner::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
@Config(application = HiltTestApplication::class)
@LooperMode(LooperMode.Mode.PAUSED)
class AppSettingDialogScreenshotTest {
@get:Rule
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
private lateinit var appSettingDialogState: AppSettingDialogState
@Before
fun setup() {
appSettingDialogState = AppSettingDialogState()
}
@Test
fun appSettingDialog_empty() {
composeTestRule.captureDialogForDevice(
name = "AppSettingDialog",
fileName = "AppSettingDialogEmpty",
deviceName = "tablet",
deviceSpec = DefaultTestDevices.TABLET.spec,
) {
GetoTheme {
AppSettingDialog(
appSettingDialogState = appSettingDialogState,
packageName = "com.android.geto",
onAddSetting = {},
contentDescription = "AppSettingDialog",
)
}
}
}
@Test
fun appSettingDialog_filled_textfields() {
appSettingDialogState.updateSelectedRadioOptionIndex(1)
appSettingDialogState.updateKey("Geto")
appSettingDialogState.updateLabel("Geto")
appSettingDialogState.updateValueOnLaunch("0")
appSettingDialogState.updateValueOnRevert("1")
composeTestRule.captureDialogForDevice(
name = "AppSettingDialog",
fileName = "AppSettingDialogFilledTextFields",
deviceName = "tablet",
deviceSpec = DefaultTestDevices.TABLET.spec,
) {
GetoTheme {
AppSettingDialog(
appSettingDialogState = appSettingDialogState,
packageName = "com.android.geto",
onAddSetting = {},
contentDescription = "AppSettingDialog",
)
}
}
}
@Test
fun appSettingDialog_error_textfields() {
appSettingDialogState.getAppSetting(packageName = "")
composeTestRule.captureDialogForDevice(
name = "AppSettingDialog",
fileName = "AppSettingDialogErrorTextFields",
deviceName = "tablet",
deviceSpec = DefaultTestDevices.TABLET.spec,
) {
GetoTheme {
AppSettingDialog(
appSettingDialogState = appSettingDialogState,
packageName = "com.android.geto",
onAddSetting = {},
contentDescription = "AppSettingDialog",
)
}
}
}
@Test
fun appSettingDialog_empty_dark() {
composeTestRule.captureDialogForDevice(
name = "AppSettingDialog",
fileName = "AppSettingDialogEmpty",
deviceName = "tablet_dark",
deviceSpec = DefaultTestDevices.TABLET.spec,
darkMode = true,
) {
GetoTheme {
GetoBackground {
AppSettingDialog(
appSettingDialogState = appSettingDialogState,
packageName = "com.android.geto",
onAddSetting = {},
contentDescription = "AppSettingDialog",
)
}
}
}
}
@Test
fun appSettingDialog_filled_textfields_dark() {
appSettingDialogState.updateSelectedRadioOptionIndex(1)
appSettingDialogState.updateKey("Geto")
appSettingDialogState.updateLabel("Geto")
appSettingDialogState.updateValueOnLaunch("0")
appSettingDialogState.updateValueOnRevert("1")
composeTestRule.captureDialogForDevice(
name = "AppSettingDialog",
fileName = "AppSettingDialogFilledTextFields",
deviceName = "tablet_dark",
deviceSpec = DefaultTestDevices.TABLET.spec,
darkMode = true,
) {
GetoTheme {
GetoBackground {
AppSettingDialog(
appSettingDialogState = appSettingDialogState,
packageName = "com.android.geto",
onAddSetting = {},
contentDescription = "AppSettingDialog",
)
}
}
}
}
@Test
fun appSettingDialog_error_textfields_dark() {
appSettingDialogState.getAppSetting(packageName = "")
composeTestRule.captureDialogForDevice(
name = "AppSettingDialog",
fileName = "AppSettingDialogErrorTextFields",
deviceName = "tablet_dark",
deviceSpec = DefaultTestDevices.TABLET.spec,
darkMode = true,
) {
GetoTheme {
GetoBackground {
AppSettingDialog(
appSettingDialogState = appSettingDialogState,
packageName = "com.android.geto",
onAddSetting = {},
contentDescription = "AppSettingDialog",
)
}
}
}
}
}
| Geto/feature/appsettings/src/test/kotlin/com/android/geto/feature/appsettings/dialog/appsetting/AppSettingDialogScreenshotTest.kt | 2175787097 |
/*
*
* Copyright 2023 Einstein Blanco
*
* Licensed under the GNU General Public License v3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.geto.feature.appsettings
import androidx.activity.ComponentActivity
import androidx.compose.material3.SnackbarHostState
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import com.android.geto.core.data.repository.ClipboardResult
import com.android.geto.core.data.repository.ShortcutResult
import com.android.geto.core.designsystem.theme.GetoTheme
import com.android.geto.core.domain.AppSettingsResult
import com.android.geto.core.model.AppSetting
import com.android.geto.core.model.SettingType
import com.android.geto.core.screenshot.testing.util.captureMultiDeviceSnackbar
import com.android.geto.core.testing.util.MainDispatcherRule
import dagger.hilt.android.testing.HiltTestApplication
import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode
import org.robolectric.annotation.LooperMode
import kotlin.test.Test
@RunWith(RobolectricTestRunner::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
@Config(application = HiltTestApplication::class)
@LooperMode(LooperMode.Mode.PAUSED)
class AppSettingsScreenSnackbarScreenshotTest {
@get:Rule
val mainDispatcherRule = MainDispatcherRule()
@get:Rule
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
private val appSettings = List(5) { index ->
AppSetting(
id = index,
enabled = true,
settingType = SettingType.SYSTEM,
packageName = "com.android.geto",
label = "Geto",
key = "Geto $index",
valueOnLaunch = "0",
valueOnRevert = "1",
)
}
@Test
fun appSettingsScreen_snackbar() = runTest {
val snackbarHostState = SnackbarHostState()
composeTestRule.captureMultiDeviceSnackbar(
snackbarHostState = snackbarHostState,
message = "This is a snackbar",
testTag = "appSettings:snackbar",
fileName = "AppSettingsScreenSnackbar",
) {
GetoTheme {
AppSettingsScreen(
packageName = "com.android.geto",
appName = "Geto",
appSettingsUiState = AppSettingsUiState.Success(appSettings),
snackbarHostState = snackbarHostState,
applicationIcon = null,
secureSettings = emptyList(),
applyAppSettingsResult = AppSettingsResult.NoResult,
revertAppSettingsResult = AppSettingsResult.NoResult,
shortcutResult = ShortcutResult.NoResult,
clipboardResult = ClipboardResult.NoResult,
onNavigationIconClick = {},
onRevertAppSettings = {},
onGetShortcut = {},
onCheckAppSetting = { _, _ -> },
onDeleteAppSetting = {},
onLaunchApp = {},
onAutoLaunchApp = {},
onResetAppSettingsResult = {},
onResetShortcutResult = {},
onResetClipboardResult = {},
onGetSecureSettingsByName = { _, _ -> },
onAddAppSetting = {},
onCopyPermissionCommand = {},
onAddShortcut = {},
onUpdateShortcut = {},
)
}
}
}
}
| Geto/feature/appsettings/src/test/kotlin/com/android/geto/feature/appsettings/AppSettingsScreenSnackbarScreenshotTest.kt | 4118450046 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.