Merge "Update MobileDataPreference about multi-SIM data enable logic"
diff --git a/res/drawable-hdpi/ic_fire_white_24.png b/res/drawable-hdpi/ic_fire_white_24.png
new file mode 100644
index 0000000..0c0c6ed
--- /dev/null
+++ b/res/drawable-hdpi/ic_fire_white_24.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_shield_white_24.png b/res/drawable-hdpi/ic_shield_white_24.png
new file mode 100644
index 0000000..bf23794
--- /dev/null
+++ b/res/drawable-hdpi/ic_shield_white_24.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_fire_white_24.png b/res/drawable-mdpi/ic_fire_white_24.png
new file mode 100644
index 0000000..de8fda9
--- /dev/null
+++ b/res/drawable-mdpi/ic_fire_white_24.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_shield_white_24.png b/res/drawable-mdpi/ic_shield_white_24.png
new file mode 100644
index 0000000..9a5d958
--- /dev/null
+++ b/res/drawable-mdpi/ic_shield_white_24.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_fire_white_24.png b/res/drawable-xhdpi/ic_fire_white_24.png
new file mode 100644
index 0000000..750072e
--- /dev/null
+++ b/res/drawable-xhdpi/ic_fire_white_24.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_shield_white_24.png b/res/drawable-xhdpi/ic_shield_white_24.png
new file mode 100644
index 0000000..e886233
--- /dev/null
+++ b/res/drawable-xhdpi/ic_shield_white_24.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_fire_white_24.png b/res/drawable-xxhdpi/ic_fire_white_24.png
new file mode 100644
index 0000000..37c6ecd
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_fire_white_24.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_shield_white_24.png b/res/drawable-xxhdpi/ic_shield_white_24.png
new file mode 100644
index 0000000..1621836
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_shield_white_24.png
Binary files differ
diff --git a/res/drawable-xxxhdpi/ic_fire_white_24.png b/res/drawable-xxxhdpi/ic_fire_white_24.png
new file mode 100644
index 0000000..fb1d630
--- /dev/null
+++ b/res/drawable-xxxhdpi/ic_fire_white_24.png
Binary files differ
diff --git a/res/drawable-xxxhdpi/ic_shield_white_24.png b/res/drawable-xxxhdpi/ic_shield_white_24.png
new file mode 100644
index 0000000..8b9f129
--- /dev/null
+++ b/res/drawable-xxxhdpi/ic_shield_white_24.png
Binary files differ
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b60d85f..6b7a105 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1152,6 +1152,19 @@
emergency calling is not currently available. -->
<string name="dial_emergency_calling_not_available">Emergency calling not available</string>
+ <!-- Text for description of police calling type -->
+ <string name="police_type_description">Police</string>
+ <!-- Text for description of ambulance calling type -->
+ <string name="ambulance_type_description">Ambulance</string>
+ <!-- Text for description of fire calling type -->
+ <string name="fire_type_description">Fire</string>
+
+ <!-- Format for concatenating multiple emergency type descriptions. The separator may differ in
+ different locales, for example arabic comma "،" is used in some countries. Some languages
+ may use full-width separator without leading or trailing spaces, eg. Ideographic comma "、"
+ in Chinese and Japanese. -->
+ <string name="description_concat_format">%1$s, %2$s</string>
+
<!-- Displayed in the text entry box in the dialer when in landscape mode to guide the user
to dial using the physical keyboard -->
<string name="dialerKeyboardHintText">Use keyboard to dial</string>
diff --git a/src/com/android/phone/CellInfoUtil.java b/src/com/android/phone/CellInfoUtil.java
index 2c5f2a8..462cafe 100644
--- a/src/com/android/phone/CellInfoUtil.java
+++ b/src/com/android/phone/CellInfoUtil.java
@@ -26,7 +26,6 @@
import android.telephony.CellInfoGsm;
import android.telephony.CellInfoLte;
import android.telephony.CellInfoWcdma;
-import android.telephony.TelephonyManager;
import android.text.BidiFormatter;
import android.text.TextDirectionHeuristics;
import android.text.TextUtils;
@@ -47,47 +46,6 @@
}
/**
- * Get the network type from a CellInfo. Network types include
- * {@link TelephonyManager#NETWORK_TYPE_LTE}, {@link TelephonyManager#NETWORK_TYPE_UMTS},
- * {@link TelephonyManager#NETWORK_TYPE_GSM}, {@link TelephonyManager#NETWORK_TYPE_CDMA} and
- * {@link TelephonyManager#NETWORK_TYPE_UNKNOWN}
- * @return network types
- */
- public static int getNetworkType(CellInfo cellInfo) {
- if (cellInfo instanceof CellInfoLte) {
- return TelephonyManager.NETWORK_TYPE_LTE;
- } else if (cellInfo instanceof CellInfoWcdma) {
- return TelephonyManager.NETWORK_TYPE_UMTS;
- } else if (cellInfo instanceof CellInfoGsm) {
- return TelephonyManager.NETWORK_TYPE_GSM;
- } else if (cellInfo instanceof CellInfoCdma) {
- return TelephonyManager.NETWORK_TYPE_CDMA;
- } else {
- Log.e(TAG, "Invalid CellInfo type");
- return TelephonyManager.NETWORK_TYPE_UNKNOWN;
- }
- }
-
- /**
- * Get signal level as an int from 0..4.
- * @return Signal strength level
- */
- public static int getLevel(CellInfo cellInfo) {
- if (cellInfo instanceof CellInfoLte) {
- return ((CellInfoLte) cellInfo).getCellSignalStrength().getLevel();
- } else if (cellInfo instanceof CellInfoWcdma) {
- return ((CellInfoWcdma) cellInfo).getCellSignalStrength().getLevel();
- } else if (cellInfo instanceof CellInfoGsm) {
- return ((CellInfoGsm) cellInfo).getCellSignalStrength().getLevel();
- } else if (cellInfo instanceof CellInfoCdma) {
- return ((CellInfoCdma) cellInfo).getCellSignalStrength().getLevel();
- } else {
- Log.e(TAG, "Invalid CellInfo type");
- return 0;
- }
- }
-
- /**
* Wrap a CellIdentity into a CellInfo.
*/
public static CellInfo wrapCellInfoWithCellIdentity(CellIdentity cellIdentity) {
diff --git a/src/com/android/phone/EccShortcutAdapter.java b/src/com/android/phone/EccShortcutAdapter.java
new file mode 100644
index 0000000..deeb82f
--- /dev/null
+++ b/src/com/android/phone/EccShortcutAdapter.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright (C) 2018 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.phone;
+
+import android.content.Context;
+import android.text.TextUtils;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.android.phone.ecc.CountryEccInfo;
+import com.android.phone.ecc.EccInfo;
+
+import com.google.common.collect.LinkedListMultimap;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * An abstract adapter between ECC data and the view contains ECC shortcuts.
+ * This adapter will convert given {@link CountryEccInfo} to number string, description string and
+ * icon resource id for each {@link EccInfo}.
+ * The subclass should implements {@link #inflateView} to provide the view for an ECC data, when the
+ * view container calls {@link #getView}.
+ */
+public abstract class EccShortcutAdapter extends BaseAdapter {
+ // GSM default emergency number, used when country's fallback ECC(112 or 911) not available.
+ private static final String FALLBACK_EMERGENCY_NUMBER = "112";
+
+ private List<EccDisplayMaterial> mEccDisplayMaterialList;
+
+ private CharSequence mPoliceDescription;
+ private CharSequence mAmbulanceDescription;
+ private CharSequence mFireDescription;
+
+ private static class EccDisplayMaterial {
+ public CharSequence number = null;
+ public int iconRes = 0;
+ public CharSequence description = null;
+ }
+
+ public EccShortcutAdapter(@NonNull Context context) {
+ mPoliceDescription = context.getText(R.string.police_type_description);
+ mAmbulanceDescription = context.getText(R.string.ambulance_type_description);
+ mFireDescription = context.getText(R.string.fire_type_description);
+
+ mEccDisplayMaterialList = new ArrayList<>();
+ }
+
+ @Override
+ public int getCount() {
+ return mEccDisplayMaterialList.size();
+ }
+
+ @Override
+ public EccDisplayMaterial getItem(int position) {
+ return mEccDisplayMaterialList.get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ EccDisplayMaterial material = getItem(position);
+ return inflateView(convertView, parent, material.number, material.description,
+ material.iconRes);
+ }
+
+ /**
+ * Get a View that display the given ECC data: number, description and iconRes.
+ *
+ * @param convertView The old view to reuse, if possible. Note: You should check that this view
+ * is non-null and of an appropriate type before using. If it is not possible
+ * to convert this view to display the correct data, this method can create a
+ * new view. Heterogeneous lists can specify their number of view types, so
+ * that this View is always of the right type (see {@link
+ * BaseAdapter#getViewTypeCount()} and {@link
+ * BaseAdapter#getItemViewType(int)}).
+ * @param parent The parent that this view will eventually be attached to.
+ * @param number The number of the ECC shortcut to display in the view.
+ * @param description The description of the ECC shortcut to display in the view.
+ * @param iconRes The icon resource ID represent for the ECC shortcut.
+ * @return A View corresponding to the data at the specified position.
+ */
+ public abstract View inflateView(View convertView, ViewGroup parent, CharSequence number,
+ CharSequence description, int iconRes);
+
+ /**
+ * Update country ECC info. This method converts given country ECC info to ECC data that could
+ * be display by the short container View.
+ *
+ * @param context The context used to access resources.
+ * @param countryEccInfo Updated country ECC info.
+ */
+ public void updateCountryEccInfo(@NonNull Context context, CountryEccInfo countryEccInfo) {
+ List<EccDisplayMaterial> displayMaterials = new ArrayList<>();
+
+ final EccInfo.Type[] orderedMustHaveTypes =
+ { EccInfo.Type.POLICE, EccInfo.Type.AMBULANCE, EccInfo.Type.FIRE };
+
+ String fallback = null;
+ EccInfo[] eccInfoList = null;
+ if (countryEccInfo != null) {
+ fallback = countryEccInfo.getFallbackEcc();
+ eccInfoList = countryEccInfo.getEccInfoList();
+ }
+ if (TextUtils.isEmpty(fallback)) {
+ fallback = FALLBACK_EMERGENCY_NUMBER;
+ }
+
+ // Finding matched ECC for each must have types.
+ // Using LinkedListMultimap to prevent duplicated keys.
+ // LinkedListMultimap also preserve the insertion order of keys (ECC number) and values
+ // (matched types of the ECC number), which follows the order in orderedMustHaveTypes.
+ LinkedListMultimap<String, EccInfo.Type> eccList = LinkedListMultimap.create();
+ for (EccInfo.Type type : orderedMustHaveTypes) {
+ String number = null;
+ if (eccInfoList != null) {
+ number = pickEccNumberForType(type, eccInfoList);
+ }
+ if (number == null) {
+ number = fallback;
+ }
+ // append type for exist number, otherwise insert a new entry.
+ eccList.put(number, type);
+ }
+
+ // prepare display material for picked ECC
+ for (String number : eccList.keySet()) {
+ EccDisplayMaterial material = prepareDisplayMaterialForEccInfo(context,
+ new EccInfo(number, eccList.asMap().get(number)));
+ if (material != null) {
+ displayMaterials.add(material);
+ }
+ }
+
+ mEccDisplayMaterialList = displayMaterials;
+ notifyDataSetChanged();
+ }
+
+ private @Nullable String pickEccNumberForType(@NonNull EccInfo.Type targetType,
+ @NonNull EccInfo[] eccInfoList) {
+ EccInfo pickedEccInfo = null;
+ for (EccInfo eccInfo : eccInfoList) {
+ if (eccInfo.containsType(targetType)) {
+ // An ECC is more suitable for a type if the ECC has fewer other types.
+ if (pickedEccInfo == null
+ || eccInfo.getTypesCount() < pickedEccInfo.getTypesCount()) {
+ pickedEccInfo = eccInfo;
+ }
+ }
+ }
+ if (pickedEccInfo != null) {
+ return pickedEccInfo.getNumber();
+ }
+ return null;
+ }
+
+ private @Nullable EccDisplayMaterial prepareDisplayMaterialForEccInfo(@NonNull Context context,
+ @NonNull EccInfo eccInfo) {
+ EccDisplayMaterial material = new EccDisplayMaterial();
+ material.number = eccInfo.getNumber();
+ EccInfo.Type[] types = eccInfo.getTypes();
+ for (EccInfo.Type type : types) {
+ CharSequence description;
+ switch (type) {
+ case POLICE:
+ description = mPoliceDescription;
+ material.iconRes = R.drawable.ic_shield_white_24;
+ break;
+ case AMBULANCE:
+ description = mAmbulanceDescription;
+ material.iconRes = R.drawable.ic_emergency_number_24;
+ break;
+ case FIRE:
+ description = mFireDescription;
+ material.iconRes = R.drawable.ic_fire_white_24;
+ break;
+ default:
+ // ignore unknown types
+ continue;
+ }
+ if (TextUtils.isEmpty(material.description)) {
+ material.description = description;
+ } else {
+ // concatenate multiple types
+ material.iconRes = R.drawable.ic_emergency_number_24;
+ material.description = context.getString(R.string.description_concat_format,
+ material.description, description);
+ }
+ }
+ if (TextUtils.isEmpty(material.description) || material.iconRes == 0) {
+ return null;
+ }
+ return material;
+ }
+
+}
diff --git a/src/com/android/phone/EmergencyDialer.java b/src/com/android/phone/EmergencyDialer.java
index fc4ef6a..a89b52d 100644
--- a/src/com/android/phone/EmergencyDialer.java
+++ b/src/com/android/phone/EmergencyDialer.java
@@ -28,6 +28,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.database.DataSetObserver;
import android.graphics.Color;
import android.graphics.Point;
import android.media.AudioManager;
@@ -70,9 +71,12 @@
import com.android.phone.common.dialpad.DialpadKeyButton;
import com.android.phone.common.util.ViewUtil;
import com.android.phone.common.widget.ResizingTextEditText;
+import com.android.phone.ecc.CountryEccInfo;
+import com.android.phone.ecc.EccInfoHelper;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
/**
* EmergencyDialer is a special dialer that is used ONLY for dialing emergency calls.
@@ -135,13 +139,20 @@
/** 85% opacity for black background **/
private static final int BLACK_BACKGROUND_GRADIENT_ALPHA = 217;
+ /** Size limit of emergency shortcut buttons container. **/
+ private static final int SHORTCUT_SIZE_LIMIT = 3;
+
ResizingTextEditText mDigits;
private View mDialButton;
private View mDelete;
private View mEmergencyShortcutView;
private View mDialpadView;
+ private EccInfoHelper mEccInfoHelper;
+
private List<EmergencyShortcutButton> mEmergencyShortcutButtonList;
+ private EccShortcutAdapter mShortcutAdapter;
+ private DataSetObserver mShortcutDataSetObserver = null;
private ToneGenerator mToneGenerator;
private Object mToneGeneratorLock = new Object();
@@ -214,6 +225,8 @@
mAreEmergencyDialerShortcutsEnabled = Settings.Global.getInt(getContentResolver(),
Settings.Global.FASTER_EMERGENCY_PHONE_CALL_ENABLED, 0) != 0;
+ Log.d(LOG_TAG, "Enable emergency dialer shortcut: "
+ + mAreEmergencyDialerShortcutsEnabled);
mColorExtractor = new ColorExtractor(this);
@@ -325,6 +338,10 @@
}
}
unregisterReceiver(mBroadcastReceiver);
+ if (mShortcutAdapter != null && mShortcutDataSetObserver != null) {
+ mShortcutAdapter.unregisterDataSetObserver(mShortcutDataSetObserver);
+ mShortcutDataSetObserver = null;
+ }
}
@Override
@@ -587,6 +604,32 @@
mBackgroundGradient.setColors(lockScreenColors, false);
updateTheme(lockScreenColors.supportsDarkText());
}
+
+ if (mAreEmergencyDialerShortcutsEnabled && mEccInfoHelper != null) {
+ final Context context = this;
+ mEccInfoHelper.getCountryEccInfoAsync(context,
+ new EccInfoHelper.CountryEccInfoResultCallback() {
+ @Override
+ public void onSuccess(String iso, CountryEccInfo countryEccInfo) {
+ Log.d(LOG_TAG, "Retrieve ECC info success, country ISO: "
+ + Rlog.pii(LOG_TAG, iso));
+ updateLocationAndEccInfo(iso, countryEccInfo);
+ }
+
+ @Override
+ public void onDetectCountryFailed() {
+ Log.w(LOG_TAG, "Cannot detect current country.");
+ updateLocationAndEccInfo(null, null);
+ }
+
+ @Override
+ public void onRetrieveCountryEccInfoFailed(String iso) {
+ Log.w(LOG_TAG, "Retrieve ECC info failed, country ISO: "
+ + Rlog.pii(LOG_TAG, iso));
+ updateLocationAndEccInfo(iso, null);
+ }
+ });
+ }
}
@Override
@@ -895,53 +938,94 @@
final View emergencyDialpadTitle = findViewById(R.id.emergency_dialpad_title_container);
emergencyDialpadTitle.setVisibility(View.VISIBLE);
- // TODO: Integrating emergency phone number table will get location information.
- // Using null to present no location status.
- setLocationInfo(null);
-
mEmergencyShortcutButtonList = new ArrayList<>();
setupEmergencyCallShortcutButton();
+ updateLocationAndEccInfo(null, null);
+
switchView(mEmergencyShortcutView, mDialpadView, false);
}
- private void setLocationInfo(String country) {
+ private void setLocationInfo(String countryIso) {
final View locationInfo = findViewById(R.id.location_info);
- if (TextUtils.isEmpty(country)) {
+ String countryName = null;
+ if (!TextUtils.isEmpty(countryIso)) {
+ Locale locale = Locale.getDefault();
+ countryName = new Locale(locale.getLanguage(), countryIso, locale.getVariant())
+ .getDisplayCountry();
+ }
+ if (TextUtils.isEmpty(countryName)) {
locationInfo.setVisibility(View.INVISIBLE);
} else {
final TextView location = (TextView) locationInfo.findViewById(R.id.location_text);
- location.setText(country);
+ location.setText(countryName);
locationInfo.setVisibility(View.VISIBLE);
}
}
- // TODO: Integrate emergency phone number table.
- // Using default layout(no location, phone number is 112, description is Emergency,
- // and icon is cross shape) until integrating emergency phone number table.
private void setupEmergencyCallShortcutButton() {
final ViewGroup shortcutButtonContainer = findViewById(
R.id.emergency_shortcut_buttons_container);
shortcutButtonContainer.setClipToOutline(true);
+ final TextView emergencyNumberTitle = findViewById(R.id.emergency_number_title);
- final EmergencyShortcutButton button =
- (EmergencyShortcutButton) getLayoutInflater().inflate(
- R.layout.emergency_shortcut_button,
- shortcutButtonContainer, false);
+ mShortcutAdapter = new EccShortcutAdapter(this) {
+ @Override
+ public View inflateView(View convertView, ViewGroup parent, CharSequence number,
+ CharSequence description, int iconRes) {
+ EmergencyShortcutButton button = (EmergencyShortcutButton) getLayoutInflater()
+ .inflate(R.layout.emergency_shortcut_button, parent, false);
+ button.setPhoneNumber(number);
+ button.setPhoneDescription(description);
+ button.setPhoneTypeIcon(iconRes);
+ button.setOnConfirmClickListener(EmergencyDialer.this);
+ return button;
+ }
+ };
+ mShortcutDataSetObserver = new DataSetObserver() {
+ @Override
+ public void onChanged() {
+ super.onChanged();
+ updateLayout();
+ }
- button.setPhoneNumber("112");
- button.setPhoneDescription("Emergency");
- button.setPhoneTypeIcon(R.drawable.ic_emergency_number_24);
- button.setOnConfirmClickListener(this);
+ @Override
+ public void onInvalidated() {
+ super.onInvalidated();
+ updateLayout();
+ }
- shortcutButtonContainer.addView(button);
- mEmergencyShortcutButtonList.add(button);
+ private void updateLayout() {
+ // clear previous added buttons
+ shortcutButtonContainer.removeAllViews();
+ mEmergencyShortcutButtonList.clear();
- //Set emergency number title for numerous buttons.
- if (shortcutButtonContainer.getChildCount() > 1) {
- final TextView emergencyNumberTitle = findViewById(R.id.emergency_number_title);
- emergencyNumberTitle.setText(getString(R.string.numerous_emergency_numbers_title));
+ for (int i = 0; i < mShortcutAdapter.getCount() && i < SHORTCUT_SIZE_LIMIT; ++i) {
+ EmergencyShortcutButton button = (EmergencyShortcutButton)
+ mShortcutAdapter.getView(i, null, shortcutButtonContainer);
+ mEmergencyShortcutButtonList.add(button);
+ shortcutButtonContainer.addView(button);
+ }
+
+ // update emergency numbers title for numerous buttons.
+ if (mEmergencyShortcutButtonList.size() > 1) {
+ emergencyNumberTitle.setText(getString(
+ R.string.numerous_emergency_numbers_title));
+ } else {
+ emergencyNumberTitle.setText(getText(R.string.single_emergency_number_title));
+ }
+ }
+ };
+ mShortcutAdapter.registerDataSetObserver(mShortcutDataSetObserver);
+ }
+
+ private void updateLocationAndEccInfo(String iso, CountryEccInfo countryEccInfo) {
+ if (!isFinishing() && !isDestroyed()) {
+ setLocationInfo(iso);
+ if (mShortcutAdapter != null) {
+ mShortcutAdapter.updateCountryEccInfo(this, countryEccInfo);
+ }
}
}
diff --git a/src/com/android/phone/EmergencyShortcutButton.java b/src/com/android/phone/EmergencyShortcutButton.java
index 92877c7..275dac0 100644
--- a/src/com/android/phone/EmergencyShortcutButton.java
+++ b/src/com/android/phone/EmergencyShortcutButton.java
@@ -103,14 +103,14 @@
/**
* Set emergency phone number description.
*/
- public void setPhoneDescription(@NonNull String description) {
+ public void setPhoneDescription(@NonNull CharSequence description) {
mPhoneTypeDescription.setText(description);
}
/**
* Set emergency phone number.
*/
- public void setPhoneNumber(@NonNull String number) {
+ public void setPhoneNumber(@NonNull CharSequence number) {
mPhoneNumber.setText(number);
mPhoneCallHint.setText(
getContext().getString(R.string.emergency_call_shortcut_hint, number));
@@ -118,7 +118,7 @@
// Set content description for phone number.
if (number.length() > 1) {
StringBuilder stringBuilder = new StringBuilder();
- for (char c : number.toCharArray()) {
+ for (char c : number.toString().toCharArray()) {
stringBuilder.append(c).append(" ");
}
mPhoneNumber.setContentDescription(stringBuilder.toString().trim());
diff --git a/src/com/android/phone/GsmUmtsAdditionalCallOptions.java b/src/com/android/phone/GsmUmtsAdditionalCallOptions.java
index 082eaa9..b79cdd8 100644
--- a/src/com/android/phone/GsmUmtsAdditionalCallOptions.java
+++ b/src/com/android/phone/GsmUmtsAdditionalCallOptions.java
@@ -2,8 +2,10 @@
import android.app.ActionBar;
import android.os.Bundle;
+import android.os.PersistableBundle;
import android.preference.Preference;
import android.preference.PreferenceScreen;
+import android.telephony.CarrierConfigManager;
import android.util.Log;
import android.view.MenuItem;
@@ -26,6 +28,9 @@
private Phone mPhone;
private SubscriptionInfoHelper mSubscriptionInfoHelper;
+ private boolean mShowCLIRButton;
+ private boolean mShowCWButton;
+
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
@@ -41,24 +46,60 @@
mCLIRButton = (CLIRListPreference) prefSet.findPreference(BUTTON_CLIR_KEY);
mCWButton = (CallWaitingSwitchPreference) prefSet.findPreference(BUTTON_CW_KEY);
- mPreferences.add(mCLIRButton);
- mPreferences.add(mCWButton);
-
- if (icicle == null) {
- if (DBG) Log.d(LOG_TAG, "start to init ");
- mCLIRButton.init(this, false, mPhone);
+ PersistableBundle b = null;
+ if (mSubscriptionInfoHelper.hasSubId()) {
+ b = PhoneGlobals.getInstance().getCarrierConfigForSubId(
+ mSubscriptionInfoHelper.getSubId());
} else {
- if (DBG) Log.d(LOG_TAG, "restore stored states");
- mInitIndex = mPreferences.size();
- mCLIRButton.init(this, true, mPhone);
- mCWButton.init(this, true, mPhone);
- int[] clirArray = icicle.getIntArray(mCLIRButton.getKey());
- if (clirArray != null) {
- if (DBG) Log.d(LOG_TAG, "onCreate: clirArray[0]="
- + clirArray[0] + ", clirArray[1]=" + clirArray[1]);
- mCLIRButton.handleGetCLIRResult(clirArray);
+ b = PhoneGlobals.getInstance().getCarrierConfig();
+ }
+
+ if (b != null) {
+ mShowCLIRButton = b.getBoolean(
+ CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALLER_ID_VISIBILITY_BOOL);
+ mShowCWButton = b.getBoolean(
+ CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALL_WAITING_VISIBILITY_BOOL);
+ }
+
+ if (mCLIRButton != null) {
+ if (mShowCLIRButton) {
+ mPreferences.add(mCLIRButton);
} else {
- mCLIRButton.init(this, false, mPhone);
+ prefSet.removePreference(mCLIRButton);
+ }
+ }
+
+ if (mCWButton != null) {
+ if (mShowCWButton) {
+ mPreferences.add(mCWButton);
+ } else {
+ prefSet.removePreference(mCWButton);
+ }
+ }
+
+ if (mPreferences.size() != 0) {
+ if (icicle == null) {
+ if (DBG) Log.d(LOG_TAG, "start to init ");
+ doPreferenceInit(mInitIndex);
+ } else {
+ if (DBG) Log.d(LOG_TAG, "restore stored states");
+ mInitIndex = mPreferences.size();
+ if (mShowCWButton) {
+ mCWButton.init(this, true, mPhone);
+ }
+ if (mShowCLIRButton) {
+ mCLIRButton.init(this, true, mPhone);
+ int[] clirArray = icicle.getIntArray(mCLIRButton.getKey());
+ if (clirArray != null) {
+ if (DBG) {
+ Log.d(LOG_TAG, "onCreate: clirArray[0]="
+ + clirArray[0] + ", clirArray[1]=" + clirArray[1]);
+ }
+ mCLIRButton.handleGetCLIRResult(clirArray);
+ } else {
+ mCLIRButton.init(this, false, mPhone);
+ }
+ }
}
}
@@ -73,7 +114,7 @@
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
- if (mCLIRButton.clirArray != null) {
+ if (mShowCLIRButton && mCLIRButton.clirArray != null) {
outState.putIntArray(mCLIRButton.getKey(), mCLIRButton.clirArray);
}
}
@@ -82,10 +123,7 @@
public void onFinished(Preference preference, boolean reading) {
if (mInitIndex < mPreferences.size()-1 && !isFinishing()) {
mInitIndex++;
- Preference pref = mPreferences.get(mInitIndex);
- if (pref instanceof CallWaitingSwitchPreference) {
- ((CallWaitingSwitchPreference) pref).init(this, false, mPhone);
- }
+ doPreferenceInit(mInitIndex);
}
super.onFinished(preference, reading);
}
@@ -99,4 +137,15 @@
}
return super.onOptionsItemSelected(item);
}
+
+ private void doPreferenceInit(int index) {
+ if (mPreferences.size() != 0) {
+ Preference pref = mPreferences.get(index);
+ if (pref instanceof CallWaitingSwitchPreference) {
+ ((CallWaitingSwitchPreference) pref).init(this, false, mPhone);
+ } else if (pref instanceof CLIRListPreference) {
+ ((CLIRListPreference) pref).init(this, false, mPhone);
+ }
+ }
+ }
}
diff --git a/src/com/android/phone/GsmUmtsCallBarringOptions.java b/src/com/android/phone/GsmUmtsCallBarringOptions.java
index 4b875ee..a6f9844 100644
--- a/src/com/android/phone/GsmUmtsCallBarringOptions.java
+++ b/src/com/android/phone/GsmUmtsCallBarringOptions.java
@@ -18,12 +18,15 @@
import android.app.ActionBar;
import android.app.Dialog;
+import android.content.Context;
import android.os.AsyncResult;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
+import android.os.PersistableBundle;
import android.preference.Preference;
import android.preference.PreferenceScreen;
+import android.telephony.CarrierConfigManager;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
@@ -360,6 +363,25 @@
Log.d(LOG_TAG, "onCreate, reading callbarring_options.xml file finished!");
}
+ CarrierConfigManager configManager = (CarrierConfigManager)
+ mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
+ PersistableBundle carrierConfig;
+ if (mSubscriptionInfoHelper.hasSubId()) {
+ carrierConfig = configManager.getConfigForSubId(mSubscriptionInfoHelper.getSubId());
+ } else {
+ carrierConfig = configManager.getConfig();
+ }
+ boolean isPwChangeButtonVisible = true;
+ boolean isDisableAllButtonVisible = true;
+ if (carrierConfig != null) {
+ isPwChangeButtonVisible = carrierConfig.getBoolean(
+ CarrierConfigManager.KEY_CALL_BARRING_SUPPORTS_PASSWORD_CHANGE_BOOL, true);
+ isDisableAllButtonVisible = carrierConfig.getBoolean(
+ CarrierConfigManager.KEY_CALL_BARRING_SUPPORTS_DEACTIVATE_ALL_BOOL, true);
+ } else {
+ Log.w(LOG_TAG, "Couldn't access CarrierConfig bundle");
+ }
+
// Get UI object references
PreferenceScreen prefSet = getPreferenceScreen();
mButtonBAOC = (CallBarringEditPreference) prefSet.findPreference(BUTTON_BAOC_KEY);
@@ -371,6 +393,15 @@
prefSet.findPreference(BUTTON_BA_ALL_KEY);
mButtonChangePW = (EditPinPreference) prefSet.findPreference(BUTTON_BA_CHANGE_PW_KEY);
+ // Some carriers do not use PW change and disable all buttons. Hide them if this is the
+ // case.
+ if (!isDisableAllButtonVisible) {
+ prefSet.removePreference(mButtonDisableAll);
+ }
+ if (!isPwChangeButtonVisible) {
+ prefSet.removePreference(mButtonChangePW);
+ }
+
// Assign click listener and update state
mButtonBAOC.setOnPinEnteredListener(this);
mButtonBAOIC.setOnPinEnteredListener(this);
diff --git a/src/com/android/phone/GsmUmtsCallOptions.java b/src/com/android/phone/GsmUmtsCallOptions.java
index 5358db9..ab44b54 100644
--- a/src/com/android/phone/GsmUmtsCallOptions.java
+++ b/src/com/android/phone/GsmUmtsCallOptions.java
@@ -62,25 +62,45 @@
}
public static void init(PreferenceScreen prefScreen, SubscriptionInfoHelper subInfoHelper) {
- Preference callForwardingPref = prefScreen.findPreference(CALL_FORWARDING_KEY);
- callForwardingPref.setIntent(subInfoHelper.getIntent(GsmUmtsCallForwardOptions.class));
-
- Preference additionalGsmSettingsPref =
- prefScreen.findPreference(ADDITIONAL_GSM_SETTINGS_KEY);
- additionalGsmSettingsPref.setIntent(
- subInfoHelper.getIntent(GsmUmtsAdditionalCallOptions.class));
-
- Preference callBarringPref = prefScreen.findPreference(CALL_BARRING_KEY);
PersistableBundle b = null;
if (subInfoHelper.hasSubId()) {
b = PhoneGlobals.getInstance().getCarrierConfigForSubId(subInfoHelper.getSubId());
} else {
b = PhoneGlobals.getInstance().getCarrierConfig();
}
- if (b != null && b.getBoolean(CarrierConfigManager.KEY_CALL_BARRING_VISIBILITY_BOOL)) {
- callBarringPref.setIntent(subInfoHelper.getIntent(GsmUmtsCallBarringOptions.class));
- } else {
- prefScreen.removePreference(callBarringPref);
+
+ Preference callForwardingPref = prefScreen.findPreference(CALL_FORWARDING_KEY);
+ if (callForwardingPref != null) {
+ if (b != null && b.getBoolean(
+ CarrierConfigManager.KEY_CALL_FORWARDING_VISIBILITY_BOOL)) {
+ callForwardingPref.setIntent(
+ subInfoHelper.getIntent(GsmUmtsCallForwardOptions.class));
+ } else {
+ prefScreen.removePreference(callForwardingPref);
+ }
+ }
+
+ Preference additionalGsmSettingsPref =
+ prefScreen.findPreference(ADDITIONAL_GSM_SETTINGS_KEY);
+ if (additionalGsmSettingsPref != null) {
+ if (b != null && (b.getBoolean(
+ CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALL_WAITING_VISIBILITY_BOOL)
+ || b.getBoolean(
+ CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALLER_ID_VISIBILITY_BOOL))) {
+ additionalGsmSettingsPref.setIntent(
+ subInfoHelper.getIntent(GsmUmtsAdditionalCallOptions.class));
+ } else {
+ prefScreen.removePreference(additionalGsmSettingsPref);
+ }
+ }
+
+ Preference callBarringPref = prefScreen.findPreference(CALL_BARRING_KEY);
+ if (callBarringPref != null) {
+ if (b != null && b.getBoolean(CarrierConfigManager.KEY_CALL_BARRING_VISIBILITY_BOOL)) {
+ callBarringPref.setIntent(subInfoHelper.getIntent(GsmUmtsCallBarringOptions.class));
+ } else {
+ prefScreen.removePreference(callBarringPref);
+ }
}
}
}
diff --git a/src/com/android/phone/NetworkOperatorPreference.java b/src/com/android/phone/NetworkOperatorPreference.java
index 85adf16..e582924 100644
--- a/src/com/android/phone/NetworkOperatorPreference.java
+++ b/src/com/android/phone/NetworkOperatorPreference.java
@@ -24,7 +24,6 @@
import android.preference.Preference;
import android.telephony.CellInfo;
import android.telephony.SignalStrength;
-import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Gravity;
@@ -71,7 +70,7 @@
networkTitle += " " + getContext().getResources().getString(R.string.forbidden_network);
}
setTitle(networkTitle);
- int level = CellInfoUtil.getLevel(mCellInfo);
+ int level = mCellInfo.getCellSignalStrength().getLevel();
if (DBG) Log.d(TAG, "refresh level: " + String.valueOf(level));
if (mLevel != level) {
mLevel = level;
@@ -86,17 +85,15 @@
updateIcon(level);
}
- private int getIconId(int networkType) {
- if (networkType == TelephonyManager.NETWORK_TYPE_CDMA) {
- return R.drawable.signal_strength_1x;
- } else if (networkType == TelephonyManager.NETWORK_TYPE_LTE) {
- return R.drawable.signal_strength_lte;
- } else if (networkType == TelephonyManager.NETWORK_TYPE_UMTS) {
- return R.drawable.signal_strength_3g;
- } else if (networkType == TelephonyManager.NETWORK_TYPE_GSM) {
- return R.drawable.signal_strength_g;
- } else {
- return 0;
+ private static int getIconIdForCell(CellInfo ci) {
+ final int type = ci.getCellIdentity().getType();
+ switch (type) {
+ case CellInfo.TYPE_GSM: return R.drawable.signal_strength_g;
+ case CellInfo.TYPE_WCDMA: // fall through
+ case CellInfo.TYPE_TDSCDMA: return R.drawable.signal_strength_3g;
+ case CellInfo.TYPE_LTE: return R.drawable.signal_strength_lte;
+ case CellInfo.TYPE_CDMA: return R.drawable.signal_strength_1x;
+ default: return 0;
}
}
@@ -113,7 +110,7 @@
signalDrawable.setDarkIntensity(0);
// Make the network type drawable
- int iconType = getIconId(CellInfoUtil.getNetworkType(mCellInfo));
+ int iconType = getIconIdForCell(mCellInfo);
Drawable networkDrawable =
iconType == NO_CELL_DATA_CONNECTED_ICON
? EMPTY_DRAWABLE
diff --git a/src/com/android/phone/NetworkSelectSetting.java b/src/com/android/phone/NetworkSelectSetting.java
index 96e4a26..6bb42c8 100644
--- a/src/com/android/phone/NetworkSelectSetting.java
+++ b/src/com/android/phone/NetworkSelectSetting.java
@@ -560,8 +560,8 @@
map.put(plmn, cellInfo);
} else {
if (map.get(plmn).isRegistered()
- || CellInfoUtil.getLevel(map.get(plmn))
- > CellInfoUtil.getLevel(cellInfo)) {
+ || map.get(plmn).getCellSignalStrength().getLevel()
+ > cellInfo.getCellSignalStrength().getLevel()) {
// Skip if the stored cellInfo is registered or has higher signal strength level
continue;
}
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index a97c4b3..51ffbd8 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -1922,7 +1922,10 @@
@SuppressWarnings("unchecked")
public List<NeighboringCellInfo>
getNeighboringCellInfo(String callingPackage, int targetSdk) {
- if (targetSdk > android.os.Build.VERSION_CODES.P) return null;
+ if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
+ throw new SecurityException(
+ "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
+ }
if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
callingPackage) != AppOpsManager.MODE_ALLOWED) {
@@ -4359,7 +4362,7 @@
synchronized (mLastModemActivityInfo) {
ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
null);
- if (info != null) {
+ if (isModemActivityInfoValid(info)) {
int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
for (int i = 0; i < mergedTxTimeMs.length; i++) {
mergedTxTimeMs[i] =
@@ -4391,6 +4394,25 @@
}
}
+ // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
+ // less than total activity duration.
+ private boolean isModemActivityInfoValid(ModemActivityInfo info) {
+ if (info == null) {
+ return false;
+ }
+ int activityDurationMs =
+ (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
+ int totalTxTimeMs = 0;
+ for (int i = 0; i < info.getTxTimeMillis().length; i++) {
+ totalTxTimeMs += info.getTxTimeMillis()[i];
+ }
+ return (info.isValid()
+ && (info.getSleepTimeMillis() <= activityDurationMs)
+ && (info.getIdleTimeMillis() <= activityDurationMs)
+ && (info.getRxTimeMillis() <= activityDurationMs)
+ && (totalTxTimeMs <= activityDurationMs));
+ }
+
/**
* {@hide}
* Returns the service state information on specified subscription.
diff --git a/src/com/android/phone/ecc/CountryEccInfo.java b/src/com/android/phone/ecc/CountryEccInfo.java
index 6bef8d3..969901d 100644
--- a/src/com/android/phone/ecc/CountryEccInfo.java
+++ b/src/com/android/phone/ecc/CountryEccInfo.java
@@ -19,7 +19,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
-import java.util.List;
+import java.util.Collection;
/**
* ECC info of a country.
@@ -28,7 +28,7 @@
private final String mFallbackEcc;
private final EccInfo[] mEccInfoList;
- public CountryEccInfo(String eccFallback, @NonNull List<EccInfo> eccInfoList) {
+ public CountryEccInfo(String eccFallback, @NonNull Collection<EccInfo> eccInfoList) {
mFallbackEcc = eccFallback;
mEccInfoList = eccInfoList.toArray(new EccInfo[eccInfoList.size()]);
}
diff --git a/src/com/android/phone/ecc/EccInfo.java b/src/com/android/phone/ecc/EccInfo.java
index d047b9b..fb41370 100644
--- a/src/com/android/phone/ecc/EccInfo.java
+++ b/src/com/android/phone/ecc/EccInfo.java
@@ -18,7 +18,7 @@
import androidx.annotation.NonNull;
-import java.util.List;
+import java.util.Collection;
/**
* Emergency call code info.
@@ -41,7 +41,7 @@
mTypes = new Type[]{ type };
}
- public EccInfo(@NonNull String number, @NonNull List<Type> types) {
+ public EccInfo(@NonNull String number, @NonNull Collection<Type> types) {
mNumber = number;
mTypes = types.toArray(new Type[types.size()]);
}
diff --git a/src/com/android/phone/ecc/EccInfoHelper.java b/src/com/android/phone/ecc/EccInfoHelper.java
index 514f388..cd47dde 100644
--- a/src/com/android/phone/ecc/EccInfoHelper.java
+++ b/src/com/android/phone/ecc/EccInfoHelper.java
@@ -27,6 +27,7 @@
import android.telephony.CellInfoLte;
import android.telephony.CellInfoWcdma;
import android.telephony.PhoneNumberUtils;
+import android.telephony.Rlog;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
@@ -45,6 +46,8 @@
* Helper for retrieve ECC info for current country.
*/
public class EccInfoHelper {
+ // Debug constants.
+ private static final boolean DBG = false;
private static final String LOG_TAG = "EccInfoHelper";
// country ISO to ECC list data source
@@ -164,14 +167,17 @@
TelephonyManager tm = (TelephonyManager) context.getSystemService(
Context.TELEPHONY_SERVICE);
String iso = tm.getNetworkCountryIso();
- Log.d(LOG_TAG, "Current country ISO is " + iso);
+ if (DBG) Log.d(LOG_TAG, "Current country ISO is " + Rlog.pii(LOG_TAG, iso));
if (TextUtils.isEmpty(iso)) {
// XXX: according to ServiceStateTracker's implementation, retrieve cell info in a
// thread other than TelephonyManager's main thread.
String mcc = getCurrentMccFromCellInfo(context);
iso = MccTable.countryCodeForMcc(mcc);
- Log.d(LOG_TAG, "Current mcc is " + mcc + ", mapping to ISO: " + iso);
+ if (DBG) {
+ Log.d(LOG_TAG, "Current mcc is " + Rlog.pii(LOG_TAG, mcc) + ", mapping to ISO: "
+ + Rlog.pii(LOG_TAG, iso));
+ }
}
return iso;
}
@@ -204,7 +210,7 @@
break;
}
}
- Log.d(LOG_TAG, "Retrieve MCC from cell info list: " + mcc);
+ if (DBG) Log.d(LOG_TAG, "Retrieve MCC from cell info list: " + Rlog.pii(LOG_TAG, mcc));
} else {
Log.w(LOG_TAG, "Cannot get cell info list.");
}
diff --git a/src/com/android/services/telephony/TelephonyConnection.java b/src/com/android/services/telephony/TelephonyConnection.java
index 409eb47..6904874 100644
--- a/src/com/android/services/telephony/TelephonyConnection.java
+++ b/src/com/android/services/telephony/TelephonyConnection.java
@@ -1034,7 +1034,13 @@
updateConnectionCapabilities();
updateConnectionProperties();
if (mOriginalConnection != null) {
- Uri address = getAddressFromNumber(mOriginalConnection.getAddress());
+ Uri address;
+ if (isShowingOriginalDialString()
+ && mOriginalConnection.getOrigDialString() != null) {
+ address = getAddressFromNumber(mOriginalConnection.getOrigDialString());
+ } else {
+ address = getAddressFromNumber(mOriginalConnection.getAddress());
+ }
int presentation = mOriginalConnection.getNumberPresentation();
if (!Objects.equals(address, getAddress()) ||
presentation != getAddressPresentation()) {
@@ -1069,6 +1075,15 @@
void setOriginalConnection(com.android.internal.telephony.Connection originalConnection) {
Log.v(this, "new TelephonyConnection, originalConnection: " + originalConnection);
+ if (mOriginalConnection != null && originalConnection != null
+ && !originalConnection.isIncoming()
+ && originalConnection.getOrigDialString() == null
+ && isShowingOriginalDialString()) {
+ Log.i(this, "new original dial string is null, convert to: "
+ + mOriginalConnection.getOrigDialString());
+ originalConnection.setConverted(mOriginalConnection.getOrigDialString());
+ }
+
clearOriginalConnection();
mOriginalConnectionExtras.clear();
mOriginalConnection = originalConnection;
@@ -2167,6 +2182,21 @@
return Collections.unmodifiableMap(result);
}
+ private boolean isShowingOriginalDialString() {
+ boolean showOrigDialString = false;
+ Phone phone = getPhone();
+ if (phone != null && (phone.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA)
+ && !mOriginalConnection.isIncoming()) {
+ PersistableBundle pb = getCarrierConfig();
+ if (pb != null) {
+ showOrigDialString = pb.getBoolean(CarrierConfigManager
+ .KEY_CONFIG_SHOW_ORIG_DIAL_STRING_FOR_CDMA_BOOL);
+ Log.d(this, "showOrigDialString: " + showOrigDialString);
+ }
+ }
+ return showOrigDialString;
+ }
+
/**
* Creates a string representation of this {@link TelephonyConnection}. Primarily intended for
* use in log statements.