Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit b7a50cf5 authored by Alexander Martinz's avatar Alexander Martinz Committed by Michael Bestas
Browse files

services: core: wfd: extend check for qualcomm wfd jar



Some BSPs have moved WfdCommon.jar out of the boot classpath
and moved it to /system_ext/framework/.

Check the new location if the initial lookup fails.

Change-Id: I78dff4bc649970e6c5608ae03f1789e30fc95c2f
Signed-off-by: Alexander Martinz's avatarAlexander Martinz <amartinz@shiftphones.com>
parent bbd716a5
Loading
Loading
Loading
Loading
+35 −9
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.content.Context;
import android.media.RemoteDisplay;
import android.os.Handler;
import android.util.Slog;
import dalvik.system.PathClassLoader;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@@ -42,6 +43,9 @@ class ExtendedRemoteDisplayHelper {
    private static final String TAG = "ExtendedRemoteDisplayHelper";
    private static final boolean DEBUG = false;

    private static final String WFD_COMMON_JAR = "/system_ext/framework/WfdCommon.jar";
    private static final String EXTDISP_WFD_CLASS = "com.qualcomm.wfd.ExtendedRemoteDisplay";

    // ExtendedRemoteDisplay class
    // ExtendedRemoteDisplay is an enhanced RemoteDisplay.
    // It has similar interface as RemoteDisplay class.
@@ -59,32 +63,54 @@ class ExtendedRemoteDisplayHelper {
    static {
        // Check availability of ExtendedRemoteDisplay runtime
        try {
            sExtRemoteDisplayClass = Class.forName("com.qualcomm.wfd.ExtendedRemoteDisplay");
            sExtRemoteDisplayClass = Class.forName(EXTDISP_WFD_CLASS);
        } catch (Throwable t) {
            if (DEBUG) {
                Slog.i(TAG, "ExtendedRemoteDisplay: failed to find on the boot classpath, " +
                    "checking for [" + WFD_COMMON_JAR + "]");
            }

            try {
                final PathClassLoader wfdCommonJarClassLoader = new PathClassLoader(
                        WFD_COMMON_JAR, ClassLoader.getSystemClassLoader());
                sExtRemoteDisplayClass = wfdCommonJarClassLoader.loadClass(EXTDISP_WFD_CLASS);
            } catch (Throwable anotherT) {
                Slog.i(TAG, "ExtendedRemoteDisplay: not available");
            }
        }

        if (sExtRemoteDisplayClass != null) {
            // If ExtendedRemoteDisplay is available find the methods
            Slog.i(TAG, "ExtendedRemoteDisplay: is available, finding methods");
            try {
                Class args[] = { String.class, RemoteDisplay.Listener.class,

            final Class listenArgs[] = { String.class, RemoteDisplay.Listener.class,
                    Handler.class, Context.class };
            try {
                sExtRemoteDisplayListen =
                        sExtRemoteDisplayClass.getDeclaredMethod("listen", args);
                        sExtRemoteDisplayClass.getDeclaredMethod("listen", listenArgs);
            } catch (Throwable t) {
                try {
                    sExtRemoteDisplayListen =
                            sExtRemoteDisplayClass.getMethod("listen", listenArgs);
                } catch (Throwable anotherT) {
                    Slog.i(TAG, "ExtendedRemoteDisplay.listen: not available");
                }
            }

            final Class disposeArgs[] = {};
            try {
                Class args[] = {};
                sExtRemoteDisplayDispose =
                        sExtRemoteDisplayClass.getDeclaredMethod("dispose", args);
                        sExtRemoteDisplayClass.getDeclaredMethod("dispose", disposeArgs);
            } catch (Throwable t) {
                try {
                    sExtRemoteDisplayDispose =
                            sExtRemoteDisplayClass.getMethod("dispose", disposeArgs);
                } catch (Throwable anotherT) {
                    Slog.i(TAG, "ExtendedRemoteDisplay.dispose: not available");
                }
            }
        }
    }

    /**
     * Starts listening for displays to be connected on the specified interface.