• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.systemui.notetask
18 
19 import android.content.Context
20 import android.content.Intent
21 import androidx.lifecycle.LifecycleService
22 import javax.inject.Inject
23 
24 /**
25  * A fire & forget service for updating note task shortcuts.
26  *
27  * The main use is to update shortcuts in different user by launching it using `startServiceAsUser`.
28  * The service will open with access to a context from that user, trigger
29  * [NoteTaskController.updateNoteTaskAsUser] and [stopSelf] immediately.
30  *
31  * The fire and forget approach was created due to its simplicity but may use unnecessary resources
32  * by recreating the services. We will investigate its impacts and consider to move to a bounded
33  * services - the implementation is more complex as a bounded service is asynchronous by default.
34  *
35  * TODO(b/278729185): Replace fire and forget service with a bounded service.
36  */
37 @InternalNoteTaskApi
38 class NoteTaskControllerUpdateService
39 @Inject
40 constructor(
41     val controller: NoteTaskController,
42 ) : LifecycleService() {
43 
onCreatenull44     override fun onCreate() {
45         super.onCreate()
46         // TODO(b/278729185): Replace fire and forget service with a bounded service.
47         controller.launchUpdateNoteTaskAsUser(user)
48         stopSelf()
49     }
50 
51     companion object {
createIntentnull52         fun createIntent(context: Context): Intent =
53             Intent(context, NoteTaskControllerUpdateService::class.java)
54     }
55 }
56