1 /*
2  * Copyright (C) 2012 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.dialer.contact;
18 
19 import android.app.IntentService;
20 import android.content.Context;
21 import android.content.Intent;
22 
23 import com.android.contacts.common.database.ContactUpdateUtils;
24 
25 /**
26  * Service for updating primary number on a contact.
27  */
28 public class ContactUpdateService extends IntentService {
29 
30     public static final String EXTRA_PHONE_NUMBER_DATA_ID = "phone_number_data_id";
31 
ContactUpdateService()32     public ContactUpdateService() {
33         super(ContactUpdateService.class.getSimpleName());
34         setIntentRedelivery(true);
35     }
36 
37     /** Creates an intent that sets the selected data item as super primary (default) */
createSetSuperPrimaryIntent(Context context, long dataId)38     public static Intent createSetSuperPrimaryIntent(Context context, long dataId) {
39         Intent serviceIntent = new Intent(context, ContactUpdateService.class);
40         serviceIntent.putExtra(EXTRA_PHONE_NUMBER_DATA_ID, dataId);
41         return serviceIntent;
42     }
43 
44     @Override
onHandleIntent(Intent intent)45     protected void onHandleIntent(Intent intent) {
46         // Currently this service only handles one type of update.
47         long dataId = intent.getLongExtra(EXTRA_PHONE_NUMBER_DATA_ID, -1);
48 
49         ContactUpdateUtils.setSuperPrimary(this, dataId);
50     }
51 }
52