Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8176539e authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Injected proper deps in PrivacyItemController

Test: atest
Change-Id: Ib12d5d6af0f8cfacbb91a2e2cd1887f337a1d61e
Fixes: 121388507
parent adf35773
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -26,16 +26,23 @@ import android.os.Handler
import android.os.UserHandle
import android.os.UserManager
import com.android.internal.annotations.VisibleForTesting
import com.android.systemui.Dependency
import com.android.systemui.Dependency.BG_HANDLER_NAME
import com.android.systemui.Dependency.MAIN_HANDLER_NAME
import com.android.systemui.R
import com.android.systemui.appops.AppOpItem
import com.android.systemui.appops.AppOpsController
import com.android.systemui.R
import java.lang.ref.WeakReference
import javax.inject.Inject
import javax.inject.Named
import javax.inject.Singleton

@Singleton
class PrivacyItemController @Inject constructor(private val context: Context) {
class PrivacyItemController @Inject constructor(
        val context: Context,
        private val appOpsController: AppOpsController,
        @Named(MAIN_HANDLER_NAME) private val uiHandler: Handler,
        @Named(BG_HANDLER_NAME) private val bgHandler: Handler
) {

    companion object {
        val OPS = intArrayOf(AppOpsManager.OP_CAMERA,
@@ -48,16 +55,10 @@ class PrivacyItemController @Inject constructor(private val context: Context) {
        const val TAG = "PrivacyItemController"
        const val SYSTEM_UID = 1000
    }
    private var privacyList = emptyList<PrivacyItem>()

    @Suppress("DEPRECATION")
    private val appOpsController = Dependency.get(AppOpsController::class.java)
    private var privacyList = emptyList<PrivacyItem>()
    private val userManager = context.getSystemService(UserManager::class.java)
    private var currentUserIds = emptyList<Int>()
    @Suppress("DEPRECATION")
    private val bgHandler = Handler(Dependency.get(Dependency.BG_LOOPER))
    @Suppress("DEPRECATION")
    private val uiHandler = Dependency.get(Dependency.MAIN_HANDLER)
    private var listening = false
    val systemApp =
            PrivacyApplication(context.getString(R.string.device_services), SYSTEM_UID, context)
+10 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.privacy

import android.app.ActivityManager
import android.app.AppOpsManager
import android.content.Context
import android.content.Intent
import android.content.pm.UserInfo
import android.os.Handler
@@ -28,6 +29,8 @@ import android.testing.AndroidTestingRunner
import android.testing.TestableLooper
import android.testing.TestableLooper.RunWithLooper
import com.android.systemui.Dependency
import com.android.systemui.Dependency.BG_HANDLER
import com.android.systemui.Dependency.MAIN_HANDLER
import com.android.systemui.R
import com.android.systemui.SysuiTestCase
import com.android.systemui.appops.AppOpItem
@@ -81,15 +84,20 @@ class PrivacyItemControllerTest : SysuiTestCase() {

    private lateinit var testableLooper: TestableLooper
    private lateinit var privacyItemController: PrivacyItemController
    private lateinit var handler: Handler

    fun PrivacyItemController(context: Context) =
            PrivacyItemController(context, appOpsController, handler, handler)

    @Before
    fun setup() {
        MockitoAnnotations.initMocks(this)
        testableLooper = TestableLooper.get(this)
        handler = Handler(testableLooper.looper)

        appOpsController = mDependency.injectMockDependency(AppOpsController::class.java)
        mDependency.injectTestDependency(Dependency.BG_LOOPER, testableLooper.looper)
        mDependency.injectTestDependency(Dependency.MAIN_HANDLER, Handler(testableLooper.looper))
        mDependency.injectTestDependency(Dependency.BG_HANDLER, handler)
        mDependency.injectTestDependency(Dependency.MAIN_HANDLER, handler)
        mContext.addMockSystemService(UserManager::class.java, userManager)
        mContext.getOrCreateTestableResources().addOverride(R.string.device_services,
                DEVICE_SERVICES_STRING)