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

Commit f78c6651 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "AVRCP: Print more info for Absolute Volume Control blacklist"

parents ae505536 6f8580e3
Loading
Loading
Loading
Loading
+21 −11
Original line number Original line Diff line number Diff line
@@ -692,7 +692,7 @@ public final class Avrcp {
                    if (mInitialRemoteVolume == -1) {
                    if (mInitialRemoteVolume == -1) {
                        Log.d(TAG, "remote " + mAddress
                        Log.d(TAG, "remote " + mAddress
                                + " never tell us initial volume, black list it.");
                                + " never tell us initial volume, black list it.");
                        blackListCurrentDevice();
                        blackListCurrentDevice("MSG_ADJUST_VOLUME");
                        break;
                        break;
                    }
                    }


@@ -791,7 +791,7 @@ public final class Avrcp {
                            Log.d(TAG, "remote " + mAddress
                            Log.d(TAG, "remote " + mAddress
                                    + " never tell us initial volume, black list it.");
                                    + " never tell us initial volume, black list it.");
                        }
                        }
                        blackListCurrentDevice();
                        blackListCurrentDevice("MSG_SET_ABSOLUTE_VOLUME");
                        break;
                        break;
                    }
                    }


@@ -821,7 +821,7 @@ public final class Avrcp {
                    if (mAbsVolRetryTimes >= MAX_ERROR_RETRY_TIMES) {
                    if (mAbsVolRetryTimes >= MAX_ERROR_RETRY_TIMES) {
                        mAbsVolRetryTimes = 0;
                        mAbsVolRetryTimes = 0;
                    /* too many volume change failures, black list the device */
                    /* too many volume change failures, black list the device */
                        blackListCurrentDevice();
                        blackListCurrentDevice("MSG_ABS_VOL_TIMEOUT");
                    } else {
                    } else {
                        mAbsVolRetryTimes += 1;
                        mAbsVolRetryTimes += 1;
                        if (setVolumeNative(mLastRemoteVolume)) {
                        if (setVolumeNative(mLastRemoteVolume)) {
@@ -1664,14 +1664,21 @@ public final class Avrcp {
        return (int) Math.ceil((double) volume * AVRCP_MAX_VOL / mAudioStreamMax);
        return (int) Math.ceil((double) volume * AVRCP_MAX_VOL / mAudioStreamMax);
    }
    }


    private void blackListCurrentDevice() {
    private void blackListCurrentDevice(String reason) {
        mFeatures &= ~BTRC_FEAT_ABSOLUTE_VOLUME;
        mFeatures &= ~BTRC_FEAT_ABSOLUTE_VOLUME;
        mAudioManager.avrcpSupportsAbsoluteVolume(mAddress, isAbsoluteVolumeSupported());
        mAudioManager.avrcpSupportsAbsoluteVolume(mAddress, isAbsoluteVolumeSupported());


        SharedPreferences pref =
        SharedPreferences pref =
                mContext.getSharedPreferences(ABSOLUTE_VOLUME_BLACKLIST, Context.MODE_PRIVATE);
                mContext.getSharedPreferences(ABSOLUTE_VOLUME_BLACKLIST, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = pref.edit();
        SharedPreferences.Editor editor = pref.edit();
        editor.putBoolean(mAddress, true);

        StringBuilder sb = new StringBuilder();
        sb.append("Time: ");
        sb.append(android.text.format.DateFormat.format("yyyy/MM/dd HH:mm:ss",
                                                        System.currentTimeMillis()));
        sb.append(" Reason: ");
        sb.append(reason);
        editor.putString(mAddress, sb.toString());
        editor.apply();
        editor.apply();
    }
    }


@@ -1681,10 +1688,7 @@ public final class Avrcp {
        if (!pref.contains(address)) {
        if (!pref.contains(address)) {
            return feature;
            return feature;
        }
        }
        if (pref.getBoolean(address, false)) {
        return feature & ~BTRC_FEAT_ABSOLUTE_VOLUME;
            feature &= ~BTRC_FEAT_ABSOLUTE_VOLUME;
        }
        return feature;
    }
    }


    public void resetBlackList(String address) {
    public void resetBlackList(String address) {
@@ -2750,8 +2754,14 @@ public final class Avrcp {
        if (allKeys.isEmpty()) {
        if (allKeys.isEmpty()) {
            ProfileService.println(sb, "  None");
            ProfileService.println(sb, "  None");
        } else {
        } else {
            for (String key : allKeys.keySet()) {
            for (Map.Entry<String, ?> entry : allKeys.entrySet()) {
                ProfileService.println(sb, "  " + key);
                String key = entry.getKey();
                Object value = entry.getValue();
                if (value instanceof String) {
                    ProfileService.println(sb, "  " + key + " " + value);
                } else {
                    ProfileService.println(sb, "  " + key + " Reason: Unknown");
                }
            }
            }
        }
        }
    }
    }