Merge commit '26684f130755966cdf68c1f090fff84dac7cdab0' into remote branch
diff --git a/packages_apps_bluetooth_ext/src/avrcp/AvrcpPlayerAppSettings.java b/packages_apps_bluetooth_ext/src/avrcp/AvrcpPlayerAppSettings.java
index 0ca60a0..baa3332 100644
--- a/packages_apps_bluetooth_ext/src/avrcp/AvrcpPlayerAppSettings.java
+++ b/packages_apps_bluetooth_ext/src/avrcp/AvrcpPlayerAppSettings.java
@@ -39,12 +39,14 @@
 import java.util.List;
 import java.util.Set;
 import java.util.Iterator;
+import android.os.SystemProperties;
 
 public class AvrcpPlayerAppSettings {
     private static final boolean DEBUG = true;
     private static final String TAG = "AvrcpPlayerAppSettings";
 
     private boolean mIsRegisterd;
+    private long mPlayerAppSettingsCmdDelay;
     private ArrayList <Integer> mPendingCmds;
     private ArrayList <Integer> mPendingSetAttributes;
     private ArrayList <Byte> mPlayerSettingCmds;
@@ -107,6 +109,10 @@
     private final String UPDATE_ATTRIB_TEXT = "UpdateAttributesText";
     private final String UPDATE_VALUE_TEXT = "UpdateValuesText";
 
+    // Property for response delay for Player App Settings commands
+    private static final String AVRCP_PLAYERAPP_SETTINGS_PROPERTY =
+            "persist.vendor.btstack.avrcp.playerappsettings_time";
+
     //Intents for PlayerApplication Settings
     private static final String PLAYERSETTINGS_REQUEST =
             "org.codeaurora.music.playersettingsrequest";
@@ -119,6 +125,8 @@
         mPendingCmds = null;
         mPendingSetAttributes = null;
         mPlayerSettingCmds = null;
+        mPlayerAppSettingsCmdDelay =
+                SystemProperties.getLong(AVRCP_PLAYERAPP_SETTINGS_PROPERTY, 100L);
         mContext = context;
         mAvrcpPlayerAppSettingsRspInterface = playerAppSettings;
     }
@@ -523,6 +531,10 @@
         return ret;
     }
 
+    public long getPlayerAppSettingsCmdDelay() {
+        return mPlayerAppSettingsCmdDelay;
+    }
+
     private byte[] getByteAddress(BluetoothDevice device) {
         return Utils.getBytesFromAddress(device.getAddress());
     }
diff --git a/packages_apps_bluetooth_ext/src/avrcp/Avrcp_ext.java b/packages_apps_bluetooth_ext/src/avrcp/Avrcp_ext.java
index 7378261..df0efe6 100644
--- a/packages_apps_bluetooth_ext/src/avrcp/Avrcp_ext.java
+++ b/packages_apps_bluetooth_ext/src/avrcp/Avrcp_ext.java
@@ -142,7 +142,6 @@
     /* Local volume in audio index 0-15 */
     private int mLocalVolume;
     private int mLastLocalVolume;
-    private int mAbsVolThreshold;
 
     private boolean mFastforward;
     private boolean mRewind;
@@ -277,7 +276,6 @@
     private SortedMap<Integer, MediaPlayerInfo_ext> mMediaPlayerInfoList;
     private boolean mAvailablePlayerViewChanged;
 
-    private boolean mPlayerSwitching;
     private List<String> mPkgRequestedMBSConnect;
 
     /* List of media players which supports browse */
@@ -476,7 +474,6 @@
         mLastDirection = 0;
         mLocalVolume = -1;
         mLastLocalVolume = -1;
-        mAbsVolThreshold = 0;
         mCurrAddrPlayerID = NO_PLAYER_ID;
         mCurrBrowsePlayerID = 0;
         mContext = context;
@@ -506,18 +503,6 @@
         mAudioStreamMax = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
         mVolumeStep = Math.max(AVRCP_BASE_VOLUME_STEP, AVRCP_MAX_VOL/mAudioStreamMax);
 
-        Resources resources = context.getResources();
-        if (resources != null) {
-            mAbsVolThreshold = resources.getInteger(R.integer.a2dp_absolute_volume_initial_threshold);
-
-            // Update the threshold if the threshold_percent is valid
-            int threshold_percent =
-                    resources.getInteger(R.integer.a2dp_absolute_volume_initial_threshold_percent);
-            if (threshold_percent >= 0 && threshold_percent <= 100) {
-                mAbsVolThreshold = (threshold_percent * mAudioStreamMax) / 100;
-            }
-        }
-
         // Register for package removal intent broadcasts for media button receiver persistence
         IntentFilter pkgFilter = new IntentFilter();
         pkgFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
@@ -570,7 +555,6 @@
         mAvrcpPlayerAppSettingsRsp = new AvrcpPlayerAppSettingsRsp();
         mMediaPlayerInfoList = new TreeMap<Integer, MediaPlayerInfo_ext>();
         mAvailablePlayerViewChanged = false;
-        mPlayerSwitching = false;
         mPkgRequestedMBSConnect = new ArrayList<String>();
         mBrowsePlayerInfoList = Collections.synchronizedList(new ArrayList<BrowsePlayerInfo_ext>());
         mPassthroughDispatched = 0;
@@ -878,15 +862,9 @@
                 deviceIndex = msg.arg1;
                 int vol = msg.arg2;
                 BluetoothDevice device = mA2dpService.getActiveDevice();
-                if(device == null)
+                if (device == null)
                     break;
-                if (mAbsVolThreshold > 0 && mAbsVolThreshold < mAudioStreamMax &&
-                    vol > mAbsVolThreshold) {
-                    if (DEBUG) Log.v(TAG, "remote inital volume too high " + vol + ">" +
-                       mAbsVolThreshold);
-                    vol = mAbsVolThreshold;
-                    notifyVolumeChanged(vol, false);
-                }
+
                 if (vol >= 0) {
                     int volume = convertToAvrcpVolume(vol);
                     int remVol = deviceFeatures[deviceIndex].mRemoteVolume;
@@ -3265,12 +3243,13 @@
     }
 
     private void SendPlayerSettingMsg(Integer cmd, byte[] address) {
+        long delay_interval = mAvrcpPlayerAppSettings.getPlayerAppSettingsCmdDelay();
         Message msg = mHandler.obtainMessage();
         msg.what = MESSAGE_PLAYERSETTINGS_TIMEOUT;
         msg.arg1 = cmd;
         msg.arg2 = 0;
         msg.obj = Utils.getAddressStringFromByte(address);
-        mHandler.sendMessageDelayed(msg, 500);
+        mHandler.sendMessageDelayed(msg, delay_interval);
     }
 
     private void CreateMusicSettingsAppCmdLookupOrUpdate(Integer cmd,
@@ -4020,7 +3999,9 @@
                         mPackageManager.queryIntentServices(intent, PackageManager.MATCH_ALL);
 
                 for (ResolveInfo info : playerList) {
+                    Log.d(TAG, "Fetch the displayName of package - start");
                     CharSequence displayName = info.loadLabel(mPackageManager);
+                    Log.d(TAG, "Fetch the displayName of package - end");
                     String displayableName =
                             (displayName != null) ? displayName.toString():new String();
                     String serviceName = info.serviceInfo.name;
@@ -4041,6 +4022,7 @@
                     } else {
                         addMediaPlayerPackage(packageName);
                     }
+                    Log.d(TAG, "Added MediaPlayerController/MediaPlayerPackage");
                 }
                 updateCurrentMediaState(null);
             }
@@ -5288,12 +5270,6 @@
           return;
         }
 
-        if (mAbsVolThreshold > 0 && mAbsVolThreshold < mAudioStreamMax &&
-           storeVolume > mAbsVolThreshold) {
-            if (DEBUG) Log.v(TAG, "remote store volume too high" + storeVolume + ">" +
-               mAbsVolThreshold);
-            storeVolume = mAbsVolThreshold;
-        }
         if (index == INVALID_DEVICE_INDEX && disconnectedActiveDevice != null &&
             (disconnectedActiveDevice.equals(device)
             || isTwsPlusPair(disconnectedActiveDevice, device))) {
diff --git a/system_bt_ext/bta/tws_plus/ag/bta_ag_twsp_sco.cc b/system_bt_ext/bta/tws_plus/ag/bta_ag_twsp_sco.cc
index aee4c0c..849aa1c 100644
--- a/system_bt_ext/bta/tws_plus/ag/bta_ag_twsp_sco.cc
+++ b/system_bt_ext/bta/tws_plus/ag/bta_ag_twsp_sco.cc
@@ -60,10 +60,6 @@
 
 #if (TWS_AG_ENABLED == TRUE)
 
-#ifndef BTA_AG_SCO_DEBUG
-#define BTA_AG_SCO_DEBUG FALSE
-#endif
-
 void send_twsp_esco_setup (const RawAddress& left_eb_addr, const RawAddress& rght_eb_addr,
     uint8_t selected_mic);
 void print_bdaddr(const RawAddress& addr);
@@ -198,13 +194,11 @@
    //PONTING TO SECONDARY sco cb
    tBTA_AG_SCO_CB* p_sco = &bta_ag_cb.twsp_sec_sco;
    tBTA_AG_SCB *other_scb = NULL;
-#if (BTA_AG_SCO_DEBUG == TRUE)
    uint8_t in_state = p_sco->state;
-#endif
-   APPL_TRACE_EVENT("%s: SCO Index 0x%04x, State %d, Event %d", __func__,
+   APPL_TRACE_IMP("%s: SCO Index 0x%04x, State %d, Event %d", __func__,
                      p_scb->sco_idx, p_sco->state, event);
 
-   APPL_TRACE_EVENT("%s: TWS+ peer p_scb: %x", __func__, p_scb);
+   APPL_TRACE_IMP("%s: TWS+ peer p_scb: %x", __func__, p_scb);
 
    switch (p_sco->state) {
        case BTA_AG_SCO_SHUTDOWN_ST:
@@ -488,14 +482,12 @@
     default:
       break;
   }
-#if (BTA_AG_SCO_DEBUG == TRUE)
   if (p_sco->state != in_state) {
-    APPL_TRACE_EVENT("BTA AG TWS SCO State Change: [%s] -> [%s] after Event [%s]",
+    APPL_TRACE_IMP("BTA AG TWS SCO State Change: [%s] -> [%s] after Event [%s]",
                      bta_ag_sco_state_str(in_state),
                      bta_ag_sco_state_str(p_sco->state),
                      bta_ag_sco_evt_str(event));
   }
-#endif
 }
 
 void print_bdaddr(const RawAddress& addr) {
diff --git a/system_bt_ext/conf/bt_profile.conf b/system_bt_ext/conf/bt_profile.conf
index 27b49d8..d3fd677 100644
--- a/system_bt_ext/conf/bt_profile.conf
+++ b/system_bt_ext/conf/bt_profile.conf
@@ -8,7 +8,6 @@
 #   2.PBAP
 #   3.MAP
 #   4.MAX_POW
-#   5.HEARING AID
 #
 # ******************************* Start of config Database *******************
 #AVRCP profile and its configurable features
@@ -44,8 +43,3 @@
 #BR_max_pow_support = 0x80
 #EDR_max_pow_support = 0x80
 BLE_max_pow_support = 0x18
-
-#Hearing Aid profile and its configurable features
-# hearing_aid_support with default value false
-[HEARING_AID]
-hearing_aid_support = false
\ No newline at end of file
diff --git a/system_bt_ext/conf/interop_database.conf b/system_bt_ext/conf/interop_database.conf
index 9e0c792..057a547 100644
--- a/system_bt_ext/conf/interop_database.conf
+++ b/system_bt_ext/conf/interop_database.conf
@@ -437,12 +437,14 @@
 # Porsche Panamera :: 74:6f:f7:8c:bf:61
 # BMW X3 :: a0:56:b2:4f:86:a8
 # Land Rover :: 00:00:2e:b0:12:5c
+# BMW USAX5 :: a0:56:b2:5a:7f:b0
 [INTEROP_DISABLE_PLAYER_APPLICATION_SETTING_CMDS]
 00:09:93 = Address_Based
 74:6f:f7 = Address_Based
 A0:56:B2:4F = Address_Based
 00:54:AF = Address_Based
 00:00:2E = Address_Based
+A0:56:B2:5A = Address_Based
 
 [INTEROP_DISABLE_CONNECTION_AFTER_COLLISION]
 A0:14:3D
diff --git a/system_bt_ext/device/src/profile_config.cc b/system_bt_ext/device/src/profile_config.cc
index 5193556..39c95d7 100644
--- a/system_bt_ext/device/src/profile_config.cc
+++ b/system_bt_ext/device/src/profile_config.cc
@@ -89,10 +89,6 @@
 } map_feature_t;
 
 typedef struct {
-   char hap_support[VALUE_MAX_LENGTH];
-} hearing_aid_feature_t;
-
-typedef struct {
   profile_t profile_id;
   char *version;
 
@@ -101,7 +97,6 @@
     pbap_feature_t pbap_feature_entry;
     map_feature_t map_feature_entry;
     max_pow_feature_t max_pow_feature_entry;
-    hearing_aid_feature_t hearing_aid_support_entry;
   } profile_feature_type;
 
 } profile_db_entry_t;
@@ -126,7 +121,6 @@
     CASE_RETURN_STR(PBAP_ID)
     CASE_RETURN_STR(MAP_ID)
     CASE_RETURN_STR(MAX_POW_ID)
-    CASE_RETURN_STR(HEARING_AID_ID)
     CASE_RETURN_STR(END_OF_PROFILE_LIST)
   }
   return "UNKNOWN";
@@ -145,7 +139,6 @@
     CASE_RETURN_STR(BR_MAX_POW_SUPPORT)
     CASE_RETURN_STR(EDR_MAX_POW_SUPPORT)
     CASE_RETURN_STR(BLE_MAX_POW_SUPPORT)
-    CASE_RETURN_STR(HEARING_AID_SUPPORT)
     CASE_RETURN_STR(END_OF_FEATURE_LIST)
   }
   return "UNKNOWN";
@@ -429,26 +422,6 @@
       }
     }
     break;
-    case HEARING_AID_ID:
-    {
-      switch(feature_name) {
-        case  HEARING_AID_SUPPORT:
-        {
-          if (strncasecmp("true",
-                  db_entry->profile_feature_type.hearing_aid_support_entry.hap_support,
-                  strlen("true")) == 0)
-            feature_set = true;
-          LOG_WARN(LOG_TAG, "profile_feature_fetch:HEARING_AID_SUPPORT found = %d" , feature_set);
-        }
-        break;
-        default:
-        {
-          LOG_WARN(LOG_TAG, "profile_feature_fetch:profile = %d , feature %d not found" ,
-              profile, feature_name);
-        }
-      }
-    }
-    break;
     default:
     {
       LOG_WARN(LOG_TAG,"%s() profile %d not found",__func__, profile);
@@ -633,32 +606,6 @@
       profile_database_add_(entry);
     }
     break;
-    case HEARING_AID_ID:
-    {
-      LOG_WARN(LOG_TAG, "HEARING_AID_ID: key :: %s, value :: %s",
-                key, value);
-      entry = profile_entry_fetch(HEARING_AID_ID);
-      if (entry == NULL) {
-        entry = (profile_db_entry_t *)osi_calloc(sizeof(profile_db_entry_t));
-        entry->profile_id = (profile_t)profile_id;
-      }
-      switch (get_feature(key)) {
-        case HEARING_AID_SUPPORT:
-        {
-          memset(&entry->profile_feature_type.hearing_aid_support_entry.hap_support,
-              '\0', VALUE_MAX_LENGTH);
-          memcpy(&entry->profile_feature_type.hearing_aid_support_entry.hap_support,
-              value, strlen(value));
-        }
-        break;
-        default:
-        {
-          LOG_WARN(LOG_TAG,"%s is invalid key %s", __func__, key);
-        }
-      }
-      profile_database_add_(entry);
-    }
-    break;
     default:
     {
       LOG_WARN(LOG_TAG,"%s is invalid profile entry %s", __func__, key);
diff --git a/vhal/include/hardware/vendor.h b/vhal/include/hardware/vendor.h
index 6afb556..ae0f7f1 100644
--- a/vhal/include/hardware/vendor.h
+++ b/vhal/include/hardware/vendor.h
@@ -65,7 +65,6 @@
   PBAP_ID,
   MAP_ID,
   MAX_POW_ID,
-  HEARING_AID_ID,
   END_OF_PROFILE_LIST
 } profile_t;
 
@@ -81,7 +80,6 @@
  BR_MAX_POW_SUPPORT,
  EDR_MAX_POW_SUPPORT,
  BLE_MAX_POW_SUPPORT,
- HEARING_AID_SUPPORT,
  END_OF_FEATURE_LIST
  } profile_info_t;