Merge "Fixing Recents crash when resetting focus of TaskView already returned to the pool." into lmp-mr1-dev
diff --git a/core/java/com/android/internal/inputmethod/InputMethodUtils.java b/core/java/com/android/internal/inputmethod/InputMethodUtils.java
index ac915d1..183527c 100644
--- a/core/java/com/android/internal/inputmethod/InputMethodUtils.java
+++ b/core/java/com/android/internal/inputmethod/InputMethodUtils.java
@@ -16,6 +16,8 @@
package com.android.internal.inputmethod;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.app.AppOpsManager;
import android.content.ContentResolver;
import android.content.Context;
@@ -34,7 +36,9 @@
import android.view.textservice.TextServicesManager;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
@@ -115,8 +119,8 @@
}
/**
- * @deprecated Use {@link Locale} returned from
- * {@link #getFallbackLocaleForDefaultIme(ArrayList)} instead.
+ * @deprecated Use {@link #isSystemImeThatHasSubtypeOf(InputMethodInfo, Context, boolean,
+ * Locale, boolean, String)} instead.
*/
@Deprecated
public static boolean isSystemImeThatHasEnglishKeyboardSubtype(InputMethodInfo imi) {
@@ -126,25 +130,60 @@
return containsSubtypeOf(imi, ENGLISH_LOCALE.getLanguage(), SUBTYPE_MODE_KEYBOARD);
}
+ private static boolean isSystemImeThatHasSubtypeOf(final InputMethodInfo imi,
+ final Context context, final boolean checkDefaultAttribute,
+ @Nullable final Locale requiredLocale, final boolean checkCountry,
+ final String requiredSubtypeMode) {
+ if (!isSystemIme(imi)) {
+ return false;
+ }
+ if (checkDefaultAttribute && !imi.isDefault(context)) {
+ return false;
+ }
+ if (!containsSubtypeOf(imi, requiredLocale, checkCountry, requiredSubtypeMode)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Nullable
public static Locale getFallbackLocaleForDefaultIme(final ArrayList<InputMethodInfo> imis,
final Context context) {
+ // At first, find the fallback locale from the IMEs that are declared as "default" in the
+ // current locale. Note that IME developers can declare an IME as "default" only for
+ // some particular locales but "not default" for other locales.
for (final Locale fallbackLocale : SEARCH_ORDER_OF_FALLBACK_LOCALES) {
for (int i = 0; i < imis.size(); ++i) {
- final InputMethodInfo imi = imis.get(i);
- if (isSystemIme(imi) && imi.isDefault(context) &&
- containsSubtypeOf(imi, fallbackLocale, false /* ignoreCountry */,
- SUBTYPE_MODE_KEYBOARD)) {
+ if (isSystemImeThatHasSubtypeOf(imis.get(i), context,
+ true /* checkDefaultAttribute */, fallbackLocale,
+ true /* checkCountry */, SUBTYPE_MODE_KEYBOARD)) {
return fallbackLocale;
}
}
}
+ // If no fallback locale is found in the above condition, find fallback locales regardless
+ // of the "default" attribute as a last resort.
+ for (final Locale fallbackLocale : SEARCH_ORDER_OF_FALLBACK_LOCALES) {
+ for (int i = 0; i < imis.size(); ++i) {
+ if (isSystemImeThatHasSubtypeOf(imis.get(i), context,
+ false /* checkDefaultAttribute */, fallbackLocale,
+ true /* checkCountry */, SUBTYPE_MODE_KEYBOARD)) {
+ return fallbackLocale;
+ }
+ }
+ }
+ Slog.w(TAG, "Found no fallback locale. imis=" + Arrays.toString(imis.toArray()));
return null;
}
- private static boolean isSystemAuxilialyImeThatHasAutomaticSubtype(InputMethodInfo imi) {
+ private static boolean isSystemAuxilialyImeThatHasAutomaticSubtype(final InputMethodInfo imi,
+ final Context context, final boolean checkDefaultAttribute) {
if (!isSystemIme(imi)) {
return false;
}
+ if (checkDefaultAttribute && !imi.isDefault(context)) {
+ return false;
+ }
if (!imi.isAuxiliaryIme()) {
return false;
}
@@ -166,98 +205,184 @@
}
}
- public static ArrayList<InputMethodInfo> getDefaultEnabledImes(
- Context context, boolean isSystemReady, ArrayList<InputMethodInfo> imis) {
- // OK to store null in fallbackLocale because isImeThatHasSubtypeOf() is null-tolerant.
- final Locale fallbackLocale = getFallbackLocaleForDefaultIme(imis, context);
+ private static final class InputMethodListBuilder {
+ // Note: We use LinkedHashSet instead of android.util.ArraySet because the enumeration
+ // order can have non-trivial effect in the call sites.
+ @NonNull
+ private final LinkedHashSet<InputMethodInfo> mInputMethodSet = new LinkedHashSet<>();
- if (!isSystemReady) {
- final ArrayList<InputMethodInfo> retval = new ArrayList<>();
+ public InputMethodListBuilder fillImes(final ArrayList<InputMethodInfo> imis,
+ final Context context, final boolean checkDefaultAttribute,
+ @Nullable final Locale locale, final boolean checkCountry,
+ final String requiredSubtypeMode) {
for (int i = 0; i < imis.size(); ++i) {
final InputMethodInfo imi = imis.get(i);
- // TODO: We should check isAsciiCapable instead of relying on fallbackLocale.
- if (isSystemIme(imi) && imi.isDefault(context) &&
- isImeThatHasSubtypeOf(imi, fallbackLocale, false /* ignoreCountry */,
- SUBTYPE_MODE_KEYBOARD)) {
- retval.add(imi);
+ if (isSystemImeThatHasSubtypeOf(imi, context, checkDefaultAttribute, locale,
+ checkCountry, requiredSubtypeMode)) {
+ mInputMethodSet.add(imi);
}
}
- return retval;
+ return this;
}
- // OK to store null in fallbackLocale because isImeThatHasSubtypeOf() is null-tolerant.
- final Locale systemLocale = getSystemLocaleFromContext(context);
- // TODO: Use LinkedHashSet to simplify the code.
- final ArrayList<InputMethodInfo> retval = new ArrayList<>();
- boolean systemLocaleKeyboardImeFound = false;
-
- // First, try to find IMEs with taking the system locale country into consideration.
- for (int i = 0; i < imis.size(); ++i) {
- final InputMethodInfo imi = imis.get(i);
- if (!isSystemIme(imi) || !imi.isDefault(context)) {
- continue;
+ // TODO: The behavior of InputMethodSubtype#overridesImplicitlyEnabledSubtype() should be
+ // documented more clearly.
+ public InputMethodListBuilder fillAuxiliaryImes(final ArrayList<InputMethodInfo> imis,
+ final Context context) {
+ // If one or more auxiliary input methods are available, OK to stop populating the list.
+ for (final InputMethodInfo imi : mInputMethodSet) {
+ if (imi.isAuxiliaryIme()) {
+ return this;
+ }
}
- final boolean isSystemLocaleKeyboardIme = isImeThatHasSubtypeOf(imi, systemLocale,
- false /* ignoreCountry */, SUBTYPE_MODE_KEYBOARD);
- // TODO: We should check isAsciiCapable instead of relying on fallbackLocale.
- // TODO: Use LinkedHashSet to simplify the code.
- if (isSystemLocaleKeyboardIme ||
- isImeThatHasSubtypeOf(imi, fallbackLocale, false /* ignoreCountry */,
- SUBTYPE_MODE_ANY)) {
- retval.add(imi);
- }
- systemLocaleKeyboardImeFound |= isSystemLocaleKeyboardIme;
- }
-
- // System locale country doesn't match any IMEs, try to find IMEs in a country-agnostic
- // way.
- if (!systemLocaleKeyboardImeFound) {
+ boolean added = false;
for (int i = 0; i < imis.size(); ++i) {
final InputMethodInfo imi = imis.get(i);
- if (!isSystemIme(imi) || !imi.isDefault(context)) {
- continue;
- }
- if (isImeThatHasSubtypeOf(imi, fallbackLocale, false /* ignoreCountry */,
- SUBTYPE_MODE_KEYBOARD)) {
- // IMEs that have fallback locale are already added in the previous loop. We
- // don't need to add them again here.
- // TODO: Use LinkedHashSet to simplify the code.
- continue;
- }
- if (isImeThatHasSubtypeOf(imi, systemLocale, true /* ignoreCountry */,
- SUBTYPE_MODE_ANY)) {
- retval.add(imi);
+ if (isSystemAuxilialyImeThatHasAutomaticSubtype(imi, context,
+ true /* checkDefaultAttribute */)) {
+ mInputMethodSet.add(imi);
+ added = true;
}
}
+ if (added) {
+ return this;
+ }
+ for (int i = 0; i < imis.size(); ++i) {
+ final InputMethodInfo imi = imis.get(i);
+ if (isSystemAuxilialyImeThatHasAutomaticSubtype(imi, context,
+ false /* checkDefaultAttribute */)) {
+ mInputMethodSet.add(imi);
+ }
+ }
+ return this;
}
- // If one or more auxiliary input methods are available, OK to stop populating the list.
- for (int i = 0; i < retval.size(); ++i) {
- if (retval.get(i).isAuxiliaryIme()) {
- return retval;
- }
+ public boolean isEmpty() {
+ return mInputMethodSet.isEmpty();
}
- for (int i = 0; i < imis.size(); ++i) {
- final InputMethodInfo imi = imis.get(i);
- if (isSystemAuxilialyImeThatHasAutomaticSubtype(imi)) {
- retval.add(imi);
- }
+
+ @NonNull
+ public ArrayList<InputMethodInfo> build() {
+ return new ArrayList<>(mInputMethodSet);
}
- return retval;
}
- public static boolean isImeThatHasSubtypeOf(final InputMethodInfo imi,
- final Locale locale, final boolean ignoreCountry, final String mode) {
- if (locale == null) {
- return false;
+ private static InputMethodListBuilder getMinimumKeyboardSetWithoutSystemLocale(
+ final ArrayList<InputMethodInfo> imis, final Context context,
+ @Nullable final Locale fallbackLocale) {
+ // Before the system becomes ready, we pick up at least one keyboard in the following order.
+ // The first user (device owner) falls into this category.
+ // 1. checkDefaultAttribute: true, locale: fallbackLocale, checkCountry: true
+ // 2. checkDefaultAttribute: false, locale: fallbackLocale, checkCountry: true
+ // 3. checkDefaultAttribute: true, locale: fallbackLocale, checkCountry: false
+ // 4. checkDefaultAttribute: false, locale: fallbackLocale, checkCountry: false
+ // TODO: We should check isAsciiCapable instead of relying on fallbackLocale.
+
+ final InputMethodListBuilder builder = new InputMethodListBuilder();
+ builder.fillImes(imis, context, true /* checkDefaultAttribute */, fallbackLocale,
+ true /* checkCountry */, SUBTYPE_MODE_KEYBOARD);
+ if (!builder.isEmpty()) {
+ return builder;
}
- return containsSubtypeOf(imi, locale, ignoreCountry, mode);
+ builder.fillImes(imis, context, false /* checkDefaultAttribute */, fallbackLocale,
+ true /* checkCountry */, SUBTYPE_MODE_KEYBOARD);
+ if (!builder.isEmpty()) {
+ return builder;
+ }
+ builder.fillImes(imis, context, true /* checkDefaultAttribute */, fallbackLocale,
+ false /* checkCountry */, SUBTYPE_MODE_KEYBOARD);
+ if (!builder.isEmpty()) {
+ return builder;
+ }
+ builder.fillImes(imis, context, false /* checkDefaultAttribute */, fallbackLocale,
+ false /* checkCountry */, SUBTYPE_MODE_KEYBOARD);
+ if (!builder.isEmpty()) {
+ return builder;
+ }
+ Slog.w(TAG, "No software keyboard is found. imis=" + Arrays.toString(imis.toArray())
+ + " fallbackLocale=" + fallbackLocale);
+ return builder;
+ }
+
+ private static InputMethodListBuilder getMinimumKeyboardSetWithSystemLocale(
+ final ArrayList<InputMethodInfo> imis, final Context context,
+ @Nullable final Locale systemLocale, @Nullable final Locale fallbackLocale) {
+ // Once the system becomes ready, we pick up at least one keyboard in the following order.
+ // Secondary users fall into this category in general.
+ // 1. checkDefaultAttribute: true, locale: systemLocale, checkCountry: true
+ // 2. checkDefaultAttribute: true, locale: systemLocale, checkCountry: false
+ // 3. checkDefaultAttribute: true, locale: fallbackLocale, checkCountry: true
+ // 4. checkDefaultAttribute: true, locale: fallbackLocale, checkCountry: false
+ // 5. checkDefaultAttribute: false, locale: fallbackLocale, checkCountry: true
+ // 6. checkDefaultAttribute: false, locale: fallbackLocale, checkCountry: false
+ // TODO: We should check isAsciiCapable instead of relying on fallbackLocale.
+
+ final InputMethodListBuilder builder = new InputMethodListBuilder();
+ builder.fillImes(imis, context, true /* checkDefaultAttribute */, systemLocale,
+ true /* checkCountry */, SUBTYPE_MODE_KEYBOARD);
+ if (!builder.isEmpty()) {
+ return builder;
+ }
+ builder.fillImes(imis, context, true /* checkDefaultAttribute */, systemLocale,
+ false /* checkCountry */, SUBTYPE_MODE_KEYBOARD);
+ if (!builder.isEmpty()) {
+ return builder;
+ }
+ builder.fillImes(imis, context, true /* checkDefaultAttribute */, fallbackLocale,
+ true /* checkCountry */, SUBTYPE_MODE_KEYBOARD);
+ if (!builder.isEmpty()) {
+ return builder;
+ }
+ builder.fillImes(imis, context, true /* checkDefaultAttribute */, fallbackLocale,
+ false /* checkCountry */, SUBTYPE_MODE_KEYBOARD);
+ if (!builder.isEmpty()) {
+ return builder;
+ }
+ builder.fillImes(imis, context, false /* checkDefaultAttribute */, fallbackLocale,
+ true /* checkCountry */, SUBTYPE_MODE_KEYBOARD);
+ if (!builder.isEmpty()) {
+ return builder;
+ }
+ builder.fillImes(imis, context, false /* checkDefaultAttribute */, fallbackLocale,
+ false /* checkCountry */, SUBTYPE_MODE_KEYBOARD);
+ if (!builder.isEmpty()) {
+ return builder;
+ }
+ Slog.w(TAG, "No software keyboard is found. imis=" + Arrays.toString(imis.toArray())
+ + " systemLocale=" + systemLocale + " fallbackLocale=" + fallbackLocale);
+ return builder;
+ }
+
+ public static ArrayList<InputMethodInfo> getDefaultEnabledImes(final Context context,
+ final boolean isSystemReady, final ArrayList<InputMethodInfo> imis) {
+ final Locale fallbackLocale = getFallbackLocaleForDefaultIme(imis, context);
+ if (!isSystemReady) {
+ // When the system is not ready, the system locale is not stable and reliable. Hence
+ // we will pick up IMEs that support software keyboard based on the fallback locale.
+ // Also pick up suitable IMEs regardless of the software keyboard support.
+ // (e.g. Voice IMEs)
+ return getMinimumKeyboardSetWithoutSystemLocale(imis, context, fallbackLocale)
+ .fillImes(imis, context, true /* checkDefaultAttribute */, fallbackLocale,
+ true /* checkCountry */, SUBTYPE_MODE_ANY)
+ .build();
+ }
+
+ // When the system is ready, we will primarily rely on the system locale, but also keep
+ // relying on the fallback locale as a last resort.
+ // Also pick up suitable IMEs regardless of the software keyboard support (e.g. Voice IMEs),
+ // then pick up suitable auxiliary IMEs when necessary (e.g. Voice IMEs with "automatic"
+ // subtype)
+ final Locale systemLocale = getSystemLocaleFromContext(context);
+ return getMinimumKeyboardSetWithSystemLocale(imis, context, systemLocale, fallbackLocale)
+ .fillImes(imis, context, true /* checkDefaultAttribute */, systemLocale,
+ true /* checkCountry */, SUBTYPE_MODE_ANY)
+ .fillAuxiliaryImes(imis, context)
+ .build();
}
/**
- * @deprecated Use {@link #isSystemIme(InputMethodInfo)} and
- * {@link InputMethodInfo#isDefault(Context)} and
- * {@link #isImeThatHasSubtypeOf(InputMethodInfo, Locale, boolean, String))} instead.
+ * @deprecated Use {@link #isSystemImeThatHasSubtypeOf(InputMethodInfo, Context, boolean,
+ * Locale, boolean, String)} instead.
*/
@Deprecated
public static boolean isValidSystemDefaultIme(
@@ -285,22 +410,25 @@
}
public static boolean containsSubtypeOf(final InputMethodInfo imi,
- final Locale locale, final boolean ignoreCountry, final String mode) {
+ @Nullable final Locale locale, final boolean checkCountry, final String mode) {
+ if (locale == null) {
+ return false;
+ }
final int N = imi.getSubtypeCount();
for (int i = 0; i < N; ++i) {
final InputMethodSubtype subtype = imi.getSubtypeAt(i);
- if (ignoreCountry) {
- final Locale subtypeLocale = new Locale(getLanguageFromLocaleString(
- subtype.getLocale()));
- if (!subtypeLocale.getLanguage().equals(locale.getLanguage())) {
- continue;
- }
- } else {
+ if (checkCountry) {
// TODO: Use {@link Locale#toLanguageTag()} and
// {@link Locale#forLanguageTag(languageTag)} instead.
if (!TextUtils.equals(subtype.getLocale(), locale.toString())) {
continue;
}
+ } else {
+ final Locale subtypeLocale = new Locale(getLanguageFromLocaleString(
+ subtype.getLocale()));
+ if (!subtypeLocale.getLanguage().equals(locale.getLanguage())) {
+ continue;
+ }
}
if (mode == SUBTYPE_MODE_ANY || TextUtils.isEmpty(mode) ||
mode.equalsIgnoreCase(subtype.getMode())) {
@@ -465,19 +593,9 @@
return applicableSubtypes;
}
- private static List<InputMethodSubtype> getEnabledInputMethodSubtypeList(
- Context context, InputMethodInfo imi, List<InputMethodSubtype> enabledSubtypes,
- boolean allowsImplicitlySelectedSubtypes) {
- if (allowsImplicitlySelectedSubtypes && enabledSubtypes.isEmpty()) {
- enabledSubtypes = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(
- context.getResources(), imi);
- }
- return InputMethodSubtype.sort(context, 0, imi, enabledSubtypes);
- }
-
/**
* Returns the language component of a given locale string.
- * TODO: Use {@link Locale#toLanguageTag()} and {@link Locale#forLanguageTag(languageTag)}
+ * TODO: Use {@link Locale#toLanguageTag()} and {@link Locale#forLanguageTag(String)}
*/
public static String getLanguageFromLocaleString(String locale) {
final int idx = locale.indexOf('_');
diff --git a/core/res/res/values-mcc204-mnc04/config.xml b/core/res/res/values-mcc204-mnc04/config.xml
index d7484e1..0e67669 100644
--- a/core/res/res/values-mcc204-mnc04/config.xml
+++ b/core/res/res/values-mcc204-mnc04/config.xml
@@ -38,4 +38,9 @@
1. Lenient threshold
-->
<integer name="config_LTE_RSRP_threshold_type">0</integer>
+
+ <string-array translatable="false" name="config_sms_convert_destination_number_support">
+ <item>true;BAE0000000000000</item>
+ <item>false</item>
+ </string-array>
</resources>
diff --git a/core/res/res/values-mcc310-mnc004/config.xml b/core/res/res/values-mcc310-mnc004/config.xml
index 423e250..6a34a3d 100644
--- a/core/res/res/values-mcc310-mnc004/config.xml
+++ b/core/res/res/values-mcc310-mnc004/config.xml
@@ -34,4 +34,9 @@
</string-array>
<bool name="config_auto_attach_data_on_creation">false</bool>
+
+ <string-array translatable="false" name="config_sms_convert_destination_number_support">
+ <item>true</item>
+ </string-array>
+
</resources>
diff --git a/core/res/res/values-mcc311-mnc480/config.xml b/core/res/res/values-mcc311-mnc480/config.xml
index 8cb2928..2022d12 100644
--- a/core/res/res/values-mcc311-mnc480/config.xml
+++ b/core/res/res/values-mcc311-mnc480/config.xml
@@ -56,4 +56,8 @@
1. Lenient threshold
-->
<integer name="config_LTE_RSRP_threshold_type">0</integer>
+
+ <string-array translatable="false" name="config_sms_convert_destination_number_support">
+ <item>true</item>
+ </string-array>
</resources>
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 52ef4f9..6713944 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -1919,4 +1919,20 @@
<!-- Show the next-alarm as a zen exit condition if it occurs in the next n hours. -->
<integer name="config_next_alarm_condition_lookahead_threshold_hrs">12</integer>
+
+ <!-- This config is used to check if the carrier requires converting destination
+ number before sending out a SMS.
+ Formats for this configuration as below:
+ [true or false][;optional gid]
+ The logic to pick up the configuration:
+ (1) If the "config_sms_convert_destination_number_support" array has no gid
+ special item, the last one will be picked
+ (2) If the "config_sms_convert_destination_number_support" array has gid special
+ item and it matches the current sim's gid, it will be picked.
+ (3) If the "config_sms_convert_destination_number_support" array has gid special
+ item but it doesn't match the current sim's gid, the last one without gid
+ will be picked -->
+ <string-array translatable="false" name="config_sms_convert_destination_number_support">
+ <item>false</item>
+ </string-array>
</resources>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 513510a..0ee8b7c 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -2105,6 +2105,7 @@
<java-symbol type="layout" name="simple_account_item" />
<java-symbol type="id" name="scrollIndicatorUp" />
<java-symbol type="id" name="scrollIndicatorDown" />
+ <java-symbol type="array" name="config_sms_convert_destination_number_support" />
<!-- From SignalStrength -->
<java-symbol type="integer" name="config_LTE_RSRP_threshold_type" />
diff --git a/core/tests/inputmethodtests/src/android/os/InputMethodTest.java b/core/tests/inputmethodtests/src/android/os/InputMethodTest.java
index 577dd64..1557918 100644
--- a/core/tests/inputmethodtests/src/android/os/InputMethodTest.java
+++ b/core/tests/inputmethodtests/src/android/os/InputMethodTest.java
@@ -33,6 +33,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
+import java.util.Objects;
public class InputMethodTest extends InstrumentationTestCase {
private static final boolean IS_AUX = true;
@@ -46,84 +47,104 @@
private static final Locale LOCALE_EN_IN = new Locale("en", "IN");
private static final Locale LOCALE_HI = new Locale("hi");
private static final Locale LOCALE_JA_JP = new Locale("ja", "JP");
+ private static final Locale LOCALE_ZH_CN = new Locale("zh", "CN");
+ private static final Locale LOCALE_ZH_TW = new Locale("zh", "TW");
private static final String SUBTYPE_MODE_KEYBOARD = "keyboard";
private static final String SUBTYPE_MODE_VOICE = "voice";
@SmallTest
public void testVoiceImes() throws Exception {
// locale: en_US
- assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_US, !IS_SYSTEM_READY,
- "DummyDefaultEnKeyboardIme");
- assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_US, !IS_SYSTEM_READY,
- "DummyDefaultEnKeyboardIme");
- assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_US, IS_SYSTEM_READY,
- "DummyDefaultAutoVoiceIme", "DummyDefaultEnKeyboardIme");
- assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_US, IS_SYSTEM_READY,
- "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1",
- "DummyDefaultEnKeyboardIme");
+ assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_US,
+ !IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
+ assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_US,
+ !IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme");
+ assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_US,
+ IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
+ assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_US,
+ IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyNonDefaultAutoVoiceIme0",
+ "DummyNonDefaultAutoVoiceIme1");
// locale: en_GB
- assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_GB, !IS_SYSTEM_READY,
- "DummyDefaultEnKeyboardIme");
- assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_GB, !IS_SYSTEM_READY,
- "DummyDefaultEnKeyboardIme");
- assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_GB, IS_SYSTEM_READY,
- "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
- assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_GB, IS_SYSTEM_READY,
- "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1",
- "DummyDefaultEnKeyboardIme");
+ assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_GB,
+ !IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
+ assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_GB,
+ !IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme");
+ assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_GB,
+ IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
+ assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_GB,
+ IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyNonDefaultAutoVoiceIme0",
+ "DummyNonDefaultAutoVoiceIme1");
// locale: ja_JP
- assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_JA_JP, !IS_SYSTEM_READY,
- "DummyDefaultEnKeyboardIme");
- assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_JA_JP, !IS_SYSTEM_READY,
- "DummyDefaultEnKeyboardIme");
- assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_JA_JP, IS_SYSTEM_READY,
- "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
- assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_JA_JP, IS_SYSTEM_READY,
- "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1",
- "DummyDefaultEnKeyboardIme");
+ assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_JA_JP,
+ !IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
+ assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_JA_JP,
+ !IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme");
+ assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_JA_JP,
+ IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
+ assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_JA_JP,
+ IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyNonDefaultAutoVoiceIme0",
+ "DummyNonDefaultAutoVoiceIme1");
}
@SmallTest
public void testKeyboardImes() throws Exception {
// locale: en_US
- assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_US, !IS_SYSTEM_READY,
- "com.android.apps.inputmethod.latin");
- assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_US, IS_SYSTEM_READY,
- "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin");
+ assertDefaultEnabledImes(getSamplePreinstalledImes("en-rUS"), LOCALE_EN_US,
+ !IS_SYSTEM_READY, "com.android.apps.inputmethod.latin");
+ assertDefaultEnabledImes(getSamplePreinstalledImes("en-rUS"), LOCALE_EN_US,
+ IS_SYSTEM_READY, "com.android.apps.inputmethod.latin",
+ "com.android.apps.inputmethod.voice");
// locale: en_GB
- assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_GB, !IS_SYSTEM_READY,
- "com.android.apps.inputmethod.latin");
- assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_GB, IS_SYSTEM_READY,
- "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin");
+ assertDefaultEnabledImes(getSamplePreinstalledImes("en-rGB"), LOCALE_EN_GB,
+ !IS_SYSTEM_READY, "com.android.apps.inputmethod.latin");
+ assertDefaultEnabledImes(getSamplePreinstalledImes("en-rGB"), LOCALE_EN_GB,
+ IS_SYSTEM_READY, "com.android.apps.inputmethod.latin",
+ "com.android.apps.inputmethod.voice");
// locale: en_IN
- assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_IN, !IS_SYSTEM_READY,
- "com.android.apps.inputmethod.latin");
- assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_IN, IS_SYSTEM_READY,
- "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin",
- "com.android.apps.inputmethod.hindi");
+ assertDefaultEnabledImes(getSamplePreinstalledImes("en-rIN"), LOCALE_EN_IN,
+ !IS_SYSTEM_READY, "com.android.apps.inputmethod.latin");
+ assertDefaultEnabledImes(getSamplePreinstalledImes("en-rIN"), LOCALE_EN_IN,
+ IS_SYSTEM_READY, "com.android.apps.inputmethod.hindi",
+ "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.voice");
// locale: hi
- assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_HI, !IS_SYSTEM_READY,
- "com.android.apps.inputmethod.latin");
- assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_HI, IS_SYSTEM_READY,
- "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin",
- "com.android.apps.inputmethod.hindi");
+ assertDefaultEnabledImes(getSamplePreinstalledImes("hi"), LOCALE_HI,
+ !IS_SYSTEM_READY, "com.android.apps.inputmethod.latin");
+ assertDefaultEnabledImes(getSamplePreinstalledImes("hi"), LOCALE_HI,
+ IS_SYSTEM_READY, "com.android.apps.inputmethod.hindi",
+ "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.voice");
// locale: ja_JP
- assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_JA_JP, !IS_SYSTEM_READY,
- "com.android.apps.inputmethod.latin");
- assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_JA_JP, IS_SYSTEM_READY,
- "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin",
- "com.android.apps.inputmethod.japanese");
+ assertDefaultEnabledImes(getSamplePreinstalledImes("ja-rJP"), LOCALE_JA_JP,
+ !IS_SYSTEM_READY, "com.android.apps.inputmethod.latin");
+ assertDefaultEnabledImes(getSamplePreinstalledImes("ja-rJP"), LOCALE_JA_JP,
+ IS_SYSTEM_READY, "com.android.apps.inputmethod.japanese",
+ "com.android.apps.inputmethod.voice");
+
+ // locale: zh_CN
+ assertDefaultEnabledImes(getSamplePreinstalledImes("zh-rCN"), LOCALE_ZH_CN,
+ !IS_SYSTEM_READY, "com.android.apps.inputmethod.latin");
+ assertDefaultEnabledImes(getSamplePreinstalledImes("zh-rCN"), LOCALE_ZH_CN,
+ IS_SYSTEM_READY, "com.android.apps.inputmethod.pinyin",
+ "com.android.apps.inputmethod.voice");
+
+ // locale: zh_TW
+ // Note: In this case, no IME is suitable for the system locale. Hence we will pick up a
+ // fallback IME regardless of the "default" attribute.
+ assertDefaultEnabledImes(getSamplePreinstalledImes("zh-rTW"), LOCALE_ZH_TW,
+ !IS_SYSTEM_READY, "com.android.apps.inputmethod.latin");
+ assertDefaultEnabledImes(getSamplePreinstalledImes("zh-rTW"), LOCALE_ZH_TW,
+ IS_SYSTEM_READY, "com.android.apps.inputmethod.latin",
+ "com.android.apps.inputmethod.voice");
}
@SmallTest
public void testParcelable() throws Exception {
- final ArrayList<InputMethodInfo> originalList = getSamplePreinstalledImes();
+ final ArrayList<InputMethodInfo> originalList = getSamplePreinstalledImes("en-rUS");
final List<InputMethodInfo> clonedList = cloneViaParcel(originalList);
assertNotNull(clonedList);
final List<InputMethodInfo> clonedClonedList = cloneViaParcel(clonedList);
@@ -139,11 +160,14 @@
}
private void assertDefaultEnabledImes(final ArrayList<InputMethodInfo> preinstalledImes,
- final Locale systemLocale, final boolean isSystemReady, String... imeNames) {
+ final Locale systemLocale, final boolean isSystemReady, String... expectedImeNames) {
final Context context = getInstrumentation().getTargetContext();
- assertEquals(new HashSet<String>(Arrays.asList(imeNames)),
- getPackageNames(callGetDefaultEnabledImesUnderWithLocale(context,
- isSystemReady, preinstalledImes, systemLocale)));
+ final String[] actualImeNames = getPackageNames(callGetDefaultEnabledImesUnderWithLocale(
+ context, isSystemReady, preinstalledImes, systemLocale));
+ assertEquals(expectedImeNames.length, actualImeNames.length);
+ for (int i = 0; i < expectedImeNames.length; ++i) {
+ assertEquals(expectedImeNames[i], actualImeNames[i]);
+ }
}
private static List<InputMethodInfo> cloneViaParcel(final List<InputMethodInfo> list) {
@@ -172,11 +196,10 @@
}
}
- private HashSet<String> getPackageNames(final ArrayList<InputMethodInfo> imis) {
- final HashSet<String> packageNames = new HashSet<>();
- for (final InputMethodInfo imi : imis) {
- final String actualPackageName = imi.getPackageName();
- packageNames.add(actualPackageName);
+ private String[] getPackageNames(final ArrayList<InputMethodInfo> imis) {
+ final String[] packageNames = new String[imis.size()];
+ for (int i = 0; i < imis.size(); ++i) {
+ packageNames[i] = imis.get(i).getPackageName();
}
return packageNames;
}
@@ -278,21 +301,34 @@
return preinstalledImes;
}
- private static ArrayList<InputMethodInfo> getSamplePreinstalledImes() {
+ private static boolean contains(final String[] textList, final String textToBeChecked) {
+ if (textList == null) {
+ return false;
+ }
+ for (final String text : textList) {
+ if (Objects.equals(textToBeChecked, text)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static ArrayList<InputMethodInfo> getSamplePreinstalledImes(final String localeString) {
ArrayList<InputMethodInfo> preinstalledImes = new ArrayList<>();
// a dummy Voice IME
{
+ final boolean isDefaultIme = false;
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
subtypes.add(createDummyInputMethodSubtype("", SUBTYPE_MODE_VOICE, IS_AUX,
IS_AUTO, !IS_ASCII_CAPABLE));
preinstalledImes.add(createDummyInputMethodInfo("com.android.apps.inputmethod.voice",
- "com.android.inputmethod.voice", "DummyVoiceIme", IS_AUX, IS_DEFAULT,
+ "com.android.inputmethod.voice", "DummyVoiceIme", IS_AUX, isDefaultIme,
subtypes));
}
-
// a dummy Hindi IME
{
+ final boolean isDefaultIme = contains(new String[]{ "hi", "en-rIN" }, localeString);
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
// TODO: This subtype should be marked as IS_ASCII_CAPABLE
subtypes.add(createDummyInputMethodSubtype("en_IN", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
@@ -300,32 +336,36 @@
subtypes.add(createDummyInputMethodSubtype("hi", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
!IS_AUTO, !IS_ASCII_CAPABLE));
preinstalledImes.add(createDummyInputMethodInfo("com.android.apps.inputmethod.hindi",
- "com.android.inputmethod.hindi", "DummyHindiIme", !IS_AUX, IS_DEFAULT,
+ "com.android.inputmethod.hindi", "DummyHindiIme", !IS_AUX, isDefaultIme,
subtypes));
}
// a dummy Pinyin IME
{
+ final boolean isDefaultIme = contains(new String[]{ "zh-rCN" }, localeString);
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
subtypes.add(createDummyInputMethodSubtype("zh_CN", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
!IS_AUTO, !IS_ASCII_CAPABLE));
- preinstalledImes.add(createDummyInputMethodInfo("ccom.android.apps.inputmethod.pinyin",
- "com.android.apps.inputmethod.pinyin", "DummyPinyinIme", !IS_AUX, IS_DEFAULT,
+ preinstalledImes.add(createDummyInputMethodInfo("com.android.apps.inputmethod.pinyin",
+ "com.android.apps.inputmethod.pinyin", "DummyPinyinIme", !IS_AUX, isDefaultIme,
subtypes));
}
- // a dummy Korian IME
+ // a dummy Korean IME
{
+ final boolean isDefaultIme = contains(new String[]{ "ko" }, localeString);
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
subtypes.add(createDummyInputMethodSubtype("ko", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
!IS_AUTO, !IS_ASCII_CAPABLE));
preinstalledImes.add(createDummyInputMethodInfo("com.android.apps.inputmethod.korean",
- "com.android.apps.inputmethod.korean", "DummyKorianIme", !IS_AUX, IS_DEFAULT,
+ "com.android.apps.inputmethod.korean", "DummyKoreanIme", !IS_AUX, isDefaultIme,
subtypes));
}
// a dummy Latin IME
{
+ final boolean isDefaultIme = contains(
+ new String[]{ "en-rUS", "en-rGB", "en-rIN", "en", "hi" }, localeString);
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
subtypes.add(createDummyInputMethodSubtype("en_US", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
!IS_AUTO, IS_ASCII_CAPABLE));
@@ -336,12 +376,13 @@
subtypes.add(createDummyInputMethodSubtype("hi", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
!IS_AUTO, IS_ASCII_CAPABLE));
preinstalledImes.add(createDummyInputMethodInfo("com.android.apps.inputmethod.latin",
- "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT,
+ "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, isDefaultIme,
subtypes));
}
// a dummy Japanese IME
{
+ final boolean isDefaultIme = contains(new String[]{ "ja", "ja-rJP" }, localeString);
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
subtypes.add(createDummyInputMethodSubtype("ja", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
!IS_AUTO, !IS_ASCII_CAPABLE));
@@ -349,7 +390,7 @@
!IS_AUTO, !IS_ASCII_CAPABLE));
preinstalledImes.add(createDummyInputMethodInfo("com.android.apps.inputmethod.japanese",
"com.android.apps.inputmethod.japanese", "DummyJapaneseIme", !IS_AUX,
- IS_DEFAULT, subtypes));
+ isDefaultIme, subtypes));
}
return preinstalledImes;
diff --git a/docs/html/distribute/tools/promote/brand.jd b/docs/html/distribute/tools/promote/brand.jd
index 9b9f9a3..22441df 100644
--- a/docs/html/distribute/tools/promote/brand.jd
+++ b/docs/html/distribute/tools/promote/brand.jd
@@ -11,17 +11,17 @@
<p>Use of the Android or Google Play brands must be reviewed by the Android
Partner Marketing team. Use the <a
-href="https://docs.google.com/forms/d/1YE5gZpAAcFKjYcUddCsK1Bv9a9Y-luaLVnkazVlaJ2w/viewform">Android and Google Play Brand Permissions Inquiry form</a> to submit your
+href="https://support.google.com/googleplay/contact/brand_developer">Android and Google Play Brand Permissions Inquiry form</a> to submit your
marketing for review.</p>
<h2 id="brand-android">Android</h2>
<p>The following are guidelines for the Android brand
and related assets.</p>
-
+
<h4 style="clear:right">Android in text</h4>
-
+
<div style="float:right;clear:right;width:200px;margin:0 0 20px 30px">
<img alt="" src="{@docRoot}images/brand/mediaplayer.png">
</div>
@@ -46,7 +46,7 @@
</ul>
</li>
</ul>
-
+
<p>Any use of the Android name needs to include this
attribution in your communication:</p>
<blockquote><em>Android is a trademark of Google Inc.</em></blockquote></p>
@@ -70,10 +70,10 @@
<p>When using the Android Robot or any modification of it, proper attribution is
required under the terms of the <a href="http://creativecommons.org/licenses/by/3.0/">Creative
Commons Attribution 3.0</a> license:</p>
-
+
<blockquote><em>The Android robot is reproduced or modified from work created and shared by Google and
used according to terms described in the Creative Commons 3.0 Attribution License.</em></blockquote>
-
+
<p>You may not file trademark applications incorporating the Android robot
logo or derivatives thereof within your company logo or business name. We
want to ensure that the Android robot remains available for all to use.</p>
@@ -119,7 +119,7 @@
<a href="{@docRoot}images/brand/Google_Play_Store_600.png">600x576</a>
</p>
</div>
-
+
<h4>Google Play store icon</h4>
<p>You may use the Google Play store icon, but you may not modify it.</p>
@@ -128,29 +128,29 @@
"Google Play store." However, when labeling the Google Play store icon directly, it's OK to use
"Play Store" alone to accurately reflect the icon label as it appears on a device.</p>
-
+
<h4>Google Play badge</h4>
-
+
<div style="float:right;clear:right;width:172px;margin-left:30px">
<img src="{@docRoot}images/brand/en_app_rgb_wo_60.png" alt="">
<p style="text-align:center">
<a href="{@docRoot}images/brand/en_app_rgb_wo_45.png">129x45</a> |
<a href="{@docRoot}images/brand/en_app_rgb_wo_60.png">172x60</a></p>
</div>
-
+
<div style="float:right;clear:right;width:172px;margin-left:30px">
<img src="{@docRoot}images/brand/en_generic_rgb_wo_60.png" alt="">
<p style="text-align:center">
<a href="{@docRoot}images/brand/en_generic_rgb_wo_45.png">129x45</a> |
<a href="{@docRoot}images/brand/en_generic_rgb_wo_60.png">172x60</a></p>
</div>
-
+
<p>The "Get it on Google Play" and "Android App on Google Play" logos are
badges that you can use on your website and promotional materials, to point
to your products on Google Play. Additional Google Play badge formats and
badges for music, books, magazines, movies, and TV shows are also available.
Use the <a
- href="https://docs.google.com/forms/d/1YE5gZpAAcFKjYcUddCsK1Bv9a9Y-luaLVnkazVlaJ2w/viewform">Android
+ href="https://support.google.com/googleplay/contact/brand_developer">Android
and Google Play Brand Permissions Inquiry form</a> to request
those badges.</p>
@@ -170,22 +170,22 @@
</ul>
</li>
</ul>
-
+
<p>To quickly create a badge that links to your apps on Google Play,
use the <a
href="{@docRoot}distribute/tools/promote/badges.html">Google Play badge generator</a>
(provides the badge in over 40 languages).</p>
-
+
<p>To create your own size, download an Adobe® Illustrator® (.ai) file for the
<a href="{@docRoot}distribute/tools/promote/badge-files.html">Google Play
badge in over 40 languages</a>.</p>
-
- <p>For details on all the ways that you can link to your product details page in Google Play,
+
+ <p>For details on all the ways that you can link to your product details page in Google Play,
see <a href="{@docRoot}distribute/tools/promote/linking.html">Linking to your products</a>.</p>
<h2 id="Marketing_Review">Marketing Reviews and Brand Inquiries</h2>
<p>Use the <a
-href="https://docs.google.com/forms/d/1YE5gZpAAcFKjYcUddCsK1Bv9a9Y-luaLVnkazVlaJ2w/viewform">Android
+href="https://support.google.com/googleplay/contact/brand_developer">Android
and Google Play Brand Permissions Inquiry form</a> to submit any marketing
reviews or brand inquires. Typical response time is at least one week.</p>
diff --git a/docs/html/tools/index.jd b/docs/html/tools/index.jd
deleted file mode 100644
index 73f8969..0000000
--- a/docs/html/tools/index.jd
+++ /dev/null
@@ -1,122 +0,0 @@
-page.title=Developer Tools
-@jd:body
-
-
-<img src="{@docRoot}images/tools-home.png" style="float:right;" height="347" width="400" />
-
-<div style="position:relative;height:0">
-<div style="position:absolute;width:420px">
- <p>The Android Developer Tools (ADT) plugin for Eclipse provides
- a professional-grade development environment for building
- Android apps. It's a full Java IDE with advanced features to help you build, test, debug,
- and package your Android apps. </p>
- <p>Free, open-source, and runs on most major OS platforms.<br>To get started,
- <a href="{@docRoot}sdk/index.html">download the Android SDK.</a></p>
-</div>
-</div>
-
-<div style="margin-top:20px;"></div>
-
-<div class="col-7" style="margin-left:0">
-<h3>Full Java IDE</h3>
-
- <ul>
- <li>Android-specific refactoring, quick fixes, integrated navigation between Java and XML resources.</li>
- <li>Enhanced XML editors for Android XML resources.</li>
- <li>Static analysis tools to catch performance, usability, and correctness problems.</li>
- <li>Build support for complex projects, command-line support for CI through Ant. Includes ProGuard and app-signing. </li>
- <li>Template-based wizard to create standard Android projects and components.</li>
- </ul>
-</div>
-
-
-<div class="col-6" style="margin-right:0">
-
-<h3>Graphical UI Builders</h3>
- <ul>
- <li>Build rich Android UI with drag and drop.
- <li>Visualize your UI on tablets, phones, and other devices. Switch themes, locales, even platform versions instantly, without building.</li>
- <li>Visual refactoring lets you extracts layout for inclusion, convert layouts, extract styles.</li>
- <li>Editor support for working with custom UI components.</li>
- </ul>
-
-</div>
-
-
-<div class="col-7" style="clear:both;margin-left:0;">
-
-<h3>On-device Developer Options</h3>
-<ul>
- <li>Enable debugging over USB.</li>
- <li>Quickly capture bug reports onto the device.</li>
- <li>Show CPU usage on screen.</li>
- <li>Draw debugging information on screen such as layout bounds,
- updates on GPU views and hardware layers, and other information.</li>
- <li>Plus many more options to simulate app stresses or enable debugging options.</li>
-</ul>
-<p>To access these settings, open the <em>Developer options</em> in the
-system Settings. On Android 4.2 and higher, the Developer options screen is
-hidden by default. To make it available, go to
-<b>Settings > About phone</b> and tap <b>Build number</b> seven times. Return to the previous
-screen to find Developer options.</p>
-
-</div>
-
-<div class="col-6" style="margin-right:0">
- <img src="{@docRoot}images/tools/dev-options-inmilk.png" alt="" style="margin:-10px 0 0;">
-</div>
-
-
-<div class="col-7" style="clear:both;margin-left:0;">
-<h3>Develop on Hardware Devices</h3>
-
- <ul>
- <li>Use any commercial Android hardware device or multiple devices.</li>
- <li>Deploy your app to connected devices directy from the IDE.</li>
- <li>Live, on-device debugging, testing, and profiling.</li>
- </ul>
-</div>
-
-<div class="col-6" style="margin-right:0">
-<h3>Develop on Virtual Devices</h3>
- <ul>
- <li>Emulate any device. Use custom screen sizes, keyboards, and other hardware components. </li>
- <li>Advanced hardware emulation, including camera, sensors, multitouch, telephony.</li>
- <li>Develop and test for broad device compatibility.</li>
- </ul>
-
-</div>
-
-<div style="margin-top:20px;"></div>
-
-<div class="col-7" style="margin-left:0">
-<h3>Powerful Debugging</h3>
-
- <ul>
- <li>Full Java debugger with on-device debugging and Android-specific tools.</li>
- <li>Built-in memory analysis, performance/CPU profiling, OpenGL ES tracing.</li>
- <li>Graphical tools for debugging and optimizing UI, runtime inspecton of UI structure and performance.</li>
- <li>Runtime graphical analysis of your app's network bandwidth usage.</li>
- </ul>
-
-<h3>Testing</h3>
-
- <ul>
- <li>Fully instrumentated, scriptable test environment.</li>
- <li>Integrated reports using standard test UI.</li>
- <li>Create and run unit tests on hardware devices or emulator.</li>
- </ul>
-
-<h3>Native Development</h3>
-
- <ul>
- <li>Support for compiling and packaging existing code written in C or C++.</li>
- <li>Support for packaging multiple architectures in a single binary, for broad compatibility.</li>
- </ul>
-</div>
-
-<div class="col-6" style="margin-right:0">
- <img src="{@docRoot}images/debugging-tall.png" align="left" style="margin-top:10px">
-</div>
-
-
diff --git a/docs/html/training/wearables/apps/bt-debugging.jd b/docs/html/training/wearables/apps/bt-debugging.jd
index 98cf804..7569e7e 100644
--- a/docs/html/training/wearables/apps/bt-debugging.jd
+++ b/docs/html/training/wearables/apps/bt-debugging.jd
@@ -19,7 +19,7 @@
</div>
</div>
-<p>You can debug your wearable over Bluetooth by routing it's debug output to the
+<p>You can debug your wearable over Bluetooth by routing its debug output to the
handheld device that's connected to your development machine.</p>
<h2 id="SetupDevices">Setup Devices for Debugging</h2>
@@ -90,4 +90,4 @@
adb -e logcat
adb -e shell
adb -e bugreport
-</pre>
\ No newline at end of file
+</pre>
diff --git a/docs/html/training/wearables/apps/creating.jd b/docs/html/training/wearables/apps/creating.jd
index 7252ada..018d9f7 100644
--- a/docs/html/training/wearables/apps/creating.jd
+++ b/docs/html/training/wearables/apps/creating.jd
@@ -92,6 +92,11 @@
<li>Leave the Android Wear app open on your phone.</li>
<li>Connect the wearable to your machine through USB, so you can install apps directly to it
as you develop. A message appears on both the wearable and the Android Wear app prompting you to allow debugging.</li>
+ <p class="note"><strong>Note:</strong> If you can not connect your wearable to your machine via USB,
+ follow the directions on
+ <a href="{@docRoot}training/wearables/apps/bt-debugging.html">Debugging over
+ Bluetooth</a>.
+ </p>
<li>On the Android Wear app, check <strong>Always allow from this computer</strong> and tap
<strong>OK</strong>.</li>
</ol>
diff --git a/docs/html/training/wearables/apps/index.jd b/docs/html/training/wearables/apps/index.jd
index 256205b..4bdd6bf 100644
--- a/docs/html/training/wearables/apps/index.jd
+++ b/docs/html/training/wearables/apps/index.jd
@@ -64,7 +64,7 @@
<dd>Learn how to create and display custom layouts for notifications and
activities.</dd>
<dt><a href="{@docRoot}training/wearables/apps/voice.html">Adding Voice Capabilities</a></dt>
- <dd>Learn how to launch an activity with a voice actions and how to start the
+ <dd>Learn how to launch an activity with voice actions and how to start the
system speech recognizer app to obtain free-form voice input.</dd>
<dt><a href="{@docRoot}training/wearables/apps/packaging.html">Packaging Wearable Apps</a></dt>
<dd>Learn how to package a wearable app inside a
diff --git a/docs/html/training/wearables/data-layer/accessing.jd b/docs/html/training/wearables/data-layer/accessing.jd
index bffd4c8..b7ecf5b 100644
--- a/docs/html/training/wearables/data-layer/accessing.jd
+++ b/docs/html/training/wearables/data-layer/accessing.jd
@@ -12,9 +12,9 @@
<h2>Dependencies and Prerequisites</h2>
<ol>
- <li><a href="{@docRoot}training/wearables/apps/environment.html">Creating
- Wearable Apps > Setting up Your Environment</a></li>
- <li><a href="{@docRoot}training/wearables/apps/creating.html">Creating
+ <li><a href="{@docRoot}training/wearables/apps/creating.html#SetupEmulator">Creating
+ Wearable Apps > Set Up an Android Wear Emulator or Device</a></li>
+ <li><a href="{@docRoot}training/wearables/apps/creating.html#CreateProject">Creating
Wearable Apps > Creating a Project</a></li>
</ol>
</div>
diff --git a/docs/html/training/wearables/data-layer/data-items.jd b/docs/html/training/wearables/data-layer/data-items.jd
index 63c32ea..f843bb6 100644
--- a/docs/html/training/wearables/data-layer/data-items.jd
+++ b/docs/html/training/wearables/data-layer/data-items.jd
@@ -47,14 +47,14 @@
<p>
However, instead of working with raw bytes using <a href="{@docRoot}reference/com/google/android/gms/wearable/PutDataRequest.html#setData(byte[])">setData()</a>,
-we recommend you <a href="#data-map">use a data map</a>, which exposes
+we recommend you <a href="#SyncData">use a data map</a>, which exposes
a data item in an easy-to-use {@link android.os.Bundle}-like interface.
</p>
<h2 id="SyncData">Sync Data with a Data Map</h2>
<p>
-When possible, use the <a href="{@docRoot}reference/com/google/android/gms/wearable/DataMap.html"><code>DataMap</code></a> class,
-which lets you work with data items in the form of an Android {@link android.os.Bundle},
+When possible, use the <a href="{@docRoot}reference/com/google/android/gms/wearable/DataMap.html"><code>DataMap</code></a> class.
+This approach lets you work with data items in the form of an Android {@link android.os.Bundle},
so object serialization and de-serialization is done for you, and you can manipulate data with key-value pairs.
</p>
@@ -120,5 +120,5 @@
<p>
This is just a snippet that requires more implementation details. Learn about
how to implement a full listener service or activity in
-<a href="{@docRoot}training/wearables/data-layer/events.html">Listening for Data Layer Events</a>.
+<a href="{@docRoot}training/wearables/data-layer/events.html#Listen">Listening for Data Layer Events</a>.
</p>
\ No newline at end of file
diff --git a/docs/html/training/wearables/data-layer/events.jd b/docs/html/training/wearables/data-layer/events.jd
index 9e8acbc..9196a2c 100644
--- a/docs/html/training/wearables/data-layer/events.jd
+++ b/docs/html/training/wearables/data-layer/events.jd
@@ -159,7 +159,7 @@
}
// Loop through the events and send a message
- / to the node that created the data item.
+ // to the node that created the data item.
for (DataEvent event : events) {
Uri uri = event.getDataItem().getUri();
diff --git a/docs/html/training/wearables/data-layer/index.jd b/docs/html/training/wearables/data-layer/index.jd
index 6ef3fc7..73d9ee5 100644
--- a/docs/html/training/wearables/data-layer/index.jd
+++ b/docs/html/training/wearables/data-layer/index.jd
@@ -83,5 +83,3 @@
<dt><a href="{@docRoot}training/wearables/data-layer/events.html">Handling Data Layer Events</a></dt>
<dd>Be notified of changes and events to the data layer.</dd>
</dl>
-
-</div>
\ No newline at end of file
diff --git a/docs/html/training/wearables/data-layer/messages.jd b/docs/html/training/wearables/data-layer/messages.jd
index 71f1bb1..b3afacb8 100644
--- a/docs/html/training/wearables/data-layer/messages.jd
+++ b/docs/html/training/wearables/data-layer/messages.jd
@@ -27,7 +27,7 @@
such as sending a message to the wearable
to start an activity. You can also use messages in request/response model
where one side of the connection sends a message, does some work,
-sends back a response message.</p>
+and sends back a response message.</p>
<h2 id="SendMessage">Send a Message</h2>
@@ -95,5 +95,5 @@
<p>
This is just a snippet that requires more implementation details. Learn about
how to implement a full listener service or activity in
-<a href="{@docRoot}training/wearables/data-layer/events.html">Listening for Data Layer Events</a>.
+<a href="{@docRoot}training/wearables/data-layer/events.html#Listen">Listening for Data Layer Events</a>.
</p>
\ No newline at end of file
diff --git a/docs/html/training/wearables/notifications/creating.jd b/docs/html/training/wearables/notifications/creating.jd
index 84e3311..57ac36e 100644
--- a/docs/html/training/wearables/notifications/creating.jd
+++ b/docs/html/training/wearables/notifications/creating.jd
@@ -4,7 +4,6 @@
<div id="tb-wrapper">
<div id="tb">
-
<h2>This lesson teaches you to</h2>
<ol>
<li><a href="#Import">Import the Necessary Classes</a></li>
@@ -30,7 +29,6 @@
layouts and the wearable only displays the text and icons. However, you can create
<a href="{@docRoot}training/wearables/apps/layouts.html#CustomNotifications">create custom notifications</a>
that use custom card layouts by creating a wearable app that runs on the wearable device.</p>
-</div>
<h2 id="Import">Import the necessary classes</h2>
@@ -255,7 +253,7 @@
Notification notif = new NotificationCompat.Builder(mContext)
.setContentTitle("New mail from " + sender)
.setContentText(subject)
- .setSmallIcon(R.drawable.new_mail);
+ .setSmallIcon(R.drawable.new_mail)
.extend(wearableExtender)
.build();
</pre>
@@ -278,7 +276,7 @@
<p>If you ever need to read wearable-specific options at a later time, use the corresponding get
method for the option. This example calls the
{@link android.support.v4.app.NotificationCompat.WearableExtender#getHintHideIcon()} method to
-get whether or not this notification hides the icon:
+get whether or not this notification hides the icon:</p>
<pre>
NotificationCompat.WearableExtender wearableExtender =
new NotificationCompat.WearableExtender(notif);
@@ -304,14 +302,3 @@
features from {@link android.support.v4.app.NotificationCompat.WearableExtender}
do not work, so make sure to use {@link android.support.v4.app.NotificationCompat}.
</p>
-
-<pre>
-NotificationCompat.WearableExtender wearableExtender =
- new NotificationCompat.WearableExtender(notif);
-boolean hintHideIcon = wearableExtender.getHintHideIcon();
- </pre>
-
-<p>The {@link android.support.v4.app.NotificationCompat.WearableExtender} APIs allow you to add
-additional pages to notifications, stack notifications, and more. Continue to the following lessons
-to learn about these features.
-</p>
diff --git a/docs/html/training/wearables/notifications/index.jd b/docs/html/training/wearables/notifications/index.jd
index a7b6733..2833dfa 100644
--- a/docs/html/training/wearables/notifications/index.jd
+++ b/docs/html/training/wearables/notifications/index.jd
@@ -49,5 +49,3 @@
<dd>Learn how to place all similar notifications from your app in a stack, allowing users to view
each notification individually without adding multiple cards to the card stream.</dd>
</dl>
-
-</div>
\ No newline at end of file
diff --git a/docs/html/training/wearables/notifications/stacks.jd b/docs/html/training/wearables/notifications/stacks.jd
index 9a528a4..9e70e1b 100644
--- a/docs/html/training/wearables/notifications/stacks.jd
+++ b/docs/html/training/wearables/notifications/stacks.jd
@@ -87,7 +87,7 @@
on the summary notification.</p>
<p>This notification does not appear in your stack of notifications on the wearable, but
-appears as the only notification on the handheld device.</p>
+it appears as the only notification on the handheld device.</p>
<pre style="clear:right">
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(),
diff --git a/docs/html/training/wearables/notifications/voice-input.jd b/docs/html/training/wearables/notifications/voice-input.jd
index 3ce1c80..5a49343 100644
--- a/docs/html/training/wearables/notifications/voice-input.jd
+++ b/docs/html/training/wearables/notifications/voice-input.jd
@@ -86,7 +86,7 @@
{@link android.support.v4.app.RemoteInput}:</p>
<pre>
-public static final EXTRA_VOICE_REPLY = "extra_voice_reply";
+public static final String EXTRA_VOICE_REPLY = "extra_voice_reply";
...
String replyLabel = getResources().getString(R.string.reply_label);
String[] replyChoices = getResources().getStringArray(R.array.reply_choices);
@@ -116,7 +116,7 @@
// Create the reply action and add the remote input
NotificationCompat.Action action =
new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon,
- getString(R.string.label, replyPendingIntent))
+ getString(R.string.label), replyPendingIntent)
.addRemoteInput(remoteInput)
.build();
@@ -171,4 +171,4 @@
}
return null;
}
-</pre>
\ No newline at end of file
+</pre>
diff --git a/libs/hwui/AmbientShadow.cpp b/libs/hwui/AmbientShadow.cpp
index cb3a002..21c869b 100644
--- a/libs/hwui/AmbientShadow.cpp
+++ b/libs/hwui/AmbientShadow.cpp
@@ -326,9 +326,9 @@
shadowVertexBuffer.updateVertexCount(vertexBufferIndex);
shadowVertexBuffer.updateIndexCount(indexBufferIndex);
- ShadowTessellator::checkOverflow(vertexBufferIndex, totalVertexCount, "Vertex Buffer");
- ShadowTessellator::checkOverflow(indexBufferIndex, totalIndexCount, "Index Buffer");
- ShadowTessellator::checkOverflow(umbraIndex, totalUmbraCount, "Umbra Buffer");
+ ShadowTessellator::checkOverflow(vertexBufferIndex, totalVertexCount, "Ambient Vertex Buffer");
+ ShadowTessellator::checkOverflow(indexBufferIndex, totalIndexCount, "Ambient Index Buffer");
+ ShadowTessellator::checkOverflow(umbraIndex, totalUmbraCount, "Ambient Umbra Buffer");
#if DEBUG_SHADOW
for (int i = 0; i < vertexBufferIndex; i++) {
diff --git a/libs/hwui/SpotShadow.cpp b/libs/hwui/SpotShadow.cpp
index df28ae8..e8f1b9a 100644
--- a/libs/hwui/SpotShadow.cpp
+++ b/libs/hwui/SpotShadow.cpp
@@ -618,68 +618,6 @@
}
/**
- * Converts a polygon specified with CW vertices into an array of distance-from-centroid values.
- *
- * Returns false in error conditions
- *
- * @param poly Array of vertices. Note that these *must* be CW.
- * @param polyLength The number of vertices in the polygon.
- * @param polyCentroid The centroid of the polygon, from which rays will be cast
- * @param rayDist The output array for the calculated distances, must be SHADOW_RAY_COUNT in size
- */
-bool convertPolyToRayDist(const Vector2* poly, int polyLength, const Vector2& polyCentroid,
- float* rayDist) {
- const int rays = SHADOW_RAY_COUNT;
- const float step = M_PI * 2 / rays;
-
- const Vector2* lastVertex = &(poly[polyLength - 1]);
- float startAngle = angle(*lastVertex, polyCentroid);
-
- // Start with the ray that's closest to and less than startAngle
- int rayIndex = floor((startAngle - EPSILON) / step);
- rayIndex = (rayIndex + rays) % rays; // ensure positive
-
- for (int polyIndex = 0; polyIndex < polyLength; polyIndex++) {
- /*
- * For a given pair of vertices on the polygon, poly[i-1] and poly[i], the rays that
- * intersect these will be those that are between the two angles from the centroid that the
- * vertices define.
- *
- * Because the polygon vertices are stored clockwise, the closest ray with an angle
- * *smaller* than that defined by angle(poly[i], centroid) will be the first ray that does
- * not intersect with poly[i-1], poly[i].
- */
- float currentAngle = angle(poly[polyIndex], polyCentroid);
-
- // find first ray that will not intersect the line segment poly[i-1] & poly[i]
- int firstRayIndexOnNextSegment = floor((currentAngle - EPSILON) / step);
- firstRayIndexOnNextSegment = (firstRayIndexOnNextSegment + rays) % rays; // ensure positive
-
- // Iterate through all rays that intersect with poly[i-1], poly[i] line segment.
- // This may be 0 rays.
- while (rayIndex != firstRayIndexOnNextSegment) {
- float distanceToIntersect = rayIntersectPoints(polyCentroid,
- cos(rayIndex * step),
- sin(rayIndex * step),
- *lastVertex, poly[polyIndex]);
- if (distanceToIntersect < 0) {
-#if DEBUG_SHADOW
- ALOGW("ERROR: convertPolyToRayDist failed");
-#endif
- return false; // error case, abort
- }
-
- rayDist[rayIndex] = distanceToIntersect;
-
- rayIndex = (rayIndex - 1 + rays) % rays;
- }
- lastVertex = &poly[polyIndex];
- }
-
- return true;
-}
-
-/**
* This is only for experimental purpose.
* After intersections are calculated, we could smooth the polygon if needed.
* So far, we don't think it is more appealing yet.
@@ -700,490 +638,223 @@
}
}
-/**
- * Generate a array of the angleData for either umbra or penumbra vertices.
- *
- * This array will be merged and used to guide where to shoot the rays, in clockwise order.
- *
- * @param angleDataList The result array of angle data.
- *
- * @return int The maximum angle's index in the array.
- */
-int SpotShadow::setupAngleList(VertexAngleData* angleDataList,
- int polyLength, const Vector2* polygon, const Vector2& centroid,
- bool isPenumbra, const char* name) {
- float maxAngle = FLT_MIN;
- int maxAngleIndex = 0;
- for (int i = 0; i < polyLength; i++) {
- float currentAngle = angle(polygon[i], centroid);
- if (currentAngle > maxAngle) {
- maxAngle = currentAngle;
- maxAngleIndex = i;
- }
- angleDataList[i].set(currentAngle, isPenumbra, i);
-#if DEBUG_SHADOW
- ALOGD("%s AngleList i %d %f", name, i, currentAngle);
-#endif
- }
- return maxAngleIndex;
-}
+// Index pair is meant for storing the tessellation information for the penumbra
+// area. One index must come from exterior tangent of the circles, the other one
+// must come from the interior tangent of the circles.
+struct IndexPair {
+ int outerIndex;
+ int innerIndex;
+};
-/**
- * Make sure the polygons are indeed in clockwise order.
- *
- * Possible reasons to return false: 1. The input polygon is not setup properly. 2. The hull
- * algorithm is not able to generate it properly.
- *
- * Anyway, since the algorithm depends on the clockwise, when these kind of unexpected error
- * situation is found, we need to detect it and early return without corrupting the memory.
- *
- * @return bool True if the angle list is actually from big to small.
- */
-bool SpotShadow::checkClockwise(int indexOfMaxAngle, int listLength, VertexAngleData* angleList,
- const char* name) {
- int currentIndex = indexOfMaxAngle;
-#if DEBUG_SHADOW
- ALOGD("max index %d", currentIndex);
-#endif
- for (int i = 0; i < listLength - 1; i++) {
- // TODO: Cache the last angle.
- float currentAngle = angleList[currentIndex].mAngle;
- float nextAngle = angleList[(currentIndex + 1) % listLength].mAngle;
- if (currentAngle < nextAngle) {
-#if DEBUG_SHADOW
- ALOGE("%s, is not CW, at index %d", name, currentIndex);
-#endif
- return false;
- }
- currentIndex = (currentIndex + 1) % listLength;
- }
- return true;
-}
-
-/**
- * Check the polygon is clockwise.
- *
- * @return bool True is the polygon is clockwise.
- */
-bool SpotShadow::checkPolyClockwise(int polyAngleLength, int maxPolyAngleIndex,
- const float* polyAngleList) {
- bool isPolyCW = true;
- // Starting from maxPolyAngleIndex , check around to make sure angle decrease.
- for (int i = 0; i < polyAngleLength - 1; i++) {
- float currentAngle = polyAngleList[(i + maxPolyAngleIndex) % polyAngleLength];
- float nextAngle = polyAngleList[(i + maxPolyAngleIndex + 1) % polyAngleLength];
- if (currentAngle < nextAngle) {
- isPolyCW = false;
- }
- }
- return isPolyCW;
-}
-
-/**
- * Given the sorted array of all the vertices angle data, calculate for each
- * vertices, the offset value to array element which represent the start edge
- * of the polygon we need to shoot the ray at.
- *
- * TODO: Calculate this for umbra and penumbra in one loop using one single array.
- *
- * @param distances The result of the array distance counter.
- */
-void SpotShadow::calculateDistanceCounter(bool needsOffsetToUmbra, int angleLength,
- const VertexAngleData* allVerticesAngleData, int* distances) {
-
- bool firstVertexIsPenumbra = allVerticesAngleData[0].mIsPenumbra;
- // If we want distance to inner, then we just set to 0 when we see inner.
- bool needsSearch = needsOffsetToUmbra ? firstVertexIsPenumbra : !firstVertexIsPenumbra;
- int distanceCounter = 0;
- if (needsSearch) {
- int foundIndex = -1;
- for (int i = (angleLength - 1); i >= 0; i--) {
- bool currentIsOuter = allVerticesAngleData[i].mIsPenumbra;
- // If we need distance to inner, then we need to find a inner vertex.
- if (currentIsOuter != firstVertexIsPenumbra) {
- foundIndex = i;
- break;
- }
- }
- LOG_ALWAYS_FATAL_IF(foundIndex == -1, "Wrong index found, means either"
- " umbra or penumbra's length is 0");
- distanceCounter = angleLength - foundIndex;
- }
-#if DEBUG_SHADOW
- ALOGD("distances[0] is %d", distanceCounter);
-#endif
-
- distances[0] = distanceCounter; // means never see a target poly
-
- for (int i = 1; i < angleLength; i++) {
- bool firstVertexIsPenumbra = allVerticesAngleData[i].mIsPenumbra;
- // When we needs for distance for each outer vertex to inner, then we
- // increase the distance when seeing outer vertices. Otherwise, we clear
- // to 0.
- bool needsIncrement = needsOffsetToUmbra ? firstVertexIsPenumbra : !firstVertexIsPenumbra;
- // If counter is not -1, that means we have seen an other polygon's vertex.
- if (needsIncrement && distanceCounter != -1) {
- distanceCounter++;
- } else {
- distanceCounter = 0;
- }
- distances[i] = distanceCounter;
- }
-}
-
-/**
- * Given umbra and penumbra angle data list, merge them by sorting the angle
- * from the biggest to smallest.
- *
- * @param allVerticesAngleData The result array of merged angle data.
- */
-void SpotShadow::mergeAngleList(int maxUmbraAngleIndex, int maxPenumbraAngleIndex,
- const VertexAngleData* umbraAngleList, int umbraLength,
- const VertexAngleData* penumbraAngleList, int penumbraLength,
- VertexAngleData* allVerticesAngleData) {
-
- int totalRayNumber = umbraLength + penumbraLength;
- int umbraIndex = maxUmbraAngleIndex;
- int penumbraIndex = maxPenumbraAngleIndex;
-
- float currentUmbraAngle = umbraAngleList[umbraIndex].mAngle;
- float currentPenumbraAngle = penumbraAngleList[penumbraIndex].mAngle;
-
- // TODO: Clean this up using a while loop with 2 iterators.
- for (int i = 0; i < totalRayNumber; i++) {
- if (currentUmbraAngle > currentPenumbraAngle) {
- allVerticesAngleData[i] = umbraAngleList[umbraIndex];
- umbraIndex = (umbraIndex + 1) % umbraLength;
-
- // If umbraIndex round back, that means we are running out of
- // umbra vertices to merge, so just copy all the penumbra leftover.
- // Otherwise, we update the currentUmbraAngle.
- if (umbraIndex != maxUmbraAngleIndex) {
- currentUmbraAngle = umbraAngleList[umbraIndex].mAngle;
- } else {
- for (int j = i + 1; j < totalRayNumber; j++) {
- allVerticesAngleData[j] = penumbraAngleList[penumbraIndex];
- penumbraIndex = (penumbraIndex + 1) % penumbraLength;
- }
- break;
- }
- } else {
- allVerticesAngleData[i] = penumbraAngleList[penumbraIndex];
- penumbraIndex = (penumbraIndex + 1) % penumbraLength;
- // If penumbraIndex round back, that means we are running out of
- // penumbra vertices to merge, so just copy all the umbra leftover.
- // Otherwise, we update the currentPenumbraAngle.
- if (penumbraIndex != maxPenumbraAngleIndex) {
- currentPenumbraAngle = penumbraAngleList[penumbraIndex].mAngle;
- } else {
- for (int j = i + 1; j < totalRayNumber; j++) {
- allVerticesAngleData[j] = umbraAngleList[umbraIndex];
- umbraIndex = (umbraIndex + 1) % umbraLength;
- }
- break;
- }
- }
- }
-}
-
-#if DEBUG_SHADOW
-/**
- * DEBUG ONLY: Verify all the offset compuation is correctly done by examining
- * each vertex and its neighbor.
- */
-static void verifyDistanceCounter(const VertexAngleData* allVerticesAngleData,
- const int* distances, int angleLength, const char* name) {
- int currentDistance = distances[0];
- for (int i = 1; i < angleLength; i++) {
- if (distances[i] != INT_MIN) {
- if (!((currentDistance + 1) == distances[i]
- || distances[i] == 0)) {
- ALOGE("Wrong distance found at i %d name %s", i, name);
- }
- currentDistance = distances[i];
- if (currentDistance != 0) {
- bool currentOuter = allVerticesAngleData[i].mIsPenumbra;
- for (int j = 1; j <= (currentDistance - 1); j++) {
- bool neigborOuter =
- allVerticesAngleData[(i + angleLength - j) % angleLength].mIsPenumbra;
- if (neigborOuter != currentOuter) {
- ALOGE("Wrong distance found at i %d name %s", i, name);
- }
- }
- bool oppositeOuter =
- allVerticesAngleData[(i + angleLength - currentDistance) % angleLength].mIsPenumbra;
- if (oppositeOuter == currentOuter) {
- ALOGE("Wrong distance found at i %d name %s", i, name);
- }
- }
- }
- }
-}
-
-/**
- * DEBUG ONLY: Verify all the angle data compuated are is correctly done
- */
-static void verifyAngleData(int totalRayNumber, const VertexAngleData* allVerticesAngleData,
- const int* distancesToInner, const int* distancesToOuter,
- const VertexAngleData* umbraAngleList, int maxUmbraAngleIndex, int umbraLength,
- const VertexAngleData* penumbraAngleList, int maxPenumbraAngleIndex,
- int penumbraLength) {
- for (int i = 0; i < totalRayNumber; i++) {
- ALOGD("currentAngleList i %d, angle %f, isInner %d, index %d distancesToInner"
- " %d distancesToOuter %d", i, allVerticesAngleData[i].mAngle,
- !allVerticesAngleData[i].mIsPenumbra,
- allVerticesAngleData[i].mVertexIndex, distancesToInner[i], distancesToOuter[i]);
- }
-
- verifyDistanceCounter(allVerticesAngleData, distancesToInner, totalRayNumber, "distancesToInner");
- verifyDistanceCounter(allVerticesAngleData, distancesToOuter, totalRayNumber, "distancesToOuter");
-
- for (int i = 0; i < totalRayNumber; i++) {
- if ((distancesToInner[i] * distancesToOuter[i]) != 0) {
- ALOGE("distancesToInner wrong at index %d distancesToInner[i] %d,"
- " distancesToOuter[i] %d", i, distancesToInner[i], distancesToOuter[i]);
- }
- }
- int currentUmbraVertexIndex =
- umbraAngleList[maxUmbraAngleIndex].mVertexIndex;
- int currentPenumbraVertexIndex =
- penumbraAngleList[maxPenumbraAngleIndex].mVertexIndex;
- for (int i = 0; i < totalRayNumber; i++) {
- if (allVerticesAngleData[i].mIsPenumbra == true) {
- if (allVerticesAngleData[i].mVertexIndex != currentPenumbraVertexIndex) {
- ALOGW("wrong penumbra indexing i %d allVerticesAngleData[i].mVertexIndex %d "
- "currentpenumbraVertexIndex %d", i,
- allVerticesAngleData[i].mVertexIndex, currentPenumbraVertexIndex);
- }
- currentPenumbraVertexIndex = (currentPenumbraVertexIndex + 1) % penumbraLength;
- } else {
- if (allVerticesAngleData[i].mVertexIndex != currentUmbraVertexIndex) {
- ALOGW("wrong umbra indexing i %d allVerticesAngleData[i].mVertexIndex %d "
- "currentUmbraVertexIndex %d", i,
- allVerticesAngleData[i].mVertexIndex, currentUmbraVertexIndex);
- }
- currentUmbraVertexIndex = (currentUmbraVertexIndex + 1) % umbraLength;
- }
- }
- for (int i = 0; i < totalRayNumber - 1; i++) {
- float currentAngle = allVerticesAngleData[i].mAngle;
- float nextAngle = allVerticesAngleData[(i + 1) % totalRayNumber].mAngle;
- if (currentAngle < nextAngle) {
- ALOGE("Unexpected angle values!, currentAngle nextAngle %f %f", currentAngle, nextAngle);
- }
- }
-}
-#endif
-
-/**
- * In order to compute the occluded umbra, we need to setup the angle data list
- * for the polygon data. Since we only store one poly vertex per polygon vertex,
- * this array only needs to be a float array which are the angles for each vertex.
- *
- * @param polyAngleList The result list
- *
- * @return int The index for the maximum angle in this array.
- */
-int SpotShadow::setupPolyAngleList(float* polyAngleList, int polyAngleLength,
- const Vector2* poly2d, const Vector2& centroid) {
- int maxPolyAngleIndex = -1;
- float maxPolyAngle = -FLT_MAX;
- for (int i = 0; i < polyAngleLength; i++) {
- polyAngleList[i] = angle(poly2d[i], centroid);
- if (polyAngleList[i] > maxPolyAngle) {
- maxPolyAngle = polyAngleList[i];
- maxPolyAngleIndex = i;
- }
- }
- return maxPolyAngleIndex;
-}
-
-/**
- * For umbra and penumbra, given the offset info and the current ray number,
- * find the right edge index (the (starting vertex) for the ray to shoot at.
- *
- * @return int The index of the starting vertex of the edge.
- */
-inline int SpotShadow::getEdgeStartIndex(const int* offsets, int rayIndex, int totalRayNumber,
- const VertexAngleData* allVerticesAngleData) {
- int tempOffset = offsets[rayIndex];
- int targetRayIndex = (rayIndex - tempOffset + totalRayNumber) % totalRayNumber;
- return allVerticesAngleData[targetRayIndex].mVertexIndex;
-}
-
-/**
- * For the occluded umbra, given the array of angles, find the index of the
- * starting vertex of the edge, for the ray to shoo at.
- *
- * TODO: Save the last result to shorten the search distance.
- *
- * @return int The index of the starting vertex of the edge.
- */
-inline int SpotShadow::getPolyEdgeStartIndex(int maxPolyAngleIndex, int polyLength,
- const float* polyAngleList, float rayAngle) {
- int minPolyAngleIndex = (maxPolyAngleIndex + polyLength - 1) % polyLength;
+// For one penumbra vertex, find the cloest umbra vertex and return its index.
+inline int getClosestUmbraIndex(const Vector2& pivot, const Vector2* polygon, int polygonLength) {
+ float minLengthSquared = FLT_MAX;
int resultIndex = -1;
- if (rayAngle > polyAngleList[maxPolyAngleIndex]
- || rayAngle <= polyAngleList[minPolyAngleIndex]) {
- resultIndex = minPolyAngleIndex;
- } else {
- for (int i = 0; i < polyLength - 1; i++) {
- int currentIndex = (maxPolyAngleIndex + i) % polyLength;
- int nextIndex = (maxPolyAngleIndex + i + 1) % polyLength;
- if (rayAngle <= polyAngleList[currentIndex]
- && rayAngle > polyAngleList[nextIndex]) {
- resultIndex = currentIndex;
+ bool hasDecreased = false;
+ // Starting with some negative offset, assuming both umbra and penumbra are starting
+ // at the same angle, this can help to find the result faster.
+ // Normally, loop 3 times, we can find the closest point.
+ int offset = polygonLength - 2;
+ for (int i = 0; i < polygonLength; i++) {
+ int currentIndex = (i + offset) % polygonLength;
+ float currentLengthSquared = (pivot - polygon[currentIndex]).lengthSquared();
+ if (currentLengthSquared < minLengthSquared) {
+ if (minLengthSquared != FLT_MAX) {
+ hasDecreased = true;
}
+ minLengthSquared = currentLengthSquared;
+ resultIndex = currentIndex;
+ } else if (currentLengthSquared > minLengthSquared && hasDecreased) {
+ // Early break b/c we have found the closet one and now the length
+ // is increasing again.
+ break;
}
}
- if (CC_UNLIKELY(resultIndex == -1)) {
- // TODO: Add more error handling here.
- ALOGE("Wrong index found, means no edge can't be found for rayAngle %f", rayAngle);
+ if(resultIndex == -1) {
+ ALOGE("resultIndex is -1, the polygon must be invalid!");
+ resultIndex = 0;
}
return resultIndex;
}
-/**
- * Convert the incoming polygons into arrays of vertices, for each ray.
- * Ray only shoots when there is one vertex either on penumbra on umbra.
- *
- * Finally, it will generate vertices per ray for umbra, penumbra and optionally
- * occludedUmbra.
- *
- * Return true (success) when all vertices are generated
- */
-int SpotShadow::convertPolysToVerticesPerRay(
- bool hasOccludedUmbraArea, const Vector2* poly2d, int polyLength,
- const Vector2* umbra, int umbraLength, const Vector2* penumbra,
- int penumbraLength, const Vector2& centroid,
- Vector2* umbraVerticesPerRay, Vector2* penumbraVerticesPerRay,
- Vector2* occludedUmbraVerticesPerRay) {
- int totalRayNumber = umbraLength + penumbraLength;
-
- // For incoming umbra / penumbra polygons, we will build an intermediate data
- // structure to help us sort all the vertices according to the vertices.
- // Using this data structure, we can tell where (the angle) to shoot the ray,
- // whether we shoot at penumbra edge or umbra edge, and which edge to shoot at.
- //
- // We first parse each vertices and generate a table of VertexAngleData.
- // Based on that, we create 2 arrays telling us which edge to shoot at.
- VertexAngleData allVerticesAngleData[totalRayNumber];
- VertexAngleData umbraAngleList[umbraLength];
- VertexAngleData penumbraAngleList[penumbraLength];
-
- int polyAngleLength = hasOccludedUmbraArea ? polyLength : 0;
- float polyAngleList[polyAngleLength];
-
- const int maxUmbraAngleIndex =
- setupAngleList(umbraAngleList, umbraLength, umbra, centroid, false, "umbra");
- const int maxPenumbraAngleIndex =
- setupAngleList(penumbraAngleList, penumbraLength, penumbra, centroid, true, "penumbra");
- const int maxPolyAngleIndex = setupPolyAngleList(polyAngleList, polyAngleLength, poly2d, centroid);
-
- // Check all the polygons here are CW.
- bool isPolyCW = checkPolyClockwise(polyAngleLength, maxPolyAngleIndex, polyAngleList);
- bool isUmbraCW = checkClockwise(maxUmbraAngleIndex, umbraLength,
- umbraAngleList, "umbra");
- bool isPenumbraCW = checkClockwise(maxPenumbraAngleIndex, penumbraLength,
- penumbraAngleList, "penumbra");
-
- if (!isUmbraCW || !isPenumbraCW || !isPolyCW) {
-#if DEBUG_SHADOW
- ALOGE("One polygon is not CW isUmbraCW %d isPenumbraCW %d isPolyCW %d",
- isUmbraCW, isPenumbraCW, isPolyCW);
-#endif
- return false;
+inline bool sameDirections(bool isPositiveCross, float a, float b) {
+ if (isPositiveCross) {
+ return a >= 0 && b >= 0;
+ } else {
+ return a <= 0 && b <= 0;
}
+}
- mergeAngleList(maxUmbraAngleIndex, maxPenumbraAngleIndex,
- umbraAngleList, umbraLength, penumbraAngleList, penumbraLength,
- allVerticesAngleData);
+// Find the right polygon edge to shoot the ray at.
+inline int findPolyIndex(bool isPositiveCross, int startPolyIndex, const Vector2& umbraDir,
+ const Vector2* polyToCentroid, int polyLength) {
+ // Make sure we loop with a bound.
+ for (int i = 0; i < polyLength; i++) {
+ int currentIndex = (i + startPolyIndex) % polyLength;
+ const Vector2& currentToCentroid = polyToCentroid[currentIndex];
+ const Vector2& nextToCentroid = polyToCentroid[(currentIndex + 1) % polyLength];
- // Calculate the offset to the left most Inner vertex for each outerVertex.
- // Then the offset to the left most Outer vertex for each innerVertex.
- int offsetToInner[totalRayNumber];
- int offsetToOuter[totalRayNumber];
- calculateDistanceCounter(true, totalRayNumber, allVerticesAngleData, offsetToInner);
- calculateDistanceCounter(false, totalRayNumber, allVerticesAngleData, offsetToOuter);
-
- // Generate both umbraVerticesPerRay and penumbraVerticesPerRay
- for (int i = 0; i < totalRayNumber; i++) {
- float rayAngle = allVerticesAngleData[i].mAngle;
- bool isUmbraVertex = !allVerticesAngleData[i].mIsPenumbra;
-
- float dx = cosf(rayAngle);
- float dy = sinf(rayAngle);
- float distanceToIntersectUmbra = -1;
-
- if (isUmbraVertex) {
- // We can just copy umbra easily, and calculate the distance for the
- // occluded umbra computation.
- int startUmbraIndex = allVerticesAngleData[i].mVertexIndex;
- umbraVerticesPerRay[i] = umbra[startUmbraIndex];
- if (hasOccludedUmbraArea) {
- distanceToIntersectUmbra = (umbraVerticesPerRay[i] - centroid).length();
- }
-
- //shoot ray to penumbra only
- int startPenumbraIndex = getEdgeStartIndex(offsetToOuter, i, totalRayNumber,
- allVerticesAngleData);
- float distanceToIntersectPenumbra = rayIntersectPoints(centroid, dx, dy,
- penumbra[startPenumbraIndex],
- penumbra[(startPenumbraIndex + 1) % penumbraLength]);
- if (distanceToIntersectPenumbra < 0) {
+ float currentCrossUmbra = currentToCentroid.cross(umbraDir);
+ float umbraCrossNext = umbraDir.cross(nextToCentroid);
+ if (sameDirections(isPositiveCross, currentCrossUmbra, umbraCrossNext)) {
#if DEBUG_SHADOW
- ALOGW("convertPolyToRayDist for penumbra failed rayAngle %f dx %f dy %f",
- rayAngle, dx, dy);
+ ALOGD("findPolyIndex loop %d times , index %d", i, currentIndex );
#endif
- distanceToIntersectPenumbra = 0;
- }
- penumbraVerticesPerRay[i].x = centroid.x + dx * distanceToIntersectPenumbra;
- penumbraVerticesPerRay[i].y = centroid.y + dy * distanceToIntersectPenumbra;
- } else {
- // We can just copy the penumbra
- int startPenumbraIndex = allVerticesAngleData[i].mVertexIndex;
- penumbraVerticesPerRay[i] = penumbra[startPenumbraIndex];
-
- // And shoot ray to umbra only
- int startUmbraIndex = getEdgeStartIndex(offsetToInner, i, totalRayNumber,
- allVerticesAngleData);
-
- distanceToIntersectUmbra = rayIntersectPoints(centroid, dx, dy,
- umbra[startUmbraIndex], umbra[(startUmbraIndex + 1) % umbraLength]);
- if (distanceToIntersectUmbra < 0) {
-#if DEBUG_SHADOW
- ALOGW("convertPolyToRayDist for umbra failed rayAngle %f dx %f dy %f",
- rayAngle, dx, dy);
-#endif
- distanceToIntersectUmbra = 0;
- }
- umbraVerticesPerRay[i].x = centroid.x + dx * distanceToIntersectUmbra;
- umbraVerticesPerRay[i].y = centroid.y + dy * distanceToIntersectUmbra;
+ return currentIndex;
}
+ }
+ LOG_ALWAYS_FATAL("Can't find the right polygon's edge from startPolyIndex %d", startPolyIndex);
+ return -1;
+}
- if (hasOccludedUmbraArea) {
- // Shoot the same ray to the poly2d, and get the distance.
- int startPolyIndex = getPolyEdgeStartIndex(maxPolyAngleIndex, polyLength,
- polyAngleList, rayAngle);
-
- float distanceToIntersectPoly = rayIntersectPoints(centroid, dx, dy,
- poly2d[startPolyIndex], poly2d[(startPolyIndex + 1) % polyLength]);
- if (distanceToIntersectPoly < 0) {
- distanceToIntersectPoly = 0;
+// Generate the index pair for penumbra / umbra vertices, and more penumbra vertices
+// if needed.
+inline void genNewPenumbraAndPairWithUmbra(const Vector2* penumbra, int penumbraLength,
+ const Vector2* umbra, int umbraLength, Vector2* newPenumbra, int& newPenumbraIndex,
+ IndexPair* verticesPair, int& verticesPairIndex) {
+ // In order to keep everything in just one loop, we need to pre-compute the
+ // closest umbra vertex for the last penumbra vertex.
+ int previousClosestUmbraIndex = getClosestUmbraIndex(penumbra[penumbraLength - 1],
+ umbra, umbraLength);
+ for (int i = 0; i < penumbraLength; i++) {
+ const Vector2& currentPenumbraVertex = penumbra[i];
+ // For current penumbra vertex, starting from previousClosestUmbraIndex,
+ // then check the next one until the distance increase.
+ // The last one before the increase is the umbra vertex we need to pair with.
+ int currentUmbraIndex = previousClosestUmbraIndex;
+ float currentLengthSquared = (currentPenumbraVertex - umbra[currentUmbraIndex]).lengthSquared();
+ int currentClosestUmbraIndex = -1;
+ int indexDelta = 0;
+ for (int j = 1; j < umbraLength; j++) {
+ int newUmbraIndex = (previousClosestUmbraIndex + j) % umbraLength;
+ float newLengthSquared = (currentPenumbraVertex - umbra[newUmbraIndex]).lengthSquared();
+ if (newLengthSquared > currentLengthSquared) {
+ currentClosestUmbraIndex = (previousClosestUmbraIndex + j - 1) % umbraLength;
+ break;
+ } else {
+ currentLengthSquared = newLengthSquared;
+ indexDelta++;
}
- distanceToIntersectPoly = MathUtils::min(distanceToIntersectUmbra, distanceToIntersectPoly);
- occludedUmbraVerticesPerRay[i].x = centroid.x + dx * distanceToIntersectPoly;
- occludedUmbraVerticesPerRay[i].y = centroid.y + dy * distanceToIntersectPoly;
+ }
+ LOG_ALWAYS_FATAL_IF(currentClosestUmbraIndex == -1, "Can't find a closet umbra vertext at all");
+
+ if (indexDelta > 1) {
+ // For those umbra don't have penumbra, generate new penumbra vertices by interpolation.
+ //
+ // Assuming Pi for penumbra vertices, and Ui for umbra vertices.
+ // In the case like below P1 paired with U1 and P2 paired with U5.
+ // U2 to U4 are unpaired umbra vertices.
+ //
+ // P1 P2
+ // | |
+ // U1 U2 U3 U4 U5
+ //
+ // We will need to generate 3 more penumbra vertices P1.1, P1.2, P1.3
+ // to pair with U2 to U4.
+ //
+ // P1 P1.1 P1.2 P1.3 P2
+ // | | | | |
+ // U1 U2 U3 U4 U5
+ //
+ // That distance ratio b/t Ui to U1 and Ui to U5 decides its paired penumbra
+ // vertex's location.
+ int newPenumbraNumber = indexDelta - 1;
+
+ float accumulatedDeltaLength[newPenumbraNumber];
+ float totalDeltaLength = 0;
+
+ // To save time, cache the previous umbra vertex info outside the loop
+ // and update each loop.
+ Vector2 previousClosestUmbra = umbra[previousClosestUmbraIndex];
+ Vector2 skippedUmbra;
+ // Use umbra data to precompute the length b/t unpaired umbra vertices,
+ // and its ratio against the total length.
+ for (int k = 0; k < indexDelta; k++) {
+ int skippedUmbraIndex = (previousClosestUmbraIndex + k + 1) % umbraLength;
+ skippedUmbra = umbra[skippedUmbraIndex];
+ float currentDeltaLength = (skippedUmbra - previousClosestUmbra).length();
+
+ totalDeltaLength += currentDeltaLength;
+ accumulatedDeltaLength[k] = totalDeltaLength;
+
+ previousClosestUmbra = skippedUmbra;
+ }
+
+ const Vector2& previousPenumbra = penumbra[(i + penumbraLength - 1) % penumbraLength];
+ // Then for each unpaired umbra vertex, create a new penumbra by the ratio,
+ // and pair them togehter.
+ for (int k = 0; k < newPenumbraNumber; k++) {
+ float weightForCurrentPenumbra = 1.0f;
+ if (totalDeltaLength != 0.0f) {
+ weightForCurrentPenumbra = accumulatedDeltaLength[k] / totalDeltaLength;
+ }
+ float weightForPreviousPenumbra = 1.0f - weightForCurrentPenumbra;
+
+ Vector2 interpolatedPenumbra = currentPenumbraVertex * weightForCurrentPenumbra +
+ previousPenumbra * weightForPreviousPenumbra;
+
+ int skippedUmbraIndex = (previousClosestUmbraIndex + k + 1) % umbraLength;
+ verticesPair[verticesPairIndex++] = {newPenumbraIndex, skippedUmbraIndex};
+ newPenumbra[newPenumbraIndex++] = interpolatedPenumbra;
+ }
+ }
+ verticesPair[verticesPairIndex++] = {newPenumbraIndex, currentClosestUmbraIndex};
+ newPenumbra[newPenumbraIndex++] = currentPenumbraVertex;
+
+ previousClosestUmbraIndex = currentClosestUmbraIndex;
+ }
+}
+
+// Precompute all the polygon's vector, return true if the reference cross product is positive.
+inline bool genPolyToCentroid(const Vector2* poly2d, int polyLength,
+ const Vector2& centroid, Vector2* polyToCentroid) {
+ for (int j = 0; j < polyLength; j++) {
+ polyToCentroid[j] = poly2d[j] - centroid;
+ }
+ float refCrossProduct = 0;
+ for (int j = 0; j < polyLength; j++) {
+ refCrossProduct = polyToCentroid[j].cross(polyToCentroid[(j + 1) % polyLength]);
+ if (refCrossProduct != 0) {
+ break;
}
}
-#if DEBUG_SHADOW
- verifyAngleData(totalRayNumber, allVerticesAngleData, offsetToInner,
- offsetToOuter, umbraAngleList, maxUmbraAngleIndex, umbraLength,
- penumbraAngleList, maxPenumbraAngleIndex, penumbraLength);
-#endif
- return true; // success
+ return refCrossProduct > 0;
+}
+// For one umbra vertex, shoot an ray from centroid to it.
+// If the ray hit the polygon first, then return the intersection point as the
+// closer vertex.
+inline Vector2 getCloserVertex(const Vector2& umbraVertex, const Vector2& centroid,
+ const Vector2* poly2d, int polyLength, const Vector2* polyToCentroid,
+ bool isPositiveCross, int& previousPolyIndex) {
+ Vector2 umbraToCentroid = umbraVertex - centroid;
+ float distanceToUmbra = umbraToCentroid.length();
+ umbraToCentroid = umbraToCentroid / distanceToUmbra;
+
+ // previousPolyIndex is updated for each item such that we can minimize the
+ // looping inside findPolyIndex();
+ previousPolyIndex = findPolyIndex(isPositiveCross, previousPolyIndex,
+ umbraToCentroid, polyToCentroid, polyLength);
+
+ float dx = umbraToCentroid.x;
+ float dy = umbraToCentroid.y;
+ float distanceToIntersectPoly = rayIntersectPoints(centroid, dx, dy,
+ poly2d[previousPolyIndex], poly2d[(previousPolyIndex + 1) % polyLength]);
+ if (distanceToIntersectPoly < 0) {
+ distanceToIntersectPoly = 0;
+ }
+
+ // Pick the closer one as the occluded area vertex.
+ Vector2 closerVertex;
+ if (distanceToIntersectPoly < distanceToUmbra) {
+ closerVertex.x = centroid.x + dx * distanceToIntersectPoly;
+ closerVertex.y = centroid.y + dy * distanceToIntersectPoly;
+ } else {
+ closerVertex = umbraVertex;
+ }
+
+ return closerVertex;
}
/**
@@ -1193,7 +864,6 @@
Vector2* penumbra, int penumbraLength, Vector2* umbra, int umbraLength,
const Vector3* poly, int polyLength, VertexBuffer& shadowTriangleStrip,
const Vector2& centroid) {
-
bool hasOccludedUmbraArea = false;
Vector2 poly2d[polyLength];
@@ -1209,128 +879,140 @@
}
}
- int totalRayNum = umbraLength + penumbraLength;
- Vector2 umbraVertices[totalRayNum];
- Vector2 penumbraVertices[totalRayNum];
- Vector2 occludedUmbraVertices[totalRayNum];
- bool convertSuccess = convertPolysToVerticesPerRay(hasOccludedUmbraArea, poly2d,
- polyLength, umbra, umbraLength, penumbra, penumbraLength,
- centroid, umbraVertices, penumbraVertices, occludedUmbraVertices);
- if (!convertSuccess) {
- return;
+ // For each penumbra vertex, find its corresponding closest umbra vertex index.
+ //
+ // Penumbra Vertices marked as Pi
+ // Umbra Vertices marked as Ui
+ // (P3)
+ // (P2) | ' (P4)
+ // (P1)' | | '
+ // ' | | '
+ // (P0) ------------------------------------------------(P5)
+ // | (U0) |(U1)
+ // | |
+ // | |(U2) (P5.1)
+ // | |
+ // | |
+ // | |
+ // | |
+ // | |
+ // | |
+ // (U4)-----------------------------------(U3) (P6)
+ //
+ // At least, like P0, P1, P2, they will find the matching umbra as U0.
+ // If we jump over some umbra vertex without matching penumbra vertex, then
+ // we will generate some new penumbra vertex by interpolation. Like P6 is
+ // matching U3, but U2 is not matched with any penumbra vertex.
+ // So interpolate P5.1 out and match U2.
+ // In this way, every umbra vertex will have a matching penumbra vertex.
+ //
+ // The total pair number can be as high as umbraLength + penumbraLength.
+ const int maxNewPenumbraLength = umbraLength + penumbraLength;
+ IndexPair verticesPair[maxNewPenumbraLength];
+ int verticesPairIndex = 0;
+
+ // Cache all the existing penumbra vertices and newly interpolated vertices into a
+ // a new array.
+ Vector2 newPenumbra[maxNewPenumbraLength];
+ int newPenumbraIndex = 0;
+
+ // For each penumbra vertex, find its closet umbra vertex by comparing the
+ // neighbor umbra vertices.
+ genNewPenumbraAndPairWithUmbra(penumbra, penumbraLength, umbra, umbraLength, newPenumbra,
+ newPenumbraIndex, verticesPair, verticesPairIndex);
+ ShadowTessellator::checkOverflow(verticesPairIndex, maxNewPenumbraLength, "Spot pair");
+ ShadowTessellator::checkOverflow(newPenumbraIndex, maxNewPenumbraLength, "Spot new penumbra");
+#if DEBUG_SHADOW
+ for (int i = 0; i < umbraLength; i++) {
+ ALOGD("umbra i %d, [%f, %f]", i, umbra[i].x, umbra[i].y);
}
+ for (int i = 0; i < newPenumbraIndex; i++) {
+ ALOGD("new penumbra i %d, [%f, %f]", i, newPenumbra[i].x, newPenumbra[i].y);
+ }
+ for (int i = 0; i < verticesPairIndex; i++) {
+ ALOGD("index i %d, [%d, %d]", i, verticesPair[i].outerIndex, verticesPair[i].innerIndex);
+ }
+#endif
- // Minimal value is 1, for each vertex show up once.
- // The bigger this value is , the smoother the look is, but more memory
- // is consumed.
- // When the ray number is high, that means the polygon has been fine
- // tessellated, we don't need this extra slice, just keep it as 1.
- int sliceNumberPerEdge = (totalRayNum > FINE_TESSELLATED_POLYGON_RAY_NUMBER) ? 1 : 2;
-
- // For each polygon, we at most add (totalRayNum * sliceNumberPerEdge) vertices.
- int slicedVertexCountPerPolygon = totalRayNum * sliceNumberPerEdge;
- int totalVertexCount = slicedVertexCountPerPolygon * 2 + totalRayNum;
- int totalIndexCount = 2 * (slicedVertexCountPerPolygon * 2 + 2);
+ // For the size of vertex buffer, we need 3 rings, one has newPenumbraSize,
+ // one has umbraLength, the last one has at most umbraLength.
+ //
+ // For the size of index buffer, the umbra area needs (2 * umbraLength + 2).
+ // The penumbra one can vary a bit, but it is bounded by (2 * verticesPairIndex + 2).
+ // And 2 more for jumping between penumbra to umbra.
+ const int newPenumbraLength = newPenumbraIndex;
+ const int totalVertexCount = newPenumbraLength + umbraLength * 2;
+ const int totalIndexCount = 2 * umbraLength + 2 * verticesPairIndex + 6;
AlphaVertex* shadowVertices =
shadowTriangleStrip.alloc<AlphaVertex>(totalVertexCount);
uint16_t* indexBuffer =
shadowTriangleStrip.allocIndices<uint16_t>(totalIndexCount);
-
- int indexBufferIndex = 0;
int vertexBufferIndex = 0;
+ int indexBufferIndex = 0;
- uint16_t slicedUmbraVertexIndex[totalRayNum * sliceNumberPerEdge];
- // Should be something like 0 0 0 1 1 1 2 3 3 3...
- int rayNumberPerSlicedUmbra[totalRayNum * sliceNumberPerEdge];
- int realUmbraVertexCount = 0;
- for (int i = 0; i < totalRayNum; i++) {
- Vector2 currentPenumbra = penumbraVertices[i];
- Vector2 currentUmbra = umbraVertices[i];
-
- Vector2 nextPenumbra = penumbraVertices[(i + 1) % totalRayNum];
- Vector2 nextUmbra = umbraVertices[(i + 1) % totalRayNum];
- // NextUmbra/Penumbra will be done in the next loop!!
- for (int weight = 0; weight < sliceNumberPerEdge; weight++) {
- const Vector2& slicedPenumbra = (currentPenumbra * (sliceNumberPerEdge - weight)
- + nextPenumbra * weight) / sliceNumberPerEdge;
-
- const Vector2& slicedUmbra = (currentUmbra * (sliceNumberPerEdge - weight)
- + nextUmbra * weight) / sliceNumberPerEdge;
-
- // In the vertex buffer, we fill the Penumbra first, then umbra.
- indexBuffer[indexBufferIndex++] = vertexBufferIndex;
- AlphaVertex::set(&shadowVertices[vertexBufferIndex++], slicedPenumbra.x,
- slicedPenumbra.y, 0.0f);
-
- // When we add umbra vertex, we need to remember its current ray number.
- // And its own vertexBufferIndex. This is for occluded umbra usage.
- indexBuffer[indexBufferIndex++] = vertexBufferIndex;
- rayNumberPerSlicedUmbra[realUmbraVertexCount] = i;
- slicedUmbraVertexIndex[realUmbraVertexCount] = vertexBufferIndex;
- realUmbraVertexCount++;
- AlphaVertex::set(&shadowVertices[vertexBufferIndex++], slicedUmbra.x,
- slicedUmbra.y, M_PI);
- }
+ // Fill the IB and VB for the penumbra area.
+ for (int i = 0; i < newPenumbraLength; i++) {
+ AlphaVertex::set(&shadowVertices[vertexBufferIndex++], newPenumbra[i].x,
+ newPenumbra[i].y, 0.0f);
+ }
+ for (int i = 0; i < umbraLength; i++) {
+ AlphaVertex::set(&shadowVertices[vertexBufferIndex++], umbra[i].x, umbra[i].y,
+ M_PI);
}
- indexBuffer[indexBufferIndex++] = 0;
- //RealUmbraVertexIndex[0] must be 1, so we connect back well at the
- //beginning of occluded area.
- indexBuffer[indexBufferIndex++] = 1;
+ for (int i = 0; i < verticesPairIndex; i++) {
+ indexBuffer[indexBufferIndex++] = verticesPair[i].outerIndex;
+ // All umbra index need to be offseted by newPenumbraSize.
+ indexBuffer[indexBufferIndex++] = verticesPair[i].innerIndex + newPenumbraLength;
+ }
+ indexBuffer[indexBufferIndex++] = verticesPair[0].outerIndex;
+ indexBuffer[indexBufferIndex++] = verticesPair[0].innerIndex + newPenumbraLength;
- float occludedUmbraAlpha = M_PI;
+ // Now fill the IB and VB for the umbra area.
+ // First duplicated the index from previous strip and the first one for the
+ // degenerated triangles.
+ indexBuffer[indexBufferIndex] = indexBuffer[indexBufferIndex - 1];
+ indexBufferIndex++;
+ indexBuffer[indexBufferIndex++] = newPenumbraLength + 0;
+ // Save the first VB index for umbra area in order to close the loop.
+ int savedStartIndex = vertexBufferIndex;
+
if (hasOccludedUmbraArea) {
- // Now the occludedUmbra area;
- int currentRayNumber = -1;
- int firstOccludedUmbraIndex = -1;
- for (int i = 0; i < realUmbraVertexCount; i++) {
- indexBuffer[indexBufferIndex++] = slicedUmbraVertexIndex[i];
+ // Precompute all the polygon's vector, and the reference cross product,
+ // in order to find the right polygon edge for the ray to intersect.
+ Vector2 polyToCentroid[polyLength];
+ bool isPositiveCross = genPolyToCentroid(poly2d, polyLength, centroid, polyToCentroid);
- // If the occludedUmbra vertex has not been added yet, then add it.
- // Otherwise, just use the previously added occludedUmbra vertices.
- if (rayNumberPerSlicedUmbra[i] != currentRayNumber) {
- currentRayNumber++;
- indexBuffer[indexBufferIndex++] = vertexBufferIndex;
- // We need to remember the begining of the occludedUmbra vertices
- // to close this loop.
- if (currentRayNumber == 0) {
- firstOccludedUmbraIndex = vertexBufferIndex;
- }
- AlphaVertex::set(&shadowVertices[vertexBufferIndex++],
- occludedUmbraVertices[currentRayNumber].x,
- occludedUmbraVertices[currentRayNumber].y,
- occludedUmbraAlpha);
- } else {
- indexBuffer[indexBufferIndex++] = (vertexBufferIndex - 1);
- }
+ // Because both the umbra and polygon are going in the same direction,
+ // we can save the previous polygon index to make sure we have less polygon
+ // vertex to compute for each ray.
+ int previousPolyIndex = 0;
+ for (int i = 0; i < umbraLength; i++) {
+ // Shoot a ray from centroid to each umbra vertices and pick the one with
+ // shorter distance to the centroid, b/t the umbra vertex or the intersection point.
+ Vector2 closerVertex = getCloserVertex(umbra[i], centroid, poly2d, polyLength,
+ polyToCentroid, isPositiveCross, previousPolyIndex);
+
+ // We already stored the umbra vertices, just need to add the occlued umbra's ones.
+ indexBuffer[indexBufferIndex++] = newPenumbraLength + i;
+ indexBuffer[indexBufferIndex++] = vertexBufferIndex;
+ AlphaVertex::set(&shadowVertices[vertexBufferIndex++],
+ closerVertex.x, closerVertex.y, M_PI);
}
- // Close the loop here!
- indexBuffer[indexBufferIndex++] = slicedUmbraVertexIndex[0];
- indexBuffer[indexBufferIndex++] = firstOccludedUmbraIndex;
} else {
+ // If there is no occluded umbra at all, then draw the triangle fan
+ // starting from the centroid to all umbra vertices.
int lastCentroidIndex = vertexBufferIndex;
AlphaVertex::set(&shadowVertices[vertexBufferIndex++], centroid.x,
- centroid.y, occludedUmbraAlpha);
- for (int i = 0; i < realUmbraVertexCount; i++) {
- indexBuffer[indexBufferIndex++] = slicedUmbraVertexIndex[i];
+ centroid.y, M_PI);
+ for (int i = 0; i < umbraLength; i++) {
+ indexBuffer[indexBufferIndex++] = newPenumbraLength + i;
indexBuffer[indexBufferIndex++] = lastCentroidIndex;
}
- // Close the loop here!
- indexBuffer[indexBufferIndex++] = slicedUmbraVertexIndex[0];
- indexBuffer[indexBufferIndex++] = lastCentroidIndex;
}
-
-#if DEBUG_SHADOW
- ALOGD("allocated IB %d allocated VB is %d", totalIndexCount, totalVertexCount);
- ALOGD("IB index %d VB index is %d", indexBufferIndex, vertexBufferIndex);
- for (int i = 0; i < vertexBufferIndex; i++) {
- ALOGD("vertexBuffer i %d, (%f, %f %f)", i, shadowVertices[i].x, shadowVertices[i].y,
- shadowVertices[i].alpha);
- }
- for (int i = 0; i < indexBufferIndex; i++) {
- ALOGD("indexBuffer i %d, indexBuffer[i] %d", i, indexBuffer[i]);
- }
-#endif
+ // Closing the umbra area triangle's loop here.
+ indexBuffer[indexBufferIndex++] = newPenumbraLength;
+ indexBuffer[indexBufferIndex++] = savedStartIndex;
// At the end, update the real index and vertex buffer size.
shadowTriangleStrip.updateVertexCount(vertexBufferIndex);
diff --git a/libs/hwui/SpotShadow.h b/libs/hwui/SpotShadow.h
index 6fa2028f..e2d94f7 100644
--- a/libs/hwui/SpotShadow.h
+++ b/libs/hwui/SpotShadow.h
@@ -36,40 +36,6 @@
static float projectCasterToOutline(Vector2& outline,
const Vector3& lightCenter, const Vector3& polyVertex);
- static int setupAngleList(VertexAngleData* angleDataList,
- int polyLength, const Vector2* polygon, const Vector2& centroid,
- bool isPenumbra, const char* name);
-
- static int convertPolysToVerticesPerRay(
- bool hasOccludedUmbraArea, const Vector2* poly2d, int polyLength,
- const Vector2* umbra, int umbraLength, const Vector2* penumbra,
- int penumbraLength, const Vector2& centroid,
- Vector2* umbraVerticesPerRay, Vector2* penumbraVerticesPerRay,
- Vector2* occludedUmbraVerticesPerRay);
-
- static bool checkClockwise(int maxIndex, int listLength,
- VertexAngleData* angleList, const char* name);
-
- static void calculateDistanceCounter(bool needsOffsetToUmbra, int angleLength,
- const VertexAngleData* allVerticesAngleData, int* distances);
-
- static void mergeAngleList(int maxUmbraAngleIndex, int maxPenumbraAngleIndex,
- const VertexAngleData* umbraAngleList, int umbraLength,
- const VertexAngleData* penumbraAngleList, int penumbraLength,
- VertexAngleData* allVerticesAngleData);
-
- static int setupPolyAngleList(float* polyAngleList, int polyAngleLength,
- const Vector2* poly2d, const Vector2& centroid);
-
- static bool checkPolyClockwise(int polyAngleLength, int maxPolyAngleIndex,
- const float* polyAngleList);
-
- static int getEdgeStartIndex(const int* offsets, int rayIndex, int totalRayNumber,
- const VertexAngleData* allVerticesAngleData);
-
- static int getPolyEdgeStartIndex(int maxPolyAngleIndex, int polyLength,
- const float* polyAngleList, float rayAngle);
-
static void computeLightPolygon(int points, const Vector3& lightCenter,
float size, Vector3* ret);
diff --git a/libs/hwui/Vector.h b/libs/hwui/Vector.h
index d033ed9..aa6acc9 100644
--- a/libs/hwui/Vector.h
+++ b/libs/hwui/Vector.h
@@ -99,6 +99,10 @@
return x * v.x + y * v.y;
}
+ float cross(const Vector2& v) const {
+ return x * v.y - y * v.x;
+ }
+
void dump() {
ALOGD("Vector2[%.2f, %.2f]", x, y);
}
diff --git a/location/java/android/location/GpsMeasurementListenerTransport.java b/location/java/android/location/GpsMeasurementListenerTransport.java
index 2d9a372..610da96 100644
--- a/location/java/android/location/GpsMeasurementListenerTransport.java
+++ b/location/java/android/location/GpsMeasurementListenerTransport.java
@@ -26,14 +26,12 @@
*/
class GpsMeasurementListenerTransport
extends LocalListenerHelper<GpsMeasurementsEvent.Listener> {
- private final Context mContext;
private final ILocationManager mLocationManager;
private final IGpsMeasurementsListener mListenerTransport = new ListenerTransport();
public GpsMeasurementListenerTransport(Context context, ILocationManager locationManager) {
- super("GpsMeasurementListenerTransport");
- mContext = context;
+ super(context, "GpsMeasurementListenerTransport");
mLocationManager = locationManager;
}
@@ -41,7 +39,7 @@
protected boolean registerWithServer() throws RemoteException {
return mLocationManager.addGpsMeasurementsListener(
mListenerTransport,
- mContext.getPackageName());
+ getContext().getPackageName());
}
@Override
@@ -59,7 +57,18 @@
listener.onGpsMeasurementsReceived(event);
}
};
+ foreach(operation);
+ }
+ @Override
+ public void onStatusChanged(final int status) {
+ ListenerOperation<GpsMeasurementsEvent.Listener> operation =
+ new ListenerOperation<GpsMeasurementsEvent.Listener>() {
+ @Override
+ public void execute(GpsMeasurementsEvent.Listener listener) throws RemoteException {
+ listener.onStatusChanged(status);
+ }
+ };
foreach(operation);
}
}
diff --git a/location/java/android/location/GpsMeasurementsEvent.java b/location/java/android/location/GpsMeasurementsEvent.java
index e04ed81..94ca920 100644
--- a/location/java/android/location/GpsMeasurementsEvent.java
+++ b/location/java/android/location/GpsMeasurementsEvent.java
@@ -32,6 +32,24 @@
* @hide
*/
public class GpsMeasurementsEvent implements Parcelable {
+
+ /**
+ * The system does not support tracking of GPS Measurements. This status will not change in the
+ * future.
+ */
+ public static final int STATUS_NOT_SUPPORTED = 0;
+
+ /**
+ * GPS Measurements are successfully being tracked, it will receive updates once they are
+ * available.
+ */
+ public static final int STATUS_READY = 1;
+
+ /**
+ * GPS provider or Location is disabled, updates will not be received until they are enabled.
+ */
+ public static final int STATUS_GPS_LOCATION_DISABLED = 2;
+
private final GpsClock mClock;
private final Collection<GpsMeasurement> mReadOnlyMeasurements;
@@ -43,7 +61,16 @@
* @hide
*/
public interface Listener {
+
+ /**
+ * Returns the latest collected GPS Measurements.
+ */
void onGpsMeasurementsReceived(GpsMeasurementsEvent eventArgs);
+
+ /**
+ * Returns the latest status of the GPS Measurements sub-system.
+ */
+ void onStatusChanged(int status);
}
public GpsMeasurementsEvent(GpsClock clock, GpsMeasurement[] measurements) {
@@ -103,7 +130,9 @@
public void writeToParcel(Parcel parcel, int flags) {
parcel.writeParcelable(mClock, flags);
- GpsMeasurement[] measurementsArray = mReadOnlyMeasurements.toArray(new GpsMeasurement[0]);
+ int measurementsCount = mReadOnlyMeasurements.size();
+ GpsMeasurement[] measurementsArray =
+ mReadOnlyMeasurements.toArray(new GpsMeasurement[measurementsCount]);
parcel.writeInt(measurementsArray.length);
parcel.writeTypedArray(measurementsArray, flags);
}
diff --git a/location/java/android/location/GpsNavigationMessageEvent.java b/location/java/android/location/GpsNavigationMessageEvent.java
index 50ffa75..b61dac0 100644
--- a/location/java/android/location/GpsNavigationMessageEvent.java
+++ b/location/java/android/location/GpsNavigationMessageEvent.java
@@ -21,9 +21,6 @@
import android.os.Parcelable;
import java.security.InvalidParameterException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
/**
* A class implementing a container for data associated with a navigation message event.
@@ -32,6 +29,24 @@
* @hide
*/
public class GpsNavigationMessageEvent implements Parcelable {
+
+ /**
+ * The system does not support tracking of GPS Navigation Messages. This status will not change
+ * in the future.
+ */
+ public static int STATUS_NOT_SUPPORTED = 0;
+
+ /**
+ * GPS Navigation Messages are successfully being tracked, it will receive updates once they are
+ * available.
+ */
+ public static int STATUS_READY = 1;
+
+ /**
+ * GPS provider or Location is disabled, updated will not be received until they are enabled.
+ */
+ public static int STATUS_GPS_LOCATION_DISABLED = 2;
+
private final GpsNavigationMessage mNavigationMessage;
/**
@@ -42,7 +57,16 @@
* @hide
*/
public interface Listener {
+
+ /**
+ * Returns the latest collected GPS Navigation Message.
+ */
void onGpsNavigationMessageReceived(GpsNavigationMessageEvent event);
+
+ /**
+ * Returns the latest status of the GPS Navigation Messages sub-system.
+ */
+ void onStatusChanged(int status);
}
public GpsNavigationMessageEvent(GpsNavigationMessage message) {
diff --git a/location/java/android/location/GpsNavigationMessageListenerTransport.java b/location/java/android/location/GpsNavigationMessageListenerTransport.java
index ec4812b..f6ba407 100644
--- a/location/java/android/location/GpsNavigationMessageListenerTransport.java
+++ b/location/java/android/location/GpsNavigationMessageListenerTransport.java
@@ -26,7 +26,6 @@
*/
class GpsNavigationMessageListenerTransport
extends LocalListenerHelper<GpsNavigationMessageEvent.Listener> {
- private final Context mContext;
private final ILocationManager mLocationManager;
private final IGpsNavigationMessageListener mListenerTransport = new ListenerTransport();
@@ -34,8 +33,7 @@
public GpsNavigationMessageListenerTransport(
Context context,
ILocationManager locationManager) {
- super("GpsNavigationMessageListenerTransport");
- mContext = context;
+ super(context, "GpsNavigationMessageListenerTransport");
mLocationManager = locationManager;
}
@@ -43,7 +41,7 @@
protected boolean registerWithServer() throws RemoteException {
return mLocationManager.addGpsNavigationMessageListener(
mListenerTransport,
- mContext.getPackageName());
+ getContext().getPackageName());
}
@Override
@@ -62,7 +60,19 @@
listener.onGpsNavigationMessageReceived(event);
}
};
+ foreach(operation);
+ }
+ @Override
+ public void onStatusChanged(final int status) {
+ ListenerOperation<GpsNavigationMessageEvent.Listener> operation =
+ new ListenerOperation<GpsNavigationMessageEvent.Listener>() {
+ @Override
+ public void execute(GpsNavigationMessageEvent.Listener listener)
+ throws RemoteException {
+ listener.onStatusChanged(status);
+ }
+ };
foreach(operation);
}
}
diff --git a/location/java/android/location/IGpsMeasurementsListener.aidl b/location/java/android/location/IGpsMeasurementsListener.aidl
index b34bb6c..cbd3100 100644
--- a/location/java/android/location/IGpsMeasurementsListener.aidl
+++ b/location/java/android/location/IGpsMeasurementsListener.aidl
@@ -23,4 +23,5 @@
*/
oneway interface IGpsMeasurementsListener {
void onGpsMeasurementsReceived(in GpsMeasurementsEvent event);
+ void onStatusChanged(in int status);
}
diff --git a/location/java/android/location/IGpsNavigationMessageListener.aidl b/location/java/android/location/IGpsNavigationMessageListener.aidl
index 18603fe..a708ea6 100644
--- a/location/java/android/location/IGpsNavigationMessageListener.aidl
+++ b/location/java/android/location/IGpsNavigationMessageListener.aidl
@@ -23,4 +23,5 @@
*/
oneway interface IGpsNavigationMessageListener {
void onGpsNavigationMessageReceived(in GpsNavigationMessageEvent event);
+ void onStatusChanged(in int status);
}
diff --git a/location/java/android/location/ILocationManager.aidl b/location/java/android/location/ILocationManager.aidl
index 1501710..af76175 100644
--- a/location/java/android/location/ILocationManager.aidl
+++ b/location/java/android/location/ILocationManager.aidl
@@ -62,12 +62,12 @@
boolean sendNiResponse(int notifId, int userResponse);
boolean addGpsMeasurementsListener(in IGpsMeasurementsListener listener, in String packageName);
- boolean removeGpsMeasurementsListener(in IGpsMeasurementsListener listener);
+ void removeGpsMeasurementsListener(in IGpsMeasurementsListener listener);
boolean addGpsNavigationMessageListener(
in IGpsNavigationMessageListener listener,
in String packageName);
- boolean removeGpsNavigationMessageListener(in IGpsNavigationMessageListener listener);
+ void removeGpsNavigationMessageListener(in IGpsNavigationMessageListener listener);
// --- deprecated ---
List<String> getAllProviders();
diff --git a/location/java/android/location/LocalListenerHelper.java b/location/java/android/location/LocalListenerHelper.java
index 1f3bf67..458c451 100644
--- a/location/java/android/location/LocalListenerHelper.java
+++ b/location/java/android/location/LocalListenerHelper.java
@@ -19,6 +19,7 @@
import com.android.internal.util.Preconditions;
import android.annotation.NonNull;
+import android.content.Context;
import android.os.RemoteException;
import android.util.Log;
@@ -32,17 +33,19 @@
* @hide
*/
abstract class LocalListenerHelper<TListener> {
- private final HashSet<TListener> mListeners = new HashSet<TListener>();
- private final String mTag;
+ private final HashSet<TListener> mListeners = new HashSet<>();
- protected LocalListenerHelper(String name) {
+ private final String mTag;
+ private final Context mContext;
+
+ protected LocalListenerHelper(Context context, String name) {
Preconditions.checkNotNull(name);
+ mContext = context;
mTag = name;
}
public boolean add(@NonNull TListener listener) {
Preconditions.checkNotNull(listener);
-
synchronized (mListeners) {
// we need to register with the service first, because we need to find out if the
// service will actually support the request before we attempt anything
@@ -59,18 +62,15 @@
return false;
}
}
-
if (mListeners.contains(listener)) {
return true;
}
- mListeners.add(listener);
+ return mListeners.add(listener);
}
- return true;
}
public void remove(@NonNull TListener listener) {
Preconditions.checkNotNull(listener);
-
synchronized (mListeners) {
boolean removed = mListeners.remove(listener);
boolean isLastRemoved = removed && mListeners.isEmpty();
@@ -78,7 +78,7 @@
try {
unregisterFromServer();
} catch (RemoteException e) {
-
+ Log.v(mTag, "Error handling last listener removal", e);
}
}
}
@@ -91,12 +91,15 @@
void execute(TListener listener) throws RemoteException;
}
- protected void foreach(ListenerOperation operation) {
+ protected Context getContext() {
+ return mContext;
+ }
+
+ protected void foreach(ListenerOperation<TListener> operation) {
Collection<TListener> listeners;
synchronized (mListeners) {
- listeners = new ArrayList<TListener>(mListeners);
+ listeners = new ArrayList<>(mListeners);
}
-
for (TListener listener : listeners) {
try {
operation.execute(listener);
diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java
index ed408e0..513a627 100644
--- a/location/java/android/location/LocationManager.java
+++ b/location/java/android/location/LocationManager.java
@@ -1579,7 +1579,7 @@
* Adds a GPS Measurement listener.
*
* @param listener a {@link GpsMeasurementsEvent.Listener} object to register.
- * @return {@code true} if the listener was successfully registered, {@code false} otherwise.
+ * @return {@code true} if the listener was added successfully, {@code false} otherwise.
*
* @hide
*/
@@ -1602,7 +1602,7 @@
* Adds a GPS Navigation Message listener.
*
* @param listener a {@link GpsNavigationMessageEvent.Listener} object to register.
- * @return {@code true} if the listener was successfully registered, {@code false} otherwise.
+ * @return {@code true} if the listener was added successfully, {@code false} otherwise.
*
* @hide
*/
diff --git a/media/java/android/media/audiofx/AudioEffect.java b/media/java/android/media/audiofx/AudioEffect.java
index 9fa3f50..a8b9686e 100644
--- a/media/java/android/media/audiofx/AudioEffect.java
+++ b/media/java/android/media/audiofx/AudioEffect.java
@@ -483,6 +483,10 @@
*/
public static boolean isEffectTypeAvailable(UUID type) {
AudioEffect.Descriptor[] desc = AudioEffect.queryEffects();
+ if (desc == null) {
+ return false;
+ }
+
for (int i = 0; i < desc.length; i++) {
if (desc[i].type.equals(type)) {
return true;
diff --git a/services/core/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/LocationManagerService.java
index d9c96e4..be83b9b 100644
--- a/services/core/java/com/android/server/LocationManagerService.java
+++ b/services/core/java/com/android/server/LocationManagerService.java
@@ -60,6 +60,8 @@
import android.location.Criteria;
import android.location.GeocoderParams;
import android.location.Geofence;
+import android.location.GpsMeasurementsEvent;
+import android.location.GpsNavigationMessageEvent;
import android.location.IGpsMeasurementsListener;
import android.location.IGpsNavigationMessageListener;
import android.location.IGpsStatusListener;
@@ -1859,8 +1861,8 @@
}
@Override
- public boolean removeGpsMeasurementsListener(IGpsMeasurementsListener listener) {
- return mGpsMeasurementsProvider.removeListener(listener);
+ public void removeGpsMeasurementsListener(IGpsMeasurementsListener listener) {
+ mGpsMeasurementsProvider.removeListener(listener);
}
@Override
@@ -1888,8 +1890,8 @@
}
@Override
- public boolean removeGpsNavigationMessageListener(IGpsNavigationMessageListener listener) {
- return mGpsNavigationMessageProvider.removeListener(listener);
+ public void removeGpsNavigationMessageListener(IGpsNavigationMessageListener listener) {
+ mGpsNavigationMessageProvider.removeListener(listener);
}
@Override
diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java
index 843a0cb..a4aff77 100644
--- a/services/core/java/com/android/server/am/ProcessList.java
+++ b/services/core/java/com/android/server/am/ProcessList.java
@@ -177,7 +177,7 @@
// 1280x800 or larger screen with around 1GB RAM. Values are in KB.
private final int[] mOomMinFreeHigh = new int[] {
73728, 92160, 110592,
- 129024, 147456, 184320
+ 129024, 225000, 325000
};
// The actual OOM killer memory levels we are using.
private final int[] mOomMinFree = new int[mOomAdj.length];
diff --git a/services/core/java/com/android/server/location/GpsLocationProvider.java b/services/core/java/com/android/server/location/GpsLocationProvider.java
index c2cb4b1..86aa516 100644
--- a/services/core/java/com/android/server/location/GpsLocationProvider.java
+++ b/services/core/java/com/android/server/location/GpsLocationProvider.java
@@ -162,6 +162,9 @@
private static final int GPS_CAPABILITY_MSA = 0x0000004;
private static final int GPS_CAPABILITY_SINGLE_SHOT = 0x0000008;
private static final int GPS_CAPABILITY_ON_DEMAND_TIME = 0x0000010;
+ private static final int GPS_CAPABILITY_GEOFENCING = 0x0000020;
+ private static final int GPS_CAPABILITY_MEASUREMENTS = 0x0000040;
+ private static final int GPS_CAPABILITY_NAV_MESSAGES = 0x0000080;
// The AGPS SUPL mode
private static final int AGPS_SUPL_MODE_MSA = 0x02;
@@ -348,20 +351,9 @@
private final ILocationManager mILocationManager;
private Location mLocation = new Location(LocationManager.GPS_PROVIDER);
private Bundle mLocationExtras = new Bundle();
- private GpsStatusListenerHelper mListenerHelper = new GpsStatusListenerHelper() {
- @Override
- protected boolean isSupported() {
- return GpsLocationProvider.isSupported();
- }
-
- @Override
- protected boolean registerWithService() {
- return true;
- }
-
- @Override
- protected void unregisterFromService() {}
- };
+ private final GpsStatusListenerHelper mListenerHelper;
+ private final GpsMeasurementsProvider mGpsMeasurementsProvider;
+ private final GpsNavigationMessageProvider mGpsNavigationMessageProvider;
// Handler for processing events
private Handler mHandler;
@@ -409,41 +401,6 @@
}
};
- private final GpsMeasurementsProvider mGpsMeasurementsProvider = new GpsMeasurementsProvider() {
- @Override
- public boolean isSupported() {
- return native_is_measurement_supported();
- }
-
- @Override
- protected boolean registerWithService() {
- return native_start_measurement_collection();
- }
-
- @Override
- protected void unregisterFromService() {
- native_stop_measurement_collection();
- }
- };
-
- private final GpsNavigationMessageProvider mGpsNavigationMessageProvider =
- new GpsNavigationMessageProvider() {
- @Override
- protected boolean isSupported() {
- return native_is_navigation_message_supported();
- }
-
- @Override
- protected boolean registerWithService() {
- return native_start_navigation_message_collection();
- }
-
- @Override
- protected void unregisterFromService() {
- native_stop_navigation_message_collection();
- }
- };
-
public IGpsStatusProvider getGpsStatusProvider() {
return mGpsStatusProvider;
}
@@ -696,6 +653,62 @@
mHandler.getLooper());
}
});
+
+ mListenerHelper = new GpsStatusListenerHelper(mHandler) {
+ @Override
+ protected boolean isAvailableInPlatform() {
+ return GpsLocationProvider.isSupported();
+ }
+
+ @Override
+ protected boolean isGpsEnabled() {
+ return isEnabled();
+ }
+ };
+
+ mGpsMeasurementsProvider = new GpsMeasurementsProvider(mHandler) {
+ @Override
+ public boolean isAvailableInPlatform() {
+ return native_is_measurement_supported();
+ }
+
+ @Override
+ protected boolean registerWithService() {
+ return native_start_measurement_collection();
+ }
+
+ @Override
+ protected void unregisterFromService() {
+ native_stop_measurement_collection();
+ }
+
+ @Override
+ protected boolean isGpsEnabled() {
+ return isEnabled();
+ }
+ };
+
+ mGpsNavigationMessageProvider = new GpsNavigationMessageProvider(mHandler) {
+ @Override
+ protected boolean isAvailableInPlatform() {
+ return native_is_navigation_message_supported();
+ }
+
+ @Override
+ protected boolean registerWithService() {
+ return native_start_navigation_message_collection();
+ }
+
+ @Override
+ protected void unregisterFromService() {
+ native_stop_navigation_message_collection();
+ }
+
+ @Override
+ protected boolean isGpsEnabled() {
+ return isEnabled();
+ }
+ };
}
private void listenForBroadcasts() {
@@ -1445,7 +1458,9 @@
}
if (wasNavigating != mNavigating) {
- mListenerHelper.onStatusChanged(mNavigating);
+ mListenerHelper.onGpsEnabledChanged(mNavigating);
+ mGpsMeasurementsProvider.onGpsEnabledChanged(mNavigating);
+ mGpsNavigationMessageProvider.onGpsEnabledChanged(mNavigating);
// send an intent to notify that the GPS has been enabled or disabled
Intent intent = new Intent(LocationManager.GPS_ENABLED_CHANGE_ACTION);
@@ -1598,6 +1613,11 @@
mPeriodicTimeInjection = true;
requestUtcTime();
}
+
+ mGpsMeasurementsProvider.onCapabilitiesUpdated(
+ (capabilities & GPS_CAPABILITY_MEASUREMENTS) == GPS_CAPABILITY_MEASUREMENTS);
+ mGpsNavigationMessageProvider.onCapabilitiesUpdated(
+ (capabilities & GPS_CAPABILITY_NAV_MESSAGES) == GPS_CAPABILITY_NAV_MESSAGES);
}
/**
diff --git a/services/core/java/com/android/server/location/GpsMeasurementsProvider.java b/services/core/java/com/android/server/location/GpsMeasurementsProvider.java
index 1c48257..0514e0c 100644
--- a/services/core/java/com/android/server/location/GpsMeasurementsProvider.java
+++ b/services/core/java/com/android/server/location/GpsMeasurementsProvider.java
@@ -18,7 +18,9 @@
import android.location.GpsMeasurementsEvent;
import android.location.IGpsMeasurementsListener;
+import android.os.Handler;
import android.os.RemoteException;
+import android.util.Log;
/**
* An base implementation for GPS measurements provider.
@@ -29,8 +31,10 @@
*/
public abstract class GpsMeasurementsProvider
extends RemoteListenerHelper<IGpsMeasurementsListener> {
- public GpsMeasurementsProvider() {
- super("GpsMeasurementsProvider");
+ private static final String TAG = "GpsMeasurementsProvider";
+
+ public GpsMeasurementsProvider(Handler handler) {
+ super(handler, TAG);
}
public void onMeasurementsAvailable(final GpsMeasurementsEvent event) {
@@ -41,7 +45,56 @@
listener.onGpsMeasurementsReceived(event);
}
};
-
foreach(operation);
}
+
+ public void onCapabilitiesUpdated(boolean isGpsMeasurementsSupported) {
+ int status = isGpsMeasurementsSupported ?
+ GpsMeasurementsEvent.STATUS_READY :
+ GpsMeasurementsEvent.STATUS_NOT_SUPPORTED;
+ setSupported(isGpsMeasurementsSupported, new StatusChangedOperation(status));
+ }
+
+ @Override
+ protected ListenerOperation<IGpsMeasurementsListener> getHandlerOperation(int result) {
+ final int status;
+ switch (result) {
+ case RESULT_SUCCESS:
+ status = GpsMeasurementsEvent.STATUS_READY;
+ break;
+ case RESULT_NOT_AVAILABLE:
+ case RESULT_NOT_SUPPORTED:
+ case RESULT_INTERNAL_ERROR:
+ status = GpsMeasurementsEvent.STATUS_NOT_SUPPORTED;
+ break;
+ case RESULT_GPS_LOCATION_DISABLED:
+ status = GpsMeasurementsEvent.STATUS_GPS_LOCATION_DISABLED;
+ break;
+ default:
+ Log.v(TAG, "Unhandled addListener result: " + result);
+ return null;
+ }
+ return new StatusChangedOperation(status);
+ }
+
+ @Override
+ protected void handleGpsEnabledChanged(boolean enabled) {
+ int status = enabled ?
+ GpsMeasurementsEvent.STATUS_READY :
+ GpsMeasurementsEvent.STATUS_GPS_LOCATION_DISABLED;
+ foreach(new StatusChangedOperation(status));
+ }
+
+ private class StatusChangedOperation implements ListenerOperation<IGpsMeasurementsListener> {
+ private final int mStatus;
+
+ public StatusChangedOperation(int status) {
+ mStatus = status;
+ }
+
+ @Override
+ public void execute(IGpsMeasurementsListener listener) throws RemoteException {
+ listener.onStatusChanged(mStatus);
+ }
+ }
}
diff --git a/services/core/java/com/android/server/location/GpsNavigationMessageProvider.java b/services/core/java/com/android/server/location/GpsNavigationMessageProvider.java
index fca7378..13d22fc 100644
--- a/services/core/java/com/android/server/location/GpsNavigationMessageProvider.java
+++ b/services/core/java/com/android/server/location/GpsNavigationMessageProvider.java
@@ -18,7 +18,9 @@
import android.location.GpsNavigationMessageEvent;
import android.location.IGpsNavigationMessageListener;
+import android.os.Handler;
import android.os.RemoteException;
+import android.util.Log;
/**
* An base implementation for GPS navigation messages provider.
@@ -29,8 +31,10 @@
*/
public abstract class GpsNavigationMessageProvider
extends RemoteListenerHelper<IGpsNavigationMessageListener> {
- public GpsNavigationMessageProvider() {
- super("GpsNavigationMessageProvider");
+ private static final String TAG = "GpsNavigationMessageProvider";
+
+ public GpsNavigationMessageProvider(Handler handler) {
+ super(handler, TAG);
}
public void onNavigationMessageAvailable(final GpsNavigationMessageEvent event) {
@@ -42,7 +46,57 @@
listener.onGpsNavigationMessageReceived(event);
}
};
-
foreach(operation);
}
+
+ public void onCapabilitiesUpdated(boolean isGpsNavigationMessageSupported) {
+ int status = isGpsNavigationMessageSupported ?
+ GpsNavigationMessageEvent.STATUS_READY :
+ GpsNavigationMessageEvent.STATUS_NOT_SUPPORTED;
+ setSupported(isGpsNavigationMessageSupported, new StatusChangedOperation(status));
+ }
+
+ @Override
+ protected ListenerOperation<IGpsNavigationMessageListener> getHandlerOperation(int result) {
+ final int status;
+ switch (result) {
+ case RESULT_SUCCESS:
+ status = GpsNavigationMessageEvent.STATUS_READY;
+ break;
+ case RESULT_NOT_AVAILABLE:
+ case RESULT_NOT_SUPPORTED:
+ case RESULT_INTERNAL_ERROR:
+ status = GpsNavigationMessageEvent.STATUS_NOT_SUPPORTED;
+ break;
+ case RESULT_GPS_LOCATION_DISABLED:
+ status = GpsNavigationMessageEvent.STATUS_GPS_LOCATION_DISABLED;
+ break;
+ default:
+ Log.v(TAG, "Unhandled addListener result: " + result);
+ return null;
+ }
+ return new StatusChangedOperation(status);
+ }
+
+ @Override
+ protected void handleGpsEnabledChanged(boolean enabled) {
+ int status = enabled ?
+ GpsNavigationMessageEvent.STATUS_READY :
+ GpsNavigationMessageEvent.STATUS_GPS_LOCATION_DISABLED;
+ foreach(new StatusChangedOperation(status));
+ }
+
+ private class StatusChangedOperation
+ implements ListenerOperation<IGpsNavigationMessageListener> {
+ private final int mStatus;
+
+ public StatusChangedOperation(int status) {
+ mStatus = status;
+ }
+
+ @Override
+ public void execute(IGpsNavigationMessageListener listener) throws RemoteException {
+ listener.onStatusChanged(mStatus);
+ }
+ }
}
diff --git a/services/core/java/com/android/server/location/GpsStatusListenerHelper.java b/services/core/java/com/android/server/location/GpsStatusListenerHelper.java
index 27cf3d8..376b4a5 100644
--- a/services/core/java/com/android/server/location/GpsStatusListenerHelper.java
+++ b/services/core/java/com/android/server/location/GpsStatusListenerHelper.java
@@ -17,14 +17,55 @@
package com.android.server.location;
import android.location.IGpsStatusListener;
+import android.os.Handler;
import android.os.RemoteException;
/**
* Implementation of a handler for {@link IGpsStatusListener}.
*/
abstract class GpsStatusListenerHelper extends RemoteListenerHelper<IGpsStatusListener> {
- public GpsStatusListenerHelper() {
- super("GpsStatusListenerHelper");
+ public GpsStatusListenerHelper(Handler handler) {
+ super(handler, "GpsStatusListenerHelper");
+
+ Operation nullOperation = new Operation() {
+ @Override
+ public void execute(IGpsStatusListener iGpsStatusListener) throws RemoteException {}
+ };
+ setSupported(GpsLocationProvider.isSupported(), nullOperation);
+ }
+
+ @Override
+ protected boolean registerWithService() {
+ return true;
+ }
+
+ @Override
+ protected void unregisterFromService() {}
+
+ @Override
+ protected ListenerOperation<IGpsStatusListener> getHandlerOperation(int result) {
+ return null;
+ }
+
+ @Override
+ protected void handleGpsEnabledChanged(boolean enabled) {
+ Operation operation;
+ if (enabled) {
+ operation = new Operation() {
+ @Override
+ public void execute(IGpsStatusListener listener) throws RemoteException {
+ listener.onGpsStarted();
+ }
+ };
+ } else {
+ operation = new Operation() {
+ @Override
+ public void execute(IGpsStatusListener listener) throws RemoteException {
+ listener.onGpsStopped();
+ }
+ };
+ }
+ foreach(operation);
}
public void onFirstFix(final int timeToFirstFix) {
@@ -34,22 +75,6 @@
listener.onFirstFix(timeToFirstFix);
}
};
-
- foreach(operation);
- }
-
- public void onStatusChanged(final boolean isNavigating) {
- Operation operation = new Operation() {
- @Override
- public void execute(IGpsStatusListener listener) throws RemoteException {
- if (isNavigating) {
- listener.onGpsStarted();
- } else {
- listener.onGpsStopped();
- }
- }
- };
-
foreach(operation);
}
@@ -76,7 +101,6 @@
usedInFixMask);
}
};
-
foreach(operation);
}
@@ -87,7 +111,6 @@
listener.onNmeaReceived(timestamp, nmea);
}
};
-
foreach(operation);
}
diff --git a/services/core/java/com/android/server/location/RemoteListenerHelper.java b/services/core/java/com/android/server/location/RemoteListenerHelper.java
index 451af18..402b601 100644
--- a/services/core/java/com/android/server/location/RemoteListenerHelper.java
+++ b/services/core/java/com/android/server/location/RemoteListenerHelper.java
@@ -19,35 +19,41 @@
import com.android.internal.util.Preconditions;
import android.annotation.NonNull;
+import android.os.Handler;
import android.os.IBinder;
import android.os.IInterface;
import android.os.RemoteException;
import android.util.Log;
-import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
/**
* A helper class, that handles operations in remote listeners, and tracks for remote process death.
*/
abstract class RemoteListenerHelper<TListener extends IInterface> {
- private final String mTag;
- private final HashMap<IBinder, LinkedListener> mListenerMap =
- new HashMap<IBinder, LinkedListener>();
+ protected static final int RESULT_SUCCESS = 0;
+ protected static final int RESULT_NOT_AVAILABLE = 1;
+ protected static final int RESULT_NOT_SUPPORTED = 2;
+ protected static final int RESULT_GPS_LOCATION_DISABLED = 3;
+ protected static final int RESULT_INTERNAL_ERROR = 4;
- protected RemoteListenerHelper(String name) {
+ private final Handler mHandler;
+ private final String mTag;
+
+ private final HashMap<IBinder, LinkedListener> mListenerMap = new HashMap<>();
+
+ private boolean mIsRegistered;
+ private boolean mHasIsSupported;
+ private boolean mIsSupported;
+
+ protected RemoteListenerHelper(Handler handler, String name) {
Preconditions.checkNotNull(name);
+ mHandler = handler;
mTag = name;
}
public boolean addListener(@NonNull TListener listener) {
Preconditions.checkNotNull(listener, "Attempted to register a 'null' listener.");
- if (!isSupported()) {
- Log.e(mTag, "Refused to add listener, the feature is not supported.");
- return false;
- }
-
IBinder binder = listener.asBinder();
LinkedListener deathListener = new LinkedListener(listener);
synchronized (mListenerMap) {
@@ -55,77 +61,128 @@
// listener already added
return true;
}
-
try {
binder.linkToDeath(deathListener, 0 /* flags */);
} catch (RemoteException e) {
// if the remote process registering the listener is already death, just swallow the
- // exception and continue
- Log.e(mTag, "Remote listener already died.", e);
+ // exception and return
+ Log.v(mTag, "Remote listener already died.", e);
return false;
}
-
mListenerMap.put(binder, deathListener);
- if (mListenerMap.size() == 1) {
- if (!registerWithService()) {
- Log.e(mTag, "RegisterWithService failed, listener will be removed.");
- removeListener(listener);
- return false;
- }
- }
- }
+ // update statuses we already know about, starting from the ones that will never change
+ int result;
+ if (!isAvailableInPlatform()) {
+ result = RESULT_NOT_AVAILABLE;
+ } else if (mHasIsSupported && !mIsSupported) {
+ result = RESULT_NOT_SUPPORTED;
+ } else if (!isGpsEnabled()) {
+ result = RESULT_GPS_LOCATION_DISABLED;
+ } else if (!tryRegister()) {
+ // only attempt to register if GPS is enabled, otherwise we will register once GPS
+ // becomes available
+ result = RESULT_INTERNAL_ERROR;
+ } else if (mHasIsSupported && mIsSupported) {
+ result = RESULT_SUCCESS;
+ } else {
+ // at this point if the supported flag is not set, the notification will be sent
+ // asynchronously in the future
+ return true;
+ }
+ post(listener, getHandlerOperation(result));
+ }
return true;
}
- public boolean removeListener(@NonNull TListener listener) {
+ public void removeListener(@NonNull TListener listener) {
Preconditions.checkNotNull(listener, "Attempted to remove a 'null' listener.");
- if (!isSupported()) {
- Log.e(mTag, "Refused to remove listener, the feature is not supported.");
- return false;
- }
-
IBinder binder = listener.asBinder();
LinkedListener linkedListener;
synchronized (mListenerMap) {
linkedListener = mListenerMap.remove(binder);
- if (mListenerMap.isEmpty() && linkedListener != null) {
- unregisterFromService();
+ if (mListenerMap.isEmpty()) {
+ tryUnregister();
}
}
-
if (linkedListener != null) {
binder.unlinkToDeath(linkedListener, 0 /* flags */);
}
- return true;
}
- protected abstract boolean isSupported();
+ public void onGpsEnabledChanged(boolean enabled) {
+ // handle first the sub-class implementation, so any error in registration can take
+ // precedence
+ handleGpsEnabledChanged(enabled);
+ synchronized (mListenerMap) {
+ if (!enabled) {
+ tryUnregister();
+ return;
+ }
+ if (mListenerMap.isEmpty()) {
+ return;
+ }
+ if (tryRegister()) {
+ // registration was successful, there is no need to update the state
+ return;
+ }
+ ListenerOperation<TListener> operation = getHandlerOperation(RESULT_INTERNAL_ERROR);
+ foreachUnsafe(operation);
+ }
+ }
+
+ protected abstract boolean isAvailableInPlatform();
+ protected abstract boolean isGpsEnabled();
protected abstract boolean registerWithService();
protected abstract void unregisterFromService();
+ protected abstract ListenerOperation<TListener> getHandlerOperation(int result);
+ protected abstract void handleGpsEnabledChanged(boolean enabled);
protected interface ListenerOperation<TListener extends IInterface> {
void execute(TListener listener) throws RemoteException;
}
- protected void foreach(ListenerOperation operation) {
- Collection<LinkedListener> linkedListeners;
+ protected void foreach(ListenerOperation<TListener> operation) {
synchronized (mListenerMap) {
- Collection<LinkedListener> values = mListenerMap.values();
- linkedListeners = new ArrayList<LinkedListener>(values);
+ foreachUnsafe(operation);
}
+ }
- for (LinkedListener linkedListener : linkedListeners) {
- TListener listener = linkedListener.getUnderlyingListener();
- try {
- operation.execute(listener);
- } catch (RemoteException e) {
- Log.e(mTag, "Error in monitored listener.", e);
- removeListener(listener);
- }
+ protected void setSupported(boolean value, ListenerOperation<TListener> notifier) {
+ synchronized (mListenerMap) {
+ mHasIsSupported = true;
+ mIsSupported = value;
+ foreachUnsafe(notifier);
}
}
+ private void foreachUnsafe(ListenerOperation<TListener> operation) {
+ for (LinkedListener linkedListener : mListenerMap.values()) {
+ post(linkedListener.getUnderlyingListener(), operation);
+ }
+ }
+
+ private void post(TListener listener, ListenerOperation<TListener> operation) {
+ if (operation != null) {
+ mHandler.post(new HandlerRunnable(listener, operation));
+ }
+ }
+
+ private boolean tryRegister() {
+ if (!mIsRegistered) {
+ mIsRegistered = registerWithService();
+ }
+ return mIsRegistered;
+ }
+
+ private void tryUnregister() {
+ if (!mIsRegistered) {
+ return;
+ }
+ unregisterFromService();
+ mIsRegistered = false;
+ }
+
private class LinkedListener implements IBinder.DeathRecipient {
private final TListener mListener;
@@ -144,4 +201,23 @@
removeListener(mListener);
}
}
+
+ private class HandlerRunnable implements Runnable {
+ private final TListener mListener;
+ private final ListenerOperation<TListener> mOperation;
+
+ public HandlerRunnable(TListener listener, ListenerOperation<TListener> operation) {
+ mListener = listener;
+ mOperation = operation;
+ }
+
+ @Override
+ public void run() {
+ try {
+ mOperation.execute(mListener);
+ } catch (RemoteException e) {
+ Log.v(mTag, "Error in monitored listener.", e);
+ }
+ }
+ }
}
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index c75fb9a..a559bdd 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -4561,6 +4561,11 @@
sortedPkgs.add(pkg);
}
+ // If we want to be lazy, filter everything that wasn't recently used.
+ if (mLazyDexOpt) {
+ filterRecentlyUsedApps(sortedPkgs);
+ }
+
int i = 0;
int total = sortedPkgs.size();
File dataDir = Environment.getDataDirectory();
@@ -4579,7 +4584,7 @@
}
}
- private void filterRecentlyUsedApps(ArraySet<PackageParser.Package> pkgs) {
+ private void filterRecentlyUsedApps(Collection<PackageParser.Package> pkgs) {
// Filter out packages that aren't recently used.
//
// The exception is first boot of a non-eng device (aka !mLazyDexOpt), which
diff --git a/telecomm/java/android/telecom/ConnectionService.java b/telecomm/java/android/telecom/ConnectionService.java
index 4648d78..65d48f1 100644
--- a/telecomm/java/android/telecom/ConnectionService.java
+++ b/telecomm/java/android/telecom/ConnectionService.java
@@ -1039,7 +1039,8 @@
connection.setConnectionService(this);
}
- private void removeConnection(Connection connection) {
+ /** {@hide} */
+ protected void removeConnection(Connection connection) {
String id = mIdByConnection.get(connection);
connection.unsetConnectionService(this);
connection.removeConnectionListener(mConnectionListener);