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

Commit 31cc6bfc authored by Priyank Singh's avatar Priyank Singh
Browse files

Use the broadCast Receiver to detect when the user is switched and register...

Use the broadCast Receiver to detect when the user is switched and register the notificationListner when the user is switched.

By default the SysUI is booted as User0 after which it switches to the current logged in user. We have to listen to the broadcast receiver to know when that happens.

Bug: 123432748
Test: Manual
Change-Id: I567ae0c53df277097de53475f9144d739fa4a18d
(cherry picked from commit e81756e4d417150ada4eb817f475ad4916751e27)
parent a99c4f30
Loading
Loading
Loading
Loading
+21 −4
Original line number Diff line number Diff line
@@ -24,13 +24,17 @@ import android.app.ActivityManager;
import android.car.Car;
import android.car.CarNotConnectedException;
import android.car.drivingstate.CarUxRestrictionsManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.GestureDetector;
@@ -91,12 +95,28 @@ public class NotificationsUI extends SystemUI
    private static int sSettleOpenPercentage;
    private static int sSettleClosePercentage;

    private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(Intent.ACTION_USER_SWITCHED)) {
                mCarNotificationListener.registerAsSystemService(mContext,
                        mCarUxRestrictionManagerWrapper,
                        mClickHandlerFactory);
                inflateNotificationContent();
            }
        }
    };

    /**
     * Inits the window that hosts the notifications and establishes the connections
     * to the car related services.
     */
    @Override
    public void start() {
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_USER_SWITCHED);
        mContext.registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, filter, null, null);
        sSettleOpenPercentage = mContext.getResources().getInteger(
                R.integer.notification_settle_open_percentage);
        sSettleClosePercentage = mContext.getResources().getInteger(
@@ -117,8 +137,7 @@ public class NotificationsUI extends SystemUI
                        closeCarNotifications(DEFAULT_FLING_VELOCITY);
                    }
                });
        mCarNotificationListener.registerAsSystemService(mContext, mCarUxRestrictionManagerWrapper,
                mClickHandlerFactory);

        mCar = Car.createCar(mContext, mCarConnectionListener);
        mCar.connect();
        NotificationGestureListener gestureListener = new NotificationGestureListener();
@@ -131,8 +150,6 @@ public class NotificationsUI extends SystemUI
        mCarNotificationWindow
                .setBackgroundColor(mContext.getColor(R.color.notification_shade_background_color));

        inflateNotificationContent();

        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY,