blob: e145dbb0f60e3f8fe6074394b43d670b6c317d4a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.mozstumbler.service.mainthread;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
/**
* Responsible for registering LocalPreferenceReceiver as a receiver with LocalBroadcastManager.
* This receiver is registered in the AndroidManifest.xml
*/
public class SafeReceiver extends BroadcastReceiver {
static final String LOG_TAG = "StumblerSafeReceiver";
static final String PREFERENCE_INTENT_FILTER = "STUMBLER_PREF";
private boolean registeredLocalReceiver = false;
@Override
public synchronized void onReceive(Context context, Intent intent) {
if (intent == null) {
return;
}
if (registeredLocalReceiver) {
return;
}
LocalBroadcastManager.getInstance(context).registerReceiver(
new LocalPreferenceReceiver(),
new IntentFilter(PREFERENCE_INTENT_FILTER)
);
Log.d(LOG_TAG, "Registered local preference listener");
registeredLocalReceiver = true;
}
}
|