This source file includes following definitions.
- getUniqueId
- getUUID
package org.chromium.chrome.browser.identity;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import com.google.common.annotations.VisibleForTesting;
import java.util.UUID;
import javax.annotation.Nullable;
public class UuidBasedUniqueIdentificationGenerator implements UniqueIdentificationGenerator {
public static final String GENERATOR_ID = "UUID";
private final Context mContext;
private final String mPreferenceKey;
public UuidBasedUniqueIdentificationGenerator(Context context, String preferenceKey) {
mContext = context;
mPreferenceKey = preferenceKey;
}
@Override
public String getUniqueId(@Nullable String salt) {
SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(mContext);
String storedUniqueId = preferences.getString(mPreferenceKey, null);
if (storedUniqueId != null) {
return storedUniqueId;
}
String uniqueId = getUUID();
SharedPreferences.Editor editor = preferences.edit();
editor.putString(mPreferenceKey, uniqueId);
editor.apply();
return uniqueId;
}
@VisibleForTesting
String getUUID() {
return UUID.randomUUID().toString();
}
}