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

Commit 6b1c183e authored by Jaewan Kim's avatar Jaewan Kim
Browse files

MediaSession2: Move MediaSessionService2.MediaNotification to updatable

Test: Run all MediaComponents tests once
Change-Id: If64c6e0ece90ee15dcf9af061fa91a6ebefd32c4
parent 839daf18
Loading
Loading
Loading
Loading
+30 −2
Original line number Diff line number Diff line
@@ -18,7 +18,9 @@ package com.android.media;

import static android.content.Context.NOTIFICATION_SERVICE;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayerInterface.PlaybackListener;
import android.media.MediaSession2;
@@ -116,7 +118,8 @@ public class MediaSessionService2Impl implements MediaSessionService2Provider {
                if (!mIsRunningForeground) {
                    mIsRunningForeground = true;
                    mInstance.startForegroundService(mStartSelfIntent);
                    mInstance.startForeground(mediaNotification.id, mediaNotification.notification);
                    mInstance.startForeground(mediaNotification.getNotificationId(),
                            mediaNotification.getNotification());
                    return;
                }
                break;
@@ -128,7 +131,8 @@ public class MediaSessionService2Impl implements MediaSessionService2Provider {
                }
                break;
        }
        mNotificationManager.notify(mediaNotification.id, mediaNotification.notification);
        mNotificationManager.notify(mediaNotification.getNotificationId(),
                mediaNotification.getNotification());
    }

    private class SessionServicePlaybackListener implements PlaybackListener {
@@ -142,4 +146,28 @@ public class MediaSessionService2Impl implements MediaSessionService2Provider {
            updateNotification(state);
        }
    }

    public static class MediaNotificationImpl implements MediaNotificationProvider {
        private int mNotificationId;
        private Notification mNotification;

        public MediaNotificationImpl(Context context, MediaNotification instance,
                int notificationId, Notification notification) {
            if (notification == null) {
                throw new IllegalArgumentException("notification shouldn't be null");
            }
            mNotificationId = notificationId;
            mNotification = notification;
        }

        @Override
        public int getNotificationId_impl() {
            return mNotificationId;
        }

        @Override
        public Notification getNotification_impl() {
            return mNotification;
        }
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.media.update;

import android.app.Notification;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
@@ -38,6 +39,7 @@ import android.media.MediaSession2.ControllerInfo;
import android.media.MediaSession2.PlaylistParams;
import android.media.MediaSession2.SessionCallback;
import android.media.MediaSessionService2;
import android.media.MediaSessionService2.MediaNotification;
import android.media.PlaybackState2;
import android.media.Rating2;
import android.media.SessionPlayer2;
@@ -52,6 +54,7 @@ import android.media.update.MediaSession2Provider;
import android.media.update.MediaSession2Provider.BuilderBaseProvider;
import android.media.update.MediaSession2Provider.PlaylistParamsProvider;
import android.media.update.MediaSessionService2Provider;
import android.media.update.MediaSessionService2Provider.MediaNotificationProvider;
import android.media.update.PlaybackState2Provider;
import android.media.update.SessionPlayer2Provider;
import android.media.update.SessionToken2Provider;
@@ -162,6 +165,13 @@ public class ApiFactory implements StaticProvider {
        return new MediaSessionService2Impl(instance);
    }

    @Override
    public MediaNotificationProvider createMediaSessionService2MediaNotification(Context context,
            MediaNotification instance, int notificationId, Notification notification) {
        return new MediaSessionService2Impl.MediaNotificationImpl(
                context, instance, notificationId, notification);
    }

    @Override
    public MediaSessionService2Provider createMediaLibraryService2(
            MediaLibraryService2 instance) {
+1 −1
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ public class MockMediaSessionService2 extends MediaSessionService2 {
                .setContentTitle(getPackageName())
                .setContentText("Playback state: " + state.getState())
                .setSmallIcon(android.R.drawable.sym_def_app_icon).build();
        return MediaNotification.create(DEFAULT_MEDIA_NOTIFICATION_ID, notification);
        return new MediaNotification(this, DEFAULT_MEDIA_NOTIFICATION_ID, notification);
    }

    private class MySessionCallback extends SessionCallback {