Skip to content

Commit 9c35ea4

Browse files
committed
Track consent explicitly.
Instead of relying on the location consent, track whether the user has seen the consent screens explicitly. This change includes a migration from the old mechanism to the new one. To facilitate the migration, the version is bumped here. Signed-off-by: Katharine Berry <ktbry@google.com>
1 parent 8db995b commit 9c35ea4

File tree

7 files changed

+57
-20
lines changed

7 files changed

+57
-20
lines changed

app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Bobby",
33
"author": "Rebble",
4-
"version": "1.1.0",
4+
"version": "1.2.0",
55
"keywords": [
66
"pebble-app"
77
],

app/src/c/assistant.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
static RootWindow* s_root_window = NULL;
3131

3232
static void prv_init(void) {
33-
version_store_current();
33+
version_init();
34+
consent_migrate();
3435
settings_init();
3536
conversation_manager_init();
3637
events_app_message_open();

app/src/c/consent/consent.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
#include "consent.h"
1818
#include "../util/persist_keys.h"
1919
#include "../util/style.h"
20+
#include "../version/version.h"
2021
#include "../root_window.h"
2122

2223
#include <pebble.h>
2324
#include <pebble-events/pebble-events.h>
2425

26+
2527
#define STAGE_LLM_WARNING 0
2628
#define STAGE_GEMINI_CONSENT 1
2729
#define STAGE_LOCATION_CONSENT 2
@@ -51,6 +53,7 @@ static void prv_present_consent_menu(Window* window);
5153
static void prv_consent_menu_select_callback(ActionMenu *action_menu, const ActionMenuItem *action, void *context);
5254
static void prv_action_menu_close(ActionMenu* action_menu, const ActionMenuItem* item, void* context);
5355
static void prv_app_message_handler(DictionaryIterator *iter, void *context);
56+
static void prv_mark_consents_complete();
5457

5558
void consent_window_push() {
5659
Window* window = window_create();
@@ -66,7 +69,24 @@ void consent_window_push() {
6669
}
6770

6871
bool must_present_consent() {
69-
return !persist_exists(PERSIST_KEY_LOCATION_ENABLED);
72+
return persist_read_int(PERSIST_KEY_CONSENTS_COMPLETED) < 1;
73+
}
74+
75+
void consent_migrate() {
76+
if (version_is_updated() && !version_is_first_launch()) {
77+
// If we're updating from version 1.1 or older, consent agreement was implied by LOCATION_ENABLED being set
78+
// (either true or false).
79+
if (version_info_compare(version_get_last_launch(), (VersionInfo) {1, 1}) <= 0) {
80+
APP_LOG(APP_LOG_LEVEL_INFO, "Performing consent migration from version 1.1.");
81+
// If the location enabled state is set, that's equivalent to consent agreement version 1.
82+
if (persist_exists(PERSIST_KEY_LOCATION_ENABLED)) {
83+
APP_LOG(APP_LOG_LEVEL_INFO, "Marking consent as 1.");;
84+
persist_write_int(PERSIST_KEY_CONSENTS_COMPLETED, 1);
85+
} else {
86+
APP_LOG(APP_LOG_LEVEL_INFO, "Not marking consent.");;
87+
}
88+
}
89+
}
7090
}
7191

7292
static void prv_window_load(Window *window) {
@@ -242,6 +262,7 @@ static void prv_app_message_handler(DictionaryIterator *iter, void *context) {
242262
events_app_message_unsubscribe(data->app_message_handle);
243263
bool location_enabled = tuple->value->int16;
244264
persist_write_bool(PERSIST_KEY_LOCATION_ENABLED, location_enabled);
265+
prv_mark_consents_complete();
245266
RootWindow *root_window = root_window_create();
246267
action_menu_set_result_window(data->action_menu, root_window_get_window(root_window));
247268
action_menu_close(data->action_menu, true);
@@ -251,3 +272,7 @@ static void prv_app_message_handler(DictionaryIterator *iter, void *context) {
251272
static void prv_action_menu_close(ActionMenu* action_menu, const ActionMenuItem* item, void* context) {
252273
action_menu_hierarchy_destroy(action_menu_get_root_level(action_menu), NULL, NULL);
253274
}
275+
276+
static void prv_mark_consents_complete() {
277+
persist_write_int(PERSIST_KEY_CONSENTS_COMPLETED, 1);
278+
}

app/src/c/consent/consent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@
2121

2222
bool must_present_consent();
2323
void consent_window_push();
24+
void consent_migrate();
2425

2526
#endif //APP_CONSENT_H

app/src/c/util/persist_keys.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// These keys are stored centrally so we can avoid accidental collisions.
2121
// Remember: these numbers can *never* be changed.
2222

23-
// next key: 12
23+
// next key: 13
2424

2525
// We write the alarm count twice - once before doing any work, and once after.
2626
// If they disagree we assume the lower number is correct.
@@ -34,6 +34,9 @@
3434
// Store whether we have successfully requested location consent.
3535
#define PERSIST_KEY_LOCATION_ENABLED 6
3636

37+
// Store whether the user has accepted the consents
38+
#define PERSIST_KEY_CONSENTS_COMPLETED 12
39+
3740
// Contains the version we were running the last time we were launched
3841
#define PERSIST_KEY_VERSION 7
3942

app/src/c/version/version.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,21 @@ extern const PebbleProcessInfo __pbl_app_info;
2525

2626
static bool s_is_first_launch = false;
2727
static bool s_is_update = false;
28+
static VersionInfo s_last_launch;
2829

29-
void version_store_current() {
30+
VersionInfo prv_read_last_launch();
31+
32+
void version_init() {
3033
VersionInfo version_info = version_get_current();
31-
VersionInfo last_version = version_get_last_launch();
32-
s_is_first_launch = last_version.major == 0 && last_version.minor == 0;
33-
if (version_info_compare(version_info, last_version) != 0) {
34+
s_last_launch = prv_read_last_launch();
35+
s_is_first_launch = s_last_launch.major == 0 && s_last_launch.minor == 0;
36+
if (version_info_compare(version_info, s_last_launch) != 0) {
3437
s_is_update = true;
3538
int status = persist_write_data(PERSIST_KEY_VERSION, &version_info, sizeof(VersionInfo));
3639
if (status < 0) {
3740
APP_LOG(APP_LOG_LEVEL_ERROR, "Failed to write version info: %d", status);
3841
} else {
39-
APP_LOG(APP_LOG_LEVEL_INFO, "Current version (v%d.%d) stored (previous: v%d.%d)", version_info.major, version_info.minor, last_version.major, last_version.minor);
42+
APP_LOG(APP_LOG_LEVEL_INFO, "Current version (v%d.%d) stored (previous: v%d.%d)", version_info.major, version_info.minor, s_last_launch.major, s_last_launch.minor);
4043
}
4144
} else {
4245
APP_LOG(APP_LOG_LEVEL_DEBUG, "Version (v%d.%d) unchanged since last launch.", version_info.major, version_info.minor);
@@ -52,16 +55,7 @@ bool version_is_updated() {
5255
}
5356

5457
VersionInfo version_get_last_launch() {
55-
VersionInfo version_info;
56-
int status = persist_read_data(PERSIST_KEY_VERSION, &version_info, sizeof(VersionInfo));
57-
if (status < 0) {
58-
APP_LOG(APP_LOG_LEVEL_WARNING, "Failed to read version info: %d", status);
59-
return (VersionInfo) {
60-
.major = 0,
61-
.minor = 0,
62-
};
63-
}
64-
return version_info;
58+
return s_last_launch;
6559
}
6660

6761
VersionInfo version_get_current() {
@@ -86,3 +80,16 @@ int version_info_compare(VersionInfo a, VersionInfo b) {
8680
}
8781
return 0;
8882
}
83+
84+
VersionInfo prv_read_last_launch() {
85+
VersionInfo version_info;
86+
int status = persist_read_data(PERSIST_KEY_VERSION, &version_info, sizeof(VersionInfo));
87+
if (status < 0) {
88+
APP_LOG(APP_LOG_LEVEL_WARNING, "Failed to read version info: %d", status);
89+
return (VersionInfo) {
90+
.major = 0,
91+
.minor = 0,
92+
};
93+
}
94+
return version_info;
95+
}

app/src/c/version/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ typedef struct __attribute__((__packed__)) {
2424
uint8_t minor;
2525
} VersionInfo;
2626

27-
void version_store_current();
27+
void version_init();
2828
bool version_is_first_launch();
2929
bool version_is_updated();
3030
VersionInfo version_get_last_launch();

0 commit comments

Comments
 (0)