Refine WifiTetherSoftApManager and DataSaverBackend to avoid activity leaks

- Declare the service callback as static class and use WeakReference to avoid the callback link being occupied

- Use application context instead of fragment context to avoid context being occupied by external modules

Bug: 237273138
Test: manual test
make RunSettingsRoboTests ROBOTEST_FILTER=TetherSettingsTest
make RunSettingsRoboTests ROBOTEST_FILTER=WifiTetherPreferenceControllerTest

Change-Id: Icca145b8ef08b9949feafbbd4e761f8d50c99181
This commit is contained in:
Weng Su
2022-09-13 21:47:50 +08:00
parent aea2e7cd2e
commit 2f55ae15f1
3 changed files with 47 additions and 16 deletions

View File

@@ -56,8 +56,9 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
WifiTetherSoftApManager mWifiTetherSoftApManager;
public WifiTetherPreferenceController(Context context, Lifecycle lifecycle) {
// TODO(b/246537032):Use fragment context to WifiManager service will caused memory leak
this(context, lifecycle,
context.getSystemService(WifiManager.class),
context.getApplicationContext().getSystemService(WifiManager.class),
context.getSystemService(TetheringManager.class),
true /* initSoftApManager */,
WifiEnterpriseRestrictionUtils.isWifiTetheringAllowed(context));