diff options
author | Xin Li <delphij@google.com> | 2017-11-13 14:35:42 -0800 |
---|---|---|
committer | Xin Li <delphij@google.com> | 2017-11-13 14:35:42 -0800 |
commit | 401377541a60fcc77f1fbdd25b375a8d85bbf4bd (patch) | |
tree | fe995e225b8d1da2320171586bb549746f97a20f /src/com/android/contacts | |
parent | ec84224dd6b9533a1bc907fb5793bfe5de606b1c (diff) | |
parent | a7e92c297e6380917411f7271b036d724fd00b14 (diff) | |
download | packages_apps_Contacts-401377541a60fcc77f1fbdd25b375a8d85bbf4bd.tar.gz packages_apps_Contacts-401377541a60fcc77f1fbdd25b375a8d85bbf4bd.tar.bz2 packages_apps_Contacts-401377541a60fcc77f1fbdd25b375a8d85bbf4bd.zip |
Merge commit 'a7e92c297e6380917411f7271b036d724fd00b14' into HEAD
Change-Id: I6a87aa70ccb73422ca581fe6b0a0968ff7e34989
Diffstat (limited to 'src/com/android/contacts')
5 files changed, 123 insertions, 30 deletions
diff --git a/src/com/android/contacts/CallUtil.java b/src/com/android/contacts/CallUtil.java index 717276642..bba1faa94 100644 --- a/src/com/android/contacts/CallUtil.java +++ b/src/com/android/contacts/CallUtil.java @@ -19,18 +19,23 @@ package com.android.contacts; import android.content.Context; import android.content.Intent; import android.net.Uri; +import android.os.Bundle; +import android.os.PersistableBundle; import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; import android.telecom.TelecomManager; import android.telecom.VideoProfile; +import android.telephony.CarrierConfigManager; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; +import android.util.Log; import com.android.contacts.compat.CompatUtils; import com.android.contacts.compat.PhoneAccountSdkCompat; import com.android.contacts.util.PermissionsUtil; import com.android.contacts.util.PhoneNumberHelper; import com.android.contactsbind.FeedbackHelper; +import com.android.contactsbind.experiments.Flags; import com.android.phone.common.PhoneConstants; import java.util.List; @@ -61,6 +66,14 @@ public class CallUtil { */ public static final int VIDEO_CALLING_PRESENCE = 2; + /** {@link PhoneAccount#EXTRA_SUPPORTS_VIDEO_CALLING_FALLBACK} */ + private static final String EXTRA_SUPPORTS_VIDEO_CALLING_FALLBACK = + "android.telecom.extra.SUPPORTS_VIDEO_CALLING_FALLBACK"; + + /** {@link CarrierConfigManager#CONFIG_ALLOW_VIDEO_CALLING_FALLBACK} */ + private static final String CONFIG_ALLOW_VIDEO_CALLING_FALLBACK = + "allow_video_calling_fallback_bool"; + /** * Return an Intent for making a phone call. Scheme (e.g. tel, sip) will be determined * automatically. @@ -210,4 +223,66 @@ public class CallUtil { } } + + /** + * Determines if we're able to use Tachyon as a fallback for video calling. + * + * @param context The context. + * @return {@code true} if there exists a call capable phone account which supports using a + * fallback for video calling, the carrier configuration supports a fallback, and the + * experiment for using a fallback is enabled. Otherwise {@code false} is returned. + */ + public static boolean isTachyonEnabled(Context context) { + // Need to be able to read phone state, and be on at least N to check PhoneAccount extras. + if (!PermissionsUtil.hasPermission(context, android.Manifest.permission.READ_PHONE_STATE) + || !CompatUtils.isNCompatible()) { + return false; + } + TelecomManager telecommMgr = (TelecomManager) + context.getSystemService(Context.TELECOM_SERVICE); + if (telecommMgr == null) { + return false; + } + try { + List<PhoneAccountHandle> accountHandles = telecommMgr.getCallCapablePhoneAccounts(); + for (PhoneAccountHandle accountHandle : accountHandles) { + PhoneAccount account = telecommMgr.getPhoneAccount(accountHandle); + if (account == null) { + continue; + } + // Check availability for the device config. + final Bundle accountExtras = account.getExtras(); + final boolean deviceEnabled = accountExtras != null && accountExtras.getBoolean( + EXTRA_SUPPORTS_VIDEO_CALLING_FALLBACK); + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "Device video fallback config: " + deviceEnabled); + } + + // Check availability from carrier config. + final PersistableBundle carrierConfig = context.getSystemService( + CarrierConfigManager.class).getConfig(); + final boolean carrierEnabled = + carrierConfig != null && carrierConfig.getBoolean( + CONFIG_ALLOW_VIDEO_CALLING_FALLBACK); + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "Carrier video fallback config: " + carrierEnabled); + } + + // Check experiment value. + final boolean experimentEnabled = Flags.getInstance().getBoolean( + Experiments.QUICK_CONTACT_VIDEO_CALL); + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "Experiment video fallback config: " + experimentEnabled); + } + + // All three checks above must be true to enable Tachyon calling. + return deviceEnabled && carrierEnabled && experimentEnabled; + } + return false; + } catch (SecurityException e) { + FeedbackHelper.sendFeedback(context, TAG, + "Security exception when getting call capable phone accounts", e); + return false; + } + } } diff --git a/src/com/android/contacts/DynamicShortcuts.java b/src/com/android/contacts/DynamicShortcuts.java index fc0d05a7a..ac950d9b7 100644 --- a/src/com/android/contacts/DynamicShortcuts.java +++ b/src/com/android/contacts/DynamicShortcuts.java @@ -297,6 +297,7 @@ public class DynamicShortcuts { final ShortcutInfo.Builder builder = new ShortcutInfo.Builder(mContext, id) .setIntent(action) .setIcon(icon) + .setExtras(extras) .setDisabledMessage(mContext.getString(R.string.dynamic_shortcut_disabled_message)); setLabel(builder, label); @@ -305,6 +306,9 @@ public class DynamicShortcuts { public ShortcutInfo getQuickContactShortcutInfo(long id, String lookupKey, String displayName) { final ShortcutInfo.Builder builder = builderForContactShortcut(id, lookupKey, displayName); + if (builder == null) { + return null; + } addIconForContact(id, lookupKey, displayName, builder); return builder.build(); } diff --git a/src/com/android/contacts/ShortcutIntentBuilder.java b/src/com/android/contacts/ShortcutIntentBuilder.java index e90e786cd..b3bd85d88 100644 --- a/src/com/android/contacts/ShortcutIntentBuilder.java +++ b/src/com/android/contacts/ShortcutIntentBuilder.java @@ -276,6 +276,9 @@ public class ShortcutIntentBuilder { private void createContactShortcutIntent(Uri contactUri, String contentType, String displayName, String lookupKey, byte[] bitmapData) { Intent intent = null; + if (TextUtils.isEmpty(displayName)) { + displayName = mContext.getResources().getString(R.string.missing_name); + } if (BuildCompat.isAtLeastO()) { final long contactId = ContentUris.parseId(contactUri); final ShortcutManager sm = (ShortcutManager) @@ -283,12 +286,11 @@ public class ShortcutIntentBuilder { final DynamicShortcuts dynamicShortcuts = new DynamicShortcuts(mContext); final ShortcutInfo shortcutInfo = dynamicShortcuts.getQuickContactShortcutInfo( contactId, lookupKey, displayName); - intent = sm.createShortcutResultIntent(shortcutInfo); + if (shortcutInfo != null) { + intent = sm.createShortcutResultIntent(shortcutInfo); + } } final Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey); - if (TextUtils.isEmpty(displayName)) { - displayName = mContext.getResources().getString(R.string.missing_name); - } final Intent shortcutIntent = ImplicitIntentsUtil.getIntentForQuickContactLauncherShortcut( mContext, contactUri); @@ -346,7 +348,9 @@ public class ShortcutIntentBuilder { final DynamicShortcuts dynamicShortcuts = new DynamicShortcuts(mContext); final ShortcutInfo shortcutInfo = dynamicShortcuts.getActionShortcutInfo( id, displayName, shortcutIntent, compatAdaptiveIcon.toIcon()); - intent = sm.createShortcutResultIntent(shortcutInfo); + if (shortcutInfo != null) { + intent = sm.createShortcutResultIntent(shortcutInfo); + } } intent = intent == null ? new Intent() : intent; diff --git a/src/com/android/contacts/model/AccountTypeManager.java b/src/com/android/contacts/model/AccountTypeManager.java index b442e4f34..993869509 100644 --- a/src/com/android/contacts/model/AccountTypeManager.java +++ b/src/com/android/contacts/model/AccountTypeManager.java @@ -622,9 +622,10 @@ class AccountTypeManagerImpl extends AccountTypeManager final AccountWithDataSet accountWithDataSet = new AccountWithDataSet( account.name, account.type, null); final AccountType type = mTypeProvider.getTypeForAccount(accountWithDataSet); - - // Accounts with a dataSet (e.g. Google plus accounts) are not writable. - result.add(type.wrapAccount(mContext, accountWithDataSet)); + if (type != null) { + // Accounts with a dataSet (e.g. Google plus accounts) are not writable. + result.add(type.wrapAccount(mContext, accountWithDataSet)); + } } return result; } diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java index 4e308b36b..b249ca6af 100644 --- a/src/com/android/contacts/quickcontact/QuickContactActivity.java +++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java @@ -35,6 +35,7 @@ import android.content.IntentFilter; import android.content.Loader; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; +import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutManager; import android.content.res.Resources; import android.graphics.Bitmap; @@ -105,7 +106,6 @@ import com.android.contacts.ContactSaveService; import com.android.contacts.ContactsActivity; import com.android.contacts.ContactsUtils; import com.android.contacts.DynamicShortcuts; -import com.android.contacts.Experiments; import com.android.contacts.NfcHandler; import com.android.contacts.R; import com.android.contacts.ShortcutIntentBuilder; @@ -176,7 +176,6 @@ import com.android.contacts.widget.MultiShrinkScroller; import com.android.contacts.widget.MultiShrinkScroller.MultiShrinkScrollerListener; import com.android.contacts.widget.QuickContactImageView; import com.android.contactsbind.HelpUtils; -import com.android.contactsbind.experiments.Flags; import com.google.common.collect.Lists; @@ -1460,6 +1459,7 @@ public class QuickContactActivity extends ContactsActivity { Trace.beginSection("Build data items map"); final Map<String, List<DataItem>> dataItemsMap = new HashMap<>(); + final boolean tachyonEnabled = CallUtil.isTachyonEnabled(this); for (RawContact rawContact : data.getRawContacts()) { for (DataItem dataItem : rawContact.getDataItems()) { @@ -1469,6 +1469,7 @@ public class QuickContactActivity extends ContactsActivity { if (mimeType == null) continue; if (!MIMETYPE_TACHYON.equals(mimeType)) { + // Only validate non-Tachyon mimetypes. final AccountType accountType = rawContact.getAccountType(this); final DataKind dataKind = AccountTypeManager.getInstance(this) .getKindOrFallback(accountType, mimeType); @@ -1480,6 +1481,9 @@ public class QuickContactActivity extends ContactsActivity { dataKind)); if (isMimeExcluded(mimeType) || !hasData) continue; + } else if (!tachyonEnabled) { + // If tachyon isn't enabled, skip its mimetypes. + continue; } List<DataItem> dataItemListByType = dataItemsMap.get(mimeType); @@ -1824,7 +1828,7 @@ public class QuickContactActivity extends ContactsActivity { thirdIntent.putExtra(EXTRA_ACTION_TYPE, ActionType.VIDEOCALL); thirdContentDescription = res.getString(R.string.description_video_call); - } else if (Flags.getInstance().getBoolean(Experiments.QUICK_CONTACT_VIDEO_CALL) + } else if (CallUtil.isTachyonEnabled(context) && ((PhoneDataItem) dataItem).isTachyonReachable()) { thirdIcon = res.getDrawable(R.drawable.quantum_ic_videocam_vd_theme_24); thirdAction = Entry.ACTION_INTENT; @@ -1919,8 +1923,8 @@ public class QuickContactActivity extends ContactsActivity { aboutCardName.value = res.getString(R.string.about_card_title); } } - } else if (Flags.getInstance().getBoolean(Experiments.QUICK_CONTACT_VIDEO_CALL) - && MIMETYPE_TACHYON.equals(dataItem.getMimeType())) { + } else if (CallUtil.isTachyonEnabled(context) && MIMETYPE_TACHYON.equals( + dataItem.getMimeType())) { // Skip these actions. They will be placed by the phone number. return null; } else { @@ -2698,21 +2702,26 @@ public class QuickContactActivity extends ContactsActivity { * Creates a launcher shortcut with the current contact. */ private void createLauncherShortcutWithContact() { - final ShortcutIntentBuilder builder = new ShortcutIntentBuilder(this, - new OnShortcutIntentCreatedListener() { + if (BuildCompat.isAtLeastO()) { + final ShortcutManager shortcutManager = (ShortcutManager) + getSystemService(SHORTCUT_SERVICE); + final DynamicShortcuts shortcuts = + new DynamicShortcuts(QuickContactActivity.this); + String displayName = mContactData.getDisplayName(); + if (displayName == null) { + displayName = getString(R.string.missing_name); + } + final ShortcutInfo shortcutInfo = shortcuts.getQuickContactShortcutInfo( + mContactData.getId(), mContactData.getLookupKey(), displayName); + if (shortcutInfo != null) { + shortcutManager.requestPinShortcut(shortcutInfo, null); + } + } else { + final ShortcutIntentBuilder builder = new ShortcutIntentBuilder(this, + new OnShortcutIntentCreatedListener() { - @Override - public void onShortcutIntentCreated(Uri uri, Intent shortcutIntent) { - if (BuildCompat.isAtLeastO()) { - final ShortcutManager shortcutManager = (ShortcutManager) - getSystemService(SHORTCUT_SERVICE); - final DynamicShortcuts shortcuts = - new DynamicShortcuts(QuickContactActivity.this); - shortcutManager.requestPinShortcut( - shortcuts.getQuickContactShortcutInfo( - mContactData.getId(), mContactData.getLookupKey(), - mContactData.getDisplayName()), null); - } else { + @Override + public void onShortcutIntentCreated(Uri uri, Intent shortcutIntent) { // Broadcast the shortcutIntent to the launcher to create a // shortcut to this contact shortcutIntent.setAction(ACTION_INSTALL_SHORTCUT); @@ -2728,9 +2737,9 @@ public class QuickContactActivity extends ContactsActivity { Toast.makeText(QuickContactActivity.this, toastMessage, Toast.LENGTH_SHORT).show(); } - } - }); - builder.createContactShortcutIntent(mContactData.getLookupUri()); + }); + builder.createContactShortcutIntent(mContactData.getLookupUri()); + } } private boolean isShortcutCreatable() { |