Use a ConcurrentSet to keep track of preferences in logger.
The preference set can be modified across different threads, apparently. Change-Id: I4506066d86f7f7d5570c24511db20471d12b0b4a Fixes: 32156066 Test: manual
This commit is contained in:
@@ -21,13 +21,13 @@ import android.content.SharedPreferences;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.ArraySet;
|
|
||||||
|
|
||||||
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentSkipListSet;
|
||||||
|
|
||||||
public class SharedPreferencesLogger implements SharedPreferences {
|
public class SharedPreferencesLogger implements SharedPreferences {
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ public class SharedPreferencesLogger implements SharedPreferences {
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
mTag = tag;
|
mTag = tag;
|
||||||
mMetricsFeature = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
mMetricsFeature = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||||
mPreferenceKeySet = new ArraySet<>();
|
mPreferenceKeySet = new ConcurrentSkipListSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -99,8 +99,12 @@ public class SharedPreferencesLogger implements SharedPreferences {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void logValue(String key, String value) {
|
private void logValue(String key, String value) {
|
||||||
|
logValue(key, value, false /* forceLog */);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void logValue(String key, String value, boolean forceLog) {
|
||||||
final String prefKey = mTag + "/" + key;
|
final String prefKey = mTag + "/" + key;
|
||||||
if (!mPreferenceKeySet.contains(prefKey)) {
|
if (!forceLog && !mPreferenceKeySet.contains(prefKey)) {
|
||||||
// Pref key doesn't exist in set, this is initial display so we skip metrics but
|
// Pref key doesn't exist in set, this is initial display so we skip metrics but
|
||||||
// keeps track of this key.
|
// keeps track of this key.
|
||||||
mPreferenceKeySet.add(prefKey);
|
mPreferenceKeySet.add(prefKey);
|
||||||
@@ -138,8 +142,9 @@ public class SharedPreferencesLogger implements SharedPreferences {
|
|||||||
pm.getPackageInfo(value, PackageManager.MATCH_UNINSTALLED_PACKAGES);
|
pm.getPackageInfo(value, PackageManager.MATCH_UNINSTALLED_PACKAGES);
|
||||||
logPackageName(key, value);
|
logPackageName(key, value);
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
// Clearly not a package, lets log it.
|
// Clearly not a package, and it's unlikely this preference is in prefSet, so
|
||||||
logValue(key, value);
|
// lets force log it.
|
||||||
|
logValue(key, value, true /* forceLog */);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user