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;
23 import com.farmerbb.taskbar.service.NotificationService;
24 import com.farmerbb.taskbar.util.BundleScrubber;
25 import com.farmerbb.taskbar.util.PluginBundleManager;
26 import com.farmerbb.taskbar.util.U;
28 public final class TaskerConditionReceiver extends BroadcastReceiver {
29 private Bundle lastbundle = null;
32 public void onReceive(Context context, Intent intent) {
33 if(U.isExternalAccessDisabled(context)) return;
35 if (lastbundle.equals(intent.getBundleExtra(com.twofortyfouram.locale.api.Intent.EXTRA_BUNDLE))) {
36 // bundle hasn't changed: we can safely return
41 BundleScrubber.scrub(intent);
43 BundleScrubber.scrub(lastbundle);
45 if(PluginBundleManager.isBundleValid(lastbundle)) {
46 String action = lastbundle.getString(PluginBundleManager.BUNDLE_EXTRA_STRING_MESSAGE);
48 if(action != null) switch(action) {
50 if(U.isServiceRunning(context, NotificationService.class))
51 setResultCode(com.twofortyfouram.locale.api.Intent.RESULT_CONDITION_SATISFIED);
53 setResultCode(com.twofortyfouram.locale.api.Intent.RESULT_CONDITION_UNSATISFIED);
56 if(U.isServiceRunning(context, NotificationService.class))
57 setResultCode(com.twofortyfouram.locale.api.Intent.RESULT_CONDITION_UNSATISFIED);
59 setResultCode(com.twofortyfouram.locale.api.Intent.RESULT_CONDITION_SATISFIED);
65 private void updateValues(Intent intent) {
66 lastbundle = intent.getBundleExtra(com.twofortyfouram.locale.api.Intent.EXTRA_BUNDLE);