|
| 1 | +/** |
| 2 | + * Copyright (C) 2025 Igalia S.L. <[email protected]> |
| 3 | + * Author: Adrian Perez de Castro <[email protected]> |
| 4 | + * |
| 5 | + * This library is free software; you can redistribute it and/or |
| 6 | + * modify it under the terms of the GNU Lesser General Public |
| 7 | + * License as published by the Free Software Foundation; either |
| 8 | + * version 2.1 of the License, or (at your option) any later version. |
| 9 | + * |
| 10 | + * This library is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + * Lesser General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Lesser General Public |
| 16 | + * License along with this library; if not, write to the Free Software |
| 17 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | + */ |
| 19 | + |
| 20 | +package org.wpewebkit; |
| 21 | + |
| 22 | +import android.app.Activity; |
| 23 | +import android.app.Application; |
| 24 | +import android.os.Bundle; |
| 25 | +import android.util.Log; |
| 26 | + |
| 27 | +public class WPEApplication extends Application { |
| 28 | + static final String LOGTAG = "WPEApplication"; |
| 29 | + |
| 30 | + private enum ProcessKind { |
| 31 | + MAIN { |
| 32 | + @Override |
| 33 | + public String[] getLibraryNames() { |
| 34 | + return new String[] {"WPEAndroidRuntime"}; |
| 35 | + } |
| 36 | + }, |
| 37 | + NETWORK { |
| 38 | + @Override |
| 39 | + public String[] getLibraryNames() { |
| 40 | + return new String[] {"WPEAndroidService"}; |
| 41 | + } |
| 42 | + }, |
| 43 | + WEBCONTENT { |
| 44 | + @Override |
| 45 | + public String[] getLibraryNames() { |
| 46 | + return new String[] {"gstreamer-1.0", "WPEAndroidService"}; |
| 47 | + } |
| 48 | + }, |
| 49 | + WEBDRIVER { |
| 50 | + @Override |
| 51 | + public String[] getLibraryNames() { |
| 52 | + return new String[] {"WPEWebDriver", "WPEAndroidService"}; |
| 53 | + } |
| 54 | + }; |
| 55 | + |
| 56 | + abstract public String[] getLibraryNames(); |
| 57 | + } |
| 58 | + |
| 59 | + private static final ProcessKind getProcessKind() { |
| 60 | + String name = getProcessName(); |
| 61 | + int colonPosition = name.indexOf(':'); |
| 62 | + if (colonPosition < 0) |
| 63 | + return ProcessKind.MAIN; |
| 64 | + |
| 65 | + name = name.substring(colonPosition + 1).replaceAll("[0-9]", ""); |
| 66 | + switch (name) { |
| 67 | + case "WPEWebProcess": |
| 68 | + return ProcessKind.WEBCONTENT; |
| 69 | + case "WPENetworkProcess": |
| 70 | + return ProcessKind.NETWORK; |
| 71 | + case "WPEWebDriverProcess": |
| 72 | + return ProcessKind.WEBDRIVER; |
| 73 | + default: |
| 74 | + throw new IllegalStateException("Cannot derive process kind from '" + getProcessName() + "'"); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + public static final ProcessKind processKind = getProcessKind(); |
| 79 | + |
| 80 | + static { |
| 81 | + final String libraries[] = processKind.getLibraryNames(); |
| 82 | + Log.d(LOGTAG, "Process: " + processKind.toString() + " - Libraries: " + String.join(", ", libraries)); |
| 83 | + for (String libraryName : libraries) |
| 84 | + System.loadLibrary(libraryName); |
| 85 | + } |
| 86 | + |
| 87 | + public WPEApplication() { |
| 88 | + super(); |
| 89 | + if (processKind == ProcessKind.MAIN) |
| 90 | + registerActivityLifecycleCallbacks(new org.wpewebkit.wpe.WKActivityObserver()); |
| 91 | + } |
| 92 | +} |
0 commit comments