Merge "Turn on dimension validation in wallpaper restore" into lmp-dev
diff --git a/api/current.txt b/api/current.txt
index 1b07af9..09497a5 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -5587,7 +5587,6 @@
     method public int describeContents();
     method public boolean getNextEvent(android.app.usage.UsageEvents.Event);
     method public boolean hasNextEvent();
-    method public void resetToStart();
     method public void writeToParcel(android.os.Parcel, int);
     field public static final android.os.Parcelable.Creator CREATOR;
   }
diff --git a/core/java/android/app/usage/UsageEvents.java b/core/java/android/app/usage/UsageEvents.java
index 1a947ec..3cf3c95 100644
--- a/core/java/android/app/usage/UsageEvents.java
+++ b/core/java/android/app/usage/UsageEvents.java
@@ -15,7 +15,6 @@
  */
 package android.app.usage;
 
-import android.content.ComponentName;
 import android.content.res.Configuration;
 import android.os.Parcel;
 import android.os.Parcelable;
@@ -95,14 +94,6 @@
         public Configuration mConfiguration;
 
         /**
-         * TODO(adamlesinski): Removed before release.
-         * {@hide}
-         */
-        public ComponentName getComponent() {
-            return new ComponentName(mPackage, mClass);
-        }
-
-        /**
          * The package name of the source of this event.
          */
         public String getPackageName() {
@@ -233,6 +224,9 @@
 
     /**
      * Resets the collection so that it can be iterated over from the beginning.
+     *
+     * @hide When this object is iterated to completion, the parcel is destroyed and
+     * so resetToStart doesn't work.
      */
     public void resetToStart() {
         mIndex = 0;
diff --git a/packages/SystemUI/res/values-lt/strings.xml b/packages/SystemUI/res/values-lt/strings.xml
index 7439b97..b30b80c 100644
--- a/packages/SystemUI/res/values-lt/strings.xml
+++ b/packages/SystemUI/res/values-lt/strings.xml
@@ -31,7 +31,7 @@
   </plurals>
     <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"Nėra įspėjimų"</string>
     <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"Vykstantys"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"Įspėjimai"</string>
+    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"Pranešimai"</string>
     <string name="battery_low_title" msgid="6456385927409742437">"Akumuliatorius senka"</string>
     <string name="battery_low_percent_format" msgid="1077244949318261761">"Liko <xliff:g id="NUMBER">%d%%</xliff:g>"</string>
     <string name="battery_low_percent_format_saver_started" msgid="6534746636002666456">"Liko <xliff:g id="NUMBER">%d%%</xliff:g>. Akumuliatoriaus tausojimo priemonė įjungta."</string>
diff --git a/packages/SystemUI/res/values-sw/strings.xml b/packages/SystemUI/res/values-sw/strings.xml
index e66522f..9ab3d91 100644
--- a/packages/SystemUI/res/values-sw/strings.xml
+++ b/packages/SystemUI/res/values-sw/strings.xml
@@ -181,7 +181,7 @@
     <string name="accessibility_quick_settings_bluetooth_changed_off" msgid="2730003763480934529">"Bluetooth imezimwa."</string>
     <string name="accessibility_quick_settings_bluetooth_changed_on" msgid="8722351798763206577">"Bluetooth imewashwa."</string>
     <string name="accessibility_quick_settings_location_off" msgid="5119080556976115520">"Programu ya Kuonyesha mahali ulipo imezimwa."</string>
-    <string name="accessibility_quick_settings_location_on" msgid="5809937096590102036">"Programu ya Kuonyesha mahali ulipo inawaka."</string>
+    <string name="accessibility_quick_settings_location_on" msgid="5809937096590102036">"Programu ya kuonyesha mahali ulipo imewashwa."</string>
     <string name="accessibility_quick_settings_location_changed_off" msgid="8526845571503387376">"Programu ya Kuonyesha mahali ulipo imezimwa."</string>
     <string name="accessibility_quick_settings_location_changed_on" msgid="339403053079338468">"Programu ya Kuonyesha mahali ulipo imewashwa."</string>
     <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"Kengele imewekwa <xliff:g id="TIME">%s</xliff:g>."</string>
@@ -251,7 +251,7 @@
     <string name="quick_settings_wifi_detail_empty_text" msgid="2831702993995222755">"Hakuna mitandao iliyohifadhiwa inayopatikana"</string>
     <string name="quick_settings_cast_title" msgid="1893629685050355115">"Tuma skrini"</string>
     <string name="quick_settings_casting" msgid="6601710681033353316">"Inatuma"</string>
-    <string name="quick_settings_cast_device_default_name" msgid="5367253104742382945">"Kifaa kisichokuwa na jina"</string>
+    <string name="quick_settings_cast_device_default_name" msgid="5367253104742382945">"Kifaa hakina jina"</string>
     <string name="quick_settings_cast_device_default_description" msgid="2484573682378634413">"Tayari kutuma"</string>
     <string name="quick_settings_cast_detail_empty_text" msgid="311785821261640623">"Hakuna vifaa vilivyopatikana"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Ung\'avu"</string>
diff --git a/services/core/java/com/android/server/MmsServiceBroker.java b/services/core/java/com/android/server/MmsServiceBroker.java
index 0fb80c9..926235f 100644
--- a/services/core/java/com/android/server/MmsServiceBroker.java
+++ b/services/core/java/com/android/server/MmsServiceBroker.java
@@ -34,7 +34,7 @@
 import android.os.IBinder;
 import android.os.Message;
 import android.os.RemoteException;
-import android.os.ServiceManager;
+import android.os.SystemClock;
 import android.telephony.TelephonyManager;
 import android.util.Slog;
 
@@ -56,10 +56,12 @@
     private static final Uri FAKE_SMS_DRAFT_URI = Uri.parse("content://sms/draft/0");
     private static final Uri FAKE_MMS_DRAFT_URI = Uri.parse("content://mms/draft/0");
 
+    private static final long SERVICE_CONNECTION_WAIT_TIME_MS = 4 * 1000L; // 4 seconds
+    private static final long RETRY_DELAY_ON_DISCONNECTION_MS = 3 * 1000L; // 3 seconds
+
     private Context mContext;
     // The actual MMS service instance to invoke
     private volatile IMms mService;
-    private boolean mIsConnecting;
 
     // Cached system service instances
     private volatile AppOpsManager mAppOpsManager = null;
@@ -85,7 +87,7 @@
             Slog.i(TAG, "MmsService connected");
             synchronized (MmsServiceBroker.this) {
                 mService = IMms.Stub.asInterface(service);
-                mIsConnecting = false;
+                MmsServiceBroker.this.notifyAll();
             }
         }
 
@@ -94,8 +96,13 @@
             Slog.i(TAG, "MmsService unexpectedly disconnected");
             synchronized (MmsServiceBroker.this) {
                 mService = null;
-                mIsConnecting = false;
+                MmsServiceBroker.this.notifyAll();
             }
+            // Retry connecting, but not too eager (with a delay)
+            // since it may come back by itself.
+            mConnectionHandler.sendMessageDelayed(
+                    mConnectionHandler.obtainMessage(MSG_TRY_CONNECTING),
+                    RETRY_DELAY_ON_DISCONNECTION_MS);
         }
     };
 
@@ -103,7 +110,6 @@
         super(context);
         mContext = context;
         mService = null;
-        mIsConnecting = false;
     }
 
     @Override
@@ -118,29 +124,50 @@
     private void tryConnecting() {
         Slog.i(TAG, "Connecting to MmsService");
         synchronized (this) {
-            if (mIsConnecting) {
-                Slog.d(TAG, "Already connecting");
+            if (mService != null) {
+                Slog.d(TAG, "Already connected");
                 return;
             }
             final Intent intent = new Intent();
             intent.setComponent(MMS_SERVICE_COMPONENT);
             try {
-                if (mContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE)) {
-                    mIsConnecting = true;
-                } else {
-                    Slog.e(TAG, "Failed to connect to MmsService");
+                if (!mContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE)) {
+                    Slog.e(TAG, "Failed to bind to MmsService");
                 }
             } catch (SecurityException e) {
-                Slog.e(TAG, "Forbidden to connect to MmsService", e);
+                Slog.e(TAG, "Forbidden to bind to MmsService", e);
             }
         }
     }
 
     private void ensureService() {
-        if (mService == null) {
-            // Service instance lost, kicking off the connection again
-            mConnectionHandler.sendMessage(mConnectionHandler.obtainMessage(MSG_TRY_CONNECTING));
-            throw new RuntimeException("MMS service is not connected");
+        synchronized (this) {
+            if (mService == null) {
+                // Service is not connected. Try blocking connecting.
+                Slog.w(TAG, "MmsService not connected. Try connecting...");
+                mConnectionHandler.sendMessage(
+                        mConnectionHandler.obtainMessage(MSG_TRY_CONNECTING));
+                final long shouldEnd =
+                        SystemClock.elapsedRealtime() + SERVICE_CONNECTION_WAIT_TIME_MS;
+                long waitTime = SERVICE_CONNECTION_WAIT_TIME_MS;
+                while (waitTime > 0) {
+                    try {
+                        // TODO: consider using Java concurrent construct instead of raw object wait
+                        this.wait(waitTime);
+                    } catch (InterruptedException e) {
+                        Slog.w(TAG, "Connection wait interrupted", e);
+                    }
+                    if (mService != null) {
+                        // Success
+                        return;
+                    }
+                    // Calculate remaining waiting time to make sure we wait the full timeout period
+                    waitTime = shouldEnd - SystemClock.elapsedRealtime();
+                }
+                // Timed out. Something's really wrong.
+                Slog.e(TAG, "Can not connect to MmsService (timed out)");
+                throw new RuntimeException("Timed out in connecting to MmsService");
+            }
         }
     }
 
diff --git a/services/core/java/com/android/server/job/JobSchedulerService.java b/services/core/java/com/android/server/job/JobSchedulerService.java
index f456bcd..c6d2db2 100644
--- a/services/core/java/com/android/server/job/JobSchedulerService.java
+++ b/services/core/java/com/android/server/job/JobSchedulerService.java
@@ -70,8 +70,7 @@
  */
 public class JobSchedulerService extends com.android.server.SystemService
         implements StateChangedListener, JobCompletedListener {
-    // TODO: Switch this off for final version.
-    static final boolean DEBUG = true;
+    static final boolean DEBUG = false;
     /** The number of concurrent jobs we run at one time. */
     private static final int MAX_JOB_CONTEXTS_COUNT = 3;
     static final String TAG = "JobSchedulerService";
diff --git a/services/core/java/com/android/server/job/JobServiceContext.java b/services/core/java/com/android/server/job/JobServiceContext.java
index 9df21a2..63c8d92 100644
--- a/services/core/java/com/android/server/job/JobServiceContext.java
+++ b/services/core/java/com/android/server/job/JobServiceContext.java
@@ -62,7 +62,7 @@
  *
  */
 public class JobServiceContext extends IJobCallback.Stub implements ServiceConnection {
-    private static final boolean DEBUG = true;
+    private static final boolean DEBUG = false;
     private static final String TAG = "JobServiceContext";
     /** Define the maximum # of jobs allowed to run on a service at once. */
     private static final int defaultMaxActiveJobsPerService =
diff --git a/services/core/java/com/android/server/job/controllers/StateController.java b/services/core/java/com/android/server/job/controllers/StateController.java
index 81658bf..ca56886 100644
--- a/services/core/java/com/android/server/job/controllers/StateController.java
+++ b/services/core/java/com/android/server/job/controllers/StateController.java
@@ -29,7 +29,7 @@
  * are ready to run, or whether they must be stopped.
  */
 public abstract class StateController {
-    protected static final boolean DEBUG = true;
+    protected static final boolean DEBUG = false;
     protected Context mContext;
     protected StateChangedListener mStateChangedListener;