From 8675fc0c5dac4cc41cc202c668314dd67c5d86ef Mon Sep 17 00:00:00 2001 From: dingfeisong Date: Thu, 26 Sep 2024 11:08:17 +0800 Subject: [PATCH] Change TetheringManager#RequestDispatcher as static If the system GC does not recycle the RequestDispatcher objects in time, they will hold more contexts, which may lead to OutOfMemoryError. So change TetheringManager#RequestDispatcher as static. Bug:369730368 Change-Id: Ia67d8547bd2d239b5f939bd870761f2946afd43b Signed-off-by: dingfeisong --- .../src/android/net/TetheringManager.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Tethering/common/TetheringLib/src/android/net/TetheringManager.java b/Tethering/common/TetheringLib/src/android/net/TetheringManager.java index 7b769d49fe..b1489166d8 100644 --- a/Tethering/common/TetheringLib/src/android/net/TetheringManager.java +++ b/Tethering/common/TetheringLib/src/android/net/TetheringManager.java @@ -423,7 +423,7 @@ public class TetheringManager { // Used to dispatch legacy ConnectivityManager methods that expect tethering to be able to // return results and perform operations synchronously. // TODO: remove once there are no callers of these legacy methods. - private class RequestDispatcher { + private static class RequestDispatcher { private final ConditionVariable mWaiting; public volatile int mRemoteResult; @@ -439,8 +439,8 @@ public class TetheringManager { mWaiting = new ConditionVariable(); } - int waitForResult(final RequestHelper request) { - getConnector(c -> request.runRequest(c, mListener)); + int waitForResult(final RequestHelper request, final TetheringManager mgr) { + mgr.getConnector(c -> request.runRequest(c, mListener)); if (!mWaiting.block(DEFAULT_TIMEOUT_MS)) { throw new IllegalStateException("Callback timeout"); } @@ -596,7 +596,7 @@ public class TetheringManager { } catch (RemoteException e) { throw new IllegalStateException(e); } - }); + }, this); } /** @@ -628,7 +628,7 @@ public class TetheringManager { } catch (RemoteException e) { throw new IllegalStateException(e); } - }); + }, this); } /** @@ -656,7 +656,7 @@ public class TetheringManager { } catch (RemoteException e) { throw new IllegalStateException(e); } - }); + }, this); } /** @@ -1677,7 +1677,7 @@ public class TetheringManager { } catch (RemoteException e) { throw new IllegalStateException(e); } - }); + }, this); return ret == TETHER_ERROR_NO_ERROR; } @@ -1726,6 +1726,6 @@ public class TetheringManager { } catch (RemoteException e) { throw new IllegalStateException(e); } - }); + }, this); } }