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

Commit 0b577cfb authored by Arthur Ishiguro's avatar Arthur Ishiguro
Browse files

Throw exception for immutable PendingIntents

Fixes: 193833333
Test: Compile
Change-Id: I2ba9e19f8962ef172ecb8defa77a352ad7073ca2
parent 6dde8a47
Loading
Loading
Loading
Loading
+8 −1
Original line number Original line Diff line number Diff line
@@ -931,6 +931,9 @@ public final class ContextHubManager {
     * on the provided PendingIntent, then the client will be automatically unregistered by the
     * on the provided PendingIntent, then the client will be automatically unregistered by the
     * service.
     * service.
     *
     *
     * Note that the {@link PendingIntent} supplied to this API must be mutable for Intent
     * notifications to work.
     *
     * @param context       the context of the application. If a PendingIntent client is recreated,
     * @param context       the context of the application. If a PendingIntent client is recreated,
     * the latest state in the context will be used and old state will be discarded
     * the latest state in the context will be used and old state will be discarded
     * @param hubInfo       the hub to attach this client to
     * @param hubInfo       the hub to attach this client to
@@ -938,7 +941,8 @@ public final class ContextHubManager {
     * @param nanoAppId     the ID of the nanoapp that Intent events will be generated for
     * @param nanoAppId     the ID of the nanoapp that Intent events will be generated for
     * @return the registered client object
     * @return the registered client object
     *
     *
     * @throws IllegalArgumentException if hubInfo does not represent a valid hub
     * @throws IllegalArgumentException if hubInfo does not represent a valid hub, or an immutable
     *                                  PendingIntent was supplied
     * @throws IllegalStateException    if there were too many registered clients at the service
     * @throws IllegalStateException    if there were too many registered clients at the service
     * @throws NullPointerException     if pendingIntent or hubInfo is null
     * @throws NullPointerException     if pendingIntent or hubInfo is null
     */
     */
@@ -951,6 +955,9 @@ public final class ContextHubManager {
            @NonNull PendingIntent pendingIntent, long nanoAppId) {
            @NonNull PendingIntent pendingIntent, long nanoAppId) {
        Objects.requireNonNull(pendingIntent);
        Objects.requireNonNull(pendingIntent);
        Objects.requireNonNull(hubInfo);
        Objects.requireNonNull(hubInfo);
        if (pendingIntent.isImmutable()) {
            throw new IllegalArgumentException("PendingIntent must be mutable");
        }


        ContextHubClient client = new ContextHubClient(hubInfo, true /* persistent */);
        ContextHubClient client = new ContextHubClient(hubInfo, true /* persistent */);