Merge "Catch potential SecurityExceptions while binding"

This commit is contained in:
TreeHugger Robot
2022-11-15 00:15:33 +00:00
committed by Android (Google) Code Review

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);
}
}