1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
"""Pages associated with pairing process of Fitbit tracker device."""
import shlex
from typing import List, Optional
from xml.dom import minidom
from blueberry.utils.ui_pages import errors
from blueberry.utils.ui_pages import ui_core
from blueberry.utils.ui_pages import ui_node
from blueberry.utils.ui_pages.fitbit_companion import constants
# Alias for typing convenience.
_NodeList = List[ui_node.UINode]
class PairRetryPage(ui_core.UIPage):
"""Fitbit Companion App's page for retry of pairing."""
PAGE_RE_TEXT = 'TRY AGAIN'
def retry(self) -> ui_core.UIPage:
"""Clicks button to retry pairing.
Returns:
The transformed page.
Raises:
errors.UIError: Fail to find the target node.
"""
return self.click_node_by_text('TRY AGAIN')
class Pairing4DigitPage(ui_core.UIPage):
"""Fitbit Companion App's page to enter 4 digit pins for pairing."""
PAGE_RID = f'{constants.PKG_NAME_ID}/digits'
NODE_DIGIT_RIDS = (f'{constants.PKG_NAME_ID}/digit0'
f'{constants.PKG_NAME_ID}/digit1'
f'{constants.PKG_NAME_ID}/digit2'
f'{constants.PKG_NAME_ID}/digit3')
def input_pins(self, pins: str) -> ui_core.UIPage:
"""Inputs 4 digit pins required in pairing process.
Args:
pins: 4 digit pins (e.g.: "1234")
Returns:
The transformed page.
Raises:
ValueError: Input pins is not valid.
"""
if len(pins) != 4:
raise ValueError(f'4 digits required here! (input={pins})')
for digit in pins:
self.ctx.ad.adb.shell(shlex.split(f'input text "{digit}"'))
return self.ctx.page
class PairingConfirmPage(ui_core.UIPage):
"""Fitbit Companion App's page to confirm pairing."""
NODE_ALLOW_ACCESS_TEXT = 'Allow access to your contacts and call history'
NODE_PAIR_TEXT = 'Pair'
@classmethod
def from_xml(cls, ctx: ui_core.Context, ui_xml: minidom.Document,
clickable_nodes: _NodeList, enabled_nodes: _NodeList,
all_nodes: _NodeList) -> Optional[ui_core.UIPage]:
"""Instantiates page object from XML object.
Args:
ctx: Page context object.
ui_xml: Parsed XML object.
clickable_nodes: Clickable node list from page.
enabled_nodes: Enabled node list from page.
all_nodes: All node from page.
Returns:
UI page object iff the given XML object can be parsed.
"""
for node in enabled_nodes:
if (node.text == cls.NODE_PAIR_TEXT and
node.resource_id == 'android:id/button1'):
return cls(ctx, ui_xml, clickable_nodes, enabled_nodes, all_nodes)
def confirm(self) -> ui_core.UIPage:
"""Confirms the action of pairing.
Returns:
The transformed page.
"""
self.click_node_by_text(self.NODE_ALLOW_ACCESS_TEXT)
return self.click_node_by_text(self.NODE_PAIR_TEXT)
class PairingIntroPage(ui_core.UIPage):
"""Fitbit Companion App's pages for introduction of product usage."""
NODE_TITLE_TEXT_SET = frozenset([
'All set!',
'Double tap to wake',
'Firmly double-tap',
'How to go back',
'Swipe down',
'Swipe left or right',
'Swipe to navigate',
'Swipe up',
'Try it on',
'Wear & care tips',
])
NODE_NEXT_BTN_RID = f'{constants.PKG_NAME_ID}/btn_next'
@classmethod
def from_xml(cls, ctx: ui_core.Context, ui_xml: minidom.Document,
clickable_nodes: _NodeList, enabled_nodes: _NodeList,
all_nodes: _NodeList) -> Optional[ui_core.UIPage]:
"""Instantiates page object from XML object.
The appending punctuation '.' of the text will be ignored during comparison.
Args:
ctx: Page context object.
ui_xml: Parsed XML object.
clickable_nodes: Clickable node list from page.
enabled_nodes: Enabled node list from page.
all_nodes: All node from page.
Returns:
UI page object iff the given XML object can be parsed.
"""
for node in enabled_nodes:
node_text = node.text[:-1] if node.text.endswith('.') else node.text
if node_text in cls.NODE_TITLE_TEXT_SET:
return cls(ctx, ui_xml, clickable_nodes, enabled_nodes, all_nodes)
def next(self):
"""Moves to next page."""
return self.click_node_by_rid(self.NODE_NEXT_BTN_RID)
class PairAndLinkPage(ui_core.UIPage):
"""Fitbit Companion App's landing page for pairing and linking."""
PAGE_TEXT = 'Bluetooth Pairing and Linking'
NODE_CANCEL_TEXT = 'Cancel'
def cancel(self) -> ui_core.UIPage:
"""Cancel pairing process.
Returns:
The transformed page.
"""
return self.click_node_by_text(self.NODE_CANCEL_TEXT)
class PremiumPage(ui_core.UIPage):
"""Fitbit Companion App's page for Premium information."""
PAGE_TEXT = 'See all Premium features'
NODE_EXIT_IMG_BTN_CLASS = 'android.widget.ImageButton'
def done(self):
"""Completes pairing process.
Returns:
The transformed page.
"""
return self.click_node_by_class(self.NODE_EXIT_IMG_BTN_CLASS)
class PairPrivacyConfirmPage(ui_core.UIPage):
"""Fitbit Companion App's page to confirm the privacy befoe pairing."""
PAGE_RID = f'{constants.PKG_NAME_ID}/gdpr_scroll_view'
_NODE_ACCEPT_BTN_TEXT = 'ACCEPT'
_SWIPE_RETRY = 5
def accept(self) -> ui_core.UIPage:
"""Accepts the privacy policy.
Returns:
The transformed page.
Raises:
errors.UIError: Fail to get target node.
"""
self.swipe_down()
for i in range(self._SWIPE_RETRY):
node = self.get_node_by_text(self._NODE_ACCEPT_BTN_TEXT)
if node is None:
raise errors.UIError(
f'Fail to find the node with text={self._NODE_ACCEPT_BTN_TEXT}')
atr_obj = node.attributes.get('enabled')
if atr_obj is not None and atr_obj.value == 'true':
return self.click_node_by_text(self._NODE_ACCEPT_BTN_TEXT)
self.log.debug('swipe down to browse the privacy info...%d', i + 1)
self.swipe_down()
self.ctx.get_page()
raise errors.UIError(
'Fail to wait for the enabled button to confirm the privacy!')
class CancelPairPage(ui_core.UIPage):
"""Fitbit Companion App's page to confirm the cancel of pairing."""
PAGE_TEXT = ('Canceling this process may result in poor connectivity with '
'your Fitbit device.')
NODE_YES_TEXT = 'YES'
NODE_NO_TEXT = 'NO'
def yes(self) -> ui_core.UIPage:
"""Cancels the pairing process.
Returns:
The transformed page.
Raises:
errors.UIError: Fail to get target node.
"""
return self.click_node_by_text(self.NODE_YES_TEXT)
def no(self) -> ui_core.UIPage:
"""Continues the pairing process.
Returns:
The transformed page.
Raises:
errors.UIError: Fail to get target node.
"""
return self.click_node_by_text(self.NODE_NO_TEXT)
class CancelPair2Page(ui_core.UIPage):
"""Fitbit Companion App's page to confirm the cancel of pairing."""
PAGE_TEXT = (
'Are you sure you want to cancel pairing?'
' You can set up your Fitbit Device later on the Devices screen.')
_NODE_YES_TEXT = 'CANCEL'
def yes(self) -> ui_core.UIPage:
"""Cancels the pairing process.
Returns:
The transformed page.
Raises:
errors.UIError: Fail to get target node.
"""
return self.click_node_by_text(self._NODE_YES_TEXT)
class ConfirmReplaceSmartWatchPage(ui_core.UIPage):
"""Fitbit Companion App's page to confirm the replacement of tracker device.
When you already have one paired tracker device and you try to pair a
new one, this page will show up.
"""
NODE_SWITCH_BTN_TEXT = 'SWITCH TO'
PAGE_TEXT = 'Switching?'
def confirm(self) -> ui_core.UIPage:
"""Confirms the switching.
Returns:
The transformed page.
Raises:
errors.UIError: Fail to get target node.
"""
def _search_switch_btn_node(node: ui_node.UINode) -> bool:
if node.text.startswith(self.NODE_SWITCH_BTN_TEXT):
return True
return False
node = self.get_node_by_func(_search_switch_btn_node)
if node is None:
raise errors.UIError(
'Failed to confirm the switching of new tracker device!')
return self.click(node)
class ConfirmChargePage(ui_core.UIPage):
"""Fitbit Companion App's page to confirm the charge condition."""
PAGE_RE_TEXT = 'Let your device charge during setup'
def next(self) -> ui_core.UIPage:
"""Forwards to pairing page.
Returns:
The transformed page.
Raises:
errors.UIError: Fail to get target node.
"""
return self.click_node_by_text('NEXT')
class ChooseTrackerPage(ui_core.UIPage):
"""Fitbit Companion App's page to select device model for pairing."""
ACTIVITY = f'{constants.PKG_NAME}/com.fitbit.device.ui.setup.choose.ChooseTrackerActivity'
PAGE_RID = f'{constants.PKG_NAME_ID}/choose_tracker_title_container'
def select_device(self, name: str) -> ui_core.UIPage:
"""Selects tracker device.
Args:
name: The name of device. (e.g.: 'Buzz')
Returns:
The transformed page.
Raises:
errors.UIError: Fail to get target node.
"""
return self.click_node_by_text(name)
class ConfirmDevicePage(ui_core.UIPage):
"""Fitbit Companion App's page to confirm the selected tracker device."""
PAGE_TEXT = 'SET UP'
ACTIVITY = f'{constants.PKG_NAME}/com.fitbit.device.ui.setup.choose.ConfirmDeviceActivity'
def confirm(self) -> ui_core.UIPage:
"""Confirms the selection.
Returns:
The transformed page.
Raises:
errors.UIError: Fail to get target node.
"""
return self.click_node_by_text(self.PAGE_TEXT)
class SkipInfoPage(ui_core.UIPage):
"""Fitbit Companion App's page to skip the 'not working' page."""
PAGE_TEXT = 'Skip Information Screens'
NODE_SKIP_TEXT = 'SKIP'
NODE_CONTINUE_TEXT = 'CONTINUE'
def skip(self) -> ui_core.UIPage:
"""Skips the information screens.
Returns:
The transformed page.
"""
return self.click_node_by_text(self.NODE_SKIP_TEXT)
class UpdateDevicePage(ui_core.UIPage):
"""Fitbit Companion App's page to update device."""
PAGE_TEXT = 'INSTALL UPDATE NOW'
NODE_UPDATE_LATER_BTN_TEXT = 'UPDATE LATER'
def update_later(self) -> ui_core.UIPage:
"""Cancels the update.
Returns:
The transformed page.
"""
return self.click_node_by_text(self.NODE_UPDATE_LATER_BTN_TEXT)
class PurchasePage(ui_core.UIPage):
"""Fitbit Companion App's page to purchase merchandise."""
PAGE_RE_TEXT = 'Protect Your New Device'
NODE_SKIP_BTN_TEXT = 'NOT NOW'
def skip(self) -> ui_core.UIPage:
"""Skips the purchase action.
Returns:
The transformed page.
"""
return self.click_node_by_text(self.NODE_SKIP_BTN_TEXT)
|