Skip to content

Commit ec20a21

Browse files
committed
feat: Implement WearOS Terms of Service consent dialog for GmsCore#2843
1 parent 6283b51 commit ec20a21

3 files changed

Lines changed: 111 additions & 3 deletions

File tree

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,54 @@
1-
/**
1+
/*
22
* SPDX-FileCopyrightText: 2025 microG Project Team
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

66
package com.google.android.gms.wearable.consent
77

8+
import android.content.SharedPreferences
89
import android.os.Bundle
910
import androidx.appcompat.app.AppCompatActivity
11+
import com.google.android.gms.wearable.R
1012

1113
class TermsOfServiceActivity : AppCompatActivity() {
1214

15+
companion object {
16+
const val WEARABLE_TOS_ACCEPTED = "wearable_tos_accepted"
17+
const val WEARABLE_TOS_PREFS = "wearable_tos_prefs"
18+
}
19+
20+
private var resultCode: Int = RESULT_CANCELED
21+
1322
override fun onCreate(savedInstanceState: Bundle?) {
1423
super.onCreate(savedInstanceState)
15-
setResult(RESULT_CANCELED)
16-
finish()
24+
setContentView(R.layout.activity_wearable_tos)
25+
26+
findViewById<android.widget.Button>(R.id.button_accept).setOnClickListener {
27+
resultCode = RESULT_OK
28+
saveTosAccepted(true)
29+
finish()
30+
}
31+
32+
findViewById<android.widget.Button>(R.id.button_decline).setOnClickListener {
33+
resultCode = RESULT_CANCELED
34+
finish()
35+
}
36+
}
37+
38+
override fun finish() {
39+
setResult(resultCode)
40+
super.finish()
41+
}
42+
43+
private fun saveTosAccepted(accepted: Boolean) {
44+
getSharedPreferences(WEARABLE_TOS_PREFS, MODE_PRIVATE)
45+
.edit()
46+
.putBoolean(WEARABLE_TOS_ACCEPTED, accepted)
47+
.apply()
48+
}
49+
50+
fun isTosAccepted(): Boolean {
51+
return getSharedPreferences(WEARABLE_TOS_PREFS, MODE_PRIVATE)
52+
.getBoolean(WEARABLE_TOS_ACCEPTED, false)
1753
}
1854
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2025 microG Project Team
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
19+
android:layout_width="match_parent"
20+
android:layout_height="match_parent"
21+
android:orientation="vertical"
22+
android:gravity="center"
23+
android:padding="24dp">
24+
25+
<TextView
26+
android:layout_width="match_parent"
27+
android:layout_height="0dp"
28+
android:layout_weight="1"
29+
android:text="@string/wearable_tos_title"
30+
android:textSize="20sp"
31+
android:textStyle="bold"
32+
android:textColor="?attr/colorPrimary"
33+
android:gravity="center"
34+
android:layout_marginTop="16dp"
35+
android:layout_marginBottom="16dp" />
36+
37+
<TextView
38+
android:layout_width="match_parent"
39+
android:layout_height="0dp"
40+
android:layout_weight="1"
41+
android:text="@string/wearable_tos_message"
42+
android:textSize="14sp"
43+
android:gravity="center"
44+
android:layout_marginBottom="24dp" />
45+
46+
<LinearLayout
47+
android:layout_width="match_parent"
48+
android:layout_height="wrap_content"
49+
android:orientation="horizontal"
50+
android:gravity="end">
51+
52+
<Button
53+
android:id="@+id/button_decline"
54+
style="?attr/buttonBarButtonStyle"
55+
android:layout_width="wrap_content"
56+
android:layout_height="wrap_content"
57+
android:text="@string/decline" />
58+
59+
<Button
60+
android:id="@+id/button_accept"
61+
android:layout_width="wrap_content"
62+
android:layout_height="wrap_content"
63+
android:text="@string/accept" />
64+
</LinearLayout>
65+
66+
</LinearLayout>

play-services-core/src/main/res/values/strings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,4 +460,10 @@ Please set up a password, PIN, or pattern lock screen."</string>
460460
<string name="location_sharing_turn_off_confirm">Turn off</string>
461461
<string name="location_sharing_confirm_dialog_title">Enable Location Sharing</string>
462462
<string name="location_sharing_confirm_dialog_text">People you share your location with can always see:\n·Your name and photo\n·Your device\'s recent location,even when you\'re not using a Google service\n·Your device\'s battery power,and if it\'s charging\n·Your arrival and departure time,if they add a Location Sharing notification</string>
463+
464+
<!-- WearOS Terms of Service -->
465+
<string name="wearable_tos_title">WearOS Terms of Service</string>
466+
<string name="wearable_tos_message">By connecting to a WearOS device, you agree to allow Google services to exchange data with your wearable device, including but not limited to notifications, phone status, and app data synchronization.\n\nYour data will be processed in accordance with Google\'s Privacy Policy.</string>
467+
<string name="accept">Accept</string>
468+
<string name="decline">Decline</string>
463469
</resources>

0 commit comments

Comments
 (0)