Merge "Fix exception of unregisterCallback when callback is not registered"
am: 43b75cad9e
Change-Id: I80436d7b921a99be91d0b3b97916728189900212
This commit is contained in:
@@ -67,6 +67,7 @@ import android.os.Looper;
|
|||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
|
import android.os.RemoteCallbackList;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -128,8 +129,6 @@ public final class TvInputManagerService extends SystemService {
|
|||||||
|
|
||||||
private final WatchLogHandler mWatchLogHandler;
|
private final WatchLogHandler mWatchLogHandler;
|
||||||
|
|
||||||
private IBinder.DeathRecipient mDeathRecipient;
|
|
||||||
|
|
||||||
public TvInputManagerService(Context context) {
|
public TvInputManagerService(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
@@ -484,7 +483,7 @@ public final class TvInputManagerService extends SystemService {
|
|||||||
userState.packageSet.clear();
|
userState.packageSet.clear();
|
||||||
userState.contentRatingSystemList.clear();
|
userState.contentRatingSystemList.clear();
|
||||||
userState.clientStateMap.clear();
|
userState.clientStateMap.clear();
|
||||||
userState.callbackSet.clear();
|
userState.mCallbacks.kill();
|
||||||
userState.mainSessionToken = null;
|
userState.mainSessionToken = null;
|
||||||
|
|
||||||
mUserStates.remove(userId);
|
mUserStates.remove(userId);
|
||||||
@@ -749,39 +748,45 @@ public final class TvInputManagerService extends SystemService {
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "notifyInputAddedLocked(inputId=" + inputId + ")");
|
Slog.d(TAG, "notifyInputAddedLocked(inputId=" + inputId + ")");
|
||||||
}
|
}
|
||||||
for (ITvInputManagerCallback callback : userState.callbackSet) {
|
int n = userState.mCallbacks.beginBroadcast();
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
try {
|
try {
|
||||||
callback.onInputAdded(inputId);
|
userState.mCallbacks.getBroadcastItem(i).onInputAdded(inputId);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Slog.e(TAG, "failed to report added input to callback", e);
|
Slog.e(TAG, "failed to report added input to callback", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
userState.mCallbacks.finishBroadcast();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyInputRemovedLocked(UserState userState, String inputId) {
|
private void notifyInputRemovedLocked(UserState userState, String inputId) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "notifyInputRemovedLocked(inputId=" + inputId + ")");
|
Slog.d(TAG, "notifyInputRemovedLocked(inputId=" + inputId + ")");
|
||||||
}
|
}
|
||||||
for (ITvInputManagerCallback callback : userState.callbackSet) {
|
int n = userState.mCallbacks.beginBroadcast();
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
try {
|
try {
|
||||||
callback.onInputRemoved(inputId);
|
userState.mCallbacks.getBroadcastItem(i).onInputRemoved(inputId);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Slog.e(TAG, "failed to report removed input to callback", e);
|
Slog.e(TAG, "failed to report removed input to callback", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
userState.mCallbacks.finishBroadcast();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyInputUpdatedLocked(UserState userState, String inputId) {
|
private void notifyInputUpdatedLocked(UserState userState, String inputId) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "notifyInputUpdatedLocked(inputId=" + inputId + ")");
|
Slog.d(TAG, "notifyInputUpdatedLocked(inputId=" + inputId + ")");
|
||||||
}
|
}
|
||||||
for (ITvInputManagerCallback callback : userState.callbackSet) {
|
int n = userState.mCallbacks.beginBroadcast();
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
try {
|
try {
|
||||||
callback.onInputUpdated(inputId);
|
userState.mCallbacks.getBroadcastItem(i).onInputUpdated(inputId);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Slog.e(TAG, "failed to report updated input to callback", e);
|
Slog.e(TAG, "failed to report updated input to callback", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
userState.mCallbacks.finishBroadcast();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyInputStateChangedLocked(UserState userState, String inputId,
|
private void notifyInputStateChangedLocked(UserState userState, String inputId,
|
||||||
@@ -791,13 +796,15 @@ public final class TvInputManagerService extends SystemService {
|
|||||||
+ ", state=" + state + ")");
|
+ ", state=" + state + ")");
|
||||||
}
|
}
|
||||||
if (targetCallback == null) {
|
if (targetCallback == null) {
|
||||||
for (ITvInputManagerCallback callback : userState.callbackSet) {
|
int n = userState.mCallbacks.beginBroadcast();
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
try {
|
try {
|
||||||
callback.onInputStateChanged(inputId, state);
|
userState.mCallbacks.getBroadcastItem(i).onInputStateChanged(inputId, state);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Slog.e(TAG, "failed to report state change to callback", e);
|
Slog.e(TAG, "failed to report state change to callback", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
userState.mCallbacks.finishBroadcast();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
targetCallback.onInputStateChanged(inputId, state);
|
targetCallback.onInputStateChanged(inputId, state);
|
||||||
@@ -819,13 +826,15 @@ public final class TvInputManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
inputState.info = inputInfo;
|
inputState.info = inputInfo;
|
||||||
|
|
||||||
for (ITvInputManagerCallback callback : userState.callbackSet) {
|
int n = userState.mCallbacks.beginBroadcast();
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
try {
|
try {
|
||||||
callback.onTvInputInfoUpdated(inputInfo);
|
userState.mCallbacks.getBroadcastItem(i).onTvInputInfoUpdated(inputInfo);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Slog.e(TAG, "failed to report updated input info to callback", 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) {
|
private void setStateLocked(String inputId, int state, int userId) {
|
||||||
@@ -1003,22 +1012,8 @@ public final class TvInputManagerService extends SystemService {
|
|||||||
try {
|
try {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
final UserState userState = getOrCreateUserStateLocked(resolvedUserId);
|
final UserState userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||||
userState.callbackSet.add(callback);
|
if (!userState.mCallbacks.register(callback)) {
|
||||||
mDeathRecipient = new IBinder.DeathRecipient() {
|
Slog.e(TAG, "client process has already died");
|
||||||
@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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -1034,8 +1029,7 @@ public final class TvInputManagerService extends SystemService {
|
|||||||
try {
|
try {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
UserState userState = getOrCreateUserStateLocked(resolvedUserId);
|
UserState userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||||
userState.callbackSet.remove(callback);
|
userState.mCallbacks.unregister(callback);
|
||||||
callback.asBinder().unlinkToDeath(mDeathRecipient, 0);
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(identity);
|
Binder.restoreCallingIdentity(identity);
|
||||||
@@ -2104,11 +2098,13 @@ public final class TvInputManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
pw.decreaseIndent();
|
pw.decreaseIndent();
|
||||||
|
|
||||||
pw.println("callbackSet:");
|
pw.println("mCallbacks:");
|
||||||
pw.increaseIndent();
|
pw.increaseIndent();
|
||||||
for (ITvInputManagerCallback callback : userState.callbackSet) {
|
int n = userState.mCallbacks.beginBroadcast();
|
||||||
pw.println(callback.toString());
|
for (int j = 0; j < n; ++j) {
|
||||||
|
pw.println(userState.mCallbacks.getRegisteredCallbackItem(j).toString());
|
||||||
}
|
}
|
||||||
|
userState.mCallbacks.finishBroadcast();
|
||||||
pw.decreaseIndent();
|
pw.decreaseIndent();
|
||||||
|
|
||||||
pw.println("mainSessionToken: " + userState.mainSessionToken);
|
pw.println("mainSessionToken: " + userState.mainSessionToken);
|
||||||
@@ -2139,8 +2135,9 @@ public final class TvInputManagerService extends SystemService {
|
|||||||
// A mapping from the token of a TV input session to its state.
|
// A mapping from the token of a TV input session to its state.
|
||||||
private final Map<IBinder, SessionState> sessionStateMap = new HashMap<>();
|
private final Map<IBinder, SessionState> sessionStateMap = new HashMap<>();
|
||||||
|
|
||||||
// A set of callbacks.
|
// A list of callbacks.
|
||||||
private final Set<ITvInputManagerCallback> callbackSet = new HashSet<>();
|
private final RemoteCallbackList<ITvInputManagerCallback> mCallbacks =
|
||||||
|
new RemoteCallbackList<ITvInputManagerCallback>();
|
||||||
|
|
||||||
// The token of a "main" TV input session.
|
// The token of a "main" TV input session.
|
||||||
private IBinder mainSessionToken = null;
|
private IBinder mainSessionToken = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user