1 /*
2  * Copyright (C) 2014 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.sip;
18 
19 import android.app.Activity;
20 import android.content.Intent;
21 import android.net.sip.SipProfile;
22 import android.os.Bundle;
23 import android.os.Parcelable;
24 import android.telecom.PhoneAccountHandle;
25 import android.telecom.TelecomManager;
26 import android.util.Log;
27 
28 /**
29  * This activity receives the standard telecom intent to open settings for a PhoneAccount. It
30  * translates the incoming phone account to a SIP profile and opens the corresponding
31  * PreferenceActivity for said profile.
32  */
33 public final class SipPhoneAccountSettingsActivity extends Activity {
34     private static final String TAG = "SipSettingsActivity";
35 
36     /** ${inheritDoc} */
37     @Override
onCreate(Bundle savedInstanceState)38     protected void onCreate(Bundle savedInstanceState) {
39         super.onCreate(savedInstanceState);
40 
41         Intent intent = getIntent();
42         Log.i(TAG, "" + intent);
43         if (intent != null) {
44             PhoneAccountHandle accountHandle = (PhoneAccountHandle)
45                     intent.getParcelableExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE);
46             Log.i(TAG, "" + accountHandle);
47 
48             if (accountHandle != null) {
49                 SipProfileDb profileDb = new SipProfileDb(this);
50                 String profileName = SipUtil.getSipProfileNameFromPhoneAccount(accountHandle);
51                 SipProfile profile = profileDb.retrieveSipProfileFromName(profileName);
52                 if (profile != null) {
53                     Intent settingsIntent = new Intent(this, SipEditor.class);
54                     settingsIntent.putExtra(SipSettings.KEY_SIP_PROFILE, (Parcelable) profile);
55                     startActivity(settingsIntent);
56                 }
57             }
58         }
59 
60         finish();
61     }
62 }
63