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

Commit e5a0d405 authored by Brad Ebinger's avatar Brad Ebinger
Browse files

Fix NPE occurring while accessing the token Map in AppSmsManager

In AppSmsManager a crash was occurring when trying to loop through
and remove elements from the token Map. Instead, an iterator is
used to perform this operation safely.

Fixes: 181897608
Test: atest CtsTelephonyTestCases
Change-Id: Icf577604c669545722448a68186da94cac2e69fb
parent 4d1d5049
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -36,8 +36,8 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.Preconditions;

import java.security.SecureRandom;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;


@@ -187,9 +187,10 @@ public class AppSmsManager {
    private void removeExpiredTokenLocked() {
        final long currentTimeMillis = System.currentTimeMillis();

        final Set<String> keySet = mTokenMap.keySet();
        for (String token : keySet) {
            AppRequestInfo request = mTokenMap.get(token);
        Iterator<Map.Entry<String, AppRequestInfo>> iterator = mTokenMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, AppRequestInfo> entry = iterator.next();
            AppRequestInfo request = entry.getValue();
            if (request.packageBasedToken
                    && (currentTimeMillis - TIMEOUT_MILLIS > request.timestamp)) {
                // Send the provided intent with SMS retriever status
@@ -202,8 +203,9 @@ public class AppSmsManager {
                } catch (PendingIntent.CanceledException e) {
                    // do nothing
                }

                removeRequestLocked(request);
                // Remove from mTokenMap and mPackageMap
                iterator.remove();
                mPackageMap.remove(entry.getValue().packageName);
            }
        }
    }