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

Commit 4a57bab0 authored by Kyeongkab.Nam's avatar Kyeongkab.Nam Committed by android-build-merger
Browse files

Merge "Merge "Fix exception of unregisterCallback when callback is not...

Merge "Merge "Fix exception of unregisterCallback when callback is not registered" am: 43b75cad am: d526de2c" into qt-dev-plus-aosp
am: 1b846b46

Change-Id: If20741319174bf3bb9a9addddc47b8fc55ec023f
parents d135418c 1b846b46
Loading
Loading
Loading
Loading
+33 −36
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import android.os.Looper;
import android.os.Message;
import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.os.UserHandle;
import android.text.TextUtils;
@@ -128,8 +129,6 @@ public final class TvInputManagerService extends SystemService {

    private final WatchLogHandler mWatchLogHandler;

    private IBinder.DeathRecipient mDeathRecipient;

    public TvInputManagerService(Context context) {
        super(context);

@@ -484,7 +483,7 @@ public final class TvInputManagerService extends SystemService {
            userState.packageSet.clear();
            userState.contentRatingSystemList.clear();
            userState.clientStateMap.clear();
            userState.callbackSet.clear();
            userState.mCallbacks.kill();
            userState.mainSessionToken = null;

            mUserStates.remove(userId);
@@ -751,39 +750,45 @@ public final class TvInputManagerService extends SystemService {
        if (DEBUG) {
            Slog.d(TAG, "notifyInputAddedLocked(inputId=" + inputId + ")");
        }
        for (ITvInputManagerCallback callback : userState.callbackSet) {
        int n = userState.mCallbacks.beginBroadcast();
        for (int i = 0; i < n; ++i) {
            try {
                callback.onInputAdded(inputId);
                userState.mCallbacks.getBroadcastItem(i).onInputAdded(inputId);
            } catch (RemoteException e) {
                Slog.e(TAG, "failed to report added input to callback", e);
            }
        }
        userState.mCallbacks.finishBroadcast();
    }

    private void notifyInputRemovedLocked(UserState userState, String inputId) {
        if (DEBUG) {
            Slog.d(TAG, "notifyInputRemovedLocked(inputId=" + inputId + ")");
        }
        for (ITvInputManagerCallback callback : userState.callbackSet) {
        int n = userState.mCallbacks.beginBroadcast();
        for (int i = 0; i < n; ++i) {
            try {
                callback.onInputRemoved(inputId);
                userState.mCallbacks.getBroadcastItem(i).onInputRemoved(inputId);
            } catch (RemoteException e) {
                Slog.e(TAG, "failed to report removed input to callback", e);
            }
        }
        userState.mCallbacks.finishBroadcast();
    }

    private void notifyInputUpdatedLocked(UserState userState, String inputId) {
        if (DEBUG) {
            Slog.d(TAG, "notifyInputUpdatedLocked(inputId=" + inputId + ")");
        }
        for (ITvInputManagerCallback callback : userState.callbackSet) {
        int n = userState.mCallbacks.beginBroadcast();
        for (int i = 0; i < n; ++i) {
            try {
                callback.onInputUpdated(inputId);
                userState.mCallbacks.getBroadcastItem(i).onInputUpdated(inputId);
            } catch (RemoteException e) {
                Slog.e(TAG, "failed to report updated input to callback", e);
            }
        }
        userState.mCallbacks.finishBroadcast();
    }

    private void notifyInputStateChangedLocked(UserState userState, String inputId,
@@ -793,13 +798,15 @@ public final class TvInputManagerService extends SystemService {
                    + ", state=" + state + ")");
        }
        if (targetCallback == null) {
            for (ITvInputManagerCallback callback : userState.callbackSet) {
            int n = userState.mCallbacks.beginBroadcast();
            for (int i = 0; i < n; ++i) {
                try {
                    callback.onInputStateChanged(inputId, state);
                    userState.mCallbacks.getBroadcastItem(i).onInputStateChanged(inputId, state);
                } catch (RemoteException e) {
                    Slog.e(TAG, "failed to report state change to callback", e);
                }
            }
            userState.mCallbacks.finishBroadcast();
        } else {
            try {
                targetCallback.onInputStateChanged(inputId, state);
@@ -821,13 +828,15 @@ public final class TvInputManagerService extends SystemService {
        }
        inputState.info = inputInfo;

        for (ITvInputManagerCallback callback : userState.callbackSet) {
        int n = userState.mCallbacks.beginBroadcast();
        for (int i = 0; i < n; ++i) {
            try {
                callback.onTvInputInfoUpdated(inputInfo);
                userState.mCallbacks.getBroadcastItem(i).onTvInputInfoUpdated(inputInfo);
            } catch (RemoteException e) {
                Slog.e(TAG, "failed to report updated input info to callback", e);
            }
        }
        userState.mCallbacks.finishBroadcast();
    }

    private void setStateLocked(String inputId, int state, int userId) {
@@ -1005,22 +1014,8 @@ public final class TvInputManagerService extends SystemService {
            try {
                synchronized (mLock) {
                    final UserState userState = getOrCreateUserStateLocked(resolvedUserId);
                    userState.callbackSet.add(callback);
                    mDeathRecipient = new IBinder.DeathRecipient() {
                        @Override
                        public void binderDied() {
                            synchronized (mLock) {
                                if (userState.callbackSet != null) {
                                    userState.callbackSet.remove(callback);
                                }
                            }
                        }
                    };

                    try {
                        callback.asBinder().linkToDeath(mDeathRecipient, 0);
                    } catch (RemoteException e) {
                        Slog.e(TAG, "client process has already died", e);
                    if (!userState.mCallbacks.register(callback)) {
                        Slog.e(TAG, "client process has already died");
                    }
                }
            } finally {
@@ -1036,8 +1031,7 @@ public final class TvInputManagerService extends SystemService {
            try {
                synchronized (mLock) {
                    UserState userState = getOrCreateUserStateLocked(resolvedUserId);
                    userState.callbackSet.remove(callback);
                    callback.asBinder().unlinkToDeath(mDeathRecipient, 0);
                    userState.mCallbacks.unregister(callback);
                }
            } finally {
                Binder.restoreCallingIdentity(identity);
@@ -2108,11 +2102,13 @@ public final class TvInputManagerService extends SystemService {
                    }
                    pw.decreaseIndent();

                    pw.println("callbackSet:");
                    pw.println("mCallbacks:");
                    pw.increaseIndent();
                    for (ITvInputManagerCallback callback : userState.callbackSet) {
                        pw.println(callback.toString());
                    int n = userState.mCallbacks.beginBroadcast();
                    for (int j = 0; j < n; ++j) {
                        pw.println(userState.mCallbacks.getRegisteredCallbackItem(j).toString());
                    }
                    userState.mCallbacks.finishBroadcast();
                    pw.decreaseIndent();

                    pw.println("mainSessionToken: " + userState.mainSessionToken);
@@ -2143,8 +2139,9 @@ public final class TvInputManagerService extends SystemService {
        // A mapping from the token of a TV input session to its state.
        private final Map<IBinder, SessionState> sessionStateMap = new HashMap<>();

        // A set of callbacks.
        private final Set<ITvInputManagerCallback> callbackSet = new HashSet<>();
        // A list of callbacks.
        private final RemoteCallbackList<ITvInputManagerCallback> mCallbacks =
                new RemoteCallbackList<ITvInputManagerCallback>();

        // The token of a "main" TV input session.
        private IBinder mainSessionToken = null;