1#!/usr/bin/env python3 2# 3# Copyright 2024 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17 18"""Update Aliases.""" 19 20import inspect 21import os 22import sys 23from core.errors import WorkflowError 24 25 26class Alias: 27 """Base class for defining an alias.""" 28 29 def build(self): 30 return [] 31 32 def update(self): 33 return [] 34 35 36class Core(Alias): 37 """Alias for Core.""" 38 39 def build(self): 40 return ['m framework framework-minus-apex'] 41 42 def update(self): 43 return [ 44 'adevice update', 45 ] 46 47 48class SystemServer(Alias): 49 """Alias for SystemServer.""" 50 51 def update(self): 52 return [ 53 'adevice update --restart=none', 54 'adb kill systemserver', 55 ] 56 57 58class SysUI(Alias): 59 """Alias for SystemUI.""" 60 61 def build(self): 62 if is_nexus(): 63 raise WorkflowError( 64 "Target 'sysui' is not allowed on Nexus Experience devices.\n" 65 'Try sysuig (with g at the end) or sysuititan' 66 ) 67 return ['m framework framework-minus-apex SystemUI'] 68 69 def update(self): 70 target = 'com.android.systemui' 71 return [ 72 'adevice update --restart=none', 73 f'adb shell "am force-stop {target}"', 74 ] 75 76 77class SysUIG(Alias): 78 """Alias for SystemUI for Google Devices.""" 79 80 def build(self): 81 if not is_nexus(): 82 raise WorkflowError( 83 "Target 'sysuig' is only allowed on Nexus Experience devices.\n" 84 'Try sysui (no g at the end)' 85 ) 86 return ['m framework framework-minus-apex SystemUIGoogle'] 87 88 def update(self): 89 target = 'com.android.systemui' 90 return [ 91 'adevice update --restart=none', 92 f'adb shell am force-stop {target}', 93 ] 94 95 96class SysUITitan(Alias): 97 """Alias for SystemUI Titan devices.""" 98 99 def build(self): 100 if not is_nexus(): 101 raise WorkflowError( 102 "Target 'sysuititan' is only allowed on Nexus Experience devices.\n" 103 'Try sysui (no g at the end)' 104 ) 105 return ['m framework framework-minus-apex SystemUITitan'] 106 107 def update(self): 108 target = 'com.android.systemui' 109 return [ 110 'adevice update --restart=none', 111 f'adb shell am force-stop {target}', 112 ] 113 114 115class SysUIGo(Alias): 116 """Alias for SystemUI.""" 117 118 def build(self): 119 if not is_nexus(): 120 raise WorkflowError( 121 "Target 'sysuigo' is only allowed on Nexus Experience devices.\n" 122 'Try sysui (no go at the end)' 123 ) 124 return ['m framework framework-minus-apex SystemUIGo'] 125 126 def update(self): 127 target = 'com.android.systemui' 128 return [ 129 'adevice update --restart=none', 130 f'adb shell am force-stop {target}', 131 ] 132 133 134class CarSysUI(Alias): 135 """Alias for CarSystemUI.""" 136 137 def build(self): 138 return ['m framework framework-minus-apex CarSystemUI'] 139 140 def update(self): 141 target = 'com.android.systemui' 142 return [ 143 'adevice update --restart=none', 144 f'adb shell am force-stop {target}', 145 ] 146 147 148class CarSysUIG(Alias): 149 """Alias for CarSystemUI.""" 150 151 def build(self): 152 return ['m framework framework-minus-apex AAECarSystemUI'] 153 154 def update(self): 155 target = 'com.android.systemui' 156 return [ 157 'adevice update --restart=none', 158 f'adb shell am force-stop {target}', 159 ] 160 161 162class Droid(Alias): 163 """Alias for Droid.""" 164 165 def build(self): 166 return ['m droid'] 167 168 def update(self): 169 return ['flashall'] 170 171 172class Snod(Alias): 173 """Alias for Snod.""" 174 175 def build(self): 176 return ['m snod'] 177 178 def update(self): 179 return ['flashall'] 180 181 182# These definitions are imported from makepush 183# https://team.git.corp.google.com/android-framework/toolbox/+/refs/heads/main/makepush/makepush.sh 184alias_definitions = { 185 'core_jni': {'build': 'libandroid_runtime'}, 186 'res_jni': {'build': 'libandroidfw libidmap2'}, 187 'idmap2': {'build': 'idmap2 idmap2d'}, 188 'sf': {'build': 'surfaceflinger'}, 189 'res': {'build': 'framework-res'}, 190 'services': {'build': 'services protolog.conf.json.gz'}, 191 'inputflinger': {'build': 'libinputflinger'}, 192 'carsysui': { 193 'build': 'carSystemUI', 194 'update': 'adb shell am force-stop com.android.systemui', 195 }, 196 'carsysuig': { 197 'build': 'AAECarSystemUI', 198 'update': 'adb shell am force-stop com.android.systemui', 199 }, 200 'car-mainline': { 201 'build': 'com.android.car.framework', 202 'update': ( 203 'adb install -r --staged --enable-rollback' 204 ' $OUT/system/apex/com.android.car.framework.apex' 205 ), 206 }, 207 'carfwk': {'build': 'carfwk car-frameworks-service'}, 208 'carfwk-module': {'build': 'car-frameworks-service-module'}, 209 'carsettings': { 210 'build': 'carSettings', 211 'update': 'adb shell am force-stop com.android.car.settings', 212 }, 213 'carks': { 214 'build': 'EmbeddedKitchenSinkApp', 215 'update': 'adb shell am force-stop com.google.android.car.kitchensink', 216 }, 217 'carlauncher': { 218 'build': 'carLauncher', 219 'update': 'adb shell am force-stop com.android.car.carlauncher', 220 }, 221 'carlauncherg': { 222 'build': 'GASCarLauncher', 223 'update': 'adb shell am force-stop com.android.car.carlauncher', 224 }, 225 'car-md-launcher': { 226 'build': 'MultiDisplaySecondaryHomeTestLauncher', 227 'update': ( 228 'adb install' 229 ' $OUT/system/priv-app/MultiDisplaySecondaryHomeTestLauncher/MultiDisplaySecondaryHomeTestLauncher.apk' 230 ), 231 }, 232 'carsuw': { 233 'build': 'carProvision', 234 'update': 'adb shell am force-stop com.android.car.provision', 235 }, 236 'car': {'build': 'android.car'}, 237 'car-builtin': {'build': 'android.car.builtin'}, 238 'vhal-legacy': { 239 'build': 'android.hardware.automotive.vehicle@2.0-service', 240 'update': ( 241 'adb shell am force-stop' 242 ' android.hardware.automotive.vehicle@2.0-service' 243 ), 244 }, 245 'vhal': { 246 'build': 'android.hardware.automotive.vehicle@V1-default-service', 247 'update': ( 248 'adb shell am force-stop' 249 ' android.hardware.automotive.vehicle@V1-default-service' 250 ), 251 }, 252 'vhal-pasa': { 253 'build': 'android.hardware.automotive.vehicle@V1-pasa-service', 254 'update': ( 255 'adb shell am force-stop' 256 ' android.hardware.automotive.vehicle@V1-pasa-service' 257 ), 258 }, 259 'launcher': {'build': 'NexusLauncherRelease'}, 260 'launcherd': { 261 'build': 'nexusLauncherDebug', 262 'update': ( 263 'adb install' 264 ' $OUT/anywhere/priv-app/NexusLauncherDebug/NexusLauncherDebug.apk' 265 ), 266 }, 267 'launchergo': { 268 'build': 'launcherGoGoogle', 269 'update': 'adb shell am force-stop com.android.launcher3', 270 }, 271 'intentresolver': { 272 'build': 'intentResolver', 273 'update': 'adb shell am force-stop com.android.intentresolver', 274 }, 275 'sysuig': { 276 'build': 'systemUIGoogle', 277 'update': 'adb shell am force-stop com.android.systemui', 278 }, 279 'sysuititan': { 280 'build': 'systemUITitan', 281 'update': 'adb shell am force-stop com.android.systemui', 282 }, 283 'sysuigo': { 284 'build': 'systemUIGo', 285 'update': 'adb shell am force-stop com.android.systemui', 286 }, 287 'flagflipper': { 288 'build': 'theFlippinApp', 289 'update': 'adb shell am force-stop com.android.theflippinapp', 290 }, 291 'docsui': { 292 'build': 'documentsUI', 293 'update': 'adb shell am force-stop com.android.documentsui', 294 }, 295 'docsuig': { 296 'build': 'documentsUIGoogle', 297 'update': 'adb shell am force-stop com.google.android.documentsui', 298 }, 299 'settings': { 300 'build': 'settings', 301 'update': 'adb shell am force-stop com.android.settings', 302 }, 303 'settingsg': { 304 'build': 'SettingsGoogle', 305 'update': 'adb shell am force-stop com.google.android.settings', 306 }, 307 'settingsgf': { 308 'build': 'SettingsGoogleFutureFaceEnroll', 309 'update': ( 310 'adb shell am force-stop' 311 ' com.google.android.settings.future.biometrics.faceenroll' 312 ), 313 }, 314 'settings_provider': {'build': 'SettingsProvider'}, 315 'apidemos': { 316 'build': 'ApiDemos', 317 'update': ( 318 'adb install' 319 ' $OUT/testcases/ApiDemos/$var_cache_TARGET_ARCH/ApiDemos.apk' 320 ), 321 }, 322 'teleservice': { 323 'build': 'TeleService', 324 'update': 'adb shell am force-stop com.android.phone', 325 }, 326 'managed_provisioning': { 327 'build': 'ManagedProvisioning', 328 'update': 'adb shell am force-stop com.android.managedprovisioning', 329 }, 330 'car_managed_provisioning': { 331 'build': 'carManagedProvisioning', 332 'update': ( 333 'adb install' 334 ' $OUT/anywhere/priv-app/CarManagedProvisioning/CarManagedProvisioning.apk' 335 ), 336 }, 337 'ctsv': { 338 'build': 'ctsVerifier', 339 'update': ( 340 'adb install' 341 ' $OUT/testcases/CtsVerifier/$var_cache_TARGET_ARCH/CtsVerifier.apk' 342 ), 343 }, 344 'gtsv': { 345 'build': 'gtsVerifier', 346 'update': ( 347 'adb install' 348 ' $OUT/testcases/GtsVerifier/$var_cache_TARGET_ARCH/GtsVerifier.apk' 349 ), 350 }, 351 'suw': { 352 'build': 'Provision', 353 'update': 'adb shell am force-stop com.android.provision', 354 }, 355 'pkg_installer': { 356 'build': 'PackageInstaller', 357 'update': 'adb shell am force-stop com.android.packageinstaller', 358 }, 359 'pkg_installer_g': { 360 'build': 'GooglePackageInstaller', 361 'update': 'adb shell am force-stop com.google.android.packageinstaller', 362 }, 363 'perm_controller': { 364 'build': 'PermissionController', 365 'update': ( 366 'adb install' 367 ' $OUT/apex/com.android.permission/priv-app/PermissionController/PermissionController.apk' 368 ), 369 }, 370 'perm_controller_g': { 371 'build': 'GooglePermissionController', 372 'update': ( 373 'adb install -r' 374 ' $OUT/apex/com.google.android.permission/priv-app/GooglePermissionController/GooglePermissionController.apk' 375 ), 376 }, 377 'wifi': { 378 'build': 'com.android.wifi', 379 'update': ( 380 'adb install -r --staged --enable-rollback' 381 ' $OUT/system/apex/com.android.wifi && adb shell am force-stop' 382 ' com.android.wifi' 383 ), 384 }, 385 'vold': {'build': 'vold', 'update': 'adb shell am force-stop vold'}, 386 'multidisplay': { 387 'build': 'multiDisplayProvider', 388 'update': 'adb shell am force-stop com.android.emulator.multidisplay', 389 }, 390 'wm_ext': { 391 'build': 'androidx.window.extensions', 392 }, 393 'rb': { 394 'build': 'adServicesApk', 395 'update': ( 396 'adb install' 397 ' $OUT/apex/com.android.adservices/priv-app/AdServices/AdServices.apk' 398 ), 399 }, 400 'rb_g': { 401 'build': 'adServicesApkGoogle', 402 'update': ( 403 'adb install' 404 ' $OUT/apex/com.google.android.adservices/priv-app/AdServicesApkGoogle@MASTER/AdServicesApkGoogle.apk' 405 ), 406 }, 407 'sdk_sandbox': { 408 'build': 'sdkSandbox', 409 'update': ( 410 'adb install' 411 ' $OUT/apex/com.google.android.adservices/app/SdkSandboxGoogle@MASTER/SdkSandboxGoogle.apk' 412 ), 413 }, 414} 415 416 417# Utilities to get type of target 418def is_nexus(): 419 target_product = os.getenv('TARGET_PRODUCT') 420 return ( 421 target_product.startswith('.aosp') 422 or 'wembley' in target_product 423 or 'gms_humuhumu' in target_product 424 ) 425 426 427def create_alias_from_config(config): 428 """Generates a Alias class from json.""" 429 alias = Alias() 430 build = config.get('build', None) 431 if build: 432 alias.build = lambda: [f'm {build}'] 433 434 update = config.get('update', None) 435 if update: 436 alias.update = lambda: [ 437 'adevice update --restart=none', 438 update, 439 ] 440 else: 441 alias.update = lambda: ['adevice update'] 442 return alias 443 444 445def get_aliases(): 446 """Dynamically find all aliases.""" 447 # definitions that subclass the Alias class 448 aliases = { 449 name.lower(): cls() 450 for name, cls in inspect.getmembers( 451 sys.modules[__name__], inspect.isclass 452 ) 453 if issubclass(cls, Alias) and cls != Alias 454 } 455 # definitions that are defined in alias_definitions 456 for name, config in alias_definitions.items(): 457 aliases[name.lower()] = create_alias_from_config(config) 458 return aliases 459