1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.car.customization.tool
18 
19 import android.accessibilityservice.AccessibilityService
20 import android.os.Handler
21 import android.os.Looper
22 import android.view.accessibility.AccessibilityEvent
23 import com.android.car.customization.tool.di.DaggerCustomizationToolComponent
24 import com.android.car.customization.tool.domain.CustomizationToolStateMachine
25 import com.android.car.customization.tool.domain.ReloadStateAction
26 import com.android.car.customization.tool.ui.CustomizationToolUI
27 import javax.inject.Inject
28 
29 /**
30  * Entry point of the Customization Tool.
31  */
32 internal class CustomizationToolService : AccessibilityService() {
33 
34     @Inject
35     lateinit var customizationToolStateMachine: CustomizationToolStateMachine
36 
37     @Inject
38     lateinit var customizationToolUI: CustomizationToolUI
39 
onServiceConnectednull40     override fun onServiceConnected() {
41         super.onServiceConnected()
42 
43         DaggerCustomizationToolComponent.factory().create(this).inject(this)
44 
45         customizationToolStateMachine.register(customizationToolUI)
46         customizationToolUI.handleAction = customizationToolStateMachine::handleAction
47 
48         val handler = Handler(Looper.getMainLooper())
49         val delay = 5000L
50 
51         handler.postDelayed(
52             object : Runnable {
53                 override fun run() {
54                     customizationToolStateMachine.handleAction(ReloadStateAction)
55                     handler.postDelayed(this, delay)
56                 }
57             },
58             delay
59         )
60     }
61 
onDestroynull62     override fun onDestroy() {
63         customizationToolStateMachine.unregister()
64         super.onDestroy()
65     }
66 
onAccessibilityEventnull67     override fun onAccessibilityEvent(p0: AccessibilityEvent?) {
68     }
69 
onInterruptnull70     override fun onInterrupt() {
71     }
72 }
73