From d5e47f6da5b08b13ecdfa7f1edc7e12aeb83fab9 Mon Sep 17 00:00:00 2001 From: Eric Erfanian Date: Wed, 15 Mar 2017 14:41:07 -0700 Subject: Update Dialer source from latest green build. * Refactor voicemail component * Add new enriched calling components Test: treehugger, manual aosp testing Change-Id: I521a0f86327d4b42e14d93927c7d613044ed5942 --- java/com/android/dialer/common/Assert.java | 30 +++++ ...Value_FallibleAsyncTask_FallibleTaskResult.java | 79 ----------- .../android/dialer/common/FallibleAsyncTask.java | 6 +- .../dialer/common/PerAccountSharedPreferences.java | 146 +++++++++++++++++++++ java/com/android/dialer/common/proguard.flags | 4 + .../android/dialer/common/res/values/config.xml | 4 + 6 files changed, 187 insertions(+), 82 deletions(-) delete mode 100644 java/com/android/dialer/common/AutoValue_FallibleAsyncTask_FallibleTaskResult.java create mode 100644 java/com/android/dialer/common/PerAccountSharedPreferences.java create mode 100644 java/com/android/dialer/common/proguard.flags create mode 100644 java/com/android/dialer/common/res/values/config.xml (limited to 'java/com/android/dialer/common') diff --git a/java/com/android/dialer/common/Assert.java b/java/com/android/dialer/common/Assert.java index 00b4f2595..943e1ddcf 100644 --- a/java/com/android/dialer/common/Assert.java +++ b/java/com/android/dialer/common/Assert.java @@ -19,6 +19,7 @@ package com.android.dialer.common; import android.os.Looper; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import javax.annotation.CheckReturnValue; /** Assertions which will result in program termination unless disabled by flags. */ public class Assert { @@ -33,7 +34,9 @@ public class Assert { * Called when a truly exceptional case occurs. * * @throws AssertionError + * @deprecated Use throw Assert.create*FailException() instead. */ + @Deprecated public static void fail() { throw new AssertionError("Fail"); } @@ -43,11 +46,38 @@ public class Assert { * * @param reason the optional reason to supply as the exception message * @throws AssertionError + * @deprecated Use throw Assert.create*FailException() instead. */ + @Deprecated public static void fail(String reason) { throw new AssertionError(reason); } + @CheckReturnValue + public static AssertionError createAssertionFailException(String msg) { + return new AssertionError(msg); + } + + @CheckReturnValue + public static UnsupportedOperationException createUnsupportedOperationFailException() { + return new UnsupportedOperationException(); + } + + @CheckReturnValue + public static UnsupportedOperationException createUnsupportedOperationFailException(String msg) { + return new UnsupportedOperationException(msg); + } + + @CheckReturnValue + public static IllegalStateException createIllegalStateFailException() { + return new IllegalStateException(); + } + + @CheckReturnValue + public static IllegalStateException createIllegalStateFailException(String msg) { + return new IllegalStateException(msg); + } + /** * Ensures the truth of an expression involving one or more parameters to the calling method. * diff --git a/java/com/android/dialer/common/AutoValue_FallibleAsyncTask_FallibleTaskResult.java b/java/com/android/dialer/common/AutoValue_FallibleAsyncTask_FallibleTaskResult.java deleted file mode 100644 index f9d7cea90..000000000 --- a/java/com/android/dialer/common/AutoValue_FallibleAsyncTask_FallibleTaskResult.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package com.android.dialer.common; - -import android.support.annotation.Nullable; -import javax.annotation.Generated; - - - final class AutoValue_FallibleAsyncTask_FallibleTaskResult extends FallibleAsyncTask.FallibleTaskResult { - - private final Throwable throwable; - private final ResultT result; - - AutoValue_FallibleAsyncTask_FallibleTaskResult( - @Nullable Throwable throwable, - @Nullable ResultT result) { - this.throwable = throwable; - this.result = result; - } - - @Nullable - @Override - public Throwable getThrowable() { - return throwable; - } - - @Nullable - @Override - public ResultT getResult() { - return result; - } - - @Override - public String toString() { - return "FallibleTaskResult{" - + "throwable=" + throwable + ", " - + "result=" + result - + "}"; - } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof FallibleAsyncTask.FallibleTaskResult) { - FallibleAsyncTask.FallibleTaskResult that = (FallibleAsyncTask.FallibleTaskResult) o; - return ((this.throwable == null) ? (that.getThrowable() == null) : this.throwable.equals(that.getThrowable())) - && ((this.result == null) ? (that.getResult() == null) : this.result.equals(that.getResult())); - } - return false; - } - - @Override - public int hashCode() { - int h = 1; - h *= 1000003; - h ^= (throwable == null) ? 0 : this.throwable.hashCode(); - h *= 1000003; - h ^= (result == null) ? 0 : this.result.hashCode(); - return h; - } - -} - diff --git a/java/com/android/dialer/common/FallibleAsyncTask.java b/java/com/android/dialer/common/FallibleAsyncTask.java index fbdbda75f..f3abace1a 100644 --- a/java/com/android/dialer/common/FallibleAsyncTask.java +++ b/java/com/android/dialer/common/FallibleAsyncTask.java @@ -20,7 +20,7 @@ import android.os.AsyncTask; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.android.dialer.common.FallibleAsyncTask.FallibleTaskResult; - +import com.google.auto.value.AutoValue; /** * A task that runs work in the background, passing Throwables from {@link @@ -52,8 +52,8 @@ public abstract class FallibleAsyncTask * * @param the type of the result of the background computation */ - - protected abstract static class FallibleTaskResult { + @AutoValue + public abstract static class FallibleTaskResult { /** Creates an instance of FallibleTaskResult for the given throwable. */ private static FallibleTaskResult createFailureResult(@NonNull Throwable t) { diff --git a/java/com/android/dialer/common/PerAccountSharedPreferences.java b/java/com/android/dialer/common/PerAccountSharedPreferences.java new file mode 100644 index 000000000..0ed1b03a5 --- /dev/null +++ b/java/com/android/dialer/common/PerAccountSharedPreferences.java @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +package com.android.dialer.common; + +import android.content.Context; +import android.content.SharedPreferences; +import android.support.annotation.Nullable; +import android.telecom.PhoneAccountHandle; +import java.util.Set; + +/** + * Class that helps us store dialer preferences that are phone account dependent. This is necessary + * for cases such as settings that are phone account dependent e.g endless vm. The logic is to + * essentially store the shared preference by appending the phone account id to the key. + */ +public class PerAccountSharedPreferences { + private final String sharedPrefsKeyPrefix; + private final SharedPreferences preferences; + private final PhoneAccountHandle phoneAccountHandle; + + public PerAccountSharedPreferences( + Context context, PhoneAccountHandle handle, SharedPreferences prefs) { + preferences = prefs; + phoneAccountHandle = handle; + sharedPrefsKeyPrefix = "phone_account_dependent_"; + } + + /** + * Not to be used, currently only used by {@VisualVoicemailPreferences} for legacy reasons. + */ + protected PerAccountSharedPreferences( + Context context, PhoneAccountHandle handle, SharedPreferences prefs, String prefix) { + Assert.checkArgument(prefix.equals("visual_voicemail_")); + preferences = prefs; + phoneAccountHandle = handle; + sharedPrefsKeyPrefix = prefix; + } + + public class Editor { + + private final SharedPreferences.Editor editor; + + private Editor() { + editor = preferences.edit(); + } + + public void apply() { + editor.apply(); + } + + public Editor putBoolean(String key, boolean value) { + editor.putBoolean(getKey(key), value); + return this; + } + + public Editor putFloat(String key, float value) { + editor.putFloat(getKey(key), value); + return this; + } + + public Editor putInt(String key, int value) { + editor.putInt(getKey(key), value); + return this; + } + + public Editor putLong(String key, long value) { + editor.putLong(getKey(key), value); + return this; + } + + public Editor putString(String key, String value) { + editor.putString(getKey(key), value); + return this; + } + + public Editor putStringSet(String key, Set value) { + editor.putStringSet(getKey(key), value); + return this; + } + } + + public Editor edit() { + return new Editor(); + } + + public boolean getBoolean(String key, boolean defValue) { + return getValue(key, defValue); + } + + public float getFloat(String key, float defValue) { + return getValue(key, defValue); + } + + public int getInt(String key, int defValue) { + return getValue(key, defValue); + } + + public long getLong(String key, long defValue) { + return getValue(key, defValue); + } + + public String getString(String key, String defValue) { + return getValue(key, defValue); + } + + @Nullable + public String getString(String key) { + return getValue(key, null); + } + + public Set getStringSet(String key, Set defValue) { + return getValue(key, defValue); + } + + public boolean contains(String key) { + return preferences.contains(getKey(key)); + } + + private T getValue(String key, T defValue) { + if (!contains(key)) { + return defValue; + } + Object object = preferences.getAll().get(getKey(key)); + if (object == null) { + return defValue; + } + return (T) object; + } + + private String getKey(String key) { + return sharedPrefsKeyPrefix + key + "_" + phoneAccountHandle.getId(); + } +} diff --git a/java/com/android/dialer/common/proguard.flags b/java/com/android/dialer/common/proguard.flags new file mode 100644 index 000000000..4b6b84671 --- /dev/null +++ b/java/com/android/dialer/common/proguard.flags @@ -0,0 +1,4 @@ +-assumenosideeffects class com.android.dialer.common.LogUtil { + public static void v(...); + public static void d(...); +} diff --git a/java/com/android/dialer/common/res/values/config.xml b/java/com/android/dialer/common/res/values/config.xml new file mode 100644 index 000000000..c4df279ba --- /dev/null +++ b/java/com/android/dialer/common/res/values/config.xml @@ -0,0 +1,4 @@ + + + false + \ No newline at end of file -- cgit v1.2.3