Android: Make incremental install work for two <instrumentation>
This happens in the case of junit4 Review-Url: https://codereview.chromium.org/2790453003 Cr-Original-Commit-Position: refs/heads/master@{#460839} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 4e5061771986fd0d506d21f33a0d8fdb065add92
This commit is contained in:
Родитель
f88d67ada7
Коммит
c209445cdd
|
@ -13,6 +13,7 @@ android_library("bootstrap_java") {
|
|||
"java/org/chromium/incrementalinstall/ClassLoaderPatcher.java",
|
||||
"java/org/chromium/incrementalinstall/LockFile.java",
|
||||
"java/org/chromium/incrementalinstall/Reflect.java",
|
||||
"java/org/chromium/incrementalinstall/SecondInstrumentation.java",
|
||||
]
|
||||
emma_never_instrument = true
|
||||
run_findbugs_override = false
|
||||
|
|
|
@ -22,9 +22,15 @@ ElementTree.register_namespace('android', _ANDROID_NAMESPACE)
|
|||
|
||||
_INCREMENTAL_APP_NAME = 'org.chromium.incrementalinstall.BootstrapApplication'
|
||||
_META_DATA_APP_NAME = 'incremental-install-real-app'
|
||||
_META_DATA_INSTRUMENTATION_NAME = 'incremental-install-real-instrumentation'
|
||||
_DEFAULT_APPLICATION_CLASS = 'android.app.Application'
|
||||
_DEFAULT_INSTRUMENTATION_CLASS = 'android.app.Instrumentation'
|
||||
_META_DATA_INSTRUMENTATION_NAMES = [
|
||||
'incremental-install-real-instrumentation-0',
|
||||
'incremental-install-real-instrumentation-1',
|
||||
]
|
||||
_INCREMENTAL_INSTRUMENTATION_CLASSES = [
|
||||
'android.app.Instrumentation',
|
||||
'org.chromium.incrementalinstall.SecondInstrumentation',
|
||||
]
|
||||
|
||||
|
||||
def _AddNamespace(name):
|
||||
|
@ -84,12 +90,13 @@ def _ProcessManifest(main_manifest, disable_isolated_processes):
|
|||
|
||||
# Seems to be a bug in ElementTree, as doc.find() doesn't work here.
|
||||
instrumentation_nodes = doc.findall('instrumentation')
|
||||
if instrumentation_nodes:
|
||||
instrumentation_node = instrumentation_nodes[0]
|
||||
assert len(instrumentation_nodes) <= 2, (
|
||||
'Need to update incremental install to support >2 <instrumentation> tags')
|
||||
for i, instrumentation_node in enumerate(instrumentation_nodes):
|
||||
real_instrumentation_class = instrumentation_node.get(_AddNamespace('name'))
|
||||
instrumentation_node.set(_AddNamespace('name'),
|
||||
_DEFAULT_INSTRUMENTATION_CLASS)
|
||||
_CreateMetaData(app_node, _META_DATA_INSTRUMENTATION_NAME,
|
||||
_INCREMENTAL_INSTRUMENTATION_CLASSES[i])
|
||||
_CreateMetaData(app_node, _META_DATA_INSTRUMENTATION_NAMES[i],
|
||||
real_instrumentation_class)
|
||||
|
||||
return ElementTree.tostring(doc, encoding='UTF-8')
|
||||
|
|
|
@ -32,8 +32,10 @@ public final class BootstrapApplication extends Application {
|
|||
private static final String TAG = "cr.incrementalinstall";
|
||||
private static final String MANAGED_DIR_PREFIX = "/data/local/tmp/incremental-app-";
|
||||
private static final String REAL_APP_META_DATA_NAME = "incremental-install-real-app";
|
||||
private static final String REAL_INSTRUMENTATION_META_DATA_NAME =
|
||||
"incremental-install-real-instrumentation";
|
||||
private static final String REAL_INSTRUMENTATION_META_DATA_NAME0 =
|
||||
"incremental-install-real-instrumentation-0";
|
||||
private static final String REAL_INSTRUMENTATION_META_DATA_NAME1 =
|
||||
"incremental-install-real-instrumentation-1";
|
||||
|
||||
private ClassLoaderPatcher mClassLoaderPatcher;
|
||||
private Application mRealApplication;
|
||||
|
@ -113,9 +115,11 @@ public final class BootstrapApplication extends Application {
|
|||
// mInstrumentationAppDir is one of a set of fields that is initialized only when
|
||||
// instrumentation is active.
|
||||
if (Reflect.getField(mActivityThread, "mInstrumentationAppDir") != null) {
|
||||
String realInstrumentationName =
|
||||
getClassNameFromMetadata(REAL_INSTRUMENTATION_META_DATA_NAME, instContext);
|
||||
initInstrumentation(realInstrumentationName);
|
||||
String metaDataName = REAL_INSTRUMENTATION_META_DATA_NAME0;
|
||||
if (mOrigInstrumentation instanceof SecondInstrumentation) {
|
||||
metaDataName = REAL_INSTRUMENTATION_META_DATA_NAME1;
|
||||
}
|
||||
initInstrumentation(getClassNameFromMetadata(metaDataName, instContext));
|
||||
} else {
|
||||
Log.i(TAG, "No instrumentation active.");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package org.chromium.incrementalinstall;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
|
||||
/**
|
||||
* Exists to support an app having multiple instrumentations.
|
||||
*/
|
||||
public final class SecondInstrumentation extends Instrumentation {}
|
Загрузка…
Ссылка в новой задаче