Merge "Merge "AudioAttributes docs: warn about small buffer size with FLAG_LOW_LATENCY" into nyc-dev am: d34d06606d am: 4eccbbf926" into nyc-mr1-dev-plus-aosp
diff --git a/core/java/android/bluetooth/IBluetoothManager.aidl b/core/java/android/bluetooth/IBluetoothManager.aidl
index 0b81ee8..2b853a3 100644
--- a/core/java/android/bluetooth/IBluetoothManager.aidl
+++ b/core/java/android/bluetooth/IBluetoothManager.aidl
@@ -37,6 +37,7 @@
     boolean enable();
     boolean enableNoAutoConnect();
     boolean disable(boolean persist);
+    int getState();
     IBluetoothGatt getBluetoothGatt();
 
     boolean bindBluetoothProfileService(int profile, IBluetoothProfileServiceConnection proxy);
diff --git a/core/res/res/drawable-nodpi/default_wallpaper.png b/core/res/res/drawable-nodpi/default_wallpaper.png
index 91ad252..ce546f0 100644
--- a/core/res/res/drawable-nodpi/default_wallpaper.png
+++ b/core/res/res/drawable-nodpi/default_wallpaper.png
Binary files differ
diff --git a/docs/html/training/basics/firstapp/building-ui.jd b/docs/html/training/basics/firstapp/building-ui.jd
index 402396e..275500c 100644
--- a/docs/html/training/basics/firstapp/building-ui.jd
+++ b/docs/html/training/basics/firstapp/building-ui.jd
@@ -396,20 +396,13 @@
 <h2>Run Your App</h2>
 
 <p>This layout is applied by the default {@link android.app.Activity} class
-that the SDK tools generated when you created the project. Run the app to see the
-results:</p>
+that the SDK tools generated when you created the project.</p>
 
-<ul>
-  <li>In Android Studio, from the toolbar, click <strong>Run</strong>
+<p>To run the app and see the results,
+  click <strong>Run 'app'</strong>
     <img src="{@docRoot}images/tools/as-run.png"
-    style="vertical-align:baseline;margin:0; max-height:1em" />.</li>
-  <li>Or from a command line, change directories to the root of your Android project and
-execute:
-<pre class="no-pretty-print">
-$ ant debug
-adb install -r app/build/outputs/apk/app-debug.apk
-</pre></li>
-</ul>
+    style="vertical-align:baseline;margin:0; max-height:1em" /> in the
+    toolbar.</p>
 
 <p>Continue to the <a href="starting-activity.html">next
 lesson</a> to learn how to respond to button presses, read content
diff --git a/docs/html/training/basics/firstapp/running-app.jd b/docs/html/training/basics/firstapp/running-app.jd
index 99b38bf..21fb64d 100755
--- a/docs/html/training/basics/firstapp/running-app.jd
+++ b/docs/html/training/basics/firstapp/running-app.jd
@@ -76,46 +76,6 @@
 <p>Android Studio installs the app on your connected device and starts it.</p>
 
 
-<h3>Run the app from a command line</h3>
-
-<p>Open a command-line and navigate to the root of your project directory.
-  Use Gradle to build your project in debug mode, invoke the <code>assembleDebug</code> build task
-  using the Gradle wrapper script (<code>gradlew assembleRelease</code>).
-
-  <p>This creates your debug <code>.apk</code> file inside the module <code>build/</code>
-  directory, named <code>app-debug.apk</code>.  </p>
-
-  <p>On Windows platforms, type this command:</p>
-
-<pre>
-> gradlew.bat assembleDebug
-</pre>
-
-<p>On Mac OS and Linux platforms, type these commands:</p>
-
-<pre>
-$ chmod +x gradlew
-$ ./gradlew assembleDebug
-</pre>
-
-  <p>After you build the project, the output APK for the app module is located in
-  <code>app/build/outputs/apk/</code>
-
-  <p class="note"><strong>Note:</strong> The first command (<code>chmod</code>) adds the execution
-  permission to the Gradle wrapper script and is only necessary the first time you build this
-  project from the command line.</p>
-
-  <p>Make sure the Android SDK <code>platform-tools/</code> directory is included in your
-  <code>PATH</code> environment variable, then execute:
-  <pre class="no-pretty-print">$ adb install app/build/outputs/apk/app-debug.apk</pre><p>
-  <p>On your device, locate <em>MyFirstApp</em> and open it.</p>
-
-<p>That's how you build and run your Android app on a device!
-  To start developing, continue to the <a href="building-ui.html">next
-lesson</a>.</p>
-
-
-
 <h2 id="Emulator">Run on the Emulator</h2>
 
 <p>Whether you're using Android Studio or the command line, to run your app on the emulator you need
@@ -168,23 +128,8 @@
 When you do, <em>My First App</em> appears on the emulator screen.</p>
 
 
-<h3>Run your app from the command line</h3>
- <ol>
-  <li>Build the project from the command line. The output APK for the app module is located in
-  <code>app/build/outputs/apk/</code>.</li>
-  <li>Make sure the Android SDK <code>platform-tools/</code> directory is included in your
-  <code>PATH</code> environment variable.</li>
-  <li>Execute this command:
-   <p>
-   <pre class="no-pretty-print">$ adb install app/build/outputs/apk/apk-debug.apk</pre>
-   </p>
-  </li>
-  <li>On the emulator, locate <em>MyFirstApp</em> and open it.</li>
- </ol>
-
-
-  <p>That's how you build and run your Android app on the emulator!
-  To start developing, continue to the <a href="building-ui.html">next
-  lesson</a>.</p>
+<p>That's how you build and run your Android app on the emulator!
+To start developing, continue to the <a href="building-ui.html">next
+lesson</a>.</p>
 
 
diff --git a/packages/SystemUI/src/com/android/systemui/recents/model/TaskStack.java b/packages/SystemUI/src/com/android/systemui/recents/model/TaskStack.java
index 50e28ca..26200d0 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/model/TaskStack.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/model/TaskStack.java
@@ -228,8 +228,8 @@
         /**
          * Notifies when a task has been removed from the stack.
          */
-        void onStackTaskRemoved(TaskStack stack, Task removedTask, boolean wasFrontMostTask,
-            Task newFrontMostTask, AnimationProps animation, boolean fromDockGesture);
+        void onStackTaskRemoved(TaskStack stack, Task removedTask, Task newFrontMostTask,
+                AnimationProps animation, boolean fromDockGesture);
 
         /**
          * Notifies when all tasks have been removed from the stack.
@@ -609,12 +609,11 @@
      */
     public void removeTask(Task t, AnimationProps animation, boolean fromDockGesture) {
         if (mStackTaskList.contains(t)) {
-            boolean wasFrontMostTask = (getStackFrontMostTask(false /* includeFreeform */) == t);
             removeTaskImpl(mStackTaskList, t);
             Task newFrontMostTask = getStackFrontMostTask(false  /* includeFreeform */);
             if (mCb != null) {
                 // Notify that a task has been removed
-                mCb.onStackTaskRemoved(this, t, wasFrontMostTask, newFrontMostTask, animation,
+                mCb.onStackTaskRemoved(this, t, newFrontMostTask, animation,
                         fromDockGesture);
             }
         }
@@ -648,6 +647,7 @@
         ArrayMap<Task.TaskKey, Task> currentTasksMap = createTaskKeyMapFromList(mRawTaskList);
         ArrayMap<Task.TaskKey, Task> newTasksMap = createTaskKeyMapFromList(tasks);
         ArrayList<Task> addedTasks = new ArrayList<>();
+        ArrayList<Task> removedTasks = new ArrayList<>();
         ArrayList<Task> allTasks = new ArrayList<>();
 
         // Disable notifications if there are no callbacks
@@ -661,11 +661,7 @@
             Task task = mRawTaskList.get(i);
             if (!newTasksMap.containsKey(task.key)) {
                 if (notifyStackChanges) {
-                    // If we are notifying, then remove the task now, otherwise the raw task list
-                    // will be reset at the end of this method
-                    removeTask(task, AnimationProps.IMMEDIATE, false /* fromDockGesture */);
-                    mCb.onStackTaskRemoved(this, task, i == (taskCount - 1), null,
-                            AnimationProps.IMMEDIATE, false /* fromDockGesture */);
+                    removedTasks.add(task);
                 }
             }
             task.setGroup(null);
@@ -699,6 +695,14 @@
         // Update the affiliated groupings
         createAffiliatedGroupings(context);
 
+        // Only callback for the removed tasks after the stack has updated
+        int removedTaskCount = removedTasks.size();
+        Task newFrontMostTask = getStackFrontMostTask(false);
+        for (int i = 0; i < removedTaskCount; i++) {
+            mCb.onStackTaskRemoved(this, removedTasks.get(i), newFrontMostTask,
+                    AnimationProps.IMMEDIATE, false /* fromDockGesture */);
+        }
+
         // Only callback for the newly added tasks after this stack has been updated
         int addedTaskCount = addedTasks.size();
         for (int i = 0; i < addedTaskCount; i++) {
diff --git a/packages/SystemUI/src/com/android/systemui/recents/tv/views/TaskStackHorizontalGridView.java b/packages/SystemUI/src/com/android/systemui/recents/tv/views/TaskStackHorizontalGridView.java
index 9f52abd..3fb339e 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/tv/views/TaskStackHorizontalGridView.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/tv/views/TaskStackHorizontalGridView.java
@@ -181,8 +181,8 @@
     }
 
     @Override
-    public void onStackTaskRemoved(TaskStack stack, Task removedTask, boolean wasFrontMostTask,
-            Task newFrontMostTask, AnimationProps animation, boolean fromDockGesture) {
+    public void onStackTaskRemoved(TaskStack stack, Task removedTask, Task newFrontMostTask,
+            AnimationProps animation, boolean fromDockGesture) {
         ((TaskStackHorizontalViewAdapter) getAdapter()).removeTask(removedTask);
         if (mFocusedTask == removedTask) {
             resetFocusedTask(removedTask);
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java
index 1a197b6..0d9f77c 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java
@@ -1400,8 +1400,8 @@
      * We expect that the {@link TaskView} associated with the removed task is already hidden.
      */
     @Override
-    public void onStackTaskRemoved(TaskStack stack, Task removedTask, boolean wasFrontMostTask,
-            Task newFrontMostTask, AnimationProps animation, boolean fromDockGesture) {
+    public void onStackTaskRemoved(TaskStack stack, Task removedTask, Task newFrontMostTask,
+            AnimationProps animation, boolean fromDockGesture) {
         if (mFocusedTask == removedTask) {
             resetFocusedTask(removedTask);
         }
diff --git a/services/core/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java
index 1f88be5..831ce01 100644
--- a/services/core/java/com/android/server/BluetoothManagerService.java
+++ b/services/core/java/com/android/server/BluetoothManagerService.java
@@ -425,6 +425,24 @@
         return false;
     }
 
+    public int getState() {
+        if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
+                (!checkIfCallerIsForegroundUser())) {
+            Slog.w(TAG, "getState(): not allowed for non-active and non system user");
+            return BluetoothAdapter.STATE_OFF;
+        }
+
+        try {
+            mBluetoothLock.readLock().lock();
+            if (mBluetooth != null) return mBluetooth.getState();
+        } catch (RemoteException e) {
+            Slog.e(TAG, "getState()", e);
+        } finally {
+            mBluetoothLock.readLock().unlock();
+        }
+        return BluetoothAdapter.STATE_OFF;
+    }
+
     class ClientDeathRecipient implements IBinder.DeathRecipient {
         public void binderDied() {
             if (DBG) Slog.d(TAG, "Binder is dead -  unregister Ble App");
diff --git a/services/core/java/com/android/server/LockSettingsService.java b/services/core/java/com/android/server/LockSettingsService.java
index fbbdccc..fb1021e 100644
--- a/services/core/java/com/android/server/LockSettingsService.java
+++ b/services/core/java/com/android/server/LockSettingsService.java
@@ -50,6 +50,7 @@
 import android.os.Process;
 import android.os.RemoteException;
 import android.os.storage.IMountService;
+import android.os.storage.StorageManager;
 import android.os.ServiceManager;
 import android.os.SystemProperties;
 import android.os.UserHandle;
@@ -355,6 +356,10 @@
     private void showEncryptionNotification(UserHandle user, CharSequence title, CharSequence message,
             CharSequence detail, PendingIntent intent) {
         if (DEBUG) Slog.v(TAG, "showing encryption notification, user: " + user.getIdentifier());
+
+        // Suppress all notifications on non-FBE devices for now
+        if (!StorageManager.isFileEncryptedNativeOrEmulated()) return;
+
         Notification notification = new Notification.Builder(mContext)
                 .setSmallIcon(com.android.internal.R.drawable.ic_user_secure)
                 .setWhen(0)
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index ed55263..7df0a06 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -5419,9 +5419,32 @@
                 }
             }
 
+            final int pkgUidF = pkgUid;
+            final int userIdF = userId;
+            final IPackageDataObserver localObserver = new IPackageDataObserver.Stub() {
+                @Override
+                public void onRemoveCompleted(String packageName, boolean succeeded)
+                        throws RemoteException {
+                    synchronized (ActivityManagerService.this) {
+                        finishForceStopPackageLocked(packageName, pkgUidF);
+                    }
+
+                    final Intent intent = new Intent(Intent.ACTION_PACKAGE_DATA_CLEARED,
+                            Uri.fromParts("package", packageName, null));
+                    intent.putExtra(Intent.EXTRA_UID, pkgUidF);
+                    intent.putExtra(Intent.EXTRA_USER_HANDLE, UserHandle.getUserId(pkgUidF));
+                    broadcastIntentInPackage("android", Process.SYSTEM_UID, intent,
+                            null, null, 0, null, null, null, null, false, false, userIdF);
+
+                    if (observer != null) {
+                        observer.onRemoveCompleted(packageName, succeeded);
+                    }
+                }
+            };
+
             try {
                 // Clear application user data
-                pm.clearApplicationUserData(packageName, observer, userId);
+                pm.clearApplicationUserData(packageName, localObserver, userId);
 
                 synchronized(this) {
                     // Remove all permissions granted from/to this package
@@ -5433,12 +5456,6 @@
                 inm.removeAutomaticZenRules(packageName);
                 inm.setNotificationPolicyAccessGranted(packageName, false);
 
-                Intent intent = new Intent(Intent.ACTION_PACKAGE_DATA_CLEARED,
-                        Uri.fromParts("package", packageName, null));
-                intent.putExtra(Intent.EXTRA_UID, pkgUid);
-                intent.putExtra(Intent.EXTRA_USER_HANDLE, UserHandle.getUserId(pkgUid));
-                broadcastIntentInPackage("android", Process.SYSTEM_UID, intent,
-                        null, null, 0, null, null, null, null, false, false, userId);
             } catch (RemoteException e) {
             }
         } finally {
@@ -5623,6 +5640,7 @@
                     }
                     if (mUserController.isUserRunningLocked(user, 0)) {
                         forceStopPackageLocked(packageName, pkgUid, "from pid " + callingPid);
+                        finishForceStopPackageLocked(packageName, pkgUid);
                     }
                 }
             }
@@ -5814,6 +5832,9 @@
     private void forceStopPackageLocked(final String packageName, int uid, String reason) {
         forceStopPackageLocked(packageName, UserHandle.getAppId(uid), false,
                 false, true, false, false, UserHandle.getUserId(uid), reason);
+    }
+
+    private void finishForceStopPackageLocked(final String packageName, int uid) {
         Intent intent = new Intent(Intent.ACTION_PACKAGE_RESTARTED,
                 Uri.fromParts("package", packageName, null));
         if (!mProcessesReady) {
@@ -10170,6 +10191,7 @@
             int N = providers.size();
             app.pubProviders.ensureCapacity(N + app.pubProviders.size());
             for (int i=0; i<N; i++) {
+                // TODO: keep logic in sync with installEncryptionUnawareProviders
                 ProviderInfo cpi =
                     (ProviderInfo)providers.get(i);
                 boolean singleton = isSingleton(cpi.processName, cpi.applicationInfo,
@@ -11150,12 +11172,18 @@
                             final PackageInfo pkgInfo = AppGlobals.getPackageManager()
                                     .getPackageInfo(pkgName, matchFlags, userId);
                             if (pkgInfo != null && !ArrayUtils.isEmpty(pkgInfo.providers)) {
-                                for (ProviderInfo provInfo : pkgInfo.providers) {
-                                    if (Objects.equals(provInfo.processName, app.processName)) {
-                                        Log.v(TAG, "Installing " + provInfo);
-                                        app.thread.scheduleInstallProvider(provInfo);
+                                for (ProviderInfo pi : pkgInfo.providers) {
+                                    // TODO: keep in sync with generateApplicationProvidersLocked
+                                    final boolean processMatch = Objects.equals(pi.processName,
+                                            app.processName) || pi.multiprocess;
+                                    final boolean userMatch = isSingleton(pi.processName,
+                                            pi.applicationInfo, pi.name, pi.flags)
+                                                    ? (app.userId == UserHandle.USER_SYSTEM) : true;
+                                    if (processMatch && userMatch) {
+                                        Log.v(TAG, "Installing " + pi);
+                                        app.thread.scheduleInstallProvider(pi);
                                     } else {
-                                        Log.v(TAG, "Skipping " + provInfo);
+                                        Log.v(TAG, "Skipping " + pi);
                                     }
                                 }
                             }
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index c61228d..0c35f50 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -3813,8 +3813,10 @@
 
         @Override
         public void onUserSwitched(int user) {
-            for (ManagedServiceInfo info : mServices) {
-                unregisterService(info.service, info.userid);
+            synchronized (mNotificationList) {
+                for (ManagedServiceInfo info : mServices) {
+                    unregisterService(info.service, info.userid);
+                }
             }
             registerRanker();
         }
diff --git a/services/core/java/com/android/server/power/ShutdownThread.java b/services/core/java/com/android/server/power/ShutdownThread.java
index 5b9d139..8ce2fd9 100644
--- a/services/core/java/com/android/server/power/ShutdownThread.java
+++ b/services/core/java/com/android/server/power/ShutdownThread.java
@@ -543,7 +543,8 @@
                 }
 
                 try {
-                    bluetoothOff = bluetooth == null || !bluetooth.isEnabled();
+                    bluetoothOff = bluetooth == null ||
+                            bluetooth.getState() == BluetoothAdapter.STATE_OFF;
                     if (!bluetoothOff) {
                         Log.w(TAG, "Disabling Bluetooth...");
                         bluetooth.disable(false);  // disable but don't persist new state
@@ -577,7 +578,7 @@
 
                     if (!bluetoothOff) {
                         try {
-                            bluetoothOff = !bluetooth.isEnabled();
+                            bluetoothOff = bluetooth.getState() == BluetoothAdapter.STATE_OFF;
                         } catch (RemoteException ex) {
                             Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
                             bluetoothOff = true;