1 /* Copyright 2017 Braden Farmer
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package com.farmerbb.taskbar.receiver;
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;
26 import com.farmerbb.taskbar.BuildConfig;
27 import com.farmerbb.taskbar.activity.HomeActivity;
28 import com.farmerbb.taskbar.util.U;
30 public class EnableHomeReceiver extends BroadcastReceiver {
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);
41 ComponentName component = new ComponentName(context, HomeActivity.class);
42 context.getPackageManager().setComponentEnabledSetting(component,
43 PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
44 PackageManager.DONT_KILL_APP);
46 LocalBroadcastManager.getInstance(context)
47 .sendBroadcast(new Intent("com.farmerbb.taskbar.LAUNCHER_PREF_CHANGED"));