Skip to content

Commit 5b8453b

Browse files
committed
Merge branch 'main' into tm/metrics-one-folder
Change-Id: I00231b47daafbeb06c3435281a5c9864b46c8f54
2 parents 375480a + 0c84570 commit 5b8453b

File tree

13 files changed

+84
-20
lines changed

13 files changed

+84
-20
lines changed

.github/workflows/Build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ jobs:
100100
disable-animations: true
101101
disk-size: 6000M
102102
heap-size: 600M
103-
script: ./gradlew connectedDemoDebugAndroidTest -x :benchmark:connectedDemoBenchmarkAndroidTest --daemon
103+
script: ./gradlew connectedDemoDebugAndroidTest --daemon
104104

105105
- name: Upload test reports
106106
if: always()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2023 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.samples.apps.nowinandroid
18+
19+
import android.Manifest.permission
20+
import android.os.Build.VERSION.SDK_INT
21+
import android.os.Build.VERSION_CODES.TIRAMISU
22+
import androidx.benchmark.macro.MacrobenchmarkScope
23+
24+
/**
25+
* Because the app under test is different from the one running the instrumentation test,
26+
* the permission has to be granted manually by either:
27+
*
28+
* - tapping the Allow button
29+
* ```kotlin
30+
* val obj = By.text("Allow")
31+
* val dialog = device.wait(Until.findObject(obj), TIMEOUT)
32+
* dialog?.let {
33+
* it.click()
34+
* device.wait(Until.gone(obj), 5_000)
35+
* }
36+
* ```
37+
* - or (preferred) executing the grant command on the target package.
38+
*/
39+
fun MacrobenchmarkScope.allowNotifications() {
40+
if (SDK_INT >= TIRAMISU) {
41+
val command = "pm grant $packageName ${permission.POST_NOTIFICATIONS}"
42+
device.executeShellCommand(command)
43+
}
44+
}

benchmarks/src/main/java/com/google/samples/apps/nowinandroid/foryou/ScrollForYouFeedBenchmark.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import androidx.benchmark.macro.StartupMode
2222
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
2323
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
2424
import com.google.samples.apps.nowinandroid.PACKAGE_NAME
25+
import com.google.samples.apps.nowinandroid.allowNotifications
2526
import org.junit.Rule
2627
import org.junit.Test
2728
import org.junit.runner.RunWith
@@ -47,6 +48,7 @@ class ScrollForYouFeedBenchmark {
4748
// Start the app
4849
pressHome()
4950
startActivityAndWait()
51+
allowNotifications()
5052
},
5153
) {
5254
forYouWaitForContent()

benchmarks/src/main/java/com/google/samples/apps/nowinandroid/interests/TopicsScreenRecompositionBenchmark.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import androidx.benchmark.macro.junit4.MacrobenchmarkRule
2323
import androidx.test.ext.junit.runners.AndroidJUnit4
2424
import androidx.test.uiautomator.By
2525
import com.google.samples.apps.nowinandroid.PACKAGE_NAME
26+
import com.google.samples.apps.nowinandroid.allowNotifications
2627
import org.junit.Rule
2728
import org.junit.Test
2829
import org.junit.runner.RunWith
@@ -47,7 +48,7 @@ class TopicsScreenRecompositionBenchmark {
4748
// Start the app
4849
pressHome()
4950
startActivityAndWait()
50-
51+
allowNotifications()
5152
// Navigate to interests screen
5253
device.findObject(By.text("Interests")).click()
5354
device.waitForIdle()

core/common/src/main/java/com/google/samples/apps/nowinandroid/core/network/di/CoroutineScopesModule.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,28 @@
1717
package com.google.samples.apps.nowinandroid.core.network.di
1818

1919
import com.google.samples.apps.nowinandroid.core.network.Dispatcher
20-
import com.google.samples.apps.nowinandroid.core.network.NiaDispatchers.IO
20+
import com.google.samples.apps.nowinandroid.core.network.NiaDispatchers.Default
2121
import dagger.Module
2222
import dagger.Provides
2323
import dagger.hilt.InstallIn
2424
import dagger.hilt.components.SingletonComponent
2525
import kotlinx.coroutines.CoroutineDispatcher
2626
import kotlinx.coroutines.CoroutineScope
2727
import kotlinx.coroutines.SupervisorJob
28+
import javax.inject.Qualifier
2829
import javax.inject.Singleton
2930

31+
@Retention(AnnotationRetention.RUNTIME)
32+
@Qualifier
33+
annotation class ApplicationScope
34+
3035
@Module
3136
@InstallIn(SingletonComponent::class)
3237
object CoroutineScopesModule {
3338
@Provides
3439
@Singleton
35-
@Dispatcher(IO)
36-
fun providesIOCoroutineScope(
37-
@Dispatcher(IO) ioDispatcher: CoroutineDispatcher,
38-
): CoroutineScope = CoroutineScope(SupervisorJob() + ioDispatcher)
40+
@ApplicationScope
41+
fun providesCoroutineScope(
42+
@Dispatcher(Default) dispatcher: CoroutineDispatcher,
43+
): CoroutineScope = CoroutineScope(SupervisorJob() + dispatcher)
3944
}

core/data-test/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ android {
2525
dependencies {
2626
api(project(":core:data"))
2727
implementation(project(":core:testing"))
28+
implementation(project(":core:common"))
2829
}

core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/DefaultSearchContentsRepository.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.google.samples.apps.nowinandroid.core.database.dao.NewsResourceDao
2020
import com.google.samples.apps.nowinandroid.core.database.dao.NewsResourceFtsDao
2121
import com.google.samples.apps.nowinandroid.core.database.dao.TopicDao
2222
import com.google.samples.apps.nowinandroid.core.database.dao.TopicFtsDao
23+
import com.google.samples.apps.nowinandroid.core.database.model.PopulatedNewsResource
2324
import com.google.samples.apps.nowinandroid.core.database.model.asExternalModel
2425
import com.google.samples.apps.nowinandroid.core.database.model.asFtsEntity
2526
import com.google.samples.apps.nowinandroid.core.model.data.SearchResult
@@ -29,6 +30,7 @@ import kotlinx.coroutines.CoroutineDispatcher
2930
import kotlinx.coroutines.flow.Flow
3031
import kotlinx.coroutines.flow.combine
3132
import kotlinx.coroutines.flow.distinctUntilChanged
33+
import kotlinx.coroutines.flow.first
3234
import kotlinx.coroutines.flow.flatMapLatest
3335
import kotlinx.coroutines.flow.mapLatest
3436
import kotlinx.coroutines.withContext
@@ -45,7 +47,12 @@ class DefaultSearchContentsRepository @Inject constructor(
4547
override suspend fun populateFtsData() {
4648
withContext(ioDispatcher) {
4749
newsResourceFtsDao.insertAll(
48-
newsResourceDao.getOneOffNewsResources().map { it.asFtsEntity() },
50+
newsResourceDao.getNewsResources(
51+
useFilterTopicIds = false,
52+
useFilterNewsIds = false,
53+
)
54+
.first()
55+
.map(PopulatedNewsResource::asFtsEntity),
4956
)
5057
topicFtsDao.insertAll(topicDao.getOneOffTopicEntities().map { it.asFtsEntity() })
5158
}

core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestNewsResourceDao.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ class TestNewsResourceDao : NewsResourceDao {
6767
result
6868
}
6969

70-
override suspend fun getOneOffNewsResources(): List<PopulatedNewsResource> = emptyList()
71-
7270
override suspend fun insertOrIgnoreNewsResources(
7371
entities: List<NewsResourceEntity>,
7472
): List<Long> {

core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDao.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ interface NewsResourceDao {
6565
filterNewsIds: Set<String> = emptySet(),
6666
): Flow<List<PopulatedNewsResource>>
6767

68-
@Transaction
69-
@Query(value = "SELECT * FROM news_resources ORDER BY publish_date DESC")
70-
suspend fun getOneOffNewsResources(): List<PopulatedNewsResource>
71-
7268
/**
7369
* Inserts [entities] into the db if they don't exist, and ignores those that do
7470
*/

core/datastore-test/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dependencies {
2626
api(project(":core:datastore"))
2727
api(libs.androidx.dataStore.core)
2828

29+
implementation(libs.protobuf.kotlin.lite)
2930
implementation(project(":core:common"))
3031
implementation(project(":core:testing"))
3132
}

0 commit comments

Comments
 (0)