Add a setting to enable/disable calling accounts.
Bug: 20303449
Change-Id: I34f9e5a572fd449ad617861576937f9648ae4ee9
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 5547624..34647a2 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -216,6 +216,17 @@
</intent-filter>
</activity>
+ <activity android:name=".settings.EnableAccountPreferenceActivity"
+ android:label="@string/enable_account_preference_title"
+ android:configChanges="orientation|screenSize|keyboardHidden"
+ android:theme="@style/Theme.Telecom.DialerSettings"
+ android:process=":ui">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
+
<activity android:name=".components.ErrorDialogActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:excludeFromRecents="true"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index a2295b5..181a7f7 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -73,6 +73,12 @@
a text response. [CHAR LIMIT=40] -->
<string name="respond_via_sms_confirmation_format">Message sent to <xliff:g id="phone_number">%s</xliff:g>.</string>
+ <!-- Title of settings screen that allows user to enable and disable phone-accounts.
+ Each method for placing a call (SIM1, SIM2, SIP account, etc) has a phone-account.
+ Phone-accounts that are created by third party apps can be disabled and enabled by user.
+ [CHAR LIMIT=30] -->
+ <string name="enable_account_preference_title">Calling accounts</string>
+
<!-- Message indicating that the user is not allowed to make non-emergency outgoing phone calls
due to a user restriction -->
<string name="outgoing_call_not_allowed">Only emergency calls are allowed by the device owner.</string>
diff --git a/res/xml/enable_account_preference.xml b/res/xml/enable_account_preference.xml
new file mode 100644
index 0000000..aa9a9c9
--- /dev/null
+++ b/res/xml/enable_account_preference.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- Settings screen that lets the user enable and disable registered phone accounts.
+ See EnableAccountPreferenceFragment.java -->
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ android:title="@string/enable_account_preference_title">
+ <!-- content created dynamically. -->
+</PreferenceScreen>
diff --git a/src/com/android/server/telecom/settings/EnableAccountPreferenceActivity.java b/src/com/android/server/telecom/settings/EnableAccountPreferenceActivity.java
new file mode 100644
index 0000000..b68c8ff
--- /dev/null
+++ b/src/com/android/server/telecom/settings/EnableAccountPreferenceActivity.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.telecom.settings;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+public class EnableAccountPreferenceActivity extends Activity {
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ getFragmentManager().beginTransaction()
+ .replace(android.R.id.content, new EnableAccountPreferenceFragment())
+ .commit();
+ }
+}
diff --git a/src/com/android/server/telecom/settings/EnableAccountPreferenceFragment.java b/src/com/android/server/telecom/settings/EnableAccountPreferenceFragment.java
new file mode 100644
index 0000000..48e22b6
--- /dev/null
+++ b/src/com/android/server/telecom/settings/EnableAccountPreferenceFragment.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.telecom.settings;
+
+import android.content.Context;
+import android.graphics.drawable.Icon;
+import android.os.Bundle;
+import android.preference.PreferenceFragment;
+import android.preference.PreferenceScreen;
+import android.preference.SwitchPreference;
+import android.telecom.PhoneAccount;
+import android.telecom.PhoneAccountHandle;
+import android.telecom.TelecomManager;
+
+import com.android.server.telecom.R;
+
+import java.util.List;
+
+/**
+ * Lists all call-capable {@link PhoneAccount}s which are not SIM-based and provides a settings
+ * for enabling and disabling each of the accounts. Only enabled accounts will be (1) listed as
+ * options with which to place a call and (2) capable of receiving incoming calls through the
+ * default dialer UI.
+ */
+public class EnableAccountPreferenceFragment extends PreferenceFragment {
+
+ private static final class AccountSwitchPreference extends SwitchPreference {
+ private final PhoneAccount mAccount;
+
+ public AccountSwitchPreference(Context context, PhoneAccount account) {
+ super(context);
+ mAccount = account;
+
+ setTitle(account.getLabel());
+ setSummary(account.getShortDescription());
+ Icon icon = account.getIcon();
+ if (icon != null) {
+ setIcon(icon.loadDrawable(context));
+ }
+ }
+
+ /** ${inheritDoc} */
+ @Override
+ protected void onClick() {
+ super.onClick();
+
+ // TODO: Handle enabling/disabling phone accounts
+ }
+ }
+
+ private TelecomManager mTelecomManager;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mTelecomManager = TelecomManager.from(getActivity());
+ }
+
+
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ addPreferencesFromResource(R.xml.enable_account_preference);
+
+ List<PhoneAccountHandle> accountHandles = mTelecomManager.getCallCapablePhoneAccounts();
+
+ PreferenceScreen screen = getPreferenceScreen();
+ Context context = getActivity();
+ for (PhoneAccountHandle handle : accountHandles) {
+ PhoneAccount account = mTelecomManager.getPhoneAccount(handle);
+ if (account != null) {
+ final boolean isSimAccount =
+ 0 != (account.getCapabilities() & PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION);
+ if (!isSimAccount) {
+ screen.addPreference(new AccountSwitchPreference(context, account));
+ }
+ }
+ }
+ }
+}