Merge "Layoutlib: Typeface support for loading fonts manually."
diff --git a/Android.mk b/Android.mk
index be8c25b..c8b2555 100644
--- a/Android.mk
+++ b/Android.mk
@@ -400,6 +400,8 @@
 		            resources/samples/AccessibilityService "Accessibility Service" \
 		-samplecode $(sample_dir)/AccelerometerPlay \
 		            resources/samples/AccelerometerPlay "Accelerometer Play" \
+                -samplecode $(sample_dir)/AndroidBeam \
+		            resources/samples/AndroidBeam "Android Beam" \
 		-samplecode $(sample_dir)/ApiDemos \
 		            resources/samples/ApiDemos "API Demos" \
 		-samplecode $(sample_dir)/Support4Demos \
diff --git a/cmds/bu/src/com/android/commands/bu/Backup.java b/cmds/bu/src/com/android/commands/bu/Backup.java
index 4c4bf98..046ccca 100644
--- a/cmds/bu/src/com/android/commands/bu/Backup.java
+++ b/cmds/bu/src/com/android/commands/bu/Backup.java
@@ -66,6 +66,7 @@
         boolean saveApks = false;
         boolean saveShared = false;
         boolean doEverything = false;
+        boolean allIncludesSystem = true;
 
         String arg;
         while ((arg = nextArg()) != null) {
@@ -78,6 +79,10 @@
                     saveShared = true;
                 } else if ("-noshared".equals(arg)) {
                     saveShared = false;
+                } else if ("-system".equals(arg)) {
+                    allIncludesSystem = true;
+                } else if ("-nosystem".equals(arg)) {
+                    allIncludesSystem = false;
                 } else if ("-all".equals(arg)) {
                     doEverything = true;
                 } else {
@@ -102,7 +107,7 @@
         try {
             ParcelFileDescriptor fd = ParcelFileDescriptor.adoptFd(socketFd);
             String[] packArray = new String[packages.size()];
-            mBackupManager.fullBackup(fd, saveApks, saveShared, doEverything,
+            mBackupManager.fullBackup(fd, saveApks, saveShared, doEverything, allIncludesSystem,
                     packages.toArray(packArray));
         } catch (RemoteException e) {
             Log.e(TAG, "Unable to invoke backup manager for backup");
diff --git a/core/java/android/app/backup/IBackupManager.aidl b/core/java/android/app/backup/IBackupManager.aidl
index c154296..acdd0b5 100644
--- a/core/java/android/app/backup/IBackupManager.aidl
+++ b/core/java/android/app/backup/IBackupManager.aidl
@@ -157,11 +157,15 @@
      * @param allApps If <code>true</code>, the resulting tar stream will include all
      *     installed applications' data, not just those named in the <code>packageNames</code>
      *     parameter.
+     * @param allIncludesSystem If {@code true}, then {@code allApps} will be interpreted
+     *     as including packages pre-installed as part of the system. If {@code false},
+     *     then setting {@code allApps} to {@code true} will mean only that all 3rd-party
+     *     applications will be included in the dataset.
      * @param packageNames The package names of the apps whose data (and optionally .apk files)
      *     are to be backed up.  The <code>allApps</code> parameter supersedes this.
      */
     void fullBackup(in ParcelFileDescriptor fd, boolean includeApks, boolean includeShared,
-            boolean allApps, in String[] packageNames);
+            boolean allApps, boolean allIncludesSystem, in String[] packageNames);
 
     /**
      * Restore device content from the data stream passed through the given socket.  The
diff --git a/core/java/android/inputmethodservice/KeyboardView.java b/core/java/android/inputmethodservice/KeyboardView.java
index 1119c1e..5343e2a 100644
--- a/core/java/android/inputmethodservice/KeyboardView.java
+++ b/core/java/android/inputmethodservice/KeyboardView.java
@@ -248,6 +248,8 @@
     private AccessibilityManager mAccessibilityManager;
     /** The audio manager for accessibility support */
     private AudioManager mAudioManager;
+    /** Whether the requirement of a headset to hear passwords if accessibility is enabled is announced. */
+    private boolean mHeadsetRequiredToHearPasswordsAnnounced;
 
     Handler mHandler = new Handler() {
         @Override
@@ -852,13 +854,15 @@
                 Key oldKey = keys[oldKeyIndex];
                 oldKey.onReleased(mCurrentKeyIndex == NOT_A_KEY);
                 invalidateKey(oldKeyIndex);
-                sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT, oldKey.codes[0]);
+                sendAccessibilityEventForUnicodeCharacter(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT,
+                        oldKey.codes[0]);
             }
             if (mCurrentKeyIndex != NOT_A_KEY && keys.length > mCurrentKeyIndex) {
                 Key newKey = keys[mCurrentKeyIndex];
                 newKey.onPressed();
                 invalidateKey(mCurrentKeyIndex);
-                sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER, newKey.codes[0]);
+                sendAccessibilityEventForUnicodeCharacter(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER,
+                        newKey.codes[0]);
             }
         }
         // If key changed and preview is on ...
@@ -958,13 +962,13 @@
         mPreviewText.setVisibility(VISIBLE);
     }
 
-    private void sendAccessibilityEvent(int eventType, int code) {
+    private void sendAccessibilityEventForUnicodeCharacter(int eventType, int code) {
         if (mAccessibilityManager.isEnabled()) {
             AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
             onInitializeAccessibilityEvent(event);
+            String text = null;
             // Add text only if headset is used to avoid leaking passwords.
             if (mAudioManager.isBluetoothA2dpOn() || mAudioManager.isWiredHeadsetOn()) {
-                String text = null;
                 switch (code) {
                     case Keyboard.KEYCODE_ALT:
                         text = mContext.getString(R.string.keyboardview_keycode_alt);
@@ -990,11 +994,17 @@
                     default:
                         text = String.valueOf((char) code);
                 }
-                event.getText().add(text);
+            } else if (!mHeadsetRequiredToHearPasswordsAnnounced) {
+                // We want the waring for required head set to be send with both the
+                // hover enter and hover exit event, so set the flag after the exit.
+                if (eventType == AccessibilityEvent.TYPE_VIEW_HOVER_EXIT) {
+                    mHeadsetRequiredToHearPasswordsAnnounced = true;
+                }
+                text = mContext.getString(R.string.keyboard_headset_required_to_hear_password);
             } else {
-                event.getText().add(mContext.getString(
-                R.string.keyboard_headset_required_to_hear_password));
+                text = mContext.getString(R.string.keyboard_password_character_no_headset);
             }
+            event.getText().add(text);
             mAccessibilityManager.sendAccessibilityEvent(event);
         }
     }
@@ -1134,15 +1144,13 @@
     }
 
     @Override
-    protected boolean dispatchHoverEvent(MotionEvent event) {
+    public boolean onHoverEvent(MotionEvent event) {
         // If touch exploring is enabled we ignore touch events and transform
         // the stream of hover events as touch events. This allows one consistent
         // event stream to drive the keyboard since during touch exploring the
         // first touch generates only hover events and tapping on the same
         // location generates hover and touch events.
-        if (mAccessibilityManager.isEnabled()
-                && mAccessibilityManager.isTouchExplorationEnabled()
-                && event.getPointerCount() == 1) {
+        if (mAccessibilityManager.isTouchExplorationEnabled() && event.getPointerCount() == 1) {
             final int action = event.getAction();
             switch (action) {
                 case MotionEvent.ACTION_HOVER_ENTER:
@@ -1156,9 +1164,9 @@
                     break;
             }
             onTouchEventInternal(event);
-            return true;
+            event.setAction(action);
         }
-        return super.dispatchHoverEvent(event);
+        return super.onHoverEvent(event);
     }
 
     @Override
@@ -1168,8 +1176,7 @@
         // event stream to drive the keyboard since during touch exploring the
         // first touch generates only hover events and tapping on the same
         // location generates hover and touch events.
-        if (mAccessibilityManager.isEnabled()
-                && mAccessibilityManager.isTouchExplorationEnabled()) {
+        if (mAccessibilityManager.isTouchExplorationEnabled()) {
             return true;
         }
         return onTouchEventInternal(event);
diff --git a/core/java/android/text/DynamicLayout.java b/core/java/android/text/DynamicLayout.java
index c3a2308..f82c9c4 100644
--- a/core/java/android/text/DynamicLayout.java
+++ b/core/java/android/text/DynamicLayout.java
@@ -76,7 +76,7 @@
                          boolean includepad,
                          TextUtils.TruncateAt ellipsize, int ellipsizedWidth) {
         this(base, display, paint, width, align, TextDirectionHeuristics.FIRSTSTRONG_LTR,
-                spacingmult, spacingadd, includepad, ellipsize, ellipsizedWidth, Integer.MAX_VALUE);
+                spacingmult, spacingadd, includepad, ellipsize, ellipsizedWidth);
     }
 
     /**
@@ -93,7 +93,7 @@
                          int width, Alignment align, TextDirectionHeuristic textDir,
                          float spacingmult, float spacingadd,
                          boolean includepad,
-                         TextUtils.TruncateAt ellipsize, int ellipsizedWidth, int maxLines) {
+                         TextUtils.TruncateAt ellipsize, int ellipsizedWidth) {
         super((ellipsize == null)
                 ? display
                 : (display instanceof Spanned)
@@ -135,8 +135,6 @@
             mEllipsize = true;
         }
 
-        mMaxLines = maxLines;
-
         // Initial state is a single line with 0 characters (0 to 0),
         // with top at 0 and bottom at whatever is natural, and
         // undefined ellipsis.
@@ -285,7 +283,7 @@
         reflowed.generate(text, where, where + after,
                 getPaint(), getWidth(), getAlignment(), getTextDirectionHeuristic(),
                 getSpacingMultiplier(), getSpacingAdd(),
-                false, true, mEllipsizedWidth, mEllipsizeAt, mMaxLines);
+                false, true, mEllipsizedWidth, mEllipsizeAt);
         int n = reflowed.getLineCount();
 
         // If the new layout has a blank line at the end, but it is not
@@ -490,8 +488,6 @@
 
     private int mTopPadding, mBottomPadding;
 
-    private int mMaxLines;
-
     private static StaticLayout sStaticLayout = new StaticLayout(null);
 
     private static final Object[] sLock = new Object[0];
diff --git a/core/java/android/text/StaticLayout.java b/core/java/android/text/StaticLayout.java
index 7c27396..583cbe6 100644
--- a/core/java/android/text/StaticLayout.java
+++ b/core/java/android/text/StaticLayout.java
@@ -139,7 +139,7 @@
 
         generate(source, bufstart, bufend, paint, outerwidth, align, textDir,
                  spacingmult, spacingadd, includepad, includepad,
-                 ellipsizedWidth, ellipsize, mMaximumVisibleLineCount);
+                 ellipsizedWidth, ellipsize);
 
         mMeasured = MeasuredText.recycle(mMeasured);
         mFontMetricsInt = null;
@@ -160,7 +160,7 @@
                         Alignment align, TextDirectionHeuristic textDir,
                         float spacingmult, float spacingadd,
                         boolean includepad, boolean trackpad,
-                        float ellipsizedWidth, TextUtils.TruncateAt ellipsize, int maxLines) {
+                        float ellipsizedWidth, TextUtils.TruncateAt ellipsize) {
         mLineCount = 0;
 
         int v = 0;
@@ -477,13 +477,13 @@
                             width = restWidth;
                         }
                     }
-                    if (mLineCount >= maxLines) {
+                    if (mLineCount >= mMaximumVisibleLineCount) {
                         break;
                     }
                 }
             }
 
-            if (paraEnd != here && mLineCount < maxLines) {
+            if (paraEnd != here && mLineCount < mMaximumVisibleLineCount) {
                 if ((fitTop | fitBottom | fitDescent | fitAscent) == 0) {
                     paint.getFontMetricsInt(fm);
 
@@ -514,7 +514,7 @@
         }
 
         if ((bufEnd == bufStart || source.charAt(bufEnd - 1) == CHAR_NEW_LINE) &&
-                mLineCount < maxLines) {
+                mLineCount < mMaximumVisibleLineCount) {
             // Log.e("text", "output last " + bufEnd);
 
             paint.getFontMetricsInt(fm);
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 17f0e05..f7a9dc1 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -6262,7 +6262,7 @@
             result = new DynamicLayout(mText, mTransformed, mTextPaint, w,
                     alignment, mTextDir, mSpacingMult,
                     mSpacingAdd, mIncludePad, mInput == null ? effectiveEllipsize : null,
-                            ellipsisWidth, mMaxMode == LINES ? mMaximum : Integer.MAX_VALUE);
+                            ellipsisWidth);
         } else {
             if (boring == UNKNOWN_BORING) {
                 boring = BoringLayout.isBoring(mTransformed, mTextPaint, mTextDir, mBoring);
diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java
index 2694aa2..d5450e4 100644
--- a/core/java/com/android/internal/widget/LockPatternUtils.java
+++ b/core/java/com/android/internal/widget/LockPatternUtils.java
@@ -119,6 +119,8 @@
     private final static String LOCKSCREEN_OPTIONS = "lockscreen.options";
     public final static String LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK
             = "lockscreen.biometric_weak_fallback";
+    public final static String BIOMETRIC_WEAK_EVER_CHOSEN_KEY
+            = "lockscreen.biometricweakeverchosen";
 
     private final static String PASSWORD_HISTORY_KEY = "lockscreen.passwordhistory";
 
@@ -341,6 +343,16 @@
     }
 
     /**
+     * Return true if the user has ever chosen biometric weak.  This is true even if biometric
+     * weak is not current set.
+     *
+     * @return True if the user has ever chosen biometric weak.
+     */
+    public boolean isBiometricWeakEverChosen() {
+        return getBoolean(BIOMETRIC_WEAK_EVER_CHOSEN_KEY);
+    }
+
+    /**
      * Used by device policy manager to validate the current password
      * information it has.
      */
@@ -489,6 +501,7 @@
                     setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK);
                     setLong(PASSWORD_TYPE_ALTERNATE_KEY,
                             DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
+                    setBoolean(BIOMETRIC_WEAK_EVER_CHOSEN_KEY, true);
                     moveTempGallery();
                 }
                 dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, pattern
@@ -606,6 +619,7 @@
                 } else {
                     setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK);
                     setLong(PASSWORD_TYPE_ALTERNATE_KEY, Math.max(quality, computedQuality));
+                    setBoolean(BIOMETRIC_WEAK_EVER_CHOSEN_KEY, true);
                     moveTempGallery();
                 }
                 if (computedQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 86ce5ef..b1dc252 100755
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -943,15 +943,16 @@
 
     <!-- Title of the read social stream permission, listed so the user can decide whether to allow the application to read information from the user's social stream. [CHAR LIMIT=30] -->
     <string name="permlab_readSocialStream" product="default">read your social stream</string>
-    <string name="permdesc_readSocialStream" product="default">Allows the application to access and
-        sync social updates from your friends.  Malicious apps can use this to access private
-        communications between you and your friends on social networks.</string>
+    <string name="permdesc_readSocialStream" product="default">Allows the application to access
+        and sync social updates from you and your friends. Malicious apps can use this to read
+        private communications between you and your friends on social networks.</string>
 
     <!-- Title of the write social stream permission, listed so the user can decide whether to allow the application to write information to the user's social stream. [CHAR LIMIT=30] -->
     <string name="permlab_writeSocialStream" product="default">write to your social stream</string>
-    <string name="permdesc_writeSocialStream" product="default">Allows the application to provide
-        social updates from your friends.  Malicious apps can use this to fake updates from your
-        friends, for instance to phish confidential information from you.</string>
+    <string name="permdesc_writeSocialStream" product="default">Allows the application to display
+        social updates from your friends. Malicious apps can use this to pretend to be a friend
+        and trick you into revealing passwords or other confidential information.</string>
+
     
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_readCalendar">read calendar events plus confidential information</string>
@@ -3228,8 +3229,9 @@
     <string name="description_target_soundon">Sound on</string>
 
     <!-- Announce that a headset is required to hear keyboard keys while typing a password. [CHAR LIMIT=NONE] -->
-    <string name="keyboard_headset_required_to_hear_password">Key. Headset required to hear
-    keys while typing a password.</string>
+    <string name="keyboard_headset_required_to_hear_password">Plug in a headset to hear password keys spoken aloud.</string>
+    <!-- The value of a keyboard key announced when accessibility is enabled and no headsed is used. [CHAR LIMIT=NONE] -->
+    <string name="keyboard_password_character_no_headset">Dot.</string>
 
     <!-- Content description for the action bar "home" affordance. [CHAR LIMIT=NONE] -->
     <string name="action_bar_home_description">Navigate home</string>
diff --git a/docs/html/resources/resources-data.js b/docs/html/resources/resources-data.js
index 6c5d882..d7700ee 100644
--- a/docs/html/resources/resources-data.js
+++ b/docs/html/resources/resources-data.js
@@ -408,6 +408,16 @@
     }
   },
   {
+    tags: ['sample', 'new'],
+    path: 'samples/AndroidBeam/index.html',
+    title: {
+      en: 'Android Beam'
+    },
+    description: {
+      en: 'An example of how to use the Android Beam feature to send messages between two Android-powered devices (API level 14 or later) that support NFC.'
+    }
+  },
+  {
     tags: ['sample', 'layout', 'ui'],
     path: 'samples/ApiDemos/index.html',
     title: {
diff --git a/services/java/com/android/server/BackupManagerService.java b/services/java/com/android/server/BackupManagerService.java
index fe49cd2..7b8657a 100644
--- a/services/java/com/android/server/BackupManagerService.java
+++ b/services/java/com/android/server/BackupManagerService.java
@@ -325,14 +325,16 @@
         public boolean includeApks;
         public boolean includeShared;
         public boolean allApps;
+        public boolean includeSystem;
         public String[] packages;
 
         FullBackupParams(ParcelFileDescriptor output, boolean saveApks, boolean saveShared,
-                boolean doAllApps, String[] pkgList) {
+                boolean doAllApps, boolean doSystem, String[] pkgList) {
             fd = output;
             includeApks = saveApks;
             includeShared = saveShared;
             allApps = doAllApps;
+            includeSystem = doSystem;
             packages = pkgList;
         }
     }
@@ -504,7 +506,7 @@
                 PerformFullBackupTask task = new PerformFullBackupTask(params.fd,
                         params.observer, params.includeApks,
                         params.includeShared, params.curPassword, params.encryptPassword,
-                        params.allApps, params.packages, params.latch);
+                        params.allApps, params.includeSystem, params.packages, params.latch);
                 (new Thread(task)).start();
                 break;
             }
@@ -2161,6 +2163,7 @@
         boolean mIncludeApks;
         boolean mIncludeShared;
         boolean mAllApps;
+        final boolean mIncludeSystem;
         String[] mPackages;
         String mCurrentPassword;
         String mEncryptPassword;
@@ -2219,13 +2222,14 @@
 
         PerformFullBackupTask(ParcelFileDescriptor fd, IFullBackupRestoreObserver observer, 
                 boolean includeApks, boolean includeShared, String curPassword,
-                String encryptPassword, boolean doAllApps, String[] packages,
+                String encryptPassword, boolean doAllApps, boolean doSystem, String[] packages,
                 AtomicBoolean latch) {
             mOutputFile = fd;
             mObserver = observer;
             mIncludeApks = includeApks;
             mIncludeShared = includeShared;
             mAllApps = doAllApps;
+            mIncludeSystem = doSystem;
             mPackages = packages;
             mCurrentPassword = curPassword;
             // when backing up, if there is a current backup password, we require that
@@ -2245,7 +2249,7 @@
 
         @Override
         public void run() {
-            final List<PackageInfo> packagesToBackup;
+            List<PackageInfo> packagesToBackup = new ArrayList<PackageInfo>();
 
             Slog.i(TAG, "--- Performing full-dataset backup ---");
             sendStartBackup();
@@ -2254,8 +2258,23 @@
             if (mAllApps) {
                 packagesToBackup = mPackageManager.getInstalledPackages(
                         PackageManager.GET_SIGNATURES);
-            } else {
-                packagesToBackup = new ArrayList<PackageInfo>();
+                // Exclude system apps if we've been asked to do so
+                if (mIncludeSystem == false) {
+                    for (int i = 0; i < packagesToBackup.size(); ) {
+                        PackageInfo pkg = packagesToBackup.get(i);
+                        if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
+                            packagesToBackup.remove(i);
+                        } else {
+                            i++;
+                        }
+                    }
+                }
+            }
+
+            // Now process the command line argument packages, if any. Note that explicitly-
+            // named system-partition packages will be included even if includeSystem was
+            // set to false.
+            if (mPackages != null) {
                 for (String pkgName : mPackages) {
                     try {
                         packagesToBackup.add(mPackageManager.getPackageInfo(pkgName,
@@ -2268,8 +2287,8 @@
 
             // Cull any packages that have indicated that backups are not permitted.
             for (int i = 0; i < packagesToBackup.size(); ) {
-                PackageInfo info = packagesToBackup.get(i);
-                if ((info.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) == 0) {
+                PackageInfo pkg = packagesToBackup.get(i);
+                if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) == 0) {
                     packagesToBackup.remove(i);
                 } else {
                     i++;
@@ -4781,7 +4800,7 @@
     // to the supplied file descriptor.  This method is synchronous and does not return
     // to the caller until the backup has been completed.
     public void fullBackup(ParcelFileDescriptor fd, boolean includeApks, boolean includeShared,
-            boolean doAllApps, String[] pkgList) {
+            boolean doAllApps, boolean includeSystem, String[] pkgList) {
         mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "fullBackup");
 
         // Validate
@@ -4811,7 +4830,7 @@
             Slog.i(TAG, "Beginning full backup...");
 
             FullBackupParams params = new FullBackupParams(fd, includeApks, includeShared,
-                    doAllApps, pkgList);
+                    doAllApps, includeSystem, pkgList);
             final int token = generateToken();
             synchronized (mFullConfirmations) {
                 mFullConfirmations.put(token, params);
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index 3ea9e81..73ac296 100644
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -5704,6 +5704,7 @@
 
     Configuration computeNewConfigurationLocked() {
         Configuration config = new Configuration();
+        config.fontScale = 0;
         if (!computeNewConfigurationLocked(config)) {
             return null;
         }