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 android.support.v4.content.LocalBroadcastManager;
26 import com.farmerbb.taskbar.BuildConfig;
27 import com.farmerbb.taskbar.activity.HomeActivity;
28 import com.farmerbb.taskbar.activity.SecondaryHomeActivity;
29 import com.farmerbb.taskbar.util.U;
31 public class EnableHomeReceiver extends BroadcastReceiver {
33 public void onReceive(Context context, Intent intent) {
34 SharedPreferences pref = U.getSharedPreferences(context);
35 if(intent.hasExtra("secondscreen") && pref.getBoolean("launcher", false))
36 pref.edit().putBoolean("skip_disable_home_receiver", true).apply();
37 else if(U.canDrawOverlays(context)) {
38 SharedPreferences.Editor editor = pref.edit();
39 editor.putBoolean("launcher", true);
42 ComponentName component = new ComponentName(context, HomeActivity.class);
43 context.getPackageManager().setComponentEnabledSetting(component,
44 PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
45 PackageManager.DONT_KILL_APP);
47 ComponentName component2 = new ComponentName(context, SecondaryHomeActivity.class);
48 context.getPackageManager().setComponentEnabledSetting(component2,
50 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
51 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
52 PackageManager.DONT_KILL_APP);
54 LocalBroadcastManager.getInstance(context)
55 .sendBroadcast(new Intent("com.farmerbb.taskbar.LAUNCHER_PREF_CHANGED"));