Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class AndroidLiveUpdateNowPlayingSurfacePublisherTest {

@Test
fun tapOpensPairedPixelAmbientHistoryInsteadOfModSettings() {
val context = ApplicationProvider.getApplicationContext<Context>()
val publisher = AndroidLiveUpdateNowPlayingSurfacePublisher(context)
val intent = publisher.buildHistoryIntent()

assertEquals("com.google.intelligence.sense.NOW_PLAYING_HISTORY", intent.action)
assertEquals("com.kieronquinn.app.pixelambientmusic", intent.`package`)
assertNull(intent.component)
assertTrue((intent.flags and android.content.Intent.FLAG_ACTIVITY_NEW_TASK) != 0)
}

@Test
fun candidateUsesVerifiedM0BShape() {
val context = ApplicationProvider.getApplicationContext<Context>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import com.kieronquinn.app.ambientmusicmod.PACKAGE_NAME_PAM
import com.kieronquinn.app.ambientmusicmod.R
import com.kieronquinn.app.ambientmusicmod.ui.activities.MainActivity

interface NowPlayingSurfacePublisher {
fun publish(event: NowPlayingSurfaceEvent)
Expand Down Expand Up @@ -54,16 +54,26 @@ class AndroidLiveUpdateNowPlayingSurfacePublisher(
)
}

/**
* The paired Pixel Ambient Music APK exports Now Playing History using this action.
* It has no verified public per-track deep link, so do not invent track extras.
* Keep the notification destination in Pixel Ambient Music, not AMM settings.
*/
fun buildHistoryIntent(): Intent {
return Intent("com.google.intelligence.sense.NOW_PLAYING_HISTORY").apply {
`package` = PACKAGE_NAME_PAM
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
}
}

fun buildCandidateNotification(
event: NowPlayingSurfaceEvent,
requestPromotion: Boolean
): Notification {
val contentIntent = PendingIntent.getActivity(
context,
NOTIFICATION_ID,
Intent(context, MainActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
},
buildHistoryIntent(),
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
return NotificationCompat.Builder(context, CHANNEL_ID)
Expand Down
Loading