Catch potential SecurityExceptions while binding

Do not allow SecurityExceptions to crash the system server.

Test: none
Change-Id: I951a20cca95801520168a2a27c87ee4e3609c9a0
This commit is contained in:
Soonil Nagarkar
2022-11-14 11:35:21 -08:00
parent 454d80ad81
commit a54902ca84

View File

@@ -206,16 +206,21 @@ class ServiceWatcherImpl<TBoundServiceInfo extends BoundServiceInfo> implements
Log.d(TAG, "[" + mTag + "] binding to " + mBoundServiceInfo);
}
mRebinder = null;
Intent bindIntent = new Intent(mBoundServiceInfo.getAction()).setComponent(
mBoundServiceInfo.getComponentName());
if (!mContext.bindServiceAsUser(bindIntent, this,
BIND_AUTO_CREATE | BIND_NOT_FOREGROUND | BIND_NOT_VISIBLE,
mHandler, UserHandle.of(mBoundServiceInfo.getUserId()))) {
Log.e(TAG, "[" + mTag + "] unexpected bind failure - retrying later");
mRebinder = this::bind;
mHandler.postDelayed(mRebinder, RETRY_DELAY_MS);
} else {
mRebinder = null;
try {
if (!mContext.bindServiceAsUser(bindIntent, this,
BIND_AUTO_CREATE | BIND_NOT_FOREGROUND | BIND_NOT_VISIBLE,
mHandler, UserHandle.of(mBoundServiceInfo.getUserId()))) {
Log.e(TAG, "[" + mTag + "] unexpected bind failure - retrying later");
mRebinder = this::bind;
mHandler.postDelayed(mRebinder, RETRY_DELAY_MS);
}
} catch (SecurityException e) {
// if anything goes wrong it shouldn't crash the system server
Log.e(TAG, "[" + mTag + "] " + mBoundServiceInfo + " bind failed", e);
}
}