diff options
53 files changed, 635 insertions, 615 deletions
diff --git a/api/17.txt b/api/17.txt index cab0cf53ff5a..0fed27afcf51 100644 --- a/api/17.txt +++ b/api/17.txt @@ -28704,8 +28704,6 @@ package android.widget { method protected void onTextChanged(java.lang.CharSequence, int, int, int); method public boolean onTextContextMenuItem(int); method public void removeTextChangedListener(android.text.TextWatcher); - method protected void resetResolvedDrawables(); - method protected void resolveDrawables(); method public void setAllCaps(boolean); method public final void setAutoLinkMask(int); method public void setCompoundDrawablePadding(int); diff --git a/api/current.txt b/api/current.txt index 7eabad8e46a0..42f6b47b7bc6 100644 --- a/api/current.txt +++ b/api/current.txt @@ -20637,66 +20637,65 @@ package android.speech.tts { package android.telephony { - public abstract class CellIdentity implements android.os.Parcelable { + public final class CellIdentityCdma implements android.os.Parcelable { method public int describeContents(); - method public abstract int hashCode(); - method public void writeToParcel(android.os.Parcel, int); - field public static final android.os.Parcelable.Creator CREATOR; - } - - public final class CellIdentityCdma extends android.telephony.CellIdentity implements android.os.Parcelable { method public int getBasestationId(); method public int getLatitude(); method public int getLongitude(); method public int getNetworkId(); method public int getSystemId(); - method public int hashCode(); + method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; } - public final class CellIdentityGsm extends android.telephony.CellIdentity implements android.os.Parcelable { + public final class CellIdentityGsm implements android.os.Parcelable { + method public int describeContents(); method public int getCid(); method public int getLac(); method public int getMcc(); method public int getMnc(); method public int getPsc(); - method public int hashCode(); + method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; } - public final class CellIdentityLte extends android.telephony.CellIdentity implements android.os.Parcelable { + public final class CellIdentityLte implements android.os.Parcelable { + method public int describeContents(); method public int getCi(); method public int getMcc(); method public int getMnc(); method public int getPci(); method public int getTac(); - method public int hashCode(); + method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; } - public class CellInfo implements android.os.Parcelable { + public abstract class CellInfo implements android.os.Parcelable { method public int describeContents(); method public long getTimeStamp(); method public boolean isRegistered(); - method public void writeToParcel(android.os.Parcel, int); + method public abstract void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; } public final class CellInfoCdma extends android.telephony.CellInfo implements android.os.Parcelable { method public android.telephony.CellIdentityCdma getCellIdentity(); method public android.telephony.CellSignalStrengthCdma getCellSignalStrength(); + method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; } public final class CellInfoGsm extends android.telephony.CellInfo implements android.os.Parcelable { method public android.telephony.CellIdentityGsm getCellIdentity(); method public android.telephony.CellSignalStrengthGsm getCellSignalStrength(); + method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; } public final class CellInfoLte extends android.telephony.CellInfo implements android.os.Parcelable { method public android.telephony.CellIdentityLte getCellIdentity(); method public android.telephony.CellSignalStrengthLte getCellSignalStrength(); + method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; } @@ -20706,18 +20705,16 @@ package android.telephony { method public static void requestLocationUpdate(); } - public abstract class CellSignalStrength implements android.os.Parcelable { - method public int describeContents(); + public abstract class CellSignalStrength { method public abstract boolean equals(java.lang.Object); method public abstract int getAsuLevel(); method public abstract int getDbm(); method public abstract int getLevel(); method public abstract int hashCode(); - method public abstract void writeToParcel(android.os.Parcel, int); - field public static final android.os.Parcelable.Creator CREATOR; } - public class CellSignalStrengthCdma extends android.telephony.CellSignalStrength implements android.os.Parcelable { + public final class CellSignalStrengthCdma extends android.telephony.CellSignalStrength implements android.os.Parcelable { + method public int describeContents(); method public boolean equals(java.lang.Object); method public int getAsuLevel(); method public int getCdmaDbm(); @@ -20734,7 +20731,8 @@ package android.telephony { field public static final android.os.Parcelable.Creator CREATOR; } - public class CellSignalStrengthGsm extends android.telephony.CellSignalStrength implements android.os.Parcelable { + public final class CellSignalStrengthGsm extends android.telephony.CellSignalStrength implements android.os.Parcelable { + method public int describeContents(); method public boolean equals(java.lang.Object); method public int getAsuLevel(); method public int getDbm(); @@ -20744,7 +20742,8 @@ package android.telephony { field public static final android.os.Parcelable.Creator CREATOR; } - public class CellSignalStrengthLte extends android.telephony.CellSignalStrength implements android.os.Parcelable { + public final class CellSignalStrengthLte extends android.telephony.CellSignalStrength implements android.os.Parcelable { + method public int describeContents(); method public boolean equals(java.lang.Object); method public int getAsuLevel(); method public int getDbm(); @@ -24830,9 +24829,6 @@ package android.view { method public void buildDrawingCache(boolean); method public void buildLayer(); method public boolean callOnClick(); - method public boolean canResolveLayoutDirection(); - method public boolean canResolveTextAlignment(); - method public boolean canResolveTextDirection(); method public boolean canScrollHorizontally(int); method public boolean canScrollVertically(int); method public void cancelLongPress(); @@ -24957,9 +24953,6 @@ package android.view { method public android.view.ViewParent getParentForAccessibility(); method public float getPivotX(); method public float getPivotY(); - method public int getResolvedLayoutDirection(); - method public int getResolvedTextAlignment(); - method public int getResolvedTextDirection(); method public android.content.res.Resources getResources(); method public final int getRight(); method protected float getRightFadingEdgeStrength(); @@ -25033,7 +25026,6 @@ package android.view { method public boolean isHovered(); method public boolean isInEditMode(); method public boolean isInTouchMode(); - method protected static boolean isLayoutDirectionRtl(java.util.Locale); method public boolean isLayoutRequested(); method public boolean isLayoutRtl(); method public boolean isLongClickable(); @@ -25089,14 +25081,8 @@ package android.view { method protected void onOverScrolled(int, int, boolean, boolean); method public void onPaddingChanged(int); method public void onPopulateAccessibilityEvent(android.view.accessibility.AccessibilityEvent); - method public void onResolveDrawables(int); - method public void onResolvedLayoutDirectionChanged(); - method public void onResolvedLayoutDirectionReset(); - method public void onResolvedTextAlignmentChanged(); - method public void onResolvedTextAlignmentReset(); - method public void onResolvedTextDirectionChanged(); - method public void onResolvedTextDirectionReset(); method protected void onRestoreInstanceState(android.os.Parcelable); + method public void onRtlPropertiesChanged(); method protected android.os.Parcelable onSaveInstanceState(); method public void onScreenStateChanged(int); method protected void onScrollChanged(int, int, int, int); @@ -25138,16 +25124,8 @@ package android.view { method public void requestLayout(); method public boolean requestRectangleOnScreen(android.graphics.Rect); method public boolean requestRectangleOnScreen(android.graphics.Rect, boolean); - method public void resetResolvedLayoutDirection(); - method public void resetResolvedTextAlignment(); - method public void resetResolvedTextDirection(); - method public void resolveDrawables(); - method public void resolveLayoutDirection(); - method public void resolvePadding(); method public static int resolveSize(int, int); method public static int resolveSizeAndState(int, int, int); - method public void resolveTextAlignment(); - method public void resolveTextDirection(); method public void restoreHierarchyState(android.util.SparseArray<android.os.Parcelable>); method public void saveHierarchyState(android.util.SparseArray<android.os.Parcelable>); method public void scheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable, long); diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 31bbc6a03b04..30b8b853a610 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -3927,7 +3927,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } // Apply layout direction to the new Drawables if needed - final int layoutDirection = getResolvedLayoutDirection(); + final int layoutDirection = getLayoutDirection(); if (track != null) { track.setLayoutDirection(layoutDirection); } @@ -5779,7 +5779,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, @ViewDebug.IntToString(from = LAYOUT_DIRECTION_INHERIT, to = "INHERIT"), @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LOCALE, to = "LOCALE") }) - public int getLayoutDirection() { + private int getRawLayoutDirection() { return (mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_MASK) >> PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT; } @@ -5796,16 +5796,16 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ @RemotableViewMethod public void setLayoutDirection(int layoutDirection) { - if (getLayoutDirection() != layoutDirection) { + if (getRawLayoutDirection() != layoutDirection) { // Reset the current layout direction and the resolved one mPrivateFlags2 &= ~PFLAG2_LAYOUT_DIRECTION_MASK; - resetResolvedLayoutDirection(); - // Reset padding resolution - mPrivateFlags2 &= ~PFLAG2_PADDING_RESOLVED; + resetRtlProperties(); // Set the new layout direction (filtered) mPrivateFlags2 |= ((layoutDirection << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT) & PFLAG2_LAYOUT_DIRECTION_MASK); resolveRtlProperties(); + // Notify changes + onRtlPropertiesChanged(); // ... and ask for a layout pass requestLayout(); } @@ -5821,7 +5821,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "RESOLVED_DIRECTION_LTR"), @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL") }) - public int getResolvedLayoutDirection() { + public int getLayoutDirection() { final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion; if (targetSdkVersion < JELLY_BEAN_MR1) { mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED; @@ -5843,7 +5843,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ @ViewDebug.ExportedProperty(category = "layout") public boolean isLayoutRtl() { - return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL); + return (getLayoutDirection() == LAYOUT_DIRECTION_RTL); } /** @@ -9936,7 +9936,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ private void resolveLayoutParams() { if (mLayoutParams != null) { - mLayoutParams.onResolveLayoutDirection(getResolvedLayoutDirection()); + mLayoutParams.onResolveLayoutDirection(getLayoutDirection()); } } @@ -11475,6 +11475,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, jumpDrawablesToCurrentState(); resolveRtlProperties(); + // Notify changes + onRtlPropertiesChanged(); clearAccessibilityFocus(); if (isFocused()) { @@ -11487,17 +11489,28 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } } + /** + * Resolve all RTL related properties + */ void resolveRtlProperties() { // Order is important here: LayoutDirection MUST be resolved first... resolveLayoutDirection(); // ... then we can resolve the others properties depending on the resolved LayoutDirection. - resolvePadding(); - resolveLayoutParams(); resolveTextDirection(); resolveTextAlignment(); + resolvePadding(); + resolveLayoutParams(); resolveDrawables(); } + // Reset resolution of all RTL related properties + void resetRtlProperties() { + resetResolvedLayoutDirection(); + resetResolvedTextDirection(); + resetResolvedTextAlignment(); + resetResolvedPadding(); + } + /** * @see #onScreenStateChanged(int) */ @@ -11525,9 +11538,22 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** + * Called when any RTL property (layout direction or text direction or text alignment) has + * been changed. + * + * Subclasses need to override this method to take care of cached information that depends on the + * resolved layout direction, or to inform child views that inherit their layout direction. + * + * The default implementation does nothing. + */ + public void onRtlPropertiesChanged() { + } + + /** * Resolve and cache the layout direction. LTR is set initially. This is implicitly supposing * that the parent directionality can and will be resolved before its children. - * Will call {@link View#onResolvedLayoutDirectionChanged} when resolution is done. + * + * @hide */ public void resolveLayoutDirection() { // Clear any previous layout direction resolution @@ -11535,7 +11561,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, if (hasRtlSupport()) { // Set resolved depending on layout direction - switch (getLayoutDirection()) { + switch ((mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_MASK) >> + PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT) { case LAYOUT_DIRECTION_INHERIT: // We cannot resolve yet. LTR is by default and let the resolution happen again // later to get the correct resolved value @@ -11547,7 +11574,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, // resolution happen again later if (!viewGroup.canResolveLayoutDirection()) return; - if (viewGroup.getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) { + if (viewGroup.getLayoutDirection() == LAYOUT_DIRECTION_RTL) { mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL; } break; @@ -11555,7 +11582,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL; break; case LAYOUT_DIRECTION_LOCALE: - if(isLayoutDirectionRtl(Locale.getDefault())) { + if((LAYOUT_DIRECTION_RTL == + TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()))) { mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL; } break; @@ -11566,19 +11594,46 @@ public class View implements Drawable.Callback, KeyEvent.Callback, // Set to resolved mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED; - onResolvedLayoutDirectionChanged(); } /** - * Called when layout direction has been resolved. + * Check if layout direction resolution can be done. * - * The default implementation does nothing. + * @return true if layout direction resolution can be done otherwise return false. + * + * @hide + */ + public boolean canResolveLayoutDirection() { + switch ((mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_MASK) >> + PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT) { + case LAYOUT_DIRECTION_INHERIT: + return (mParent != null) && (mParent instanceof ViewGroup); + default: + return true; + } + } + + /** + * Reset the resolved layout direction. + * + * @hide */ - public void onResolvedLayoutDirectionChanged() { + public void resetResolvedLayoutDirection() { + // Reset the current resolved bits + mPrivateFlags2 &= ~PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK; + } + + /** + * @hide + */ + public boolean isLayoutDirectionInherited() { + return (getRawLayoutDirection() == LAYOUT_DIRECTION_INHERIT); } /** * Return if padding has been resolved + * + * @hide */ boolean isPaddingResolved() { return (mPrivateFlags2 & PFLAG2_PADDING_RESOLVED) != 0; @@ -11586,6 +11641,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, /** * Resolve padding depending on layout direction. + * + * @hide */ public void resolvePadding() { final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion; @@ -11612,7 +11669,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, // If start / end padding are defined, they will be resolved (hence overriding) to // left / right or right / left depending on the resolved layout direction. // If start / end padding are not defined, use the left / right ones. - int resolvedLayoutDirection = getResolvedLayoutDirection(); + int resolvedLayoutDirection = getLayoutDirection(); // Set user padding to initial values ... mUserPaddingLeft = (mUserPaddingLeftInitial == UNDEFINED_PADDING) ? 0 : mUserPaddingLeftInitial; @@ -11649,6 +11706,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** + * Reset the resolved layout direction. + * + * @hide + */ + public void resetResolvedPadding() { + mPrivateFlags2 &= ~PFLAG2_PADDING_RESOLVED; + } + + /** * Resolve padding depending on the layout direction. Subclasses that care about * padding resolution should override this method. The default implementation does * nothing. @@ -11662,53 +11728,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** - * Check if layout direction resolution can be done. - * - * @return true if layout direction resolution can be done otherwise return false. - */ - public boolean canResolveLayoutDirection() { - switch (getLayoutDirection()) { - case LAYOUT_DIRECTION_INHERIT: - return (mParent != null) && (mParent instanceof ViewGroup); - default: - return true; - } - } - - /** - * Reset the resolved layout direction. Will call {@link View#onResolvedLayoutDirectionReset} - * when reset is done. - */ - public void resetResolvedLayoutDirection() { - // Reset the current resolved bits - mPrivateFlags2 &= ~PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK; - onResolvedLayoutDirectionReset(); - // Reset also the text direction - resetResolvedTextDirection(); - } - - /** - * Called during reset of resolved layout direction. - * - * Subclasses need to override this method to clear cached information that depends on the - * resolved layout direction, or to inform child views that inherit their layout direction. - * - * The default implementation does nothing. - */ - public void onResolvedLayoutDirectionReset() { - } - - /** - * Check if a Locale uses an RTL script. - * - * @param locale Locale to check - * @return true if the Locale uses an RTL script. - */ - protected static boolean isLayoutDirectionRtl(Locale locale) { - return (LAYOUT_DIRECTION_RTL == TextUtils.getLayoutDirectionFromLocale(locale)); - } - - /** * This is called when the view is detached from a window. At this point it * no longer has a surface for drawing. * @@ -11738,10 +11757,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, mCurrentAnimation = null; - resetResolvedLayoutDirection(); - resetResolvedTextAlignment(); + resetRtlProperties(); + onRtlPropertiesChanged(); resetAccessibilityStateChanged(); - mPrivateFlags2 &= ~PFLAG2_PADDING_RESOLVED; } /** @@ -14091,12 +14109,14 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * that the View directionality can and will be resolved before its Drawables. * * Will call {@link View#onResolveDrawables} when resolution is done. + * + * @hide */ public void resolveDrawables() { if (mBackground != null) { - mBackground.setLayoutDirection(getResolvedLayoutDirection()); + mBackground.setLayoutDirection(getLayoutDirection()); } - onResolveDrawables(getResolvedLayoutDirection()); + onResolveDrawables(getLayoutDirection()); } /** @@ -14108,6 +14128,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * * @see #LAYOUT_DIRECTION_LTR * @see #LAYOUT_DIRECTION_RTL + * + * @hide */ public void onResolveDrawables(int layoutDirection) { } @@ -14381,10 +14403,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, padding = new Rect(); sThreadLocal.set(padding); } - background.setLayoutDirection(getResolvedLayoutDirection()); + background.setLayoutDirection(getLayoutDirection()); if (background.getPadding(padding)) { - // Reset padding resolution - mPrivateFlags2 &= ~PFLAG2_PADDING_RESOLVED; + resetResolvedPadding(); switch (background.getLayoutDirection()) { case LAYOUT_DIRECTION_RTL: mUserPaddingLeftInitial = padding.right; @@ -14485,8 +14506,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @param bottom the bottom padding in pixels */ public void setPadding(int left, int top, int right, int bottom) { - // Reset padding resolution - mPrivateFlags2 &= ~PFLAG2_PADDING_RESOLVED; + resetResolvedPadding(); mUserPaddingStart = UNDEFINED_PADDING; mUserPaddingEnd = UNDEFINED_PADDING; @@ -14575,13 +14595,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @param bottom the bottom padding in pixels */ public void setPaddingRelative(int start, int top, int end, int bottom) { - // Reset padding resolution - mPrivateFlags2 &= ~PFLAG2_PADDING_RESOLVED; + resetResolvedPadding(); mUserPaddingStart = start; mUserPaddingEnd = end; - switch(getResolvedLayoutDirection()) { + switch(getLayoutDirection()) { case LAYOUT_DIRECTION_RTL: mUserPaddingLeftInitial = end; mUserPaddingRightInitial = start; @@ -14640,7 +14659,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, if (!isPaddingResolved()) { resolvePadding(); } - return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? + return (getLayoutDirection() == LAYOUT_DIRECTION_RTL) ? mPaddingRight : mPaddingLeft; } @@ -14669,7 +14688,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, if (!isPaddingResolved()) { resolvePadding(); } - return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? + return (getLayoutDirection() == LAYOUT_DIRECTION_RTL) ? mPaddingLeft : mPaddingRight; } @@ -16481,6 +16500,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * {@link #TEXT_DIRECTION_LTR}, * {@link #TEXT_DIRECTION_RTL}, * {@link #TEXT_DIRECTION_LOCALE} + * + * @hide */ @ViewDebug.ExportedProperty(category = "text", mapping = { @ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"), @@ -16490,7 +16511,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL"), @ViewDebug.IntToString(from = TEXT_DIRECTION_LOCALE, to = "LOCALE") }) - public int getTextDirection() { + public int getRawTextDirection() { return (mPrivateFlags2 & PFLAG2_TEXT_DIRECTION_MASK) >> PFLAG2_TEXT_DIRECTION_MASK_SHIFT; } @@ -16507,12 +16528,14 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * {@link #TEXT_DIRECTION_LOCALE} */ public void setTextDirection(int textDirection) { - if (getTextDirection() != textDirection) { + if (getRawTextDirection() != textDirection) { // Reset the current text direction and the resolved one mPrivateFlags2 &= ~PFLAG2_TEXT_DIRECTION_MASK; resetResolvedTextDirection(); // Set the new text direction mPrivateFlags2 |= ((textDirection << PFLAG2_TEXT_DIRECTION_MASK_SHIFT) & PFLAG2_TEXT_DIRECTION_MASK); + // Notify change + onRtlPropertiesChanged(); // Refresh requestLayout(); invalidate(true); @@ -16522,10 +16545,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, /** * Return the resolved text direction. * - * This needs resolution if the value is TEXT_DIRECTION_INHERIT. The resolution matches - * {@link #getTextDirection()}if it is not TEXT_DIRECTION_INHERIT, otherwise resolution proceeds - * up the parent chain of the view. if there is no parent, then it will return the default - * {@link #TEXT_DIRECTION_FIRST_STRONG}. + * This needs resolution if the value is TEXT_DIRECTION_INHERIT. The resolution matches what has + * been set by {@link #setTextDirection(int)} if it is not TEXT_DIRECTION_INHERIT, otherwise the + * resolution proceeds up the parent chain of the view. If there is no parent, then it will + * return the default {@link #TEXT_DIRECTION_FIRST_STRONG}. * * @return the resolved text direction. Returns one of: * @@ -16535,7 +16558,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * {@link #TEXT_DIRECTION_RTL}, * {@link #TEXT_DIRECTION_LOCALE} */ - public int getResolvedTextDirection() { + public int getTextDirection() { // The text direction will be resolved only if needed if ((mPrivateFlags2 & PFLAG2_TEXT_DIRECTION_RESOLVED) != PFLAG2_TEXT_DIRECTION_RESOLVED) { resolveTextDirection(); @@ -16544,8 +16567,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** - * Resolve the text direction. Will call {@link View#onResolvedTextDirectionChanged} when - * resolution is done. + * Resolve the text direction. + * + * @hide */ public void resolveTextDirection() { // Reset any previous text direction resolution @@ -16553,14 +16577,14 @@ public class View implements Drawable.Callback, KeyEvent.Callback, if (hasRtlSupport()) { // Set resolved text direction flag depending on text direction flag - final int textDirection = getTextDirection(); + final int textDirection = getRawTextDirection(); switch(textDirection) { case TEXT_DIRECTION_INHERIT: if (canResolveTextDirection()) { ViewGroup viewGroup = ((ViewGroup) mParent); // Set current resolved direction to the same value as the parent's one - final int parentResolvedDirection = viewGroup.getResolvedTextDirection(); + final int parentResolvedDirection = viewGroup.getTextDirection(); switch (parentResolvedDirection) { case TEXT_DIRECTION_FIRST_STRONG: case TEXT_DIRECTION_ANY_RTL: @@ -16598,16 +16622,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, // Set to resolved mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED; - onResolvedTextDirectionChanged(); - } - - /** - * Called when text direction has been resolved. Subclasses that care about text direction - * resolution should override this method. - * - * The default implementation does nothing. - */ - public void onResolvedTextDirectionChanged() { } /** @@ -16615,8 +16629,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * * @return true if text direction resolution can be done otherwise return false. */ - public boolean canResolveTextDirection() { - switch (getTextDirection()) { + private boolean canResolveTextDirection() { + switch (getRawTextDirection()) { case TEXT_DIRECTION_INHERIT: return (mParent != null) && (mParent instanceof ViewGroup); default: @@ -16626,20 +16640,19 @@ public class View implements Drawable.Callback, KeyEvent.Callback, /** * Reset resolved text direction. Text direction can be resolved with a call to - * getResolvedTextDirection(). Will call {@link View#onResolvedTextDirectionReset} when - * reset is done. + * getTextDirection(). + * + * @hide */ public void resetResolvedTextDirection() { mPrivateFlags2 &= ~(PFLAG2_TEXT_DIRECTION_RESOLVED | PFLAG2_TEXT_DIRECTION_RESOLVED_MASK); - onResolvedTextDirectionReset(); } /** - * Called when text direction is reset. Subclasses that care about text direction reset should - * override this method and do a reset of the text direction of their children. The default - * implementation does nothing. + * @hide */ - public void onResolvedTextDirectionReset() { + public boolean isTextDirectionInherited() { + return (getRawTextDirection() == TEXT_DIRECTION_INHERIT); } /** @@ -16655,6 +16668,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * {@link #TEXT_ALIGNMENT_TEXT_END}, * {@link #TEXT_ALIGNMENT_VIEW_START}, * {@link #TEXT_ALIGNMENT_VIEW_END} + * + * @hide */ @ViewDebug.ExportedProperty(category = "text", mapping = { @ViewDebug.IntToString(from = TEXT_ALIGNMENT_INHERIT, to = "INHERIT"), @@ -16665,7 +16680,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_START, to = "VIEW_START"), @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_END, to = "VIEW_END") }) - public int getTextAlignment() { + public int getRawTextAlignment() { return (mPrivateFlags2 & PFLAG2_TEXT_ALIGNMENT_MASK) >> PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT; } @@ -16685,12 +16700,14 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @attr ref android.R.styleable#View_textAlignment */ public void setTextAlignment(int textAlignment) { - if (textAlignment != getTextAlignment()) { + if (textAlignment != getRawTextAlignment()) { // Reset the current and resolved text alignment mPrivateFlags2 &= ~PFLAG2_TEXT_ALIGNMENT_MASK; resetResolvedTextAlignment(); // Set the new text alignment mPrivateFlags2 |= ((textAlignment << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT) & PFLAG2_TEXT_ALIGNMENT_MASK); + // Notify change + onRtlPropertiesChanged(); // Refresh requestLayout(); invalidate(true); @@ -16722,7 +16739,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_START, to = "VIEW_START"), @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_END, to = "VIEW_END") }) - public int getResolvedTextAlignment() { + public int getTextAlignment() { // If text alignment is not resolved, then resolve it if ((mPrivateFlags2 & PFLAG2_TEXT_ALIGNMENT_RESOLVED) != PFLAG2_TEXT_ALIGNMENT_RESOLVED) { resolveTextAlignment(); @@ -16731,8 +16748,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** - * Resolve the text alignment. Will call {@link View#onResolvedTextAlignmentChanged} when - * resolution is done. + * Resolve the text alignment. + * + * @hide */ public void resolveTextAlignment() { // Reset any previous text alignment resolution @@ -16740,14 +16758,14 @@ public class View implements Drawable.Callback, KeyEvent.Callback, if (hasRtlSupport()) { // Set resolved text alignment flag depending on text alignment flag - final int textAlignment = getTextAlignment(); + final int textAlignment = getRawTextAlignment(); switch (textAlignment) { case TEXT_ALIGNMENT_INHERIT: // Check if we can resolve the text alignment - if (canResolveLayoutDirection() && mParent instanceof View) { + if (canResolveTextAlignment() && mParent instanceof View) { View view = (View) mParent; - final int parentResolvedTextAlignment = view.getResolvedTextAlignment(); + final int parentResolvedTextAlignment = view.getTextAlignment(); switch (parentResolvedTextAlignment) { case TEXT_ALIGNMENT_GRAVITY: case TEXT_ALIGNMENT_TEXT_START: @@ -16790,7 +16808,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, // Set the resolved mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED; - onResolvedTextAlignmentChanged(); } /** @@ -16798,8 +16815,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * * @return true if text alignment resolution can be done otherwise return false. */ - public boolean canResolveTextAlignment() { - switch (getTextAlignment()) { + private boolean canResolveTextAlignment() { + switch (getRawTextAlignment()) { case TEXT_DIRECTION_INHERIT: return (mParent != null); default: @@ -16808,31 +16825,20 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** - * Called when text alignment has been resolved. Subclasses that care about text alignment - * resolution should override this method. + * Reset resolved text alignment. * - * The default implementation does nothing. - */ - public void onResolvedTextAlignmentChanged() { - } - - /** - * Reset resolved text alignment. Text alignment can be resolved with a call to - * getResolvedTextAlignment(). Will call {@link View#onResolvedTextAlignmentReset} when - * reset is done. + * @hide */ public void resetResolvedTextAlignment() { // Reset any previous text alignment resolution mPrivateFlags2 &= ~(PFLAG2_TEXT_ALIGNMENT_RESOLVED | PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK); - onResolvedTextAlignmentReset(); } /** - * Called when text alignment is reset. Subclasses that care about text alignment reset should - * override this method and do a reset of the text alignment of their children. The default - * implementation does nothing. + * @hide */ - public void onResolvedTextAlignmentReset() { + public boolean isTextAlignmentInherited() { + return (getRawTextAlignment() == TEXT_ALIGNMENT_INHERIT); } /** diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index ae10fbebb954..34411ea81de0 100644 --- a/core/java/android/view/ViewGroup.java +++ b/core/java/android/view/ViewGroup.java @@ -3392,7 +3392,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager childHasTransientStateChanged(child, true); } - if (child.getLayoutDirection() == View.LAYOUT_DIRECTION_INHERIT) { + if (child.isLayoutDirectionInherited()) { child.resetResolvedLayoutDirection(); child.resolveRtlProperties(); } @@ -5257,37 +5257,24 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager } } + /** + * @hide + */ @Override - public void onResolvedLayoutDirectionReset() { + public void resetResolvedLayoutDirection() { + super.resetResolvedLayoutDirection(); + // Take care of resetting the children resolution too - final int count = getChildCount(); + int count = getChildCount(); for (int i = 0; i < count; i++) { final View child = getChildAt(i); - if (child.getLayoutDirection() == LAYOUT_DIRECTION_INHERIT) { + if (child.isLayoutDirectionInherited()) { child.resetResolvedLayoutDirection(); } - } - } - - @Override - public void onResolvedTextDirectionReset() { - // Take care of resetting the children resolution too - final int count = getChildCount(); - for (int i = 0; i < count; i++) { - final View child = getChildAt(i); - if (child.getTextDirection() == TEXT_DIRECTION_INHERIT) { + if (child.isTextDirectionInherited()) { child.resetResolvedTextDirection(); } - } - } - - @Override - public void onResolvedTextAlignmentReset() { - // Take care of resetting the children resolution too - final int count = getChildCount(); - for (int i = 0; i < count; i++) { - final View child = getChildAt(i); - if (child.getTextAlignment() == TEXT_ALIGNMENT_INHERIT) { + if (child.isTextAlignmentInherited()) { child.resetResolvedTextAlignment(); } } @@ -6168,7 +6155,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager view.getDrawingRect(viewLocation); root.offsetDescendantRectToMyCoords(view, viewLocation); mView = view; - mLayoutDirection = root.getResolvedLayoutDirection(); + mLayoutDirection = root.getLayoutDirection(); } private void clear() { diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 6bb869700433..6db40ba04bef 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -52,6 +52,7 @@ import android.os.RemoteException; import android.os.SystemClock; import android.os.SystemProperties; import android.os.Trace; +import android.os.UserHandle; import android.util.AndroidRuntimeException; import android.util.DisplayMetrics; import android.util.Log; @@ -1493,7 +1494,8 @@ public final class ViewRootImpl implements ViewParent, } catch (Surface.OutOfResourcesException e) { Log.e(TAG, "OutOfResourcesException initializing HW surface", e); try { - if (!mWindowSession.outOfMemory(mWindow)) { + if (!mWindowSession.outOfMemory(mWindow) && + Process.myUid() != Process.SYSTEM_UID) { Slog.w(TAG, "No processes killed for memory; killing self"); Process.killProcess(Process.myPid()); } diff --git a/core/java/android/widget/AbsSeekBar.java b/core/java/android/widget/AbsSeekBar.java index 62253d3abb2a..646fe7e23239 100644 --- a/core/java/android/widget/AbsSeekBar.java +++ b/core/java/android/widget/AbsSeekBar.java @@ -108,7 +108,7 @@ public abstract class AbsSeekBar extends ProgressBar { if (thumb != null) { thumb.setCallback(this); if (canResolveLayoutDirection()) { - thumb.setLayoutDirection(getResolvedLayoutDirection()); + thumb.setLayoutDirection(getLayoutDirection()); } // Assuming the thumb drawable is symmetric, set the thumb offset @@ -308,6 +308,9 @@ public abstract class AbsSeekBar extends ProgressBar { thumb.setBounds(left, topBound, left + thumbWidth, bottomBound); } + /** + * @hide + */ @Override public void onResolveDrawables(int layoutDirection) { super.onResolveDrawables(layoutDirection); diff --git a/core/java/android/widget/AutoCompleteTextView.java b/core/java/android/widget/AutoCompleteTextView.java index e4d49818cc3c..75d1471524bb 100644 --- a/core/java/android/widget/AutoCompleteTextView.java +++ b/core/java/android/widget/AutoCompleteTextView.java @@ -16,7 +16,6 @@ package android.widget; -import android.app.SearchManager.OnDismissListener; import android.content.Context; import android.content.res.TypedArray; import android.database.DataSetObserver; @@ -1094,7 +1093,7 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe mPopup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NEEDED); mPopup.setListItemExpandMax(EXPAND_MAX); } - mPopup.setLayoutDirection(getResolvedLayoutDirection()); + mPopup.setLayoutDirection(getLayoutDirection()); mPopup.show(); mPopup.getListView().setOverScrollMode(View.OVER_SCROLL_ALWAYS); } diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index 237275ae597e..c67cae636f45 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -88,9 +88,6 @@ import android.view.inputmethod.ExtractedTextRequest; import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputMethodManager; import android.widget.AdapterView.OnItemClickListener; -import android.widget.Editor.InputContentType; -import android.widget.Editor.InputMethodState; -import android.widget.Editor.SelectionModifierCursorController; import android.widget.TextView.Drawables; import android.widget.TextView.OnEditorActionListener; @@ -292,7 +289,7 @@ public class Editor { mErrorWasChanged = true; final Drawables dr = mTextView.mDrawables; if (dr != null) { - switch (mTextView.getResolvedLayoutDirection()) { + switch (mTextView.getLayoutDirection()) { default: case View.LAYOUT_DIRECTION_LTR: mTextView.setCompoundDrawables(dr.mDrawableLeft, dr.mDrawableTop, icon, diff --git a/core/java/android/widget/FrameLayout.java b/core/java/android/widget/FrameLayout.java index a025610dde0d..00cd60434e5c 100644 --- a/core/java/android/widget/FrameLayout.java +++ b/core/java/android/widget/FrameLayout.java @@ -411,7 +411,7 @@ public class FrameLayout extends ViewGroup { gravity = DEFAULT_CHILD_GRAVITY; } - final int layoutDirection = getResolvedLayoutDirection(); + final int layoutDirection = getLayoutDirection(); final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection); final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK; @@ -483,7 +483,7 @@ public class FrameLayout extends ViewGroup { selfBounds.set(mPaddingLeft, mPaddingTop, w - mPaddingRight, h - mPaddingBottom); } - final int layoutDirection = getResolvedLayoutDirection(); + final int layoutDirection = getLayoutDirection(); Gravity.apply(mForegroundGravity, foreground.getIntrinsicWidth(), foreground.getIntrinsicHeight(), selfBounds, overlayBounds, layoutDirection); diff --git a/core/java/android/widget/GridView.java b/core/java/android/widget/GridView.java index b6fcb03036c1..63147dd73411 100644 --- a/core/java/android/widget/GridView.java +++ b/core/java/android/widget/GridView.java @@ -1425,7 +1425,7 @@ public class GridView extends AbsListView { int childLeft; final int childTop = flow ? y : y - h; - final int layoutDirection = getResolvedLayoutDirection(); + final int layoutDirection = getLayoutDirection(); final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection); switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: diff --git a/core/java/android/widget/LinearLayout.java b/core/java/android/widget/LinearLayout.java index ea8532503927..b6f08623a38f 100644 --- a/core/java/android/widget/LinearLayout.java +++ b/core/java/android/widget/LinearLayout.java @@ -1495,7 +1495,7 @@ public class LinearLayout extends ViewGroup { if (gravity < 0) { gravity = minorGravity; } - final int layoutDirection = getResolvedLayoutDirection(); + final int layoutDirection = getLayoutDirection(); final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection); switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: @@ -1559,7 +1559,7 @@ public class LinearLayout extends ViewGroup { final int[] maxAscent = mMaxAscent; final int[] maxDescent = mMaxDescent; - final int layoutDirection = getResolvedLayoutDirection(); + final int layoutDirection = getLayoutDirection(); switch (Gravity.getAbsoluteGravity(majorGravity, layoutDirection)) { case Gravity.RIGHT: // mTotalLength contains the padding already diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java index b6d099565287..6afaba32311d 100644 --- a/core/java/android/widget/ProgressBar.java +++ b/core/java/android/widget/ProgressBar.java @@ -479,7 +479,7 @@ public class ProgressBar extends View { } mIndeterminateDrawable = d; if (mIndeterminateDrawable != null && canResolveLayoutDirection()) { - mIndeterminateDrawable.setLayoutDirection(getResolvedLayoutDirection()); + mIndeterminateDrawable.setLayoutDirection(getLayoutDirection()); } if (mIndeterminate) { mCurrentDrawable = d; @@ -521,7 +521,7 @@ public class ProgressBar extends View { if (d != null) { d.setCallback(this); if (canResolveLayoutDirection()) { - d.setLayoutDirection(getResolvedLayoutDirection()); + d.setLayoutDirection(getLayoutDirection()); } // Make sure the ProgressBar is always tall enough @@ -565,6 +565,9 @@ public class ProgressBar extends View { if (mIndeterminateDrawable != null) mIndeterminateDrawable.jumpToCurrentState(); } + /** + * @hide + */ @Override public void onResolveDrawables(int layoutDirection) { final Drawable d = mCurrentDrawable; @@ -669,7 +672,7 @@ public class ProgressBar extends View { if (d instanceof LayerDrawable) { progressDrawable = ((LayerDrawable) d).findDrawableByLayerId(id); if (progressDrawable != null && canResolveLayoutDirection()) { - progressDrawable.setLayoutDirection(getResolvedLayoutDirection()); + progressDrawable.setLayoutDirection(getLayoutDirection()); } } diff --git a/core/java/android/widget/RelativeLayout.java b/core/java/android/widget/RelativeLayout.java index 43519dfaa51b..455355f195cc 100644 --- a/core/java/android/widget/RelativeLayout.java +++ b/core/java/android/widget/RelativeLayout.java @@ -483,7 +483,7 @@ public class RelativeLayout extends ViewGroup { } } - final int layoutDirection = getResolvedLayoutDirection(); + final int layoutDirection = getLayoutDirection(); if (isWrapContentWidth) { // Width already has left padding in it since it was calculated by looking at @@ -578,7 +578,7 @@ public class RelativeLayout extends ViewGroup { } private void alignBaseline(View child, LayoutParams params) { - final int layoutDirection = getResolvedLayoutDirection(); + final int layoutDirection = getLayoutDirection(); int[] rules = params.getRules(layoutDirection); int anchorBaseline = getRelatedViewBaseline(rules, ALIGN_BASELINE); @@ -727,7 +727,7 @@ public class RelativeLayout extends ViewGroup { private boolean positionChildHorizontal(View child, LayoutParams params, int myWidth, boolean wrapContent) { - final int layoutDirection = getResolvedLayoutDirection(); + final int layoutDirection = getLayoutDirection(); int[] rules = params.getRules(layoutDirection); params.onResolveLayoutDirection(layoutDirection); @@ -792,7 +792,7 @@ public class RelativeLayout extends ViewGroup { } private void applyHorizontalSizeRules(LayoutParams childParams, int myWidth) { - final int layoutDirection = getResolvedLayoutDirection(); + final int layoutDirection = getLayoutDirection(); int[] rules = childParams.getRules(layoutDirection); RelativeLayout.LayoutParams anchorParams; @@ -983,7 +983,7 @@ public class RelativeLayout extends ViewGroup { if (child.getVisibility() != GONE) { RelativeLayout.LayoutParams st = (RelativeLayout.LayoutParams) child.getLayoutParams(); - st.onResolveLayoutDirection(getResolvedLayoutDirection()); + st.onResolveLayoutDirection(getLayoutDirection()); child.layout(st.mLeft, st.mTop, st.mRight, st.mBottom); } } diff --git a/core/java/android/widget/SearchView.java b/core/java/android/widget/SearchView.java index 9b62a510f62b..c8389738f21e 100644 --- a/core/java/android/widget/SearchView.java +++ b/core/java/android/widget/SearchView.java @@ -1354,8 +1354,8 @@ public class SearchView extends LinearLayout implements CollapsibleActionView { }; @Override - public void onResolvedLayoutDirectionChanged() { - mQueryTextView.setLayoutDirection(getResolvedLayoutDirection()); + public void onRtlPropertiesChanged() { + mQueryTextView.setLayoutDirection(getLayoutDirection()); } /** diff --git a/core/java/android/widget/Spinner.java b/core/java/android/widget/Spinner.java index ecd7277a04ba..317baf1552db 100644 --- a/core/java/android/widget/Spinner.java +++ b/core/java/android/widget/Spinner.java @@ -492,7 +492,7 @@ public class Spinner extends AbsSpinner implements OnClickListener { View sel = makeAndAddView(mSelectedPosition); int width = sel.getMeasuredWidth(); int selectedOffset = childrenLeft; - final int layoutDirection = getResolvedLayoutDirection(); + final int layoutDirection = getLayoutDirection(); final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection); switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: diff --git a/core/java/android/widget/TableRow.java b/core/java/android/widget/TableRow.java index fb548df30de8..db3853f7c510 100644 --- a/core/java/android/widget/TableRow.java +++ b/core/java/android/widget/TableRow.java @@ -226,7 +226,7 @@ public class TableRow extends LinearLayout { final int childWidth = child.getMeasuredWidth(); lp.mOffset[LayoutParams.LOCATION_NEXT] = columnWidth - childWidth; - final int layoutDirection = getResolvedLayoutDirection(); + final int layoutDirection = getLayoutDirection(); final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection); switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index dd2ff3562499..2937166784d5 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -1546,7 +1546,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener */ public int getCompoundPaddingStart() { resolveDrawables(); - switch(getResolvedLayoutDirection()) { + switch(getLayoutDirection()) { default: case LAYOUT_DIRECTION_LTR: return getCompoundPaddingLeft(); @@ -1561,7 +1561,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener */ public int getCompoundPaddingEnd() { resolveDrawables(); - switch(getResolvedLayoutDirection()) { + switch(getLayoutDirection()) { default: case LAYOUT_DIRECTION_LTR: return getCompoundPaddingRight(); @@ -4858,7 +4858,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener final boolean isLayoutRtl = isLayoutRtl(); - final int layoutDirection = getResolvedLayoutDirection(); + final int layoutDirection = getLayoutDirection(); final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection); if (mEllipsize == TextUtils.TruncateAt.MARQUEE && mMarqueeFadeMode != MARQUEE_FADE_SWITCH_SHOW_ELLIPSIS) { @@ -5635,7 +5635,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } @Override - public void onResolvedLayoutDirectionReset() { + public void onRtlPropertiesChanged() { if (mLayoutAlignment != null) { if (mResolvedTextAlignment == TEXT_ALIGNMENT_VIEW_START || mResolvedTextAlignment == TEXT_ALIGNMENT_VIEW_END) { @@ -5646,7 +5646,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener private Layout.Alignment getLayoutAlignment() { if (mLayoutAlignment == null) { - mResolvedTextAlignment = getResolvedTextAlignment(); + mResolvedTextAlignment = getTextAlignment(); switch (mResolvedTextAlignment) { case TEXT_ALIGNMENT_GRAVITY: switch (mGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) { @@ -5680,11 +5680,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener mLayoutAlignment = Layout.Alignment.ALIGN_CENTER; break; case TEXT_ALIGNMENT_VIEW_START: - mLayoutAlignment = (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? + mLayoutAlignment = (getLayoutDirection() == LAYOUT_DIRECTION_RTL) ? Layout.Alignment.ALIGN_RIGHT : Layout.Alignment.ALIGN_LEFT; break; case TEXT_ALIGNMENT_VIEW_END: - mLayoutAlignment = (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? + mLayoutAlignment = (getLayoutDirection() == LAYOUT_DIRECTION_RTL) ? Layout.Alignment.ALIGN_LEFT : Layout.Alignment.ALIGN_RIGHT; break; case TEXT_ALIGNMENT_INHERIT: @@ -5733,7 +5733,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } if (mTextDir == null) { - resolveTextDirection(); + mTextDir = getTextDirectionHeuristic(); } mLayout = makeSingleLayout(wantWidth, boring, ellipsisWidth, alignment, shouldEllipsize, @@ -5995,7 +5995,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener BoringLayout.Metrics hintBoring = UNKNOWN_BORING; if (mTextDir == null) { - resolveTextDirection(); + getTextDirectionHeuristic(); } int des = -1; @@ -7485,7 +7485,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener return 0.0f; } } else if (getLineCount() == 1) { - final int layoutDirection = getResolvedLayoutDirection(); + final int layoutDirection = getLayoutDirection(); final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection); switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: @@ -7512,7 +7512,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener final float scroll = marquee.getScroll(); return (maxFadeScroll - scroll) / getHorizontalFadingEdgeLength(); } else if (getLineCount() == 1) { - final int layoutDirection = getResolvedLayoutDirection(); + final int layoutDirection = getLayoutDirection(); final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection); switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: @@ -8181,41 +8181,36 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener return mEditor.mInBatchEditControllers; } - @Override - public void onResolvedTextDirectionChanged() { + TextDirectionHeuristic getTextDirectionHeuristic() { if (hasPasswordTransformationMethod()) { // TODO: take care of the content direction to show the password text and dots justified // to the left or to the right - mTextDir = TextDirectionHeuristics.LOCALE; - return; + return TextDirectionHeuristics.LOCALE; } // Always need to resolve layout direction first - final boolean defaultIsRtl = (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL); + final boolean defaultIsRtl = (getLayoutDirection() == LAYOUT_DIRECTION_RTL); // Now, we can select the heuristic - int textDir = getResolvedTextDirection(); - switch (textDir) { + switch (getTextDirection()) { default: case TEXT_DIRECTION_FIRST_STRONG: - mTextDir = (defaultIsRtl ? TextDirectionHeuristics.FIRSTSTRONG_RTL : + return (defaultIsRtl ? TextDirectionHeuristics.FIRSTSTRONG_RTL : TextDirectionHeuristics.FIRSTSTRONG_LTR); - break; case TEXT_DIRECTION_ANY_RTL: - mTextDir = TextDirectionHeuristics.ANYRTL_LTR; - break; + return TextDirectionHeuristics.ANYRTL_LTR; case TEXT_DIRECTION_LTR: - mTextDir = TextDirectionHeuristics.LTR; - break; + return TextDirectionHeuristics.LTR; case TEXT_DIRECTION_RTL: - mTextDir = TextDirectionHeuristics.RTL; - break; + return TextDirectionHeuristics.RTL; case TEXT_DIRECTION_LOCALE: - mTextDir = TextDirectionHeuristics.LOCALE; - break; + return TextDirectionHeuristics.LOCALE; } } + /** + * @hide + */ @Override public void onResolveDrawables(int layoutDirection) { // No need to resolve twice diff --git a/core/java/com/android/internal/view/menu/IconMenuItemView.java b/core/java/com/android/internal/view/menu/IconMenuItemView.java index c7c857104e59..5d0b25f7ce16 100644 --- a/core/java/com/android/internal/view/menu/IconMenuItemView.java +++ b/core/java/com/android/internal/view/menu/IconMenuItemView.java @@ -281,7 +281,7 @@ public final class IconMenuItemView extends TextView implements MenuView.ItemVie Rect tmpRect = mPositionIconOutput; getLineBounds(0, tmpRect); mPositionIconAvailable.set(0, 0, getWidth(), tmpRect.top); - final int layoutDirection = getResolvedLayoutDirection(); + final int layoutDirection = getLayoutDirection(); Gravity.apply(Gravity.CENTER_VERTICAL | Gravity.START, mIcon.getIntrinsicWidth(), mIcon .getIntrinsicHeight(), mPositionIconAvailable, mPositionIconOutput, layoutDirection); diff --git a/core/java/com/android/internal/widget/ActionBarContainer.java b/core/java/com/android/internal/widget/ActionBarContainer.java index 6bcaa0e4731e..0cfe4fdf932a 100644 --- a/core/java/com/android/internal/widget/ActionBarContainer.java +++ b/core/java/com/android/internal/widget/ActionBarContainer.java @@ -161,6 +161,9 @@ public class ActionBarContainer extends FrameLayout { } } + /** + * @hide + */ @Override public void onResolveDrawables(int layoutDirection) { super.onResolveDrawables(layoutDirection); diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java index 2108d0d07fa7..471575085e9a 100644 --- a/core/java/com/android/internal/widget/ActionBarView.java +++ b/core/java/com/android/internal/widget/ActionBarView.java @@ -1088,7 +1088,7 @@ public class ActionBarView extends AbsActionBarView { customView = mCustomNavView; } if (customView != null) { - final int resolvedLayoutDirection = getResolvedLayoutDirection(); + final int resolvedLayoutDirection = getLayoutDirection(); ViewGroup.LayoutParams lp = customView.getLayoutParams(); lp.onResolveLayoutDirection(resolvedLayoutDirection); final ActionBar.LayoutParams ablp = lp instanceof ActionBar.LayoutParams ? @@ -1372,7 +1372,7 @@ public class ActionBarView extends AbsActionBarView { protected void onLayout(boolean changed, int l, int t, int r, int b) { final int vCenter = (b - t) / 2; final boolean isLayoutRtl = isLayoutRtl(); - final int layoutDirection = getResolvedLayoutDirection(); + final int layoutDirection = getLayoutDirection(); final int width = getWidth(); int upOffset = 0; if (mUpView.getVisibility() != GONE) { diff --git a/core/java/com/android/internal/widget/multiwaveview/GlowPadView.java b/core/java/com/android/internal/widget/multiwaveview/GlowPadView.java index 421e247cf52b..7c1f26641d2d 100644 --- a/core/java/com/android/internal/widget/multiwaveview/GlowPadView.java +++ b/core/java/com/android/internal/widget/multiwaveview/GlowPadView.java @@ -39,7 +39,6 @@ import android.util.TypedValue; import android.view.Gravity; import android.view.MotionEvent; import android.view.View; -import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; import com.android.internal.R; @@ -957,7 +956,7 @@ public class GlowPadView extends View { } private void computeInsets(int dx, int dy) { - final int layoutDirection = getResolvedLayoutDirection(); + final int layoutDirection = getLayoutDirection(); final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection); switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { diff --git a/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java b/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java index 10804c024178..7990b4c75640 100644 --- a/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java +++ b/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java @@ -19,7 +19,6 @@ package com.android.internal.widget.multiwaveview; import android.animation.Animator; import android.animation.Animator.AnimatorListener; import android.animation.AnimatorListenerAdapter; -import android.animation.ObjectAnimator; import android.animation.TimeInterpolator; import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; @@ -970,7 +969,7 @@ public class MultiWaveView extends View { } private void computeInsets(int dx, int dy) { - final int layoutDirection = getResolvedLayoutDirection(); + final int layoutDirection = getLayoutDirection(); final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection); switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp index 22f1decc7ad5..898962a4ced7 100644 --- a/libs/hwui/Caches.cpp +++ b/libs/hwui/Caches.cpp @@ -435,15 +435,13 @@ void Caches::resetScissor() { /////////////////////////////////////////////////////////////////////////////// void Caches::startTiling(GLuint x, GLuint y, GLuint width, GLuint height, bool opaque) { - if (extensions.hasTiledRendering()) { - glStartTilingQCOM(x, y, width, height, - (opaque ? GL_NONE : GL_COLOR_BUFFER_BIT0_QCOM) | - (debugOverdraw ? GL_STENCIL_BUFFER_BIT0_QCOM : 0)); + if (extensions.hasTiledRendering() && !debugOverdraw) { + glStartTilingQCOM(x, y, width, height, (opaque ? GL_NONE : GL_COLOR_BUFFER_BIT0_QCOM)); } } void Caches::endTiling() { - if (extensions.hasTiledRendering()) { + if (extensions.hasTiledRendering() && !debugOverdraw) { glEndTilingQCOM(GL_COLOR_BUFFER_BIT0_QCOM); } } diff --git a/libs/hwui/Layer.cpp b/libs/hwui/Layer.cpp index 76b274b00443..fb525ee428ac 100644 --- a/libs/hwui/Layer.cpp +++ b/libs/hwui/Layer.cpp @@ -50,6 +50,13 @@ Layer::~Layer() { deleteTexture(); } +void Layer::freeResourcesLocked() { + if (colorFilter) { + Caches::getInstance().resourceCache.decrementRefcountLocked(colorFilter); + colorFilter = NULL; + } +} + void Layer::setPaint(SkPaint* paint) { OpenGLRenderer::getAlphaAndModeDirect(paint, &alpha, &mode); } diff --git a/libs/hwui/Layer.h b/libs/hwui/Layer.h index 420073ac3b09..d2cd4407ed94 100644 --- a/libs/hwui/Layer.h +++ b/libs/hwui/Layer.h @@ -45,10 +45,11 @@ class DisplayList; * A layer has dimensions and is backed by an OpenGL texture or FBO. */ struct Layer { - Layer(const uint32_t layerWidth, const uint32_t layerHeight); ~Layer(); + void freeResourcesLocked(); + /** * Sets this layer's region to a rectangle. Computes the appropriate * texture coordinates. diff --git a/libs/hwui/ResourceCache.cpp b/libs/hwui/ResourceCache.cpp index 1c83ea463b4d..18d8324b8488 100644 --- a/libs/hwui/ResourceCache.cpp +++ b/libs/hwui/ResourceCache.cpp @@ -155,7 +155,7 @@ void ResourceCache::decrementRefcountLocked(void* resource) { } ref->refCount--; if (ref->refCount == 0) { - deleteResourceReference(resource, ref); + deleteResourceReferenceLocked(resource, ref); } } @@ -201,7 +201,7 @@ void ResourceCache::destructorLocked(SkPath* resource) { } ref->destroyed = true; if (ref->refCount == 0) { - deleteResourceReference(resource, ref); + deleteResourceReferenceLocked(resource, ref); } } @@ -223,7 +223,7 @@ void ResourceCache::destructorLocked(SkBitmap* resource) { } ref->destroyed = true; if (ref->refCount == 0) { - deleteResourceReference(resource, ref); + deleteResourceReferenceLocked(resource, ref); } } @@ -242,7 +242,7 @@ void ResourceCache::destructorLocked(SkiaShader* resource) { } ref->destroyed = true; if (ref->refCount == 0) { - deleteResourceReference(resource, ref); + deleteResourceReferenceLocked(resource, ref); } } @@ -261,7 +261,7 @@ void ResourceCache::destructorLocked(SkiaColorFilter* resource) { } ref->destroyed = true; if (ref->refCount == 0) { - deleteResourceReference(resource, ref); + deleteResourceReferenceLocked(resource, ref); } } @@ -284,7 +284,7 @@ void ResourceCache::recycleLocked(SkBitmap* resource) { } ref->recycled = true; if (ref->refCount == 0) { - deleteResourceReference(resource, ref); + deleteResourceReferenceLocked(resource, ref); } } @@ -292,7 +292,7 @@ void ResourceCache::recycleLocked(SkBitmap* resource) { * This method should only be called while the mLock mutex is held (that mutex is grabbed * by the various destructor() and recycle() methods which call this method). */ -void ResourceCache::deleteResourceReference(void* resource, ResourceReference* ref) { +void ResourceCache::deleteResourceReferenceLocked(void* resource, ResourceReference* ref) { if (ref->recycled && ref->resourceType == kBitmap) { ((SkBitmap*) resource)->setPixels(NULL, NULL); } @@ -326,6 +326,7 @@ void ResourceCache::deleteResourceReference(void* resource, ResourceReference* r break; case kLayer: { Layer* layer = (Layer*) resource; + layer->freeResourcesLocked(); delete layer; } break; diff --git a/libs/hwui/ResourceCache.h b/libs/hwui/ResourceCache.h index 2053d964cbe6..a80670ce36ed 100644 --- a/libs/hwui/ResourceCache.h +++ b/libs/hwui/ResourceCache.h @@ -103,7 +103,7 @@ public: void recycleLocked(SkBitmap* resource); private: - void deleteResourceReference(void* resource, ResourceReference* ref); + void deleteResourceReferenceLocked(void* resource, ResourceReference* ref); void incrementRefcount(void* resource, ResourceType resourceType); void incrementRefcountLocked(void* resource, ResourceType resourceType); diff --git a/libs/hwui/font/CacheTexture.h b/libs/hwui/font/CacheTexture.h index 800bfc43b63e..fdd16232bc41 100644 --- a/libs/hwui/font/CacheTexture.h +++ b/libs/hwui/font/CacheTexture.h @@ -78,12 +78,7 @@ public: } ~CacheTexture() { - if (mTexture) { - delete[] mTexture; - } - if (mTextureId) { - glDeleteTextures(1, &mTextureId); - } + releaseTexture(); reset(); } @@ -106,38 +101,40 @@ public: void releaseTexture() { if (mTexture) { - glDeleteTextures(1, &mTextureId); delete[] mTexture; mTexture = NULL; + } + if (mTextureId) { + glDeleteTextures(1, &mTextureId); mTextureId = 0; } + mDirty = false; } /** * This method assumes that the proper texture unit is active. */ void allocateTexture() { - int width = mWidth; - int height = mHeight; - - mTexture = new uint8_t[width * height]; + if (!mTexture) { + mTexture = new uint8_t[mWidth * mHeight]; + } if (!mTextureId) { glGenTextures(1, &mTextureId); - } - glBindTexture(GL_TEXTURE_2D, mTextureId); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - // Initialize texture dimensions - glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, - GL_ALPHA, GL_UNSIGNED_BYTE, 0); + glBindTexture(GL_TEXTURE_2D, mTextureId); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + // Initialize texture dimensions + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, mWidth, mHeight, 0, + GL_ALPHA, GL_UNSIGNED_BYTE, 0); - const GLenum filtering = getLinearFiltering() ? GL_LINEAR : GL_NEAREST; - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering); + const GLenum filtering = getLinearFiltering() ? GL_LINEAR : GL_NEAREST; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + } } bool fitBitmap(const SkGlyph& glyph, uint32_t* retOriginX, uint32_t* retOriginY); @@ -158,7 +155,8 @@ public: return mTexture; } - inline GLuint getTextureId() const { + GLuint getTextureId() { + allocateTexture(); return mTextureId; } diff --git a/location/java/android/location/Location.java b/location/java/android/location/Location.java index 2d94ddcf227d..672e378e99e4 100644 --- a/location/java/android/location/Location.java +++ b/location/java/android/location/Location.java @@ -59,6 +59,16 @@ public class Location implements Parcelable { */ public static final int FORMAT_SECONDS = 2; + /** + * @hide + */ + public static final String EXTRA_COARSE_LOCATION = "coarseLocation"; + + /** + * @hide + */ + public static final String EXTRA_NO_GPS_LOCATION = "noGPSLocation"; + private String mProvider; private long mTime = 0; private long mElapsedRealtimeNano = 0; @@ -893,4 +903,36 @@ public class Location implements Parcelable { parcel.writeFloat(mAccuracy); parcel.writeBundle(mExtras); } + + /** + * Returns one of the optional extra {@link Location}s that can be attached + * to this Location. + * + * @param key the key associated with the desired extra Location + * @return the extra Location, or null if unavailable + * @hide + */ + public Location getExtraLocation(String key) { + if (mExtras != null) { + Parcelable value = mExtras.getParcelable(key); + if (value instanceof Location) { + return (Location) value; + } + } + return null; + } + + /** + * Attaches an extra {@link Location} to this Location. + * + * @param key the key associated with the Location extra + * @param location the Location to attach + * @hide + */ + public void setExtraLocation(String key, Location value) { + if (mExtras == null) { + mExtras = new Bundle(); + } + mExtras.putParcelable(key, value); + } } diff --git a/location/java/android/location/LocationRequest.java b/location/java/android/location/LocationRequest.java index b1863b807dff..f4f7b09f0864 100644 --- a/location/java/android/location/LocationRequest.java +++ b/location/java/android/location/LocationRequest.java @@ -144,7 +144,7 @@ public final class LocationRequest implements Parcelable { private int mNumUpdates = Integer.MAX_VALUE; // no expiry private float mSmallestDisplacement = 0.0f; // meters - private String mProvider = null; // for deprecated API's that explicitly request a provider + private String mProvider = LocationManager.FUSED_PROVIDER; // for deprecated APIs that explicitly request a provider /** * Create a location request with default parameters. diff --git a/packages/FusedLocation/src/com/android/location/fused/FusionEngine.java b/packages/FusedLocation/src/com/android/location/fused/FusionEngine.java index 1c22c7a33bc3..b83521aef929 100644 --- a/packages/FusedLocation/src/com/android/location/fused/FusionEngine.java +++ b/packages/FusedLocation/src/com/android/location/fused/FusionEngine.java @@ -302,6 +302,10 @@ public class FusionEngine implements LocationListener { 0.0, 360.0)); } + if (mNetworkLocation != null) { + fused.setExtraLocation(Location.EXTRA_NO_GPS_LOCATION, mNetworkLocation); + } + mFusedLocation = fused; mCallback.reportLocation(mFusedLocation); diff --git a/services/java/com/android/server/LocationManagerService.java b/services/java/com/android/server/LocationManagerService.java index 197f6ab63860..840d432ae52e 100644 --- a/services/java/com/android/server/LocationManagerService.java +++ b/services/java/com/android/server/LocationManagerService.java @@ -900,25 +900,41 @@ public class LocationManagerService extends ILocationManager.Stub implements Run return receiver; } + private boolean isProviderAllowedByCoarsePermission(String provider) { + if (LocationManager.FUSED_PROVIDER.equals(provider)) { + return true; + } + if (LocationManager.PASSIVE_PROVIDER.equals(provider)) { + return true; + } + if (LocationManager.NETWORK_PROVIDER.equals(provider)) { + return true; + } + return false; + } + private String checkPermissionAndRequest(LocationRequest request) { String perm = checkPermission(); if (ACCESS_COARSE_LOCATION.equals(perm)) { - switch (request.getQuality()) { - case LocationRequest.ACCURACY_FINE: - request.setQuality(LocationRequest.ACCURACY_BLOCK); - break; - case LocationRequest.POWER_HIGH: - request.setQuality(LocationRequest.POWER_LOW); - break; - } - // throttle - if (request.getInterval() < LocationFudger.FASTEST_INTERVAL_MS) { - request.setInterval(LocationFudger.FASTEST_INTERVAL_MS); - } - if (request.getFastestInterval() < LocationFudger.FASTEST_INTERVAL_MS) { - request.setFastestInterval(LocationFudger.FASTEST_INTERVAL_MS); - } + if (!isProviderAllowedByCoarsePermission(request.getProvider())) { + throw new SecurityException("Requires ACCESS_FINE_LOCATION permission"); + } + switch (request.getQuality()) { + case LocationRequest.ACCURACY_FINE: + request.setQuality(LocationRequest.ACCURACY_BLOCK); + break; + case LocationRequest.POWER_HIGH: + request.setQuality(LocationRequest.POWER_LOW); + break; + } + // throttle + if (request.getInterval() < LocationFudger.FASTEST_INTERVAL_MS) { + request.setInterval(LocationFudger.FASTEST_INTERVAL_MS); + } + if (request.getFastestInterval() < LocationFudger.FASTEST_INTERVAL_MS) { + request.setFastestInterval(LocationFudger.FASTEST_INTERVAL_MS); + } } // make getFastestInterval() the minimum of interval and fastest interval if (request.getFastestInterval() > request.getInterval()) { @@ -990,7 +1006,9 @@ public class LocationManagerService extends ILocationManager.Stub implements Run // use the fused provider if (request == null) request = DEFAULT_LOCATION_REQUEST; String name = request.getProvider(); - if (name == null) name = LocationManager.FUSED_PROVIDER; + if (name == null) { + throw new IllegalArgumentException("provider name must not be null"); + } LocationProviderInterface provider = mProvidersByName.get(name); if (provider == null) { throw new IllegalArgumentException("provider doesn't exisit: " + provider); @@ -1094,12 +1112,19 @@ public class LocationManagerService extends ILocationManager.Stub implements Run if (!isAllowedBySettingsLocked(name)) return null; Location location = mLastLocation.get(name); + if (location == null) { + return null; + } if (ACCESS_FINE_LOCATION.equals(perm)) { return location; } else { - return mLocationFudger.getOrCreate(location); + Location noGPSLocation = location.getExtraLocation(Location.EXTRA_NO_GPS_LOCATION); + if (noGPSLocation != null) { + return mLocationFudger.getOrCreate(noGPSLocation); + } } } + return null; } @Override @@ -1329,17 +1354,29 @@ public class LocationManagerService extends ILocationManager.Stub implements Run LocationProviderInterface p = mProvidersByName.get(provider); if (p == null) return; - // Add the coarse location as an extra - Location coarse = mLocationFudger.getOrCreate(location); - // Update last known locations + Location noGPSLocation = location.getExtraLocation(Location.EXTRA_NO_GPS_LOCATION); + Location lastNoGPSLocation = null; Location lastLocation = mLastLocation.get(provider); if (lastLocation == null) { lastLocation = new Location(provider); mLastLocation.put(provider, lastLocation); + } else { + lastNoGPSLocation = lastLocation.getExtraLocation(Location.EXTRA_NO_GPS_LOCATION); + if (noGPSLocation == null && lastNoGPSLocation != null) { + // New location has no no-GPS location: adopt last no-GPS location. This is set + // directly into location because we do not want to notify COARSE clients. + location.setExtraLocation(Location.EXTRA_NO_GPS_LOCATION, lastNoGPSLocation); + } } lastLocation.set(location); + // Fetch coarse location + Location coarseLocation = null; + if (noGPSLocation != null && !noGPSLocation.equals(lastNoGPSLocation)) { + coarseLocation = mLocationFudger.getOrCreate(noGPSLocation); + } + // Fetch latest status update time long newStatusUpdateTime = p.getStatusUpdateTime(); @@ -1361,29 +1398,31 @@ public class LocationManagerService extends ILocationManager.Stub implements Run continue; } + Location notifyLocation = null; if (ACCESS_FINE_LOCATION.equals(receiver.mPermission)) { - location = lastLocation; // use fine location + notifyLocation = lastLocation; // use fine location } else { - location = coarse; // use coarse location - } - - Location lastLoc = r.mLastFixBroadcast; - if ((lastLoc == null) || shouldBroadcastSafe(location, lastLoc, r)) { - if (lastLoc == null) { - lastLoc = new Location(location); - r.mLastFixBroadcast = lastLoc; - } else { - lastLoc.set(location); - } - if (!receiver.callLocationChangedLocked(location)) { - Slog.w(TAG, "RemoteException calling onLocationChanged on " + receiver); - receiverDead = true; + notifyLocation = coarseLocation; // use coarse location if available + } + if (notifyLocation != null) { + Location lastLoc = r.mLastFixBroadcast; + if ((lastLoc == null) || shouldBroadcastSafe(notifyLocation, lastLoc, r)) { + if (lastLoc == null) { + lastLoc = new Location(notifyLocation); + r.mLastFixBroadcast = lastLoc; + } else { + lastLoc.set(notifyLocation); + } + if (!receiver.callLocationChangedLocked(notifyLocation)) { + Slog.w(TAG, "RemoteException calling onLocationChanged on " + receiver); + receiverDead = true; + } } } long prevStatusUpdateTime = r.mLastStatusBroadcast; if ((newStatusUpdateTime > prevStatusUpdateTime) && - (prevStatusUpdateTime != 0 || status != LocationProvider.AVAILABLE)) { + (prevStatusUpdateTime != 0 || status != LocationProvider.AVAILABLE)) { r.mLastStatusBroadcast = newStatusUpdateTime; if (!receiver.callStatusChangedLocked(provider, status, extras)) { diff --git a/services/java/com/android/server/display/WifiDisplayController.java b/services/java/com/android/server/display/WifiDisplayController.java index 58f04453cf18..d533c941dcc8 100644 --- a/services/java/com/android/server/display/WifiDisplayController.java +++ b/services/java/com/android/server/display/WifiDisplayController.java @@ -73,7 +73,7 @@ final class WifiDisplayController implements DumpUtils.Dump { private static final int DEFAULT_CONTROL_PORT = 7236; private static final int MAX_THROUGHPUT = 50; - private static final int CONNECTION_TIMEOUT_SECONDS = 30; + private static final int CONNECTION_TIMEOUT_SECONDS = 60; private static final int RTSP_TIMEOUT_SECONDS = 15; private static final int DISCOVER_PEERS_MAX_RETRIES = 10; diff --git a/services/java/com/android/server/location/LocationFudger.java b/services/java/com/android/server/location/LocationFudger.java index 84fd25540617..2a68743c578d 100644 --- a/services/java/com/android/server/location/LocationFudger.java +++ b/services/java/com/android/server/location/LocationFudger.java @@ -22,6 +22,7 @@ import java.security.SecureRandom; import android.content.Context; import android.database.ContentObserver; import android.location.Location; +import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.os.Parcelable; @@ -40,8 +41,6 @@ public class LocationFudger { private static final boolean D = false; private static final String TAG = "LocationFudge"; - private static final String EXTRA_COARSE_LOCATION = "coarseLocation"; - /** * Default coarse accuracy in meters. */ @@ -168,18 +167,10 @@ public class LocationFudger { */ public Location getOrCreate(Location location) { synchronized (mLock) { - Bundle extras = location.getExtras(); - if (extras == null) { - return addCoarseLocationExtraLocked(location); - } - Parcelable parcel = extras.getParcelable(EXTRA_COARSE_LOCATION); - if (parcel == null) { - return addCoarseLocationExtraLocked(location); - } - if (!(parcel instanceof Location)) { + Location coarse = location.getExtraLocation(Location.EXTRA_COARSE_LOCATION); + if (coarse == null) { return addCoarseLocationExtraLocked(location); } - Location coarse = (Location) parcel; if (coarse.getAccuracy() < mAccuracyInMeters) { return addCoarseLocationExtraLocked(location); } @@ -188,11 +179,8 @@ public class LocationFudger { } private Location addCoarseLocationExtraLocked(Location location) { - Bundle extras = location.getExtras(); - if (extras == null) extras = new Bundle(); Location coarse = createCoarseLocked(location); - extras.putParcelable(EXTRA_COARSE_LOCATION, coarse); - location.setExtras(extras); + location.setExtraLocation(Location.EXTRA_COARSE_LOCATION, coarse); return coarse; } diff --git a/services/java/com/android/server/location/PassiveProvider.java b/services/java/com/android/server/location/PassiveProvider.java index 0ce21b7bf297..71bae07680a3 100644 --- a/services/java/com/android/server/location/PassiveProvider.java +++ b/services/java/com/android/server/location/PassiveProvider.java @@ -114,6 +114,6 @@ public class PassiveProvider implements LocationProviderInterface { @Override public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { - pw.println("mReportLocaiton=" + mReportLocation); + pw.println("mReportLocation=" + mReportLocation); } } diff --git a/telephony/java/android/telephony/CellIdentity.java b/telephony/java/android/telephony/CellIdentity.java deleted file mode 100644 index a3f78601c759..000000000000 --- a/telephony/java/android/telephony/CellIdentity.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.telephony; - -import android.os.Parcel; -import android.os.Parcelable; - -/** - * CellIdentity is immutable and represents ONE unique cell in the world - * it contains all levels of info to identity country, carrier, etc. - */ -public abstract class CellIdentity implements Parcelable { - - // Type fields for parceling - /** @hide */ - protected static final int TYPE_GSM = 1; - /** @hide */ - protected static final int TYPE_CDMA = 2; - /** @hide */ - protected static final int TYPE_LTE = 3; - - /** @hide */ - protected CellIdentity() { - } - - /** @hide */ - protected CellIdentity(Parcel in) { - } - - /** @hide */ - protected CellIdentity(CellIdentity cid) { - } - - /** - * @return a copy of this object with package visibility. - */ - abstract CellIdentity copy(); - - @Override - public abstract int hashCode(); - - @Override - public boolean equals(Object other) { - if (other == null) { - return false; - } - if (this == other) { - return true; - } - return (other instanceof CellIdentity); - } - - @Override - public String toString() { - return ""; - } - - /** Implement the Parcelable interface */ - @Override - public int describeContents() { - return 0; - } - - /** Implement the Parcelable interface */ - @Override - public void writeToParcel(Parcel dest, int flags) { - } - - /** Implement the Parcelable interface */ - public static final Creator<CellIdentity> CREATOR = - new Creator<CellIdentity>() { - @Override - public CellIdentity createFromParcel(Parcel in) { - int type = in.readInt(); - switch (type) { - case TYPE_GSM: return CellIdentityGsm.createFromParcelBody(in); - case TYPE_CDMA: return CellIdentityCdma.createFromParcelBody(in); - case TYPE_LTE: return CellIdentityLte.createFromParcelBody(in); - default: throw new RuntimeException("Bad CellIdentity Parcel"); - } - } - - @Override - public CellIdentity[] newArray(int size) { - return new CellIdentity[size]; - } - }; -} diff --git a/telephony/java/android/telephony/CellIdentityCdma.java b/telephony/java/android/telephony/CellIdentityCdma.java index fccf98cc5c7a..9579b917f134 100644 --- a/telephony/java/android/telephony/CellIdentityCdma.java +++ b/telephony/java/android/telephony/CellIdentityCdma.java @@ -23,7 +23,7 @@ import android.util.Log; /** * CellIdentity is to represent a unique CDMA cell */ -public final class CellIdentityCdma extends CellIdentity implements Parcelable { +public final class CellIdentityCdma implements Parcelable { private static final String LOG_TAG = "CellSignalStrengthCdma"; private static final boolean DBG = false; @@ -81,7 +81,6 @@ public final class CellIdentityCdma extends CellIdentity implements Parcelable { } private CellIdentityCdma(CellIdentityCdma cid) { - super(cid); mNetworkId = cid.mNetworkId; mSystemId = cid.mSystemId; mBasestationId = cid.mBasestationId; @@ -89,7 +88,6 @@ public final class CellIdentityCdma extends CellIdentity implements Parcelable { mLatitude = cid.mLatitude; } - @Override CellIdentityCdma copy() { return new CellIdentityCdma(this); } @@ -185,8 +183,6 @@ public final class CellIdentityCdma extends CellIdentity implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); - dest.writeInt(TYPE_CDMA); - super.writeToParcel(dest, flags); dest.writeInt(mNetworkId); dest.writeInt(mSystemId); dest.writeInt(mBasestationId); @@ -196,7 +192,6 @@ public final class CellIdentityCdma extends CellIdentity implements Parcelable { /** Construct from Parcel, type has already been processed */ private CellIdentityCdma(Parcel in) { - super(in); mNetworkId = in.readInt(); mSystemId = in.readInt(); mBasestationId = in.readInt(); @@ -211,8 +206,7 @@ public final class CellIdentityCdma extends CellIdentity implements Parcelable { new Creator<CellIdentityCdma>() { @Override public CellIdentityCdma createFromParcel(Parcel in) { - in.readInt(); // Skip past token, we know what it is - return createFromParcelBody(in); + return new CellIdentityCdma(in); } @Override @@ -221,11 +215,6 @@ public final class CellIdentityCdma extends CellIdentity implements Parcelable { } }; - /** @hide */ - static CellIdentityCdma createFromParcelBody(Parcel in) { - return new CellIdentityCdma(in); - } - /** * log */ diff --git a/telephony/java/android/telephony/CellIdentityGsm.java b/telephony/java/android/telephony/CellIdentityGsm.java index dead049f7e69..21cb790cfb53 100644 --- a/telephony/java/android/telephony/CellIdentityGsm.java +++ b/telephony/java/android/telephony/CellIdentityGsm.java @@ -23,7 +23,7 @@ import android.util.Log; /** * CellIdentity to represent a unique GSM or UMTS cell */ -public final class CellIdentityGsm extends CellIdentity implements Parcelable { +public final class CellIdentityGsm implements Parcelable { private static final String LOG_TAG = "CellIdentityGsm"; private static final boolean DBG = false; @@ -69,7 +69,6 @@ public final class CellIdentityGsm extends CellIdentity implements Parcelable { } private CellIdentityGsm(CellIdentityGsm cid) { - super(cid); mMcc = cid.mMcc; mMnc = cid.mMnc; mLac = cid.mLac; @@ -77,7 +76,6 @@ public final class CellIdentityGsm extends CellIdentity implements Parcelable { mPsc = cid.mPsc; } - @Override CellIdentityGsm copy() { return new CellIdentityGsm(this); } @@ -170,8 +168,6 @@ public final class CellIdentityGsm extends CellIdentity implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); - dest.writeInt(TYPE_GSM); - super.writeToParcel(dest, flags); dest.writeInt(mMcc); dest.writeInt(mMnc); dest.writeInt(mLac); @@ -181,7 +177,6 @@ public final class CellIdentityGsm extends CellIdentity implements Parcelable { /** Construct from Parcel, type has already been processed */ private CellIdentityGsm(Parcel in) { - super(in); mMcc = in.readInt(); mMnc = in.readInt(); mLac = in.readInt(); @@ -196,8 +191,7 @@ public final class CellIdentityGsm extends CellIdentity implements Parcelable { new Creator<CellIdentityGsm>() { @Override public CellIdentityGsm createFromParcel(Parcel in) { - in.readInt(); // Skip past token, we know what it is - return createFromParcelBody(in); + return new CellIdentityGsm(in); } @Override @@ -206,11 +200,6 @@ public final class CellIdentityGsm extends CellIdentity implements Parcelable { } }; - /** @hide */ - static CellIdentityGsm createFromParcelBody(Parcel in) { - return new CellIdentityGsm(in); - } - /** * log */ diff --git a/telephony/java/android/telephony/CellIdentityLte.java b/telephony/java/android/telephony/CellIdentityLte.java index 832cbe1c7048..ad822bb30fce 100644 --- a/telephony/java/android/telephony/CellIdentityLte.java +++ b/telephony/java/android/telephony/CellIdentityLte.java @@ -23,7 +23,7 @@ import android.util.Log; /** * CellIdentity is to represent a unique LTE cell */ -public final class CellIdentityLte extends CellIdentity implements Parcelable { +public final class CellIdentityLte implements Parcelable { private static final String LOG_TAG = "CellIdentityLte"; private static final boolean DBG = false; @@ -69,7 +69,6 @@ public final class CellIdentityLte extends CellIdentity implements Parcelable { } private CellIdentityLte(CellIdentityLte cid) { - super(cid); mMcc = cid.mMcc; mMnc = cid.mMnc; mCi = cid.mCi; @@ -77,7 +76,6 @@ public final class CellIdentityLte extends CellIdentity implements Parcelable { mTac = cid.mTac; } - @Override CellIdentityLte copy() { return new CellIdentityLte(this); } @@ -165,8 +163,6 @@ public final class CellIdentityLte extends CellIdentity implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); - dest.writeInt(TYPE_LTE); - super.writeToParcel(dest, flags); dest.writeInt(mMcc); dest.writeInt(mMnc); dest.writeInt(mCi); @@ -176,7 +172,6 @@ public final class CellIdentityLte extends CellIdentity implements Parcelable { /** Construct from Parcel, type has already been processed */ private CellIdentityLte(Parcel in) { - super(in); mMcc = in.readInt(); mMnc = in.readInt(); mCi = in.readInt(); @@ -191,8 +186,7 @@ public final class CellIdentityLte extends CellIdentity implements Parcelable { new Creator<CellIdentityLte>() { @Override public CellIdentityLte createFromParcel(Parcel in) { - in.readInt(); // Skip past token, we know what it is - return createFromParcelBody(in); + return new CellIdentityLte(in); } @Override @@ -201,11 +195,6 @@ public final class CellIdentityLte extends CellIdentity implements Parcelable { } }; - /** @hide */ - static CellIdentityLte createFromParcelBody(Parcel in) { - return new CellIdentityLte(in); - } - /** * log */ diff --git a/telephony/java/android/telephony/CellInfo.java b/telephony/java/android/telephony/CellInfo.java index 1946b5ddcd86..f367f99192e2 100644 --- a/telephony/java/android/telephony/CellInfo.java +++ b/telephony/java/android/telephony/CellInfo.java @@ -22,7 +22,7 @@ import android.os.Parcelable; /** * Immutable cell information from a point in time. */ -public class CellInfo implements Parcelable { +public abstract class CellInfo implements Parcelable { // Type fields for parceling /** @hide */ @@ -157,7 +157,9 @@ public class CellInfo implements Parcelable { return sb.toString(); } - /** Implement the Parcelable interface */ + /** + * Implement the Parcelable interface + */ @Override public int describeContents() { return 0; @@ -165,13 +167,25 @@ public class CellInfo implements Parcelable { /** Implement the Parcelable interface */ @Override - public void writeToParcel(Parcel dest, int flags) { + public abstract void writeToParcel(Parcel dest, int flags); + + /** + * Used by child classes for parceling. + * + * @hide + */ + protected void writeToParcel(Parcel dest, int flags, int type) { + dest.writeInt(type); dest.writeInt(mRegistered ? 1 : 0); dest.writeInt(mTimeStampType); dest.writeLong(mTimeStamp); } - /** @hide */ + /** + * Used by child classes for parceling + * + * @hide + */ protected CellInfo(Parcel in) { mRegistered = (in.readInt() == 1) ? true : false; mTimeStampType = in.readInt(); diff --git a/telephony/java/android/telephony/CellInfoCdma.java b/telephony/java/android/telephony/CellInfoCdma.java index 1c41ba4b81f1..ea48e2e2313b 100644 --- a/telephony/java/android/telephony/CellInfoCdma.java +++ b/telephony/java/android/telephony/CellInfoCdma.java @@ -104,9 +104,7 @@ public final class CellInfoCdma extends CellInfo implements Parcelable { /** Implement the Parcelable interface */ @Override public void writeToParcel(Parcel dest, int flags) { - if (DBG) log("writeToParcel(Parcel, int): " + toString()); - dest.writeInt(TYPE_LTE); - super.writeToParcel(dest, flags); + super.writeToParcel(dest, flags, TYPE_CDMA); mCellIdentityCdma.writeToParcel(dest, flags); mCellSignalStrengthCdma.writeToParcel(dest, flags); } diff --git a/telephony/java/android/telephony/CellInfoGsm.java b/telephony/java/android/telephony/CellInfoGsm.java index c644cb38d6e9..bd14d45a2d1a 100644 --- a/telephony/java/android/telephony/CellInfoGsm.java +++ b/telephony/java/android/telephony/CellInfoGsm.java @@ -104,8 +104,7 @@ public final class CellInfoGsm extends CellInfo implements Parcelable { /** Implement the Parcelable interface */ @Override public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(TYPE_LTE); - super.writeToParcel(dest, flags); + super.writeToParcel(dest, flags, TYPE_GSM); mCellIdentityGsm.writeToParcel(dest, flags); mCellSignalStrengthGsm.writeToParcel(dest, flags); } diff --git a/telephony/java/android/telephony/CellInfoLte.java b/telephony/java/android/telephony/CellInfoLte.java index 8921db2b2ba6..2f81b65607be 100644 --- a/telephony/java/android/telephony/CellInfoLte.java +++ b/telephony/java/android/telephony/CellInfoLte.java @@ -26,7 +26,7 @@ import android.util.Log; public final class CellInfoLte extends CellInfo implements Parcelable { private static final String LOG_TAG = "CellInfoLte"; - private static final boolean DBG = false; + private static final boolean DBG = true; private CellIdentityLte mCellIdentityLte; private CellSignalStrengthLte mCellSignalStrengthLte; @@ -46,18 +46,22 @@ public final class CellInfoLte extends CellInfo implements Parcelable { } public CellIdentityLte getCellIdentity() { + if (DBG) log("getCellIdentity: " + mCellIdentityLte); return mCellIdentityLte; } /** @hide */ public void setCellIdentity(CellIdentityLte cid) { + if (DBG) log("setCellIdentity: " + cid); mCellIdentityLte = cid; } public CellSignalStrengthLte getCellSignalStrength() { + if (DBG) log("getCellSignalStrength: " + mCellSignalStrengthLte); return mCellSignalStrengthLte; } /** @hide */ public void setCellSignalStrength(CellSignalStrengthLte css) { + if (DBG) log("setCellSignalStrength: " + css); mCellSignalStrengthLte = css; } @@ -105,8 +109,7 @@ public final class CellInfoLte extends CellInfo implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); - dest.writeInt(TYPE_LTE); - super.writeToParcel(dest, flags); + super.writeToParcel(dest, flags, TYPE_LTE); mCellIdentityLte.writeToParcel(dest, flags); mCellSignalStrengthLte.writeToParcel(dest, flags); } diff --git a/telephony/java/android/telephony/CellSignalStrength.java b/telephony/java/android/telephony/CellSignalStrength.java index 581efc24dc82..3b470fcba706 100644 --- a/telephony/java/android/telephony/CellSignalStrength.java +++ b/telephony/java/android/telephony/CellSignalStrength.java @@ -22,16 +22,7 @@ import android.os.Parcelable; /** * Abstract base class for cell phone signal strength related information. */ -public abstract class CellSignalStrength implements Parcelable { - - // Type fields for parceling - /** @hide */ - protected static final int TYPE_GSM = 1; - /** @hide */ - protected static final int TYPE_CDMA = 2; - /** @hide */ - protected static final int TYPE_LTE = 3; - +public abstract class CellSignalStrength { /** @hide */ public static final int SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 0; @@ -85,34 +76,4 @@ public abstract class CellSignalStrength implements Parcelable { @Override public abstract boolean equals (Object o); - - /** Implement the Parcelable interface */ - @Override - public int describeContents() { - return 0; - } - - /** Implement the Parcelable interface */ - @Override - public abstract void writeToParcel(Parcel dest, int flags); - - /** Implement the Parcelable interface */ - public static final Creator<CellSignalStrength> CREATOR = - new Creator<CellSignalStrength>() { - @Override - public CellSignalStrength createFromParcel(Parcel in) { - int type = in.readInt(); - switch (type) { - case TYPE_GSM: return CellSignalStrengthGsm.createFromParcelBody(in); - case TYPE_CDMA: return CellSignalStrengthCdma.createFromParcelBody(in); - case TYPE_LTE: return CellSignalStrengthLte.createFromParcelBody(in); - default: throw new RuntimeException("Bad CellSignalStrength Parcel"); - } - } - - @Override - public CellSignalStrength[] newArray(int size) { - return new CellSignalStrength[size]; - } - }; } diff --git a/telephony/java/android/telephony/CellSignalStrengthCdma.java b/telephony/java/android/telephony/CellSignalStrengthCdma.java index 3912629f57e6..660326c4bffe 100644 --- a/telephony/java/android/telephony/CellSignalStrengthCdma.java +++ b/telephony/java/android/telephony/CellSignalStrengthCdma.java @@ -23,7 +23,7 @@ import android.util.Log; /** * LTE signal strength related information. */ -public class CellSignalStrengthCdma extends CellSignalStrength implements Parcelable { +public final class CellSignalStrengthCdma extends CellSignalStrength implements Parcelable { private static final String LOG_TAG = "CellSignalStrengthCdma"; private static final boolean DBG = false; @@ -331,7 +331,6 @@ public class CellSignalStrengthCdma extends CellSignalStrength implements Parcel @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); - dest.writeInt(CellSignalStrength.TYPE_CDMA); dest.writeInt(mCdmaDbm); dest.writeInt(mCdmaEcio); dest.writeInt(mEvdoDbm); @@ -364,10 +363,7 @@ public class CellSignalStrengthCdma extends CellSignalStrength implements Parcel new Parcelable.Creator<CellSignalStrengthCdma>() { @Override public CellSignalStrengthCdma createFromParcel(Parcel in) { - if (in.readInt() != CellSignalStrength.TYPE_CDMA) { - throw new RuntimeException("Expecting TYPE_CDMA"); - } - return createFromParcelBody(in); + return new CellSignalStrengthCdma(in); } @Override @@ -376,11 +372,6 @@ public class CellSignalStrengthCdma extends CellSignalStrength implements Parcel } }; - /** @hide */ - public static CellSignalStrengthCdma createFromParcelBody(Parcel in) { - return new CellSignalStrengthCdma(in); - } - /** * log */ diff --git a/telephony/java/android/telephony/CellSignalStrengthGsm.java b/telephony/java/android/telephony/CellSignalStrengthGsm.java index 30b444b1c2e9..4108f615ec71 100644 --- a/telephony/java/android/telephony/CellSignalStrengthGsm.java +++ b/telephony/java/android/telephony/CellSignalStrengthGsm.java @@ -23,7 +23,7 @@ import android.util.Log; /** * LTE signal strength related information. */ -public class CellSignalStrengthGsm extends CellSignalStrength implements Parcelable { +public final class CellSignalStrengthGsm extends CellSignalStrength implements Parcelable { private static final String LOG_TAG = "CellSignalStrengthGsm"; private static final boolean DBG = false; @@ -190,7 +190,6 @@ public class CellSignalStrengthGsm extends CellSignalStrength implements Parcela @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); - dest.writeInt(CellSignalStrength.TYPE_GSM); dest.writeInt(mSignalStrength); dest.writeInt(mBitErrorRate); } @@ -217,10 +216,7 @@ public class CellSignalStrengthGsm extends CellSignalStrength implements Parcela new Parcelable.Creator<CellSignalStrengthGsm>() { @Override public CellSignalStrengthGsm createFromParcel(Parcel in) { - if (in.readInt() != CellSignalStrength.TYPE_GSM) { - throw new RuntimeException("Expecting TYPE_GSM"); - } - return createFromParcelBody(in); + return new CellSignalStrengthGsm(in); } @Override @@ -229,11 +225,6 @@ public class CellSignalStrengthGsm extends CellSignalStrength implements Parcela } }; - /** @hide */ - public static CellSignalStrengthGsm createFromParcelBody(Parcel in) { - return new CellSignalStrengthGsm(in); - } - /** * log */ diff --git a/telephony/java/android/telephony/CellSignalStrengthLte.java b/telephony/java/android/telephony/CellSignalStrengthLte.java index 7a4d626c189b..925f4d4d1e77 100644 --- a/telephony/java/android/telephony/CellSignalStrengthLte.java +++ b/telephony/java/android/telephony/CellSignalStrengthLte.java @@ -23,7 +23,7 @@ import android.util.Log; /** * LTE signal strength related information. */ -public class CellSignalStrengthLte extends CellSignalStrength implements Parcelable { +public final class CellSignalStrengthLte extends CellSignalStrength implements Parcelable { private static final String LOG_TAG = "CellSignalStrengthLte"; private static final boolean DBG = false; @@ -246,7 +246,6 @@ public class CellSignalStrengthLte extends CellSignalStrength implements Parcela @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); - dest.writeInt(CellSignalStrength.TYPE_LTE); dest.writeInt(mSignalStrength); dest.writeInt(mRsrp); dest.writeInt(mRsrq); @@ -281,10 +280,7 @@ public class CellSignalStrengthLte extends CellSignalStrength implements Parcela new Parcelable.Creator<CellSignalStrengthLte>() { @Override public CellSignalStrengthLte createFromParcel(Parcel in) { - if (in.readInt() != CellSignalStrength.TYPE_LTE) { - throw new RuntimeException("Expecting TYPE_LTE"); - } - return createFromParcelBody(in); + return new CellSignalStrengthLte(in); } @Override @@ -293,11 +289,6 @@ public class CellSignalStrengthLte extends CellSignalStrength implements Parcela } }; - /** @hide */ - public static CellSignalStrengthLte createFromParcelBody(Parcel in) { - return new CellSignalStrengthLte(in); - } - /** * log */ diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Convolve5x5.java b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Convolve5x5.java index b3914d1886c3..03b3bb8e3f83 100644 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Convolve5x5.java +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Convolve5x5.java @@ -46,11 +46,23 @@ public class Convolve5x5 extends TestBase { mHeight = mInPixelsAllocation.getType().getY(); float f[] = new float[25]; - f[0] = 0.012f; f[1] = 0.025f; f[2] = 0.031f; f[3] = 0.025f; f[4] = 0.012f; - f[5] = 0.025f; f[6] = 0.057f; f[7] = 0.075f; f[8] = 0.057f; f[9] = 0.025f; - f[10]= 0.031f; f[11]= 0.075f; f[12]= 0.095f; f[13]= 0.075f; f[14]= 0.031f; - f[15]= 0.025f; f[16]= 0.057f; f[17]= 0.075f; f[18]= 0.057f; f[19]= 0.025f; - f[20]= 0.012f; f[21]= 0.025f; f[22]= 0.031f; f[23]= 0.025f; f[24]= 0.012f; + //f[0] = 0.012f; f[1] = 0.025f; f[2] = 0.031f; f[3] = 0.025f; f[4] = 0.012f; + //f[5] = 0.025f; f[6] = 0.057f; f[7] = 0.075f; f[8] = 0.057f; f[9] = 0.025f; + //f[10]= 0.031f; f[11]= 0.075f; f[12]= 0.095f; f[13]= 0.075f; f[14]= 0.031f; + //f[15]= 0.025f; f[16]= 0.057f; f[17]= 0.075f; f[18]= 0.057f; f[19]= 0.025f; + //f[20]= 0.012f; f[21]= 0.025f; f[22]= 0.031f; f[23]= 0.025f; f[24]= 0.012f; + + //f[0] = 1.f; f[1] = 2.f; f[2] = 0.f; f[3] = -2.f; f[4] = -1.f; + //f[5] = 4.f; f[6] = 8.f; f[7] = 0.f; f[8] = -8.f; f[9] = -4.f; + //f[10]= 6.f; f[11]=12.f; f[12]= 0.f; f[13]=-12.f; f[14]= -6.f; + //f[15]= 4.f; f[16]= 8.f; f[17]= 0.f; f[18]= -8.f; f[19]= -4.f; + //f[20]= 1.f; f[21]= 2.f; f[22]= 0.f; f[23]= -2.f; f[24]= -1.f; + + f[0] = -1.f; f[1] = -3.f; f[2] = -4.f; f[3] = -3.f; f[4] = -1.f; + f[5] = -3.f; f[6] = 0.f; f[7] = 6.f; f[8] = 0.f; f[9] = -3.f; + f[10]= -4.f; f[11]= 6.f; f[12]= 20.f; f[13]= 6.f; f[14]= -4.f; + f[15]= -3.f; f[16]= 0.f; f[17]= 6.f; f[18]= 0.f; f[19]= -3.f; + f[20]= -1.f; f[21]= -3.f; f[22]= -4.f; f[23]= -3.f; f[24]= -1.f; if (mUseIntrinsic) { mIntrinsic = ScriptIntrinsicConvolve5x5.create(mRS, Element.U8_4(mRS)); diff --git a/tests/RenderScriptTests/tests/src/com/android/rs/test/RSTestCore.java b/tests/RenderScriptTests/tests/src/com/android/rs/test/RSTestCore.java index c5850651af33..2a06491228d1 100644 --- a/tests/RenderScriptTests/tests/src/com/android/rs/test/RSTestCore.java +++ b/tests/RenderScriptTests/tests/src/com/android/rs/test/RSTestCore.java @@ -71,6 +71,7 @@ public class RSTestCore { unitTests.add(new UT_array_init(this, mRes, mCtx)); unitTests.add(new UT_array_alloc(this, mRes, mCtx)); unitTests.add(new UT_kernel(this, mRes, mCtx)); + unitTests.add(new UT_kernel_struct(this, mRes, mCtx)); unitTests.add(new UT_clamp(this, mRes, mCtx)); unitTests.add(new UT_clamp_relaxed(this, mRes, mCtx)); unitTests.add(new UT_convert(this, mRes, mCtx)); diff --git a/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_kernel_struct.java b/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_kernel_struct.java new file mode 100644 index 000000000000..8e22810d0154 --- /dev/null +++ b/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_kernel_struct.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test; + +import android.content.Context; +import android.content.res.Resources; +import android.renderscript.*; +import android.util.Log; + +public class UT_kernel_struct extends UnitTest { + private Resources mRes; + private Allocation A; + private Allocation B; + + protected UT_kernel_struct(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Kernels (struct pass-by-value)", ctx); + mRes = res; + } + + private void initializeGlobals(RenderScript RS, ScriptC_kernel_struct s) { + int X = 5; + s.set_dimX(X); + ScriptField_simpleStruct t; + t = new ScriptField_simpleStruct(RS, X); + s.bind_ain(t); + A = t.getAllocation(); + t = new ScriptField_simpleStruct(RS, X); + s.bind_aout(t); + B = t.getAllocation(); + + return; + } + + public void run() { + RenderScript pRS = RenderScript.create(mCtx); + ScriptC_kernel_struct s = new ScriptC_kernel_struct(pRS); + pRS.setMessageHandler(mRsMessage); + initializeGlobals(pRS, s); + s.forEach_init_vars(A); + s.forEach_root(A, B); + s.invoke_verify_root(); + s.invoke_kernel_struct_test(); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/tests/RenderScriptTests/tests/src/com/android/rs/test/kernel_struct.rs b/tests/RenderScriptTests/tests/src/com/android/rs/test/kernel_struct.rs new file mode 100644 index 000000000000..62c30ae445cd --- /dev/null +++ b/tests/RenderScriptTests/tests/src/com/android/rs/test/kernel_struct.rs @@ -0,0 +1,66 @@ +#include "shared.rsh" + +struct simpleStruct { + int i1; + char ignored1; + float f1; + int i2; + char ignored2; + float f2; +}; + +struct simpleStruct *ain; +struct simpleStruct *aout; +int dimX; +static bool failed = false; + +void init_vars(struct simpleStruct *out, uint32_t x) { + out->i1 = 0; + out->f1 = 0.f; + out->i2 = 1; + out->f2 = 1.0f; +} + +struct simpleStruct __attribute__((kernel)) + root(struct simpleStruct in, uint32_t x) { + struct simpleStruct s; + s.i1 = in.i1 + x; + s.f1 = in.f1 + x; + s.i2 = in.i2 + x; + s.f2 = in.f2 + x; + return s; +} + +static bool test_root_output() { + bool failed = false; + int i; + + for (i = 0; i < dimX; i++) { + _RS_ASSERT(aout[i].i1 == (i + ain[i].i1)); + _RS_ASSERT(aout[i].f1 == (i + ain[i].f1)); + _RS_ASSERT(aout[i].i2 == (i + ain[i].i2)); + _RS_ASSERT(aout[i].f2 == (i + ain[i].f2)); + } + + if (failed) { + rsDebug("test_root_output FAILED", 0); + } + else { + rsDebug("test_root_output PASSED", 0); + } + + return failed; +} + +void verify_root() { + failed |= test_root_output(); +} + +void kernel_struct_test() { + if (failed) { + rsSendToClientBlocking(RS_MSG_TEST_FAILED); + } + else { + rsSendToClientBlocking(RS_MSG_TEST_PASSED); + } +} diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java b/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java index bc492b362cd1..cf7604d8a074 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java @@ -68,7 +68,7 @@ public class WifiP2pGroup implements Parcelable { "ssid=\"(.+)\" " + "freq=(\\d+) " + "(?:psk=)?([0-9a-fA-F]{64})?" + - "(?:passphrase=)?(?:\"(.{8,63})\")? " + + "(?:passphrase=)?(?:\"(.{0,63})\")? " + "go_dev_addr=((?:[0-9a-f]{2}:){5}[0-9a-f]{2})" + " ?(\\[PERSISTENT\\])?" ); diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pService.java b/wifi/java/android/net/wifi/p2p/WifiP2pService.java index 13abb79672ad..b317f3f58488 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pService.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pService.java @@ -527,6 +527,11 @@ public class WifiP2pService extends IWifiP2pManager.Stub { case WifiMonitor.NETWORK_CONNECTION_EVENT: case WifiMonitor.NETWORK_DISCONNECTION_EVENT: case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT: + case WifiMonitor.AUTHENTICATION_FAILURE_EVENT: + case WifiMonitor.WPS_SUCCESS_EVENT: + case WifiMonitor.WPS_FAIL_EVENT: + case WifiMonitor.WPS_OVERLAP_EVENT: + case WifiMonitor.WPS_TIMEOUT_EVENT: case WifiMonitor.P2P_GROUP_REMOVED_EVENT: case WifiMonitor.P2P_DEVICE_FOUND_EVENT: case WifiMonitor.P2P_DEVICE_LOST_EVENT: @@ -537,6 +542,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub { case PEER_CONNECTION_USER_ACCEPT: case PEER_CONNECTION_USER_REJECT: case GROUP_CREATING_TIMED_OUT: + case DhcpStateMachine.CMD_PRE_DHCP_ACTION: + case DhcpStateMachine.CMD_POST_DHCP_ACTION: + case DhcpStateMachine.CMD_ON_QUIT: break; /* unexpected group created, remove */ case WifiMonitor.P2P_GROUP_STARTED_EVENT: @@ -1351,34 +1359,18 @@ public class WifiP2pService extends IWifiP2pManager.Stub { if (mWifiNative.p2pGroupRemove(mGroup.getInterface())) { replyToMessage(message, WifiP2pManager.REMOVE_GROUP_SUCCEEDED); } else { + handleGroupRemoved(); + transitionTo(mInactiveState); replyToMessage(message, WifiP2pManager.REMOVE_GROUP_FAILED, WifiP2pManager.ERROR); } break; + /* The supplicant misses the group removed event at times and just + * sends a network disconnect event */ + case WifiMonitor.NETWORK_DISCONNECTION_EVENT: case WifiMonitor.P2P_GROUP_REMOVED_EVENT: if (DBG) logd(getName() + " group removed"); - Collection <WifiP2pDevice> devices = mGroup.getClientList(); - boolean changed = false; - for (WifiP2pDevice d : mPeers.getDeviceList()) { - if (devices.contains(d) || mGroup.getOwner().equals(d)) { - d.status = WifiP2pDevice.AVAILABLE; - changed = true; - } - } - - if (mGroup.isGroupOwner()) { - stopDhcpServer(mGroup.getInterface()); - } else { - if (DBG) logd("stop DHCP client"); - mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_STOP_DHCP); - mDhcpStateMachine.doQuit(); - mDhcpStateMachine = null; - } - - mGroup = null; - mWifiNative.p2pFlush(); - mServiceDiscReqId = null; - if (changed) sendP2pPeersChangedBroadcast(); + handleGroupRemoved(); transitionTo(mInactiveState); break; case WifiMonitor.P2P_DEVICE_LOST_EVENT: @@ -1734,9 +1726,12 @@ public class WifiP2pService extends IWifiP2pManager.Stub { */ private void updatePersistentNetworks() { String listStr = mWifiNative.listNetworks(); + if (listStr == null) return; boolean isSaveRequired = false; String[] lines = listStr.split("\n"); + if (lines == null) return; + // Skip the first line, which is a header for (int i = 1; i < lines.length; i++) { String[] result = lines[i].split("\t"); @@ -2101,6 +2096,31 @@ public class WifiP2pService extends IWifiP2pManager.Stub { sendMessage(WifiP2pManager.DISCOVER_PEERS); } + private void handleGroupRemoved() { + Collection <WifiP2pDevice> devices = mGroup.getClientList(); + boolean changed = false; + for (WifiP2pDevice d : mPeers.getDeviceList()) { + if (devices.contains(d) || mGroup.getOwner().equals(d)) { + d.status = WifiP2pDevice.AVAILABLE; + changed = true; + } + } + + if (mGroup.isGroupOwner()) { + stopDhcpServer(mGroup.getInterface()); + } else { + if (DBG) logd("stop DHCP client"); + mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_STOP_DHCP); + mDhcpStateMachine.doQuit(); + mDhcpStateMachine = null; + } + + mGroup = null; + mWifiNative.p2pFlush(); + mServiceDiscReqId = null; + if (changed) sendP2pPeersChangedBroadcast(); + } + //State machine initiated requests can have replyTo set to null indicating //there are no recipients, we ignore those reply actions private void replyToMessage(Message msg, int what) { |