diff options
author | Hall Liu <hallliu@google.com> | 2020-05-13 18:32:20 -0700 |
---|---|---|
committer | Hall Liu <hallliu@google.com> | 2020-05-14 01:43:16 +0000 |
commit | 4fdcab4996fe96b1ec28c28f8985c4be11ec2701 (patch) | |
tree | a4c03ee78176ca6996ef343e2f8b5bb0313ce8f0 /tests/telephonytests | |
parent | ebc187d0e03046e9607c2fcbe5fcbe23d394e577 (diff) | |
download | telephony-4fdcab4996fe96b1ec28c28f8985c4be11ec2701.tar.gz |
Fix various thread and memory leaks
Fix several places in Telephony tests where threads were being leaked.
Also remove telephony tests from TestableLooper during teardown in order
to avoid a memory leak.
Fixes: 156287358
Test: atest FrameworksTelephonyTests
Change-Id: I89cae577965db9d912a979627bcd8175159d7d72
Diffstat (limited to 'tests/telephonytests')
9 files changed, 22 insertions, 4 deletions
diff --git a/tests/telephonytests/src/com/android/internal/telephony/CellularNetworkServiceTest.java b/tests/telephonytests/src/com/android/internal/telephony/CellularNetworkServiceTest.java index f80cf04b73..e2bacc24bf 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/CellularNetworkServiceTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/CellularNetworkServiceTest.java @@ -89,6 +89,9 @@ public class CellularNetworkServiceTest extends TelephonyTest { @After public void tearDown() throws Exception { + if (mCellularNetworkService != null) { + mCellularNetworkService.onDestroy(); + } super.tearDown(); } diff --git a/tests/telephonytests/src/com/android/internal/telephony/RILTest.java b/tests/telephonytests/src/com/android/internal/telephony/RILTest.java index 716d834555..8dcff0fa0e 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/RILTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/RILTest.java @@ -312,6 +312,8 @@ public class RILTest extends TelephonyTest { @After public void tearDown() throws Exception { + mRILUnderTest.mWakeLock.release(); + mRILUnderTest.mAckWakeLock.release(); super.tearDown(); } diff --git a/tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java b/tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java index 3b47f7f3e6..cc7c8e904f 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java @@ -334,6 +334,9 @@ public class ServiceStateTrackerTest extends TelephonyTest { sst = null; mSSTTestHandler.quit(); mSSTTestHandler.join(); + if (mCellularNetworkService != null) { + mCellularNetworkService.onDestroy(); + } super.tearDown(); } diff --git a/tests/telephonytests/src/com/android/internal/telephony/SmsDispatchersControllerTest.java b/tests/telephonytests/src/com/android/internal/telephony/SmsDispatchersControllerTest.java index 2117238c3e..90ec3d5865 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/SmsDispatchersControllerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/SmsDispatchersControllerTest.java @@ -64,6 +64,7 @@ public class SmsDispatchersControllerTest extends TelephonyTest { @After public void tearDown() throws Exception { + mSmsDispatchersController.dispose(); mSmsDispatchersController = null; super.tearDown(); } diff --git a/tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java b/tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java index 4d65f69691..7c0bdd9a3c 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java @@ -699,6 +699,7 @@ public abstract class TelephonyTest { for (TestableLooper looper : mTestableLoopers) { looper.destroy(); } + TestableLooper.remove(TelephonyTest.this); mSimulatedCommands.dispose(); SharedPreferences sharedPreferences = mContext.getSharedPreferences((String) null, 0); diff --git a/tests/telephonytests/src/com/android/internal/telephony/dataconnection/DataConnectionTest.java b/tests/telephonytests/src/com/android/internal/telephony/dataconnection/DataConnectionTest.java index 9dc73819b4..e79bdfdf22 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/dataconnection/DataConnectionTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/dataconnection/DataConnectionTest.java @@ -99,6 +99,7 @@ public class DataConnectionTest extends TelephonyTest { private DataConnection mDc; private DataConnectionTestHandler mDataConnectionTestHandler; private DcController mDcc; + private CellularDataService mCellularDataService; private ApnSetting mApn1 = ApnSetting.makeApnSetting( 2163, // id @@ -261,7 +262,7 @@ public class DataConnectionTest extends TelephonyTest { } private void addDataService() { - CellularDataService cellularDataService = new CellularDataService(); + mCellularDataService = new CellularDataService(); ServiceInfo serviceInfo = new ServiceInfo(); serviceInfo.packageName = "com.android.phone"; serviceInfo.permission = "android.permission.BIND_TELEPHONY_DATA_SERVICE"; @@ -270,7 +271,7 @@ public class DataConnectionTest extends TelephonyTest { DataService.SERVICE_INTERFACE, null, "com.android.phone", - cellularDataService.mBinder, + mCellularDataService.mBinder, serviceInfo, filter); } @@ -323,6 +324,7 @@ public class DataConnectionTest extends TelephonyTest { mDcc = null; mDataConnectionTestHandler.quit(); mDataConnectionTestHandler.join(); + mCellularDataService.onDestroy(); super.tearDown(); } diff --git a/tests/telephonytests/src/com/android/internal/telephony/dataconnection/DcTrackerTest.java b/tests/telephonytests/src/com/android/internal/telephony/dataconnection/DcTrackerTest.java index 8ac4d1a688..3bcf99f85a 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/dataconnection/DcTrackerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/dataconnection/DcTrackerTest.java @@ -164,8 +164,10 @@ public class DcTrackerTest extends TelephonyTest { private Message mMessage; + private CellularDataService mCellularDataService; + private void addDataService() { - CellularDataService cellularDataService = new CellularDataService(); + mCellularDataService = new CellularDataService(); ServiceInfo serviceInfo = new ServiceInfo(); serviceInfo.packageName = "com.android.phone"; serviceInfo.permission = "android.permission.BIND_TELEPHONY_DATA_SERVICE"; @@ -174,7 +176,7 @@ public class DcTrackerTest extends TelephonyTest { DataService.SERVICE_INTERFACE, null, "com.android.phone", - cellularDataService.mBinder, + mCellularDataService.mBinder, serviceInfo, filter); } @@ -539,9 +541,11 @@ public class DcTrackerTest extends TelephonyTest { public void tearDown() throws Exception { logd("DcTrackerTest -tearDown"); mDct.removeCallbacksAndMessages(null); + mDct.stopHandlerThread(); mDct = null; mDcTrackerTestHandler.quit(); mDcTrackerTestHandler.join(); + mCellularDataService.onDestroy(); waitForMs(100); super.tearDown(); } diff --git a/tests/telephonytests/src/com/android/internal/telephony/gsm/GsmInboundSmsHandlerTest.java b/tests/telephonytests/src/com/android/internal/telephony/gsm/GsmInboundSmsHandlerTest.java index 411738ae37..552b548174 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/gsm/GsmInboundSmsHandlerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/gsm/GsmInboundSmsHandlerTest.java @@ -249,6 +249,7 @@ public class GsmInboundSmsHandlerTest extends TelephonyTest { i++; } assertFalse(mGsmInboundSmsHandler.getWakeLock().isHeld()); + mGsmInboundSmsHandler.quit(); mGsmInboundSmsHandler = null; mContentProvider.shutdown(); super.tearDown(); diff --git a/tests/telephonytests/src/com/android/internal/telephony/ims/ImsManagerTest.java b/tests/telephonytests/src/com/android/internal/telephony/ims/ImsManagerTest.java index f09140eb72..7088024e2b 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/ims/ImsManagerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/ims/ImsManagerTest.java @@ -873,6 +873,7 @@ public class ImsManagerTest extends TelephonyTest { fail("failed with " + ex); } + ((ImsManager.ImsExecutorFactory) imsManager.mExecutorFactory).destroy(); imsManager.mExecutorFactory = Runnable::run; return imsManager; |