[UNOp2][Android] Add support for long in the Android pref service
This will be used in follow-up CLs to record prefs related to the user declining top opt-in to history sync Bug: 331568233 Change-Id: Ieac35e7170598fbb827b57a56ba293506bfe960e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5600005 Commit-Queue: Theresa Sullivan <twellington@chromium.org> Auto-Submit: Samar Chehade-Lepleux <samarchehade@google.com> Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com> Reviewed-by: Theresa Sullivan <twellington@chromium.org> Cr-Commit-Position: refs/heads/main@{#1312012}
This commit is contained in:
components/prefs/android
@ -92,6 +92,22 @@ public class PrefService {
|
||||
PrefServiceJni.get().setDouble(mNativePrefServiceAndroid, preference, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param preference The name of the preference.
|
||||
* @return value The value of the specified preference.
|
||||
*/
|
||||
public long getLong(@NonNull String preference) {
|
||||
return PrefServiceJni.get().getLong(mNativePrefServiceAndroid, preference);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param preference The name of the preference.
|
||||
* @param value The value the specified preference will be set to.
|
||||
*/
|
||||
public void setLong(@NonNull String preference, long value) {
|
||||
PrefServiceJni.get().setLong(mNativePrefServiceAndroid, preference, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param preference The name of the preference.
|
||||
* @return value The value of the specified preference.
|
||||
@ -144,6 +160,10 @@ public class PrefService {
|
||||
|
||||
void setDouble(long nativePrefServiceAndroid, String preference, double value);
|
||||
|
||||
long getLong(long nativePrefServiceAndroid, String preference);
|
||||
|
||||
void setLong(long nativePrefServiceAndroid, String preference, long value);
|
||||
|
||||
String getString(long nativePrefServiceAndroid, String preference);
|
||||
|
||||
void setString(long nativePrefServiceAndroid, String preference, String value);
|
||||
|
@ -95,6 +95,24 @@ public class PrefServiceTest {
|
||||
verify(mNativeMock).setDouble(eq(NATIVE_HANDLE), eq(PREF), eq(value));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLong() {
|
||||
long expected = 123L;
|
||||
|
||||
doReturn(expected).when(mNativeMock).getLong(NATIVE_HANDLE, PREF);
|
||||
|
||||
assertEquals(expected, mPrefService.getLong(PREF));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetLong() {
|
||||
long value = 123L;
|
||||
|
||||
mPrefService.setLong(PREF, value);
|
||||
|
||||
verify(mNativeMock).setLong(eq(NATIVE_HANDLE), eq(PREF), eq(value));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetString() {
|
||||
String expected = "foo";
|
||||
|
@ -107,6 +107,19 @@ void PrefServiceAndroid::SetDouble(JNIEnv* env,
|
||||
base::android::ConvertJavaStringToUTF8(env, j_preference), j_value);
|
||||
}
|
||||
|
||||
jlong PrefServiceAndroid::GetLong(JNIEnv* env,
|
||||
const JavaParamRef<jstring>& j_preference) {
|
||||
return pref_service_->GetInt64(
|
||||
base::android::ConvertJavaStringToUTF8(env, j_preference));
|
||||
}
|
||||
|
||||
void PrefServiceAndroid::SetLong(JNIEnv* env,
|
||||
const JavaParamRef<jstring>& j_preference,
|
||||
const jlong j_value) {
|
||||
pref_service_->SetInt64(
|
||||
base::android::ConvertJavaStringToUTF8(env, j_preference), j_value);
|
||||
}
|
||||
|
||||
ScopedJavaLocalRef<jstring> PrefServiceAndroid::GetString(
|
||||
JNIEnv* env,
|
||||
const JavaParamRef<jstring>& j_preference) {
|
||||
|
@ -46,6 +46,11 @@ class COMPONENTS_PREFS_EXPORT PrefServiceAndroid {
|
||||
void SetDouble(JNIEnv* env,
|
||||
const base::android::JavaParamRef<jstring>& j_preference,
|
||||
const jdouble j_value);
|
||||
jlong GetLong(JNIEnv* env,
|
||||
const base::android::JavaParamRef<jstring>& j_preference);
|
||||
void SetLong(JNIEnv* env,
|
||||
const base::android::JavaParamRef<jstring>& j_preference,
|
||||
const jlong j_value);
|
||||
base::android::ScopedJavaLocalRef<jstring> GetString(
|
||||
JNIEnv* env,
|
||||
const base::android::JavaParamRef<jstring>& j_preference);
|
||||
|
Reference in New Issue
Block a user