Reduce chance of notification listener dropped messages.
The existing code for notification manager/listeners uses a oneway binder api to deliver messages. One problem with this is that notification objects can sometimes get fairly large, and can bump into the oneway binder transaction buffer if many happen at once. To reduce this issue, flip the service into a oneway delivery of a status bar notification holder, whose wrapped content is then immediately fetched upon receipt of the one-way message. This moves the meat of the fetch to be over a two-way interface without changing the properties of which object is actually sent (a tickle solution with lookup key would have changed this) Further research: attempt to chunk notification objects themselves. They can sometimes transfer hundreds of KB over a binder transaction. Bug: 15426276 Change-Id: Ib1a1f4ff848c16f80bcf2ae4dfd2b87a9091f0b2
This commit is contained in:
@@ -204,6 +204,7 @@ LOCAL_SRC_FILES += \
|
||||
core/java/android/os/IUserManager.aidl \
|
||||
core/java/android/os/IVibratorService.aidl \
|
||||
core/java/android/service/notification/INotificationListener.aidl \
|
||||
core/java/android/service/notification/IStatusBarNotificationHolder.aidl \
|
||||
core/java/android/service/notification/IConditionListener.aidl \
|
||||
core/java/android/service/notification/IConditionProvider.aidl \
|
||||
core/java/android/print/ILayoutResultCallback.aidl \
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.service.notification;
|
||||
|
||||
import android.service.notification.IStatusBarNotificationHolder;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.service.notification.NotificationRankingUpdate;
|
||||
|
||||
@@ -23,9 +24,9 @@ import android.service.notification.NotificationRankingUpdate;
|
||||
oneway interface INotificationListener
|
||||
{
|
||||
void onListenerConnected(in NotificationRankingUpdate update);
|
||||
void onNotificationPosted(in StatusBarNotification notification,
|
||||
void onNotificationPosted(in IStatusBarNotificationHolder notificationHolder,
|
||||
in NotificationRankingUpdate update);
|
||||
void onNotificationRemoved(in StatusBarNotification notification,
|
||||
void onNotificationRemoved(in IStatusBarNotificationHolder notificationHolder,
|
||||
in NotificationRankingUpdate update);
|
||||
void onNotificationRankingUpdate(in NotificationRankingUpdate update);
|
||||
void onListenerHintsChanged(int hints);
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) 2014, 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 android.service.notification;
|
||||
|
||||
import android.service.notification.StatusBarNotification;
|
||||
|
||||
/** @hide */
|
||||
interface IStatusBarNotificationHolder {
|
||||
StatusBarNotification get();
|
||||
}
|
||||
@@ -601,8 +601,15 @@ public abstract class NotificationListenerService extends Service {
|
||||
|
||||
private class INotificationListenerWrapper extends INotificationListener.Stub {
|
||||
@Override
|
||||
public void onNotificationPosted(StatusBarNotification sbn,
|
||||
public void onNotificationPosted(IStatusBarNotificationHolder sbnHolder,
|
||||
NotificationRankingUpdate update) {
|
||||
StatusBarNotification sbn;
|
||||
try {
|
||||
sbn = sbnHolder.get();
|
||||
} catch (RemoteException e) {
|
||||
Log.w(TAG, "onNotificationPosted: Error receiving StatusBarNotification", e);
|
||||
return;
|
||||
}
|
||||
Notification.Builder.rebuild(getContext(), sbn.getNotification());
|
||||
|
||||
// protect subclass from concurrent modifications of (@link mNotificationKeys}.
|
||||
@@ -616,8 +623,15 @@ public abstract class NotificationListenerService extends Service {
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onNotificationRemoved(StatusBarNotification sbn,
|
||||
public void onNotificationRemoved(IStatusBarNotificationHolder sbnHolder,
|
||||
NotificationRankingUpdate update) {
|
||||
StatusBarNotification sbn;
|
||||
try {
|
||||
sbn = sbnHolder.get();
|
||||
} catch (RemoteException e) {
|
||||
Log.w(TAG, "onNotificationRemoved: Error receiving StatusBarNotification", e);
|
||||
return;
|
||||
}
|
||||
// protect subclass from concurrent modifications of (@link mNotificationKeys}.
|
||||
synchronized (mWrapper) {
|
||||
applyUpdate(update);
|
||||
|
||||
@@ -69,6 +69,7 @@ import android.service.notification.Condition;
|
||||
import android.service.notification.IConditionListener;
|
||||
import android.service.notification.IConditionProvider;
|
||||
import android.service.notification.INotificationListener;
|
||||
import android.service.notification.IStatusBarNotificationHolder;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.service.notification.NotificationRankingUpdate;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
@@ -2811,8 +2812,9 @@ public class NotificationManagerService extends SystemService {
|
||||
private void notifyPosted(final ManagedServiceInfo info,
|
||||
final StatusBarNotification sbn, NotificationRankingUpdate rankingUpdate) {
|
||||
final INotificationListener listener = (INotificationListener)info.service;
|
||||
StatusBarNotificationHolder sbnHolder = new StatusBarNotificationHolder(sbn);
|
||||
try {
|
||||
listener.onNotificationPosted(sbn, rankingUpdate);
|
||||
listener.onNotificationPosted(sbnHolder, rankingUpdate);
|
||||
} catch (RemoteException ex) {
|
||||
Log.e(TAG, "unable to notify listener (posted): " + listener, ex);
|
||||
}
|
||||
@@ -2824,8 +2826,9 @@ public class NotificationManagerService extends SystemService {
|
||||
return;
|
||||
}
|
||||
final INotificationListener listener = (INotificationListener) info.service;
|
||||
StatusBarNotificationHolder sbnHolder = new StatusBarNotificationHolder(sbn);
|
||||
try {
|
||||
listener.onNotificationRemoved(sbn, rankingUpdate);
|
||||
listener.onNotificationRemoved(sbnHolder, rankingUpdate);
|
||||
} catch (RemoteException ex) {
|
||||
Log.e(TAG, "unable to notify listener (removed): " + listener, ex);
|
||||
}
|
||||
@@ -2913,4 +2916,22 @@ public class NotificationManagerService extends SystemService {
|
||||
return zen ? "zen" : ('\'' + pkgFilter + '\'');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for a StatusBarNotification object that allows transfer across a oneway
|
||||
* binder without sending large amounts of data over a oneway transaction.
|
||||
*/
|
||||
private static final class StatusBarNotificationHolder
|
||||
extends IStatusBarNotificationHolder.Stub {
|
||||
private final StatusBarNotification mValue;
|
||||
|
||||
public StatusBarNotificationHolder(StatusBarNotification value) {
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatusBarNotification get() {
|
||||
return mValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user