/* * Copyright (C) 2012 asksven * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * This file was contributed by two forty four a.m. LLC <http://www.twofortyfouram.com> * unter the terms of the Apache License, Version 2.0 */ package com.asksven.betterwifionoff.localeplugin.receiver; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.content.SharedPreferences; import android.os.Bundle; import android.os.IBinder; import android.preference.PreferenceManager; import android.util.Log; import android.widget.Toast; import com.asksven.betterwifionoff.MyWidgetProvider; import com.asksven.betterwifionoff.localeplugin.Constants; import com.asksven.betterwifionoff.localeplugin.bundle.BundleScrubber; import com.asksven.betterwifionoff.localeplugin.bundle.PluginBundleManager; import com.asksven.betterwifionoff.localeplugin.ui.EditActivity; /** * This is the "fire" BroadcastReceiver for a Locale Plug-in setting. */ public final class FireReceiver extends BroadcastReceiver { private static String TAG = "BetterWifiOnOff.FireReceiver"; /** * @param context {@inheritDoc}. * @param intent the incoming {@link com.twofortyfouram.locale.Intent#ACTION_FIRE_SETTING} Intent. This should contain the * {@link com.twofortyfouram.locale.Intent#EXTRA_BUNDLE} that was saved by {@link EditActivity} and later broadcast * by Locale. */ @Override public void onReceive(final Context context, final Intent intent) { /* * Always be sure to be strict on input parameters! A malicious third-party app could always send an empty or otherwise * malformed Intent. And since Locale applies settings in the background, the plug-in definitely shouldn't crash in the * background. */ /* * Locale guarantees that the Intent action will be ACTION_FIRE_SETTING */ if (!com.twofortyfouram.locale.Intent.ACTION_FIRE_SETTING.equals(intent.getAction())) { if (Constants.IS_LOGGABLE) { Log.e(Constants.LOG_TAG, String.format("Received unexpected Intent action %s", intent.getAction())); //$NON-NLS-1$ } return; } /* * A hack to prevent a private serializable classloader attack */ BundleScrubber.scrub(intent); BundleScrubber.scrub(intent.getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE)); final Bundle bundle = intent.getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE); // TODO add processing code here boolean bEnable = bundle.getBoolean(PluginBundleManager.BUNDLE_EXTRA_BOOL_ENABLE); Log.i(TAG, "Received parameter: " + bEnable); // refresh widget Intent intentWidget = new Intent(context, //.getApplicationContext(), MyWidgetProvider.class); if (bEnable) { intentWidget.setAction(MyWidgetProvider.ACTION_ENABLE); } else { intentWidget.setAction(MyWidgetProvider.ACTION_DISABLE); } context.sendBroadcast(intentWidget); } }