Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a54902ca authored by Soonil Nagarkar's avatar Soonil Nagarkar
Browse files

Catch potential SecurityExceptions while binding

Do not allow SecurityExceptions to crash the system server.

Test: none
Change-Id: I951a20cca95801520168a2a27c87ee4e3609c9a0
parent 454d80ad
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -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());
            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);
            } else {
                mRebinder = null;
                }
            } catch (SecurityException e) {
                // if anything goes wrong it shouldn't crash the system server
                Log.e(TAG, "[" + mTag + "] " + mBoundServiceInfo + " bind failed", e);
            }
        }