Skip to content

Sync changes from internal dev branch.#91

Merged
kaishi05 merged 8 commits into
mainfrom
copybara_HEAD
Apr 22, 2026
Merged

Sync changes from internal dev branch.#91
kaishi05 merged 8 commits into
mainfrom
copybara_HEAD

Conversation

@lip-liu

@lip-liu lip-liu commented Apr 22, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Google and others added 8 commits April 22, 2026 22:33
PiperOrigin-RevId: 899668942
PiperOrigin-RevId: 901467957
PiperOrigin-RevId: 903887631
PiperOrigin-RevId: 903942917
PiperOrigin-RevId: 903974744
PiperOrigin-RevId: 903994153
PiperOrigin-RevId: 904009306
PiperOrigin-RevId: 904079133

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces two new utility functions, disable_package_verifiers and enable_package_verifiers, to manage package verification settings on rooted Android devices via ADB. It also includes a minor formatting update to an existing version extraction check. A review comment suggests refactoring the new functions to use a common private helper to eliminate code duplication and improve maintainability.

Comment thread betocq/setup_utils.py
Comment on lines +1726 to +1767

def disable_package_verifiers(ad: android_device.AndroidDevice):
"""Disables package verifier and Play Protect for ADB installs."""
try:
if not ad.is_adb_root:
ad.log.info(
'Device is not rooted. Skipping disabling package verifiers.'
)
return
ad.log.info(
'Device is in Root. Disabling package verifier and Play Protect for ADB'
' installs.'
)
ad.adb.shell(['settings', 'put', 'global', 'package_verifier_enable', '0'])
ad.adb.shell(
['settings', 'put', 'global', 'verifier_verify_adb_installs', '0']
)
ad.adb.shell(['settings', 'put', 'global', 'verifier_engprod', '1'])
except adb.AdbError as e:
ad.log.error(f'Failed to disable package verifiers: {e} on '
f'device {ad.serial}.')


def enable_package_verifiers(ad: android_device.AndroidDevice):
"""Reverts package verifier and Play Protect settings."""
try:
if not ad.is_adb_root:
ad.log.info(
'Device is not rooted. Skipping reverting package verifiers.'
)
return
ad.log.info(
'Device is in Root. Reverting package verifier and Play Protect'
' settings for ADB installs.'
)
ad.adb.shell(['settings', 'put', 'global', 'package_verifier_enable', '1'])
ad.adb.shell(
['settings', 'put', 'global', 'verifier_verify_adb_installs', '1']
)
ad.adb.shell(['settings', 'put', 'global', 'verifier_engprod', '0'])
except adb.AdbError as e:
ad.log.error(f'Failed to enable package verifiers: {e} on '

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The functions disable_package_verifiers and enable_package_verifiers share almost identical logic, including the root check, logging, and error handling. This duplication makes the code harder to maintain. Consider refactoring them to use a common private helper function that takes the desired state as a parameter.

def _set_package_verifiers(ad: android_device.AndroidDevice, enable: bool):
  """Sets package verifier and Play Protect settings."""
  try:
    if not ad.is_adb_root:
      ad.log.info(
          f'Device is not rooted. Skipping {"reverting" if enable else "disabling"} package verifiers.'
      )
      return
    action = "Reverting" if enable else "Disabling"
    ad.log.info(
        f'Device is in Root. {action} package verifier and Play Protect'
        ' settings for ADB installs.'
    )
    val = '1' if enable else '0'
    eng_val = '0' if enable else '1'
    ad.adb.shell(['settings', 'put', 'global', 'package_verifier_enable', val])
    ad.adb.shell(['settings', 'put', 'global', 'verifier_verify_adb_installs', val])
    ad.adb.shell(['settings', 'put', 'global', 'verifier_engprod', eng_val])
  except adb.AdbError as e:
    ad.log.error(f'Failed to {action.lower()} package verifiers: {e} on device {ad.serial}.')


def disable_package_verifiers(ad: android_device.AndroidDevice):
  """Disables package verifier and Play Protect for ADB installs."""
  _set_package_verifiers(ad, enable=False)


def enable_package_verifiers(ad: android_device.AndroidDevice):
  """Reverts package verifier and Play Protect settings."""
  _set_package_verifiers(ad, enable=True)

@kaishi05 kaishi05 merged commit a5be20d into main Apr 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants