73 lines
2.3 KiB
Python
73 lines
2.3 KiB
Python
from __future__ import annotations
|
|
|
|
from .device_profile import DeviceProfile
|
|
|
|
|
|
def _density_dpi(profile: DeviceProfile) -> str:
|
|
return str(int(round(profile.screen_density * 160)))
|
|
|
|
|
|
def _model_name(profile: DeviceProfile) -> str:
|
|
return f"{profile.manufacturer}({profile.model})"
|
|
|
|
|
|
def device_profile_cookie_fields(profile: DeviceProfile) -> dict[str, str]:
|
|
model_name = _model_name(profile)
|
|
return {
|
|
"did": profile.did,
|
|
"oDid": profile.o_did,
|
|
"rdid": profile.rdid,
|
|
"egid": profile.egid,
|
|
"oaid": profile.runtime_hints.oaid,
|
|
"cdid_tag": str(profile.cdid_tag),
|
|
"did_tag": "0",
|
|
"appver": profile.app_version,
|
|
"ver": ".".join(profile.app_version.split(".")[:2]),
|
|
"sys": f"ANDROID_{profile.android_release}",
|
|
"androidApiLevel": "36" if profile.android_release == "16" else profile.android_release,
|
|
"mod": model_name,
|
|
"deviceName": model_name,
|
|
"c": profile.brand,
|
|
"oc": profile.brand,
|
|
"newOc": profile.brand,
|
|
"isp": profile.isp,
|
|
"country_code": profile.country_code,
|
|
"countryCode": profile.country_code.upper(),
|
|
"sid": profile.sid,
|
|
"cold_launch_time_ms": str(profile.cold_launch_time_ms),
|
|
"did_gt": profile.runtime_hints.did_gt or str(profile.install_time_ms),
|
|
"boardPlatform": profile.board_platform,
|
|
"socName": profile.soc_name,
|
|
"max_memory": str(profile.max_memory),
|
|
"deviceBit": profile.device_bit,
|
|
"sw": str(profile.screen_width),
|
|
"sh": str(profile.screen_height),
|
|
"sbh": str(profile.status_bar_height),
|
|
"ddpi": _density_dpi(profile),
|
|
"totalMemory": str(profile.total_memory_mb),
|
|
"abi": "arm64",
|
|
"device_abi": "arm64",
|
|
}
|
|
|
|
|
|
def apply_device_profile_to_cookie(
|
|
cookie: dict[str, str],
|
|
profile: DeviceProfile,
|
|
) -> dict[str, str]:
|
|
out = dict(cookie)
|
|
out.update(device_profile_cookie_fields(profile))
|
|
if "ud" not in out and "userId" in out:
|
|
out["ud"] = out["userId"]
|
|
return out
|
|
|
|
|
|
def cookie_to_string(cookie: dict[str, str]) -> str:
|
|
return "; ".join(f"{key}={value}" for key, value in cookie.items())
|
|
|
|
|
|
__all__ = [
|
|
"apply_device_profile_to_cookie",
|
|
"cookie_to_string",
|
|
"device_profile_cookie_fields",
|
|
]
|