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

Commit b1c4a2a3 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Fix issue #2364506: Phone locked up while listening to music and attempting to download an update

Make sure calls into the notification manager are not done with the
activity manager lock held.

Change-Id: Ib53c3b9f46160d94ee1e7079b1a5123e0d1225d8
parent 6866daee
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -10276,7 +10276,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
                                sInfo.applicationInfo.uid, sInfo.packageName,
                                sInfo.name);
                    }
                    r = new ServiceRecord(ss, name, filter, sInfo, res);
                    r = new ServiceRecord(this, ss, name, filter, sInfo, res);
                    res.setService(r);
                    mServices.put(name, r);
                    mServicesByIntent.put(filter, r);
+37 −15
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import java.util.List;
 * A running application service.
 */
class ServiceRecord extends Binder {
    final ActivityManagerService ams;
    final BatteryStatsImpl.Uid.Pkg.Serv stats;
    final ComponentName name; // service component.
    final String shortName; // name.flattenToShortString().
@@ -192,8 +193,10 @@ class ServiceRecord extends Binder {
        }
    }

    ServiceRecord(BatteryStatsImpl.Uid.Pkg.Serv servStats, ComponentName name,
    ServiceRecord(ActivityManagerService ams,
            BatteryStatsImpl.Uid.Pkg.Serv servStats, ComponentName name,
            Intent.FilterComparison intent, ServiceInfo sInfo, Runnable restarter) {
        this.ams = ams;
        this.stats = servStats;
        this.name = name;
        shortName = name.flattenToShortString();
@@ -249,27 +252,46 @@ class ServiceRecord extends Binder {
    
    public void postNotification() {
        if (foregroundId != 0 && foregroundNoti != null) {
            // Do asynchronous communication with notification manager to
            // avoid deadlocks.
            final String localPackageName = packageName;
            final int localForegroundId = foregroundId;
            final Notification localForegroundNoti = foregroundNoti;
            ams.mHandler.post(new Runnable() {
                public void run() {
                    INotificationManager inm = NotificationManager.getService();
            if (inm != null) {
                    if (inm == null) {
                        return;
                    }
                    try {
                        int[] outId = new int[1];
                    inm.enqueueNotification(packageName, foregroundId,
                            foregroundNoti, outId);
                        inm.enqueueNotification(localPackageName, localForegroundId,
                                localForegroundNoti, outId);
                    } catch (RemoteException e) {
                    }
                }
            });
        }
    }
    
    public void cancelNotification() {
        if (foregroundId != 0) {
            // Do asynchronous communication with notification manager to
            // avoid deadlocks.
            final String localPackageName = packageName;
            final int localForegroundId = foregroundId;
            ams.mHandler.post(new Runnable() {
                public void run() {
                    INotificationManager inm = NotificationManager.getService();
            if (inm != null) {
                    if (inm == null) {
                        return;
                    }
                    try {
                    inm.cancelNotification(packageName, foregroundId);
                        inm.cancelNotification(localPackageName, localForegroundId);
                    } catch (RemoteException e) {
                    }
                }
            });
        }
    }