From a58751eba45019bcf9214daeeaf900fc1ba9e628 Mon Sep 17 00:00:00 2001 From: Google AI Edge Gallery Date: Fri, 27 Jun 2025 20:55:29 -0700 Subject: [PATCH] Add a "view licenses" button in settings dialog to view open source licenses. - Followed the instructions here: https://developers.google.com/android/guides/opensource - The plugin will automatically parse libs.versions.toml and store the licenses related data in the app bundle as resources. - Use the activities in play-services-oss-licenses library to view the licenses. PiperOrigin-RevId: 776826500 --- Android/src/app/build.gradle.kts | 2 + Android/src/app/src/main/AndroidManifest.xml | 16 +++++++ .../ai/edge/gallery/ui/home/SettingsDialog.kt | 46 ++++++++++++++++++- .../app/src/main/res/values-night/themes.xml | 22 +++++++++ .../src/app/src/main/res/values/themes.xml | 5 +- Android/src/gradle/libs.versions.toml | 4 ++ Android/src/settings.gradle.kts | 7 +++ 7 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 Android/src/app/src/main/res/values-night/themes.xml diff --git a/Android/src/app/build.gradle.kts b/Android/src/app/build.gradle.kts index b051876..0dc53b5 100644 --- a/Android/src/app/build.gradle.kts +++ b/Android/src/app/build.gradle.kts @@ -21,6 +21,7 @@ plugins { alias(libs.plugins.kotlin.serialization) alias(libs.plugins.protobuf) alias(libs.plugins.hilt.application) + alias(libs.plugins.oss.licenses) kotlin("kapt") } @@ -95,6 +96,7 @@ dependencies { implementation(libs.protobuf.javalite) implementation(libs.hilt.android) implementation(libs.hilt.navigation.compose) + implementation(libs.play.services.oss.licenses) kapt(libs.hilt.android.compiler) testImplementation(libs.junit) androidTestImplementation(libs.androidx.junit) diff --git a/Android/src/app/src/main/AndroidManifest.xml b/Android/src/app/src/main/AndroidManifest.xml index 6bacbd3..364da5f 100644 --- a/Android/src/app/src/main/AndroidManifest.xml +++ b/Android/src/app/src/main/AndroidManifest.xml @@ -47,12 +47,18 @@ android:supportsRtl="true" android:theme="@style/Theme.Gallery" tools:targetApi="31"> + @@ -71,6 +77,16 @@ + + + + = Build.VERSION_CODES.S) { + val uiModeManager = + context.applicationContext.getSystemService(Context.UI_MODE_SERVICE) + as UiModeManager + if (theme == Theme.THEME_AUTO) { + uiModeManager.setApplicationNightMode(UiModeManager.MODE_NIGHT_AUTO) + } else if (theme == Theme.THEME_LIGHT) { + uiModeManager.setApplicationNightMode(UiModeManager.MODE_NIGHT_NO) + } else { + uiModeManager.setApplicationNightMode(UiModeManager.MODE_NIGHT_YES) + } + } }, checked = theme == selectedTheme, label = { Text(themeLabel(theme)) }, @@ -166,7 +192,7 @@ fun SettingsDialog( ) // Show the start of the token. val curHfToken = hfToken - if (curHfToken != null) { + if (curHfToken != null && curHfToken.accessToken.isNotEmpty()) { Text( curHfToken.accessToken.substring(0, min(16, curHfToken.accessToken.length)) + "...", style = MaterialTheme.typography.bodyMedium, @@ -254,6 +280,24 @@ fun SettingsDialog( } } } + + // Third party licenses. + Column(modifier = Modifier.fillMaxWidth()) { + Text( + "Third-party libraries", + style = MaterialTheme.typography.titleSmall.copy(fontWeight = FontWeight.Bold), + ) + OutlinedButton( + onClick = { + // Create an Intent to launch a license viewer that displays a list of + // third-party library names. Clicking a name will show its license content. + val intent = Intent(context, OssLicensesMenuActivity::class.java) + context.startActivity(intent) + } + ) { + Text("View licenses") + } + } } // Button row. diff --git a/Android/src/app/src/main/res/values-night/themes.xml b/Android/src/app/src/main/res/values-night/themes.xml new file mode 100644 index 0000000..663a1b1 --- /dev/null +++ b/Android/src/app/src/main/res/values-night/themes.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/Android/src/app/src/main/res/values/themes.xml b/Android/src/app/src/main/res/values/themes.xml index beeda9c..b69d8fb 100644 --- a/Android/src/app/src/main/res/values/themes.xml +++ b/Android/src/app/src/main/res/values/themes.xml @@ -15,10 +15,13 @@ limitations under the License. --> - + + \ No newline at end of file diff --git a/Android/src/gradle/libs.versions.toml b/Android/src/gradle/libs.versions.toml index 57b3aa1..2431c2f 100644 --- a/Android/src/gradle/libs.versions.toml +++ b/Android/src/gradle/libs.versions.toml @@ -31,6 +31,8 @@ netOpenidAppauth = "0.11.1" splashscreen = "1.2.0-beta01" hilt = "2.56.2" hiltNavigation = "1.2.0" +ossLicenses = "0.10.6" +playServicesOssLicenses = "17.1.0" [libraries] androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } @@ -73,6 +75,7 @@ hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt" hilt-navigation-compose = { module = "androidx.hilt:hilt-navigation-compose", version.ref = "hiltNavigation" } hilt-android-testing = { module = "com.google.dagger:hilt-android-testing", version.ref = "hilt" } hilt-android-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hilt" } +play-services-oss-licenses = { module = "com.google.android.gms:play-services-oss-licenses", version.ref = "playServicesOssLicenses"} [plugins] android-application = { id = "com.android.application", version.ref = "agp" } @@ -81,3 +84,4 @@ kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "ko kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "serializationPlugin" } protobuf = {id = "com.google.protobuf", version.ref = "protobuf"} hilt-application = { id = "com.google.dagger.hilt.android", version.ref = "hilt" } +oss-licenses = {id = "com.google.android.gms.oss-licenses-plugin", version.ref = "ossLicenses"} diff --git a/Android/src/settings.gradle.kts b/Android/src/settings.gradle.kts index fa3d79f..e10f0ee 100644 --- a/Android/src/settings.gradle.kts +++ b/Android/src/settings.gradle.kts @@ -26,6 +26,13 @@ pluginManagement { mavenCentral() gradlePluginPortal() } + resolutionStrategy { + eachPlugin { + if (requested.id.id == "com.google.android.gms.oss-licenses-plugin") { + useModule("com.google.android.gms:oss-licenses-plugin:0.10.6") + } + } + } } dependencyResolutionManagement {