Add Filtering for snoop logs based on L2CAP and RFCOMM Channels (3/4)

* Change btsnoop logging into disabled, filtered, and full modes
* When ro.isdebuggable is 1, filtered logging is enabled by default
* Otherwise, disabled by default
* When legacy mode is enabled, translate it to full and reset legacy
  property to empty

Bug: 112970672
Bug: 67669544
Test: See that the snoop file always exists but is filtered when
snooplogs are disabled and unfiltered when enabled. Unit tests.
Change-Id: Icec8c4f2f01138b8858765f6f1c1318e1f005135
This commit is contained in:
Ajay Panicker
2018-11-30 15:26:02 -08:00
parent f57f490aa6
commit fc4d53c24a
3 changed files with 131 additions and 47 deletions

View File

@@ -17,12 +17,19 @@
package com.android.settings.development;
import android.content.Context;
import android.os.Build;
import android.os.SystemProperties;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
@@ -31,11 +38,40 @@ public class BluetoothSnoopLogPreferenceController extends DeveloperOptionsPrefe
private static final String PREFERENCE_KEY = "bt_hci_snoop_log";
@VisibleForTesting
static final String BLUETOOTH_BTSNOOP_ENABLE_PROPERTY =
"persist.bluetooth.btsnoopenable";
static final int BTSNOOP_LOG_MODE_DISABLED_INDEX = 0;
@VisibleForTesting
static final int BTSNOOP_LOG_MODE_FILTERED_INDEX = 1;
@VisibleForTesting
static final int BTSNOOP_LOG_MODE_FULL_INDEX = 2;
@VisibleForTesting
static final String BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY = "persist.bluetooth.btsnooplogmode";
private final String[] mListValues;
private final String[] mListEntries;
public BluetoothSnoopLogPreferenceController(Context context) {
super(context);
mListValues = context.getResources().getStringArray(R.array.bt_hci_snoop_log_values);
mListEntries = context.getResources().getStringArray(R.array.bt_hci_snoop_log_entries);
}
// Default mode is FILTERED on userdebug/eng build, DISABLED on user build,
// or can be changed by modifying the global setting.
public int getDefaultModeIndex() {
if (!Build.IS_DEBUGGABLE) {
return BTSNOOP_LOG_MODE_DISABLED_INDEX;
}
final String default_mode = Settings.Global.getString(mContext.getContentResolver(),
Settings.Global.BLUETOOTH_BTSNOOP_DEFAULT_MODE);
for (int i = 0; i < mListValues.length; i++) {
if (TextUtils.equals(default_mode, mListValues[i])) {
return i;
}
}
return BTSNOOP_LOG_MODE_FILTERED_INDEX;
}
@Override
@@ -45,23 +81,32 @@ public class BluetoothSnoopLogPreferenceController extends DeveloperOptionsPrefe
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean enableBtSnoopLog = (Boolean) newValue;
SystemProperties.set(BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, Boolean.toString(enableBtSnoopLog));
SystemProperties.set(BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY, newValue.toString());
updateState(mPreference);
return true;
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
final boolean enableBtSnoopLog = SystemProperties.getBoolean(
BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, false /* def */);
((SwitchPreference) mPreference).setChecked(enableBtSnoopLog);
final ListPreference listPreference = (ListPreference) preference;
final String currentValue = SystemProperties.get(BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY);
int index = getDefaultModeIndex();
for (int i = 0; i < mListValues.length; i++) {
if (TextUtils.equals(currentValue, mListValues[i])) {
index = i;
break;
}
}
listPreference.setValue(mListValues[index]);
listPreference.setSummary(mListEntries[index]);
}
@Override
protected void onDeveloperOptionsSwitchDisabled() {
super.onDeveloperOptionsSwitchDisabled();
SystemProperties.set(BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, Boolean.toString(false));
((SwitchPreference) mPreference).setChecked(false);
SystemProperties.set(BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY, null);
((ListPreference) mPreference).setValue(mListValues[getDefaultModeIndex()]);
((ListPreference) mPreference).setSummary(mListEntries[getDefaultModeIndex()]);
}
}