OSDN Git Service

558873bd0d74246ebd9774ca26db6e6a24896c64
[android-x86/packages-apps-Taskbar.git] / app / src / playstore / java / com / farmerbb / taskbar / receiver / EnableHomeReceiver.java
1 /* Copyright 2017 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.ComponentName;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.SharedPreferences;
23 import android.content.pm.PackageManager;
24 import androidx.localbroadcastmanager.content.LocalBroadcastManager;
25
26 import com.farmerbb.taskbar.BuildConfig;
27 import com.farmerbb.taskbar.activity.HomeActivity;
28 import com.farmerbb.taskbar.util.U;
29
30 public class EnableHomeReceiver extends BroadcastReceiver {
31     @Override
32     public void onReceive(Context context, Intent intent) {
33         SharedPreferences pref = U.getSharedPreferences(context);
34         if(intent.hasExtra("secondscreen") && pref.getBoolean("launcher", false))
35             pref.edit().putBoolean("skip_disable_home_receiver", true).apply();
36         else if(U.canDrawOverlays(context)) {
37             SharedPreferences.Editor editor = pref.edit();
38             editor.putBoolean("launcher", true);
39             editor.apply();
40
41             ComponentName component = new ComponentName(context, HomeActivity.class);
42             context.getPackageManager().setComponentEnabledSetting(component,
43                     PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
44                     PackageManager.DONT_KILL_APP);
45
46             LocalBroadcastManager.getInstance(context)
47                     .sendBroadcast(new Intent("com.farmerbb.taskbar.LAUNCHER_PREF_CHANGED"));
48         }
49     }
50 }