1 /* Copyright 2018 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.Context;
20 import android.content.Intent;
21 import android.os.Bundle;
22 import androidx.localbroadcastmanager.content.LocalBroadcastManager;
24 import com.farmerbb.taskbar.content.TaskbarIntent;
25 import com.farmerbb.taskbar.util.BundleScrubber;
26 import com.farmerbb.taskbar.util.PluginBundleManager;
27 import com.farmerbb.taskbar.util.U;
29 public final class TaskerActionReceiver extends BroadcastReceiver {
31 public void onReceive(Context context, Intent intent) {
32 if(U.isExternalAccessDisabled(context)) return;
34 BundleScrubber.scrub(intent);
36 final Bundle bundle = intent.getBundleExtra(com.twofortyfouram.locale.api.Intent.EXTRA_BUNDLE);
37 BundleScrubber.scrub(bundle);
39 if(bundle.containsKey(PluginBundleManager.BUNDLE_EXTRA_STRING_MESSAGE)
40 && PluginBundleManager.isBundleValid(bundle)) {
41 String action = bundle.getString(PluginBundleManager.BUNDLE_EXTRA_STRING_MESSAGE);
42 Intent actionIntent = generateIntent(action);
44 if(actionIntent != null) switch(action) {
47 actionIntent.setPackage(context.getPackageName());
48 context.sendBroadcast(actionIntent);
51 LocalBroadcastManager.getInstance(context).sendBroadcast(actionIntent);
57 private Intent generateIntent(String action) {
58 if(action != null) switch(action) {
60 return new Intent("com.farmerbb.taskbar.START");
62 return new Intent("com.farmerbb.taskbar.QUIT");
64 return new Intent("com.farmerbb.taskbar.SHOW_TASKBAR");
66 return new Intent(TaskbarIntent.ACTION_HIDE_TASKBAR);
67 case "toggle_start_menu":
68 return new Intent(TaskbarIntent.ACTION_TOGGLE_START_MENU);
69 case "toggle_dashboard":
70 return new Intent("com.farmerbb.taskbar.TOGGLE_DASHBOARD");