Showing notification when activity is in PiP.
- Adding callback to SystemUI to be notified which package entered PiP,
and when it leaves PiP.
- Showing a BTW notification on a new PiP-specific channel.
Bug: 36070720
Test: Launch PiP, observe notification, leave PiP, observe no notification
Change-Id: Ibe10298288fe0464d7d136f2571e855f3f5c70ea
diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java
index 2885e66..e64b4b3 100644
--- a/services/core/java/com/android/server/am/ActivityStack.java
+++ b/services/core/java/com/android/server/am/ActivityStack.java
@@ -4983,6 +4983,11 @@
}
task.setStack(null);
+
+ // Notify if a task from the pinned stack is being removed (or moved depending on the mode)
+ if (mStackId == PINNED_STACK_ID) {
+ mService.mTaskChangeNotificationController.notifyActivityUnpinned();
+ }
}
TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent,
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
index 42efe0b..bce8c40 100644
--- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
@@ -2852,7 +2852,7 @@
resumeFocusedStackTopActivityLocked();
stack.animateResizePinnedStack(bounds, -1 /* animationDuration */);
- mService.mTaskChangeNotificationController.notifyActivityPinned();
+ mService.mTaskChangeNotificationController.notifyActivityPinned(r.packageName);
}
/** Move activity with its stack to front and make the stack focused. */
diff --git a/services/core/java/com/android/server/am/TaskChangeNotificationController.java b/services/core/java/com/android/server/am/TaskChangeNotificationController.java
index 3cec7e4..94cf092 100644
--- a/services/core/java/com/android/server/am/TaskChangeNotificationController.java
+++ b/services/core/java/com/android/server/am/TaskChangeNotificationController.java
@@ -47,6 +47,7 @@
static final int NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG = 14;
static final int NOTIFY_TASK_SNAPSHOT_CHANGED_LISTENERS_MSG = 15;
static final int NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG = 16;
+ static final int NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG = 17;
// Delay in notifying task stack change listeners (in millis)
static final int NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY = 100;
@@ -94,7 +95,11 @@
};
private final TaskStackConsumer mNotifyActivityPinned = (l, m) -> {
- l.onActivityPinned();
+ l.onActivityPinned((String) m.obj);
+ };
+
+ private final TaskStackConsumer mNotifyActivityUnpinned = (l, m) -> {
+ l.onActivityUnpinned();
};
private final TaskStackConsumer mNotifyPinnedActivityRestartAttempt = (l, m) -> {
@@ -168,6 +173,9 @@
case NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG:
forAllRemoteListeners(mNotifyActivityPinned, msg);
break;
+ case NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG:
+ forAllRemoteListeners(mNotifyActivityUnpinned, msg);
+ break;
case NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG:
forAllRemoteListeners(mNotifyPinnedActivityRestartAttempt, msg);
break;
@@ -263,13 +271,22 @@
}
/** Notifies all listeners when an Activity is pinned. */
- void notifyActivityPinned() {
+ void notifyActivityPinned(String packageName) {
mHandler.removeMessages(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG);
- final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG);
+ final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG,
+ packageName);
forAllLocalListeners(mNotifyActivityPinned, msg);
msg.sendToTarget();
}
+ /** Notifies all listeners when an Activity is unpinned. */
+ void notifyActivityUnpinned() {
+ mHandler.removeMessages(NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG);
+ final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG);
+ forAllLocalListeners(mNotifyActivityUnpinned, msg);
+ msg.sendToTarget();
+ }
+
/**
* Notifies all listeners when an attempt was made to start an an activity that is already
* running in the pinned stack and the activity was not actually started, but the task is