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

Commit f85fc967 authored by Jason Monk's avatar Jason Monk
Browse files

Fix when instant app notif is showing

Test: manual
Change-Id: If17eddad60f8207fecf9518430a280261bde5b30
Fixes: 37107497
parent 38323f50
Loading
Loading
Loading
Loading
+69 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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;

import android.os.RemoteException;
import android.util.Log;
import android.view.IDockedStackListener;
import android.view.WindowManagerGlobal;

import java.util.function.Consumer;

/**
 * Utility wrapper to listen for whether or not a docked stack exists, to be
 * used for things like the different overview icon in that mode.
 */
public class DockedStackExistsListener extends IDockedStackListener.Stub {

    private static final String TAG = "DockedStackExistsListener";

    private final Consumer<Boolean> mCallback;

    private DockedStackExistsListener(Consumer<Boolean> callback) {
        mCallback = callback;
    }

    @Override
    public void onDividerVisibilityChanged(boolean visible) throws RemoteException {
    }

    @Override
    public void onDockedStackExistsChanged(final boolean exists) throws RemoteException {
        mCallback.accept(exists);
    }

    @Override
    public void onDockedStackMinimizedChanged(boolean minimized, long animDuration,
                                              boolean isHomeStackResizable) throws RemoteException {
    }

    @Override
    public void onAdjustedForImeChanged(boolean adjustedForIme, long animDuration)
            throws RemoteException {
    }

    @Override
    public void onDockSideChanged(int newDockSide) throws RemoteException {
    }

    public static void register(Consumer<Boolean> callback) {
        try {
            WindowManagerGlobal.getWindowManagerService().registerDockedStackListener(
                    new DockedStackExistsListener(callback));
        } catch (RemoteException e) {
            Log.e(TAG, "Failed registering docked stack exists listener", e);
        }
    }
}
+5 −34
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.FrameLayout;

import com.android.systemui.Dependency;
import com.android.systemui.DockedStackExistsListener;
import com.android.systemui.R;
import com.android.systemui.RecentsComponent;
import com.android.systemui.plugins.PluginListener;
@@ -566,40 +567,10 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav

        getImeSwitchButton().setOnClickListener(mImeSwitcherClickListener);

        try {
            WindowManagerGlobal.getWindowManagerService().registerDockedStackListener(new Stub() {
                @Override
                public void onDividerVisibilityChanged(boolean visible) throws RemoteException {
                }

                @Override
                public void onDockedStackExistsChanged(final boolean exists) throws RemoteException {
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
        DockedStackExistsListener.register(exists -> mHandler.post(() -> {
            mDockedStackExists = exists;
            updateRecentsIcon();
                        }
                    });
                }

                @Override
                public void onDockedStackMinimizedChanged(boolean minimized, long animDuration,
                        boolean isHomeStackResizable) throws RemoteException {
                }

                @Override
                public void onAdjustedForImeChanged(boolean adjustedForIme, long animDuration)
                        throws RemoteException {
                }

                @Override
                public void onDockSideChanged(int newDockSide) throws RemoteException {
                }
            });
        } catch (RemoteException e) {
            Log.e(TAG, "Failed registering docked stack exists listener", e);
        }
        }));
    }

    void updateRotatedViews() {
+35 −20
Original line number Diff line number Diff line
@@ -16,17 +16,11 @@

package com.android.systemui.statusbar.phone;

import android.app.ActivityManager;
import android.app.*;
import android.app.ActivityManager.StackId;
import android.app.ActivityManager.StackInfo;
import android.app.AlarmManager;
import android.app.AlarmManager.AlarmClockInfo;
import android.app.AppGlobals;
import android.app.Notification;
import android.app.Notification.Action;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.SynchronousUserSwitchObserver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -55,6 +49,7 @@ import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.internal.telephony.IccCardConstants;
import com.android.internal.telephony.TelephonyIntents;
import com.android.systemui.Dependency;
import com.android.systemui.DockedStackExistsListener;
import com.android.systemui.R;
import com.android.systemui.SysUiServiceProvider;
import com.android.systemui.qs.tiles.DndTile;
@@ -132,6 +127,7 @@ public class PhoneStatusBarPolicy implements Callback, Callbacks,
    private boolean mZenVisible;
    private boolean mVolumeVisible;
    private boolean mCurrentUserSetup;
    private boolean mDockedStackExists;

    private boolean mManagedProfileIconVisible = false;
    private boolean mManagedProfileInQuietMode = false;
@@ -248,6 +244,10 @@ public class PhoneStatusBarPolicy implements Callback, Callbacks,
                noMan.cancel(notification.getTag(), notification.getId());
            }
        }
        DockedStackExistsListener.register(exists -> {
            mDockedStackExists = exists;
            updateForegroundInstantApps();
        });
    }

    public void destroy() {
@@ -495,13 +495,32 @@ public class PhoneStatusBarPolicy implements Callback, Callbacks,
        IPackageManager pm = AppGlobals.getPackageManager();
        mCurrentNotifs.clear();
        try {
            ArraySet<Integer> stacksToCheck = new ArraySet<>();
            int[] STACKS_TO_CHECK = new int[]{
                    StackId.FULLSCREEN_WORKSPACE_STACK_ID,
                    StackId.DOCKED_STACK_ID,
            };
            for (int i = 0; i < STACKS_TO_CHECK.length; i++) {
                StackInfo info = ActivityManager.getService().getStackInfo(STACKS_TO_CHECK[i]);
                if (info == null || info.topActivity == null) continue;
            int focusedId = ActivityManager.getService().getFocusedStackId();
            if (focusedId == StackId.FULLSCREEN_WORKSPACE_STACK_ID
                    || focusedId == StackId.FULLSCREEN_WORKSPACE_STACK_ID) {
                checkStack(StackId.FULLSCREEN_WORKSPACE_STACK_ID, notifs, noMan, pm);
            }
            if (mDockedStackExists) {
                checkStack(StackId.DOCKED_STACK_ID, notifs, noMan, pm);
            }
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
        // Cancel all the leftover notifications that don't have a foreground process anymore.
        notifs.forEach(v -> noMan.cancelAsUser(v.first, SystemMessage.NOTE_INSTANT_APPS,
                new UserHandle(v.second)));
    }

    private void checkStack(int stackId, ArraySet<Pair<String, Integer>> notifs,
            NotificationManager noMan, IPackageManager pm) {
        try {
            StackInfo info = ActivityManager.getService().getStackInfo(stackId);
            if (info == null || info.topActivity == null) return;
            String pkg = info.topActivity.getPackageName();
            if (!hasNotif(notifs, pkg, info.userId)) {
                // TODO: Optimize by not always needing to get application info.
@@ -512,13 +531,9 @@ public class PhoneStatusBarPolicy implements Callback, Callbacks,
                    postEphemeralNotif(pkg, info.userId, appInfo, noMan);
                }
            }
            }
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
        // Cancel all the leftover notifications that don't have a foreground process anymore.
        notifs.forEach(v -> noMan.cancelAsUser(v.first, SystemMessage.NOTE_INSTANT_APPS,
                new UserHandle(v.second)));
    }

    private void postEphemeralNotif(String pkg, int userId, ApplicationInfo appInfo,