This topic describes how to use the AgentBay SDK to create cloud phone sessions with advanced configuration options. These configurations allow you to control application access and screen resolution settings in the mobile environment.
Overview
When you create a cloud phone session, you can use the extra_configs field of the CreateSessionParams parameter to configure advanced settings. These settings include the following:
Controlling application access with a whitelist or blacklist.
Locking or unlocking the screen resolution.
Enhancing security and testing flexibility.
Configuration options
Resolution settings
lock_resolution(bool): Specifies whether to lock the screen resolution.True: Locks the resolution to prevent changes.False: Allows resolution changes for flexible display adaptation.
Application management rules
app_manager_rule(AppManagerRule): Specifies the rules that control application access.rule_type: The rule type, which can be "White" (whitelist) or "Black" (blacklist).app_package_name_list: A list of package names to allow or block.
Whitelist configuration
In production environments, use a whitelist to ensure that only approved applications can be installed and accessed. This approach provides the highest level of security by explicitly allowing only trusted applications.
Example: Create a session with an application whitelist
from agentbay import AgentBay
from agentbay.session_params import CreateSessionParams
from agentbay.api.models import ExtraConfigs, MobileExtraConfig, AppManagerRule
# Initialize the SDK
agent_bay = AgentBay(api_key="your_api_key")
# Configure mobile application management with a whitelist
app_whitelist_rule = AppManagerRule(
rule_type="White",
app_package_name_list=[
"com.example.allowed.app",
"com.company.trusted.app",
"com.system.essential.service"
]
)
# Configure mobile settings
mobile_config = MobileExtraConfig(
lock_resolution=True,
app_manager_rule=app_whitelist_rule
)
# Create extra configurations
extra_configs = ExtraConfigs(mobile=mobile_config)
# Create a session with mobile configurations
params = CreateSessionParams(
image_id="mobile_latest",
labels={"project": "mobile-testing", "environment": "development"},
extra_configs=extra_configs
)
session_result = agent_bay.create(params)
if session_result.success:
session = session_result.session
print(f"Mobile session created, ID: {session.session_id}")
print("Mobile configurations applied:")
print("- Resolution is locked")
print("- Application whitelist is enabled with allowed packages")
else:
print(f"Failed to create mobile session: {session_result.error_message}")Blacklist configuration
During development and testing, use a blacklist to block known problematic applications while allowing flexibility for other applications. This configuration blocks access to specific applications without restricting the entire environment.
Sample: Create a session with an application blacklist
from agentbay import AgentBay
from agentbay.session_params import CreateSessionParams
from agentbay.api.models import ExtraConfigs, MobileExtraConfig, AppManagerRule
# Initialize the SDK
agent_bay = AgentBay(api_key="your_api_key")
# Configure mobile application management with a blacklist
app_blacklist_rule = AppManagerRule(
rule_type="Black",
app_package_name_list=[
"com.malware.suspicious.app",
"com.unwanted.adware",
"com.blocked.social.media"
]
)
# Configure mobile settings with resolution flexibility
mobile_config = MobileExtraConfig(
lock_resolution=False,
app_manager_rule=app_blacklist_rule
)
# Create extra configurations
extra_configs = ExtraConfigs(mobile=mobile_config)
# Create a session with a mobile blacklist configuration
params = CreateSessionParams(
image_id="mobile_latest",
labels={"project": "security-testing"},
extra_configs=extra_configs
)
session_result = agent_bay.create(params)
if session_result.success:
session = session_result.session
print(f"Secure mobile session created, ID: {session.session_id}")
print("Security configurations applied:")
print("- Resolution is unlocked for flexibility")
print("- Application blacklist is enabled to block malicious packages")
else:
print(f"Failed to create mobile session: {session_result.error_message}")