From c3199997a359e45fee3526111b4a5d25d8e6ea1b Mon Sep 17 00:00:00 2001 From: paulmiller Date: Wed, 22 Jun 2016 14:52:10 -0700 Subject: [PATCH] Roll internal Google Play Services (Chromium part) BUG=613768 TBR=jbudorick@chromium.org,agrieve@chromium.org,mariakhomenko@chromium.org NOTRY=true (skipping trybots because previous, identical patch passed CQ, and because this is needed to fix the tree) Review-Url: https://codereview.chromium.org/2088073002 Cr-Commit-Position: refs/heads/master@{#401419} --- build/android/play_services/preprocess.py | 50 +++++++++++++------ build/config/android/internal_rules.gni | 17 ++++++- .../chrome/browser/IntentHandler.java | 2 +- .../externalauth/ExternalAuthUtils.java | 11 ++-- 4 files changed, 56 insertions(+), 24 deletions(-) diff --git a/build/android/play_services/preprocess.py b/build/android/play_services/preprocess.py index 99c000e223115b..ef7d97c7cbd041 100755 --- a/build/android/play_services/preprocess.py +++ b/build/android/play_services/preprocess.py @@ -67,9 +67,6 @@ from pylib.utils import argparse_utils -M2_PKG_PATH = os.path.join('com', 'google', 'android', 'gms') - - def main(): parser = argparse.ArgumentParser(description=( "Prepares the Google Play services split client libraries before usage " @@ -168,11 +165,16 @@ def _MakeWritable(dir_path): os.chmod(os.path.join(root, path), st.st_mode | stat.S_IWUSR) +# E.g. turn "base_1p" into "base" +def _RemovePartySuffix(client): + return client[:-3] if client[-3:] == '_1p' else client + + def _ImportFromAars(config, tmp_paths, repo): for client in config.clients: - aar_name = '%s-%s.aar' % (client, config.sdk_version) - aar_path = os.path.join(repo, M2_PKG_PATH, client, - config.sdk_version, aar_name) + client_name = _RemovePartySuffix(client) + aar_name = 'client_' + client + '.aar' + aar_path = os.path.join(repo, client_name, aar_name) aar_out_path = os.path.join(tmp_paths['imported_clients'], client) _ExtractAll(aar_path, aar_out_path) @@ -203,18 +205,34 @@ def _ProcessResources(config, tmp_paths, repo): LOCALIZED_VALUES_BASE_NAME = 'values-' locale_whitelist = set(config.locale_whitelist) - glob_pattern = os.path.join(tmp_paths['imported_clients'], '*', 'res', '*') - for res_dir in glob.glob(glob_pattern): - dir_name = os.path.basename(res_dir) + # The directory structure here is: + # /_1p/res//.xml + for client_dir in os.listdir(tmp_paths['imported_clients']): + client_prefix = _RemovePartySuffix(client_dir) + '_' - if dir_name.startswith('drawable'): - shutil.rmtree(res_dir) + res_path = os.path.join(tmp_paths['imported_clients'], client_dir, 'res') + if not os.path.isdir(res_path): continue - - if dir_name.startswith(LOCALIZED_VALUES_BASE_NAME): - dir_locale = dir_name[len(LOCALIZED_VALUES_BASE_NAME):] - if dir_locale not in locale_whitelist: - shutil.rmtree(res_dir) + for res_type in os.listdir(res_path): + res_type_path = os.path.join(res_path, res_type) + + if res_type.startswith('drawable'): + shutil.rmtree(res_type_path) + continue + + if res_type.startswith(LOCALIZED_VALUES_BASE_NAME): + dir_locale = res_type[len(LOCALIZED_VALUES_BASE_NAME):] + if dir_locale not in locale_whitelist: + shutil.rmtree(res_type_path) + continue + + if res_type.startswith('values'): + # Beginning with v3, resource file names are not necessarily unique, and + # would overwrite each other when merged at build time. Prefix each + # "values" resource file with its client name. + for res_file in os.listdir(res_type_path): + os.rename(os.path.join(res_type_path, res_file), + os.path.join(res_type_path, client_prefix + res_file)) # Reimport files from the whitelist. for res_path in config.resource_whitelist: diff --git a/build/config/android/internal_rules.gni b/build/config/android/internal_rules.gni index 239f4cb6c58853..661ed253a3ad83 100644 --- a/build/config/android/internal_rules.gni +++ b/build/config/android/internal_rules.gni @@ -553,6 +553,10 @@ if (enable_java_templates) { _proguard_jar_path = "//third_party/proguard/lib/proguard.jar" } _output_jar_path = invoker.output_jar_path + _input_jars_paths = [] + if (defined(invoker.input_jars_paths)) { + _input_jars_paths += invoker.input_jars_paths + } inputs = [ _proguard_jar_path, ] @@ -586,6 +590,9 @@ if (enable_java_templates) { "--classpath", _rebased_android_sdk_jar, ] + foreach(c, _input_jars_paths) { + args += [ "--classpath=" + c ] + } if (proguard_verbose) { args += [ "--verbose" ] } @@ -809,7 +816,12 @@ if (enable_java_templates) { template("process_java_prebuilt") { set_sources_assignment_filter([]) - forward_variables_from(invoker, [ "testonly" ]) + forward_variables_from(invoker, + [ + "testonly", + "input_jars_paths", + ]) + assert(!defined(input_jars_paths) || input_jars_paths != [] || true) # Mark as used assert(invoker.build_config != "") _build_config = invoker.build_config @@ -1604,7 +1616,10 @@ if (enable_java_templates) { [ "jar_excluded_patterns", "strip_resource_classes", + "input_jars_paths", ]) + assert(!defined(input_jars_paths) || input_jars_paths != [] || true) # Mark as used + visibility = [ ":$_ijar_target_name", ":$_template_name", diff --git a/chrome/android/java/src/org/chromium/chrome/browser/IntentHandler.java b/chrome/android/java/src/org/chromium/chrome/browser/IntentHandler.java index 993061d5a575fe..cb59ac679ea6d9 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/IntentHandler.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/IntentHandler.java @@ -710,7 +710,7 @@ public static boolean isIntentChromeOrFirstParty(Intent intent, Context context) return true; } if (ExternalAuthUtils.getInstance().isGoogleSigned( - context.getPackageManager(), ApiCompatibilityUtils.getCreatorPackage(token))) { + context, ApiCompatibilityUtils.getCreatorPackage(token))) { return true; } return false; diff --git a/chrome/android/java/src/org/chromium/chrome/browser/externalauth/ExternalAuthUtils.java b/chrome/android/java/src/org/chromium/chrome/browser/externalauth/ExternalAuthUtils.java index 733a71a87f445d..27f5a9aef3fedd 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/externalauth/ExternalAuthUtils.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/externalauth/ExternalAuthUtils.java @@ -96,16 +96,15 @@ public boolean isSystemBuild(PackageManager pm, String packageName) { * @return whether the currently running application is signed with Google keys. */ public boolean isChromeGoogleSigned(Context context) { - return isGoogleSigned( - context.getApplicationContext().getPackageManager(), context.getPackageName()); + return isGoogleSigned(context, context.getPackageName()); } /** * Returns whether the call is originating from a Google-signed package. - * @param pm Package manager to use for getting package related info. + * @param appContext the current context. * @param packageName The package name to inquire about. */ - public boolean isGoogleSigned(PackageManager pm, String packageName) { + public boolean isGoogleSigned(Context context, String packageName) { // This is overridden in a subclass. return false; } @@ -129,7 +128,7 @@ private boolean isCallerValid(Context context, int authRequirements, String pack for (String packageName : callingPackages) { if (!TextUtils.isEmpty(packageToMatch) && !packageName.equals(packageToMatch)) continue; matchFound = true; - if ((shouldBeGoogleSigned && !isGoogleSigned(pm, packageName)) + if ((shouldBeGoogleSigned && !isGoogleSigned(context, packageName)) || (shouldBeSystem && !isSystemBuild(pm, packageName))) { return false; } @@ -216,7 +215,7 @@ public void run() { public boolean canUseFirstPartyGooglePlayServices( Context context, UserRecoverableErrorHandler userRecoverableErrorHandler) { return canUseGooglePlayServices(context, userRecoverableErrorHandler) - && isGoogleSigned(context.getPackageManager(), context.getPackageName()); + && isChromeGoogleSigned(context); } /**