diff options
86 files changed, 2708 insertions, 341 deletions
diff --git a/api/current.txt b/api/current.txt index 46cf2af..f3dda78 100644 --- a/api/current.txt +++ b/api/current.txt @@ -16007,6 +16007,7 @@ package android.provider { protected static abstract interface ContactsContract.GroupsColumns { field public static final java.lang.String AUTO_ADD = "auto_add"; + field public static final java.lang.String DATA_SET = "data_set"; field public static final java.lang.String DELETED = "deleted"; field public static final java.lang.String FAVORITES = "favorites"; field public static final java.lang.String GROUP_IS_READ_ONLY = "group_is_read_only"; @@ -16134,6 +16135,7 @@ package android.provider { protected static abstract interface ContactsContract.RawContactsColumns { field public static final java.lang.String AGGREGATION_MODE = "aggregation_mode"; field public static final java.lang.String CONTACT_ID = "contact_id"; + field public static final java.lang.String DATA_SET = "data_set"; field public static final java.lang.String DELETED = "deleted"; field public static final java.lang.String RAW_CONTACT_IS_READ_ONLY = "raw_contact_is_read_only"; field public static final java.lang.String RAW_CONTACT_IS_USER_PROFILE = "raw_contact_is_user_profile"; diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java index 479b70a..3fb1736 100644 --- a/cmds/am/src/com/android/commands/am/Am.java +++ b/cmds/am/src/com/android/commands/am/Am.java @@ -157,6 +157,11 @@ public class Am { String value = nextArgRequired(); intent.putExtra(key, Integer.valueOf(value)); hasIntentInfo = true; + } else if (opt.equals("--eu")) { + String key = nextArgRequired(); + String value = nextArgRequired(); + intent.putExtra(key, Uri.parse(value)); + hasIntentInfo = true; } else if (opt.equals("--eia")) { String key = nextArgRequired(); String value = nextArgRequired(); @@ -1119,6 +1124,7 @@ public class Am { " [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]\n" + " [--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]\n" + " [--el <EXTRA_KEY> <EXTRA_LONG_VALUE> ...]\n" + + " [--eu <EXTRA_KEY> <EXTRA_URI_VALUE> ...]\n" + " [--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]\n" + " [--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]\n" + " [-n <COMPONENT>] [-f <FLAGS>]\n" + diff --git a/core/java/android/animation/AnimatorSet.java b/core/java/android/animation/AnimatorSet.java index d77dbdc..e6c2a0f 100644 --- a/core/java/android/animation/AnimatorSet.java +++ b/core/java/android/animation/AnimatorSet.java @@ -87,11 +87,13 @@ public final class AnimatorSet extends Animator { private AnimatorSetListener mSetListener = null; /** - * Flag indicating that the AnimatorSet has been canceled (by calling cancel() or end()). + * Flag indicating that the AnimatorSet has been manually + * terminated (by calling cancel() or end()). * This flag is used to avoid starting other animations when currently-playing - * child animations of this AnimatorSet end. + * child animations of this AnimatorSet end. It also determines whether cancel/end + * notifications are sent out via the normal AnimatorSetListener mechanism. */ - boolean mCanceled = false; + boolean mTerminated = false; // The amount of time in ms to delay starting the animation after start() is called private long mStartDelay = 0; @@ -271,30 +273,28 @@ public final class AnimatorSet extends Animator { @SuppressWarnings("unchecked") @Override public void cancel() { - mCanceled = true; - if (mListeners != null) { - ArrayList<AnimatorListener> tmpListeners = - (ArrayList<AnimatorListener>) mListeners.clone(); - for (AnimatorListener listener : tmpListeners) { - listener.onAnimationCancel(this); - } - } - if (mDelayAnim != null && mDelayAnim.isRunning()) { - // If we're currently in the startDelay period, just cancel that animator and - // send out the end event to all listeners - mDelayAnim.cancel(); + mTerminated = true; + if (isRunning()) { + ArrayList<AnimatorListener> tmpListeners = null; if (mListeners != null) { - ArrayList<AnimatorListener> tmpListeners = - (ArrayList<AnimatorListener>) mListeners.clone(); + tmpListeners = (ArrayList<AnimatorListener>) mListeners.clone(); for (AnimatorListener listener : tmpListeners) { - listener.onAnimationEnd(this); + listener.onAnimationCancel(this); } } - return; - } - if (mSortedNodes.size() > 0) { - for (Node node : mSortedNodes) { - node.animation.cancel(); + if (mDelayAnim != null && mDelayAnim.isRunning()) { + // If we're currently in the startDelay period, just cancel that animator and + // send out the end event to all listeners + mDelayAnim.cancel(); + } else if (mSortedNodes.size() > 0) { + for (Node node : mSortedNodes) { + node.animation.cancel(); + } + } + if (tmpListeners != null) { + for (AnimatorListener listener : tmpListeners) { + listener.onAnimationEnd(this); + } } } } @@ -307,23 +307,32 @@ public final class AnimatorSet extends Animator { */ @Override public void end() { - mCanceled = true; - if (mSortedNodes.size() != mNodes.size()) { - // hasn't been started yet - sort the nodes now, then end them - sortNodes(); - for (Node node : mSortedNodes) { - if (mSetListener == null) { - mSetListener = new AnimatorSetListener(this); + mTerminated = true; + if (isRunning()) { + if (mSortedNodes.size() != mNodes.size()) { + // hasn't been started yet - sort the nodes now, then end them + sortNodes(); + for (Node node : mSortedNodes) { + if (mSetListener == null) { + mSetListener = new AnimatorSetListener(this); + } + node.animation.addListener(mSetListener); } - node.animation.addListener(mSetListener); } - } - if (mDelayAnim != null) { - mDelayAnim.cancel(); - } - if (mSortedNodes.size() > 0) { - for (Node node : mSortedNodes) { - node.animation.end(); + if (mDelayAnim != null) { + mDelayAnim.cancel(); + } + if (mSortedNodes.size() > 0) { + for (Node node : mSortedNodes) { + node.animation.end(); + } + } + if (mListeners != null) { + ArrayList<AnimatorListener> tmpListeners = + (ArrayList<AnimatorListener>) mListeners.clone(); + for (AnimatorListener listener : tmpListeners) { + listener.onAnimationEnd(this); + } } } } @@ -424,7 +433,7 @@ public final class AnimatorSet extends Animator { @SuppressWarnings("unchecked") @Override public void start() { - mCanceled = false; + mTerminated = false; // First, sort the nodes (if necessary). This will ensure that sortedNodes // contains the animation nodes in the correct order. @@ -437,7 +446,8 @@ public final class AnimatorSet extends Animator { ArrayList<AnimatorListener> oldListeners = node.animation.getListeners(); if (oldListeners != null && oldListeners.size() > 0) { for (AnimatorListener listener : oldListeners) { - if (listener instanceof DependencyListener) { + if (listener instanceof DependencyListener || + listener instanceof AnimatorSetListener) { node.animation.removeListener(listener); } } @@ -522,7 +532,7 @@ public final class AnimatorSet extends Animator { * and will populate any appropriate lists, when it is started. */ anim.mNeedsSort = true; - anim.mCanceled = false; + anim.mTerminated = false; anim.mPlayingSet = new ArrayList<Animator>(); anim.mNodeMap = new HashMap<Animator, Node>(); anim.mNodes = new ArrayList<Node>(); @@ -640,7 +650,7 @@ public final class AnimatorSet extends Animator { * @param dependencyAnimation the animation that sent the event. */ private void startIfReady(Animator dependencyAnimation) { - if (mAnimatorSet.mCanceled) { + if (mAnimatorSet.mTerminated) { // if the parent AnimatorSet was canceled, then don't start any dependent anims return; } @@ -676,11 +686,15 @@ public final class AnimatorSet extends Animator { } public void onAnimationCancel(Animator animation) { - if (mPlayingSet.size() == 0) { - if (mListeners != null) { - int numListeners = mListeners.size(); - for (int i = 0; i < numListeners; ++i) { - mListeners.get(i).onAnimationCancel(mAnimatorSet); + if (!mTerminated) { + // Listeners are already notified of the AnimatorSet canceling in cancel(). + // The logic below only kicks in when animations end normally + if (mPlayingSet.size() == 0) { + if (mListeners != null) { + int numListeners = mListeners.size(); + for (int i = 0; i < numListeners; ++i) { + mListeners.get(i).onAnimationCancel(mAnimatorSet); + } } } } @@ -692,24 +706,28 @@ public final class AnimatorSet extends Animator { mPlayingSet.remove(animation); Node animNode = mAnimatorSet.mNodeMap.get(animation); animNode.done = true; - ArrayList<Node> sortedNodes = mAnimatorSet.mSortedNodes; - boolean allDone = true; - int numSortedNodes = sortedNodes.size(); - for (int i = 0; i < numSortedNodes; ++i) { - if (!sortedNodes.get(i).done) { - allDone = false; - break; + if (!mTerminated) { + // Listeners are already notified of the AnimatorSet ending in cancel() or + // end(); the logic below only kicks in when animations end normally + ArrayList<Node> sortedNodes = mAnimatorSet.mSortedNodes; + boolean allDone = true; + int numSortedNodes = sortedNodes.size(); + for (int i = 0; i < numSortedNodes; ++i) { + if (!sortedNodes.get(i).done) { + allDone = false; + break; + } } - } - if (allDone) { - // If this was the last child animation to end, then notify listeners that this - // AnimatorSet has ended - if (mListeners != null) { - ArrayList<AnimatorListener> tmpListeners = - (ArrayList<AnimatorListener>) mListeners.clone(); - int numListeners = tmpListeners.size(); - for (int i = 0; i < numListeners; ++i) { - tmpListeners.get(i).onAnimationEnd(mAnimatorSet); + if (allDone) { + // If this was the last child animation to end, then notify listeners that this + // AnimatorSet has ended + if (mListeners != null) { + ArrayList<AnimatorListener> tmpListeners = + (ArrayList<AnimatorListener>) mListeners.clone(); + int numListeners = tmpListeners.size(); + for (int i = 0; i < numListeners; ++i) { + tmpListeners.get(i).onAnimationEnd(mAnimatorSet); + } } } } @@ -791,6 +809,8 @@ public final class AnimatorSet extends Animator { } } } + // nodes are 'done' by default; they become un-done when started, and done + // again when ended node.done = false; } } diff --git a/core/java/android/animation/ValueAnimator.java b/core/java/android/animation/ValueAnimator.java index 1dcaa04..90d676e 100755 --- a/core/java/android/animation/ValueAnimator.java +++ b/core/java/android/animation/ValueAnimator.java @@ -933,17 +933,17 @@ public class ValueAnimator extends Animator { @Override public void cancel() { - if (mListeners != null) { - ArrayList<AnimatorListener> tmpListeners = - (ArrayList<AnimatorListener>) mListeners.clone(); - for (AnimatorListener listener : tmpListeners) { - listener.onAnimationCancel(this); - } - } // Only cancel if the animation is actually running or has been started and is about // to run if (mPlayingState != STOPPED || sPendingAnimations.get().contains(this) || sDelayedAnims.get().contains(this)) { + if (mListeners != null) { + ArrayList<AnimatorListener> tmpListeners = + (ArrayList<AnimatorListener>) mListeners.clone(); + for (AnimatorListener listener : tmpListeners) { + listener.onAnimationCancel(this); + } + } endAnimation(); } } diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java index a6658cc..d207a0a 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -1471,6 +1471,24 @@ public class ActivityManager { } /** + * Returns the usage statistics of each installed package. + * + * @hide + */ + public PkgUsageStats[] getAllPackageUsageStats() { + try { + IUsageStats usageStatsService = IUsageStats.Stub.asInterface( + ServiceManager.getService("usagestats")); + if (usageStatsService != null) { + return usageStatsService.getAllPkgUsageStats(); + } + } catch (RemoteException e) { + Log.w(TAG, "Could not query usage stats", e); + } + return new PkgUsageStats[0]; + } + + /** * @param userid the user's id. Zero indicates the default user * @hide */ diff --git a/core/java/android/net/NetworkStats.java b/core/java/android/net/NetworkStats.java index 9d40c42..a4c66e4 100644 --- a/core/java/android/net/NetworkStats.java +++ b/core/java/android/net/NetworkStats.java @@ -43,17 +43,41 @@ public class NetworkStats implements Parcelable { /** {@link #tag} value for without tag. */ public static final int TAG_NONE = 0; + // TODO: move public fields to Entry accessors, then undeprecate + // TODO: refactor rx/tx to rxBytes/txBytes + /** * {@link SystemClock#elapsedRealtime()} timestamp when this data was * generated. */ + @Deprecated public final long elapsedRealtime; + @Deprecated public int size; + @Deprecated public String[] iface; + @Deprecated public int[] uid; + @Deprecated public int[] tag; + @Deprecated public long[] rx; + @Deprecated + public long[] rxPackets; + @Deprecated public long[] tx; + @Deprecated + public long[] txPackets; + + public static class Entry { + public String iface; + public int uid; + public int tag; + public long rxBytes; + public long rxPackets; + public long txBytes; + public long txPackets; + } public NetworkStats(long elapsedRealtime, int initialSize) { this.elapsedRealtime = elapsedRealtime; @@ -62,7 +86,9 @@ public class NetworkStats implements Parcelable { this.uid = new int[initialSize]; this.tag = new int[initialSize]; this.rx = new long[initialSize]; + this.rxPackets = new long[initialSize]; this.tx = new long[initialSize]; + this.txPackets = new long[initialSize]; } public NetworkStats(Parcel parcel) { @@ -72,38 +98,82 @@ public class NetworkStats implements Parcelable { uid = parcel.createIntArray(); tag = parcel.createIntArray(); rx = parcel.createLongArray(); + rxPackets = parcel.createLongArray(); tx = parcel.createLongArray(); + txPackets = parcel.createLongArray(); } /** * Add new stats entry with given values. */ public NetworkStats addEntry(String iface, int uid, int tag, long rx, long tx) { + final Entry entry = new Entry(); + entry.iface = iface; + entry.uid = uid; + entry.tag = tag; + entry.rxBytes = rx; + entry.txBytes = tx; + return addValues(entry); + } + + /** + * Add new stats entry, copying from given {@link Entry}. The {@link Entry} + * object can be recycled across multiple calls. + */ + public NetworkStats addValues(Entry entry) { if (size >= this.iface.length) { - final int newLength = Math.max(this.iface.length, 10) * 3 / 2; - this.iface = Arrays.copyOf(this.iface, newLength); - this.uid = Arrays.copyOf(this.uid, newLength); - this.tag = Arrays.copyOf(this.tag, newLength); - this.rx = Arrays.copyOf(this.rx, newLength); - this.tx = Arrays.copyOf(this.tx, newLength); + final int newLength = Math.max(iface.length, 10) * 3 / 2; + iface = Arrays.copyOf(iface, newLength); + uid = Arrays.copyOf(uid, newLength); + tag = Arrays.copyOf(tag, newLength); + rx = Arrays.copyOf(rx, newLength); + rxPackets = Arrays.copyOf(rxPackets, newLength); + tx = Arrays.copyOf(tx, newLength); + txPackets = Arrays.copyOf(txPackets, newLength); } - this.iface[size] = iface; - this.uid[size] = uid; - this.tag[size] = tag; - this.rx[size] = rx; - this.tx[size] = tx; + iface[size] = entry.iface; + uid[size] = entry.uid; + tag[size] = entry.tag; + rx[size] = entry.rxBytes; + rxPackets[size] = entry.rxPackets; + tx[size] = entry.txBytes; + txPackets[size] = entry.txPackets; size++; return this; } /** + * Return specific stats entry. + */ + public Entry getValues(int i, Entry recycle) { + final Entry entry = recycle != null ? recycle : new Entry(); + entry.iface = iface[i]; + entry.uid = uid[i]; + entry.tag = tag[i]; + entry.rxBytes = rx[i]; + entry.rxPackets = rxPackets[i]; + entry.txBytes = tx[i]; + entry.txPackets = txPackets[i]; + return entry; + } + + public long getElapsedRealtime() { + return elapsedRealtime; + } + + public int size() { + return size; + } + + /** * Combine given values with an existing row, or create a new row if * {@link #findIndex(String, int, int)} is unable to find match. Can also be * used to subtract values from existing rows. */ public NetworkStats combineEntry(String iface, int uid, int tag, long rx, long tx) { + // TODO: extent to accept rxPackets/txPackets final int i = findIndex(iface, uid, tag); if (i == -1) { // only create new entry when positive contribution @@ -199,30 +269,41 @@ public class NetworkStats implements Parcelable { } // result will have our rows, and elapsed time between snapshots + final Entry entry = new Entry(); final NetworkStats result = new NetworkStats(deltaRealtime, size); for (int i = 0; i < size; i++) { - final String iface = this.iface[i]; - final int uid = this.uid[i]; - final int tag = this.tag[i]; + entry.iface = iface[i]; + entry.uid = uid[i]; + entry.tag = tag[i]; // find remote row that matches, and subtract - final int j = value.findIndex(iface, uid, tag); + final int j = value.findIndex(entry.iface, entry.uid, entry.tag); if (j == -1) { // newly appearing row, return entire value - result.addEntry(iface, uid, tag, this.rx[i], this.tx[i]); + entry.rxBytes = rx[i]; + entry.rxPackets = rxPackets[i]; + entry.txBytes = tx[i]; + entry.txPackets = txPackets[i]; } else { // existing row, subtract remote value - long rx = this.rx[i] - value.rx[j]; - long tx = this.tx[i] - value.tx[j]; - if (enforceMonotonic && (rx < 0 || tx < 0)) { + entry.rxBytes = rx[i] - value.rx[j]; + entry.rxPackets = rxPackets[i] - value.rxPackets[j]; + entry.txBytes = tx[i] - value.tx[j]; + entry.txPackets = txPackets[i] - value.txPackets[j]; + if (enforceMonotonic + && (entry.rxBytes < 0 || entry.rxPackets < 0 || entry.txBytes < 0 + || entry.txPackets < 0)) { throw new IllegalArgumentException("found non-monotonic values"); } if (clampNegative) { - rx = Math.max(0, rx); - tx = Math.max(0, tx); + entry.rxBytes = Math.max(0, entry.rxBytes); + entry.rxPackets = Math.max(0, entry.rxPackets); + entry.txBytes = Math.max(0, entry.txBytes); + entry.txPackets = Math.max(0, entry.txPackets); } - result.addEntry(iface, uid, tag, rx, tx); } + + result.addValues(entry); } return result; @@ -235,13 +316,15 @@ public class NetworkStats implements Parcelable { public void dump(String prefix, PrintWriter pw) { pw.print(prefix); pw.print("NetworkStats: elapsedRealtime="); pw.println(elapsedRealtime); - for (int i = 0; i < iface.length; i++) { + for (int i = 0; i < size; i++) { pw.print(prefix); pw.print(" iface="); pw.print(iface[i]); pw.print(" uid="); pw.print(uid[i]); pw.print(" tag="); pw.print(tag[i]); - pw.print(" rx="); pw.print(rx[i]); - pw.print(" tx="); pw.println(tx[i]); + pw.print(" rxBytes="); pw.print(rx[i]); + pw.print(" rxPackets="); pw.print(rxPackets[i]); + pw.print(" txBytes="); pw.print(tx[i]); + pw.print(" txPackets="); pw.println(txPackets[i]); } } @@ -265,7 +348,9 @@ public class NetworkStats implements Parcelable { dest.writeIntArray(uid); dest.writeIntArray(tag); dest.writeLongArray(rx); + dest.writeLongArray(rxPackets); dest.writeLongArray(tx); + dest.writeLongArray(txPackets); } public static final Creator<NetworkStats> CREATOR = new Creator<NetworkStats>() { diff --git a/core/java/android/provider/ContactsContract.java b/core/java/android/provider/ContactsContract.java index 61deea4..ec67683 100644 --- a/core/java/android/provider/ContactsContract.java +++ b/core/java/android/provider/ContactsContract.java @@ -135,14 +135,6 @@ public final class ContactsContract { public static final String ALLOW_PROFILE = "allow_profile"; /** - * A query parameter key used to specify the package that is requesting a query. - * This is used for restricting data based on package name. - * - * @hide - */ - public static final String REQUESTING_PACKAGE_PARAM_KEY = "requesting_package"; - - /** * Query parameter that should be used by the client to access a specific * {@link Directory}. The parameter value should be the _ID of the corresponding * directory, e.g. @@ -271,8 +263,6 @@ public final class ContactsContract { * <li>The URI authority is replaced with the corresponding {@link #DIRECTORY_AUTHORITY}.</li> * <li>The {@code accountName=} and {@code accountType=} parameters are added or * replaced using the corresponding {@link #ACCOUNT_TYPE} and {@link #ACCOUNT_NAME} values.</li> - * <li>If the URI is missing a ContactsContract.REQUESTING_PACKAGE_PARAM_KEY - * parameter, this parameter is added.</li> * </ul> * </p> * <p> @@ -1881,13 +1871,16 @@ public final class ContactsContract { public static final String CONTACT_ID = "contact_id"; /** - * Flag indicating that this {@link RawContacts} entry and its children have - * been restricted to specific platform apps. - * <P>Type: INTEGER (boolean)</P> + * The data set within the account that this row belongs to. This allows + * multiple sync adapters for the same account type to distinguish between + * each others' data. * - * @hide until finalized in future platform release + * This is empty by default, and is completely optional. It only needs to + * be populated if multiple sync adapters are entering distinct data for + * the same account type and account name. + * <P>Type: TEXT</P> */ - public static final String IS_RESTRICTED = "is_restricted"; + public static final String DATA_SET = "data_set"; /** * The aggregation mode for this contact. @@ -2211,8 +2204,8 @@ public final class ContactsContract { * <td>The name of the account instance to which this row belongs, which when paired with * {@link #ACCOUNT_TYPE} identifies a specific account. * For example, this will be the Gmail address if it is a Google account. - * It should be set at the time - * the raw contact is inserted and never changed afterwards.</td> + * It should be set at the time the raw contact is inserted and never + * changed afterwards.</td> * </tr> * <tr> * <td>String</td> @@ -2222,8 +2215,8 @@ public final class ContactsContract { * <p> * The type of account to which this row belongs, which when paired with * {@link #ACCOUNT_NAME} identifies a specific account. - * It should be set at the time - * the raw contact is inserted and never changed afterwards. + * It should be set at the time the raw contact is inserted and never + * changed afterwards. * </p> * <p> * To ensure uniqueness, new account types should be chosen according to the @@ -2233,15 +2226,38 @@ public final class ContactsContract { * </tr> * <tr> * <td>String</td> + * <td>{@link #DATA_SET}</td> + * <td>read/write-once</td> + * <td> + * <p> + * The data set within the account that this row belongs to. This allows + * multiple sync adapters for the same account type to distinguish between + * each others' data. The combination of {@link #ACCOUNT_TYPE}, + * {@link #ACCOUNT_NAME}, and {@link #DATA_SET} identifies a set of data + * that is associated with a single sync adapter. + * </p> + * <p> + * This is empty by default, and is completely optional. It only needs to + * be populated if multiple sync adapters are entering distinct data for + * the same account type and account name. + * </p> + * <p> + * It should be set at the time the raw contact is inserted and never + * changed afterwards. + * </p> + * </td> + * </tr> + * <tr> + * <td>String</td> * <td>{@link #SOURCE_ID}</td> * <td>read/write</td> * <td>String that uniquely identifies this row to its source account. * Typically it is set at the time the raw contact is inserted and never * changed afterwards. The one notable exception is a new raw contact: it - * will have an account name and type, but no source id. This - * indicates to the sync adapter that a new contact needs to be created - * server-side and its ID stored in the corresponding SOURCE_ID field on - * the phone. + * will have an account name and type (and possibly a data set), but no + * source id. This indicates to the sync adapter that a new contact needs + * to be created server-side and its ID stored in the corresponding + * SOURCE_ID field on the phone. * </td> * </tr> * <tr> @@ -2537,7 +2553,6 @@ public final class ContactsContract { DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DELETED); DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, CONTACT_ID); DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, STARRED); - DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, IS_RESTRICTED); DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, NAME_VERIFIED); android.content.Entity contact = new android.content.Entity(cv); @@ -3814,27 +3829,6 @@ public final class ContactsContract { /** * <p> - * If {@link #FOR_EXPORT_ONLY} is explicitly set to "1", returned Cursor toward - * Data.CONTENT_URI contains only exportable data. - * </p> - * <p> - * This flag is useful (currently) only for vCard exporter in Contacts app, which - * needs to exclude "un-exportable" data from available data to export, while - * Contacts app itself has priviledge to access all data including "un-exportable" - * ones and providers return all of them regardless of the callers' intention. - * </p> - * <p> - * Type: INTEGER - * </p> - * - * @hide Maybe available only in Eclair and not really ready for public use. - * TODO: remove, or implement this feature completely. As of now (Eclair), - * we only use this flag in queryEntities(), not query(). - */ - public static final String FOR_EXPORT_ONLY = "for_export_only"; - - /** - * <p> * Build a {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI} * style {@link Uri} for the parent {@link android.provider.ContactsContract.Contacts} * entry of the given {@link ContactsContract.Data} entry. @@ -6213,6 +6207,18 @@ public final class ContactsContract { */ protected interface GroupsColumns { /** + * The data set within the account that this group belongs to. This allows + * multiple sync adapters for the same account type to distinguish between + * each others' group data. + * + * This is empty by default, and is completely optional. It only needs to + * be populated if multiple sync adapters are entering distinct group data + * for the same account type and account name. + * <P>Type: TEXT</P> + */ + public static final String DATA_SET = "data_set"; + + /** * The display title of this group. * <p> * Type: TEXT @@ -6338,6 +6344,29 @@ public final class ContactsContract { * In other words, it would be a really bad idea to delete and reinsert a * group. A sync adapter should always do an update instead.</td> * </tr> + # <tr> + * <td>String</td> + * <td>{@link #DATA_SET}</td> + * <td>read/write-once</td> + * <td> + * <p> + * The data set within the account that this group belongs to. This allows + * multiple sync adapters for the same account type to distinguish between + * each others' group data. The combination of {@link #ACCOUNT_TYPE}, + * {@link #ACCOUNT_NAME}, and {@link #DATA_SET} identifies a set of data + * that is associated with a single sync adapter. + * </p> + * <p> + * This is empty by default, and is completely optional. It only needs to + * be populated if multiple sync adapters are entering distinct data for + * the same account type and account name. + * </p> + * <p> + * It should be set at the time the group is inserted and never changed + * afterwards. + * </p> + * </td> + * </tr> * <tr> * <td>String</td> * <td>{@link #TITLE}</td> diff --git a/core/java/android/view/HardwareRenderer.java b/core/java/android/view/HardwareRenderer.java index 1638c74..011e44c 100644 --- a/core/java/android/view/HardwareRenderer.java +++ b/core/java/android/view/HardwareRenderer.java @@ -128,10 +128,19 @@ public abstract class HardwareRenderer { abstract void updateSurface(SurfaceHolder holder) throws Surface.OutOfResourcesException; /** - * Invoked whenever the size of the target surface changes. This will - * not be invoked when the surface is first created. + * This method should be invoked whenever the current hardware renderer + * context should be reset. */ - abstract void preapareSurfaceForResize(); + abstract void invalidate(); + + /** + * This method should be invoked to ensure the hardware renderer is in + * valid state (for instance, to ensure the correct EGL context is bound + * to the current thread.) + * + * @return true if the renderer is now valid, false otherwise + */ + abstract boolean validate(); /** * Setup the hardware renderer for drawing. This is called whenever the @@ -629,11 +638,16 @@ public abstract class HardwareRenderer { } @Override - void preapareSurfaceForResize() { + void invalidate() { // Cancels any existing buffer to ensure we'll get a buffer // of the right size before we call eglSwapBuffers sEgl.eglMakeCurrent(sEglDisplay, EGL10.EGL_NO_SURFACE, - EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT); + EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT); + } + + @Override + boolean validate() { + return checkCurrent() != SURFACE_STATE_ERROR; } @Override @@ -662,7 +676,7 @@ public abstract class HardwareRenderer { attachInfo.mDrawingTime = SystemClock.uptimeMillis(); view.mPrivateFlags |= View.DRAWN; - + final int surfaceState = checkCurrent(); if (surfaceState != SURFACE_STATE_ERROR) { // We had to change the current surface and/or context, redraw everything @@ -723,10 +737,21 @@ public abstract class HardwareRenderer { } } } - + + /** + * Ensures the currnet EGL context is the one we expect. + * + * @return {@link #SURFACE_STATE_ERROR} if the correct EGL context cannot be made current, + * {@link #SURFACE_STATE_UPDATED} if the EGL context was changed or + * {@link #SURFACE_STATE_SUCCESS} if the EGL context was the correct one + */ private int checkCurrent() { - // TODO: Don't check the current context when we have one per UI thread - // TODO: Use a threadlocal flag to know whether the surface has changed + if (sEglThread != Thread.currentThread()) { + throw new IllegalStateException("Hardware acceleration can only be used with a " + + "single UI thread.\nOriginal thread: " + sEglThread + "\n" + + "Current thread: " + Thread.currentThread()); + } + if (!sEglContext.equals(sEgl.eglGetCurrentContext()) || !mEglSurface.equals(sEgl.eglGetCurrentSurface(EGL10.EGL_DRAW))) { if (!sEgl.eglMakeCurrent(sEglDisplay, mEglSurface, mEglSurface, sEglContext)) { diff --git a/core/java/android/view/ViewAncestor.java b/core/java/android/view/ViewAncestor.java index b4f323c..1dcbc26 100644 --- a/core/java/android/view/ViewAncestor.java +++ b/core/java/android/view/ViewAncestor.java @@ -901,6 +901,7 @@ public final class ViewAncestor extends Handler implements ViewParent, !mAttachInfo.mTurnOffWindowResizeAnim && mAttachInfo.mHardwareRenderer != null && mAttachInfo.mHardwareRenderer.isEnabled() && + mAttachInfo.mHardwareRenderer.validate() && lp != null && !PixelFormat.formatHasAlpha(lp.format)) { disposeResizeBuffer(); @@ -1314,10 +1315,10 @@ public final class ViewAncestor extends Handler implements ViewParent, if (hwInitialized || ((windowShouldResize || params != null) && mAttachInfo.mHardwareRenderer != null && mAttachInfo.mHardwareRenderer.isEnabled())) { + mAttachInfo.mHardwareRenderer.setup(mWidth, mHeight); if (!hwInitialized) { - mAttachInfo.mHardwareRenderer.preapareSurfaceForResize(); + mAttachInfo.mHardwareRenderer.invalidate(); } - mAttachInfo.mHardwareRenderer.setup(mWidth, mHeight); } if (!mStopped) { diff --git a/core/java/android/webkit/L10nUtils.java b/core/java/android/webkit/L10nUtils.java index f9d0067d..a1c6a53 100644 --- a/core/java/android/webkit/L10nUtils.java +++ b/core/java/android/webkit/L10nUtils.java @@ -75,7 +75,18 @@ public class L10nUtils { com.android.internal.R.string.autofill_area_code_notext_re, // IDS_AUTOFILL_AREA_CODE_NOTEXT_RE com.android.internal.R.string.autofill_phone_prefix_separator_re, // IDS_AUTOFILL_PHONE_PREFIX_SEPARATOR_RE com.android.internal.R.string.autofill_phone_suffix_separator_re, // IDS_AUTOFILL_PHONE_SUFFIX_SEPARATOR_RE - com.android.internal.R.string.credit_card_number_preview_format // IDS_CREDIT_CARD_NUMBER_PREVIEW_FORMAT + com.android.internal.R.string.autofill_province, // IDS_AUTOFILL_DIALOG_PROVINCE + com.android.internal.R.string.autofill_postal_code, // IDS_AUTOFILL_DIALOG_POSTAL_CODE + com.android.internal.R.string.autofill_state, // IDS_AUTOFILL_DIALOG_STATE + com.android.internal.R.string.autofill_zip_code, // IDS_AUTOFILL_DIALOG_ZIP_CODE + com.android.internal.R.string.autofill_county, // IDS_AUTOFILL_DIALOG_COUNTY + com.android.internal.R.string.autofill_island, // IDS_AUTOFILL_DIALOG_ISLAND + com.android.internal.R.string.autofill_district, // IDS_AUTOFILL_DIALOG_DISTRICT + com.android.internal.R.string.autofill_department, // IDS_AUTOFILL_DIALOG_DEPARTMENT + com.android.internal.R.string.autofill_prefecture, // IDS_AUTOFILL_DIALOG_PREFECTURE + com.android.internal.R.string.autofill_parish, // IDS_AUTOFILL_DIALOG_PARISH + com.android.internal.R.string.autofill_area, // IDS_AUTOFILL_DIALOG_AREA + com.android.internal.R.string.autofill_emirate // IDS_AUTOFILL_DIALOG_EMIRATE }; private static Context mApplicationContext; diff --git a/core/java/android/webkit/ZoomManager.java b/core/java/android/webkit/ZoomManager.java index 7d3f313..49ea944 100644 --- a/core/java/android/webkit/ZoomManager.java +++ b/core/java/android/webkit/ZoomManager.java @@ -344,6 +344,8 @@ class ZoomManager { public final void setInitialScaleInPercent(int scaleInPercent) { mInitialScale = scaleInPercent * 0.01f; + mActualScale = mInitialScale > 0 ? mInitialScale : mDefaultScale; + mInvActualScale = 1 / mActualScale; } public final float computeScaleWithLimits(float scale) { diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index e350ec4..766b520 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -6212,6 +6212,15 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener int scrollx, scrolly; + // Convert to left, center, or right alignment. + if (a == Layout.Alignment.ALIGN_NORMAL) { + a = dir == Layout.DIR_LEFT_TO_RIGHT ? Layout.Alignment.ALIGN_LEFT : + Layout.Alignment.ALIGN_RIGHT; + } else if (a == Layout.Alignment.ALIGN_OPPOSITE){ + a = dir == Layout.DIR_LEFT_TO_RIGHT ? Layout.Alignment.ALIGN_RIGHT : + Layout.Alignment.ALIGN_LEFT; + } + if (a == Layout.Alignment.ALIGN_CENTER) { /* * Keep centered if possible, or, if it is too wide to fit, @@ -6230,28 +6239,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener scrollx = left; } } - } else if (a == Layout.Alignment.ALIGN_NORMAL) { - /* - * Keep leading edge in view. - */ - - if (dir < 0) { - int right = (int) FloatMath.ceil(mLayout.getLineRight(line)); - scrollx = right - hspace; - } else { - scrollx = (int) FloatMath.floor(mLayout.getLineLeft(line)); - } - } else /* a == Layout.Alignment.ALIGN_OPPOSITE */ { - /* - * Keep trailing edge in view. - */ - - if (dir < 0) { - scrollx = (int) FloatMath.floor(mLayout.getLineLeft(line)); - } else { - int right = (int) FloatMath.ceil(mLayout.getLineRight(line)); - scrollx = right - hspace; - } + } else if (a == Layout.Alignment.ALIGN_LEFT) { + scrollx = (int) FloatMath.floor(mLayout.getLineLeft(line)); + } else { // a == Layout.Alignment.ALIGN_RIGHT + int right = (int) FloatMath.ceil(mLayout.getLineRight(line)); + scrollx = right - hspace; } if (ht < vspace) { @@ -6293,20 +6285,24 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener int grav; switch (mLayout.getParagraphAlignment(line)) { - case ALIGN_NORMAL: + case ALIGN_LEFT: grav = 1; break; - - case ALIGN_OPPOSITE: + case ALIGN_RIGHT: grav = -1; break; - + case ALIGN_NORMAL: + grav = mLayout.getParagraphDirection(line); + break; + case ALIGN_OPPOSITE: + grav = -mLayout.getParagraphDirection(line); + break; + case ALIGN_CENTER: default: grav = 0; + break; } - grav *= mLayout.getParagraphDirection(line); - int hspace = mRight - mLeft - getCompoundPaddingLeft() - getCompoundPaddingRight(); int vspace = mBottom - mTop - getExtendedPaddingTop() - getExtendedPaddingBottom(); diff --git a/core/java/com/android/internal/os/PkgUsageStats.java b/core/java/com/android/internal/os/PkgUsageStats.java index 1ac191b..8c2c405 100755 --- a/core/java/com/android/internal/os/PkgUsageStats.java +++ b/core/java/com/android/internal/os/PkgUsageStats.java @@ -19,6 +19,9 @@ package com.android.internal.os; import android.os.Parcel; import android.os.Parcelable; +import java.util.HashMap; +import java.util.Map; + /** * implementation of PkgUsageStats associated with an * application package. @@ -28,6 +31,7 @@ public class PkgUsageStats implements Parcelable { public String packageName; public int launchCount; public long usageTime; + public Map<String, Long> componentResumeTimes; public static final Parcelable.Creator<PkgUsageStats> CREATOR = new Parcelable.Creator<PkgUsageStats>() { @@ -46,31 +50,45 @@ public class PkgUsageStats implements Parcelable { + " " + packageName + "}"; } - public PkgUsageStats(String pkgName, int count, long time) { + public PkgUsageStats(String pkgName, int count, long time, Map<String, Long> lastResumeTimes) { packageName = pkgName; launchCount = count; usageTime = time; + componentResumeTimes = new HashMap<String, Long>(lastResumeTimes); } public PkgUsageStats(Parcel source) { packageName = source.readString(); launchCount = source.readInt(); usageTime = source.readLong(); + final int N = source.readInt(); + componentResumeTimes = new HashMap<String, Long>(N); + for (int i = 0; i < N; i++) { + String component = source.readString(); + long lastResumeTime = source.readLong(); + componentResumeTimes.put(component, lastResumeTime); + } } public PkgUsageStats(PkgUsageStats pStats) { packageName = pStats.packageName; launchCount = pStats.launchCount; usageTime = pStats.usageTime; + componentResumeTimes = new HashMap<String, Long>(pStats.componentResumeTimes); } public int describeContents() { return 0; } - public void writeToParcel(Parcel dest, int parcelableFlags){ + public void writeToParcel(Parcel dest, int parcelableFlags) { dest.writeString(packageName); dest.writeInt(launchCount); dest.writeLong(usageTime); + dest.writeInt(componentResumeTimes.size()); + for (Map.Entry<String, Long> ent : componentResumeTimes.entrySet()) { + dest.writeString(ent.getKey()); + dest.writeLong(ent.getValue()); + } } } diff --git a/core/java/com/android/internal/view/menu/ActionMenuPresenter.java b/core/java/com/android/internal/view/menu/ActionMenuPresenter.java index b86eb13..9c06d69 100644 --- a/core/java/com/android/internal/view/menu/ActionMenuPresenter.java +++ b/core/java/com/android/internal/view/menu/ActionMenuPresenter.java @@ -20,7 +20,8 @@ import com.android.internal.view.menu.ActionMenuView.ActionMenuChildView; import android.content.Context; import android.content.res.Resources; -import android.util.Log; +import android.os.Parcel; +import android.os.Parcelable; import android.util.SparseBooleanArray; import android.view.MenuItem; import android.view.SoundEffectConstants; @@ -60,6 +61,9 @@ public class ActionMenuPresenter extends BaseMenuPresenter { private OpenOverflowRunnable mPostedOpenRunnable; + final PopupPresenterCallback mPopupPresenterCallback = new PopupPresenterCallback(); + int mOpenSubMenuId; + public ActionMenuPresenter() { super(com.android.internal.R.layout.action_menu_layout, com.android.internal.R.layout.action_menu_item_layout); @@ -196,8 +200,12 @@ public class ActionMenuPresenter extends BaseMenuPresenter { topSubMenu = (SubMenuBuilder) topSubMenu.getParentMenu(); } View anchor = findViewForItem(topSubMenu.getItem()); - if (anchor == null) return false; + if (anchor == null) { + if (mOverflowButton == null) return false; + anchor = mOverflowButton; + } + mOpenSubMenuId = subMenu.getItem().getItemId(); mActionButtonPopup = new ActionButtonSubmenu(mContext, subMenu); mActionButtonPopup.setAnchorView(anchor); mActionButtonPopup.show(); @@ -426,6 +434,57 @@ public class ActionMenuPresenter extends BaseMenuPresenter { super.onCloseMenu(menu, allMenusAreClosing); } + @Override + public Parcelable onSaveInstanceState() { + SavedState state = new SavedState(); + state.openSubMenuId = mOpenSubMenuId; + return state; + } + + @Override + public void onRestoreInstanceState(Parcelable state) { + SavedState saved = (SavedState) state; + if (saved.openSubMenuId > 0) { + MenuItem item = mMenu.findItem(saved.openSubMenuId); + if (item != null) { + SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu(); + onSubMenuSelected(subMenu); + } + } + } + + private static class SavedState implements Parcelable { + public int openSubMenuId; + + SavedState() { + } + + SavedState(Parcel in) { + openSubMenuId = in.readInt(); + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(openSubMenuId); + } + + public static final Parcelable.Creator<SavedState> CREATOR + = new Parcelable.Creator<SavedState>() { + public SavedState createFromParcel(Parcel in) { + return new SavedState(in); + } + + public SavedState[] newArray(int size) { + return new SavedState[size]; + } + }; + } + private class OverflowMenuButton extends ImageButton implements ActionMenuChildView { public OverflowMenuButton(Context context) { super(context, null, com.android.internal.R.attr.actionOverflowButtonStyle); @@ -460,6 +519,7 @@ public class ActionMenuPresenter extends BaseMenuPresenter { public OverflowPopup(Context context, MenuBuilder menu, View anchorView, boolean overflowOnly) { super(context, menu, anchorView, overflowOnly); + setCallback(mPopupPresenterCallback); } @Override @@ -482,6 +542,8 @@ public class ActionMenuPresenter extends BaseMenuPresenter { // Give a reasonable anchor to nested submenus. setAnchorView(mOverflowButton == null ? (View) mMenuView : mOverflowButton); } + + setCallback(mPopupPresenterCallback); } @Override @@ -489,6 +551,20 @@ public class ActionMenuPresenter extends BaseMenuPresenter { super.onDismiss(); mSubMenu.close(); mActionButtonPopup = null; + mOpenSubMenuId = 0; + } + } + + private class PopupPresenterCallback implements MenuPresenter.Callback { + + @Override + public boolean onOpenSubMenu(MenuBuilder subMenu) { + mOpenSubMenuId = ((SubMenuBuilder) subMenu).getItem().getItemId(); + return false; + } + + @Override + public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) { } } diff --git a/core/java/com/android/internal/view/menu/BaseMenuPresenter.java b/core/java/com/android/internal/view/menu/BaseMenuPresenter.java index ddbb08c..ed9d34a 100644 --- a/core/java/com/android/internal/view/menu/BaseMenuPresenter.java +++ b/core/java/com/android/internal/view/menu/BaseMenuPresenter.java @@ -39,6 +39,8 @@ public abstract class BaseMenuPresenter implements MenuPresenter { protected MenuView mMenuView; + private int mId; + /** * Construct a new BaseMenuPresenter. * @@ -200,4 +202,12 @@ public abstract class BaseMenuPresenter implements MenuPresenter { public boolean collapseItemActionView(MenuBuilder menu, MenuItemImpl item) { return false; } + + public int getId() { + return mId; + } + + public void setId(int id) { + mId = id; + } } diff --git a/core/java/com/android/internal/view/menu/IconMenuPresenter.java b/core/java/com/android/internal/view/menu/IconMenuPresenter.java index f717904..56128d4 100644 --- a/core/java/com/android/internal/view/menu/IconMenuPresenter.java +++ b/core/java/com/android/internal/view/menu/IconMenuPresenter.java @@ -23,6 +23,7 @@ import android.os.Parcelable; import android.util.SparseArray; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -35,7 +36,12 @@ public class IconMenuPresenter extends BaseMenuPresenter { private IconMenuItemView mMoreView; private int mMaxItems = -1; + int mOpenSubMenuId; + SubMenuPresenterCallback mSubMenuPresenterCallback = new SubMenuPresenterCallback(); + MenuDialogHelper mOpenSubMenu; + private static final String VIEWS_TAG = "android:menu:icon"; + private static final String OPEN_SUBMENU_KEY = "android:menu:icon:submenu"; public IconMenuPresenter() { super(com.android.internal.R.layout.icon_menu_layout, @@ -86,7 +92,11 @@ public class IconMenuPresenter extends BaseMenuPresenter { if (!subMenu.hasVisibleItems()) return false; // The window manager will give us a token. - new MenuDialogHelper(subMenu).show(null); + MenuDialogHelper helper = new MenuDialogHelper(subMenu); + helper.setPresenterCallback(mSubMenuPresenterCallback); + helper.show(null); + mOpenSubMenu = helper; + mOpenSubMenuId = subMenu.getItem().getItemId(); super.onSubMenuSelected(subMenu); return true; } @@ -137,5 +147,47 @@ public class IconMenuPresenter extends BaseMenuPresenter { if (viewStates != null) { ((View) mMenuView).restoreHierarchyState(viewStates); } + int subMenuId = inState.getInt(OPEN_SUBMENU_KEY, 0); + if (subMenuId > 0 && mMenu != null) { + MenuItem item = mMenu.findItem(subMenuId); + if (item != null) { + onSubMenuSelected((SubMenuBuilder) item.getSubMenu()); + } + } + } + + @Override + public Parcelable onSaveInstanceState() { + if (mMenuView == null) { + return null; + } + + Bundle state = new Bundle(); + saveHierarchyState(state); + if (mOpenSubMenuId > 0) { + state.putInt(OPEN_SUBMENU_KEY, mOpenSubMenuId); + } + return state; + } + + @Override + public void onRestoreInstanceState(Parcelable state) { + restoreHierarchyState((Bundle) state); + } + + class SubMenuPresenterCallback implements MenuPresenter.Callback { + @Override + public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) { + mOpenSubMenuId = 0; + mOpenSubMenu.dismiss(); + mOpenSubMenu = null; + } + + @Override + public boolean onOpenSubMenu(MenuBuilder subMenu) { + mOpenSubMenuId = ((SubMenuBuilder) subMenu).getItem().getItemId(); + return false; + } + } } diff --git a/core/java/com/android/internal/view/menu/ListMenuPresenter.java b/core/java/com/android/internal/view/menu/ListMenuPresenter.java index 27e4191..146c7ac 100644 --- a/core/java/com/android/internal/view/menu/ListMenuPresenter.java +++ b/core/java/com/android/internal/view/menu/ListMenuPresenter.java @@ -47,6 +47,8 @@ public class ListMenuPresenter implements MenuPresenter, AdapterView.OnItemClick private Callback mCallback; private MenuAdapter mAdapter; + private int mId; + public static final String VIEWS_TAG = "android:menu:list"; /** @@ -182,6 +184,31 @@ public class ListMenuPresenter implements MenuPresenter, AdapterView.OnItemClick } } + public void setId(int id) { + mId = id; + } + + @Override + public int getId() { + return mId; + } + + @Override + public Parcelable onSaveInstanceState() { + if (mMenuView == null) { + return null; + } + + Bundle state = new Bundle(); + saveHierarchyState(state); + return state; + } + + @Override + public void onRestoreInstanceState(Parcelable state) { + restoreHierarchyState((Bundle) state); + } + private class MenuAdapter extends BaseAdapter { public int getCount() { ArrayList<MenuItemImpl> items = mMenu.getNonActionItems(); diff --git a/core/java/com/android/internal/view/menu/MenuBuilder.java b/core/java/com/android/internal/view/menu/MenuBuilder.java index fdfa954..a4edbc5 100644 --- a/core/java/com/android/internal/view/menu/MenuBuilder.java +++ b/core/java/com/android/internal/view/menu/MenuBuilder.java @@ -25,8 +25,8 @@ import android.content.pm.ResolveInfo; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.drawable.Drawable; +import android.os.Bundle; import android.os.Parcelable; -import android.util.Log; import android.util.SparseArray; import android.view.ContextMenu.ContextMenuInfo; import android.view.KeyCharacterMap; @@ -38,7 +38,6 @@ import android.view.View; import java.lang.ref.WeakReference; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; @@ -49,6 +48,8 @@ import java.util.concurrent.CopyOnWriteArrayList; public class MenuBuilder implements Menu { private static final String LOGTAG = "MenuBuilder"; + private static final String PRESENTER_KEY = "android:menu:presenters"; + private static final int[] sCategoryToOrder = new int[] { 1, /* No category */ 4, /* CONTAINER */ @@ -254,6 +255,58 @@ public class MenuBuilder implements Menu { return result; } + private void dispatchSaveInstanceState(Bundle outState) { + if (mPresenters.isEmpty()) return; + + SparseArray<Parcelable> presenterStates = new SparseArray<Parcelable>(); + + for (WeakReference<MenuPresenter> ref : mPresenters) { + final MenuPresenter presenter = ref.get(); + if (presenter == null) { + mPresenters.remove(ref); + } else { + final int id = presenter.getId(); + if (id > 0) { + final Parcelable state = presenter.onSaveInstanceState(); + if (state != null) { + presenterStates.put(id, state); + } + } + } + } + + outState.putSparseParcelableArray(PRESENTER_KEY, presenterStates); + } + + private void dispatchRestoreInstanceState(Bundle state) { + SparseArray<Parcelable> presenterStates = state.getSparseParcelableArray(PRESENTER_KEY); + + if (presenterStates == null || mPresenters.isEmpty()) return; + + for (WeakReference<MenuPresenter> ref : mPresenters) { + final MenuPresenter presenter = ref.get(); + if (presenter == null) { + mPresenters.remove(ref); + } else { + final int id = presenter.getId(); + if (id > 0) { + Parcelable parcel = presenterStates.get(id); + if (parcel != null) { + presenter.onRestoreInstanceState(parcel); + } + } + } + } + } + + public void savePresenterStates(Bundle outState) { + dispatchSaveInstanceState(outState); + } + + public void restorePresenterStates(Bundle state) { + dispatchRestoreInstanceState(state); + } + public void setCallback(Callback cb) { mCallback = cb; } diff --git a/core/java/com/android/internal/view/menu/MenuPopupHelper.java b/core/java/com/android/internal/view/menu/MenuPopupHelper.java index cffbb4e..4ecc828 100644 --- a/core/java/com/android/internal/view/menu/MenuPopupHelper.java +++ b/core/java/com/android/internal/view/menu/MenuPopupHelper.java @@ -18,6 +18,7 @@ package com.android.internal.view.menu; import android.content.Context; import android.content.res.Resources; +import android.os.Parcelable; import android.util.DisplayMetrics; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -296,4 +297,18 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On return convertView; } } + + @Override + public int getId() { + return 0; + } + + @Override + public Parcelable onSaveInstanceState() { + return null; + } + + @Override + public void onRestoreInstanceState(Parcelable state) { + } } diff --git a/core/java/com/android/internal/view/menu/MenuPresenter.java b/core/java/com/android/internal/view/menu/MenuPresenter.java index bd66448..d913a39 100644 --- a/core/java/com/android/internal/view/menu/MenuPresenter.java +++ b/core/java/com/android/internal/view/menu/MenuPresenter.java @@ -17,6 +17,7 @@ package com.android.internal.view.menu; import android.content.Context; +import android.os.Parcelable; import android.view.Menu; import android.view.ViewGroup; @@ -125,4 +126,24 @@ public interface MenuPresenter { * @return true if this presenter collapsed the action view, false otherwise. */ public boolean collapseItemActionView(MenuBuilder menu, MenuItemImpl item); + + /** + * Returns an ID for determining how to save/restore instance state. + * @return a valid ID value. + */ + public int getId(); + + /** + * Returns a Parcelable describing the current state of the presenter. + * It will be passed to the {@link #onRestoreInstanceState(Parcelable)} + * method of the presenter sharing the same ID later. + * @return The saved instance state + */ + public Parcelable onSaveInstanceState(); + + /** + * Supplies the previously saved instance state to be restored. + * @param state The previously saved instance state + */ + public void onRestoreInstanceState(Parcelable state); } diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java index 09bc1fc..595753a 100644 --- a/core/java/com/android/internal/widget/ActionBarView.java +++ b/core/java/com/android/internal/widget/ActionBarView.java @@ -337,6 +337,7 @@ public class ActionBarView extends AbsActionBarView { if (mActionMenuPresenter == null) { mActionMenuPresenter = new ActionMenuPresenter(); mActionMenuPresenter.setCallback(cb); + mActionMenuPresenter.setId(com.android.internal.R.id.action_menu_presenter); mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter(); } @@ -1301,5 +1302,19 @@ public class ActionBarView extends AbsActionBarView { item.setActionViewExpanded(false); return true; } + + @Override + public int getId() { + return 0; + } + + @Override + public Parcelable onSaveInstanceState() { + return null; + } + + @Override + public void onRestoreInstanceState(Parcelable state) { + } } } diff --git a/core/res/res/values/ids.xml b/core/res/res/values/ids.xml index d05685c..547a192 100644 --- a/core/res/res/values/ids.xml +++ b/core/res/res/values/ids.xml @@ -74,4 +74,9 @@ <item type="id" name="rowTypeId" /> <item type="id" name="up" /> <item type="id" name="action_menu_divider" /> + <item type="id" name="icon_menu_presenter" /> + <item type="id" name="list_menu_presenter" /> + <item type="id" name="action_menu_presenter" /> + <item type="id" name="overflow_menu_presenter" /> + <item type="id" name="popup_submenu_presenter" /> </resources> diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 97a8c0b..70c204e 100755 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -2038,13 +2038,13 @@ <string name="autofill_phone_re">phone<!-- de-DE -->|telefonnummer<!-- es -->|telefono|teléfono<!-- fr-FR -->|telfixe<!-- ja-JP -->|電話<!-- pt-BR, pt-PT -->|telefone|telemovel<!-- ru -->|телефон<!-- zh-CN -->|电话</string> <!-- Do not translate. Regex used by AutoFill. --> - <string name="autofill_area_code_re">area code</string> + <string name="autofill_area_code_re">area.*code|acode|area</string> <!-- Do not translate. Regex used by AutoFill. --> - <string name="autofill_phone_prefix_re">^-$|\\)$|prefix<!-- fr-FR -->|preselection<!-- pt-BR, pt-PT -->|ddd</string> + <string name="autofill_phone_prefix_re">prefix<!-- fr-FR -->|preselection<!-- pt-BR, pt-PT -->|ddd</string> <!-- Do not translate. Regex used by AutoFill. --> - <string name="autofill_phone_suffix_re">^-$|suffix</string> + <string name="autofill_phone_suffix_re">suffix</string> <!-- Do not translate. Regex used by AutoFill. --> <string name="autofill_phone_extension_re">ext<!-- pt-BR, pt-PT -->|ramal</string> @@ -2077,17 +2077,49 @@ <string name="autofill_country_code_re">country.*code|ccode|_cc</string> <!-- Do not translate. Regex used by AutoFill. --> - <string name="autofill_area_code_notext_re">^\($</string> + <string name="autofill_area_code_notext_re">^\\($</string> <!-- Do not translate. Regex used by AutoFill. --> - <string name="autofill_phone_prefix_separator_re">^-$|^\)$</string> + <string name="autofill_phone_prefix_separator_re">^-$|^\\)$</string> <!-- Do not translate. Regex used by AutoFill. --> <string name="autofill_phone_suffix_separator_re">^-$</string> - <!-- Do not translate. Regex used by AutoFill. --> - <!-- Ex: ************1234 --> - <string name="credit_card_number_preview_format">$1</string> + <!-- Label in a web form for "Province" [CHAR-LIMIT=NONE] --> + <string name="autofill_province">Province</string> + + <!-- Label in a web form for "Postal code" [CHAR-LIMIT=NONE] --> + <string name="autofill_postal_code">Postal code</string> + + <!-- Label in a web form for "State" [CHAR-LIMIT=NONE] --> + <string name="autofill_state">State</string> + + <!-- Label in a web form for "ZIP code" [CHAR-LIMIT=NONE] --> + <string name="autofill_zip_code">ZIP code</string> + + <!-- Label in a web form for "County" [CHAR-LIMIT=NONE] --> + <string name="autofill_county">County</string> + + <!-- Label in a web form for "Island" [CHAR-LIMIT=NONE] --> + <string name="autofill_island">Island</string> + + <!-- Label in a web form for "District" [CHAR-LIMIT=NONE] --> + <string name="autofill_district">District</string> + + <!-- Label in a web form for "Department" [CHAR-LIMIT=NONE] --> + <string name="autofill_department">Department</string> + + <!-- Label in a web form for "Prefecture" [CHAR-LIMIT=NONE] --> + <string name="autofill_prefecture">Prefecture</string> + + <!-- Label in a web form for "Parish" [CHAR-LIMIT=NONE] --> + <string name="autofill_parish">Parish</string> + + <!-- Label in a web form for "Area" [CHAR-LIMIT=NONE] --> + <string name="autofill_area">Area</string> + + <!-- Label in a web form for "Emirate" [CHAR-LIMIT=NONE] --> + <string name="autofill_emirate">Emirate</string> <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. --> diff --git a/core/tests/coretests/Android.mk b/core/tests/coretests/Android.mk index 00f47fa..b2ebb08 100644 --- a/core/tests/coretests/Android.mk +++ b/core/tests/coretests/Android.mk @@ -12,7 +12,7 @@ LOCAL_SRC_FILES := \ $(call all-java-files-under, EnabledTestApp/src) LOCAL_DX_FLAGS := --core-library -LOCAL_STATIC_JAVA_LIBRARIES := core-tests android-common frameworks-core-util-lib mockwebserver +LOCAL_STATIC_JAVA_LIBRARIES := core-tests android-common frameworks-core-util-lib mockwebserver guava LOCAL_JAVA_LIBRARIES := android.test.runner LOCAL_PACKAGE_NAME := FrameworksCoreTests diff --git a/core/tests/coretests/AndroidManifest.xml b/core/tests/coretests/AndroidManifest.xml index 40fa552..146466f 100644 --- a/core/tests/coretests/AndroidManifest.xml +++ b/core/tests/coretests/AndroidManifest.xml @@ -1242,6 +1242,13 @@ </intent-filter> </activity> + <activity android:name="android.animation.BasicAnimatorActivity"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" /> + </intent-filter> + </activity> + </application> <instrumentation android:name="android.test.InstrumentationTestRunner" diff --git a/core/tests/coretests/res/layout/animator_basic.xml b/core/tests/coretests/res/layout/animator_basic.xml new file mode 100644 index 0000000..7b8ef11 --- /dev/null +++ b/core/tests/coretests/res/layout/animator_basic.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8"?> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:orientation="vertical"> + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/animatingButton"/> +</LinearLayout>
\ No newline at end of file diff --git a/core/tests/coretests/src/android/animation/AnimatorSetEventsTest.java b/core/tests/coretests/src/android/animation/AnimatorSetEventsTest.java new file mode 100644 index 0000000..65f2b8e --- /dev/null +++ b/core/tests/coretests/src/android/animation/AnimatorSetEventsTest.java @@ -0,0 +1,39 @@ +/* +* Copyright (C) 2011 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.animation; + +import android.widget.Button; +import com.android.frameworks.coretests.R; + +/** + * Listener tests for AnimatorSet. + */ +public class AnimatorSetEventsTest extends EventsTest { + + @Override + public void setUp() throws Exception { + final BasicAnimatorActivity activity = getActivity(); + Button button = (Button) activity.findViewById(R.id.animatingButton); + + ObjectAnimator xAnim = ObjectAnimator.ofFloat(button, "translationX", 0, 100); + ObjectAnimator yAnim = ObjectAnimator.ofFloat(button, "translationX", 0, 100); + mAnimator = new AnimatorSet(); + ((AnimatorSet)mAnimator).playSequentially(xAnim, yAnim); + + super.setUp(); + } + +} diff --git a/core/tests/coretests/src/android/animation/BasicAnimatorActivity.java b/core/tests/coretests/src/android/animation/BasicAnimatorActivity.java new file mode 100644 index 0000000..93808d9 --- /dev/null +++ b/core/tests/coretests/src/android/animation/BasicAnimatorActivity.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2011 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.animation; + +import com.android.frameworks.coretests.R; + +import android.app.Activity; +import android.os.Bundle; + +public class BasicAnimatorActivity extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.animator_basic); + } +} diff --git a/core/tests/coretests/src/android/animation/EventsTest.java b/core/tests/coretests/src/android/animation/EventsTest.java new file mode 100644 index 0000000..f970ffc --- /dev/null +++ b/core/tests/coretests/src/android/animation/EventsTest.java @@ -0,0 +1,265 @@ +/* + * Copyright (C) 2011 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.animation; + +import android.os.Handler; +import android.test.ActivityInstrumentationTestCase2; +import android.test.UiThreadTest; +import android.test.suitebuilder.annotation.MediumTest; +import android.test.suitebuilder.annotation.SmallTest; + +/** + * Tests for the various lifecycle events of Animators. This abstract class is subclassed by + * concrete implementations that provide the actual Animator objects being tested. All of the + * testing mechanisms are in this class; the subclasses are only responsible for providing + * the mAnimator object. + * + * This test is more complicated than a typical synchronous test because much of the functionality + * must happen on the UI thread. Some tests do this by using the UiThreadTest annotation to + * automatically run the whole test on that thread. Other tests must run on the UI thread and also + * wait for some later event to occur before ending. These tests use a combination of an + * AbstractFuture mechanism and a delayed action to release that Future later. + */ +public abstract class EventsTest + extends ActivityInstrumentationTestCase2<BasicAnimatorActivity> { + + private static final int ANIM_DURATION = 400; + private static final int ANIM_DELAY = 100; + private static final int ANIM_MID_DURATION = ANIM_DURATION / 2; + private static final int ANIM_MID_DELAY = ANIM_DELAY / 2; + + private boolean mRunning; // tracks whether we've started the animator + private boolean mCanceled; // trackes whether we've canceled the animator + private Animator.AnimatorListener mFutureListener; // mechanism for delaying the end of the test + private FutureWaiter mFuture; // Mechanism for waiting for the UI test to complete + private Animator.AnimatorListener mListener; // Listener that handles/tests the events + + protected Animator mAnimator; // The animator used in the tests. Must be set in subclass + // setup() method prior to calling the superclass setup() + + /** + * Cancels the given animator. Used to delay cancelation until some later time (after the + * animator has started playing). + */ + static class Canceler implements Runnable { + Animator mAnim; + public Canceler(Animator anim) { + mAnim = anim; + } + @Override + public void run() { + mAnim.cancel(); + } + }; + + /** + * Releases the given Future object when the listener's end() event is called. Specifically, + * it releases it after some further delay, to give the test time to do other things right + * after an animation ends. + */ + static class FutureReleaseListener extends AnimatorListenerAdapter { + FutureWaiter mFuture; + + public FutureReleaseListener(FutureWaiter future) { + mFuture = future; + } + @Override + public void onAnimationEnd(Animator animation) { + Handler handler = new Handler(); + handler.postDelayed(new Runnable() { + @Override + public void run() { + mFuture.release(); + } + }, ANIM_MID_DURATION); + } + }; + + public EventsTest() { + super(BasicAnimatorActivity.class); + } + + + /** + * Sets up the fields used by each test. Subclasses must override this method to create + * the protected mAnimator object used in all tests. Overrides must create that animator + * and then call super.setup(), where further properties are set on that animator. + * @throws Exception + */ + @Override + public void setUp() throws Exception { + super.setUp(); + + // mListener is the main testing mechanism of this file. The asserts of each test + // are embedded in the listener callbacks that it implements. + mListener = new AnimatorListenerAdapter() { + @Override + public void onAnimationCancel(Animator animation) { + // This should only be called on an animation that has been started and not + // yet canceled or ended + assertFalse(mCanceled); + assertTrue(mRunning); + mCanceled = true; + } + + @Override + public void onAnimationEnd(Animator animation) { + // This should only be called on an animation that has been started and not + // yet ended + assertTrue(mRunning); + mRunning = false; + super.onAnimationEnd(animation); + } + }; + + mAnimator.addListener(mListener); + mAnimator.setDuration(ANIM_DURATION); + + mFuture = new FutureWaiter(); + + mRunning = false; + mCanceled = false; + } + + /** + * Verify that calling cancel on an unstarted animator does nothing. + */ + @UiThreadTest + @SmallTest + public void testCancel() throws Exception { + mAnimator.cancel(); + } + + /** + * Verify that calling cancel on a started animator does the right thing. + */ + @UiThreadTest + @SmallTest + public void testStartCancel() throws Exception { + mRunning = true; + mAnimator.start(); + mAnimator.cancel(); + } + + /** + * Same as testStartCancel, but with a startDelayed animator + */ + @UiThreadTest + @SmallTest + public void testStartDelayedCancel() throws Exception { + mAnimator.setStartDelay(ANIM_DELAY); + mRunning = true; + mAnimator.start(); + mAnimator.cancel(); + } + + /** + * Verify that canceling an animator that is playing does the right thing. + */ + @MediumTest + public void testPlayingCancel() throws Exception { + mFutureListener = new FutureReleaseListener(mFuture); + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + try { + Handler handler = new Handler(); + mAnimator.addListener(mFutureListener); + mRunning = true; + mAnimator.start(); + handler.postDelayed(new Canceler(mAnimator), ANIM_MID_DURATION); + } catch (junit.framework.AssertionFailedError e) { + mFuture.setException(new RuntimeException(e)); + } + } + }); + mFuture.get(); + } + + /** + * Same as testPlayingCancel, but with a startDelayed animator + */ + @MediumTest + public void testPlayingDelayedCancel() throws Exception { + mAnimator.setStartDelay(ANIM_DELAY); + mFutureListener = new FutureReleaseListener(mFuture); + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + try { + Handler handler = new Handler(); + mAnimator.addListener(mFutureListener); + mRunning = true; + mAnimator.start(); + handler.postDelayed(new Canceler(mAnimator), ANIM_MID_DURATION); + } catch (junit.framework.AssertionFailedError e) { + mFuture.setException(new RuntimeException(e)); + } + } + }); + mFuture.get(); + } + + /** + * Verifies that canceling a started animation after it has already been canceled + * does nothing. + */ + @MediumTest + public void testStartDoubleCancel() throws Exception { + mFutureListener = new FutureReleaseListener(mFuture); + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + try { + mRunning = true; + mAnimator.start(); + mAnimator.cancel(); + mAnimator.cancel(); + mFuture.release(); + } catch (junit.framework.AssertionFailedError e) { + mFuture.setException(new RuntimeException(e)); + } + } + }); + mFuture.get(); + } + + /** + * Same as testStartDoubleCancel, but with a startDelayed animator + */ + @MediumTest + public void testStartDelayedDoubleCancel() throws Exception { + mAnimator.setStartDelay(ANIM_DELAY); + mFutureListener = new FutureReleaseListener(mFuture); + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + try { + mRunning = true; + mAnimator.start(); + mAnimator.cancel(); + mAnimator.cancel(); + mFuture.release(); + } catch (junit.framework.AssertionFailedError e) { + mFuture.setException(new RuntimeException(e)); + } + } + }); + mFuture.get(); + } + + +} diff --git a/core/tests/coretests/src/android/animation/FutureWaiter.java b/core/tests/coretests/src/android/animation/FutureWaiter.java new file mode 100644 index 0000000..320a1c2 --- /dev/null +++ b/core/tests/coretests/src/android/animation/FutureWaiter.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2011 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.animation; + +import com.google.common.util.concurrent.AbstractFuture; + +/** + * Simple extension of {@link com.google.common.util.concurrent.AbstractFuture} which exposes a new + * release() method which calls the protected + * {@link com.google.common.util.concurrent.AbstractFuture#set(Object)} method internally. It + * also exposes the protected {@link AbstractFuture#setException(Throwable)} method. + */ +public class FutureWaiter extends AbstractFuture<Void> { + + /** + * Release the Future currently waiting on + * {@link com.google.common.util.concurrent.AbstractFuture#get()}. + */ + public void release() { + super.set(null); + } + + @Override + public boolean setException(Throwable throwable) { + return super.setException(throwable); + } +} diff --git a/core/tests/coretests/src/android/animation/ObjectAnimatorEventsTest.java b/core/tests/coretests/src/android/animation/ObjectAnimatorEventsTest.java new file mode 100644 index 0000000..606a939 --- /dev/null +++ b/core/tests/coretests/src/android/animation/ObjectAnimatorEventsTest.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2011 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.animation; + +import android.widget.Button; +import com.android.frameworks.coretests.R; + +/** + * Listener tests for ObjectAnimator. + */ +public class ObjectAnimatorEventsTest extends EventsTest { + + @Override + public void setUp() throws Exception { + final BasicAnimatorActivity activity = getActivity(); + Button button = (Button) activity.findViewById(R.id.animatingButton); + + mAnimator = ObjectAnimator.ofFloat(button, "translationX", 0, 100); + super.setUp(); + } + +} diff --git a/core/tests/coretests/src/android/animation/ValueAnimatorEventsTest.java b/core/tests/coretests/src/android/animation/ValueAnimatorEventsTest.java new file mode 100644 index 0000000..c25d050 --- /dev/null +++ b/core/tests/coretests/src/android/animation/ValueAnimatorEventsTest.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2011 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.animation; + +/** + * Listener tests for ValueAnimator. + */ +public class ValueAnimatorEventsTest extends EventsTest { + + @Override + public void setUp() throws Exception { + mAnimator = ValueAnimator.ofFloat(0, 1); + super.setUp(); + } + +} diff --git a/core/tests/coretests/src/android/net/NetworkStatsTest.java b/core/tests/coretests/src/android/net/NetworkStatsTest.java index 3cb64c7..82345e2 100644 --- a/core/tests/coretests/src/android/net/NetworkStatsTest.java +++ b/core/tests/coretests/src/android/net/NetworkStatsTest.java @@ -44,20 +44,20 @@ public class NetworkStatsTest extends TestCase { public void testAddEntryGrow() throws Exception { final NetworkStats stats = new NetworkStats(TEST_START, 2); - assertEquals(0, stats.size); + assertEquals(0, stats.size()); assertEquals(2, stats.iface.length); stats.addEntry(TEST_IFACE, TEST_UID, TAG_NONE, 1L, 2L); stats.addEntry(TEST_IFACE, TEST_UID, TAG_NONE, 2L, 2L); - assertEquals(2, stats.size); + assertEquals(2, stats.size()); assertEquals(2, stats.iface.length); stats.addEntry(TEST_IFACE, TEST_UID, TAG_NONE, 3L, 4L); stats.addEntry(TEST_IFACE, TEST_UID, TAG_NONE, 4L, 4L); stats.addEntry(TEST_IFACE, TEST_UID, TAG_NONE, 5L, 5L); - assertEquals(5, stats.size); + assertEquals(5, stats.size()); assertTrue(stats.iface.length >= 5); assertEquals(1L, stats.rx[0]); diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index 6254192..12e5ada 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -155,6 +155,14 @@ public class Allocation extends BaseObj { } } + + private int getIDSafe() { + if (mAdaptedAllocation != null) { + return mAdaptedAllocation.getID(); + } + return getID(); + } + private void updateCacheInfo(Type t) { mCurrentDimX = t.getX(); mCurrentDimY = t.getY(); @@ -262,7 +270,7 @@ public class Allocation extends BaseObj { throw new RSIllegalArgumentException("Source must be exactly one usage type."); } mRS.validate(); - mRS.nAllocationSyncAll(getID(), srcLocation); + mRS.nAllocationSyncAll(getIDSafe(), srcLocation); } public void copyFrom(BaseObj[] d) { @@ -480,7 +488,7 @@ public class Allocation extends BaseObj { " does not match component size " + eSize + "."); } - mRS.nAllocationElementData1D(getID(), xoff, mSelectedLOD, + mRS.nAllocationElementData1D(getIDSafe(), xoff, mSelectedLOD, component_number, data, data.length); } @@ -527,7 +535,7 @@ public class Allocation extends BaseObj { public void copy1DRangeFromUnchecked(int off, int count, int[] d) { int dataSize = mType.mElement.getSizeBytes() * count; data1DChecks(off, count, d.length * 4, dataSize); - mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize); + mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize); } /** * Copy part of an allocation from an array. This variant is @@ -541,7 +549,7 @@ public class Allocation extends BaseObj { public void copy1DRangeFromUnchecked(int off, int count, short[] d) { int dataSize = mType.mElement.getSizeBytes() * count; data1DChecks(off, count, d.length * 2, dataSize); - mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize); + mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize); } /** * Copy part of an allocation from an array. This variant is @@ -555,7 +563,7 @@ public class Allocation extends BaseObj { public void copy1DRangeFromUnchecked(int off, int count, byte[] d) { int dataSize = mType.mElement.getSizeBytes() * count; data1DChecks(off, count, d.length, dataSize); - mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize); + mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize); } /** * Copy part of an allocation from an array. This variant is @@ -569,7 +577,7 @@ public class Allocation extends BaseObj { public void copy1DRangeFromUnchecked(int off, int count, float[] d) { int dataSize = mType.mElement.getSizeBytes() * count; data1DChecks(off, count, d.length * 4, dataSize); - mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize); + mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize); } /** @@ -638,7 +646,7 @@ public class Allocation extends BaseObj { * be copied. */ public void copy1DRangeFrom(int off, int count, Allocation data, int dataOff) { - mRS.nAllocationData2D(getID(), off, 0, + mRS.nAllocationData2D(getIDSafe(), off, 0, mSelectedLOD, mSelectedFace.mID, count, 1, data.getID(), dataOff, 0, data.mSelectedLOD, data.mSelectedFace.mID); @@ -674,28 +682,28 @@ public class Allocation extends BaseObj { public void copy2DRangeFrom(int xoff, int yoff, int w, int h, byte[] data) { mRS.validate(); validate2DRange(xoff, yoff, w, h); - mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, + mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, data, data.length); } public void copy2DRangeFrom(int xoff, int yoff, int w, int h, short[] data) { mRS.validate(); validate2DRange(xoff, yoff, w, h); - mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, + mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, data, data.length * 2); } public void copy2DRangeFrom(int xoff, int yoff, int w, int h, int[] data) { mRS.validate(); validate2DRange(xoff, yoff, w, h); - mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, + mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, data, data.length * 4); } public void copy2DRangeFrom(int xoff, int yoff, int w, int h, float[] data) { mRS.validate(); validate2DRange(xoff, yoff, w, h); - mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, + mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, data, data.length * 4); } @@ -715,7 +723,7 @@ public class Allocation extends BaseObj { Allocation data, int dataXoff, int dataYoff) { mRS.validate(); validate2DRange(xoff, yoff, w, h); - mRS.nAllocationData2D(getID(), xoff, yoff, + mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, data.getID(), dataXoff, dataYoff, data.mSelectedLOD, data.mSelectedFace.mID); @@ -734,10 +742,16 @@ public class Allocation extends BaseObj { mRS.validate(); validateBitmapFormat(data); validate2DRange(xoff, yoff, data.getWidth(), data.getHeight()); - mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, data); + mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, data); } + /** + * Copy from the Allocation into a Bitmap. The bitmap must + * match the dimensions of the Allocation. + * + * @param b The bitmap to be set from the Allocation. + */ public void copyTo(Bitmap b) { mRS.validate(); validateBitmapFormat(b); @@ -745,24 +759,52 @@ public class Allocation extends BaseObj { mRS.nAllocationCopyToBitmap(getID(), b); } + /** + * Copy from the Allocation into a byte array. The array must + * be at least as large as the Allocation. The allocation must + * be of an 8 bit elemental type. + * + * @param d The array to be set from the Allocation. + */ public void copyTo(byte[] d) { validateIsInt8(); mRS.validate(); mRS.nAllocationRead(getID(), d); } + /** + * Copy from the Allocation into a short array. The array must + * be at least as large as the Allocation. The allocation must + * be of an 16 bit elemental type. + * + * @param d The array to be set from the Allocation. + */ public void copyTo(short[] d) { validateIsInt16(); mRS.validate(); mRS.nAllocationRead(getID(), d); } + /** + * Copy from the Allocation into a int array. The array must be + * at least as large as the Allocation. The allocation must be + * of an 32 bit elemental type. + * + * @param d The array to be set from the Allocation. + */ public void copyTo(int[] d) { validateIsInt32(); mRS.validate(); mRS.nAllocationRead(getID(), d); } + /** + * Copy from the Allocation into a float array. The array must + * be at least as large as the Allocation. The allocation must + * be of an 32 bit float elemental type. + * + * @param d The array to be set from the Allocation. + */ public void copyTo(float[] d) { validateIsFloat32(); mRS.validate(); diff --git a/graphics/java/android/renderscript/AllocationAdapter.java b/graphics/java/android/renderscript/AllocationAdapter.java index ca5246a..d38f2df 100644 --- a/graphics/java/android/renderscript/AllocationAdapter.java +++ b/graphics/java/android/renderscript/AllocationAdapter.java @@ -31,7 +31,8 @@ public class AllocationAdapter extends Allocation { } int getID() { - return mAdaptedAllocation.getID(); + throw new RSInvalidStateException( + "This operation is not supported with adapters at this time."); } /** diff --git a/include/gui/SurfaceTextureClient.h b/include/gui/SurfaceTextureClient.h index 6ce44fc..9db7364 100644 --- a/include/gui/SurfaceTextureClient.h +++ b/include/gui/SurfaceTextureClient.h @@ -65,6 +65,8 @@ private: int dispatchDisconnect(va_list args); int dispatchSetBufferCount(va_list args); int dispatchSetBuffersGeometry(va_list args); + int dispatchSetBuffersDimensions(va_list args); + int dispatchSetBuffersFormat(va_list args); int dispatchSetBuffersTransform(va_list args); int dispatchSetBuffersTimestamp(va_list args); int dispatchSetCrop(va_list args); @@ -73,7 +75,8 @@ private: int connect(int api); int disconnect(int api); int setBufferCount(int bufferCount); - int setBuffersGeometry(int w, int h, int format); + int setBuffersDimensions(int w, int h); + int setBuffersFormat(int format); int setBuffersTransform(int transform); int setBuffersTimestamp(int64_t timestamp); int setCrop(Rect const* rect); diff --git a/libs/gui/SurfaceTextureClient.cpp b/libs/gui/SurfaceTextureClient.cpp index b9b2310..e203035 100644 --- a/libs/gui/SurfaceTextureClient.cpp +++ b/libs/gui/SurfaceTextureClient.cpp @@ -254,6 +254,12 @@ int SurfaceTextureClient::perform(int operation, va_list args) case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP: res = dispatchSetBuffersTimestamp(args); break; + case NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS: + res = dispatchSetBuffersDimensions(args); + break; + case NATIVE_WINDOW_SET_BUFFERS_FORMAT: + res = dispatchSetBuffersFormat(args); + break; default: res = NAME_NOT_FOUND; break; @@ -290,7 +296,22 @@ int SurfaceTextureClient::dispatchSetBuffersGeometry(va_list args) { int w = va_arg(args, int); int h = va_arg(args, int); int f = va_arg(args, int); - return setBuffersGeometry(w, h, f); + int err = setBuffersDimensions(w, h); + if (err != 0) { + return err; + } + return setBuffersFormat(f); +} + +int SurfaceTextureClient::dispatchSetBuffersDimensions(va_list args) { + int w = va_arg(args, int); + int h = va_arg(args, int); + return setBuffersDimensions(w, h); +} + +int SurfaceTextureClient::dispatchSetBuffersFormat(va_list args) { + int f = va_arg(args, int); + return setBuffersFormat(f); } int SurfaceTextureClient::dispatchSetBuffersTransform(va_list args) { @@ -390,12 +411,12 @@ int SurfaceTextureClient::setBufferCount(int bufferCount) return err; } -int SurfaceTextureClient::setBuffersGeometry(int w, int h, int format) +int SurfaceTextureClient::setBuffersDimensions(int w, int h) { - LOGV("SurfaceTextureClient::setBuffersGeometry"); + LOGV("SurfaceTextureClient::setBuffersDimensions"); Mutex::Autolock lock(mMutex); - if (w<0 || h<0 || format<0) + if (w<0 || h<0) return BAD_VALUE; if ((w && !h) || (!w && h)) @@ -403,7 +424,6 @@ int SurfaceTextureClient::setBuffersGeometry(int w, int h, int format) mReqWidth = w; mReqHeight = h; - mReqFormat = format; status_t err = mSurfaceTexture->setCrop(Rect(0, 0)); LOGE_IF(err, "ISurfaceTexture::setCrop(...) returned %s", strerror(-err)); @@ -411,6 +431,19 @@ int SurfaceTextureClient::setBuffersGeometry(int w, int h, int format) return err; } +int SurfaceTextureClient::setBuffersFormat(int format) +{ + LOGV("SurfaceTextureClient::setBuffersFormat"); + Mutex::Autolock lock(mMutex); + + if (format<0) + return BAD_VALUE; + + mReqFormat = format; + + return NO_ERROR; +} + int SurfaceTextureClient::setBuffersTransform(int transform) { LOGV("SurfaceTextureClient::setBuffersTransform"); diff --git a/libs/ui/FramebufferNativeWindow.cpp b/libs/ui/FramebufferNativeWindow.cpp index 4393504..9c10c75 100644 --- a/libs/ui/FramebufferNativeWindow.cpp +++ b/libs/ui/FramebufferNativeWindow.cpp @@ -299,6 +299,7 @@ int FramebufferNativeWindow::perform(ANativeWindow* window, { switch (operation) { case NATIVE_WINDOW_SET_USAGE: + case NATIVE_WINDOW_SET_BUFFERS_FORMAT: case NATIVE_WINDOW_CONNECT: case NATIVE_WINDOW_DISCONNECT: break; diff --git a/libs/utils/VectorImpl.cpp b/libs/utils/VectorImpl.cpp index 289c826..87ae3d5 100644 --- a/libs/utils/VectorImpl.cpp +++ b/libs/utils/VectorImpl.cpp @@ -290,7 +290,7 @@ void VectorImpl::clear() void* VectorImpl::editItemLocation(size_t index) { LOG_ASSERT(index<capacity(), - "[%p] itemLocation: index=%d, capacity=%d, count=%d", + "[%p] editItemLocation: index=%d, capacity=%d, count=%d", this, (int)index, (int)capacity(), (int)mCount); void* buffer = editArrayImpl(); @@ -302,7 +302,7 @@ void* VectorImpl::editItemLocation(size_t index) const void* VectorImpl::itemLocation(size_t index) const { LOG_ASSERT(index<capacity(), - "[%p] editItemLocation: index=%d, capacity=%d, count=%d", + "[%p] itemLocation: index=%d, capacity=%d, count=%d", this, (int)index, (int)capacity(), (int)mCount); const void* buffer = arrayImpl(); diff --git a/media/libeffects/factory/EffectsFactory.c b/media/libeffects/factory/EffectsFactory.c index a3e76d9..a9689bc 100644 --- a/media/libeffects/factory/EffectsFactory.c +++ b/media/libeffects/factory/EffectsFactory.c @@ -130,10 +130,43 @@ int Effect_GetDescriptor(effect_handle_t self, return ret; } +int Effect_ProcessReverse(effect_handle_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer) +{ + int ret = init(); + if (ret < 0) { + return ret; + } + effect_entry_t *fx = (effect_entry_t *)self; + pthread_mutex_lock(&gLibLock); + if (fx->lib == NULL) { + pthread_mutex_unlock(&gLibLock); + return -EPIPE; + } + pthread_mutex_lock(&fx->lib->lock); + pthread_mutex_unlock(&gLibLock); + + if ((*fx->subItfe)->process_reverse != NULL) { + ret = (*fx->subItfe)->process_reverse(fx->subItfe, inBuffer, outBuffer); + } else { + ret = -ENOSYS; + } + pthread_mutex_unlock(&fx->lib->lock); + return ret; +} + + const struct effect_interface_s gInterface = { Effect_Process, Effect_Command, - Effect_GetDescriptor + Effect_GetDescriptor, + NULL +}; + +const struct effect_interface_s gInterfaceWithReverse = { + Effect_Process, + Effect_Command, + Effect_GetDescriptor, + Effect_ProcessReverse }; ///////////////////////////////////////////////// @@ -266,7 +299,13 @@ int EffectCreate(effect_uuid_t *uuid, int32_t sessionId, int32_t ioId, effect_ha // add entry to effect list fx = (effect_entry_t *)malloc(sizeof(effect_entry_t)); fx->subItfe = itfe; - fx->itfe = (struct effect_interface_s *)&gInterface; + if ((*itfe)->process_reverse != NULL) { + fx->itfe = (struct effect_interface_s *)&gInterfaceWithReverse; + LOGV("EffectCreate() gInterfaceWithReverse"); + } else { + fx->itfe = (struct effect_interface_s *)&gInterface; + LOGV("EffectCreate() gInterface"); + } fx->lib = l; e = (list_elem_t *)malloc(sizeof(list_elem_t)); diff --git a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp index 21c451f..efa1c45 100644 --- a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp +++ b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp @@ -3231,7 +3231,8 @@ int Effect_getDescriptor(effect_handle_t self, const struct effect_interface_s gLvmEffectInterface = { Effect_process, Effect_command, - Effect_getDescriptor + Effect_getDescriptor, + NULL, }; /* end gLvmEffectInterface */ audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = { diff --git a/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp b/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp index 2727375..663f8ff 100755 --- a/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp +++ b/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp @@ -2134,7 +2134,8 @@ int Reverb_getDescriptor(effect_handle_t self, const struct effect_interface_s gReverbInterface = { Reverb_process, Reverb_command, - Reverb_getDescriptor + Reverb_getDescriptor, + NULL, }; /* end gReverbInterface */ audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = { diff --git a/media/libeffects/testlibs/EffectEqualizer.cpp b/media/libeffects/testlibs/EffectEqualizer.cpp index c2ffce5..b22ebec 100644 --- a/media/libeffects/testlibs/EffectEqualizer.cpp +++ b/media/libeffects/testlibs/EffectEqualizer.cpp @@ -736,7 +736,8 @@ extern "C" int Equalizer_getDescriptor(effect_handle_t self, const struct effect_interface_s gEqualizerInterface = { Equalizer_process, Equalizer_command, - Equalizer_getDescriptor + Equalizer_getDescriptor, + NULL }; diff --git a/media/libeffects/testlibs/EffectReverb.c b/media/libeffects/testlibs/EffectReverb.c index 02762c9..405f908 100644 --- a/media/libeffects/testlibs/EffectReverb.c +++ b/media/libeffects/testlibs/EffectReverb.c @@ -27,7 +27,8 @@ const struct effect_interface_s gReverbInterface = { Reverb_Process, Reverb_Command, - Reverb_GetDescriptor + Reverb_GetDescriptor, + NULL }; // Google auxiliary environmental reverb UUID: 1f0ae2e0-4ef7-11df-bc09-0002a5d5c51b diff --git a/media/libeffects/visualizer/EffectVisualizer.cpp b/media/libeffects/visualizer/EffectVisualizer.cpp index aeebd4d..3c3af8f 100644 --- a/media/libeffects/visualizer/EffectVisualizer.cpp +++ b/media/libeffects/visualizer/EffectVisualizer.cpp @@ -450,7 +450,8 @@ int Visualizer_getDescriptor(effect_handle_t self, const struct effect_interface_s gVisualizerInterface = { Visualizer_process, Visualizer_command, - Visualizer_getDescriptor + Visualizer_getDescriptor, + NULL, }; diff --git a/opengl/libs/EGL/egl.cpp b/opengl/libs/EGL/egl.cpp index b11db32..ddad2d3 100644 --- a/opengl/libs/EGL/egl.cpp +++ b/opengl/libs/EGL/egl.cpp @@ -31,6 +31,7 @@ #include <cutils/properties.h> #include <cutils/memory.h> +#include <utils/CallStack.h> #include <utils/String8.h> #include "egldefs.h" @@ -147,6 +148,10 @@ static int gl_no_context() { if (egl_tls_t::logNoContextCall()) { LOGE("call to OpenGL ES API with no current context " "(logged once per thread)"); + LOGE("call stack before error:"); + CallStack stack; + stack.update(); + stack.dump(); } return 0; } diff --git a/opengl/libs/EGL/eglApi.cpp b/opengl/libs/EGL/eglApi.cpp index 7d5d010..ba5d29a 100644 --- a/opengl/libs/EGL/eglApi.cpp +++ b/opengl/libs/EGL/eglApi.cpp @@ -367,7 +367,12 @@ EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config, if (cnx->egl.eglGetConfigAttrib(iDpy, iConfig, EGL_NATIVE_VISUAL_ID, &format)) { if (format != 0) { - native_window_set_buffers_geometry(window, 0, 0, format); + int err = native_window_set_buffers_format(window, format); + if (err != 0) { + LOGE("error setting native window pixel format: %s (%d)", + strerror(-err), err); + return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); + } } } diff --git a/opengl/specs/EGL_ANDROID_blob_cache.txt b/opengl/specs/EGL_ANDROID_blob_cache.txt new file mode 100644 index 0000000..55dc900 --- /dev/null +++ b/opengl/specs/EGL_ANDROID_blob_cache.txt @@ -0,0 +1,208 @@ +Name + + ANDROID_blob_cache + +Name Strings + + EGL_ANDROID_blob_cache + +Contributors + + Jamie Gennis + +Contact + + Jamie Gennis, Google Inc. (jgennis 'at' google.com) + +Status + + Draft. + +Version + + Version 1, April 22, 2011 + +Number + + EGL Extension #XXX + +Dependencies + + Requires EGL 1.0 + + This extension is written against the wording of the EGL 1.4 Specification + +Overview + + Shader compilation and optimization has been a troublesome aspect of OpenGL + programming for a long time. It can consume seconds of CPU cycles during + application start-up. Additionally, state-based re-compiles done + internally by the drivers add an unpredictable element to application + performance tuning, often leading to occasional pauses in otherwise smooth + animations. + + This extension provides a mechanism through which client API + implementations may cache shader binaries after they are compiled. It may + then retrieve those cached shaders during subsequent executions of the same + program. The management of the cache is handled by the application (or + middleware), allowing it to be tuned to a particular platform or + environment. + + While the focus of this extension is on providing a persistent cache for + shader binaries, it may also be useful for caching other data. This is + perfectly acceptable, but the guarantees provided (or lack thereof) were + designed around the shader use case. + + Note that although this extension is written as if the application + implements the caching functionality, on the Android OS it is implemented + as part of the Android EGL module. This extension is not exposed to + applications on Android, but will be used automatically in every + application that uses EGL if it is supported by the underlying + device-specific EGL implementation. + +New Types + + /* + * EGLsizei is a signed integer type for representing the size of a memory + * buffer. + */ + #include <khrplatform.h> + typedef khronos_ssize_t EGLsizei; + + /* + * EGLSetBlobFunc is a pointer to an application-provided function that a + * client API implementation may use to insert a key/value pair into the + * cache. + */ + typedef void (*EGLSetBlobFunc) (const void* key, EGLsizei keySize, + const void* value, EGLsizei valueSize) + + /* + * EGLGetBlobFunc is a pointer to an application-provided function that a + * client API implementation may use to retrieve a cached value from the + * cache. + */ + typedef EGLsizei (*EGLGetBlobFunc) (const void* key, EGLsizei keySize, + void* value, EGLsizei valueSize) + +New Procedures and Functions + + void eglSetBlobCacheFuncs(EGLDisplay dpy, + EGLSetBlobFunc set, + EGLGetBlobFunc get); + +New Tokens + + None. + +Changes to Chapter 3 of the EGL 1.4 Specification (EGL Functions and Errors) + + Add a new subsection after Section 3.8, page 50 + (Synchronization Primitives) + + "3.9 Persistent Caching + + In order to facilitate persistent caching of internal client API state that + is slow to compute or collect, the application may specify callback + function pointers through which the client APIs can request data be cached + and retrieved. The command + + void eglSetBlobCacheFuncs(EGLDisplay dpy, + EGLSetBlobFunc set, EGLGetBlobFunc get); + + sets the callback function pointers that client APIs associated with + display <dpy> can use to interact with caching functionality provided by + the application. <set> points to a function that inserts a new value into + the cache and associates it with the given key. <get> points to a function + that retrieves from the cache the value associated with a given key. The + semantics of these callback functions are described in Section 3.9.1 (Cache + Operations). + + Cache functions may only be specified once during the lifetime of an + EGLDisplay. The <set> and <get> functions may be called at any time and + from any thread from the time at which eglSetBlobCacheFuncs is called until + the time that the last resource associated with <dpy> is deleted and <dpy> + itself is terminated. Concurrent calls to these functions from different + threads is also allowed. + + If eglSetBlobCacheFuncs generates an error then all client APIs must behave + as though eglSetBlobCacheFuncs was not called for the display <dpy>. If + <set> or <get> is NULL then an EGL_BAD_PARAMETER error is generated. If a + successful eglSetBlobCacheFuncs call was already made for <dpy> and the + display has not since been terminated then an EGL_BAD_PARAMETER error is + generated. + + 3.9.1 Cache Operations + + To insert a new binary value into the cache and associate it with a given + key, a client API implementation can call the application-provided callback + function + + void (*set) (const void* key, EGLsizei keySize, const void* value, + EGLsizei valueSize) + + <key> and <value> are pointers to the beginning of the key and value, + respectively, that are to be inserted. <keySize> and <valueSize> specify + the size in bytes of the data pointed to by <key> and <value>, + respectively. + + No guarantees are made as to whether a given key/value pair is present in + the cache after the set call. If a different value has been associated + with the given key in the past then it is undefined which value, if any, is + associated with the key after the set call. Note that while there are no + guarantees, the cache implementation should attempt to cache the most + recently set value for a given key. + + To retrieve the binary value associated with a given key from the cache, a + client API implementation can call the application-provided callback + function + + EGLsizei (*get) (const void* key, EGLsizei keySize, void* value, + EGLsizei valueSize) + + <key> is a pointer to the beginning of the key. <keySize> specifies the + size in bytes of the binary key pointed to by <key>. If the cache contains + a value associated with the given key then the size of that binary value in + bytes is returned. Otherwise 0 is returned. + + If the cache contains a value for the given key and its size in bytes is + less than or equal to <valueSize> then the value is written to the memory + pointed to by <value>. Otherwise nothing is written to the memory pointed + to by <value>. + +Issues + + 1. How should errors be handled in the callback functions? + + RESOLVED: No guarantees are made about the presence of values in the cache, + so there should not be a need to return error information to the client API + implementation. The cache implementation can simply drop a value if it + encounters an error during the 'set' callback. Similarly, it can simply + return 0 if it encouters an error in a 'get' callback. + + 2. When a client API driver gets updated, that may need to invalidate + previously cached entries. How can the driver handle this situation? + + RESPONSE: There are a number of ways the driver can handle this situation. + The recommended way is to include the driver version in all cache keys. + That way each driver version will use a set of cache keys that are unique + to that version, and conflicts should never occur. Updating the driver + could then leave a number of values in the cache that will never be + requested again. If needed, the cache implementation can handle those + values in some way, but the driver does not need to take any special + action. + + 3. How much data can be stored in the cache? + + RESPONSE: This is entirely dependent upon the cache implementation. + Presumably it will be tuned to store enough data to be useful, but not + enough to become problematic. :) + +Revision History + +#2 (Jamie Gennis, April 25, 2011) + - Swapped the order of the size and pointer arguments to the get and set + functions. + +#1 (Jamie Gennis, April 22, 2011) + - Initial draft. diff --git a/opengl/specs/EGL_ANDROID_recordable.txt b/opengl/specs/EGL_ANDROID_recordable.txt new file mode 100644 index 0000000..cf44465 --- /dev/null +++ b/opengl/specs/EGL_ANDROID_recordable.txt @@ -0,0 +1,113 @@ +Name + + ANDROID_recordable + +Name Strings + + EGL_ANDROID_recordable + +Contributors + + Jamie Gennis + +Contact + + Jamie Gennis, Google Inc. (jgennis 'at' google.com) + +Status + + Draft. + +Version + + Version 1, July 8, 2011 + +Number + + EGL Extension #XXX + +Dependencies + + Requires EGL 1.0 + + This extension is written against the wording of the EGL 1.4 Specification + +Overview + + Android supports a number of different ANativeWindow implementations that + can be used to create an EGLSurface. One implementation, which records the + rendered image as a video each time eglSwapBuffers gets called, may have + some device-specific restrictions. Because of this, some EGLConfigs may be + incompatible with these ANativeWindows. This extension introduces a new + boolean EGLConfig attribute that indicates whether the EGLConfig supports + rendering to an ANativeWindow that records images to a video. + +New Types + + None. + +New Procedures and Functions + + None. + +New Tokens + + Accepted by the <attribute> parameter of eglGetConfigAttrib and + the <attrib_list> parameter of eglChooseConfig: + + EGL_RECORDABLE_ANDROID 0xXXXX + +Changes to Chapter 3 of the EGL 1.4 Specification (EGL Functions and Errors) + + Section 3.4, Configuration Management, add a row to Table 3.1. + + Attribute Type Notes + ---------------------- ------- -------------------------- + EGL_RECORDABLE_ANDROID boolean whether video recording is + supported + + Section 3.4, Configuration Management, add a row to Table 3.4. + + Attribute Default Selection Sort Sort + Criteria Order Priority + ---------------------- ------------- --------- ----- -------- + EGL_RECORDABLE_ANDROID EGL_DONT_CARE Exact None + + Section 3.4, Configuration Management, add a paragraph at the end of the + subsection titled Other EGLConfig Attribute Descriptions. + + EGL_RECORDABLE_ANDROID is a boolean indicating whether the config may + be used to create an EGLSurface from an ANativeWindow that is a video + recorder as indicated by the NATIVE_WINDOW_IS_VIDEO_RECORDER query on + the ANativeWindow. + + Section 3.4.1, Querying Configurations, change the last paragraph as follow + + EGLConfigs are not sorted with respect to the parameters + EGL_BIND_TO_TEXTURE_RGB, EGL_BIND_TO_TEXTURE_RGBA, EGL_CONFORMANT, + EGL_LEVEL, EGL_NATIVE_RENDERABLE, EGL_MAX_SWAP_INTERVAL, + EGL_MIN_SWAP_INTERVAL, EGL_RENDERABLE_TYPE, EGL_SURFACE_TYPE, + EGL_TRANSPARENT_TYPE, EGL_TRANSPARENT_RED_VALUE, + EGL_TRANSPARENT_GREEN_VALUE, EGL_TRANSPARENT_BLUE_VALUE, and + EGL_RECORDABLE_ANDROID. + +Issues + + 1. Should this functionality be exposed as a new attribute or as a bit in + the EGL_SURFACE_TYPE bitfield? + + RESOLVED: It should be a new attribute. It does not make sense to use up a + bit in the limit-size bitfield for a platform-specific extension. + + 2. How should the new attribute affect the sorting of EGLConfigs? + + RESOLVED: It should not affect sorting. Some implementations may not have + any drawback associated with using a recordable EGLConfig. Such + implementations should not have to double-up some of their configs to one sort earlier than . + Implementations that do have drawbacks can use the existing caveat + mechanism to report this drawback to the client. + +Revision History + +#1 (Jamie Gennis, July 8, 2011) + - Initial draft. diff --git a/opengl/specs/README b/opengl/specs/README new file mode 100644 index 0000000..2fa2587 --- /dev/null +++ b/opengl/specs/README @@ -0,0 +1,12 @@ +This directory contains OpenGL ES and EGL extension specifications that have +been or are being defined for Android. + +The table below tracks usage of EGL enumerant values that have been reserved +for use by Android extensions. + + Value Extension +---------------- ---------------------------------- +0x3140 EGL_ANDROID_image_native_buffer +0x3141 (unused) +0x3142 EGL_ANDROID_recordable +0x3143 - 0x314F (unused) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java index 826ac92..dedbe5d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java @@ -785,7 +785,7 @@ public class PhoneStatusBarPolicy { int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); mBluetoothEnabled = state == BluetoothAdapter.STATE_ON; } else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) { - int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, + int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, BluetoothAdapter.STATE_DISCONNECTED); if (state == BluetoothAdapter.STATE_CONNECTED) { iconId = R.drawable.stat_sys_data_bluetooth_connected; diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java index 7f6327d..dff0556 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java @@ -1555,9 +1555,12 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { // We restore the panel if it was last open; we skip it if it // now is open, to avoid a race condition if the user immediately // opens it when we are resuming. - if ((st != null) && !st.isOpen && st.wasLastOpen) { - st.isInExpandedMode = st.wasLastExpanded; - openPanel(st, null); + if (st != null) { + st.applyFrozenState(); + if (!st.isOpen && st.wasLastOpen) { + st.isInExpandedMode = st.wasLastExpanded; + openPanel(st, null); + } } } } @@ -2235,6 +2238,11 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { } mActionModePopup = null; } + + PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false); + if (st != null && st.menu != null) { + st.menu.close(); + } } @Override @@ -3046,46 +3054,33 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { getIconMenuView(cb); // Need this initialized to know where our offset goes - boolean init = false; if (expandedMenuPresenter == null) { expandedMenuPresenter = new ListMenuPresenter( com.android.internal.R.layout.list_menu_item_layout, com.android.internal.R.style.Theme_ExpandedMenu); expandedMenuPresenter.setCallback(cb); + expandedMenuPresenter.setId(com.android.internal.R.id.list_menu_presenter); menu.addMenuPresenter(expandedMenuPresenter); - init = true; } expandedMenuPresenter.setItemIndexOffset(iconMenuPresenter.getNumActualItemsShown()); MenuView result = expandedMenuPresenter.getMenuView(decorView); - if (init && frozenMenuState != null) { - expandedMenuPresenter.restoreHierarchyState(frozenMenuState); - // Once we initialize the expanded menu we're done with the frozen state - // since we will have also restored any icon menu state. - frozenMenuState = null; - } - return result; } MenuView getIconMenuView(MenuPresenter.Callback cb) { if (menu == null) return null; - boolean init = false; if (iconMenuPresenter == null) { iconMenuPresenter = new IconMenuPresenter(); iconMenuPresenter.setCallback(cb); + iconMenuPresenter.setId(com.android.internal.R.id.icon_menu_presenter); menu.addMenuPresenter(iconMenuPresenter); - init = true; } MenuView result = iconMenuPresenter.getMenuView(decorView); - if (init && frozenMenuState != null) { - iconMenuPresenter.restoreHierarchyState(frozenMenuState); - } - return result; } @@ -3097,12 +3092,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { if (menu != null) { savedState.menuState = new Bundle(); - if (iconMenuPresenter != null) { - iconMenuPresenter.saveHierarchyState(savedState.menuState); - } - if (expandedMenuPresenter != null) { - expandedMenuPresenter.saveHierarchyState(savedState.menuState); - } + menu.savePresenterStates(savedState.menuState); } return savedState; @@ -3127,6 +3117,13 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { decorView = null; } + void applyFrozenState() { + if (menu != null && frozenMenuState != null) { + menu.restorePresenterStates(frozenMenuState); + frozenMenuState = null; + } + } + private static class SavedState implements Parcelable { int featureId; boolean isOpen; diff --git a/services/input/InputDispatcher.cpp b/services/input/InputDispatcher.cpp index 10b9083..da9b55c 100644 --- a/services/input/InputDispatcher.cpp +++ b/services/input/InputDispatcher.cpp @@ -3154,11 +3154,9 @@ void InputDispatcher::setInputWindows(const Vector<InputWindow>& inputWindows) { mLastHoverWindow = NULL; } - mWindows.clear(); - // Loop over new windows and rebuild the necessary window pointers for // tracking focus and touch. - mWindows.appendVector(inputWindows); + mWindows = inputWindows; size_t numWindows = mWindows.size(); for (size_t i = 0; i < numWindows; i++) { @@ -4560,8 +4558,7 @@ void InputDispatcher::TouchState::copyFrom(const TouchState& other) { split = other.split; deviceId = other.deviceId; source = other.source; - windows.clear(); - windows.appendVector(other.windows); + windows = other.windows; } void InputDispatcher::TouchState::addOrUpdateWindow(const InputWindow* window, diff --git a/services/java/com/android/server/InputMethodManagerService.java b/services/java/com/android/server/InputMethodManagerService.java index 2d55433..18d393f 100644 --- a/services/java/com/android/server/InputMethodManagerService.java +++ b/services/java/com/android/server/InputMethodManagerService.java @@ -531,10 +531,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub mImeSwitcherNotification.sound = null; mImeSwitcherNotification.vibrate = null; Intent intent = new Intent(Settings.ACTION_SHOW_INPUT_METHOD_PICKER); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK - | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED - | Intent.FLAG_ACTIVITY_CLEAR_TOP); - mImeSwitchPendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0); + mImeSwitchPendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0); mShowOngoingImeSwitcherForPhones = mRes.getBoolean( com.android.internal.R.bool.show_ongoing_ime_switcher); diff --git a/services/java/com/android/server/NetworkManagementService.java b/services/java/com/android/server/NetworkManagementService.java index da1bf83..829df39 100644 --- a/services/java/com/android/server/NetworkManagementService.java +++ b/services/java/com/android/server/NetworkManagementService.java @@ -77,11 +77,15 @@ class NetworkManagementService extends INetworkManagementService.Stub { /** Path to {@code /proc/uid_stat}. */ @Deprecated - private final File mProcStatsUidstat; + private final File mStatsUid; + /** Path to {@code /proc/net/dev}. */ + private final File mStatsIface; /** Path to {@code /proc/net/xt_qtaguid/stats}. */ - private final File mProcStatsNetfilter; + private final File mStatsXtUid; + /** Path to {@code /proc/net/xt_qtaguid/iface_stat}. */ + private final File mStatsXtIface; - /** {@link #mProcStatsNetfilter} headers. */ + /** {@link #mStatsXtUid} headers. */ private static final String KEY_IFACE = "iface"; private static final String KEY_TAG_HEX = "acct_tag_hex"; private static final String KEY_UID = "uid_tag_int"; @@ -137,8 +141,10 @@ class NetworkManagementService extends INetworkManagementService.Stub { mContext = context; mObservers = new ArrayList<INetworkManagementEventObserver>(); - mProcStatsUidstat = new File(procRoot, "uid_stat"); - mProcStatsNetfilter = new File(procRoot, "net/xt_qtaguid/stats"); + mStatsUid = new File(procRoot, "uid_stat"); + mStatsIface = new File(procRoot, "net/dev"); + mStatsXtUid = new File(procRoot, "net/xt_qtaguid/stats"); + mStatsXtIface = new File(procRoot, "net/xt_qtaguid/iface_stat"); if ("simulator".equals(SystemProperties.get("ro.product.device"))) { return; @@ -161,9 +167,12 @@ class NetworkManagementService extends INetworkManagementService.Stub { } // @VisibleForTesting - public static NetworkManagementService createForTest(Context context, File procRoot) { + public static NetworkManagementService createForTest( + Context context, File procRoot, boolean bandwidthControlEnabled) { // TODO: eventually connect with mock netd - return new NetworkManagementService(context, procRoot); + final NetworkManagementService service = new NetworkManagementService(context, procRoot); + service.mBandwidthControlEnabled = bandwidthControlEnabled; + return service; } public void systemReady() { @@ -930,13 +939,68 @@ class NetworkManagementService extends INetworkManagementService.Stub { mContext.enforceCallingOrSelfPermission( android.Manifest.permission.ACCESS_NETWORK_STATE, "NetworkManagementService"); - final String[] ifaces = listInterfaces(); - final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), ifaces.length); + final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 6); + final NetworkStats.Entry entry = new NetworkStats.Entry(); + + final HashSet<String> activeIfaces = Sets.newHashSet(); + final ArrayList<String> values = Lists.newArrayList(); + + BufferedReader reader = null; + try { + reader = new BufferedReader(new FileReader(mStatsIface)); + + // skip first two header lines + reader.readLine(); + reader.readLine(); + + // parse remaining lines + String line; + while ((line = reader.readLine()) != null) { + splitLine(line, values); + + try { + entry.iface = values.get(0); + entry.uid = UID_ALL; + entry.tag = TAG_NONE; + entry.rxBytes = Long.parseLong(values.get(1)); + entry.rxPackets = Long.parseLong(values.get(2)); + entry.txBytes = Long.parseLong(values.get(9)); + entry.txPackets = Long.parseLong(values.get(10)); + + activeIfaces.add(entry.iface); + stats.addValues(entry); + } catch (NumberFormatException e) { + Slog.w(TAG, "problem parsing stats row '" + line + "': " + e); + } + } + } catch (IOException e) { + Slog.w(TAG, "problem parsing stats: " + e); + } finally { + IoUtils.closeQuietly(reader); + } + + if (DBG) Slog.d(TAG, "recorded active stats from " + activeIfaces); + + // splice in stats from any disabled ifaces + if (mBandwidthControlEnabled) { + final HashSet<String> xtIfaces = Sets.newHashSet(fileListWithoutNull(mStatsXtIface)); + xtIfaces.removeAll(activeIfaces); + + for (String iface : xtIfaces) { + final File ifacePath = new File(mStatsXtIface, iface); + + entry.iface = iface; + entry.uid = UID_ALL; + entry.tag = TAG_NONE; + entry.rxBytes = readSingleLongFromFile(new File(ifacePath, "rx_bytes")); + entry.rxPackets = readSingleLongFromFile(new File(ifacePath, "rx_packets")); + entry.txBytes = readSingleLongFromFile(new File(ifacePath, "tx_bytes")); + entry.txPackets = readSingleLongFromFile(new File(ifacePath, "tx_packets")); - for (String iface : ifaces) { - final long rx = getInterfaceCounter(iface, true); - final long tx = getInterfaceCounter(iface, false); - stats.addEntry(iface, UID_ALL, TAG_NONE, rx, tx); + stats.addValues(entry); + } + + if (DBG) Slog.d(TAG, "recorded stale stats from " + xtIfaces); } return stats; @@ -1063,13 +1127,15 @@ class NetworkManagementService extends INetworkManagementService.Stub { */ private NetworkStats getNetworkStatsDetailNetfilter(int limitUid) { final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 24); + final NetworkStats.Entry entry = new NetworkStats.Entry(); + final ArrayList<String> keys = Lists.newArrayList(); final ArrayList<String> values = Lists.newArrayList(); final HashMap<String, String> parsed = Maps.newHashMap(); BufferedReader reader = null; try { - reader = new BufferedReader(new FileReader(mProcStatsNetfilter)); + reader = new BufferedReader(new FileReader(mStatsXtUid)); // parse first line as header String line = reader.readLine(); @@ -1081,15 +1147,16 @@ class NetworkManagementService extends INetworkManagementService.Stub { parseLine(keys, values, parsed); try { - final String iface = parsed.get(KEY_IFACE); - final int tag = NetworkManagementSocketTagger.kernelToTag( + // TODO: add rxPackets/txPackets once kernel exports + entry.iface = parsed.get(KEY_IFACE); + entry.tag = NetworkManagementSocketTagger.kernelToTag( parsed.get(KEY_TAG_HEX)); - final int uid = Integer.parseInt(parsed.get(KEY_UID)); - final long rx = Long.parseLong(parsed.get(KEY_RX)); - final long tx = Long.parseLong(parsed.get(KEY_TX)); + entry.uid = Integer.parseInt(parsed.get(KEY_UID)); + entry.rxBytes = Long.parseLong(parsed.get(KEY_RX)); + entry.txBytes = Long.parseLong(parsed.get(KEY_TX)); - if (limitUid == UID_ALL || limitUid == uid) { - stats.addEntry(iface, uid, tag, rx, tx); + if (limitUid == UID_ALL || limitUid == entry.uid) { + stats.addValues(entry); } } catch (NumberFormatException e) { Slog.w(TAG, "problem parsing stats row '" + line + "': " + e); @@ -1114,19 +1181,27 @@ class NetworkManagementService extends INetworkManagementService.Stub { private NetworkStats getNetworkStatsDetailUidstat(int limitUid) { final String[] knownUids; if (limitUid == UID_ALL) { - knownUids = mProcStatsUidstat.list(); + knownUids = fileListWithoutNull(mStatsUid); } else { knownUids = new String[] { String.valueOf(limitUid) }; } final NetworkStats stats = new NetworkStats( SystemClock.elapsedRealtime(), knownUids.length); + final NetworkStats.Entry entry = new NetworkStats.Entry(); for (String uid : knownUids) { final int uidInt = Integer.parseInt(uid); - final File uidPath = new File(mProcStatsUidstat, uid); - final long rx = readSingleLongFromFile(new File(uidPath, "tcp_rcv")); - final long tx = readSingleLongFromFile(new File(uidPath, "tcp_snd")); - stats.addEntry(IFACE_ALL, uidInt, TAG_NONE, rx, tx); + final File uidPath = new File(mStatsUid, uid); + + entry.iface = IFACE_ALL; + entry.uid = uidInt; + entry.tag = TAG_NONE; + entry.rxBytes = readSingleLongFromFile(new File(uidPath, "tcp_rcv")); + entry.rxPackets = readSingleLongFromFile(new File(uidPath, "tcp_rcv_pkt")); + entry.txBytes = readSingleLongFromFile(new File(uidPath, "tcp_snd")); + entry.txPackets = readSingleLongFromFile(new File(uidPath, "tcp_snd_pkt")); + + stats.addValues(entry); } return stats; @@ -1197,7 +1272,7 @@ class NetworkManagementService extends INetworkManagementService.Stub { private static void splitLine(String line, ArrayList<String> outSplit) { outSplit.clear(); - final StringTokenizer t = new StringTokenizer(line); + final StringTokenizer t = new StringTokenizer(line, " \t\n\r\f:"); while (t.hasMoreTokens()) { outSplit.add(t.nextToken()); } @@ -1232,6 +1307,15 @@ class NetworkManagementService extends INetworkManagementService.Stub { } } + /** + * Wrapper for {@link File#list()} that returns empty array instead of + * {@code null}. + */ + private static String[] fileListWithoutNull(File file) { + final String[] list = file.list(); + return list != null ? list : new String[0]; + } + public void setDefaultInterfaceForDns(String iface) throws IllegalStateException { mContext.enforceCallingOrSelfPermission( android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService"); diff --git a/services/java/com/android/server/am/UsageStatsService.java b/services/java/com/android/server/am/UsageStatsService.java index 6e8f248..12c8ccf 100644 --- a/services/java/com/android/server/am/UsageStatsService.java +++ b/services/java/com/android/server/am/UsageStatsService.java @@ -63,7 +63,7 @@ public final class UsageStatsService extends IUsageStats.Stub { private static final String TAG = "UsageStats"; // Current on-disk Parcel version - private static final int VERSION = 1005; + private static final int VERSION = 1006; private static final int CHECKIN_VERSION = 4; @@ -145,6 +145,8 @@ public final class UsageStatsService extends IUsageStats.Stub { final HashMap<String, TimeStats> mLaunchTimes = new HashMap<String, TimeStats>(); int mLaunchCount; + final HashMap<String, Long> mLastResumeTimes + = new HashMap<String, Long>(); long mUsageTime; long mPausedTime; long mResumedTime; @@ -160,20 +162,28 @@ public final class UsageStatsService extends IUsageStats.Stub { if (localLOGV) Slog.v(TAG, "Launch count: " + mLaunchCount + ", Usage time:" + mUsageTime); - final int N = in.readInt(); - if (localLOGV) Slog.v(TAG, "Reading comps: " + N); - for (int i=0; i<N; i++) { + final int numTimeStats = in.readInt(); + if (localLOGV) Slog.v(TAG, "Reading comps: " + numTimeStats); + for (int i=0; i<numTimeStats; i++) { String comp = in.readString(); if (localLOGV) Slog.v(TAG, "Component: " + comp); TimeStats times = new TimeStats(in); mLaunchTimes.put(comp, times); } + final int numResumeTimes = in.readInt(); + if (localLOGV) Slog.v(TAG, "Reading last resume times: " + numResumeTimes); + for (int i=0; i<numResumeTimes; i++) { + String comp = in.readString(); + if (localLOGV) Slog.v(TAG, "Component: " + comp); + mLastResumeTimes.put(comp, in.readLong()); + } } - - void updateResume(boolean launched) { + + void updateResume(String comp, boolean launched) { if (launched) { mLaunchCount ++; } + mLastResumeTimes.put(comp, System.currentTimeMillis()); mResumedTime = SystemClock.elapsedRealtime(); } @@ -203,20 +213,29 @@ public final class UsageStatsService extends IUsageStats.Stub { void writeToParcel(Parcel out) { out.writeInt(mLaunchCount); out.writeLong(mUsageTime); - final int N = mLaunchTimes.size(); - out.writeInt(N); - if (N > 0) { + final int numTimeStats = mLaunchTimes.size(); + out.writeInt(numTimeStats); + if (numTimeStats > 0) { for (Map.Entry<String, TimeStats> ent : mLaunchTimes.entrySet()) { out.writeString(ent.getKey()); TimeStats times = ent.getValue(); times.writeToParcel(out); } } + final int numResumeTimes = mLastResumeTimes.size(); + out.writeInt(numResumeTimes); + if (numResumeTimes > 0) { + for (Map.Entry<String, Long> ent : mLastResumeTimes.entrySet()) { + out.writeString(ent.getKey()); + out.writeLong(ent.getValue()); + } + } } void clear() { mLaunchTimes.clear(); mLaunchCount = 0; + mLastResumeTimes.clear(); mUsageTime = 0; } } @@ -546,7 +565,7 @@ public final class UsageStatsService extends IUsageStats.Stub { pus = new PkgUsageStatsExtended(); mStats.put(pkgName, pus); } - pus.updateResume(!samePackage); + pus.updateResume(mLastResumedComp, !samePackage); if (!sameComp) { pus.addLaunchCount(mLastResumedComp); } @@ -624,7 +643,8 @@ public final class UsageStatsService extends IUsageStats.Stub { if (pus == null) { return null; } - return new PkgUsageStats(pkgName, pus.mLaunchCount, pus.mUsageTime); + return new PkgUsageStats(pkgName, pus.mLaunchCount, pus.mUsageTime, + pus.mLastResumeTimes); } } @@ -641,7 +661,8 @@ public final class UsageStatsService extends IUsageStats.Stub { int i = 0; for (String key: keys) { PkgUsageStatsExtended pus = mStats.get(key); - retArr[i] = new PkgUsageStats(key, pus.mLaunchCount, pus.mUsageTime); + retArr[i] = new PkgUsageStats(key, pus.mLaunchCount, pus.mUsageTime, + pus.mLastResumeTimes); i++; } return retArr; diff --git a/services/java/com/android/server/connectivity/Tethering.java b/services/java/com/android/server/connectivity/Tethering.java index 6bb7949..d7d4b03 100644 --- a/services/java/com/android/server/connectivity/Tethering.java +++ b/services/java/com/android/server/connectivity/Tethering.java @@ -221,8 +221,6 @@ public class Tethering extends INetworkManagementEventObserver.Stub { } public void interfaceLinkStateChanged(String iface, boolean up) { - if (DEBUG) Log.d(TAG, "interfaceLinkStateChanged " + iface + ", " + up); - interfaceStatusChanged(iface, up); } private boolean isUsb(String iface) { diff --git a/services/java/com/android/server/usb/UsbDeviceManager.java b/services/java/com/android/server/usb/UsbDeviceManager.java index 1ab570a..86b3d36 100644 --- a/services/java/com/android/server/usb/UsbDeviceManager.java +++ b/services/java/com/android/server/usb/UsbDeviceManager.java @@ -251,19 +251,18 @@ public class UsbDeviceManager { public UsbHandler() { try { + // persist.sys.usb.config should never be unset. But if it is, set it to "adb" + // so we have a chance of debugging what happened. + mDefaultFunctions = SystemProperties.get("persist.sys.usb.config", "adb"); // sanity check the sys.usb.config system property // this may be necessary if we crashed while switching USB configurations String config = SystemProperties.get("sys.usb.config", "none"); - if (config.equals("none")) { - String persistConfig = SystemProperties.get("persist.sys.usb.config", "none"); - Slog.w(TAG, "resetting config to persistent property: " + persistConfig); - SystemProperties.set("sys.usb.config", persistConfig); + if (!config.equals(mDefaultFunctions)) { + Slog.w(TAG, "resetting config to persistent property: " + mDefaultFunctions); + SystemProperties.set("sys.usb.config", mDefaultFunctions); } - // Read initial USB state - mCurrentFunctions = FileUtils.readTextFile( - new File(FUNCTIONS_PATH), 0, null).trim(); - mDefaultFunctions = mCurrentFunctions; + mCurrentFunctions = mDefaultFunctions; String state = FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim(); updateState(state); mAdbEnabled = containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ADB); @@ -621,6 +620,16 @@ public class UsbDeviceManager { pw.println(" mConnected: " + mConnected); pw.println(" mConfigured: " + mConfigured); pw.println(" mCurrentAccessory: " + mCurrentAccessory); + try { + pw.println(" Kernel state: " + + FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim()); + pw.println(" Kernel function list: " + + FileUtils.readTextFile(new File(FUNCTIONS_PATH), 0, null).trim()); + pw.println(" Mass storage backing file: " + + FileUtils.readTextFile(new File(MASS_STORAGE_FILE_PATH), 0, null).trim()); + } catch (IOException e) { + pw.println("IOException: " + e); + } } } diff --git a/services/tests/servicestests/res/raw/net_dev_typical b/services/tests/servicestests/res/raw/net_dev_typical new file mode 100644 index 0000000..290bf03 --- /dev/null +++ b/services/tests/servicestests/res/raw/net_dev_typical @@ -0,0 +1,8 @@ +Inter-| Receive | Transmit + face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed + lo: 8308 116 0 0 0 0 0 0 8308 116 0 0 0 0 0 0 +rmnet0: 1507570 2205 0 0 0 0 0 0 489339 2237 0 0 0 0 0 0 + ifb0: 52454 151 0 151 0 0 0 0 0 0 0 0 0 0 0 0 + ifb1: 52454 151 0 151 0 0 0 0 0 0 0 0 0 0 0 0 + sit0: 0 0 0 0 0 0 0 0 0 0 148 0 0 0 0 0 +ip6tnl0: 0 0 0 0 0 0 0 0 0 0 151 151 0 0 0 0 diff --git a/services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java index ac7cb5a..56ef995 100644 --- a/services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java @@ -16,6 +16,8 @@ package com.android.server; +import static android.net.NetworkStats.TAG_NONE; +import static android.net.NetworkStats.UID_ALL; import static com.android.server.NetworkManagementSocketTagger.kernelToTag; import static com.android.server.NetworkManagementSocketTagger.tagToKernel; @@ -25,9 +27,11 @@ import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.LargeTest; import com.android.frameworks.servicestests.R; +import com.google.common.io.Files; import java.io.File; import java.io.FileOutputStream; +import java.io.FileWriter; import java.io.InputStream; import java.io.OutputStream; @@ -46,14 +50,23 @@ public class NetworkManagementServiceTest extends AndroidTestCase { public void setUp() throws Exception { super.setUp(); - mTestProc = getContext().getFilesDir(); - mService = NetworkManagementService.createForTest(mContext, mTestProc); + final File canonicalFilesDir = getContext().getFilesDir().getCanonicalFile(); + mTestProc = new File(canonicalFilesDir, "proc"); + if (mTestProc.exists()) { + Files.deleteRecursively(mTestProc); + } + + mService = NetworkManagementService.createForTest(mContext, mTestProc, true); } @Override public void tearDown() throws Exception { mService = null; + if (mTestProc.exists()) { + Files.deleteRecursively(mTestProc); + } + super.tearDown(); } @@ -61,7 +74,7 @@ public class NetworkManagementServiceTest extends AndroidTestCase { stageFile(R.raw.xt_qtaguid_typical, new File(mTestProc, "net/xt_qtaguid/stats")); final NetworkStats stats = mService.getNetworkStatsDetail(); - assertEquals(31, stats.size); + assertEquals(31, stats.size()); assertStatsEntry(stats, "wlan0", 0, 0, 14615L, 4270L); assertStatsEntry(stats, "wlan0", 10004, 0, 333821L, 53558L); assertStatsEntry(stats, "wlan0", 10004, 1947740890, 18725L, 1066L); @@ -73,11 +86,37 @@ public class NetworkManagementServiceTest extends AndroidTestCase { stageFile(R.raw.xt_qtaguid_extended, new File(mTestProc, "net/xt_qtaguid/stats")); final NetworkStats stats = mService.getNetworkStatsDetail(); - assertEquals(2, stats.size); + assertEquals(2, stats.size()); assertStatsEntry(stats, "test0", 1000, 0, 1024L, 2048L); assertStatsEntry(stats, "test0", 1000, 0xF00D, 512L, 512L); } + public void testNetworkStatsSummary() throws Exception { + stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev")); + + final NetworkStats stats = mService.getNetworkStatsSummary(); + assertEquals(6, stats.size()); + assertStatsEntry(stats, "lo", UID_ALL, TAG_NONE, 8308L, 8308L); + assertStatsEntry(stats, "rmnet0", UID_ALL, TAG_NONE, 1507570L, 489339L); + assertStatsEntry(stats, "ifb0", UID_ALL, TAG_NONE, 52454L, 0L); + assertStatsEntry(stats, "ifb1", UID_ALL, TAG_NONE, 52454L, 0L); + assertStatsEntry(stats, "sit0", UID_ALL, TAG_NONE, 0L, 0L); + assertStatsEntry(stats, "ip6tnl0", UID_ALL, TAG_NONE, 0L, 0L); + } + + public void testNetworkStatsSummaryDown() throws Exception { + stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev")); + stageLong(1024L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/rx_bytes")); + stageLong(128L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/rx_packets")); + stageLong(2048L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/tx_bytes")); + stageLong(256L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/tx_packets")); + + final NetworkStats stats = mService.getNetworkStatsSummary(); + assertEquals(7, stats.size()); + assertStatsEntry(stats, "rmnet0", UID_ALL, TAG_NONE, 1507570L, 489339L); + assertStatsEntry(stats, "wlan0", UID_ALL, TAG_NONE, 1024L, 2048L); + } + public void testKernelTags() throws Exception { assertEquals("0", tagToKernel(0x0)); assertEquals("214748364800", tagToKernel(0x32)); @@ -90,7 +129,6 @@ public class NetworkManagementServiceTest extends AndroidTestCase { assertEquals(2147483647, kernelToTag("0x7fffffff00000000")); assertEquals(0, kernelToTag("0x0000000000000000")); assertEquals(2147483136, kernelToTag("0x7FFFFE0000000000")); - } /** @@ -111,11 +149,23 @@ public class NetworkManagementServiceTest extends AndroidTestCase { } } + private void stageLong(long value, File file) throws Exception { + new File(file.getParent()).mkdirs(); + FileWriter out = null; + try { + out = new FileWriter(file); + out.write(Long.toString(value)); + } finally { + IoUtils.closeQuietly(out); + } + } + private static void assertStatsEntry( - NetworkStats stats, String iface, int uid, int tag, long rx, long tx) { + NetworkStats stats, String iface, int uid, int tag, long rxBytes, long txBytes) { final int i = stats.findIndex(iface, uid, tag); - assertEquals(rx, stats.rx[i]); - assertEquals(tx, stats.tx[i]); + final NetworkStats.Entry entry = stats.getValues(i, null); + assertEquals(rxBytes, entry.rxBytes); + assertEquals(txBytes, entry.txBytes); } } diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml index cb8084d..32a6a65 100644 --- a/tests/HwAccelerationTest/AndroidManifest.xml +++ b/tests/HwAccelerationTest/AndroidManifest.xml @@ -382,6 +382,15 @@ <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> + + <activity + android:name="MoreNinePatchesActivity" + android:label="_9patch2"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> <activity android:name="QuickRejectActivity" diff --git a/tests/HwAccelerationTest/res/drawable-nodpi/progress_vertical_bg_holo_dark.9.png b/tests/HwAccelerationTest/res/drawable-nodpi/progress_vertical_bg_holo_dark.9.png Binary files differnew file mode 100644 index 0000000..089704e --- /dev/null +++ b/tests/HwAccelerationTest/res/drawable-nodpi/progress_vertical_bg_holo_dark.9.png diff --git a/tests/HwAccelerationTest/res/drawable-nodpi/progress_vertical_primary_holo_dark.9.png b/tests/HwAccelerationTest/res/drawable-nodpi/progress_vertical_primary_holo_dark.9.png Binary files differnew file mode 100644 index 0000000..385dbc4 --- /dev/null +++ b/tests/HwAccelerationTest/res/drawable-nodpi/progress_vertical_primary_holo_dark.9.png diff --git a/tests/HwAccelerationTest/res/drawable-nodpi/progress_vertical_secondary_holo_dark.9.png b/tests/HwAccelerationTest/res/drawable-nodpi/progress_vertical_secondary_holo_dark.9.png Binary files differnew file mode 100644 index 0000000..f1510b2 --- /dev/null +++ b/tests/HwAccelerationTest/res/drawable-nodpi/progress_vertical_secondary_holo_dark.9.png diff --git a/tests/HwAccelerationTest/res/drawable-nodpi/scrubber_vertical_primary_holo.9.png b/tests/HwAccelerationTest/res/drawable-nodpi/scrubber_vertical_primary_holo.9.png Binary files differnew file mode 100644 index 0000000..4208c6f --- /dev/null +++ b/tests/HwAccelerationTest/res/drawable-nodpi/scrubber_vertical_primary_holo.9.png diff --git a/tests/HwAccelerationTest/res/drawable-nodpi/scrubber_vertical_secondary_holo.9.png b/tests/HwAccelerationTest/res/drawable-nodpi/scrubber_vertical_secondary_holo.9.png Binary files differnew file mode 100644 index 0000000..b25fb2f --- /dev/null +++ b/tests/HwAccelerationTest/res/drawable-nodpi/scrubber_vertical_secondary_holo.9.png diff --git a/tests/HwAccelerationTest/res/drawable-nodpi/scrubber_vertical_track_holo_dark.9.png b/tests/HwAccelerationTest/res/drawable-nodpi/scrubber_vertical_track_holo_dark.9.png Binary files differnew file mode 100644 index 0000000..25129c6 --- /dev/null +++ b/tests/HwAccelerationTest/res/drawable-nodpi/scrubber_vertical_track_holo_dark.9.png diff --git a/tests/HwAccelerationTest/res/drawable-nodpi/scrubber_vertical_track_holo_light.9.png b/tests/HwAccelerationTest/res/drawable-nodpi/scrubber_vertical_track_holo_light.9.png Binary files differnew file mode 100644 index 0000000..1505e0e --- /dev/null +++ b/tests/HwAccelerationTest/res/drawable-nodpi/scrubber_vertical_track_holo_light.9.png diff --git a/tests/HwAccelerationTest/res/drawable/progress_vertical_holo_dark.xml b/tests/HwAccelerationTest/res/drawable/progress_vertical_holo_dark.xml new file mode 100644 index 0000000..9eb54b7 --- /dev/null +++ b/tests/HwAccelerationTest/res/drawable/progress_vertical_holo_dark.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2010 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. +--> + +<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> + + <item android:id="@android:id/background" + android:drawable="@drawable/progress_vertical_bg_holo_dark" /> + + <item android:id="@android:id/secondaryProgress"> + <scale android:scaleHeight="100%" android:scaleGravity="bottom" + android:drawable="@drawable/progress_vertical_secondary_holo_dark" /> + </item> + + <item android:id="@android:id/progress"> + <scale android:scaleHeight="100%" android:scaleGravity="bottom" + android:drawable="@drawable/progress_vertical_primary_holo_dark" /> + </item> + +</layer-list> diff --git a/tests/HwAccelerationTest/res/drawable/scrubber_progress_vertical_holo_dark.xml b/tests/HwAccelerationTest/res/drawable/scrubber_progress_vertical_holo_dark.xml new file mode 100644 index 0000000..0cc56bf --- /dev/null +++ b/tests/HwAccelerationTest/res/drawable/scrubber_progress_vertical_holo_dark.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2010 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. +--> + +<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:id="@android:id/background" + android:drawable="@drawable/scrubber_vertical_track_holo_dark" /> + <item android:id="@android:id/secondaryProgress"> + <scale android:scaleHeight="100%" android:scaleGravity="bottom" + android:drawable="@drawable/scrubber_vertical_secondary_holo" /> + </item> + <item android:id="@android:id/progress"> + <scale android:scaleHeight="100%" android:scaleGravity="bottom" + android:drawable="@drawable/scrubber_vertical_primary_holo" /> + </item> +</layer-list> diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/MoreNinePatchesActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/MoreNinePatchesActivity.java new file mode 100644 index 0000000..0c42387 --- /dev/null +++ b/tests/HwAccelerationTest/src/com/android/test/hwui/MoreNinePatchesActivity.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2010 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.test.hwui; + +import android.app.Activity; +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Canvas; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.view.Gravity; +import android.view.View; +import android.widget.FrameLayout; + +@SuppressWarnings({"UnusedDeclaration"}) +public class MoreNinePatchesActivity extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + FrameLayout layout = new FrameLayout(this); + PatchView b = new PatchView (this); + b.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, + FrameLayout.LayoutParams.MATCH_PARENT, Gravity.CENTER)); + layout.addView(b); + layout.setBackgroundColor(0xffffffff); + + setContentView(layout); + } + + private class PatchView extends View { + private final Drawable mDrawable1; + private final Drawable mDrawable2; + private final Drawable mDrawable3; + + private PatchView(Context context) { + super(context); + Resources res = context.getResources(); + mDrawable1 = res.getDrawable(R.drawable.progress_vertical_holo_dark); + mDrawable2 = res.getDrawable(R.drawable.scrubber_progress_vertical_holo_dark); + mDrawable3 = res.getDrawable(R.drawable.scrubber_vertical_primary_holo); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + + canvas.translate(100, 100); + mDrawable1.setBounds(0, 0, 33, 120); + mDrawable1.setLevel(5000); + mDrawable1.draw(canvas); + + canvas.translate(20, 0); + mDrawable2.setBounds(0, 0, 33, 120); + mDrawable2.setLevel(5000); + mDrawable2.draw(canvas); + + canvas.translate(20, 0); + mDrawable3.setBounds(0, 0, 33, 120); + mDrawable3.draw(canvas); + } + } +} diff --git a/tools/layoutlib/bridge/resources/bars/hdpi/ic_sysbar_back_default.png b/tools/layoutlib/bridge/resources/bars/hdpi/ic_sysbar_back_default.png Binary files differnew file mode 100644 index 0000000..ac5a97b --- /dev/null +++ b/tools/layoutlib/bridge/resources/bars/hdpi/ic_sysbar_back_default.png diff --git a/tools/layoutlib/bridge/resources/bars/hdpi/ic_sysbar_home_default.png b/tools/layoutlib/bridge/resources/bars/hdpi/ic_sysbar_home_default.png Binary files differnew file mode 100644 index 0000000..a90dc9b --- /dev/null +++ b/tools/layoutlib/bridge/resources/bars/hdpi/ic_sysbar_home_default.png diff --git a/tools/layoutlib/bridge/resources/bars/hdpi/ic_sysbar_recent_default.png b/tools/layoutlib/bridge/resources/bars/hdpi/ic_sysbar_recent_default.png Binary files differnew file mode 100644 index 0000000..cb3c433 --- /dev/null +++ b/tools/layoutlib/bridge/resources/bars/hdpi/ic_sysbar_recent_default.png diff --git a/tools/layoutlib/bridge/resources/bars/mdpi/ic_sysbar_back_default.png b/tools/layoutlib/bridge/resources/bars/mdpi/ic_sysbar_back_default.png Binary files differindex 4bcd2be..5ab09f0 100644 --- a/tools/layoutlib/bridge/resources/bars/mdpi/ic_sysbar_back_default.png +++ b/tools/layoutlib/bridge/resources/bars/mdpi/ic_sysbar_back_default.png diff --git a/tools/layoutlib/bridge/resources/bars/mdpi/ic_sysbar_home_default.png b/tools/layoutlib/bridge/resources/bars/mdpi/ic_sysbar_home_default.png Binary files differindex cfeba3e..62ca427 100644 --- a/tools/layoutlib/bridge/resources/bars/mdpi/ic_sysbar_home_default.png +++ b/tools/layoutlib/bridge/resources/bars/mdpi/ic_sysbar_home_default.png diff --git a/tools/layoutlib/bridge/resources/bars/mdpi/ic_sysbar_recent_default.png b/tools/layoutlib/bridge/resources/bars/mdpi/ic_sysbar_recent_default.png Binary files differindex 1d97e05..ff698fb 100644 --- a/tools/layoutlib/bridge/resources/bars/mdpi/ic_sysbar_recent_default.png +++ b/tools/layoutlib/bridge/resources/bars/mdpi/ic_sysbar_recent_default.png diff --git a/tools/layoutlib/bridge/resources/bars/xhdpi/ic_sysbar_back_default.png b/tools/layoutlib/bridge/resources/bars/xhdpi/ic_sysbar_back_default.png Binary files differnew file mode 100644 index 0000000..4cb305d --- /dev/null +++ b/tools/layoutlib/bridge/resources/bars/xhdpi/ic_sysbar_back_default.png diff --git a/tools/layoutlib/bridge/resources/bars/xhdpi/ic_sysbar_home_default.png b/tools/layoutlib/bridge/resources/bars/xhdpi/ic_sysbar_home_default.png Binary files differnew file mode 100644 index 0000000..31d35c8 --- /dev/null +++ b/tools/layoutlib/bridge/resources/bars/xhdpi/ic_sysbar_home_default.png diff --git a/tools/layoutlib/bridge/resources/bars/xhdpi/ic_sysbar_recent_default.png b/tools/layoutlib/bridge/resources/bars/xhdpi/ic_sysbar_recent_default.png Binary files differnew file mode 100644 index 0000000..f0cc341 --- /dev/null +++ b/tools/layoutlib/bridge/resources/bars/xhdpi/ic_sysbar_recent_default.png diff --git a/tools/layoutlib/bridge/src/android/view/Display_Delegate.java b/tools/layoutlib/bridge/src/android/view/Display_Delegate.java new file mode 100644 index 0000000..83f9cc2 --- /dev/null +++ b/tools/layoutlib/bridge/src/android/view/Display_Delegate.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2011 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.view; + +import com.android.layoutlib.bridge.android.BridgeWindowManager; +import com.android.layoutlib.bridge.impl.RenderAction; +import com.android.tools.layoutlib.annotations.LayoutlibDelegate; + +import android.os.RemoteException; + +/** + * Delegate used to provide new implementation of a select few methods of {@link Display} + * + * Through the layoutlib_create tool, the original methods of Display have been replaced + * by calls to methods of the same name in this delegate class. + * + */ +public class Display_Delegate { + + // ---- Overridden methods ---- + + @LayoutlibDelegate + public static IWindowManager getWindowManager() { + return RenderAction.getCurrentContext().getIWindowManager(); + } + + // ---- Native methods ---- + + @LayoutlibDelegate + /*package*/ static int getDisplayCount() { + return 1; + } + + @LayoutlibDelegate + /** @hide Returns the actual screen size, not including any decor. */ + /*package*/ static int getRealWidth(Display theDisplay) { + // always dynamically query for the current window manager + return RenderAction.getCurrentContext().getIWindowManager().getMetrics().widthPixels; + } + + @LayoutlibDelegate + /** @hide Returns the actual screen size, not including any decor. */ + /*package*/ static int getRealHeight(Display theDisplay) { + // always dynamically query for the current window manager + return RenderAction.getCurrentContext().getIWindowManager().getMetrics().heightPixels; + } + + @LayoutlibDelegate + /** @hide special for when we are faking the screen size. */ + /*package*/ static int getRawWidth(Display theDisplay) { + // same as real since we're not faking compatibility mode. + return getRealWidth(theDisplay); + } + + @LayoutlibDelegate + /** @hide special for when we are faking the screen size. */ + /*package*/ static int getRawHeight(Display theDisplay) { + // same as real since we're not faking compatibility mode. + return getRealHeight(theDisplay); + } + + @LayoutlibDelegate + /*package*/ static int getOrientation(Display theDisplay) { + try { + // always dynamically query for the current window manager + return getWindowManager().getRotation(); + } catch (RemoteException e) { + // this will never been thrown since this is not a true RPC. + } + + return Surface.ROTATION_0; + } + + @LayoutlibDelegate + /*package*/ static void nativeClassInit() { + // not needed for now. + } + + @LayoutlibDelegate + /*package*/ static void init(Display theDisplay, int display) { + // always dynamically query for the current window manager + BridgeWindowManager wm = RenderAction.getCurrentContext().getIWindowManager(); + theDisplay.mDensity = wm.getMetrics().density; + theDisplay.mDpiX = wm.getMetrics().xdpi; + theDisplay.mDpiY = wm.getMetrics().ydpi; + } +} diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java index 47fa68e..69e0de9 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java @@ -64,6 +64,7 @@ import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.LayoutInflater; +import android.view.Surface; import android.view.View; import android.view.ViewGroup; @@ -91,7 +92,11 @@ public final class BridgeContext extends Activity { private final Object mProjectKey; private final DisplayMetrics mMetrics; private final RenderResources mRenderResources; + private final Configuration mConfig; private final ApplicationInfo mApplicationInfo; + private final IProjectCallback mProjectCallback; + + private final BridgeWindowManager mIWindowManager; private final Map<Object, Map<String, String>> mDefaultPropMaps = new IdentityHashMap<Object, Map<String,String>>(); @@ -105,7 +110,6 @@ public final class BridgeContext extends Activity { private Map<int[], Map<Integer, TypedArray>> mTypedArrayCache; private BridgeInflater mBridgeInflater; - private final IProjectCallback mProjectCallback; private BridgeContentResolver mContentResolver; private final Stack<BridgeXmlBlockParser> mParserStack = new Stack<BridgeXmlBlockParser>(); @@ -113,28 +117,25 @@ public final class BridgeContext extends Activity { /** * @param projectKey An Object identifying the project. This is used for the cache mechanism. * @param metrics the {@link DisplayMetrics}. - * @param themeName The name of the theme to use. - * @param projectResources the resources of the project. The map contains (String, map) pairs - * where the string is the type of the resource reference used in the layout file, and the - * map contains (String, {@link }) pairs where the key is the resource name, - * and the value is the resource value. - * @param frameworkResources the framework resources. The map contains (String, map) pairs - * where the string is the type of the resource reference used in the layout file, and the map - * contains (String, {@link ResourceValue}) pairs where the key is the resource name, and the - * value is the resource value. - * @param styleInheritanceMap + * @param renderResources the configured resources (both framework and projects) for this + * render. * @param projectCallback + * @param config the Configuration object for this render. * @param targetSdkVersion the targetSdkVersion of the application. */ public BridgeContext(Object projectKey, DisplayMetrics metrics, RenderResources renderResources, IProjectCallback projectCallback, + Configuration config, int targetSdkVersion) { mProjectKey = projectKey; mMetrics = metrics; mProjectCallback = projectCallback; mRenderResources = renderResources; + mConfig = config; + + mIWindowManager = new BridgeWindowManager(mConfig, metrics, Surface.ROTATION_0); mFragments.mCurState = Fragment.CREATED; mFragments.mActivity = this; @@ -151,13 +152,12 @@ public final class BridgeContext extends Activity { */ public void initResources() { AssetManager assetManager = AssetManager.getSystem(); - Configuration config = new Configuration(); mSystemResources = BridgeResources.initSystem( this, assetManager, mMetrics, - config, + mConfig, mProjectCallback); mTheme = mSystemResources.newTheme(); } @@ -197,6 +197,10 @@ public final class BridgeContext extends Activity { return mRenderResources; } + public BridgeWindowManager getIWindowManager() { + return mIWindowManager; + } + public Map<String, String> getDefaultPropMap(Object key) { return mDefaultPropMaps.get(key); } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowManager.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowManager.java new file mode 100644 index 0000000..13cd9ec --- /dev/null +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowManager.java @@ -0,0 +1,455 @@ +/* + * Copyright (C) 2011 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.layoutlib.bridge.android; + +import com.android.internal.view.IInputContext; +import com.android.internal.view.IInputMethodClient; + +import android.content.res.CompatibilityInfo; +import android.content.res.Configuration; +import android.graphics.Bitmap; +import android.graphics.Point; +import android.os.IBinder; +import android.os.RemoteException; +import android.util.DisplayMetrics; +import android.view.Display; +import android.view.Display_Delegate; +import android.view.IApplicationToken; +import android.view.IOnKeyguardExitResult; +import android.view.IRotationWatcher; +import android.view.IWindowManager; +import android.view.IWindowSession; +import android.view.InputChannel; +import android.view.InputDevice; +import android.view.InputEvent; +import android.view.KeyEvent; +import android.view.MotionEvent; + +import java.util.List; + +/** + * Basic implementation of {@link IWindowManager} so that {@link Display} (and + * {@link Display_Delegate}) can return a valid instance. + */ +public class BridgeWindowManager implements IWindowManager { + + private final Configuration mConfig; + private final DisplayMetrics mMetrics; + private final int mRotation; + + public BridgeWindowManager(Configuration config, DisplayMetrics metrics, int rotation) { + mConfig = config; + mMetrics = metrics; + mRotation = rotation; + } + + // custom API. + + public DisplayMetrics getMetrics() { + return mMetrics; + } + + // ---- implementation of IWindowManager that we care about ---- + + public int getRotation() throws RemoteException { + return mRotation; + } + + public int getMaximumSizeDimension() throws RemoteException { + return 0; + } + + public void getDisplaySize(Point arg0) throws RemoteException { + } + + // ---- unused implementation of IWindowManager ---- + + public boolean canStatusBarHide() throws RemoteException { + // TODO Auto-generated method stub + return false; + } + + public void addAppToken(int arg0, IApplicationToken arg1, int arg2, int arg3, boolean arg4) + throws RemoteException { + // TODO Auto-generated method stub + + } + + public void addWindowToken(IBinder arg0, int arg1) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void clearForcedDisplaySize() throws RemoteException { + // TODO Auto-generated method stub + + } + + public void closeSystemDialogs(String arg0) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void disableKeyguard(IBinder arg0, String arg1) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void executeAppTransition() throws RemoteException { + // TODO Auto-generated method stub + + } + + public void exitKeyguardSecurely(IOnKeyguardExitResult arg0) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void freezeRotation() throws RemoteException { + // TODO Auto-generated method stub + + } + + public float getAnimationScale(int arg0) throws RemoteException { + // TODO Auto-generated method stub + return 0; + } + + public float[] getAnimationScales() throws RemoteException { + // TODO Auto-generated method stub + return null; + } + + public int getAppOrientation(IApplicationToken arg0) throws RemoteException { + // TODO Auto-generated method stub + return 0; + } + + public int getDPadKeycodeState(int arg0) throws RemoteException { + // TODO Auto-generated method stub + return 0; + } + + public int getDPadScancodeState(int arg0) throws RemoteException { + // TODO Auto-generated method stub + return 0; + } + + + public InputDevice getInputDevice(int arg0) throws RemoteException { + // TODO Auto-generated method stub + return null; + } + + public int[] getInputDeviceIds() throws RemoteException { + // TODO Auto-generated method stub + return null; + } + + public int getKeycodeState(int arg0) throws RemoteException { + // TODO Auto-generated method stub + return 0; + } + + public int getKeycodeStateForDevice(int arg0, int arg1) throws RemoteException { + // TODO Auto-generated method stub + return 0; + } + + + public int getPendingAppTransition() throws RemoteException { + // TODO Auto-generated method stub + return 0; + } + + + public int getScancodeState(int arg0) throws RemoteException { + // TODO Auto-generated method stub + return 0; + } + + public int getScancodeStateForDevice(int arg0, int arg1) throws RemoteException { + // TODO Auto-generated method stub + return 0; + } + + public int getSwitchState(int arg0) throws RemoteException { + // TODO Auto-generated method stub + return 0; + } + + public int getSwitchStateForDevice(int arg0, int arg1) throws RemoteException { + // TODO Auto-generated method stub + return 0; + } + + public int getTrackballKeycodeState(int arg0) throws RemoteException { + // TODO Auto-generated method stub + return 0; + } + + public int getTrackballScancodeState(int arg0) throws RemoteException { + // TODO Auto-generated method stub + return 0; + } + + public boolean hasKeys(int[] arg0, boolean[] arg1) throws RemoteException { + // TODO Auto-generated method stub + return false; + } + + public boolean inKeyguardRestrictedInputMode() throws RemoteException { + // TODO Auto-generated method stub + return false; + } + + public boolean injectInputEventNoWait(InputEvent arg0) throws RemoteException { + // TODO Auto-generated method stub + return false; + } + + public boolean injectKeyEvent(KeyEvent arg0, boolean arg1) throws RemoteException { + // TODO Auto-generated method stub + return false; + } + + public boolean injectPointerEvent(MotionEvent arg0, boolean arg1) throws RemoteException { + // TODO Auto-generated method stub + return false; + } + + public boolean injectTrackballEvent(MotionEvent arg0, boolean arg1) throws RemoteException { + // TODO Auto-generated method stub + return false; + } + + public boolean inputMethodClientHasFocus(IInputMethodClient arg0) throws RemoteException { + // TODO Auto-generated method stub + return false; + } + + public boolean isKeyguardLocked() throws RemoteException { + // TODO Auto-generated method stub + return false; + } + + public boolean isKeyguardSecure() throws RemoteException { + // TODO Auto-generated method stub + return false; + } + + public boolean isViewServerRunning() throws RemoteException { + // TODO Auto-generated method stub + return false; + } + + public InputChannel monitorInput(String arg0) throws RemoteException { + // TODO Auto-generated method stub + return null; + } + + public void moveAppToken(int arg0, IBinder arg1) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void moveAppTokensToBottom(List<IBinder> arg0) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void moveAppTokensToTop(List<IBinder> arg0) throws RemoteException { + // TODO Auto-generated method stub + + } + + public IWindowSession openSession(IInputMethodClient arg0, IInputContext arg1) + throws RemoteException { + // TODO Auto-generated method stub + return null; + } + + public void overridePendingAppTransition(String arg0, int arg1, int arg2) + throws RemoteException { + // TODO Auto-generated method stub + + } + + public void pauseKeyDispatching(IBinder arg0) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void prepareAppTransition(int arg0, boolean arg1) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void reenableKeyguard(IBinder arg0) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void removeAppToken(IBinder arg0) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void removeWindowToken(IBinder arg0) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void resumeKeyDispatching(IBinder arg0) throws RemoteException { + // TODO Auto-generated method stub + + } + + public Bitmap screenshotApplications(IBinder arg0, int arg1, int arg2) throws RemoteException { + // TODO Auto-generated method stub + return null; + } + + public void setAnimationScale(int arg0, float arg1) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void setAnimationScales(float[] arg0) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void setAppGroupId(IBinder arg0, int arg1) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void setAppOrientation(IApplicationToken arg0, int arg1) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void setAppStartingWindow(IBinder arg0, String arg1, int arg2, CompatibilityInfo arg3, + CharSequence arg4, int arg5, int arg6, int arg7, IBinder arg8, boolean arg9) + throws RemoteException { + // TODO Auto-generated method stub + + } + + public void setAppVisibility(IBinder arg0, boolean arg1) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void setAppWillBeHidden(IBinder arg0) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void setEventDispatching(boolean arg0) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void setFocusedApp(IBinder arg0, boolean arg1) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void setForcedDisplaySize(int arg0, int arg1) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void setInTouchMode(boolean arg0) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void setNewConfiguration(Configuration arg0) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void setPointerSpeed(int arg0) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void setRotation(int arg0, boolean arg1, int arg2) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void setStrictModeVisualIndicatorPreference(String arg0) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void showStrictModeViolation(boolean arg0) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void startAppFreezingScreen(IBinder arg0, int arg1) throws RemoteException { + // TODO Auto-generated method stub + + } + + public boolean startViewServer(int arg0) throws RemoteException { + // TODO Auto-generated method stub + return false; + } + + public void statusBarVisibilityChanged(int arg0) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void stopAppFreezingScreen(IBinder arg0, boolean arg1) throws RemoteException { + // TODO Auto-generated method stub + + } + + public boolean stopViewServer() throws RemoteException { + // TODO Auto-generated method stub + return false; + } + + public void thawRotation() throws RemoteException { + // TODO Auto-generated method stub + + } + + public Configuration updateOrientationFromAppTokens(Configuration arg0, IBinder arg1) + throws RemoteException { + // TODO Auto-generated method stub + return null; + } + + public int watchRotation(IRotationWatcher arg0) throws RemoteException { + // TODO Auto-generated method stub + return 0; + } + + public IBinder asBinder() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java index 6194f5d..20f7195 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java @@ -27,10 +27,14 @@ import com.android.ide.common.rendering.api.Result; import com.android.ide.common.rendering.api.RenderResources.FrameworkResourceIdProvider; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.android.BridgeContext; +import com.android.resources.Density; import com.android.resources.ResourceType; +import com.android.resources.ScreenSize; +import android.content.res.Configuration; import android.os.HandlerThread_Delegate; import android.util.DisplayMetrics; +import android.view.ViewConfiguration; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; @@ -94,24 +98,29 @@ public abstract class RenderAction<T extends RenderParams> extends FrameworkReso // setup the display Metrics. DisplayMetrics metrics = new DisplayMetrics(); metrics.densityDpi = mParams.getDensity().getDpiValue(); - metrics.density = metrics.densityDpi / (float) DisplayMetrics.DENSITY_DEFAULT; - metrics.scaledDensity = metrics.density; - metrics.widthPixels = mParams.getScreenWidth(); - metrics.heightPixels = mParams.getScreenHeight(); - metrics.xdpi = mParams.getXdpi(); - metrics.ydpi = mParams.getYdpi(); + + metrics.density = metrics.noncompatDensity = + metrics.densityDpi / (float) DisplayMetrics.DENSITY_DEFAULT; + + metrics.scaledDensity = metrics.noncompatScaledDensity = metrics.density; + + metrics.widthPixels = metrics.noncompatWidthPixels = mParams.getScreenWidth(); + metrics.heightPixels = metrics.noncompatHeightPixels = mParams.getScreenHeight(); + metrics.xdpi = metrics.noncompatXdpi = mParams.getXdpi(); + metrics.ydpi = metrics.noncompatYdpi = mParams.getYdpi(); RenderResources resources = mParams.getResources(); // build the context mContext = new BridgeContext(mParams.getProjectKey(), metrics, resources, - mParams.getProjectCallback(), mParams.getTargetSdkVersion()); + mParams.getProjectCallback(), getConfiguration(), mParams.getTargetSdkVersion()); setUp(); return SUCCESS.createResult(); } + /** * Prepares the scene for action. * <p> @@ -233,6 +242,9 @@ public abstract class RenderAction<T extends RenderParams> extends FrameworkReso // quit HandlerThread created during this session. HandlerThread_Delegate.cleanUp(sCurrentContext); + // clear the stored ViewConfiguration since the map is per density and not per context. + ViewConfiguration.sConfigurations.clear(); + sCurrentContext = null; Bridge.setLog(null); @@ -281,6 +293,50 @@ public abstract class RenderAction<T extends RenderParams> extends FrameworkReso } } + private Configuration getConfiguration() { + Configuration config = new Configuration(); + + ScreenSize screenSize = mParams.getConfigScreenSize(); + if (screenSize != null) { + switch (screenSize) { + case SMALL: + config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_SMALL; + break; + case NORMAL: + config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_NORMAL; + break; + case LARGE: + config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_LARGE; + break; + case XLARGE: + config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_XLARGE; + break; + } + } + + Density density = mParams.getDensity(); + if (density == null) { + density = Density.MEDIUM; + } + + config.screenWidthDp = mParams.getScreenWidth() / density.getDpiValue(); + config.screenHeightDp = mParams.getScreenHeight() / density.getDpiValue(); + if (config.screenHeightDp < config.screenWidthDp) { + config.smallestScreenWidthDp = config.screenHeightDp; + } else { + config.smallestScreenWidthDp = config.screenWidthDp; + } + + // never run in compat mode: + config.compatScreenWidthDp = config.screenWidthDp; + config.compatScreenHeightDp = config.screenHeightDp; + + // TODO: fill in more config info. + + return config; + } + + // --- FrameworkResourceIdProvider methods @Override diff --git a/tools/layoutlib/bridge/tests/.classpath b/tools/layoutlib/bridge/tests/.classpath index 9cc2433..027bc67 100644 --- a/tools/layoutlib/bridge/tests/.classpath +++ b/tools/layoutlib/bridge/tests/.classpath @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> + <classpathentry kind="src" path="res"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry combineaccessrules="false" kind="src" path="/layoutlib_bridge"/> <classpathentry kind="var" path="ANDROID_PLAT_SRC/prebuilt/common/kxml2/kxml2-2.3.0.jar" sourcepath="/ANDROID_PLAT_SRC/dalvik/libcore/xml/src/main/java"/> diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java index 233f72e..f385805 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java @@ -103,6 +103,7 @@ public final class CreateInfo implements ICreateInfo { "android.os.Handler#sendMessageAtTime", "android.os.HandlerThread#run", "android.os.Build#getString", + "android.view.Display#getWindowManager", "android.view.LayoutInflater#rInflate", "android.view.LayoutInflater#parseInclude", "android.view.View#isInEditMode", @@ -154,6 +155,7 @@ public final class CreateInfo implements ICreateInfo { "android.graphics.Xfermode", "android.os.SystemClock", "android.util.FloatMath", + "android.view.Display", "libcore.icu.ICU", }; |
