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

Commit dc34df5d authored by Dan Sandler's avatar Dan Sandler
Browse files

Suppress heads-up notifications in VR mode.

Fixes: 27884853
Change-Id: I14d2dd66bea5b18e4d710c74d443e88cfbb3c028
parent db5c5653
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -159,6 +159,9 @@
    <!-- DND access -->
    <!-- DND access -->
    <uses-permission android:name="android.permission.MANAGE_NOTIFICATIONS" />
    <uses-permission android:name="android.permission.MANAGE_NOTIFICATIONS" />


    <!-- It's like, reality, but, you know, virtual -->
    <uses-permission android:name="android.permission.ACCESS_VR_MANAGER" />

    <application
    <application
        android:name=".SystemUIApplication"
        android:name=".SystemUIApplication"
        android:persistent="true"
        android:persistent="true"
+27 −0
Original line number Original line Diff line number Diff line
@@ -63,6 +63,8 @@ import android.service.dreams.IDreamManager;
import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationListenerService.RankingMap;
import android.service.notification.NotificationListenerService.RankingMap;
import android.service.notification.StatusBarNotification;
import android.service.notification.StatusBarNotification;
import android.service.vr.IVrManager;
import android.service.vr.IVrStateCallbacks;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.ArraySet;
import android.util.Log;
import android.util.Log;
@@ -262,11 +264,24 @@ public abstract class BaseStatusBar extends SystemUI implements


    protected AssistManager mAssistManager;
    protected AssistManager mAssistManager;


    protected boolean mVrMode;

    @Override  // NotificationData.Environment
    @Override  // NotificationData.Environment
    public boolean isDeviceProvisioned() {
    public boolean isDeviceProvisioned() {
        return mDeviceProvisioned;
        return mDeviceProvisioned;
    }
    }


    private final IVrStateCallbacks mVrStateCallbacks = new IVrStateCallbacks.Stub() {
        @Override
        public void onVrStateChanged(boolean enabled) {
            mVrMode = enabled;
        }
    };

    public boolean isDeviceInVrMode() {
        return mVrMode;
    }

    protected final ContentObserver mSettingsObserver = new ContentObserver(mHandler) {
    protected final ContentObserver mSettingsObserver = new ContentObserver(mHandler) {
        @Override
        @Override
        public void onChange(boolean selfChange) {
        public void onChange(boolean selfChange) {
@@ -776,6 +791,14 @@ public abstract class BaseStatusBar extends SystemUI implements
        mContext.registerReceiverAsUser(mAllUsersReceiver, UserHandle.ALL, allUsersFilter,
        mContext.registerReceiverAsUser(mAllUsersReceiver, UserHandle.ALL, allUsersFilter,
                null, null);
                null, null);
        updateCurrentProfilesCache();
        updateCurrentProfilesCache();

        IVrManager vrManager = IVrManager.Stub.asInterface(ServiceManager.getService("vrmanager"));
        try {
            vrManager.registerListener(mVrStateCallbacks);
        } catch (RemoteException e) {
            Slog.e(TAG, "Failed to register VR mode state listener: " + e);
        }

    }
    }


    protected void notifyUserAboutHiddenNotifications() {
    protected void notifyUserAboutHiddenNotifications() {
@@ -2353,6 +2376,10 @@ public abstract class BaseStatusBar extends SystemUI implements
    }
    }


    protected boolean shouldPeek(Entry entry, StatusBarNotification sbn) {
    protected boolean shouldPeek(Entry entry, StatusBarNotification sbn) {
        if (isDeviceInVrMode()) {
            return false;
        }

        if (mNotificationData.shouldFilterOut(sbn)) {
        if (mNotificationData.shouldFilterOut(sbn)) {
            if (DEBUG) Log.d(TAG, "No peeking: filtered notification: " + sbn.getKey());
            if (DEBUG) Log.d(TAG, "No peeking: filtered notification: " + sbn.getKey());
            return false;
            return false;
+4 −0
Original line number Original line Diff line number Diff line
@@ -1374,6 +1374,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
    }
    }


    private boolean shouldSuppressFullScreenIntent(String key) {
    private boolean shouldSuppressFullScreenIntent(String key) {
        if (isDeviceInVrMode()) {
            return true;
        }

        if (mPowerManager.isInteractive()) {
        if (mPowerManager.isInteractive()) {
            return mNotificationData.shouldSuppressScreenOn(key);
            return mNotificationData.shouldSuppressScreenOn(key);
        } else {
        } else {
+28 −0
Original line number Original line Diff line number Diff line
@@ -50,6 +50,8 @@ import com.android.server.vr.EnabledComponentsObserver.EnabledComponentChangeLis
import com.android.server.utils.ManagedApplicationService;
import com.android.server.utils.ManagedApplicationService;
import com.android.server.utils.ManagedApplicationService.BinderChecker;
import com.android.server.utils.ManagedApplicationService.BinderChecker;


import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.lang.StringBuilder;
import java.lang.StringBuilder;
import java.lang.ref.WeakReference;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.ArrayList;
@@ -186,6 +188,32 @@ public class VrManagerService extends SystemService implements EnabledComponentC
            return VrManagerService.this.getVrMode();
            return VrManagerService.this.getVrMode();
        }
        }


        @Override
        protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
            if (getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
                    != PackageManager.PERMISSION_GRANTED) {
                pw.println("permission denied: can't dump VrManagerService from pid="
                        + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
                return;
            }
            pw.print("mVrModeEnabled=");
            pw.println(mVrModeEnabled);
            pw.print("mCurrentVrModeUser=");
            pw.println(mCurrentVrModeUser);
            pw.print("mRemoteCallbacks=");
            int i=mRemoteCallbacks.beginBroadcast(); // create the broadcast item array
            while(i-->0) {
                pw.print(mRemoteCallbacks.getBroadcastItem(i));
                if (i>0) pw.print(", ");
            }
            mRemoteCallbacks.finishBroadcast();
            pw.println();
            pw.print("mCurrentVrService=");
            pw.println(mCurrentVrService != null ? mCurrentVrService.getComponent() : "(none)");
            pw.print("mCurrentVrModeComponent=");
            pw.println(mCurrentVrModeComponent);
        }

    };
    };


    private void enforceCallerPermission(String permission) {
    private void enforceCallerPermission(String permission) {