Merge "(Re-Introduce locking)[TEMP] Re-Introduce synchronization locking" am: 14087b39d1 am: b646fcd689

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2036103

Change-Id: Iee40ad7958f8ff75395d89a0c7a713e238759598
This commit is contained in:
Virkumar Karavate
2022-03-23 12:41:06 +00:00
committed by Automerger Merge Worker
3 changed files with 167 additions and 126 deletions

View File

@@ -375,12 +375,16 @@ public abstract class ImsFeature {
*/ */
@SystemApi @SystemApi
public final void setFeatureState(@ImsState int state) { public final void setFeatureState(@ImsState int state) {
boolean isNotify = false;
synchronized (mLock) { synchronized (mLock) {
if (mState != state) { if (mState != state) {
mState = state; mState = state;
notifyFeatureState(state); isNotify = true;
} }
} }
if (isNotify) {
notifyFeatureState(state);
}
} }
/** /**
@@ -412,6 +416,7 @@ public abstract class ImsFeature {
* Internal method called by ImsFeature when setFeatureState has changed. * Internal method called by ImsFeature when setFeatureState has changed.
*/ */
private void notifyFeatureState(@ImsState int state) { private void notifyFeatureState(@ImsState int state) {
synchronized (mStatusCallbacks) {
mStatusCallbacks.broadcastAction((c) -> { mStatusCallbacks.broadcastAction((c) -> {
try { try {
c.notifyImsFeatureStatus(state); c.notifyImsFeatureStatus(state);
@@ -421,6 +426,7 @@ public abstract class ImsFeature {
} }
}); });
} }
}
/** /**
* @hide * @hide
@@ -491,8 +497,12 @@ public abstract class ImsFeature {
synchronized (mLock) { synchronized (mLock) {
mCapabilityStatus = caps.copy(); mCapabilityStatus = caps.copy();
} }
synchronized (mCapabilityCallbacks) {
mCapabilityCallbacks.broadcastAction((callback) -> { mCapabilityCallbacks.broadcastAction((callback) -> {
try { try {
Log.d(LOG_TAG, "ImsFeature notifyCapabilitiesStatusChanged Capabilities = "
+ caps.mCapabilities);
callback.onCapabilitiesStatusChanged(caps.mCapabilities); callback.onCapabilitiesStatusChanged(caps.mCapabilities);
} catch (RemoteException e) { } catch (RemoteException e) {
Log.w(LOG_TAG, e + " notifyCapabilitiesStatusChanged() - Skipping " Log.w(LOG_TAG, e + " notifyCapabilitiesStatusChanged() - Skipping "
@@ -500,6 +510,7 @@ public abstract class ImsFeature {
} }
}); });
} }
}
/** /**
* Provides the ImsFeature with the ability to return the framework Capability Configuration * Provides the ImsFeature with the ability to return the framework Capability Configuration

View File

@@ -587,6 +587,7 @@ public class ImsConfigImplBase {
if (mCallbacks == null) { if (mCallbacks == null) {
return; return;
} }
synchronized (mCallbacks) {
mCallbacks.broadcastAction(c -> { mCallbacks.broadcastAction(c -> {
try { try {
c.onIntConfigChanged(item, value); c.onIntConfigChanged(item, value);
@@ -595,12 +596,14 @@ public class ImsConfigImplBase {
} }
}); });
} }
}
private void notifyConfigChanged(int item, String value) { private void notifyConfigChanged(int item, String value) {
// can be null in testing // can be null in testing
if (mCallbacks == null) { if (mCallbacks == null) {
return; return;
} }
synchronized (mCallbacks) {
mCallbacks.broadcastAction(c -> { mCallbacks.broadcastAction(c -> {
try { try {
c.onStringConfigChanged(item, value); c.onStringConfigChanged(item, value);
@@ -609,6 +612,7 @@ public class ImsConfigImplBase {
} }
}); });
} }
}
private void addRcsConfigCallback(IRcsConfigCallback c) { private void addRcsConfigCallback(IRcsConfigCallback c) {
mRcsCallbacks.register(c); mRcsCallbacks.register(c);
@@ -635,6 +639,7 @@ public class ImsConfigImplBase {
// can be null in testing // can be null in testing
if (mRcsCallbacks != null) { if (mRcsCallbacks != null) {
synchronized (mRcsCallbacks) {
mRcsCallbacks.broadcastAction(c -> { mRcsCallbacks.broadcastAction(c -> {
try { try {
c.onConfigurationChanged(mRcsConfigData); c.onConfigurationChanged(mRcsConfigData);
@@ -643,12 +648,14 @@ public class ImsConfigImplBase {
} }
}); });
} }
}
notifyRcsAutoConfigurationReceived(config, isCompressed); notifyRcsAutoConfigurationReceived(config, isCompressed);
} }
private void onNotifyRcsAutoConfigurationRemoved() { private void onNotifyRcsAutoConfigurationRemoved() {
mRcsConfigData = null; mRcsConfigData = null;
if (mRcsCallbacks != null) { if (mRcsCallbacks != null) {
synchronized (mRcsCallbacks) {
mRcsCallbacks.broadcastAction(c -> { mRcsCallbacks.broadcastAction(c -> {
try { try {
c.onConfigurationReset(); c.onConfigurationReset();
@@ -657,6 +664,7 @@ public class ImsConfigImplBase {
} }
}); });
} }
}
notifyRcsAutoConfigurationRemoved(); notifyRcsAutoConfigurationRemoved();
} }
@@ -801,6 +809,7 @@ public class ImsConfigImplBase {
if (mRcsCallbacks == null) { if (mRcsCallbacks == null) {
return; return;
} }
synchronized (mRcsCallbacks) {
mRcsCallbacks.broadcastAction(c -> { mRcsCallbacks.broadcastAction(c -> {
try { try {
c.onAutoConfigurationErrorReceived(errorCode, errorString); c.onAutoConfigurationErrorReceived(errorCode, errorString);
@@ -809,6 +818,7 @@ public class ImsConfigImplBase {
} }
}); });
} }
}
/** /**
* Notifies application that pre-provisioning config is received. * Notifies application that pre-provisioning config is received.
@@ -825,6 +835,7 @@ public class ImsConfigImplBase {
if (mRcsCallbacks == null) { if (mRcsCallbacks == null) {
return; return;
} }
synchronized (mRcsCallbacks) {
mRcsCallbacks.broadcastAction(c -> { mRcsCallbacks.broadcastAction(c -> {
try { try {
c.onPreProvisioningReceived(configXml); c.onPreProvisioningReceived(configXml);
@@ -833,6 +844,7 @@ public class ImsConfigImplBase {
} }
}); });
} }
}
/** /**
* Set default Executor from ImsService. * Set default Executor from ImsService.

View File

@@ -219,12 +219,16 @@ public class ImsSmsImplBase {
*/ */
public final void onSmsReceived(int token, @SmsMessage.Format String format, byte[] pdu) public final void onSmsReceived(int token, @SmsMessage.Format String format, byte[] pdu)
throws RuntimeException { throws RuntimeException {
IImsSmsListener listener = null;
synchronized (mLock) { synchronized (mLock) {
if (mListener == null) { listener = mListener;
}
if (listener == null) {
throw new RuntimeException("Feature not ready."); throw new RuntimeException("Feature not ready.");
} }
try { try {
mListener.onSmsReceived(token, format, pdu); listener.onSmsReceived(token, format, pdu);
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(LOG_TAG, "Can not deliver sms: " + e.getMessage()); Log.e(LOG_TAG, "Can not deliver sms: " + e.getMessage());
SmsMessage message = SmsMessage.createFromPdu(pdu, format); SmsMessage message = SmsMessage.createFromPdu(pdu, format);
@@ -237,7 +241,6 @@ public class ImsSmsImplBase {
} }
} }
} }
}
/** /**
* This method should be triggered by the IMS providers when an outgoing SMS message has been * This method should be triggered by the IMS providers when an outgoing SMS message has been
@@ -254,18 +257,21 @@ public class ImsSmsImplBase {
*/ */
public final void onSendSmsResultSuccess(int token, public final void onSendSmsResultSuccess(int token,
@IntRange(from = 0, to = 65535) int messageRef) throws RuntimeException { @IntRange(from = 0, to = 65535) int messageRef) throws RuntimeException {
IImsSmsListener listener = null;
synchronized (mLock) { synchronized (mLock) {
if (mListener == null) { listener = mListener;
}
if (listener == null) {
throw new RuntimeException("Feature not ready."); throw new RuntimeException("Feature not ready.");
} }
try { try {
mListener.onSendSmsResult(token, messageRef, SEND_STATUS_OK, listener.onSendSmsResult(token, messageRef, SEND_STATUS_OK,
SmsManager.RESULT_ERROR_NONE, RESULT_NO_NETWORK_ERROR); SmsManager.RESULT_ERROR_NONE, RESULT_NO_NETWORK_ERROR);
} catch (RemoteException e) { } catch (RemoteException e) {
e.rethrowFromSystemServer(); e.rethrowFromSystemServer();
} }
} }
}
/** /**
* This method should be triggered by the IMS providers to pass the result of the sent message * This method should be triggered by the IMS providers to pass the result of the sent message
@@ -288,18 +294,21 @@ public class ImsSmsImplBase {
@Deprecated @Deprecated
public final void onSendSmsResult(int token, @IntRange(from = 0, to = 65535) int messageRef, public final void onSendSmsResult(int token, @IntRange(from = 0, to = 65535) int messageRef,
@SendStatusResult int status, @SmsManager.Result int reason) throws RuntimeException { @SendStatusResult int status, @SmsManager.Result int reason) throws RuntimeException {
IImsSmsListener listener = null;
synchronized (mLock) { synchronized (mLock) {
if (mListener == null) { listener = mListener;
}
if (listener == null) {
throw new RuntimeException("Feature not ready."); throw new RuntimeException("Feature not ready.");
} }
try { try {
mListener.onSendSmsResult(token, messageRef, status, reason, listener.onSendSmsResult(token, messageRef, status, reason,
RESULT_NO_NETWORK_ERROR); RESULT_NO_NETWORK_ERROR);
} catch (RemoteException e) { } catch (RemoteException e) {
e.rethrowFromSystemServer(); e.rethrowFromSystemServer();
} }
} }
}
/** /**
* This method should be triggered by the IMS providers when an outgoing message fails to be * This method should be triggered by the IMS providers when an outgoing message fails to be
@@ -322,17 +331,20 @@ public class ImsSmsImplBase {
public final void onSendSmsResultError(int token, public final void onSendSmsResultError(int token,
@IntRange(from = 0, to = 65535) int messageRef, @SendStatusResult int status, @IntRange(from = 0, to = 65535) int messageRef, @SendStatusResult int status,
@SmsManager.Result int reason, int networkErrorCode) throws RuntimeException { @SmsManager.Result int reason, int networkErrorCode) throws RuntimeException {
IImsSmsListener listener = null;
synchronized (mLock) { synchronized (mLock) {
if (mListener == null) { listener = mListener;
}
if (listener == null) {
throw new RuntimeException("Feature not ready."); throw new RuntimeException("Feature not ready.");
} }
try { try {
mListener.onSendSmsResult(token, messageRef, status, reason, networkErrorCode); listener.onSendSmsResult(token, messageRef, status, reason, networkErrorCode);
} catch (RemoteException e) { } catch (RemoteException e) {
e.rethrowFromSystemServer(); e.rethrowFromSystemServer();
} }
} }
}
/** /**
* This method should be triggered by the IMS providers when the status report of the sent * This method should be triggered by the IMS providers when the status report of the sent
@@ -357,18 +369,21 @@ public class ImsSmsImplBase {
public final void onSmsStatusReportReceived(int token, public final void onSmsStatusReportReceived(int token,
@IntRange(from = 0, to = 65535) int messageRef, @SmsMessage.Format String format, @IntRange(from = 0, to = 65535) int messageRef, @SmsMessage.Format String format,
byte[] pdu) throws RuntimeException { byte[] pdu) throws RuntimeException {
IImsSmsListener listener = null;
synchronized (mLock) { synchronized (mLock) {
if (mListener == null) { listener = mListener;
}
if (listener == null) {
throw new RuntimeException("Feature not ready."); throw new RuntimeException("Feature not ready.");
} }
try { try {
mListener.onSmsStatusReportReceived(token, format, pdu); listener.onSmsStatusReportReceived(token, format, pdu);
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(LOG_TAG, "Can not process sms status report: " + e.getMessage()); Log.e(LOG_TAG, "Can not process sms status report: " + e.getMessage());
acknowledgeSmsReport(token, messageRef, STATUS_REPORT_STATUS_ERROR); acknowledgeSmsReport(token, messageRef, STATUS_REPORT_STATUS_ERROR);
} }
} }
}
/** /**
* This method should be triggered by the IMS providers when the status report of the sent * This method should be triggered by the IMS providers when the status report of the sent
@@ -386,12 +401,16 @@ public class ImsSmsImplBase {
*/ */
public final void onSmsStatusReportReceived(int token, @SmsMessage.Format String format, public final void onSmsStatusReportReceived(int token, @SmsMessage.Format String format,
byte[] pdu) throws RuntimeException { byte[] pdu) throws RuntimeException {
IImsSmsListener listener = null;
synchronized (mLock) { synchronized (mLock) {
if (mListener == null) { listener = mListener;
}
if (listener == null) {
throw new RuntimeException("Feature not ready."); throw new RuntimeException("Feature not ready.");
} }
try { try {
mListener.onSmsStatusReportReceived(token, format, pdu); listener.onSmsStatusReportReceived(token, format, pdu);
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(LOG_TAG, "Can not process sms status report: " + e.getMessage()); Log.e(LOG_TAG, "Can not process sms status report: " + e.getMessage());
SmsMessage message = SmsMessage.createFromPdu(pdu, format); SmsMessage message = SmsMessage.createFromPdu(pdu, format);
@@ -406,7 +425,6 @@ public class ImsSmsImplBase {
} }
} }
} }
}
/** /**
* Returns the SMS format that the ImsService expects. * Returns the SMS format that the ImsService expects.