OSDN Git Service

Update to SDK 28 + remove SDK 25 compat support
[android-x86/packages-apps-Taskbar.git] / app / src / main / java / com / farmerbb / taskbar / receiver / BootReceiver.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
23 import com.farmerbb.taskbar.activity.DummyActivity;
24 import com.farmerbb.taskbar.service.NotificationService;
25 import com.farmerbb.taskbar.util.U;
26
27 public class BootReceiver extends BroadcastReceiver {
28     @Override
29     public void onReceive(Context context, Intent intent) {
30         if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
31             // Initialize preferences on BlissOS
32             SharedPreferences pref = U.getSharedPreferences(context);
33             if(U.isBlissOs(context) && !pref.getBoolean("bliss_os_prefs", false))
34                 U.initPrefs(context);
35
36             SharedPreferences.Editor editor = pref.edit();
37
38             if(!U.hasFreeformSupport(context))
39                 editor.putBoolean("freeform_hack", false);
40
41             if(pref.getBoolean("start_on_boot", false)) {
42                 editor.putBoolean("taskbar_active", true);
43                 editor.putLong("time_of_service_start", System.currentTimeMillis());
44                 editor.apply();
45
46                 boolean startServices = false;
47
48                 if(!pref.getBoolean("is_hidden", false)) {
49                     if(U.hasFreeformSupport(context) && pref.getBoolean("freeform_hack", false)) {
50                         Intent intent2 = new Intent(context, DummyActivity.class);
51                         intent2.putExtra("start_freeform_hack", true);
52                         intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
53
54                         context.startActivity(intent2);
55                     }
56
57                     startServices = true;
58                 }
59
60                 Intent notificationIntent = new Intent(context, NotificationService.class);
61                 notificationIntent.putExtra("start_services", startServices);
62
63                 U.startForegroundService(context, notificationIntent);
64             } else {
65                 editor.putBoolean("taskbar_active", U.isServiceRunning(context, NotificationService.class));
66                 editor.apply();
67             }
68         }
69     }
70 }