summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/common
diff options
context:
space:
mode:
authorEric Erfanian <erfanian@google.com>2017-03-15 14:41:07 -0700
committerEric Erfanian <erfanian@google.com>2017-03-15 16:24:23 -0700
commitd5e47f6da5b08b13ecdfa7f1edc7e12aeb83fab9 (patch)
treeb54abbb51fb7d66e7755a1fbb5db023ff601090b /java/com/android/dialer/common
parent30436e7e6d3f2c8755a91b2b6222b74d465a9e87 (diff)
Update Dialer source from latest green build.
* Refactor voicemail component * Add new enriched calling components Test: treehugger, manual aosp testing Change-Id: I521a0f86327d4b42e14d93927c7d613044ed5942
Diffstat (limited to 'java/com/android/dialer/common')
-rw-r--r--java/com/android/dialer/common/Assert.java30
-rw-r--r--java/com/android/dialer/common/AutoValue_FallibleAsyncTask_FallibleTaskResult.java79
-rw-r--r--java/com/android/dialer/common/FallibleAsyncTask.java6
-rw-r--r--java/com/android/dialer/common/PerAccountSharedPreferences.java146
-rw-r--r--java/com/android/dialer/common/proguard.flags4
-rw-r--r--java/com/android/dialer/common/res/values/config.xml4
6 files changed, 187 insertions, 82 deletions
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<ResultT> extends FallibleAsyncTask.FallibleTaskResult<ResultT> {
-
- 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<ParamsT, ProgressT, ResultT>
*
* @param <ResultT> the type of the result of the background computation
*/
-
- protected abstract static class FallibleTaskResult<ResultT> {
+ @AutoValue
+ public abstract static class FallibleTaskResult<ResultT> {
/** Creates an instance of FallibleTaskResult for the given throwable. */
private static <ResultT> FallibleTaskResult<ResultT> 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<String> 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<String> getStringSet(String key, Set<String> defValue) {
+ return getValue(key, defValue);
+ }
+
+ public boolean contains(String key) {
+ return preferences.contains(getKey(key));
+ }
+
+ private <T> 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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <bool name="spring_hd_codec">false</bool>
+</resources> \ No newline at end of file