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

Commit 3661ad03 authored by Christofer Åkersten's avatar Christofer Åkersten
Browse files

Only load preinstalled updatable in release

Test: Instantiate MediaController2
Change-Id: I8da88cf9291ee1365143ca86fa64d3f2fde8e225
parent 4b60648b
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -17,9 +17,9 @@
package android.media.update;

import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PackageManager;
import android.os.Build;

/**
 * @hide
@@ -36,22 +36,24 @@ public final class ApiLoader {
    public static StaticProvider getProvider(Context context) {
        try {
            return (StaticProvider) getMediaLibraryImpl(context);
        } catch (NameNotFoundException | ReflectiveOperationException e) {
        } catch (PackageManager.NameNotFoundException | ReflectiveOperationException e) {
            throw new RuntimeException(e);
        }
    }

    // TODO This method may do I/O; Ensure it does not violate (emit warnings in) strict mode.
    private static synchronized Object getMediaLibraryImpl(Context appContext)
            throws NameNotFoundException, ReflectiveOperationException {
    private static synchronized Object getMediaLibraryImpl(Context context)
            throws PackageManager.NameNotFoundException, ReflectiveOperationException {
        if (sMediaLibrary != null) return sMediaLibrary;

        // TODO Dynamically find the package name
        Context libContext = appContext.createPackageContext(UPDATE_PACKAGE,
        // TODO Figure out when to use which package (query media update service)
        int flags = Build.IS_DEBUGGABLE ? 0 : PackageManager.MATCH_FACTORY_ONLY;
        Context libContext = context.createApplicationContext(
                context.getPackageManager().getPackageInfo(UPDATE_PACKAGE, flags).applicationInfo,
                Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
        sMediaLibrary = libContext.getClassLoader()
                .loadClass(UPDATE_CLASS)
                .getMethod(UPDATE_METHOD, Resources.class, Theme.class)
                .getMethod(UPDATE_METHOD, Resources.class, Resources.Theme.class)
                .invoke(null, libContext.getResources(), libContext.getTheme());
        return sMediaLibrary;
    }