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

Commit b5f88e7e authored by Dongwon Kang's avatar Dongwon Kang Committed by android-build-merger
Browse files

Merge "Merge "Use system property to get the package name for media update"...

Merge "Merge "Use system property to get the package name for media update" into pi-dev am: fd3e190c" into pi-dev-plus-aosp
am: 88457229

Change-Id: I36b09cf6b75932aa978c603c6d29ad0f87dad8e9
parents 28bca54d 88457229
Loading
Loading
Loading
Loading
+2 −56
Original line number Diff line number Diff line
@@ -16,68 +16,14 @@

package android.media.update;

import android.app.ActivityManager;
import android.app.AppGlobals;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.os.RemoteException;
import android.os.UserHandle;

import com.android.internal.annotations.GuardedBy;

import dalvik.system.PathClassLoader;

import java.io.File;

/**
 * @hide
 */
public final class ApiLoader {
    @GuardedBy("this")
    private static StaticProvider sMediaUpdatable;

    private static final String UPDATE_PACKAGE = "com.android.media.update";
    private static final String UPDATE_CLASS = "com.android.media.update.ApiFactory";
    private static final String UPDATE_METHOD = "initialize";
    private static final boolean REGISTER_UPDATE_DEPENDENCY = true;

    private ApiLoader() { }

    public static StaticProvider getProvider() {
        if (sMediaUpdatable != null) return sMediaUpdatable;

        try {
            return getMediaUpdatable();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        } catch (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 StaticProvider getMediaUpdatable()
            throws NameNotFoundException, ReflectiveOperationException, RemoteException {
        if (sMediaUpdatable != null) return sMediaUpdatable;

        // TODO Figure out when to use which package (query media update service)
        int flags = Build.IS_DEBUGGABLE ? 0 : PackageManager.MATCH_FACTORY_ONLY;
        flags |= PackageManager.GET_SHARED_LIBRARY_FILES;
        ApplicationInfo ai = AppGlobals.getPackageManager().getApplicationInfo(
                UPDATE_PACKAGE, flags, UserHandle.myUserId());

        if (REGISTER_UPDATE_DEPENDENCY) {
            // Register a dependency to the updatable in order to be killed during updates
            ActivityManager.getService().addPackageDependency(ai.packageName);
        }

        ClassLoader classLoader = new PathClassLoader(ai.sourceDir,
                ai.nativeLibraryDir + File.pathSeparator + System.getProperty("java.library.path"),
                ClassLoader.getSystemClassLoader().getParent());
        return sMediaUpdatable = (StaticProvider) classLoader.loadClass(UPDATE_CLASS)
                .getMethod(UPDATE_METHOD, ApplicationInfo.class).invoke(null, ai);
        throw new RuntimeException("Use MediaSession/Browser instead of"
                + " hidden MediaSession2/Browser2 APIs.");
    }
}
+13 −2
Original line number Diff line number Diff line
@@ -23,11 +23,14 @@ import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.media.IMediaExtractorUpdateService;
import android.os.Build;
import android.os.IBinder;
import android.os.Handler;
import android.os.PatternMatcher;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Log;
import android.util.Slog;
import com.android.server.SystemService;
@@ -36,7 +39,8 @@ import com.android.server.SystemService;
public class MediaUpdateService extends SystemService {
    private static final String TAG = "MediaUpdateService";
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
    private static final String MEDIA_UPDATE_PACKAGE_NAME = "com.android.media.update";
    private static final String MEDIA_UPDATE_PACKAGE_NAME =
            SystemProperties.get("ro.mediacomponents.package");
    private static final String EXTRACTOR_UPDATE_SERVICE_NAME = "media.extractor.update";

    private IMediaExtractorUpdateService mMediaExtractorUpdateService;
@@ -49,7 +53,8 @@ public class MediaUpdateService extends SystemService {

    @Override
    public void onStart() {
        if ("userdebug".equals(android.os.Build.TYPE) || "eng".equals(android.os.Build.TYPE)) {
        if (("userdebug".equals(android.os.Build.TYPE) || "eng".equals(android.os.Build.TYPE))
                && !TextUtils.isEmpty(MEDIA_UPDATE_PACKAGE_NAME)) {
            connect();
            registerBroadcastReceiver();
        }
@@ -133,6 +138,12 @@ public class MediaUpdateService extends SystemService {
        } catch (Exception e) {
            Slog.v(TAG, "package '" + MEDIA_UPDATE_PACKAGE_NAME + "' not installed");
        }
        if (packageInfo != null && Build.VERSION.SDK_INT != packageInfo.targetSdkVersion) {
            Slog.w(TAG, "This update package is not for this platform version. Ignoring. "
                    + "platform:" + Build.VERSION.SDK_INT
                    + " targetSdk:" + packageInfo.targetSdkVersion);
            pluginsAvailable = false;
        }
        loadExtractorPlugins(
                (packageInfo != null && pluginsAvailable) ? packageInfo.sourceDir : "");
    }