Merge "Adding the ability for carrier app to override SPN and carrier name." into lmp-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ee47f18..c0cdc3e 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -585,5 +585,11 @@
</intent-filter>
</provider>
+ <receiver android:name="com.android.services.telephony.AddAccountsReceiver">
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </receiver>
</application>
</manifest>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2825a7e..70dcfc2 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -125,7 +125,7 @@
<!-- Label for the "Network settings" screen in the Settings UI -->
<string name="settings_label">Network settings</string>
<!-- Label for connection service setting -->
- <string name="connection_service">Connection service to use</string>
+ <string name="phone_accounts">Phone account settings</string>
<!-- Built-in label for the default connection service setting. -->
<string name="connection_service_default_label">Built-in connection service</string>
<!-- Call settings screen, setting option name -->
diff --git a/res/xml/call_feature_setting.xml b/res/xml/call_feature_setting.xml
index 6c1b570..30811e4 100644
--- a/res/xml/call_feature_setting.xml
+++ b/res/xml/call_feature_setting.xml
@@ -41,11 +41,13 @@
android:title="@string/other_settings"
android:persistent="false" />
- <ListPreference
- android:key="button_connection_service"
- android:title="@string/connection_service"
- android:defaultValue="@string/connection_service_default"
- android:persistent="true" />
+ <Preference
+ android:key="phone_accounts"
+ android:title="@string/phone_accounts" >
+ <intent
+ android:targetClass="com.android.telecomm.PhoneAccountPreferencesActivity"
+ android:targetPackage="com.android.telecomm" />
+ </Preference>
<PreferenceScreen
android:key="button_voicemail_category_key"
diff --git a/sip/src/com/android/services/telephony/sip/SipConnection.java b/sip/src/com/android/services/telephony/sip/SipConnection.java
index 5bca97b..699090f 100644
--- a/sip/src/com/android/services/telephony/sip/SipConnection.java
+++ b/sip/src/com/android/services/telephony/sip/SipConnection.java
@@ -144,11 +144,11 @@
}
@Override
- protected void onAnswer() {
+ protected void onAnswer(int videoState) {
if (VERBOSE) log("onAnswer");
try {
if (isValidRingingCall() && getPhone() != null) {
- getPhone().acceptCall();
+ getPhone().acceptCall(videoState);
}
} catch (CallStateException e) {
log("onAnswer, exception: " + e);
diff --git a/sip/src/com/android/services/telephony/sip/SipConnectionService.java b/sip/src/com/android/services/telephony/sip/SipConnectionService.java
index a46180d..a87b398 100644
--- a/sip/src/com/android/services/telephony/sip/SipConnectionService.java
+++ b/sip/src/com/android/services/telephony/sip/SipConnectionService.java
@@ -48,9 +48,7 @@
static PhoneAccount getPhoneAccount(Context context) {
return new PhoneAccount(
new ComponentName(context, SipConnectionService.class),
- null /* id */,
- null /* handle */,
- PhoneAccount.CAPABILITY_CALL_PROVIDER);
+ null /* id */);
}
@Override
diff --git a/src/com/android/phone/CdmaOptions.java b/src/com/android/phone/CdmaOptions.java
index 3e3c8b5..8971fa4 100644
--- a/src/com/android/phone/CdmaOptions.java
+++ b/src/com/android/phone/CdmaOptions.java
@@ -43,6 +43,7 @@
private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key";
private static final String BUTTON_CDMA_SUBSCRIPTION_KEY = "cdma_subscription_key";
private static final String BUTTON_CDMA_ACTIVATE_DEVICE_KEY = "cdma_activate_device_key";
+ private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
private PreferenceActivity mPrefActivity;
private PreferenceScreen mPrefScreen;
@@ -83,6 +84,16 @@
mPrefScreen.removePreference(
mPrefScreen.findPreference(BUTTON_CDMA_ACTIVATE_DEVICE_KEY));
}
+
+ // Read platform settings for carrier settings
+ final boolean isCarrierSettingsEnabled = mPrefActivity.getResources().getBoolean(
+ R.bool.config_carrier_settings_enable);
+ if (!isCarrierSettingsEnabled) {
+ Preference pref = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
+ if (pref != null) {
+ mPrefScreen.removePreference(pref);
+ }
+ }
}
private boolean deviceSupportsNvAndRuim() {
diff --git a/src/com/android/phone/GsmUmtsOptions.java b/src/com/android/phone/GsmUmtsOptions.java
index 6829dec..6791f27 100644
--- a/src/com/android/phone/GsmUmtsOptions.java
+++ b/src/com/android/phone/GsmUmtsOptions.java
@@ -36,6 +36,7 @@
private static final String BUTTON_APN_EXPAND_KEY = "button_apn_key";
private static final String BUTTON_OPERATOR_SELECTION_EXPAND_KEY = "button_carrier_sel_key";
+ private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
private PreferenceActivity mPrefActivity;
private PreferenceScreen mPrefScreen;
@@ -80,6 +81,16 @@
.findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY));
}
}
+
+ // Read platform settings for carrier settings
+ final boolean isCarrierSettingsEnabled = mPrefActivity.getResources().getBoolean(
+ R.bool.config_carrier_settings_enable);
+ if (!isCarrierSettingsEnabled) {
+ Preference pref = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
+ if (pref != null) {
+ mPrefScreen.removePreference(pref);
+ }
+ }
}
}
diff --git a/src/com/android/phone/MobileNetworkSettings.java b/src/com/android/phone/MobileNetworkSettings.java
index c225eb4..492ccc5 100644
--- a/src/com/android/phone/MobileNetworkSettings.java
+++ b/src/com/android/phone/MobileNetworkSettings.java
@@ -71,7 +71,6 @@
private static final String BUTTON_ROAMING_KEY = "button_roaming_key";
private static final String BUTTON_CDMA_LTE_DATA_SERVICE_KEY = "cdma_lte_data_service_key";
private static final String BUTTON_ENABLED_NETWORKS_KEY = "enabled_networks_key";
- private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
static final int preferredNetworkMode = Phone.PREFERRED_NT_MODE;
@@ -333,16 +332,6 @@
android.util.Log.d(LOG_TAG, "keep ltePref");
}
- // Read platform settings for carrier settings
- final boolean isCarrierSettingsEnabled = getResources().getBoolean(
- R.bool.config_carrier_settings_enable);
- if (!isCarrierSettingsEnabled) {
- Preference pref = prefSet.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
- if (pref != null) {
- prefSet.removePreference(pref);
- }
- }
-
ActionBar actionBar = getActionBar();
if (actionBar != null) {
// android.R.id.home will be triggered in onOptionsItemSelected()
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index a8d9598..8e25be9 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -1618,6 +1618,10 @@
if (DBG) log("setPreferredNetworkType: type " + networkType);
Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType);
if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
+ if (success) {
+ Settings.Global.putInt(mPhone.getContext().getContentResolver(),
+ Settings.Global.PREFERRED_NETWORK_MODE, networkType);
+ }
return success;
}
diff --git a/src/com/android/phone/SimContacts.java b/src/com/android/phone/SimContacts.java
index ebfc775..bebb6ea 100644
--- a/src/com/android/phone/SimContacts.java
+++ b/src/com/android/phone/SimContacts.java
@@ -59,10 +59,6 @@
public class SimContacts extends ADNList {
private static final String LOG_TAG = "SimContacts";
- private static final String UP_ACTIVITY_PACKAGE = "com.android.contacts";
- private static final String UP_ACTIVITY_CLASS =
- "com.android.contacts.activities.PeopleActivity";
-
static final ContentValues sEmptyContentValues = new ContentValues();
private static final int MENU_IMPORT_ONE = 1;
@@ -274,11 +270,7 @@
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
- Intent intent = new Intent();
- intent.setClassName(UP_ACTIVITY_PACKAGE, UP_ACTIVITY_CLASS);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(intent);
- finish();
+ onBackPressed();
return true;
case MENU_IMPORT_ALL:
CharSequence title = getString(R.string.importAllSimEntries);
diff --git a/src/com/android/services/telephony/AddAccountsReceiver.java b/src/com/android/services/telephony/AddAccountsReceiver.java
new file mode 100644
index 0000000..2e635c7
--- /dev/null
+++ b/src/com/android/services/telephony/AddAccountsReceiver.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2014 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.services.telephony;
+
+import com.android.phone.R;
+
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.telecomm.PhoneAccount;
+import android.telecomm.PhoneAccountMetadata;
+import android.telecomm.TelecommManager;
+
+public class AddAccountsReceiver extends BroadcastReceiver {
+
+ private static String SCHEME_TEL = "tel";
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Log.d(this, "onReceive");
+ try {
+ TelecommManager telecommManager = TelecommManager.from(context);
+ telecommManager.clearAccounts(context.getPackageName());
+ PhoneAccountMetadata[] accounts = makeAccounts(context);
+ for (int i = 0; i < accounts.length; i++) {
+ telecommManager.registerPhoneAccount(accounts[i]);
+ }
+ } catch (Exception e) {
+ Log.e(this, e, "onReceive");
+ throw e;
+ }
+ }
+
+ public static PhoneAccountMetadata[] makeAccounts(Context context) {
+ ComponentName componentName = new ComponentName(
+ context.getPackageName(),
+ TelephonyConnectionService.class.getName());
+ return new PhoneAccountMetadata[]{
+ new PhoneAccountMetadata(
+ new PhoneAccount(componentName, "sim_0"),
+ Uri.fromParts(SCHEME_TEL, "650-555-1212", null),
+ PhoneAccountMetadata.CAPABILITY_CALL_PROVIDER,
+ R.drawable.fab_ic_call,
+ "Zero SIM Account",
+ "Short description for SIM card zero",
+ false),
+ new PhoneAccountMetadata(
+ new PhoneAccount(componentName, "sim_1"),
+ Uri.fromParts(SCHEME_TEL, "650-555-1234", null),
+ PhoneAccountMetadata.CAPABILITY_CALL_PROVIDER,
+ R.drawable.fab_ic_call,
+ "One SIM Account",
+ "Short description for SIM card one",
+ false)
+ };
+ }
+}
diff --git a/src/com/android/services/telephony/PstnIncomingCallNotifier.java b/src/com/android/services/telephony/PstnIncomingCallNotifier.java
index e19991a..1ba4a4e 100644
--- a/src/com/android/services/telephony/PstnIncomingCallNotifier.java
+++ b/src/com/android/services/telephony/PstnIncomingCallNotifier.java
@@ -20,7 +20,6 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
-import android.net.Uri;
import android.os.AsyncResult;
import android.os.Handler;
import android.os.Message;
@@ -157,7 +156,7 @@
Intent intent = new Intent(TelecommConstants.ACTION_INCOMING_CALL);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(TelecommConstants.EXTRA_PHONE_ACCOUNT,
- TelephonyConnectionService.getPhoneAccount(context));
+ AddAccountsReceiver.makeAccounts(context)[0].getAccount());
Log.d(this, "Sending incoming call intent: %s", intent);
context.startActivityAsUser(intent, UserHandle.CURRENT);
diff --git a/src/com/android/services/telephony/TelephonyConnection.java b/src/com/android/services/telephony/TelephonyConnection.java
index 5886ef2..3bf51d5 100644
--- a/src/com/android/services/telephony/TelephonyConnection.java
+++ b/src/com/android/services/telephony/TelephonyConnection.java
@@ -18,16 +18,26 @@
import android.net.Uri;
import android.os.AsyncResult;
+import android.content.ComponentName;
+import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.telecomm.CallAudioState;
+import android.telecomm.CallCapabilities;
+import android.telecomm.ConnectionService;
+import android.telecomm.StatusHints;
+import android.telecomm.TelecommConstants;
import android.telephony.DisconnectCause;
import com.android.internal.telephony.Call;
import com.android.internal.telephony.CallStateException;
import com.android.internal.telephony.Connection.PostDialListener;
import com.android.internal.telephony.Phone;
+import com.android.phone.R;
+
import android.telecomm.Connection;
+import android.telephony.PhoneNumberUtils;
+import android.telephony.TelephonyManager;
import java.util.List;
import java.util.Objects;
@@ -72,9 +82,62 @@
}
};
+ /**
+ * Listener for listening to events in the {@link com.android.internal.telephony.Connection}.
+ */
+ private final com.android.internal.telephony.Connection.Listener mOriginalConnectionListener =
+ new com.android.internal.telephony.Connection.ListenerBase() {
+ @Override
+ public void onVideoStateChanged(int videoState) {
+ setVideoState(videoState);
+ }
+
+ /**
+ * The {@link com.android.internal.telephony.Connection} has reported a change in local
+ * video capability.
+ *
+ * @param capable True if capable.
+ */
+ @Override
+ public void onLocalVideoCapabilityChanged(boolean capable) {
+ setLocalVideoCapable(capable);
+ }
+
+ /**
+ * The {@link com.android.internal.telephony.Connection} has reported a change in remote
+ * video capability.
+ *
+ * @param capable True if capable.
+ */
+ @Override
+ public void onRemoteVideoCapabilityChanged(boolean capable) {
+ setRemoteVideoCapable(capable);
+ }
+ };
+
private com.android.internal.telephony.Connection mOriginalConnection;
private Call.State mOriginalConnectionState = Call.State.IDLE;
+ /**
+ * Determines if the {@link TelephonyConnection} has local video capabilities.
+ * This is used when {@link TelephonyConnection#updateCallCapabilities(boolean)}} is called,
+ * ensuring the appropriate {@link CallCapabilities} are set. Since {@link CallCapabilities}
+ * can be rebuilt at any time it is necessary to track the video capabilities between rebuild.
+ * The {@link CallCapabilities} (including video capabilities) are communicated to the telecomm
+ * layer.
+ */
+ private boolean mLocalVideoCapable;
+
+ /**
+ * Determines if the {@link TelephonyConnection} has remote video capabilities.
+ * This is used when {@link TelephonyConnection#updateCallCapabilities(boolean)}} is called,
+ * ensuring the appropriate {@link CallCapabilities} are set. Since {@link CallCapabilities}
+ * can be rebuilt at any time it is necessary to track the video capabilities between rebuild.
+ * The {@link CallCapabilities} (including video capabilities) are communicated to the telecomm
+ * layer.
+ */
+ private boolean mRemoteVideoCapable;
+
protected TelephonyConnection(com.android.internal.telephony.Connection originalConnection) {
Log.v(this, "new TelephonyConnection, originalConnection: " + originalConnection);
mOriginalConnection = originalConnection;
@@ -82,6 +145,12 @@
mHandler, MSG_PRECISE_CALL_STATE_CHANGED, null);
getPhone().registerForRingbackTone(mHandler, MSG_RINGBACK_TONE, null);
mOriginalConnection.addPostDialListener(mPostDialListener);
+ mOriginalConnection.addListener(mOriginalConnectionListener);
+
+ // Set video state and capabilities
+ setVideoState(mOriginalConnection.getVideoState());
+ setLocalVideoCapable(mOriginalConnection.isLocalVideoCapable());
+ setRemoteVideoCapable(mOriginalConnection.isRemoteVideoCapable());
}
@Override
@@ -171,14 +240,14 @@
}
@Override
- protected void onAnswer() {
+ protected void onAnswer(int videoState) {
Log.v(this, "onAnswer");
// TODO(santoscordon): Tons of hairy logic is missing here around multiple active calls on
// CDMA devices. See {@link CallManager.acceptCall}.
if (isValidRingingCall() && getPhone() != null) {
try {
- getPhone().acceptCall();
+ getPhone().acceptCall(videoState);
} catch (CallStateException e) {
Log.e(this, e, "Failed to accept call.");
}
@@ -225,12 +294,15 @@
protected final void updateCallCapabilities(boolean force) {
int newCallCapabilities = buildCallCapabilities();
+ newCallCapabilities = applyVideoCapabilities(newCallCapabilities);
+
if (force || getCallCapabilities() != newCallCapabilities) {
setCallCapabilities(newCallCapabilities);
}
}
protected final void updateHandle(boolean force) {
+ updateCallCapabilities(force);
if (mOriginalConnection != null) {
Uri handle = TelephonyConnectionService.getHandleFromAddress(
mOriginalConnection.getAddress());
@@ -251,8 +323,30 @@
}
}
- void onAddedToCallService() {
+ void onAddedToCallService(ConnectionService connectionService) {
updateState(false);
+
+ StatusHints hints = getStatusHints();
+ if (hints == null) {
+ hints = new StatusHints(
+ new ComponentName(connectionService, TelephonyConnectionService.class),
+ "", R.mipmap.ic_launcher_phone, new Bundle());
+ }
+
+ Bundle extras = hints.getExtras();
+ String number = getHandle().getSchemeSpecificPart();
+ if (PhoneNumberUtils.isEmergencyNumber(number)) {
+ Phone phone = getOriginalConnection().getCall().getPhone();
+ long subId = phone.getSubId();
+
+ String simNumber = phone.getPhoneSubInfo().getLine1Number();
+ String visibleNumber = TelephonyManager.from(connectionService).getLine1Number(subId);
+ if (!PhoneNumberUtils.compare(simNumber, visibleNumber)) {
+ Log.d(this, "SIM number is different; populate the SIM number");
+ extras.putString(TelecommConstants.EXTRA_EMERGENCY_CALL_BACK_NUMBER, simNumber);
+ }
+ }
+ setStatusHints(hints);
}
void onRemovedFromCallService() {
@@ -377,4 +471,66 @@
mOriginalConnection = null;
setDestroyed();
}
+
+ /**
+ * Applies the video capability states to the CallCapabilities bit-mask.
+ *
+ * @param capabilities The CallCapabilities bit-mask.
+ * @return The capabilities with video capabilities applied.
+ */
+ private int applyVideoCapabilities(int capabilities) {
+ int currentCapabilities = getCallCapabilities();
+ if (mRemoteVideoCapable) {
+ currentCapabilities |= CallCapabilities.SUPPORTS_VT_REMOTE;
+ } else {
+ currentCapabilities &= ~CallCapabilities.SUPPORTS_VT_REMOTE;
+ }
+
+ if (mLocalVideoCapable) {
+ currentCapabilities |= CallCapabilities.SUPPORTS_VT_LOCAL;
+ } else {
+ currentCapabilities &= ~CallCapabilities.SUPPORTS_VT_LOCAL;
+ }
+ return currentCapabilities;
+ }
+
+ /**
+ * Returns the local video capability state for the connection.
+ *
+ * @return {@code True} if the connection has local video capabilities.
+ */
+ public boolean isLocalVideoCapable() {
+ return mLocalVideoCapable;
+ }
+
+ /**
+ * Returns the remote video capability state for the connection.
+ *
+ * @return {@code True} if the connection has remote video capabilities.
+ */
+ public boolean isRemoteVideoCapable() {
+ return mRemoteVideoCapable;
+ }
+
+ /**
+ * Sets whether video capability is present locally. Used during rebuild of the
+ * {@link CallCapabilities} to set the video call capabilities.
+ *
+ * @param capable {@code True} if video capable.
+ */
+ public void setLocalVideoCapable(boolean capable) {
+ mLocalVideoCapable = capable;
+ updateCallCapabilities(false);
+ }
+
+ /**
+ * Sets whether video capability is present remotely. Used during rebuild of the
+ * {@link CallCapabilities} to set the video call capabilities.
+ *
+ * @param capable {@code True} if video capable.
+ */
+ public void setRemoteVideoCapable(boolean capable) {
+ mRemoteVideoCapable = capable;
+ updateCallCapabilities(false);
+ }
}
diff --git a/src/com/android/services/telephony/TelephonyConnectionService.java b/src/com/android/services/telephony/TelephonyConnectionService.java
index 2d55165..04b016b 100644
--- a/src/com/android/services/telephony/TelephonyConnectionService.java
+++ b/src/com/android/services/telephony/TelephonyConnectionService.java
@@ -20,6 +20,8 @@
import android.content.Context;
import android.net.Uri;
import android.os.Debug;
+import android.telecomm.PhoneAccountMetadata;
+import android.telecomm.TelecommManager;
import android.telephony.DisconnectCause;
import android.telephony.ServiceState;
import android.text.TextUtils;
@@ -45,14 +47,6 @@
private EmergencyCallHelper mEmergencyCallHelper;
- static PhoneAccount getPhoneAccount(Context context) {
- return new PhoneAccount(
- new ComponentName(context, TelephonyConnectionService.class),
- null /* id */,
- null,
- PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION);
- }
-
@Override
protected void onCreateOutgoingConnection(
final ConnectionRequest request,
@@ -176,7 +170,7 @@
Uri handle = getHandleFromAddress(originalConnection.getAddress());
ConnectionRequest telephonyRequest = new ConnectionRequest(
- getPhoneAccount(this),
+ request.getAccount(),
request.getCallId(),
handle,
originalConnection.getNumberPresentation(),
@@ -196,7 +190,7 @@
protected void onConnectionAdded(Connection connection) {
Log.v(this, "onConnectionAdded, connection: " + connection);
if (connection instanceof TelephonyConnection) {
- ((TelephonyConnection) connection).onAddedToCallService();
+ ((TelephonyConnection) connection).onAddedToCallService(this);
}
}
@@ -231,7 +225,7 @@
}
ConnectionRequest telephonyRequest = new ConnectionRequest(
- getPhoneAccount(this),
+ request.getAccount(),
request.getCallId(),
request.getHandle(),
request.getHandlePresentation(),