Merge "Do not use hidden broadcast API of RemoteCallbackList"
This commit is contained in:
committed by
Android (Google) Code Review
commit
bdf260dd90
@@ -22,7 +22,6 @@ import android.annotation.SystemApi;
|
||||
import android.annotation.TestApi;
|
||||
import android.content.Context;
|
||||
import android.os.IInterface;
|
||||
import android.os.RemoteCallbackList;
|
||||
import android.os.RemoteException;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.ims.aidl.IImsCapabilityCallback;
|
||||
@@ -31,6 +30,7 @@ import android.util.Log;
|
||||
|
||||
import com.android.ims.internal.IImsFeatureStatusCallback;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.telephony.util.RemoteCallbackListExt;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -310,12 +310,12 @@ public abstract class ImsFeature {
|
||||
/** @hide */
|
||||
protected final Object mLock = new Object();
|
||||
|
||||
private final RemoteCallbackList<IImsFeatureStatusCallback> mStatusCallbacks =
|
||||
new RemoteCallbackList<>();
|
||||
private final RemoteCallbackListExt<IImsFeatureStatusCallback> mStatusCallbacks =
|
||||
new RemoteCallbackListExt<>();
|
||||
private @ImsState int mState = STATE_UNAVAILABLE;
|
||||
private int mSlotId = SubscriptionManager.INVALID_SIM_SLOT_INDEX;
|
||||
private final RemoteCallbackList<IImsCapabilityCallback> mCapabilityCallbacks =
|
||||
new RemoteCallbackList<>();
|
||||
private final RemoteCallbackListExt<IImsCapabilityCallback> mCapabilityCallbacks =
|
||||
new RemoteCallbackListExt<>();
|
||||
private Capabilities mCapabilityStatus = new Capabilities();
|
||||
|
||||
/**
|
||||
@@ -391,7 +391,7 @@ public abstract class ImsFeature {
|
||||
* Internal method called by ImsFeature when setFeatureState has changed.
|
||||
*/
|
||||
private void notifyFeatureState(@ImsState int state) {
|
||||
mStatusCallbacks.broadcast((c) -> {
|
||||
mStatusCallbacks.broadcastAction((c) -> {
|
||||
try {
|
||||
c.notifyImsFeatureStatus(state);
|
||||
} catch (RemoteException e) {
|
||||
@@ -470,7 +470,7 @@ public abstract class ImsFeature {
|
||||
synchronized (mLock) {
|
||||
mCapabilityStatus = caps.copy();
|
||||
}
|
||||
mCapabilityCallbacks.broadcast((callback) -> {
|
||||
mCapabilityCallbacks.broadcastAction((callback) -> {
|
||||
try {
|
||||
callback.onCapabilitiesStatusChanged(caps.mCapabilities);
|
||||
} catch (RemoteException e) {
|
||||
|
||||
@@ -21,7 +21,6 @@ import android.annotation.SystemApi;
|
||||
import android.annotation.TestApi;
|
||||
import android.content.Context;
|
||||
import android.os.PersistableBundle;
|
||||
import android.os.RemoteCallbackList;
|
||||
import android.os.RemoteException;
|
||||
import android.telephony.ims.aidl.IImsConfig;
|
||||
import android.telephony.ims.aidl.IImsConfigCallback;
|
||||
@@ -29,6 +28,7 @@ import android.util.Log;
|
||||
|
||||
import com.android.ims.ImsConfig;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.telephony.util.RemoteCallbackListExt;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -248,7 +248,8 @@ public class ImsConfigImplBase {
|
||||
})
|
||||
public @interface SetConfigResult {}
|
||||
|
||||
private final RemoteCallbackList<IImsConfigCallback> mCallbacks = new RemoteCallbackList<>();
|
||||
private final RemoteCallbackListExt<IImsConfigCallback> mCallbacks =
|
||||
new RemoteCallbackListExt<>();
|
||||
ImsConfigStub mImsConfigStub;
|
||||
|
||||
/**
|
||||
@@ -289,7 +290,7 @@ public class ImsConfigImplBase {
|
||||
if (mCallbacks == null) {
|
||||
return;
|
||||
}
|
||||
mCallbacks.broadcast(c -> {
|
||||
mCallbacks.broadcastAction(c -> {
|
||||
try {
|
||||
c.onIntConfigChanged(item, value);
|
||||
} catch (RemoteException e) {
|
||||
@@ -303,7 +304,7 @@ public class ImsConfigImplBase {
|
||||
if (mCallbacks == null) {
|
||||
return;
|
||||
}
|
||||
mCallbacks.broadcast(c -> {
|
||||
mCallbacks.broadcastAction(c -> {
|
||||
try {
|
||||
c.onStringConfigChanged(item, value);
|
||||
} catch (RemoteException e) {
|
||||
|
||||
@@ -20,7 +20,6 @@ import android.annotation.IntDef;
|
||||
import android.annotation.SystemApi;
|
||||
import android.annotation.TestApi;
|
||||
import android.net.Uri;
|
||||
import android.os.RemoteCallbackList;
|
||||
import android.os.RemoteException;
|
||||
import android.telephony.ims.ImsReasonInfo;
|
||||
import android.telephony.ims.RegistrationManager;
|
||||
@@ -29,6 +28,7 @@ import android.telephony.ims.aidl.IImsRegistrationCallback;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.telephony.util.RemoteCallbackListExt;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -94,8 +94,8 @@ public class ImsRegistrationImplBase {
|
||||
}
|
||||
};
|
||||
|
||||
private final RemoteCallbackList<IImsRegistrationCallback> mCallbacks
|
||||
= new RemoteCallbackList<>();
|
||||
private final RemoteCallbackListExt<IImsRegistrationCallback> mCallbacks =
|
||||
new RemoteCallbackListExt<>();
|
||||
private final Object mLock = new Object();
|
||||
// Locked on mLock
|
||||
private @ImsRegistrationTech
|
||||
@@ -129,7 +129,7 @@ public class ImsRegistrationImplBase {
|
||||
*/
|
||||
public final void onRegistered(@ImsRegistrationTech int imsRadioTech) {
|
||||
updateToState(imsRadioTech, RegistrationManager.REGISTRATION_STATE_REGISTERED);
|
||||
mCallbacks.broadcast((c) -> {
|
||||
mCallbacks.broadcastAction((c) -> {
|
||||
try {
|
||||
c.onRegistered(imsRadioTech);
|
||||
} catch (RemoteException e) {
|
||||
@@ -147,7 +147,7 @@ public class ImsRegistrationImplBase {
|
||||
*/
|
||||
public final void onRegistering(@ImsRegistrationTech int imsRadioTech) {
|
||||
updateToState(imsRadioTech, RegistrationManager.REGISTRATION_STATE_REGISTERING);
|
||||
mCallbacks.broadcast((c) -> {
|
||||
mCallbacks.broadcastAction((c) -> {
|
||||
try {
|
||||
c.onRegistering(imsRadioTech);
|
||||
} catch (RemoteException e) {
|
||||
@@ -175,7 +175,7 @@ public class ImsRegistrationImplBase {
|
||||
*/
|
||||
public final void onDeregistered(ImsReasonInfo info) {
|
||||
updateToDisconnectedState(info);
|
||||
mCallbacks.broadcast((c) -> {
|
||||
mCallbacks.broadcastAction((c) -> {
|
||||
try {
|
||||
c.onDeregistered(info);
|
||||
} catch (RemoteException e) {
|
||||
@@ -194,7 +194,7 @@ public class ImsRegistrationImplBase {
|
||||
*/
|
||||
public final void onTechnologyChangeFailed(@ImsRegistrationTech int imsRadioTech,
|
||||
ImsReasonInfo info) {
|
||||
mCallbacks.broadcast((c) -> {
|
||||
mCallbacks.broadcastAction((c) -> {
|
||||
try {
|
||||
c.onTechnologyChangeFailed(imsRadioTech, info);
|
||||
} catch (RemoteException e) {
|
||||
@@ -210,7 +210,7 @@ public class ImsRegistrationImplBase {
|
||||
* @param uris
|
||||
*/
|
||||
public final void onSubscriberAssociatedUriChanged(Uri[] uris) {
|
||||
mCallbacks.broadcast((c) -> {
|
||||
mCallbacks.broadcastAction((c) -> {
|
||||
try {
|
||||
c.onSubscriberAssociatedUriChanged(uris);
|
||||
} catch (RemoteException e) {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.internal.telephony.util;
|
||||
|
||||
import android.os.IInterface;
|
||||
import android.os.RemoteCallbackList;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Extension of RemoteCallbackList
|
||||
* @param <E> defines the type of registered callbacks
|
||||
*/
|
||||
public class RemoteCallbackListExt<E extends IInterface> extends RemoteCallbackList<E> {
|
||||
/**
|
||||
* Performs {@code action} on each callback, calling
|
||||
* {@link RemoteCallbackListExt#beginBroadcast()}
|
||||
* /{@link RemoteCallbackListExt#finishBroadcast()} before/after looping
|
||||
* @param action to be performed on each callback
|
||||
*
|
||||
*/
|
||||
public void broadcastAction(Consumer<E> action) {
|
||||
int itemCount = beginBroadcast();
|
||||
try {
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
action.accept(getBroadcastItem(i));
|
||||
}
|
||||
} finally {
|
||||
finishBroadcast();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user