From: Jeff Sharkey Date: Wed, 28 Nov 2018 00:33:42 +0000 (-0700) Subject: Guide towards Context.createPackageContextAsUser(). X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=a8e5df06a010406b20a081c780a6e9854a2bad31;p=android-x86%2Fframeworks-base.git Guide towards Context.createPackageContextAsUser(). It's a better alternative that should be used instead of adding new "ForUser" or "AsUser" methods. Bug: 115654727 Test: manual Change-Id: I8742c2ef42d743ef69f8f7a91378f498fdc81e43 (cherry picked from commit 86445841ac90e04941dbc8dad34f2a893a2e0f8b) --- diff --git a/tools/apilint/apilint.py b/tools/apilint/apilint.py index 91cd1cba964d..cb8fef946baf 100644 --- a/tools/apilint/apilint.py +++ b/tools/apilint/apilint.py @@ -1285,10 +1285,19 @@ def verify_user_handle(clazz): if clazz.fullname == "android.os.UserManager": return for m in clazz.methods: - if m.name.endswith("AsUser") or m.name.endswith("ForUser"): continue if re.match("on[A-Z]+", m.name): continue - if "android.os.UserHandle" in m.args: - warn(clazz, m, None, "Method taking UserHandle should be named 'doFooAsUser' or 'queryFooForUser'") + + has_arg = "android.os.UserHandle" in m.args + has_name = m.name.endswith("AsUser") or m.name.endswith("ForUser") + + if clazz.fullname.endswith("Manager") and has_arg: + warn(clazz, m, None, "When a method overload is needed to target a specific " + "UserHandle, callers should be directed to use " + "Context.createPackageContextAsUser() and re-obtain the relevant " + "Manager, and no new API should be added") + elif has_arg and not has_name: + warn(clazz, m, None, "Method taking UserHandle should be named 'doFooAsUser' " + "or 'queryFooForUser'") def verify_params(clazz):