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

Commit d752e1f9 authored by Arthur Ishiguro's avatar Arthur Ishiguro
Browse files

Close unregistered clients with no PendingIntent

This may happen if a PendingIntent becomes invalid without
the client explicitly unregistering it (e.g. invalidated through
the Android system or canceled by the PendingIntent originator). This
avoids dangling client registrations at the service.

Bug: 117612105
Test: Compile only
Change-Id: Ic8d269b4c8d5267fc85170c0a95abcd03538fa9a
parent ee72c438
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -245,11 +245,17 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
    public boolean unregisterIntent(PendingIntent pendingIntent) {
        ContextHubServiceUtil.checkPermissions(mContext);

        boolean success = false;
        synchronized (this) {
            return mPendingIntentRequest.unregister(pendingIntent);
            success = mPendingIntentRequest.unregister(pendingIntent);
            if (mCallbackInterface == null) {
                close();
            }
        }

        return success;
    }

    /**
     * Closes the connection for this client with the service.
     */
@@ -407,6 +413,9 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
                Log.w(TAG, "PendingIntent has been canceled, unregistering from client"
                        + " (host endpoint ID " + mHostEndPointId + ")");
                mPendingIntentRequest.clear();
                if (mCallbackInterface == null) {
                    close();
                }
            }
        }
    }