1 /*
2  * Copyright (C) 2021 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 /*
18  * Copyright (C) 2019 The Android Open Source Project
19  *
20  * Licensed under the Apache License, Version 2.0 (the "License");
21  * you may not use this file except in compliance with the License.
22  * You may obtain a copy of the License at
23  *
24  *      http://www.apache.org/licenses/LICENSE-2.0
25  *
26  * Unless required by applicable law or agreed to in writing, software
27  * distributed under the License is distributed on an "AS IS" BASIS,
28  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29  * See the License for the specific language governing permissions and
30  * limitations under the License.
31  */
32 
33 package android.app.stubs;
34 
35 import android.content.Intent;
36 import android.util.Log;
37 
38 /**
39  * Foreground Service with location type.
40  */
41 public class LocalForegroundServiceSticky extends LocalForegroundService {
42     private static final String TAG = "LocalForegroundServiceSticky";
43     public static String STICKY_FLAG =
44             "android.app.stubs.LocalForegroundServiceSticky.sticky_flag";
45     public static String ACTION_RESTART_FGS_STICKY_RESULT =
46             "android.app.stubs.LocalForegroundServiceSticky.STICKY_RESULT";
47 
48     @Override
onStartCommand(Intent intent, int flags, int startId)49     public int onStartCommand(Intent intent, int flags, int startId) {
50         if (intent == null) {
51             Log.d(TAG, "LocalForegroundServiceSticky.onStartCommand: null intent");
52             sendBroadcast(new Intent(ACTION_RESTART_FGS_STICKY_RESULT).setFlags(
53                     Intent.FLAG_RECEIVER_FOREGROUND));
54             return START_STICKY;
55         } else {
56             super.onStartCommand(intent, flags, startId);
57             final int stickyFlag = intent.getIntExtra(STICKY_FLAG, START_NOT_STICKY);
58             Log.d(TAG, "LocalForegroundServiceSticky.onStartCommand, return " + stickyFlag);
59             return stickyFlag;
60         }
61     }
62 }
63