Merge "Toast: Fix the concurrency problem of mAuthenticator"

This commit is contained in:
Dmitry Dementyev
2022-11-07 18:41:02 +00:00
committed by Gerrit Code Review

View File

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