Skip to content

Commit

Permalink
Add open source license display to Settings
Browse files Browse the repository at this point in the history
This change adds an option to display open source licenses within the settings screen by launching the `com.google.wear.ACTION_SHOW_LICENSE` intent. It also registers `OssLicensesMenuActivity` and `OssLicensesActivity` in the AndroidManifest.
  • Loading branch information
yschimke committed Jan 20, 2025
1 parent 7dd5e19 commit accc45e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ buildscript {
classpath(libs.gradleMavenPublishPlugin)

classpath(libs.dagger.hiltandroidplugin)
classpath(libs.oss.licenses.plugin)
}
}

Expand Down
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ appcompat = "1.7.0"
com-squareup-okhttp3 = "5.0.0-alpha.14"
com-squareup-retrofit2 = "2.11.0"
compose-material3 = "1.3.1"
ossLicensesPlugin = "0.10.6"
playServicesOssLicenses = "17.1.0"
wearComposeMaterial3 = "1.0.0-alpha31"
composesnapshot = "-"
dependencyAnalysis = "2.7.0"
Expand Down Expand Up @@ -197,6 +199,8 @@ moshi-adapters = { module = "com.squareup.moshi:moshi-adapters", version.ref = "
moshi-kotlin = { module = "com.squareup.moshi:moshi-kotlin", version.ref = "moshi" }
moshi-kotlin-codegen = { module = "com.squareup.moshi:moshi-kotlin-codegen", version.ref = "moshi" }
okio = { module = "com.squareup.okio:okio", version.ref = "okio" }
oss-licenses-plugin = { module = "com.google.android.gms:oss-licenses-plugin", version.ref = "ossLicensesPlugin" }
play-services-oss-licenses = { module = "com.google.android.gms:play-services-oss-licenses", version.ref = "playServicesOssLicenses" }
playservices-auth = { module = "com.google.android.gms:play-services-auth", version.ref = "playServicesAuth" }
playservices-base = "com.google.android.gms:play-services-base:18.5.0"
playservices-wearable = "com.google.android.gms:play-services-wearable:19.0.0"
Expand Down
3 changes: 3 additions & 0 deletions media/sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ plugins {
kotlin("plugin.serialization")
alias(libs.plugins.roborazzi)
alias(libs.plugins.compose.compiler)
id("com.google.android.gms.oss-licenses-plugin")
}

val localProperties = Properties()
Expand Down Expand Up @@ -247,6 +248,8 @@ dependencies {
implementation(libs.playservices.auth)
implementation(libs.kotlinx.coroutines.playservices)

implementation(libs.play.services.oss.licenses)

add("benchmarkImplementation", libs.androidx.runtime.tracing)

debugImplementation(libs.compose.ui.tooling)
Expand Down
18 changes: 18 additions & 0 deletions media/sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>

<activity
android:name="com.google.android.gms.oss.licenses.OssLicensesMenuActivity"
android:exported="true"
android:label="@string/oss_license_title"
android:taskAffinity=".licenses"
android:theme="@style/Theme.AppCompat"
tools:node="replace">
<intent-filter>
<action android:name="com.google.wear.ACTION_SHOW_LICENSE" />
</intent-filter>
</activity>
<activity
android:name="com.google.android.gms.oss.licenses.OssLicensesActivity"
android:exported="false"
android:taskAffinity=".licenses"
android:theme="@style/Theme.AppCompat"
tools:node="replace" />
</application>

<uses-sdk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.google.android.horologist.mediasample.ui.settings

import android.content.Intent
import androidx.activity.compose.LocalActivity
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.icons.Icons
Expand Down Expand Up @@ -117,6 +119,20 @@ fun UampSettingsScreen(
)
}
}
item {
val activity = LocalActivity.current
Chip(
label = stringResource(id = R.string.show_licenses),
modifier = Modifier.fillMaxWidth(),
onClick = {
activity?.startActivity(Intent().apply {
setPackage(activity.packageName)
setAction("com.google.wear.ACTION_SHOW_LICENSE")
})
},
enabled = true,
)
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions media/sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@
<string name="sample_guest_mode">Guest Mode</string>
<string name="seen_login_details">Seen Login Details</string>
<string name="complication_content_description">UAMP\n%1$s\n%2$s</string>
<string name="show_licenses">App Licenses</string>
</resources>

0 comments on commit accc45e

Please sign in to comment.