flutter-dev 0.1.10__tar.gz → 0.1.12__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/CHANGELOG.md +21 -0
  2. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/PKG-INFO +6 -6
  3. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/README.md +5 -5
  4. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/fdev.py +1 -1
  5. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/flutter_dev.egg-info/SOURCES.txt +1 -0
  6. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/managers/app.py +64 -41
  7. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/pyproject.toml +1 -1
  8. flutter_dev-0.1.12/tests/test_app_commands.py +161 -0
  9. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/.env.example +0 -0
  10. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/LICENSE +0 -0
  11. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/MANIFEST.in +0 -0
  12. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/common_utils.py +0 -0
  13. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/core/__init__.py +0 -0
  14. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/core/ai_config.py +0 -0
  15. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/core/constants.py +0 -0
  16. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/core/state.py +0 -0
  17. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/create_page.py +0 -0
  18. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/gemini_api.py +0 -0
  19. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/git_diff_output_editor.py +0 -0
  20. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/install_legacy.py +0 -0
  21. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/managers/__init__.py +0 -0
  22. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/managers/ai.py +0 -0
  23. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/managers/brew.py +0 -0
  24. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/managers/build.py +0 -0
  25. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/managers/datetime.py +0 -0
  26. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/managers/device.py +0 -0
  27. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/managers/doctor.py +0 -0
  28. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/managers/git.py +0 -0
  29. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/managers/git_account.py +0 -0
  30. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/managers/localization.py +0 -0
  31. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/managers/merge.py +0 -0
  32. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/managers/mirror.py +0 -0
  33. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/managers/package.py +0 -0
  34. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/managers/project.py +0 -0
  35. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/managers/web_deploy.py +0 -0
  36. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/requirements.txt +0 -0
  37. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/setup.cfg +0 -0
  38. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/setup.py +0 -0
  39. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/switch_ai.py +0 -0
  40. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/tests/test_ai_config.py +0 -0
  41. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/tests/test_fdev_cli.py +0 -0
  42. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/tests/test_localization.py +0 -0
  43. {flutter_dev-0.1.10 → flutter_dev-0.1.12}/tests/test_package_commands.py +0 -0
@@ -2,6 +2,27 @@
2
2
 
3
3
  All notable changes to this project are documented in this file.
4
4
 
5
+ ## 0.1.12 - 2026-07-22
6
+
7
+ ### Changed
8
+
9
+ - Updated the PyPI workflow to use Node.js 24-native `actions/upload-artifact@v7`.
10
+
11
+ ### Fixed
12
+
13
+ - Fixed `fdev clear-data` to verify that the current project app is installed before clearing it, and to fall back to a confirmed foreground-app clear when the project app is missing or the direct clear fails.
14
+
15
+ ## 0.1.11 - 2026-07-22
16
+
17
+ ### Added
18
+
19
+ - Added Python regression coverage for project-root and outside-project `fdev clear-data` behavior.
20
+
21
+ ### Changed
22
+
23
+ - Changed `fdev clear-data` to target the current project's Android package without confirmation when run from a Flutter project root, matching `fdev uninstall`; outside a project it still confirms before clearing the foreground app.
24
+ - Updated the PyPI publishing workflow to run on pushes to the `deployment` branch as well as manual dispatches.
25
+
5
26
  ## 0.1.10 - 2026-07-16
6
27
 
7
28
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flutter-dev
3
- Version: 0.1.10
3
+ Version: 0.1.12
4
4
  Summary: A cross-platform CLI toolkit for Flutter development workflows.
5
5
  Author: Royal Court BD
6
6
  License-Expression: MIT
@@ -42,14 +42,14 @@ The package is published on PyPI as `flutter-dev` and installs console commands
42
42
  python -m pip install flutter-dev
43
43
  ```
44
44
 
45
- Current package metadata declares version `0.1.10`, Python `>=3.8`, MIT license, and support for macOS, Linux, and Windows.
45
+ Current package metadata declares version `0.1.12`, Python `>=3.8`, MIT license, and support for macOS, Linux, and Windows.
46
46
 
47
47
  ## Key Features
48
48
 
49
49
  - Flutter build automation for APK, split APK, AAB, IPA, release install, and Firebase web deploy.
50
50
  - Project maintenance helpers for `flutter clean`, dependency refresh, `build_runner`, localization generation, analysis, formatting, cache repair, and CocoaPods.
51
51
  - Localization CSV helpers for exporting ARB files to translator-friendly CSV files and generating ARB files back from CSV.
52
- - Android device helpers for APK install, app uninstall, foreground app data clearing, screen mirroring with `scrcpy`, wireless ADB setup, and Date & Time settings.
52
+ - Android device helpers for APK install, app uninstall, project/foreground app data clearing, screen mirroring with `scrcpy`, wireless ADB setup, and Date & Time settings.
53
53
  - AI-assisted Git commits using Groq, Mistral, SambaNova, or OpenRouter-compatible chat completion APIs.
54
54
  - Git workflow helpers for version tags, branch sync, deployment branch merge, discard, and GitHub account management through `gh`.
55
55
  - Feature/page generator that creates a `lib/features/<name>` structure using the project's presenter/base-state pattern.
@@ -201,7 +201,7 @@ Android APK/AAB build commands rename output files using the Android app label a
201
201
  | --- | --- |
202
202
  | `fdev install` | Installs a built APK from `build/app/outputs/flutter-apk`, prefers `arm64-v8a`, retries after uninstall on failure, then launches the app. |
203
203
  | `fdev uninstall` | In a Flutter project root, uninstalls by package/bundle id. Outside a project, detects the foreground app and asks for confirmation. |
204
- | `fdev clear-data` | Detects the foreground app and runs `adb shell pm clear <package>` on Android. Confirmation is skipped when it matches the current Flutter project; otherwise the default-Yes safety prompt is shown. iOS prints manual options. |
204
+ | `fdev clear-data` | In a Flutter project root, clears the installed project's Android package data without confirmation; if it is missing or the clear fails, falls back to the foreground app with a default-Yes safety prompt. Outside a project, always detects and confirms the foreground app. iOS prints manual options. |
205
205
  | `fdev install-scrcpy` | Installs `scrcpy` using the best supported package manager for the current platform. |
206
206
  | `fdev mirror` | Launches `scrcpy` for a selected Android device. |
207
207
  | `fdev mirror --wireless` | Guides wireless ADB setup using a USB-connected Android device. |
@@ -390,7 +390,7 @@ core/constants.py Shared regex patterns, paths, and build command constant
390
390
  core/state.py Selected Android device state
391
391
  managers/build.py APK/AAB/IPA/release-run build workflow
392
392
  managers/project.py setup, cleanup, lang, db, pod, cache repair
393
- managers/app.py install, uninstall, foreground app data clearing
393
+ managers/app.py install, uninstall, project/foreground app data clearing
394
394
  managers/device.py ADB device detection and selection
395
395
  managers/mirror.py scrcpy install, mirror, wireless ADB setup
396
396
  managers/git.py commit, tag, discard, branch sync, deployment merge
@@ -413,7 +413,7 @@ The installed Python layout is top-level modules plus the `core` and `managers`
413
413
  - `fdev tag` updates `pubspec.yaml`, creates a commit, creates a Git tag, and pushes both.
414
414
  - `fdev discard` removes tracked changes and untracked files after confirmation.
415
415
  - `fdev cleanup` applies `dart fix`, formats the project, and runs a major-version dependency upgrade.
416
- - `fdev clear-data` skips confirmation only when the foreground Android app matches the current Flutter project's package ID; otherwise it uses a default-Yes `[Y/n]` confirmation.
416
+ - `fdev clear-data` clears the installed current project's Android package without confirmation when run from a Flutter project root. If that package is missing or cannot be cleared, and whenever the command runs outside a project, it targets the foreground app after a default-Yes `[Y/n]` confirmation.
417
417
  - `fdev uninstall` may fall back to foreground app detection outside a Flutter project root.
418
418
  - `fdev upgrade` and `fdev delete` manage the local `flutter-dev` Python package, not the Flutter app on a device.
419
419
  - `fdev upgrade` reports the installed version and location before upgrading, then shows the before→after version when the active process can verify it immediately.
@@ -8,14 +8,14 @@ The package is published on PyPI as `flutter-dev` and installs console commands
8
8
  python -m pip install flutter-dev
9
9
  ```
10
10
 
11
- Current package metadata declares version `0.1.10`, Python `>=3.8`, MIT license, and support for macOS, Linux, and Windows.
11
+ Current package metadata declares version `0.1.12`, Python `>=3.8`, MIT license, and support for macOS, Linux, and Windows.
12
12
 
13
13
  ## Key Features
14
14
 
15
15
  - Flutter build automation for APK, split APK, AAB, IPA, release install, and Firebase web deploy.
16
16
  - Project maintenance helpers for `flutter clean`, dependency refresh, `build_runner`, localization generation, analysis, formatting, cache repair, and CocoaPods.
17
17
  - Localization CSV helpers for exporting ARB files to translator-friendly CSV files and generating ARB files back from CSV.
18
- - Android device helpers for APK install, app uninstall, foreground app data clearing, screen mirroring with `scrcpy`, wireless ADB setup, and Date & Time settings.
18
+ - Android device helpers for APK install, app uninstall, project/foreground app data clearing, screen mirroring with `scrcpy`, wireless ADB setup, and Date & Time settings.
19
19
  - AI-assisted Git commits using Groq, Mistral, SambaNova, or OpenRouter-compatible chat completion APIs.
20
20
  - Git workflow helpers for version tags, branch sync, deployment branch merge, discard, and GitHub account management through `gh`.
21
21
  - Feature/page generator that creates a `lib/features/<name>` structure using the project's presenter/base-state pattern.
@@ -167,7 +167,7 @@ Android APK/AAB build commands rename output files using the Android app label a
167
167
  | --- | --- |
168
168
  | `fdev install` | Installs a built APK from `build/app/outputs/flutter-apk`, prefers `arm64-v8a`, retries after uninstall on failure, then launches the app. |
169
169
  | `fdev uninstall` | In a Flutter project root, uninstalls by package/bundle id. Outside a project, detects the foreground app and asks for confirmation. |
170
- | `fdev clear-data` | Detects the foreground app and runs `adb shell pm clear <package>` on Android. Confirmation is skipped when it matches the current Flutter project; otherwise the default-Yes safety prompt is shown. iOS prints manual options. |
170
+ | `fdev clear-data` | In a Flutter project root, clears the installed project's Android package data without confirmation; if it is missing or the clear fails, falls back to the foreground app with a default-Yes safety prompt. Outside a project, always detects and confirms the foreground app. iOS prints manual options. |
171
171
  | `fdev install-scrcpy` | Installs `scrcpy` using the best supported package manager for the current platform. |
172
172
  | `fdev mirror` | Launches `scrcpy` for a selected Android device. |
173
173
  | `fdev mirror --wireless` | Guides wireless ADB setup using a USB-connected Android device. |
@@ -356,7 +356,7 @@ core/constants.py Shared regex patterns, paths, and build command constant
356
356
  core/state.py Selected Android device state
357
357
  managers/build.py APK/AAB/IPA/release-run build workflow
358
358
  managers/project.py setup, cleanup, lang, db, pod, cache repair
359
- managers/app.py install, uninstall, foreground app data clearing
359
+ managers/app.py install, uninstall, project/foreground app data clearing
360
360
  managers/device.py ADB device detection and selection
361
361
  managers/mirror.py scrcpy install, mirror, wireless ADB setup
362
362
  managers/git.py commit, tag, discard, branch sync, deployment merge
@@ -379,7 +379,7 @@ The installed Python layout is top-level modules plus the `core` and `managers`
379
379
  - `fdev tag` updates `pubspec.yaml`, creates a commit, creates a Git tag, and pushes both.
380
380
  - `fdev discard` removes tracked changes and untracked files after confirmation.
381
381
  - `fdev cleanup` applies `dart fix`, formats the project, and runs a major-version dependency upgrade.
382
- - `fdev clear-data` skips confirmation only when the foreground Android app matches the current Flutter project's package ID; otherwise it uses a default-Yes `[Y/n]` confirmation.
382
+ - `fdev clear-data` clears the installed current project's Android package without confirmation when run from a Flutter project root. If that package is missing or cannot be cleared, and whenever the command runs outside a project, it targets the foreground app after a default-Yes `[Y/n]` confirmation.
383
383
  - `fdev uninstall` may fall back to foreground app detection outside a Flutter project root.
384
384
  - `fdev upgrade` and `fdev delete` manage the local `flutter-dev` Python package, not the Flutter app on a device.
385
385
  - `fdev upgrade` reports the installed version and location before upgrading, then shows the before→after version when the active process can verify it immediately.
@@ -102,7 +102,7 @@ def show_usage(exit_code=1):
102
102
  print(f"\n{BLUE}Device Commands:{NC}")
103
103
  print(" install Install built APK on connected device")
104
104
  print(" uninstall Uninstall app from connected device")
105
- print(" clear-data Clear data of currently running foreground app")
105
+ print(" clear-data Clear project app data with confirmed foreground fallback")
106
106
  print(" install-scrcpy Install scrcpy for Android screen mirroring")
107
107
  print(" mirror Launch scrcpy screen mirror (auto-detect device)")
108
108
  print(" --wireless Setup wireless ADB connection")
@@ -34,6 +34,7 @@ managers/package.py
34
34
  managers/project.py
35
35
  managers/web_deploy.py
36
36
  tests/test_ai_config.py
37
+ tests/test_app_commands.py
37
38
  tests/test_fdev_cli.py
38
39
  tests/test_localization.py
39
40
  tests/test_package_commands.py
@@ -186,12 +186,65 @@ def get_current_foreground_app():
186
186
 
187
187
  def clear_app_data():
188
188
  """
189
- Automatically clear data of currently running foreground app
190
- Works for both Android and iOS on all operating systems (macOS, Linux, Windows)
189
+ Clear app data from a connected device.
190
+
191
+ In a Flutter project root, clear the project's installed Android package
192
+ without confirmation. If it is not installed or cannot be cleared, fall
193
+ back to the foreground app with confirmation. Outside a project root,
194
+ always detect and confirm before clearing the foreground app.
191
195
  """
192
- print(f"{YELLOW}Clearing app data for foreground app...{NC}\n")
196
+ print(f"{YELLOW}Clearing app data...{NC}\n")
193
197
 
194
- # Get current foreground app
198
+ # Match uninstall behavior in a Flutter project: target the installed
199
+ # project package first, then fall back to the foreground app if needed.
200
+ if is_flutter_project_root() and get_all_connected_devices():
201
+ print(f"{GREEN}✓ Flutter project detected{NC}\n")
202
+ print(f"{BLUE}Android device detected{NC}")
203
+
204
+ if not ensure_device_connected("Device selection failed!"):
205
+ return False
206
+
207
+ package_name = get_package_name()
208
+ if not package_name:
209
+ print(f"{RED}Cannot proceed without package name{NC}")
210
+ return False
211
+
212
+ print(f"{BLUE}Package name: {package_name}{NC}\n")
213
+
214
+ if is_app_installed(package_name):
215
+ print(f"{GREEN}✓ App is installed on device{NC}\n")
216
+ success = _clear_android_package_data(package_name)
217
+ if success:
218
+ return True
219
+
220
+ print(f"\n{YELLOW}⚠️ Could not clear data for {package_name}{NC}")
221
+ else:
222
+ print(f"{YELLOW}⚠️ Project app is not installed on device{NC}")
223
+
224
+ print(f"{YELLOW} Detecting foreground app instead...{NC}\n")
225
+
226
+ return _clear_foreground_app_data()
227
+
228
+
229
+ def _clear_android_package_data(package_name):
230
+ """Clear one Android package and report the command result."""
231
+ success = run_flutter_command(
232
+ build_adb_cmd(["shell", "pm", "clear", package_name]),
233
+ "Clearing app data... ",
234
+ )
235
+
236
+ if success:
237
+ print(f"\n{GREEN}✓ App data cleared successfully!{NC}")
238
+ print(f"{BLUE}You can now relaunch the app from the device{NC}")
239
+ else:
240
+ print(f"\n{RED}✗ Failed to clear app data!{NC}")
241
+ print(f"{YELLOW}Make sure the app package name is correct{NC}")
242
+
243
+ return success
244
+
245
+
246
+ def _clear_foreground_app_data():
247
+ """Detect the foreground app and clear it only after confirmation."""
195
248
  platform_type, package_name = get_current_foreground_app()
196
249
 
197
250
  if not platform_type:
@@ -207,45 +260,15 @@ def clear_app_data():
207
260
  print(f"{BLUE}Platform: {platform_type.upper()}{NC}")
208
261
  print(f"{BLUE}App: {package_name}{NC}\n")
209
262
 
210
- # Skip confirmation only when the foreground app matches the current
211
- # Flutter project's Android package. Otherwise, keep the safety prompt.
212
- project_package = get_package_name() if is_flutter_project_root() else None
213
- is_current_project_app = (
214
- platform_type == "android"
215
- and project_package is not None
216
- and project_package == package_name
217
- )
218
-
219
- if is_current_project_app:
220
- print(f"{GREEN}✓ Foreground app matches the current Flutter project{NC}\n")
221
- else:
222
- if project_package and platform_type == "android":
223
- print(f"{YELLOW}⚠️ Foreground app does not match the current Flutter project{NC}")
224
- print(f"{BLUE}Project package: {project_package}{NC}\n")
225
-
226
- user_input = input(
227
- f"Clear data for {GREEN}{package_name}{NC}? [Y/n]: "
228
- ).strip().lower()
229
- if user_input in ("n", "no"):
230
- print(f"{YELLOW}Operation cancelled{NC}")
231
- return False
263
+ user_input = input(
264
+ f"Clear data for {GREEN}{package_name}{NC}? [Y/n]: "
265
+ ).strip().lower()
266
+ if user_input in ("n", "no"):
267
+ print(f"{YELLOW}Operation cancelled{NC}")
268
+ return False
232
269
 
233
- # Clear data based on platform
234
270
  if platform_type == "android":
235
- # Clear app data on Android
236
- success = run_flutter_command(
237
- build_adb_cmd(["shell", "pm", "clear", package_name]),
238
- f"Clearing app data... "
239
- )
240
-
241
- if success:
242
- print(f"\n{GREEN}✓ App data cleared successfully!{NC}")
243
- print(f"{BLUE}You can now relaunch the app from the device{NC}")
244
- else:
245
- print(f"\n{RED}✗ Failed to clear app data!{NC}")
246
- print(f"{YELLOW}Make sure the app package name is correct{NC}")
247
-
248
- return success
271
+ return _clear_android_package_data(package_name)
249
272
 
250
273
  elif platform_type == "ios":
251
274
  # iOS doesn't support direct app data clearing via command line
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "flutter-dev"
7
- version = "0.1.10"
7
+ version = "0.1.12"
8
8
  description = "A cross-platform CLI toolkit for Flutter development workflows."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -0,0 +1,161 @@
1
+ import unittest
2
+ from unittest.mock import patch
3
+
4
+ from managers import app
5
+
6
+
7
+ class ClearAppDataTests(unittest.TestCase):
8
+ def test_project_root_clears_project_package_without_confirmation(self):
9
+ with (
10
+ patch.object(app, "is_flutter_project_root", return_value=True),
11
+ patch.object(app, "get_all_connected_devices", return_value=["device-1"]),
12
+ patch.object(app, "ensure_device_connected", return_value=True),
13
+ patch.object(app, "get_package_name", return_value="com.example.app"),
14
+ patch.object(app, "is_app_installed", return_value=True),
15
+ patch.object(
16
+ app,
17
+ "build_adb_cmd",
18
+ return_value=["adb", "shell", "pm", "clear", "com.example.app"],
19
+ ),
20
+ patch.object(app, "run_flutter_command", return_value=True) as run_command,
21
+ patch.object(app, "get_current_foreground_app") as foreground_app,
22
+ patch("builtins.input") as user_input,
23
+ ):
24
+ result = app.clear_app_data()
25
+
26
+ self.assertTrue(result)
27
+ foreground_app.assert_not_called()
28
+ user_input.assert_not_called()
29
+ run_command.assert_called_once_with(
30
+ ["adb", "shell", "pm", "clear", "com.example.app"],
31
+ "Clearing app data... ",
32
+ )
33
+
34
+ def test_missing_project_app_falls_back_to_confirmed_foreground_app(self):
35
+ with (
36
+ patch.object(app, "is_flutter_project_root", return_value=True),
37
+ patch.object(app, "get_all_connected_devices", return_value=["device-1"]),
38
+ patch.object(app, "ensure_device_connected", return_value=True),
39
+ patch.object(app, "get_package_name", return_value="com.example.app"),
40
+ patch.object(app, "is_app_installed", return_value=False),
41
+ patch.object(
42
+ app,
43
+ "get_current_foreground_app",
44
+ return_value=("android", "com.example.foreground"),
45
+ ) as foreground_app,
46
+ patch.object(
47
+ app,
48
+ "build_adb_cmd",
49
+ return_value=[
50
+ "adb",
51
+ "shell",
52
+ "pm",
53
+ "clear",
54
+ "com.example.foreground",
55
+ ],
56
+ ),
57
+ patch.object(app, "run_flutter_command", return_value=True) as run_command,
58
+ patch("builtins.input", return_value="") as user_input,
59
+ ):
60
+ result = app.clear_app_data()
61
+
62
+ self.assertTrue(result)
63
+ foreground_app.assert_called_once_with()
64
+ user_input.assert_called_once()
65
+ run_command.assert_called_once_with(
66
+ ["adb", "shell", "pm", "clear", "com.example.foreground"],
67
+ "Clearing app data... ",
68
+ )
69
+
70
+ def test_failed_project_clear_falls_back_to_confirmed_foreground_app(self):
71
+ def adb_command(parts):
72
+ return ["adb", *parts]
73
+
74
+ with (
75
+ patch.object(app, "is_flutter_project_root", return_value=True),
76
+ patch.object(app, "get_all_connected_devices", return_value=["device-1"]),
77
+ patch.object(app, "ensure_device_connected", return_value=True),
78
+ patch.object(app, "get_package_name", return_value="com.example.app"),
79
+ patch.object(app, "is_app_installed", return_value=True),
80
+ patch.object(
81
+ app,
82
+ "get_current_foreground_app",
83
+ return_value=("android", "com.example.foreground"),
84
+ ),
85
+ patch.object(app, "build_adb_cmd", side_effect=adb_command),
86
+ patch.object(
87
+ app,
88
+ "run_flutter_command",
89
+ side_effect=[False, True],
90
+ ) as run_command,
91
+ patch("builtins.input", return_value="") as user_input,
92
+ ):
93
+ result = app.clear_app_data()
94
+
95
+ self.assertTrue(result)
96
+ user_input.assert_called_once()
97
+ self.assertEqual(run_command.call_count, 2)
98
+ self.assertEqual(
99
+ run_command.call_args_list[0].args[0],
100
+ ["adb", "shell", "pm", "clear", "com.example.app"],
101
+ )
102
+ self.assertEqual(
103
+ run_command.call_args_list[1].args[0],
104
+ ["adb", "shell", "pm", "clear", "com.example.foreground"],
105
+ )
106
+
107
+ def test_missing_project_app_foreground_fallback_can_be_cancelled(self):
108
+ with (
109
+ patch.object(app, "is_flutter_project_root", return_value=True),
110
+ patch.object(app, "get_all_connected_devices", return_value=["device-1"]),
111
+ patch.object(app, "ensure_device_connected", return_value=True),
112
+ patch.object(app, "get_package_name", return_value="com.example.app"),
113
+ patch.object(app, "is_app_installed", return_value=False),
114
+ patch.object(
115
+ app,
116
+ "get_current_foreground_app",
117
+ return_value=("android", "com.example.foreground"),
118
+ ),
119
+ patch.object(app, "run_flutter_command") as run_command,
120
+ patch("builtins.input", return_value="n") as user_input,
121
+ ):
122
+ result = app.clear_app_data()
123
+
124
+ self.assertFalse(result)
125
+ user_input.assert_called_once()
126
+ run_command.assert_not_called()
127
+
128
+ def test_outside_project_confirms_before_clearing_foreground_app(self):
129
+ with (
130
+ patch.object(app, "is_flutter_project_root", return_value=False),
131
+ patch.object(
132
+ app,
133
+ "get_current_foreground_app",
134
+ return_value=("android", "com.example.foreground"),
135
+ ),
136
+ patch.object(
137
+ app,
138
+ "build_adb_cmd",
139
+ return_value=[
140
+ "adb",
141
+ "shell",
142
+ "pm",
143
+ "clear",
144
+ "com.example.foreground",
145
+ ],
146
+ ),
147
+ patch.object(app, "run_flutter_command", return_value=True) as run_command,
148
+ patch("builtins.input", return_value="") as user_input,
149
+ ):
150
+ result = app.clear_app_data()
151
+
152
+ self.assertTrue(result)
153
+ user_input.assert_called_once()
154
+ run_command.assert_called_once_with(
155
+ ["adb", "shell", "pm", "clear", "com.example.foreground"],
156
+ "Clearing app data... ",
157
+ )
158
+
159
+
160
+ if __name__ == "__main__":
161
+ unittest.main()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes