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

Commit 3a6b3992 authored by Yixiao Luo's avatar Yixiao Luo
Browse files

Move calling service.unregisterCallback() into unbindService()

In addition, update some logs for ServiceCallback.

Bug: 351126751
Change-Id: I874be283e1c32de5f473aeea830f991448711af0
Test: mmm
Flag: EXEMPT bugfix
parent 5e11b629
Loading
Loading
Loading
Loading
+16 −20
Original line number Diff line number Diff line
@@ -599,13 +599,6 @@ public final class TvInputManagerService extends SystemService {
            ComponentName component = it.next();
            ServiceState serviceState = userState.serviceStateMap.get(component);
            if (serviceState != null && serviceState.sessionTokens.isEmpty()) {
                if (serviceState.callback != null) {
                    try {
                        serviceState.service.unregisterCallback(serviceState.callback);
                    } catch (RemoteException e) {
                        Slog.e(TAG, "error in unregisterCallback", e);
                    }
                }
                unbindService(serviceState);
                it.remove();
            }
@@ -667,13 +660,6 @@ public final class TvInputManagerService extends SystemService {
            // Unregister all callbacks and unbind all services.
            for (ServiceState serviceState : userState.serviceStateMap.values()) {
                if (serviceState.service != null) {
                    if (serviceState.callback != null) {
                        try {
                            serviceState.service.unregisterCallback(serviceState.callback);
                        } catch (RemoteException e) {
                            Slog.e(TAG, "error in unregisterCallback", e);
                        }
                    }
                    unbindService(serviceState);
                }
            }
@@ -3571,12 +3557,19 @@ public final class TvInputManagerService extends SystemService {

    @GuardedBy("mLock")
    private void unbindService(ServiceState serviceState) {
        if (!serviceState.bound) {
        if (serviceState == null || !serviceState.bound) {
            return;
        }
        if (DEBUG) {
            Slog.d(TAG, "unbindService(service=" + serviceState.component + ")");
        }
        if (serviceState.callback != null) {
            try {
                serviceState.service.unregisterCallback(serviceState.callback);
            } catch (RemoteException e) {
                Slog.e(TAG, "error in unregisterCallback", e);
            }
        }
        mContext.unbindService(serviceState.connection);
        serviceState.bound = false;
        serviceState.service = null;
@@ -3794,9 +3787,9 @@ public final class TvInputManagerService extends SystemService {
                    if (serviceState.hardwareInputMap.containsKey(inputInfo.getId())) {
                        return;
                    }
                    Slog.d("ServiceCallback",
                            "addHardwareInput: device id " + deviceId + ", "
                                    + inputInfo.toString());
                    Slog.d(TAG, "ServiceCallback: addHardwareInput, deviceId: " + deviceId +
                                ", inputInfo: " + inputInfo.toString() + " by " + mComponent +
                                ", userId: " + mUserId);
                    mTvInputHardwareManager.addHardwareInput(deviceId, inputInfo);
                    addHardwareInputLocked(inputInfo, mComponent, mUserId);
                }
@@ -3815,6 +3808,9 @@ public final class TvInputManagerService extends SystemService {
                    if (serviceState.hardwareInputMap.containsKey(inputInfo.getId())) {
                        return;
                    }
                    Slog.d(TAG, "ServiceCallback: addHdmiInput, id: " + id +
                                ", inputInfo: "+ inputInfo.toString() + " by " + mComponent +
                                ", userId: " + mUserId);
                    mTvInputHardwareManager.addHdmiInput(id, inputInfo);
                    addHardwareInputLocked(inputInfo, mComponent, mUserId);
                    if (mOnScreenInputId != null && mOnScreenSessionState != null) {
@@ -3845,8 +3841,8 @@ public final class TvInputManagerService extends SystemService {
            final long identity = Binder.clearCallingIdentity();
            try {
                synchronized (mLock) {
                    Slog.d("ServiceCallback",
                            "removeHardwareInput " + inputId + " by " + mComponent);
                    Slog.d(TAG, "ServiceCallback: removeHardwareInput, inputId: " + inputId +
                                " by " + mComponent + ", userId: " + mUserId);
                    removeHardwareInputLocked(inputId, mUserId);
                }
            } finally {