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

Commit 6d3d2904 authored by Sihua Ma's avatar Sihua Ma
Browse files

Wrap service connection in try-catch block

Exceptions might be thrown when binding/unbinding to the service which
should be handled to avoid crash.

Test: Manual
Bug: 389127703
Flag: EXEMPT bug fix
Change-Id: I6231733a9b59235612d1e9b8e6b6ed4995126600
parent 34303f98
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -1684,10 +1684,14 @@ public class AppWidgetManager {
            private IBinder mIBinder;

            ConnectionTask(@NonNull FilterComparison filter) {
                try {
                    mContext.bindService(filter.getIntent(),
                            Context.BindServiceFlags.of(Context.BIND_AUTO_CREATE),
                            mHandler::post,
                            this);
                } catch (Exception e) {
                    Log.e(TAG, "Error connecting to service in connection cache", e);
                }
            }

            @Override
@@ -1737,7 +1741,11 @@ public class AppWidgetManager {
                    handleNext();
                    return;
                }
                try {
                    mContext.unbindService(this);
                } catch (Exception e) {
                    Log.e(TAG, "Error unbinding the cached connection", e);
                }
                mActiveConnections.values().remove(this);
            }
        }