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

Commit 533226a3 authored by RoboErik's avatar RoboErik Committed by Android (Google) Code Review
Browse files

Merge "Move VolumeController into AudioService"

parents 6487bccf d09bd0c6
Loading
Loading
Loading
Loading
+88 −0
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set;

/**
@@ -4792,4 +4793,91 @@ public class AudioService extends IAudioService.Stub {
        }
        mVolumeController.setController(controller);
    }

    public static class VolumeController {
        private static final String TAG = "VolumeController";

        private IVolumeController mController;

        public void setController(IVolumeController controller) {
            mController = controller;
        }

        public boolean isSameBinder(IVolumeController controller) {
            return Objects.equals(asBinder(), binder(controller));
        }

        public IBinder asBinder() {
            return binder(mController);
        }

        private static IBinder binder(IVolumeController controller) {
            return controller == null ? null : controller.asBinder();
        }

        @Override
        public String toString() {
            return "VolumeController(" + asBinder() + ")";
        }

        public void postDisplaySafeVolumeWarning(int flags) {
            if (mController == null)
                return;
            try {
                mController.displaySafeVolumeWarning(flags);
            } catch (RemoteException e) {
                Log.w(TAG, "Error calling displaySafeVolumeWarning", e);
            }
        }

        public void postVolumeChanged(int streamType, int flags) {
            if (mController == null)
                return;
            try {
                mController.volumeChanged(streamType, flags);
            } catch (RemoteException e) {
                Log.w(TAG, "Error calling volumeChanged", e);
            }
        }

        public void postMasterVolumeChanged(int flags) {
            if (mController == null)
                return;
            try {
                mController.masterVolumeChanged(flags);
            } catch (RemoteException e) {
                Log.w(TAG, "Error calling masterVolumeChanged", e);
            }
        }

        public void postMasterMuteChanged(int flags) {
            if (mController == null)
                return;
            try {
                mController.masterMuteChanged(flags);
            } catch (RemoteException e) {
                Log.w(TAG, "Error calling masterMuteChanged", e);
            }
        }

        public void setLayoutDirection(int layoutDirection) {
            if (mController == null)
                return;
            try {
                mController.setLayoutDirection(layoutDirection);
            } catch (RemoteException e) {
                Log.w(TAG, "Error calling setLayoutDirection", e);
            }
        }

        public void postDismiss() {
            if (mController == null)
                return;
            try {
                mController.dismiss();
            } catch (RemoteException e) {
                Log.w(TAG, "Error calling dismiss", e);
            }
        }
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ public class MediaFocusControl implements OnFinished {
    private final MediaEventHandler mEventHandler;
    private final Context mContext;
    private final ContentResolver mContentResolver;
    private final VolumeController mVolumeController;
    private final AudioService.VolumeController mVolumeController;
    private final BroadcastReceiver mReceiver = new PackageIntentsReceiver();
    private final AppOpsManager mAppOps;
    private final KeyguardManager mKeyguardManager;
@@ -85,7 +85,7 @@ public class MediaFocusControl implements OnFinished {
    private final NotificationListenerObserver mNotifListenerObserver;

    protected MediaFocusControl(Looper looper, Context cntxt,
            VolumeController volumeCtrl, AudioService as) {
            AudioService.VolumeController volumeCtrl, AudioService as) {
        mEventHandler = new MediaEventHandler(looper);
        mContext = cntxt;
        mContentResolver = mContext.getContentResolver();
+0 −110
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

import java.util.Objects;

/**
 * Wraps the volume controller binder interface as a convenience to audio
 * service.
 *
 * @hide
 */
public class VolumeController {
    private static final String TAG = "VolumeController";

    private IVolumeController mController;

    public void setController(IVolumeController controller) {
        mController = controller;
    }

    public boolean isSameBinder(IVolumeController controller) {
        return Objects.equals(asBinder(), binder(controller));
    }

    public IBinder asBinder() {
        return binder(mController);
    }

    private static IBinder binder(IVolumeController controller) {
        return controller == null ? null : controller.asBinder();
    }

    @Override
    public String toString() {
        return "VolumeController(" + asBinder() + ")";
    }

    public void postDisplaySafeVolumeWarning(int flags) {
        if (mController == null) return;
        try {
            mController.displaySafeVolumeWarning(flags);
        } catch (RemoteException e) {
            Log.w(TAG, "Error calling displaySafeVolumeWarning", e);
        }
    }

    public void postVolumeChanged(int streamType, int flags) {
        if (mController == null) return;
        try {
            mController.volumeChanged(streamType, flags);
        } catch (RemoteException e) {
            Log.w(TAG, "Error calling volumeChanged", e);
        }
    }

    public void postMasterVolumeChanged(int flags) {
        if (mController == null) return;
        try {
            mController.masterVolumeChanged(flags);
        } catch (RemoteException e) {
            Log.w(TAG, "Error calling masterVolumeChanged", e);
        }
    }

    public void postMasterMuteChanged(int flags) {
        if (mController == null) return;
        try {
            mController.masterMuteChanged(flags);
        } catch (RemoteException e) {
            Log.w(TAG, "Error calling masterMuteChanged", e);
        }
    }

    public void setLayoutDirection(int layoutDirection) {
        if (mController == null) return;
        try {
            mController.setLayoutDirection(layoutDirection);
        } catch (RemoteException e) {
            Log.w(TAG, "Error calling setLayoutDirection", e);
        }
    }

    public void postDismiss() {
        if (mController == null) return;
        try {
            mController.dismiss();
        } catch (RemoteException e) {
            Log.w(TAG, "Error calling dismiss", e);
        }
    }
}
 No newline at end of file
+0 −3
Original line number Diff line number Diff line
@@ -102,9 +102,6 @@ public class MediaSessionService extends SystemService implements Monitor {
    // better way to handle this.
    private IRemoteVolumeController mRvc;

    // TODO refactor to have per user state for providers. See
    // MediaRouterService for an example

    public MediaSessionService(Context context) {
        super(context);
        mSessionManagerImpl = new SessionManagerImpl();