Loading core/java/android/app/ActivityThread.java +3 −0 Original line number Diff line number Diff line Loading @@ -86,6 +86,8 @@ import android.graphics.Canvas; import android.graphics.HardwareRenderer; import android.hardware.display.DisplayManagerGlobal; import android.inputmethodservice.InputMethodService; import android.media.MediaFrameworkInitializer; import android.media.MediaServiceManager; import android.net.ConnectivityManager; import android.net.IConnectivityManager; import android.net.Proxy; Loading Loading @@ -7665,6 +7667,7 @@ public final class ActivityThread extends ClientTransactionHandler { public static void initializeMainlineModules() { TelephonyFrameworkInitializer.setTelephonyServiceManager(new TelephonyServiceManager()); StatsFrameworkInitializer.setStatsServiceManager(new StatsServiceManager()); MediaFrameworkInitializer.setMediaServiceManager(new MediaServiceManager()); } private void purgePendingResources() { Loading core/java/android/app/SystemServiceRegistry.java +2 −8 Original line number Diff line number Diff line Loading @@ -101,11 +101,11 @@ import android.location.ICountryDetector; import android.location.ILocationManager; import android.location.LocationManager; import android.media.AudioManager; import android.media.MediaFrameworkInitializer; import android.media.MediaRouter; import android.media.midi.IMidiManager; import android.media.midi.MidiManager; import android.media.projection.MediaProjectionManager; import android.media.session.MediaSessionManager; import android.media.soundtrigger.SoundTriggerManager; import android.media.tv.ITvInputManager; import android.media.tv.TvInputManager; Loading Loading @@ -855,13 +855,6 @@ public final class SystemServiceRegistry { return new ConsumerIrManager(ctx); }}); registerService(Context.MEDIA_SESSION_SERVICE, MediaSessionManager.class, new CachedServiceFetcher<MediaSessionManager>() { @Override public MediaSessionManager createService(ContextImpl ctx) { return new MediaSessionManager(ctx); }}); registerService(Context.TRUST_SERVICE, TrustManager.class, new StaticServiceFetcher<TrustManager>() { @Override Loading Loading @@ -1335,6 +1328,7 @@ public final class SystemServiceRegistry { WifiFrameworkInitializer.registerServiceWrappers(); StatsFrameworkInitializer.registerServiceWrappers(); RollbackManagerFrameworkInitializer.initialize(); MediaFrameworkInitializer.registerServiceWrappers(); } finally { // If any of the above code throws, we're in a pretty bad shape and the process // will likely crash, but we'll reset it just in case there's an exception handler... Loading media/java/android/media/MediaFrameworkInitializer.java 0 → 100644 +74 −0 Original line number Diff line number Diff line /* * Copyright 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.media; import android.annotation.NonNull; import android.app.SystemServiceRegistry; import android.content.Context; import android.media.session.MediaSessionManager; import com.android.internal.util.Preconditions; import java.util.Objects; /** * Class for performing registration for all media services * * TODO (b/160513103): Move this class when moving media service code to APEX * @hide */ public class MediaFrameworkInitializer { private MediaFrameworkInitializer() { } private static volatile MediaServiceManager sMediaServiceManager; /** * Sets an instance of {@link MediaServiceManager} that allows * the media mainline module to register/obtain media binder services. This is called * by the platform during the system initialization. * * @param mediaServiceManager instance of {@link MediaServiceManager} that allows * the media mainline module to register/obtain media binder services. */ public static void setMediaServiceManager( @NonNull MediaServiceManager mediaServiceManager) { Preconditions.checkState(sMediaServiceManager == null, "setMediaServiceManager called twice!"); sMediaServiceManager = Objects.requireNonNull(mediaServiceManager); } /** @hide */ public static MediaServiceManager getMediaServiceManager() { return sMediaServiceManager; } /** * Called by {@link SystemServiceRegistry}'s static initializer and registers all media * services to {@link Context}, so that {@link Context#getSystemService} can return them. * * @throws IllegalStateException if this is called from anywhere besides * {@link SystemServiceRegistry} */ public static void registerServiceWrappers() { SystemServiceRegistry.registerContextAwareService( Context.MEDIA_SESSION_SERVICE, MediaSessionManager.class, context -> new MediaSessionManager(context) ); } } media/java/android/media/MediaServiceManager.java 0 → 100644 +68 −0 Original line number Diff line number Diff line /* * Copyright 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.media; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.IBinder; import android.os.ServiceManager; /** * Provides a way to register and obtain the system service binder objects managed by the media * service. * * <p> Only the media mainline module will be able to access an instance of this class. * @hide */ public class MediaServiceManager { /** * @hide */ public MediaServiceManager() {} /** * A class that exposes the methods to register and obtain each system service. */ public static final class ServiceRegisterer { private final String mServiceName; /** * @hide */ public ServiceRegisterer(String serviceName) { mServiceName = serviceName; } /** * Get the system server binding object for MediaServiceManager. * * <p> This blocks until the service instance is ready. * or a timeout happens, in which case it returns null. */ @Nullable public IBinder get() { return ServiceManager.getService(mServiceName); } } /** * Returns {@link ServiceRegisterer} for the "media_session" service. */ @NonNull public ServiceRegisterer getMediaSessionServiceRegisterer() { return new ServiceRegisterer("media_session"); } } media/java/android/media/session/MediaSessionManager.java +5 −4 Original line number Diff line number Diff line Loading @@ -28,14 +28,13 @@ import android.content.Context; import android.content.pm.ParceledListSlice; import android.media.AudioManager; import android.media.IRemoteVolumeController; import android.media.MediaFrameworkInitializer; import android.media.MediaSession2; import android.media.Session2Token; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.RemoteException; import android.os.ResultReceiver; import android.os.ServiceManager; import android.os.UserHandle; import android.service.media.MediaBrowserService; import android.service.notification.NotificationListenerService; Loading Loading @@ -115,8 +114,10 @@ public final class MediaSessionManager { // Consider rewriting like DisplayManagerGlobal // Decide if we need context mContext = context; IBinder b = ServiceManager.getService(Context.MEDIA_SESSION_SERVICE); mService = ISessionManager.Stub.asInterface(b); mService = ISessionManager.Stub.asInterface(MediaFrameworkInitializer .getMediaServiceManager() .getMediaSessionServiceRegisterer() .get()); } /** Loading Loading
core/java/android/app/ActivityThread.java +3 −0 Original line number Diff line number Diff line Loading @@ -86,6 +86,8 @@ import android.graphics.Canvas; import android.graphics.HardwareRenderer; import android.hardware.display.DisplayManagerGlobal; import android.inputmethodservice.InputMethodService; import android.media.MediaFrameworkInitializer; import android.media.MediaServiceManager; import android.net.ConnectivityManager; import android.net.IConnectivityManager; import android.net.Proxy; Loading Loading @@ -7665,6 +7667,7 @@ public final class ActivityThread extends ClientTransactionHandler { public static void initializeMainlineModules() { TelephonyFrameworkInitializer.setTelephonyServiceManager(new TelephonyServiceManager()); StatsFrameworkInitializer.setStatsServiceManager(new StatsServiceManager()); MediaFrameworkInitializer.setMediaServiceManager(new MediaServiceManager()); } private void purgePendingResources() { Loading
core/java/android/app/SystemServiceRegistry.java +2 −8 Original line number Diff line number Diff line Loading @@ -101,11 +101,11 @@ import android.location.ICountryDetector; import android.location.ILocationManager; import android.location.LocationManager; import android.media.AudioManager; import android.media.MediaFrameworkInitializer; import android.media.MediaRouter; import android.media.midi.IMidiManager; import android.media.midi.MidiManager; import android.media.projection.MediaProjectionManager; import android.media.session.MediaSessionManager; import android.media.soundtrigger.SoundTriggerManager; import android.media.tv.ITvInputManager; import android.media.tv.TvInputManager; Loading Loading @@ -855,13 +855,6 @@ public final class SystemServiceRegistry { return new ConsumerIrManager(ctx); }}); registerService(Context.MEDIA_SESSION_SERVICE, MediaSessionManager.class, new CachedServiceFetcher<MediaSessionManager>() { @Override public MediaSessionManager createService(ContextImpl ctx) { return new MediaSessionManager(ctx); }}); registerService(Context.TRUST_SERVICE, TrustManager.class, new StaticServiceFetcher<TrustManager>() { @Override Loading Loading @@ -1335,6 +1328,7 @@ public final class SystemServiceRegistry { WifiFrameworkInitializer.registerServiceWrappers(); StatsFrameworkInitializer.registerServiceWrappers(); RollbackManagerFrameworkInitializer.initialize(); MediaFrameworkInitializer.registerServiceWrappers(); } finally { // If any of the above code throws, we're in a pretty bad shape and the process // will likely crash, but we'll reset it just in case there's an exception handler... Loading
media/java/android/media/MediaFrameworkInitializer.java 0 → 100644 +74 −0 Original line number Diff line number Diff line /* * Copyright 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.media; import android.annotation.NonNull; import android.app.SystemServiceRegistry; import android.content.Context; import android.media.session.MediaSessionManager; import com.android.internal.util.Preconditions; import java.util.Objects; /** * Class for performing registration for all media services * * TODO (b/160513103): Move this class when moving media service code to APEX * @hide */ public class MediaFrameworkInitializer { private MediaFrameworkInitializer() { } private static volatile MediaServiceManager sMediaServiceManager; /** * Sets an instance of {@link MediaServiceManager} that allows * the media mainline module to register/obtain media binder services. This is called * by the platform during the system initialization. * * @param mediaServiceManager instance of {@link MediaServiceManager} that allows * the media mainline module to register/obtain media binder services. */ public static void setMediaServiceManager( @NonNull MediaServiceManager mediaServiceManager) { Preconditions.checkState(sMediaServiceManager == null, "setMediaServiceManager called twice!"); sMediaServiceManager = Objects.requireNonNull(mediaServiceManager); } /** @hide */ public static MediaServiceManager getMediaServiceManager() { return sMediaServiceManager; } /** * Called by {@link SystemServiceRegistry}'s static initializer and registers all media * services to {@link Context}, so that {@link Context#getSystemService} can return them. * * @throws IllegalStateException if this is called from anywhere besides * {@link SystemServiceRegistry} */ public static void registerServiceWrappers() { SystemServiceRegistry.registerContextAwareService( Context.MEDIA_SESSION_SERVICE, MediaSessionManager.class, context -> new MediaSessionManager(context) ); } }
media/java/android/media/MediaServiceManager.java 0 → 100644 +68 −0 Original line number Diff line number Diff line /* * Copyright 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.media; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.IBinder; import android.os.ServiceManager; /** * Provides a way to register and obtain the system service binder objects managed by the media * service. * * <p> Only the media mainline module will be able to access an instance of this class. * @hide */ public class MediaServiceManager { /** * @hide */ public MediaServiceManager() {} /** * A class that exposes the methods to register and obtain each system service. */ public static final class ServiceRegisterer { private final String mServiceName; /** * @hide */ public ServiceRegisterer(String serviceName) { mServiceName = serviceName; } /** * Get the system server binding object for MediaServiceManager. * * <p> This blocks until the service instance is ready. * or a timeout happens, in which case it returns null. */ @Nullable public IBinder get() { return ServiceManager.getService(mServiceName); } } /** * Returns {@link ServiceRegisterer} for the "media_session" service. */ @NonNull public ServiceRegisterer getMediaSessionServiceRegisterer() { return new ServiceRegisterer("media_session"); } }
media/java/android/media/session/MediaSessionManager.java +5 −4 Original line number Diff line number Diff line Loading @@ -28,14 +28,13 @@ import android.content.Context; import android.content.pm.ParceledListSlice; import android.media.AudioManager; import android.media.IRemoteVolumeController; import android.media.MediaFrameworkInitializer; import android.media.MediaSession2; import android.media.Session2Token; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.RemoteException; import android.os.ResultReceiver; import android.os.ServiceManager; import android.os.UserHandle; import android.service.media.MediaBrowserService; import android.service.notification.NotificationListenerService; Loading Loading @@ -115,8 +114,10 @@ public final class MediaSessionManager { // Consider rewriting like DisplayManagerGlobal // Decide if we need context mContext = context; IBinder b = ServiceManager.getService(Context.MEDIA_SESSION_SERVICE); mService = ISessionManager.Stub.asInterface(b); mService = ISessionManager.Stub.asInterface(MediaFrameworkInitializer .getMediaServiceManager() .getMediaSessionServiceRegisterer() .get()); } /** Loading