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

Commit efa42d2c authored by Hongwei Wang's avatar Hongwei Wang
Browse files

Removes the SysUi hook for car VolumeController

Bug: 64448388
Test: None
Change-Id: I367c392adbf12f07ee5ad0f0cb4b60f0eb769c84
parent c17c2a8a
Loading
Loading
Loading
Loading
+0 −15
Original line number Diff line number Diff line
@@ -18,23 +18,9 @@ package com.android.systemui.car;
import android.content.Context;
import android.util.ArrayMap;

import com.android.internal.logging.MetricsLogger;
import com.android.systemui.Dependency;
import com.android.systemui.Dependency.DependencyProvider;
import com.android.systemui.ForegroundServiceController;
import com.android.systemui.SystemUIFactory;
import com.android.systemui.UiOffloadThread;
import com.android.systemui.plugins.VolumeDialogController;
import com.android.systemui.statusbar.NotificationEntryManager;
import com.android.systemui.statusbar.NotificationGutsManager;
import com.android.systemui.statusbar.NotificationListener;
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
import com.android.systemui.statusbar.NotificationMediaManager;
import com.android.systemui.statusbar.NotificationRemoteInputManager;
import com.android.systemui.statusbar.notification.VisualStabilityManager;
import com.android.systemui.statusbar.phone.NotificationGroupManager;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.systemui.volume.car.CarVolumeDialogController;

/**
 * Class factory to provide car specific SystemUI components.
@@ -44,7 +30,6 @@ public class CarSystemUIFactory extends SystemUIFactory {
    public void injectDependencies(ArrayMap<Object, DependencyProvider> providers,
            Context context) {
        super.injectDependencies(providers, context);
        providers.put(VolumeDialogController.class, () -> new CarVolumeDialogController(context));
        providers.put(NotificationEntryManager.class,
                () -> new CarNotificationEntryManager(context));
    }
+0 −138
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 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 com.android.systemui.volume.car;

import android.car.Car;
import android.car.CarNotConnectedException;
import android.car.media.CarAudioManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.util.Log;

import com.android.systemui.volume.VolumeDialogControllerImpl;

/**
 * A volume dialog controller for the automotive use case.
 * TODO(hwwang): consider removing this class since it's coupled with stream_type and we are
 * moving to use AudioAttributes usage for volume control in a car.
 *
 * {@link android.car.media.CarAudioManager} is the source of truth to get the stream volumes.
 * And volume changes should be sent to the car's audio module instead of the android's audio mixer.
 */
public class CarVolumeDialogController extends VolumeDialogControllerImpl {
    private static final String TAG = "CarVolumeDialogController";

    private final Car mCar;
    private CarAudioManager mCarAudioManager;

    private final ServiceConnection mConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            try {
                mCarAudioManager = (CarAudioManager) mCar.getCarManager(Car.AUDIO_SERVICE);
                setVolumeController();
                CarVolumeDialogController.this.getState();
            } catch (CarNotConnectedException e) {
                Log.e(TAG, "Car is not connected!", e);
            }
        }

        @Override
        public void onServiceDisconnected(ComponentName componentName) {
            Log.e(TAG, "Car service is disconnected");
        }
    };

    public CarVolumeDialogController(Context context) {
        super(context);
        mCar = Car.createCar(context, mConnection);
        mCar.connect();
    }

    @Override
    protected void setAudioManagerStreamVolume(int stream, int level, int flag) {
        if (mCarAudioManager == null) {
            Log.d(TAG, "Car audio manager is not initialized yet");
            return;
        }
        try {
            mCarAudioManager.setUsageVolume(stream, level, flag);
        } catch (CarNotConnectedException e) {
            Log.e(TAG, "Car is not connected", e);
        }
    }

    @Override
    protected int getAudioManagerStreamVolume(int stream) {
        if(mCarAudioManager == null) {
            Log.d(TAG, "Car audio manager is not initialized yet");
            return 0;
        }

        try {
            return mCarAudioManager.getUsageVolume(stream);
        } catch (CarNotConnectedException e) {
            Log.e(TAG, "Car is not connected", e);
            return 0;
        }
    }

    @Override
    protected int getAudioManagerStreamMaxVolume(int stream) {
        if(mCarAudioManager == null) {
            Log.d(TAG, "Car audio manager is not initialized yet");
            return 0;
        }

        try {
            return mCarAudioManager.getUsageMaxVolume(stream);
        } catch (CarNotConnectedException e) {
            Log.e(TAG, "Car is not connected", e);
            return 0;
        }
    }

    @Override
    protected int getAudioManagerStreamMinVolume(int stream) {
        if(mCarAudioManager == null) {
            Log.d(TAG, "Car audio manager is not initialized yet");
            return 0;
        }

        try {
            return mCarAudioManager.getUsageMinVolume(stream);
        } catch (CarNotConnectedException e) {
            Log.e(TAG, "Car is not connected", e);
            return 0;
        }
    }

    @Override
    public void setVolumeController() {
        if (mCarAudioManager == null) {
            Log.d(TAG, "Car audio manager is not initialized yet");
            return;
        }
        try {
            mCarAudioManager.setVolumeController(mVolumeController);
        } catch (CarNotConnectedException e) {
            Log.e(TAG, "Car is not connected", e);
        }
    }
}