Bug 1298090 - [1.6] Extract and cache native libraries on APK update. r=glandium,snorp

This commit is contained in:
Eugen Sawin 2016-08-26 15:36:37 +02:00
Родитель f3346119eb
Коммит 06c47357d2
5 изменённых файлов: 82 добавлений и 0 удалений

Просмотреть файл

@ -393,6 +393,14 @@
</intent-filter>
</receiver>
<receiver
android:name="org.mozilla.gecko.PackageReplacedReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"></action>
</intent-filter>
</receiver>
<service
android:name="org.mozilla.gecko.telemetry.TelemetryUploadService"
android:exported="false"/>

Просмотреть файл

@ -0,0 +1,38 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import org.mozilla.gecko.mozglue.GeckoLoader;
/**
* This broadcast receiver receives ACTION_MY_PACKAGE_REPLACED broadcasts and
* starts procedures that should run after the APK has been updated.
*/
public class PackageReplacedReceiver extends BroadcastReceiver {
public static final String ACTION_MY_PACKAGE_REPLACED = "android.intent.action.MY_PACKAGE_REPLACED";
@Override
public void onReceive(Context context, Intent intent) {
if (intent == null || !ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
// This is not the broadcast we are looking for.
return;
}
// Extract Gecko libs to allow them to be loaded from cache on startup.
extractGeckoLibs(context);
}
private static void extractGeckoLibs(final Context context) {
final String resourcePath = context.getPackageResourcePath();
GeckoLoader.loadMozGlue(context);
GeckoLoader.extractGeckoLibs(context, resourcePath);
}
}

Просмотреть файл

@ -588,6 +588,7 @@ gbjar.sources += ['java/org/mozilla/gecko/' + x for x in [
'overlays/ui/SendTabList.java',
'overlays/ui/SendTabTargetSelectedListener.java',
'overlays/ui/ShareDialog.java',
'PackageReplacedReceiver.java',
'preferences/AlignRightLinkPreference.java',
'preferences/AndroidImport.java',
'preferences/AndroidImportPreference.java',

Просмотреть файл

@ -507,6 +507,15 @@ public final class GeckoLoader {
loadGeckoLibsNative(apkName);
}
public synchronized static void extractGeckoLibs(final Context context, final String apkName) {
loadLibsSetupLocked(context);
try {
extractGeckoLibsNative(apkName);
} catch (Exception e) {
Log.e(LOGTAG, "Failing library extraction.", e);
}
}
private static void setupLocaleEnvironment() {
putenv("LANG=" + Locale.getDefault().toString());
NumberFormat nf = NumberFormat.getInstance();
@ -545,4 +554,5 @@ public final class GeckoLoader {
private static native void loadGeckoLibsNative(String apkName);
private static native void loadSQLiteLibsNative(String apkName);
private static native void loadNSSLibsNative(String apkName);
private static native void extractGeckoLibsNative(String apkName);
}

Просмотреть файл

@ -310,6 +310,31 @@ loadNSSLibs(const char *apkName)
return setup_nss_functions(nss_handle, nspr_handle, plc_handle);
}
extern "C" NS_EXPORT void MOZ_JNICALL
Java_org_mozilla_gecko_mozglue_GeckoLoader_extractGeckoLibsNative(
JNIEnv *jenv, jclass jGeckoAppShellClass, jstring jApkName)
{
MOZ_ALWAYS_TRUE(!jenv->GetJavaVM(&sJavaVM));
const char* apkName = jenv->GetStringUTFChars(jApkName, nullptr);
if (apkName == nullptr) {
return;
}
// Extract and cache native lib to allow for efficient startup from cache.
void* handle = dlopenAPKLibrary(apkName, "libxul.so");
if (handle) {
__android_log_print(ANDROID_LOG_INFO, "GeckoLibLoad",
"Extracted and cached libxul.so.");
// We have extracted and cached the lib, we can close it now.
__wrap_dlclose(handle);
} else {
JNI_Throw(jenv, "java/lang/Exception", "Error extracting gecko libraries");
}
jenv->ReleaseStringUTFChars(jApkName, apkName);
}
extern "C" NS_EXPORT void MOZ_JNICALL
Java_org_mozilla_gecko_mozglue_GeckoLoader_loadGeckoLibsNative(JNIEnv *jenv, jclass jGeckoAppShellClass, jstring jApkName)
{