Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eb7e15be authored by Angela Wang's avatar Angela Wang
Browse files

Save BT hearing device event history for HaTS surveys

We'll run surveys on hearing adis and general hearing devices users to
know the satisfaction difference between different kinds of devices.
This can help us prioritize to improve the parts which are less satisfying.

getProfiles() are not availabe right after the bonded event. We need to wait until the device is connected to see if it's a hearing device or not. Delay
the saving time of hearing devices bonded events until the profiles are connected.

Bug: 294627726
Test: atest HearingAidStatsLogUtilsTest
Test: atest CachedBluetoothDeviceTest
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:ea207bdb0a87dccd7026cc133b407f3081c7c823)

Change-Id: I70dc1680bea2f1002325c2ba1497dfccb5cf2b48
parent 8dafcfc0
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -277,6 +277,32 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
                mRemovedProfiles.add(profile);
                mLocalNapRoleConnected = false;
            }

            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);
                }
            }
        }

        fetchActiveDevices();
@@ -899,6 +925,10 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
            if (mDevice.isBondingInitiatedLocally()) {
                connect();
            }

            // 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());
        }
    }

+30 −0
Original line number Diff line number Diff line
@@ -31,8 +31,10 @@ import com.android.internal.util.FrameworkStatsLog;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

@@ -70,6 +72,7 @@ public final class HearingAidStatsLogUtils {
    }

    private static final HashMap<String, Integer> sDeviceAddressToBondEntryMap = new HashMap<>();
    private static final Set<String> sJustBondedDeviceAddressSet = new HashSet<>();

    /**
     * Sets the mapping from hearing aid device to the bond entry where this device starts it's
@@ -111,6 +114,33 @@ public final class HearingAidStatsLogUtils {
        return sDeviceAddressToBondEntryMap;
    }

    /**
     * Maintains a temporarily list of just bonded device address. After the device profiles are
     * connected, {@link HearingAidStatsLogUtils#removeFromJustBonded} will be called to remove the
     * address.
     * @param address the device address
     */
    public static void addToJustBonded(String address) {
        sJustBondedDeviceAddressSet.add(address);
    }

    /**
     * Removes the device address from the just bonded list.
     * @param address the device address
     */
    public static void removeFromJustBonded(String address) {
        sJustBondedDeviceAddressSet.remove(address);
    }

    /**
     * Checks whether the device address is in the just bonded list.
     * @param address the device address
     * @return true if the device address is in the just bonded list
     */
    public 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