Don't return null in the default ActivityManagerService.Injector.
Usually with injectors like these, we are expected to use methods
provided by these instead of directly accessing the fields, so just
returning "null" in Injector.getContext() is counterintuitive and
ideally other callsites which are directly accessing mContext should
be updated to use injector provided one instead.
Bug: 138952436
Test: atest services/tests/servicestests/src/com/android/server/am/ActivityManagerServiceTest.java
Test: atest services/tests/mockingservicestests/src/com/android/server/am/AppCompactorTest.java
Test: atest services/tests/servicestests/src/com/android/server/am/AppErrorDialogTest.java
Change-Id: Idb7cb9a5b7c4c0d237ece9716932a260956a0109
diff --git a/services/tests/servicestests/src/com/android/server/am/ActivityManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/am/ActivityManagerServiceTest.java
index 8a1f046..29244f0 100644
--- a/services/tests/servicestests/src/com/android/server/am/ActivityManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/am/ActivityManagerServiceTest.java
@@ -133,7 +133,7 @@
mHandlerThread = new HandlerThread(TAG);
mHandlerThread.start();
mHandler = new TestHandler(mHandlerThread.getLooper());
- mInjector = new TestInjector();
+ mInjector = new TestInjector(mContext);
mAms = new ActivityManagerService(mInjector, mServiceThreadRule.getThread());
mAms.mWaitForNetworkTimeoutMs = 2000;
mAms.mActivityTaskManager = new ActivityTaskManagerService(mContext);
@@ -920,9 +920,8 @@
private class TestInjector extends Injector {
private boolean mRestricted = true;
- @Override
- public Context getContext() {
- return mContext;
+ TestInjector(Context context) {
+ super(context);
}
@Override
diff --git a/services/tests/servicestests/src/com/android/server/am/AppErrorDialogTest.java b/services/tests/servicestests/src/com/android/server/am/AppErrorDialogTest.java
index 87cc0ff..377bfd1 100644
--- a/services/tests/servicestests/src/com/android/server/am/AppErrorDialogTest.java
+++ b/services/tests/servicestests/src/com/android/server/am/AppErrorDialogTest.java
@@ -51,7 +51,7 @@
@Before
public void setUp() throws Exception {
mContext = getInstrumentation().getTargetContext();
- mService = new ActivityManagerService(new ActivityManagerService.Injector() {
+ mService = new ActivityManagerService(new ActivityManagerService.Injector(mContext) {
@Override
public AppOpsService getAppOpsService(File file, Handler handler) {
return null;
@@ -66,11 +66,6 @@
public boolean isNetworkRestrictedForUid(int uid) {
return false;
}
-
- @Override
- public Context getContext() {
- return mContext;
- }
}, mServiceThreadRule.getThread());
mService.mActivityTaskManager = new ActivityTaskManagerService(mContext);
mService.mActivityTaskManager.initialize(null, null, mContext.getMainLooper());
diff --git a/services/tests/servicestests/src/com/android/server/am/CoreSettingsObserverTest.java b/services/tests/servicestests/src/com/android/server/am/CoreSettingsObserverTest.java
index 1eb02ad..5463291 100644
--- a/services/tests/servicestests/src/com/android/server/am/CoreSettingsObserverTest.java
+++ b/services/tests/servicestests/src/com/android/server/am/CoreSettingsObserverTest.java
@@ -93,7 +93,8 @@
mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
when(mContext.getContentResolver()).thenReturn(mContentResolver);
- mAms = new ActivityManagerService(new TestInjector(), mServiceThreadRule.getThread());
+ mAms = new ActivityManagerService(new TestInjector(mContext),
+ mServiceThreadRule.getThread());
mCoreSettingsObserver = new CoreSettingsObserver(mAms);
}
@@ -158,9 +159,9 @@
}
private class TestInjector extends Injector {
- @Override
- public Context getContext() {
- return getInstrumentation().getContext();
+
+ TestInjector(Context context) {
+ super(context);
}
@Override