Toast: Fix the concurrency problem of mAuthenticator

In terms of calling logic, there is concurrency when mAuthenticator is assigned,
which causes the phone to restart. We need to add a lock to protect him.

Bug: 256398179

Test: atest AccountManagerServiceTest

Signed-off-by: hupeng3 <hp121520@gmail.com>
Change-Id: I937f6e00c0ac7cca76f26b37a365b5f19171eac6
This commit is contained in:
Peng Hu
2022-10-24 10:52:56 +08:00
committed by hupeng3
parent 9e7649d5e7
commit 13389cd45f

View File

@@ -4794,6 +4794,7 @@ public class AccountManagerService
private abstract class Session extends IAccountAuthenticatorResponse.Stub
implements IBinder.DeathRecipient, ServiceConnection {
private final Object mSessionLock = new Object();
IAccountManagerResponse mResponse;
final String mAccountType;
final boolean mExpectActivityLaunch;
@@ -4959,9 +4960,11 @@ public class AccountManagerService
}
private void unbind() {
if (mAuthenticator != null) {
mAuthenticator = null;
mContext.unbindService(this);
synchronized (mSessionLock) {
if (mAuthenticator != null) {
mAuthenticator = null;
mContext.unbindService(this);
}
}
}
@@ -4971,12 +4974,14 @@ public class AccountManagerService
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mAuthenticator = IAccountAuthenticator.Stub.asInterface(service);
try {
run();
} catch (RemoteException e) {
onError(AccountManager.ERROR_CODE_REMOTE_EXCEPTION,
"remote exception");
synchronized (mSessionLock) {
mAuthenticator = IAccountAuthenticator.Stub.asInterface(service);
try {
run();
} catch (RemoteException e) {
onError(AccountManager.ERROR_CODE_REMOTE_EXCEPTION,
"remote exception");
}
}
}