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

Commit 956024c5 authored by Shubang Lu's avatar Shubang Lu
Browse files

[TIF CTS] Fix NEP in TvInputManagerService

In onServiceConnected, userState.serviceStateMap.get(mComponent) returns
null because some components are removed in buildTvInputListLocked.

The service state should not be removed there because:
1. The service may be bound and there may be existing sessions
2. ActivityManager restarts crashed service automatically and it causes
   NPE.

The original issue 204469566 can be resolved by calling
updateServiceConnectionLocked()

Bug: 291759647
Test: atest CtsTvTestCases
Change-Id: Ia7d8b7ce5ea3d2d4d9dcd86ffc1ecfaf2fa6c386
parent f01ab23c
Loading
Loading
Loading
Loading
+1 −12
Original line number Diff line number Diff line
@@ -333,7 +333,6 @@ public final class TvInputManagerService extends SystemService {
                PackageManager.GET_SERVICES | PackageManager.GET_META_DATA,
                userId);
        List<TvInputInfo> inputList = new ArrayList<>();
        List<ComponentName> hardwareComponents = new ArrayList<>();
        for (ResolveInfo ri : services) {
            ServiceInfo si = ri.serviceInfo;
            if (!android.Manifest.permission.BIND_TV_INPUT.equals(si.permission)) {
@@ -344,17 +343,16 @@ public final class TvInputManagerService extends SystemService {

            ComponentName component = new ComponentName(si.packageName, si.name);
            if (hasHardwarePermission(pm, component)) {
                hardwareComponents.add(component);
                ServiceState serviceState = userState.serviceStateMap.get(component);
                if (serviceState == null) {
                    // New hardware input found. Create a new ServiceState and connect to the
                    // service to populate the hardware list.
                    serviceState = new ServiceState(component, userId);
                    userState.serviceStateMap.put(component, serviceState);
                    updateServiceConnectionLocked(component, userId);
                } else {
                    inputList.addAll(serviceState.hardwareInputMap.values());
                }
                updateServiceConnectionLocked(component, userId);
            } else {
                try {
                    TvInputInfo info = new TvInputInfo.Builder(mContext, ri).build();
@@ -417,15 +415,6 @@ public final class TvInputManagerService extends SystemService {
            }
        }

        // Clean up ServiceState corresponding to the removed hardware inputs
        Iterator<ServiceState> it = userState.serviceStateMap.values().iterator();
        while (it.hasNext()) {
            ServiceState serviceState = it.next();
            if (serviceState.isHardware && !hardwareComponents.contains(serviceState.component)) {
                it.remove();
            }
        }

        userState.inputMap.clear();
        userState.inputMap = inputMap;
    }