diff options
Diffstat (limited to 'services/java/com')
11 files changed, 99 insertions, 74 deletions
diff --git a/services/java/com/android/server/am/ActiveServices.java b/services/java/com/android/server/am/ActiveServices.java index fa1769f..8f4bf21 100644 --- a/services/java/com/android/server/am/ActiveServices.java +++ b/services/java/com/android/server/am/ActiveServices.java @@ -1839,7 +1839,7 @@ public final class ActiveServices { } } } else { - ServiceMap smap = mServiceMap.valueAt(userId); + ServiceMap smap = mServiceMap.get(userId); if (smap != null) { ArrayMap<ComponentName, ServiceRecord> items = smap.mServicesByName; didSomething = collectForceStopServicesLocked(name, userId, evenPersistent, diff --git a/services/java/com/android/server/am/ActivityStack.java b/services/java/com/android/server/am/ActivityStack.java index 4d66946..dd2f4c4 100644 --- a/services/java/com/android/server/am/ActivityStack.java +++ b/services/java/com/android/server/am/ActivityStack.java @@ -3438,23 +3438,22 @@ final class ActivityStack { // Determine if the top task is exiting and should return to home. Do this before it gets // removed in removeHistoryRecordsForAppsLocked. boolean launchHomeNext = false; - int top = mTaskHistory.size() - 1; - while (top >= 0) { - final TaskRecord topTask = mTaskHistory.get(top); - if (topTask.mActivities.isEmpty()) { - // Not possible, but just in case. - --top; + TaskRecord topTask = mTaskHistory.get(mTaskHistory.size() - 1); + ArrayList<ActivityRecord> activities = topTask.mActivities; + int activityNdx; + for (activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { + ActivityRecord r = activities.get(activityNdx); + if (r.finishing) { continue; } - ActivityRecord r = topTask.topRunningActivityLocked(null); - if (r != null) { - // r will be launched next. + if (r.app != app) { + // This is the dying activity. break; } - // There is an activity in topTask that is finishing. If topTask belongs to the app - // return to home depending on the task flag. + } + if (activityNdx < 0) { + // All activities in task belong to app. Set launchHomeNext to task's value. launchHomeNext = topTask.mOnTopOfHome; - break; } removeHistoryRecordsForAppLocked(app); diff --git a/services/java/com/android/server/am/ActivityStackSupervisor.java b/services/java/com/android/server/am/ActivityStackSupervisor.java index f718706..2db67d5 100644 --- a/services/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/java/com/android/server/am/ActivityStackSupervisor.java @@ -1932,7 +1932,7 @@ public final class ActivityStackSupervisor { for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { final ActivityStack stack = mStacks.get(stackNdx); // Only update launchHomeTaskNext for the focused stack. - launchHomeTaskNext |= (stack == focusedStack && stack.handleAppDiedLocked(app)); + launchHomeTaskNext |= (stack.handleAppDiedLocked(app) && stack == focusedStack); } if (!restarting) { diff --git a/services/java/com/android/server/am/AppErrorDialog.java b/services/java/com/android/server/am/AppErrorDialog.java index bfc86b0..fffa75e 100644 --- a/services/java/com/android/server/am/AppErrorDialog.java +++ b/services/java/com/android/server/am/AppErrorDialog.java @@ -16,7 +16,7 @@ package com.android.server.am; -import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR; +import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR; import android.content.Context; import android.content.DialogInterface; @@ -72,7 +72,7 @@ final class AppErrorDialog extends BaseErrorDialog { } setTitle(res.getText(com.android.internal.R.string.aerr_title)); - getWindow().addFlags(FLAG_SYSTEM_ERROR); + getWindow().addFlags(PRIVATE_FLAG_SYSTEM_ERROR); WindowManager.LayoutParams attrs = getWindow().getAttributes(); attrs.setTitle("Application Error: " + app.info.processName); attrs.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; diff --git a/services/java/com/android/server/am/AppNotRespondingDialog.java b/services/java/com/android/server/am/AppNotRespondingDialog.java index d0a0441..4de272d 100644 --- a/services/java/com/android/server/am/AppNotRespondingDialog.java +++ b/services/java/com/android/server/am/AppNotRespondingDialog.java @@ -16,7 +16,7 @@ package com.android.server.am; -import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR; +import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR; import android.content.ActivityNotFoundException; import android.content.Context; @@ -94,7 +94,7 @@ final class AppNotRespondingDialog extends BaseErrorDialog { if (aboveSystem) { getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); } - getWindow().addFlags(FLAG_SYSTEM_ERROR); + getWindow().addFlags(PRIVATE_FLAG_SYSTEM_ERROR); WindowManager.LayoutParams attrs = getWindow().getAttributes(); attrs.setTitle("Application Not Responding: " + app.info.processName); attrs.privateFlags = WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; diff --git a/services/java/com/android/server/am/StrictModeViolationDialog.java b/services/java/com/android/server/am/StrictModeViolationDialog.java index b6d0daa..5fee0d3 100644 --- a/services/java/com/android/server/am/StrictModeViolationDialog.java +++ b/services/java/com/android/server/am/StrictModeViolationDialog.java @@ -16,14 +16,13 @@ package com.android.server.am; -import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR; +import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR; import android.content.Context; import android.content.DialogInterface; import android.content.res.Resources; import android.os.Handler; import android.os.Message; -import android.util.Slog; final class StrictModeViolationDialog extends BaseErrorDialog { private final static String TAG = "StrictModeViolationDialog"; @@ -75,7 +74,7 @@ final class StrictModeViolationDialog extends BaseErrorDialog { } setTitle(res.getText(com.android.internal.R.string.aerr_title)); - getWindow().addFlags(FLAG_SYSTEM_ERROR); + getWindow().addFlags(PRIVATE_FLAG_SYSTEM_ERROR); getWindow().setTitle("Strict Mode Violation: " + app.info.processName); // After the timeout, pretend the user clicked the quit button diff --git a/services/java/com/android/server/power/PowerManagerService.java b/services/java/com/android/server/power/PowerManagerService.java index fe09a33..2ccd21c 100644 --- a/services/java/com/android/server/power/PowerManagerService.java +++ b/services/java/com/android/server/power/PowerManagerService.java @@ -453,7 +453,8 @@ public final class PowerManagerService extends IPowerManager.Stub mDisplayPowerControllerCallbacks, mHandler); mWirelessChargerDetector = new WirelessChargerDetector(sensorManager, - createSuspendBlockerLocked("PowerManagerService.WirelessChargerDetector")); + createSuspendBlockerLocked("PowerManagerService.WirelessChargerDetector"), + mHandler); mSettingsObserver = new SettingsObserver(mHandler); mAttentionLight = mLightsService.getLight(LightsService.LIGHT_ID_ATTENTION); diff --git a/services/java/com/android/server/power/WirelessChargerDetector.java b/services/java/com/android/server/power/WirelessChargerDetector.java index 35920f7..38f5d77 100644 --- a/services/java/com/android/server/power/WirelessChargerDetector.java +++ b/services/java/com/android/server/power/WirelessChargerDetector.java @@ -21,8 +21,11 @@ import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.os.BatteryManager; +import android.os.Handler; +import android.os.Message; import android.os.SystemClock; import android.util.Slog; +import android.util.TimeUtils; import java.io.PrintWriter; @@ -70,12 +73,12 @@ final class WirelessChargerDetector { private static final String TAG = "WirelessChargerDetector"; private static final boolean DEBUG = false; - // Number of nanoseconds per millisecond. - private static final long NANOS_PER_MS = 1000000; - // The minimum amount of time to spend watching the sensor before making // a determination of whether movement occurred. - private static final long SETTLE_TIME_NANOS = 500 * NANOS_PER_MS; + private static final long SETTLE_TIME_MILLIS = 800; + + // The sensor sampling interval. + private static final int SAMPLING_INTERVAL_MILLIS = 50; // The minimum number of samples that must be collected. private static final int MIN_SAMPLES = 3; @@ -97,6 +100,7 @@ final class WirelessChargerDetector { private final SensorManager mSensorManager; private final SuspendBlocker mSuspendBlocker; + private final Handler mHandler; // The gravity sensor, or null if none. private Sensor mGravitySensor; @@ -116,6 +120,9 @@ final class WirelessChargerDetector { // The suspend blocker is held while this is the case. private boolean mDetectionInProgress; + // The time when detection was last performed. + private long mDetectionStartTime; + // True if the rest position should be updated if at rest. // Otherwise, the current rest position is simply checked and cleared if movement // is detected but no new rest position is stored. @@ -127,18 +134,17 @@ final class WirelessChargerDetector { // The number of samples collected that showed evidence of not being at rest. private int mMovingSamples; - // The time and value of the first sample that was collected. - private long mFirstSampleTime; + // The value of the first sample that was collected. private float mFirstSampleX, mFirstSampleY, mFirstSampleZ; - // The time and value of the last sample that was collected (for debugging only). - private long mLastSampleTime; + // The value of the last sample that was collected. private float mLastSampleX, mLastSampleY, mLastSampleZ; public WirelessChargerDetector(SensorManager sensorManager, - SuspendBlocker suspendBlocker) { + SuspendBlocker suspendBlocker, Handler handler) { mSensorManager = sensorManager; mSuspendBlocker = suspendBlocker; + mHandler = handler; mGravitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY); } @@ -152,13 +158,13 @@ final class WirelessChargerDetector { pw.println(" mAtRest=" + mAtRest); pw.println(" mRestX=" + mRestX + ", mRestY=" + mRestY + ", mRestZ=" + mRestZ); pw.println(" mDetectionInProgress=" + mDetectionInProgress); + pw.println(" mDetectionStartTime=" + (mDetectionStartTime == 0 ? "0 (never)" + : TimeUtils.formatUptime(mDetectionStartTime))); pw.println(" mMustUpdateRestPosition=" + mMustUpdateRestPosition); pw.println(" mTotalSamples=" + mTotalSamples); pw.println(" mMovingSamples=" + mMovingSamples); - pw.println(" mFirstSampleTime=" + mFirstSampleTime); pw.println(" mFirstSampleX=" + mFirstSampleX + ", mFirstSampleY=" + mFirstSampleY + ", mFirstSampleZ=" + mFirstSampleZ); - pw.println(" mLastSampleTime=" + mLastSampleTime); pw.println(" mLastSampleX=" + mLastSampleX + ", mLastSampleY=" + mLastSampleY + ", mLastSampleZ=" + mLastSampleZ); } @@ -217,22 +223,56 @@ final class WirelessChargerDetector { private void startDetectionLocked() { if (!mDetectionInProgress && mGravitySensor != null) { if (mSensorManager.registerListener(mListener, mGravitySensor, - SensorManager.SENSOR_DELAY_UI)) { + SAMPLING_INTERVAL_MILLIS * 1000)) { mSuspendBlocker.acquire(); mDetectionInProgress = true; + mDetectionStartTime = SystemClock.uptimeMillis(); mTotalSamples = 0; mMovingSamples = 0; + + Message msg = Message.obtain(mHandler, mSensorTimeout); + msg.setAsynchronous(true); + mHandler.sendMessageDelayed(msg, SETTLE_TIME_MILLIS); } } } - private void processSample(long timeNanos, float x, float y, float z) { - synchronized (mLock) { - if (!mDetectionInProgress) { - return; + private void finishDetectionLocked() { + if (mDetectionInProgress) { + mSensorManager.unregisterListener(mListener); + mHandler.removeCallbacks(mSensorTimeout); + + if (mMustUpdateRestPosition) { + clearAtRestLocked(); + if (mTotalSamples < MIN_SAMPLES) { + Slog.w(TAG, "Wireless charger detector is broken. Only received " + + mTotalSamples + " samples from the gravity sensor but we " + + "need at least " + MIN_SAMPLES + " and we expect to see " + + "about " + SETTLE_TIME_MILLIS / SAMPLING_INTERVAL_MILLIS + + " on average."); + } else if (mMovingSamples == 0) { + mAtRest = true; + mRestX = mLastSampleX; + mRestY = mLastSampleY; + mRestZ = mLastSampleZ; + } + mMustUpdateRestPosition = false; } - mLastSampleTime = timeNanos; + if (DEBUG) { + Slog.d(TAG, "New state: mAtRest=" + mAtRest + + ", mRestX=" + mRestX + ", mRestY=" + mRestY + ", mRestZ=" + mRestZ + + ", mTotalSamples=" + mTotalSamples + + ", mMovingSamples=" + mMovingSamples); + } + + mDetectionInProgress = false; + mSuspendBlocker.release(); + } + } + + private void processSampleLocked(float x, float y, float z) { + if (mDetectionInProgress) { mLastSampleX = x; mLastSampleY = y; mLastSampleZ = z; @@ -240,7 +280,6 @@ final class WirelessChargerDetector { mTotalSamples += 1; if (mTotalSamples == 1) { // Save information about the first sample collected. - mFirstSampleTime = timeNanos; mFirstSampleX = x; mFirstSampleY = y; mFirstSampleZ = z; @@ -260,32 +299,6 @@ final class WirelessChargerDetector { } clearAtRestLocked(); } - - // Save the result when done. - if (timeNanos - mFirstSampleTime >= SETTLE_TIME_NANOS - && mTotalSamples >= MIN_SAMPLES) { - mSensorManager.unregisterListener(mListener); - if (mMustUpdateRestPosition) { - if (mMovingSamples == 0) { - mAtRest = true; - mRestX = x; - mRestY = y; - mRestZ = z; - } else { - clearAtRestLocked(); - } - mMustUpdateRestPosition = false; - } - mDetectionInProgress = false; - mSuspendBlocker.release(); - - if (DEBUG) { - Slog.d(TAG, "New state: mAtRest=" + mAtRest - + ", mRestX=" + mRestX + ", mRestY=" + mRestY + ", mRestZ=" + mRestZ - + ", mTotalSamples=" + mTotalSamples - + ", mMovingSamples=" + mMovingSamples); - } - } } } @@ -323,14 +336,22 @@ final class WirelessChargerDetector { private final SensorEventListener mListener = new SensorEventListener() { @Override public void onSensorChanged(SensorEvent event) { - // We use SystemClock.elapsedRealtimeNanos() instead of event.timestamp because - // on some devices the sensor HAL may produce timestamps that are not monotonic. - processSample(SystemClock.elapsedRealtimeNanos(), - event.values[0], event.values[1], event.values[2]); + synchronized (mLock) { + processSampleLocked(event.values[0], event.values[1], event.values[2]); + } } @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { } }; + + private final Runnable mSensorTimeout = new Runnable() { + @Override + public void run() { + synchronized (mLock) { + finishDetectionLocked(); + } + } + }; } diff --git a/services/java/com/android/server/print/UserState.java b/services/java/com/android/server/print/UserState.java index bc70fe3..3b0ee24 100644 --- a/services/java/com/android/server/print/UserState.java +++ b/services/java/com/android/server/print/UserState.java @@ -134,6 +134,11 @@ final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks { } if (service != null) { service.onPrintJobQueued(printJob); + } else { + // The service for the job is no longer enabled, so just + // fail the job with the appropriate message. + mSpooler.setPrintJobState(printJob.getId(), PrintJobInfo.STATE_FAILED, + mContext.getString(R.string.reason_service_unavailable)); } } @@ -779,7 +784,7 @@ final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks { for (int i = 0; i < printJobCount; i++) { PrintJobInfo printJob = printJobs.get(i); mSpooler.setPrintJobState(printJob.getId(), PrintJobInfo.STATE_FAILED, - mContext.getString(R.string.reason_unknown)); + mContext.getString(R.string.reason_service_unavailable)); } } finally { Binder.restoreCallingIdentity(identity); diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java index e6b0531..a888731 100644 --- a/services/java/com/android/server/wm/WindowManagerService.java +++ b/services/java/com/android/server/wm/WindowManagerService.java @@ -2793,7 +2793,7 @@ public class WindowManagerService extends IWindowManager.Stub if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": viewVisibility=" + viewVisibility + " req=" + requestedWidth + "x" + requestedHeight + " " + win.mAttrs); - win.mEnforceSizeCompat = (win.mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0; + win.mEnforceSizeCompat = (win.mAttrs.flags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0; if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { winAnimator.mAlpha = attrs.alpha; diff --git a/services/java/com/android/server/wm/WindowState.java b/services/java/com/android/server/wm/WindowState.java index 64b5a09..d56e225 100644 --- a/services/java/com/android/server/wm/WindowState.java +++ b/services/java/com/android/server/wm/WindowState.java @@ -20,7 +20,7 @@ import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY; import static com.android.server.wm.WindowManagerService.DEBUG_LAYOUT; import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; -import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW; +import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION; import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; @@ -332,7 +332,7 @@ final class WindowState implements WindowManagerPolicy.WindowState { mContext = mService.mContext; DeathRecipient deathRecipient = new DeathRecipient(); mSeq = seq; - mEnforceSizeCompat = (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0; + mEnforceSizeCompat = (mAttrs.flags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0; if (WindowManagerService.localLOGV) Slog.v( TAG, "Window " + this + " client=" + c.asBinder() + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a); |