OSDN Git Service

Cache display windowing mode since it's not consistent on Android 12
[android-x86/packages-apps-Taskbar.git] / app / src / main / java / com / farmerbb / taskbar / receiver / QuitReceiver.java
1 /* Copyright 2016 Braden Farmer
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 package com.farmerbb.taskbar.receiver;
17
18 import android.content.BroadcastReceiver;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.content.SharedPreferences;
22 import com.farmerbb.taskbar.service.DashboardService;
23 import com.farmerbb.taskbar.service.NotificationService;
24 import com.farmerbb.taskbar.service.StartMenuService;
25 import com.farmerbb.taskbar.service.TaskbarService;
26 import com.farmerbb.taskbar.util.IconCache;
27 import com.farmerbb.taskbar.helper.LauncherHelper;
28 import com.farmerbb.taskbar.util.U;
29
30 import static com.farmerbb.taskbar.util.Constants.*;
31
32 public class QuitReceiver extends BroadcastReceiver {
33     @Override
34     public void onReceive(Context context, Intent intent) {
35         if (intent == null || !ACTION_QUIT.equals(intent.getAction())) {
36             return;
37         }
38         SharedPreferences pref = U.getSharedPreferences(context);
39         if(!pref.getBoolean(PREF_SKIP_QUIT_RECEIVER, false)) {
40             Intent taskbarIntent = new Intent(context, TaskbarService.class);
41             Intent startMenuIntent = new Intent(context, StartMenuService.class);
42             Intent dashboardIntent = new Intent(context, DashboardService.class);
43             Intent notificationIntent = new Intent(context, NotificationService.class);
44
45             pref.edit().putBoolean(PREF_TASKBAR_ACTIVE, false).apply();
46
47             if(!LauncherHelper.getInstance().isOnHomeScreen(context)) {
48                 context.stopService(taskbarIntent);
49                 context.stopService(startMenuIntent);
50                 context.stopService(dashboardIntent);
51
52                 U.clearCaches(context);
53                 U.sendBroadcast(context, ACTION_START_MENU_DISAPPEARING);
54             }
55
56             context.stopService(notificationIntent);
57         } else
58             pref.edit().remove(PREF_SKIP_QUIT_RECEIVER).apply();
59     }
60 }