1/* 2 * Copyright (c) 2015, Motorola Mobility LLC 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * - Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * - Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * - Neither the name of Motorola Mobility nor the 13 * names of its contributors may be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 18 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MOTOROLA MOBILITY LLC BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 26 * DAMAGE. 27 */ 28 29package com.android.service.ims.presence; 30 31import android.content.BroadcastReceiver; 32import android.content.Context; 33import android.content.Intent; 34 35import com.android.ims.internal.Logger; 36import com.android.service.ims.presence.Contacts; 37import com.android.service.ims.presence.SharedPrefUtil; 38 39public class AlarmBroadcastReceiver extends BroadcastReceiver { 40 private Logger logger = Logger.getLogger(this.getClass().getName()); 41 42 private static final String ACTION_PERIODICAL_DISCOVERY_ALARM = 43 CapabilityPolling.ACTION_PERIODICAL_DISCOVERY_ALARM; 44 private static final String ACTION_POLLING_RETRY_ALARM = 45 PollingTask.ACTION_POLLING_RETRY_ALARM; 46 private static final String ACTION_EAB_NEW_CONTACT_INSERTED = 47 Contacts.ACTION_NEW_CONTACT_INSERTED; 48 49 @Override 50 public void onReceive(Context context, Intent intent) { 51 logger.info("onReceive(), intent: " + intent + 52 ", context: " + context); 53 54 String action = intent.getAction(); 55 if (ACTION_PERIODICAL_DISCOVERY_ALARM.equals(action)) { 56 CapabilityPolling capabilityPolling = CapabilityPolling.getInstance(null); 57 if (capabilityPolling != null) { 58 int pollingType = intent.getIntExtra("pollingType", 59 CapabilityPolling.ACTION_POLLING_NORMAL); 60 capabilityPolling.enqueueDiscovery(pollingType); 61 } 62 } else if (ACTION_POLLING_RETRY_ALARM.equals(action)) { 63 PollingsQueue queue = PollingsQueue.getInstance(null); 64 if (queue != null) { 65 long id = intent.getLongExtra("pollingTaskId", -1); 66 queue.retry(id); 67 } 68 } else if (ACTION_EAB_NEW_CONTACT_INSERTED.equals(action)) { 69 CapabilityPolling capabilityPolling = CapabilityPolling.getInstance(null); 70 if (capabilityPolling != null) { 71 String number = intent.getStringExtra(Contacts.NEW_PHONE_NUMBER); 72 capabilityPolling.enqueueNewContact(number); 73 } 74 } else { 75 logger.debug("No interest in this intent: " + action); 76 } 77 } 78}; 79 80