3 import subprocess, os, argparse
6 from getpass import getpass
8 # Default .NET application used in TV
10 "com.samsung.tv.csfs",
11 "com.samsung.tv.mycontents",
12 "com.samsung.tv.samsung-health",
13 "com.samsung.tv.searchall",
14 "com.samsung.tv.social-chat-app",
15 "com.samsung.tv.store"]
17 # Default system module used for candidate process in TV
18 pre_system_module_lists = [
19 "System.Private.CoreLib",
24 tizen_profile_data_path = "/home/owner/data/.__tizen_candidate_profile_data"
27 return subprocess.run((f"sdb -s {serial_num} " + command).split(), encoding="utf-8", stdout=subprocess.PIPE)
30 def download_mcj_edit():
31 if not os.path.exists("mcj-edit.py"):
32 print("Download mcj-edit.py: Start")
34 user_id = input("Username for 'https://github.sec.samsung.net': ")
35 password = getpass(f"Password for 'https://{user_id}@github.sec.samsung.net': ")
36 subprocess.Popen((f"curl -L -O https://raw.github.sec.samsung.net/dotnet/runtime/release/6.0-tizen/src/coreclr/tools/mcj-edit/mcj-edit.py -u {user_id}:{password} -v").split(), encoding="utf-8", stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout
38 with open("mcj-edit.py", 'r') as f:
39 if "404: Not Found" == f.readline():
40 print("\nremote: Invalid username or password.")
41 os.remove("mcj-edit.py")
44 print("Download mcj-edit.py: End")
48 print("Get profile data: Start")
51 print(f"Kill appId: {app}")
52 cmd(f"shell app_launcher -t {app}")
53 cmd(f"shell dotnettool --rm-app-profile {app}")
56 cmd(f"shell cp {tizen_profile_data_path} {tizen_profile_data_path}.origin")
57 cmd(f"shell rm {tizen_profile_data_path}")
58 cmd(f'shell killall dotnet-hydra-loader dotnet-loader')
62 print(f"Launch appId: {app}")
63 cmd(f"shell app_launcher -s {app}")
65 cmd(f"shell app_launcher -t {app}")
66 cmd(f"pull /home/owner/apps_rw/{app}/data/.__tizen_specific_profile_data {app}")
69 print("Get profile data: End")
73 print("Split profile data: Start")
75 system_module_path = ""
76 with open("system_module", 'w') as f:
77 for module in sys_modules:
79 print(f"System modules: {module}")
82 print(f"Split appId: {app}")
83 subprocess.run((f"python3 mcj-edit.py split -i {app} --system-modules-list system_module").split(), encoding="utf-8", stdout=subprocess.PIPE)
86 os.remove("system_module")
88 print("Split profile data: End")
92 cmd(f"shell chsmack -a User::App::Shared {tizen_profile_data_path}")
93 cmd(f"shell chown owner:users {tizen_profile_data_path}")
94 cmd(f"shell chmod 644 {tizen_profile_data_path}")
95 cmd(f"shell rm {tizen_profile_data_path}.origin")
96 os.remove("mcj-edit.py")
99 subprocess.run((f"rm {app}").split(), encoding="utf-8", stdout=subprocess.PIPE)
100 subprocess.run((f"rm {app}.app").split(), encoding="utf-8", stdout=subprocess.PIPE)
101 subprocess.run((f"rm {app}.sys").split(), encoding="utf-8", stdout=subprocess.PIPE)
105 print("Merge profile data: Start")
109 app_sys_lists += f"-i {app}.sys "
111 subprocess.run((f"python3 mcj-edit.py merge " + app_sys_lists + "-o .__tizen_candidate_profile_data").split(), encoding="utf-8", stdout=subprocess.PIPE)
114 print("Merge profile data: End")
116 if not os.path.exists(f".__tizen_candidate_profile_data"):
117 cmd(f"shell cp {tizen_profile_data_path}.origin {tizen_profile_data_path}")
119 print("Candidate profile data generation: FAIL")
122 cmd(f"push .__tizen_candidate_profile_data /home/owner/data/")
124 print("Candidate profile data generation: SUCCESS")
130 raw = subprocess.run(("sdb devices").split(), encoding="utf-8", stdout=subprocess.PIPE).stdout
131 lines = [l for l in raw.splitlines() if not l.startswith("* ")]
134 elif len(lines) == 2:
135 serial_num = lines[1].split(" ")[0].split(":")[0].strip()
138 for idx in range(1, len(lines)):
139 serial = lines[idx].split(" ")[0].split(":")[0].replace("device", "").strip()
140 serials.append(serial)
141 print(f"[{idx}] {serial} - {lines[idx].split(' ')[2].strip()}")
142 choice = input(f"Select a device [1-{len(lines) - 1}]: ")
143 serial_num = serials[int(choice) - 1].strip() if choice.isdigit() else None
150 https://github.sec.samsung.net/dotnet/runtime/blob/release/6.0-tizen/src/coreclr/tools/mcj-edit/README.md
153 global app_ids, sys_modules
155 parser = argparse.ArgumentParser(description="Profile data generation tools to use in candidate process", epilog=epilog, formatter_class=argparse.RawDescriptionHelpFormatter)
156 parser.add_argument("-a", metavar="APP_ID", nargs="*", type=str, help='target app ids (default: predefined 6 applications)', default=pre_app_lists)
157 parser.add_argument("-s", metavar="SYS_MODULE", nargs="*", type=str, help='system module lists (default: predefined 4 system modules)', default=pre_system_module_lists)
158 args = parser.parse_args()
162 serial = read_serial()
164 print("No connected device(s).")
168 cmd(f"shell mount -o remount,rw /")
176 if __name__ == "__main__":
179 except KeyboardInterrupt: