• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.services.telephony.activation;
18 
19 import android.content.BroadcastReceiver;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.IntentFilter;
23 
24 import com.android.services.telephony.Log;
25 
26 public class ResponseReceiver extends BroadcastReceiver {
27     volatile public static boolean responseReceived = false;
28     public static final String ACTION_ACTIVATION_RESPONSE =
29             "com.android.services.telephony.ACTIVATION_RESPONSE";
30 
31     private final Object mLock;
32     private Context mContext;
33 
ResponseReceiver(Object lock)34     ResponseReceiver(Object lock) {
35         mLock = lock;
36     }
37 
38     /** ${inheritDoc} */
39     @Override
onReceive(Context context, Intent intent)40     public void onReceive(Context context, Intent intent) {
41         if (!ACTION_ACTIVATION_RESPONSE.equals(intent.getAction())) {
42             Log.e(this, null, "Unexpected intent: " + intent.getAction());
43             return;
44         }
45 
46         responseReceived = true;
47         Log.i(this, "received intent");
48 
49         if (mLock != null) {
50             synchronized(mLock) {
51                 Log.i(this, "notifying");
52                 mLock.notify();
53             }
54         }
55     }
56 
register(Context context)57     void register(Context context) {
58         context.registerReceiver(this, new IntentFilter(ACTION_ACTIVATION_RESPONSE));
59         mContext = context;
60     }
61 
unregister()62     void unregister() {
63         mContext.unregisterReceiver(this);
64     }
65 }
66