Fix memory leak of ConnectivityManager

The instance of ConnectivityManager is static, and so its inner class
should be static to avoid the memory leak. Otherwise, the inner class
will get the reference to the mContext.

Bug:248184860

Signed-off-by: zhujiatai <zhujiatai@xiaomi.com>
Change-Id: I2c755f04a689f3e9e5f829d9be48765816257366
This commit is contained in:
zhujiatai
2022-09-22 15:44:02 +08:00
parent 98a35775cd
commit 79b0de9ef2

View File

@@ -4080,7 +4080,7 @@ public class ConnectivityManager {
}
}
private class CallbackHandler extends Handler {
private static class CallbackHandler extends Handler {
private static final String TAG = "ConnectivityManager.CallbackHandler";
private static final boolean DBG = false;
@@ -4095,7 +4095,10 @@ public class ConnectivityManager {
@Override
public void handleMessage(Message message) {
if (message.what == EXPIRE_LEGACY_REQUEST) {
expireRequest((NetworkCapabilities) message.obj, message.arg1);
// the sInstance can't be null because to send this message a ConnectivityManager
// instance must have been created prior to creating the thread on which this
// Handler is running.
sInstance.expireRequest((NetworkCapabilities) message.obj, message.arg1);
return;
}