Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +4 −36 Original line number Diff line number Diff line Loading @@ -300,37 +300,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> mLocalNapRoleConnected = false; } if (!HearingAidStatsLogUtils.isUserCategorized(mContext)) { if (HearingAidStatsLogUtils.isJustBonded(getAddress())) { // Saves bonded timestamp as the source for judging whether to display // the survey if (getProfiles().stream().anyMatch( p -> (p instanceof HearingAidProfile || p instanceof HapClientProfile))) { HearingAidStatsLogUtils.addCurrentTimeToHistory(mContext, HearingAidStatsLogUtils.HistoryType.TYPE_HEARING_AIDS_PAIRED); } else if (getProfiles().stream().anyMatch( p -> (p instanceof A2dpSinkProfile || p instanceof HeadsetProfile))) { HearingAidStatsLogUtils.addCurrentTimeToHistory(mContext, HearingAidStatsLogUtils.HistoryType.TYPE_HEARING_DEVICES_PAIRED); } HearingAidStatsLogUtils.removeFromJustBonded(getAddress()); } // Saves connected timestamp as the source for judging whether to display // the survey if (newProfileState == BluetoothProfile.STATE_CONNECTED) { if (profile instanceof HearingAidProfile || profile instanceof HapClientProfile) { HearingAidStatsLogUtils.addCurrentTimeToHistory(mContext, HearingAidStatsLogUtils.HistoryType.TYPE_HEARING_AIDS_CONNECTED); } else if (profile instanceof A2dpSinkProfile || profile instanceof HeadsetProfile) { HearingAidStatsLogUtils.addCurrentTimeToHistory(mContext, HearingAidStatsLogUtils.HistoryType.TYPE_HEARING_DEVICES_CONNECTED); } } } HearingAidStatsLogUtils.updateHistoryIfNeeded(mContext, this, profile, newProfileState); } fetchActiveDevices(); Loading Loading @@ -987,13 +957,11 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> connect(); } if (!HearingAidStatsLogUtils.isUserCategorized(mContext)) { // Saves this device as just bonded and checks if it's an hearing device after // profiles are connected. This is for judging whether to display the survey. HearingAidStatsLogUtils.addToJustBonded(getAddress()); } } } public Timestamp getBondTimestamp() { return mBondTimestamp; Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidStatsLogUtils.java +37 −30 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.settingslib.bluetooth; import android.bluetooth.BluetoothProfile; import android.content.Context; import android.content.SharedPreferences; import android.icu.text.SimpleDateFormat; Loading Loading @@ -126,16 +127,43 @@ public final class HearingAidStatsLogUtils { } /** * Indicates if user is categorized as one of {@link #CATEGORY_HEARING_AIDS}, * {@link #CATEGORY_NEW_HEARING_AIDS}, {@link #CATEGORY_HEARING_DEVICES}, and * {@link #CATEGORY_NEW_HEARING_DEVICES}. * Updates corresponding history if we found the device is a hearing device after profile state * changed. * * @param context the request context * @return true if user is already categorized as one of interested group * @param cachedDevice the remote device * @param profile the profile that has a state changed * @param profileState the new profile state */ public static boolean isUserCategorized(Context context) { String userCategory = getSharedPreferences(context).getString(BT_HEARING_USER_CATEGORY, ""); return !userCategory.isEmpty(); public static void updateHistoryIfNeeded(Context context, CachedBluetoothDevice cachedDevice, LocalBluetoothProfile profile, int profileState) { if (isJustBonded(cachedDevice.getAddress())) { // Saves bonded timestamp as the source for judging whether to display // the survey if (cachedDevice.getProfiles().stream().anyMatch( p -> (p instanceof HearingAidProfile || p instanceof HapClientProfile))) { HearingAidStatsLogUtils.addCurrentTimeToHistory(context, HearingAidStatsLogUtils.HistoryType.TYPE_HEARING_AIDS_PAIRED); } else if (cachedDevice.getProfiles().stream().anyMatch( p -> (p instanceof A2dpSinkProfile || p instanceof HeadsetProfile))) { HearingAidStatsLogUtils.addCurrentTimeToHistory(context, HearingAidStatsLogUtils.HistoryType.TYPE_HEARING_DEVICES_PAIRED); } removeFromJustBonded(cachedDevice.getAddress()); } // Saves connected timestamp as the source for judging whether to display // the survey if (profileState == BluetoothProfile.STATE_CONNECTED) { if (profile instanceof HearingAidProfile || profile instanceof HapClientProfile) { HearingAidStatsLogUtils.addCurrentTimeToHistory(context, HearingAidStatsLogUtils.HistoryType.TYPE_HEARING_AIDS_CONNECTED); } else if (profile instanceof A2dpSinkProfile || profile instanceof HeadsetProfile) { HearingAidStatsLogUtils.addCurrentTimeToHistory(context, HearingAidStatsLogUtils.HistoryType.TYPE_HEARING_DEVICES_CONNECTED); } } } /** Loading Loading @@ -186,14 +214,6 @@ public final class HearingAidStatsLogUtils { userCategory = CATEGORY_HEARING_DEVICES; } } if (!userCategory.isEmpty()) { // History become useless once user is categorized. Clear all history. SharedPreferences.Editor editor = getSharedPreferences(context).edit(); editor.putString(BT_HEARING_USER_CATEGORY, userCategory).apply(); clearHistory(context); sJustBondedDeviceAddressSet.clear(); } return userCategory; } Loading @@ -211,7 +231,7 @@ public final class HearingAidStatsLogUtils { * Removes the device address from the just bonded list. * @param address the device address */ public static void removeFromJustBonded(String address) { private static void removeFromJustBonded(String address) { sJustBondedDeviceAddressSet.remove(address); } Loading @@ -220,23 +240,10 @@ public final class HearingAidStatsLogUtils { * @param address the device address * @return true if the device address is in the just bonded list */ public static boolean isJustBonded(String address) { private static boolean isJustBonded(String address) { return sJustBondedDeviceAddressSet.contains(address); } /** * Clears all BT hearing devices related history stored in shared preference. * @param context the request context */ private static synchronized void clearHistory(Context context) { SharedPreferences.Editor editor = getSharedPreferences(context).edit(); editor.remove(BT_HEARING_AIDS_PAIRED_HISTORY) .remove(BT_HEARING_AIDS_CONNECTED_HISTORY) .remove(BT_HEARING_DEVICES_PAIRED_HISTORY) .remove(BT_HEARING_DEVICES_CONNECTED_HISTORY) .apply(); } /** * Adds current timestamp into BT hearing devices related history. * @param context the request context Loading Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +4 −36 Original line number Diff line number Diff line Loading @@ -300,37 +300,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> mLocalNapRoleConnected = false; } if (!HearingAidStatsLogUtils.isUserCategorized(mContext)) { if (HearingAidStatsLogUtils.isJustBonded(getAddress())) { // Saves bonded timestamp as the source for judging whether to display // the survey if (getProfiles().stream().anyMatch( p -> (p instanceof HearingAidProfile || p instanceof HapClientProfile))) { HearingAidStatsLogUtils.addCurrentTimeToHistory(mContext, HearingAidStatsLogUtils.HistoryType.TYPE_HEARING_AIDS_PAIRED); } else if (getProfiles().stream().anyMatch( p -> (p instanceof A2dpSinkProfile || p instanceof HeadsetProfile))) { HearingAidStatsLogUtils.addCurrentTimeToHistory(mContext, HearingAidStatsLogUtils.HistoryType.TYPE_HEARING_DEVICES_PAIRED); } HearingAidStatsLogUtils.removeFromJustBonded(getAddress()); } // Saves connected timestamp as the source for judging whether to display // the survey if (newProfileState == BluetoothProfile.STATE_CONNECTED) { if (profile instanceof HearingAidProfile || profile instanceof HapClientProfile) { HearingAidStatsLogUtils.addCurrentTimeToHistory(mContext, HearingAidStatsLogUtils.HistoryType.TYPE_HEARING_AIDS_CONNECTED); } else if (profile instanceof A2dpSinkProfile || profile instanceof HeadsetProfile) { HearingAidStatsLogUtils.addCurrentTimeToHistory(mContext, HearingAidStatsLogUtils.HistoryType.TYPE_HEARING_DEVICES_CONNECTED); } } } HearingAidStatsLogUtils.updateHistoryIfNeeded(mContext, this, profile, newProfileState); } fetchActiveDevices(); Loading Loading @@ -987,13 +957,11 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> connect(); } if (!HearingAidStatsLogUtils.isUserCategorized(mContext)) { // Saves this device as just bonded and checks if it's an hearing device after // profiles are connected. This is for judging whether to display the survey. HearingAidStatsLogUtils.addToJustBonded(getAddress()); } } } public Timestamp getBondTimestamp() { return mBondTimestamp; Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidStatsLogUtils.java +37 −30 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.settingslib.bluetooth; import android.bluetooth.BluetoothProfile; import android.content.Context; import android.content.SharedPreferences; import android.icu.text.SimpleDateFormat; Loading Loading @@ -126,16 +127,43 @@ public final class HearingAidStatsLogUtils { } /** * Indicates if user is categorized as one of {@link #CATEGORY_HEARING_AIDS}, * {@link #CATEGORY_NEW_HEARING_AIDS}, {@link #CATEGORY_HEARING_DEVICES}, and * {@link #CATEGORY_NEW_HEARING_DEVICES}. * Updates corresponding history if we found the device is a hearing device after profile state * changed. * * @param context the request context * @return true if user is already categorized as one of interested group * @param cachedDevice the remote device * @param profile the profile that has a state changed * @param profileState the new profile state */ public static boolean isUserCategorized(Context context) { String userCategory = getSharedPreferences(context).getString(BT_HEARING_USER_CATEGORY, ""); return !userCategory.isEmpty(); public static void updateHistoryIfNeeded(Context context, CachedBluetoothDevice cachedDevice, LocalBluetoothProfile profile, int profileState) { if (isJustBonded(cachedDevice.getAddress())) { // Saves bonded timestamp as the source for judging whether to display // the survey if (cachedDevice.getProfiles().stream().anyMatch( p -> (p instanceof HearingAidProfile || p instanceof HapClientProfile))) { HearingAidStatsLogUtils.addCurrentTimeToHistory(context, HearingAidStatsLogUtils.HistoryType.TYPE_HEARING_AIDS_PAIRED); } else if (cachedDevice.getProfiles().stream().anyMatch( p -> (p instanceof A2dpSinkProfile || p instanceof HeadsetProfile))) { HearingAidStatsLogUtils.addCurrentTimeToHistory(context, HearingAidStatsLogUtils.HistoryType.TYPE_HEARING_DEVICES_PAIRED); } removeFromJustBonded(cachedDevice.getAddress()); } // Saves connected timestamp as the source for judging whether to display // the survey if (profileState == BluetoothProfile.STATE_CONNECTED) { if (profile instanceof HearingAidProfile || profile instanceof HapClientProfile) { HearingAidStatsLogUtils.addCurrentTimeToHistory(context, HearingAidStatsLogUtils.HistoryType.TYPE_HEARING_AIDS_CONNECTED); } else if (profile instanceof A2dpSinkProfile || profile instanceof HeadsetProfile) { HearingAidStatsLogUtils.addCurrentTimeToHistory(context, HearingAidStatsLogUtils.HistoryType.TYPE_HEARING_DEVICES_CONNECTED); } } } /** Loading Loading @@ -186,14 +214,6 @@ public final class HearingAidStatsLogUtils { userCategory = CATEGORY_HEARING_DEVICES; } } if (!userCategory.isEmpty()) { // History become useless once user is categorized. Clear all history. SharedPreferences.Editor editor = getSharedPreferences(context).edit(); editor.putString(BT_HEARING_USER_CATEGORY, userCategory).apply(); clearHistory(context); sJustBondedDeviceAddressSet.clear(); } return userCategory; } Loading @@ -211,7 +231,7 @@ public final class HearingAidStatsLogUtils { * Removes the device address from the just bonded list. * @param address the device address */ public static void removeFromJustBonded(String address) { private static void removeFromJustBonded(String address) { sJustBondedDeviceAddressSet.remove(address); } Loading @@ -220,23 +240,10 @@ public final class HearingAidStatsLogUtils { * @param address the device address * @return true if the device address is in the just bonded list */ public static boolean isJustBonded(String address) { private static boolean isJustBonded(String address) { return sJustBondedDeviceAddressSet.contains(address); } /** * Clears all BT hearing devices related history stored in shared preference. * @param context the request context */ private static synchronized void clearHistory(Context context) { SharedPreferences.Editor editor = getSharedPreferences(context).edit(); editor.remove(BT_HEARING_AIDS_PAIRED_HISTORY) .remove(BT_HEARING_AIDS_CONNECTED_HISTORY) .remove(BT_HEARING_DEVICES_PAIRED_HISTORY) .remove(BT_HEARING_DEVICES_CONNECTED_HISTORY) .apply(); } /** * Adds current timestamp into BT hearing devices related history. * @param context the request context Loading