diff options
Diffstat (limited to 'services')
19 files changed, 445 insertions, 154 deletions
diff --git a/services/core/java/com/android/server/AlarmManagerService.java b/services/core/java/com/android/server/AlarmManagerService.java index f79a51b13afd..47b646c1a667 100644 --- a/services/core/java/com/android/server/AlarmManagerService.java +++ b/services/core/java/com/android/server/AlarmManagerService.java @@ -48,6 +48,7 @@ import android.content.pm.PermissionInfo; import android.database.ContentObserver; import android.net.Uri; import android.os.Binder; +import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.Handler; @@ -1288,9 +1289,13 @@ class AlarmManagerService extends SystemService { // because kernel doesn't keep this after reboot setTimeZoneImpl(SystemProperties.get(TIMEZONE_PROPERTY)); - // Also sure that we're booting with a halfway sensible current time if (mNativeData != 0) { - final long systemBuildTime = Environment.getRootDirectory().lastModified(); + // Ensure that we're booting with a halfway sensible current time. Use the + // most recent of Build.TIME, the root file system's timestamp, and the + // value of the ro.build.date.utc system property (which is in seconds). + final long systemBuildTime = Long.max( + 1000L * SystemProperties.getLong("ro.build.date.utc", -1L), + Long.max(Environment.getRootDirectory().lastModified(), Build.TIME)); if (System.currentTimeMillis() < systemBuildTime) { Slog.i(TAG, "Current time only " + System.currentTimeMillis() + ", advancing to build time " + systemBuildTime); diff --git a/services/core/java/com/android/server/am/ActivityMetricsLogger.java b/services/core/java/com/android/server/am/ActivityMetricsLogger.java index 5cbd8fd1cd60..54e6fd11d937 100644 --- a/services/core/java/com/android/server/am/ActivityMetricsLogger.java +++ b/services/core/java/com/android/server/am/ActivityMetricsLogger.java @@ -497,6 +497,16 @@ class ActivityMetricsLogger { mHandler.obtainMessage(MSG_CHECK_VISIBILITY, args).sendToTarget(); } + private boolean hasVisibleNonFinishingActivity(TaskRecord t) { + for (int i = t.mActivities.size() - 1; i >= 0; --i) { + final ActivityRecord r = t.mActivities.get(i); + if (r.visible && !r.finishing) { + return true; + } + } + return false; + } + private void checkVisibility(TaskRecord t, ActivityRecord r) { synchronized (mSupervisor.mService) { @@ -505,7 +515,7 @@ class ActivityMetricsLogger { // If we have an active transition that's waiting on a certain activity that will be // invisible now, we'll never get onWindowsDrawn, so abort the transition if necessary. - if (info != null && !t.isVisible()) { + if (info != null && !hasVisibleNonFinishingActivity(t)) { if (DEBUG_METRICS) Slog.i(TAG, "notifyVisibilityChanged to invisible" + " activity=" + r); logAppTransitionCancel(info); diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java index aa5aa70b2e56..19ee3572d619 100644 --- a/services/core/java/com/android/server/am/ActivityStack.java +++ b/services/core/java/com/android/server/am/ActivityStack.java @@ -2494,7 +2494,9 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai if (prev != null && prev != next) { if (!mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(prev) - && next != null && !next.nowVisible) { + && next != null && !next.nowVisible + && checkKeyguardVisibility(next, true /* shouldBeVisible */, + next.isTopRunningActivity())) { mStackSupervisor.mActivitiesWaitingForVisibleActivity.add(prev); if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resuming top, waiting visible to hide: " + prev); diff --git a/services/core/java/com/android/server/content/SyncLogger.java b/services/core/java/com/android/server/content/SyncLogger.java index 8c35e27671eb..b714077aab0f 100644 --- a/services/core/java/com/android/server/content/SyncLogger.java +++ b/services/core/java/com/android/server/content/SyncLogger.java @@ -16,6 +16,7 @@ package com.android.server.content; +import android.accounts.Account; import android.app.job.JobParameters; import android.os.Build; import android.os.Environment; @@ -26,6 +27,8 @@ import android.util.Log; import android.util.Slog; import com.android.internal.annotations.GuardedBy; +import com.android.server.content.SyncManager.ActiveSyncContext; +import com.android.server.content.SyncStorageEngine.EndPoint; import libcore.io.IoUtils; @@ -273,4 +276,20 @@ public class SyncLogger { } } } + + static String logSafe(Account account) { + return account == null ? "[null]" : "***/" + account.type; + } + + static String logSafe(EndPoint endPoint) { + return endPoint == null ? "[null]" : endPoint.toSafeString(); + } + + static String logSafe(SyncOperation operation) { + return operation == null ? "[null]" : operation.toSafeString(); + } + + static String logSafe(ActiveSyncContext asc) { + return asc == null ? "[null]" : asc.toSafeString(); + } } diff --git a/services/core/java/com/android/server/content/SyncManager.java b/services/core/java/com/android/server/content/SyncManager.java index 0a640b8a76c6..132bf0bc9978 100644 --- a/services/core/java/com/android/server/content/SyncManager.java +++ b/services/core/java/com/android/server/content/SyncManager.java @@ -16,6 +16,8 @@ package com.android.server.content; +import static com.android.server.content.SyncLogger.logSafe; + import android.accounts.Account; import android.accounts.AccountAndUser; import android.accounts.AccountManager; @@ -1175,7 +1177,7 @@ public class SyncManager { /* ignore - local call */ } if (checkAccountAccess && !canAccessAccount(account, owningPackage, owningUid)) { - Log.w(TAG, "Access to " + account + " denied for package " + Log.w(TAG, "Access to " + logSafe(account) + " denied for package " + owningPackage + " in UID " + syncAdapterInfo.uid); return AuthorityInfo.SYNCABLE_NO_ACCOUNT_ACCESS; } @@ -1508,7 +1510,8 @@ public class SyncManager { if (!syncOperation.ignoreBackoff()) { Pair<Long, Long> backoff = mSyncStorageEngine.getBackoff(syncOperation.target); if (backoff == null) { - Slog.e(TAG, "Couldn't find backoff values for " + syncOperation.target); + Slog.e(TAG, "Couldn't find backoff values for " + + logSafe(syncOperation.target)); backoff = new Pair<Long, Long>(SyncStorageEngine.NOT_IN_BACKOFF_MODE, SyncStorageEngine.NOT_IN_BACKOFF_MODE); } @@ -1779,8 +1782,8 @@ public class SyncManager { scheduleSyncOperationH(operation); } else { // Otherwise do not reschedule. - Log.d(TAG, "not retrying sync operation because the error is a hard error: " - + operation); + Log.e(TAG, "not retrying sync operation because the error is a hard error: " + + logSafe(operation)); } } @@ -1914,11 +1917,12 @@ public class SyncManager { sendSyncFinishedOrCanceledMessage(this, result); } - public void toString(StringBuilder sb) { + public void toString(StringBuilder sb, boolean logSafe) { sb.append("startTime ").append(mStartTime) .append(", mTimeoutStartTime ").append(mTimeoutStartTime) .append(", mHistoryRowId ").append(mHistoryRowId) - .append(", syncOperation ").append(mSyncOperation); + .append(", syncOperation ").append( + logSafe ? logSafe(mSyncOperation) : mSyncOperation); } public void onServiceConnected(ComponentName name, IBinder service) { @@ -1980,7 +1984,13 @@ public class SyncManager { public String toString() { StringBuilder sb = new StringBuilder(); - toString(sb); + toString(sb, false); + return sb.toString(); + } + + public String toSafeString() { + StringBuilder sb = new StringBuilder(); + toString(sb, true); return sb.toString(); } @@ -2069,7 +2079,7 @@ public class SyncManager { int count = 0; for (SyncOperation op: pendingSyncs) { if (!op.isPeriodic) { - pw.println(op.dump(null, false, buckets)); + pw.println(op.dump(null, false, buckets, /*logSafe=*/ false)); count++; } } @@ -2086,7 +2096,7 @@ public class SyncManager { int count = 0; for (SyncOperation op: pendingSyncs) { if (op.isPeriodic) { - pw.println(op.dump(null, false, buckets)); + pw.println(op.dump(null, false, buckets, /*logSafe=*/ false)); count++; } } @@ -2219,7 +2229,7 @@ public class SyncManager { sb.setLength(0); pw.print(formatDurationHMS(sb, durationInSeconds)); pw.print(" - "); - pw.print(activeSyncContext.mSyncOperation.dump(pm, false, buckets)); + pw.print(activeSyncContext.mSyncOperation.dump(pm, false, buckets, /*logSafe=*/ false)); pw.println(); } pw.println(); @@ -3050,7 +3060,7 @@ public class SyncManager { case SyncHandler.MESSAGE_CANCEL: SyncStorageEngine.EndPoint endpoint = (SyncStorageEngine.EndPoint) msg.obj; Bundle extras = msg.peekData(); - if (Log.isLoggable(TAG, Log.DEBUG)) { + if (isLoggable) { Log.d(TAG, "handleSyncHandlerMessage: MESSAGE_CANCEL: " + endpoint + " bundle: " + extras); } @@ -3061,9 +3071,11 @@ public class SyncManager { SyncFinishedOrCancelledMessagePayload payload = (SyncFinishedOrCancelledMessagePayload) msg.obj; if (!isSyncStillActiveH(payload.activeSyncContext)) { - Log.d(TAG, "handleSyncHandlerMessage: dropping since the " - + "sync is no longer active: " - + payload.activeSyncContext); + if (isLoggable) { + Log.d(TAG, "handleSyncHandlerMessage: dropping since the " + + "sync is no longer active: " + + payload.activeSyncContext); + } break; } if (isLoggable) { @@ -3078,7 +3090,7 @@ public class SyncManager { case SyncHandler.MESSAGE_SERVICE_CONNECTED: { ServiceConnectionData msgData = (ServiceConnectionData) msg.obj; - if (Log.isLoggable(TAG, Log.VERBOSE)) { + if (isLoggable) { Log.d(TAG, "handleSyncHandlerMessage: MESSAGE_SERVICE_CONNECTED: " + msgData.activeSyncContext); } @@ -3094,7 +3106,7 @@ public class SyncManager { case SyncHandler.MESSAGE_SERVICE_DISCONNECTED: { final ActiveSyncContext currentSyncContext = ((ServiceConnectionData) msg.obj).activeSyncContext; - if (Log.isLoggable(TAG, Log.VERBOSE)) { + if (isLoggable) { Log.d(TAG, "handleSyncHandlerMessage: MESSAGE_SERVICE_DISCONNECTED: " + currentSyncContext); } @@ -3129,7 +3141,7 @@ public class SyncManager { case SyncHandler.MESSAGE_MONITOR_SYNC: ActiveSyncContext monitoredSyncContext = (ActiveSyncContext) msg.obj; - if (Log.isLoggable(TAG, Log.DEBUG)) { + if (isLoggable) { Log.d(TAG, "handleSyncHandlerMessage: MESSAGE_MONITOR_SYNC: " + monitoredSyncContext.mSyncOperation.target); } @@ -3137,7 +3149,7 @@ public class SyncManager { if (isSyncNotUsingNetworkH(monitoredSyncContext)) { Log.w(TAG, String.format( "Detected sync making no progress for %s. cancelling.", - monitoredSyncContext)); + logSafe(monitoredSyncContext))); mSyncJobService.callJobFinished( monitoredSyncContext.mSyncOperation.jobId, false, "no network activity"); @@ -3636,7 +3648,8 @@ public class SyncManager { } catch (RuntimeException exc) { mLogger.log("Sync failed with RuntimeException: ", exc.toString()); closeActiveSyncContext(activeSyncContext); - Slog.e(TAG, "Caught RuntimeException while starting the sync " + syncOperation, exc); + Slog.e(TAG, "Caught RuntimeException while starting the sync " + + logSafe(syncOperation), exc); } } @@ -3736,7 +3749,8 @@ public class SyncManager { reschedulePeriodicSyncH(syncOperation); } } else { - Log.w(TAG, "failed sync operation " + syncOperation + ", " + syncResult); + Log.w(TAG, "failed sync operation " + + logSafe(syncOperation) + ", " + syncResult); syncOperation.retries++; if (syncOperation.retries > mConstants.getMaxRetriesWithAppStandbyExemption()) { @@ -4120,11 +4134,6 @@ public class SyncManager { getJobScheduler().cancel(op.jobId); } - private void wtfWithLog(String message) { - Slog.wtf(TAG, message); - mLogger.log("WTF: ", message); - } - public void resetTodayStats() { mSyncStorageEngine.resetTodayStats(/*force=*/ true); } diff --git a/services/core/java/com/android/server/content/SyncOperation.java b/services/core/java/com/android/server/content/SyncOperation.java index 25edf4070689..2abc2e60a47b 100644 --- a/services/core/java/com/android/server/content/SyncOperation.java +++ b/services/core/java/com/android/server/content/SyncOperation.java @@ -363,14 +363,19 @@ public class SyncOperation { @Override public String toString() { - return dump(null, true, null); + return dump(null, true, null, false); } - String dump(PackageManager pm, boolean shorter, SyncAdapterStateFetcher appStates) { + public String toSafeString() { + return dump(null, true, null, true); + } + + String dump(PackageManager pm, boolean shorter, SyncAdapterStateFetcher appStates, + boolean logSafe) { StringBuilder sb = new StringBuilder(); sb.append("JobId=").append(jobId) .append(" ") - .append(target.account.name) + .append(logSafe ? "***" : target.account.name) .append("/") .append(target.account.type) .append(" u") diff --git a/services/core/java/com/android/server/content/SyncStorageEngine.java b/services/core/java/com/android/server/content/SyncStorageEngine.java index 11f07015ef12..0a2af9ee109b 100644 --- a/services/core/java/com/android/server/content/SyncStorageEngine.java +++ b/services/core/java/com/android/server/content/SyncStorageEngine.java @@ -16,6 +16,8 @@ package com.android.server.content; +import static com.android.server.content.SyncLogger.logSafe; + import android.accounts.Account; import android.accounts.AccountAndUser; import android.accounts.AccountManager; @@ -228,6 +230,15 @@ public class SyncStorageEngine { sb.append(":u" + userId); return sb.toString(); } + + public String toSafeString() { + StringBuilder sb = new StringBuilder(); + sb.append(account == null ? "ALL ACCS" : logSafe(account)) + .append("/") + .append(provider == null ? "ALL PDRS" : provider); + sb.append(":u" + userId); + return sb.toString(); + } } public static class AuthorityInfo { @@ -1863,8 +1874,8 @@ public class SyncStorageEngine { } } else { - Slog.w(TAG, "Failure adding authority: account=" - + accountName + " auth=" + authorityName + Slog.w(TAG, "Failure adding authority:" + + " auth=" + authorityName + " enabled=" + enabled + " syncable=" + syncable); } diff --git a/services/core/java/com/android/server/display/AutomaticBrightnessController.java b/services/core/java/com/android/server/display/AutomaticBrightnessController.java index 1c3342a9af42..2612b53e1052 100644 --- a/services/core/java/com/android/server/display/AutomaticBrightnessController.java +++ b/services/core/java/com/android/server/display/AutomaticBrightnessController.java @@ -16,30 +16,26 @@ package com.android.server.display; -import com.android.server.EventLogTags; -import com.android.server.LocalServices; - import android.annotation.Nullable; -import android.app.ActivityManager; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.hardware.display.BrightnessConfiguration; import android.hardware.display.DisplayManagerInternal.DisplayPowerRequest; -import android.os.Build; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.PowerManager; import android.os.SystemClock; import android.os.Trace; -import android.text.format.DateUtils; import android.util.EventLog; import android.util.MathUtils; import android.util.Slog; import android.util.TimeUtils; +import com.android.server.EventLogTags; + import java.io.PrintWriter; class AutomaticBrightnessController { @@ -127,7 +123,8 @@ class AutomaticBrightnessController { private final int mWeightingIntercept; // Configuration object for determining thresholds to change brightness dynamically - private final HysteresisLevels mHysteresisLevels; + private final HysteresisLevels mAmbientBrightnessThresholds; + private final HysteresisLevels mScreenBrightnessThresholds; // Amount of time to delay auto-brightness after screen on while waiting for // the light sensor to warm-up in milliseconds. @@ -147,8 +144,12 @@ class AutomaticBrightnessController { private boolean mAmbientLuxValid; // The ambient light level threshold at which to brighten or darken the screen. - private float mBrighteningLuxThreshold; - private float mDarkeningLuxThreshold; + private float mAmbientBrighteningThreshold; + private float mAmbientDarkeningThreshold; + + // The screen light level threshold at which to brighten or darken the screen. + private float mScreenBrighteningThreshold; + private float mScreenDarkeningThreshold; // The most recent light sample. private float mLastObservedLux; @@ -196,7 +197,8 @@ class AutomaticBrightnessController { int lightSensorWarmUpTime, int brightnessMin, int brightnessMax, float dozeScaleFactor, int lightSensorRate, int initialLightSensorRate, long brighteningLightDebounceConfig, long darkeningLightDebounceConfig, boolean resetAmbientLuxAfterWarmUpConfig, - HysteresisLevels hysteresisLevels) { + HysteresisLevels ambientBrightnessThresholds, + HysteresisLevels screenBrightnessThresholds) { mCallbacks = callbacks; mSensorManager = sensorManager; mBrightnessMapper = mapper; @@ -212,7 +214,8 @@ class AutomaticBrightnessController { mResetAmbientLuxAfterWarmUpConfig = resetAmbientLuxAfterWarmUpConfig; mAmbientLightHorizon = AMBIENT_LIGHT_LONG_HORIZON_MILLIS; mWeightingIntercept = AMBIENT_LIGHT_LONG_HORIZON_MILLIS; - mHysteresisLevels = hysteresisLevels; + mAmbientBrightnessThresholds = ambientBrightnessThresholds; + mScreenBrightnessThresholds = screenBrightnessThresholds; mShortTermModelValid = true; mShortTermModelAnchor = -1; @@ -364,8 +367,10 @@ class AutomaticBrightnessController { pw.println(" mCurrentLightSensorRate=" + mCurrentLightSensorRate); pw.println(" mAmbientLux=" + mAmbientLux); pw.println(" mAmbientLuxValid=" + mAmbientLuxValid); - pw.println(" mBrighteningLuxThreshold=" + mBrighteningLuxThreshold); - pw.println(" mDarkeningLuxThreshold=" + mDarkeningLuxThreshold); + pw.println(" mAmbientBrighteningThreshold=" + mAmbientBrighteningThreshold); + pw.println(" mAmbientDarkeningThreshold=" + mAmbientDarkeningThreshold); + pw.println(" mScreenBrighteningThreshold=" + mScreenBrighteningThreshold); + pw.println(" mScreenDarkeningThreshold=" + mScreenDarkeningThreshold); pw.println(" mLastObservedLux=" + mLastObservedLux); pw.println(" mLastObservedLuxTime=" + TimeUtils.formatUptime(mLastObservedLuxTime)); pw.println(" mRecentLightSamples=" + mRecentLightSamples); @@ -384,7 +389,8 @@ class AutomaticBrightnessController { mBrightnessMapper.dump(pw); pw.println(); - mHysteresisLevels.dump(pw); + mAmbientBrightnessThresholds.dump(pw); + mScreenBrightnessThresholds.dump(pw); } private boolean setLightSensorEnabled(boolean enable) { @@ -459,8 +465,8 @@ class AutomaticBrightnessController { lux = 0; } mAmbientLux = lux; - mBrighteningLuxThreshold = mHysteresisLevels.getBrighteningThreshold(lux); - mDarkeningLuxThreshold = mHysteresisLevels.getDarkeningThreshold(lux); + mAmbientBrighteningThreshold = mAmbientBrightnessThresholds.getBrighteningThreshold(lux); + mAmbientDarkeningThreshold = mAmbientBrightnessThresholds.getDarkeningThreshold(lux); // If the short term model was invalidated and the change is drastic enough, reset it. if (!mShortTermModelValid && mShortTermModelAnchor != -1) { @@ -551,7 +557,7 @@ class AutomaticBrightnessController { final int N = mAmbientLightRingBuffer.size(); long earliestValidTime = time; for (int i = N - 1; i >= 0; i--) { - if (mAmbientLightRingBuffer.getLux(i) <= mBrighteningLuxThreshold) { + if (mAmbientLightRingBuffer.getLux(i) <= mAmbientBrighteningThreshold) { break; } earliestValidTime = mAmbientLightRingBuffer.getTime(i); @@ -563,7 +569,7 @@ class AutomaticBrightnessController { final int N = mAmbientLightRingBuffer.size(); long earliestValidTime = time; for (int i = N - 1; i >= 0; i--) { - if (mAmbientLightRingBuffer.getLux(i) >= mDarkeningLuxThreshold) { + if (mAmbientLightRingBuffer.getLux(i) >= mAmbientDarkeningThreshold) { break; } earliestValidTime = mAmbientLightRingBuffer.getTime(i); @@ -616,20 +622,19 @@ class AutomaticBrightnessController { float slowAmbientLux = calculateAmbientLux(time, AMBIENT_LIGHT_LONG_HORIZON_MILLIS); float fastAmbientLux = calculateAmbientLux(time, AMBIENT_LIGHT_SHORT_HORIZON_MILLIS); - if ((slowAmbientLux >= mBrighteningLuxThreshold && - fastAmbientLux >= mBrighteningLuxThreshold && - nextBrightenTransition <= time) - || - (slowAmbientLux <= mDarkeningLuxThreshold && - fastAmbientLux <= mDarkeningLuxThreshold && - nextDarkenTransition <= time)) { + if ((slowAmbientLux >= mAmbientBrighteningThreshold + && fastAmbientLux >= mAmbientBrighteningThreshold + && nextBrightenTransition <= time) + || (slowAmbientLux <= mAmbientDarkeningThreshold + && fastAmbientLux <= mAmbientDarkeningThreshold + && nextDarkenTransition <= time)) { setAmbientLux(fastAmbientLux); if (DEBUG) { Slog.d(TAG, "updateAmbientLux: " + - ((fastAmbientLux > mAmbientLux) ? "Brightened" : "Darkened") + ": " + - "mBrighteningLuxThreshold=" + mBrighteningLuxThreshold + ", " + - "mAmbientLightRingBuffer=" + mAmbientLightRingBuffer + ", " + - "mAmbientLux=" + mAmbientLux); + ((fastAmbientLux > mAmbientLux) ? "Brightened" : "Darkened") + ": " + + "mAmbientBrighteningThreshold=" + mAmbientBrighteningThreshold + ", " + + "mAmbientLightRingBuffer=" + mAmbientLightRingBuffer + ", " + + "mAmbientLux=" + mAmbientLux); } updateAutoBrightness(true); nextBrightenTransition = nextAmbientLightBrighteningTransition(time); @@ -660,6 +665,20 @@ class AutomaticBrightnessController { int newScreenAutoBrightness = clampScreenBrightness(Math.round(value * PowerManager.BRIGHTNESS_ON)); + + // If mScreenAutoBrightness is set, we should have screen{Brightening,Darkening}Threshold, + // in which case we ignore the new screen brightness if it doesn't differ enough from the + // previous one. + if (mScreenAutoBrightness != -1 + && newScreenAutoBrightness > mScreenDarkeningThreshold + && newScreenAutoBrightness < mScreenBrighteningThreshold) { + if (DEBUG) { + Slog.d(TAG, "ignoring newScreenAutoBrightness: " + mScreenDarkeningThreshold + + " < " + newScreenAutoBrightness + " < " + mScreenBrighteningThreshold); + } + return; + } + if (mScreenAutoBrightness != newScreenAutoBrightness) { if (DEBUG) { Slog.d(TAG, "updateAutoBrightness: " + @@ -668,6 +687,11 @@ class AutomaticBrightnessController { } mScreenAutoBrightness = newScreenAutoBrightness; + mScreenBrighteningThreshold = + mScreenBrightnessThresholds.getBrighteningThreshold(newScreenAutoBrightness); + mScreenDarkeningThreshold = + mScreenBrightnessThresholds.getDarkeningThreshold(newScreenAutoBrightness); + if (sendUpdate) { mCallbacks.updateBrightness(); } diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java index 99412c56b274..c75761ff6ece 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController.java +++ b/services/core/java/com/android/server/display/DisplayPowerController.java @@ -16,16 +16,11 @@ package com.android.server.display; -import android.app.ActivityManager; -import com.android.internal.app.IBatteryStats; -import com.android.server.LocalServices; -import com.android.server.am.BatteryStatsService; -import com.android.server.policy.WindowManagerPolicy; - import android.animation.Animator; import android.animation.ObjectAnimator; import android.annotation.Nullable; import android.annotation.UserIdInt; +import android.app.ActivityManager; import android.content.Context; import android.content.pm.ParceledListSlice; import android.content.res.Resources; @@ -54,6 +49,11 @@ import android.util.Slog; import android.util.TimeUtils; import android.view.Display; +import com.android.internal.app.IBatteryStats; +import com.android.server.LocalServices; +import com.android.server.am.BatteryStatsService; +import com.android.server.policy.WindowManagerPolicy; + import java.io.PrintWriter; /** @@ -422,14 +422,25 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call com.android.internal.R.fraction.config_screenAutoBrightnessDozeScaleFactor, 1, 1); - int[] brightLevels = resources.getIntArray( - com.android.internal.R.array.config_dynamicHysteresisBrightLevels); - int[] darkLevels = resources.getIntArray( - com.android.internal.R.array.config_dynamicHysteresisDarkLevels); - int[] luxHysteresisLevels = resources.getIntArray( - com.android.internal.R.array.config_dynamicHysteresisLuxLevels); - HysteresisLevels hysteresisLevels = new HysteresisLevels( - brightLevels, darkLevels, luxHysteresisLevels); + int[] ambientBrighteningThresholds = resources.getIntArray( + com.android.internal.R.array.config_ambientBrighteningThresholds); + int[] ambientDarkeningThresholds = resources.getIntArray( + com.android.internal.R.array.config_ambientDarkeningThresholds); + int[] ambientThresholdLevels = resources.getIntArray( + com.android.internal.R.array.config_ambientThresholdLevels); + HysteresisLevels ambientBrightnessThresholds = new HysteresisLevels( + ambientBrighteningThresholds, ambientDarkeningThresholds, + ambientThresholdLevels); + + int[] screenBrighteningThresholds = resources.getIntArray( + com.android.internal.R.array.config_screenBrighteningThresholds); + int[] screenDarkeningThresholds = resources.getIntArray( + com.android.internal.R.array.config_screenDarkeningThresholds); + int[] screenThresholdLevels = resources.getIntArray( + com.android.internal.R.array.config_screenThresholdLevels); + HysteresisLevels screenBrightnessThresholds = new HysteresisLevels( + screenBrighteningThresholds, screenDarkeningThresholds, screenThresholdLevels); + long brighteningLightDebounce = resources.getInteger( com.android.internal.R.integer.config_autoBrightnessBrighteningLightDebounce); @@ -459,7 +470,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call lightSensorWarmUpTimeConfig, mScreenBrightnessRangeMinimum, mScreenBrightnessRangeMaximum, dozeScaleFactor, lightSensorRate, initialLightSensorRate, brighteningLightDebounce, darkeningLightDebounce, - autoBrightnessResetAmbientLuxAfterWarmUp, hysteresisLevels); + autoBrightnessResetAmbientLuxAfterWarmUp, ambientBrightnessThresholds, + screenBrightnessThresholds); } else { mUseSoftwareAutoBrightnessConfig = false; } @@ -791,9 +803,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call && mAutomaticBrightnessController != null; final boolean userSetBrightnessChanged = updateUserSetScreenBrightness(); - if (userSetBrightnessChanged) { - mTemporaryScreenBrightness = -1; - } // Use the temporary screen brightness if there isn't an override, either from // WindowManager or based on the display state. @@ -1514,11 +1523,13 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call } if (mCurrentScreenBrightnessSetting == mPendingScreenBrightnessSetting) { mPendingScreenBrightnessSetting = -1; + mTemporaryScreenBrightness = -1; return false; } mCurrentScreenBrightnessSetting = mPendingScreenBrightnessSetting; mLastUserSetScreenBrightness = mPendingScreenBrightnessSetting; mPendingScreenBrightnessSetting = -1; + mTemporaryScreenBrightness = -1; return true; } diff --git a/services/core/java/com/android/server/display/HysteresisLevels.java b/services/core/java/com/android/server/display/HysteresisLevels.java index 1c02dd1fcdf4..2db1d03893d2 100644 --- a/services/core/java/com/android/server/display/HysteresisLevels.java +++ b/services/core/java/com/android/server/display/HysteresisLevels.java @@ -28,67 +28,67 @@ final class HysteresisLevels { private static final String TAG = "HysteresisLevels"; // Default hysteresis constraints for brightening or darkening. - // The recent lux must have changed by at least this fraction relative to the - // current ambient lux before a change will be considered. + // The recent value must have changed by at least this fraction relative to the + // current value before a change will be considered. private static final float DEFAULT_BRIGHTENING_HYSTERESIS = 0.10f; private static final float DEFAULT_DARKENING_HYSTERESIS = 0.20f; private static final boolean DEBUG = false; - private final float[] mBrightLevels; - private final float[] mDarkLevels; - private final float[] mLuxLevels; + private final float[] mBrighteningThresholds; + private final float[] mDarkeningThresholds; + private final float[] mThresholdLevels; - /** - * Creates a {@code HysteresisLevels} object with the given equal-length - * integer arrays. - * @param brightLevels an array of brightening hysteresis constraint constants - * @param darkLevels an array of darkening hysteresis constraint constants - * @param luxLevels a monotonically increasing array of illuminance - * thresholds in units of lux - */ - public HysteresisLevels(int[] brightLevels, int[] darkLevels, int[] luxLevels) { - if (brightLevels.length != darkLevels.length || darkLevels.length != luxLevels.length + 1) { + /** + * Creates a {@code HysteresisLevels} object with the given equal-length + * integer arrays. + * @param brighteningThresholds an array of brightening hysteresis constraint constants. + * @param darkeningThresholds an array of darkening hysteresis constraint constants. + * @param thresholdLevels a monotonically increasing array of threshold levels. + */ + HysteresisLevels(int[] brighteningThresholds, int[] darkeningThresholds, + int[] thresholdLevels) { + if (brighteningThresholds.length != darkeningThresholds.length + || darkeningThresholds.length != thresholdLevels.length + 1) { throw new IllegalArgumentException("Mismatch between hysteresis array lengths."); } - mBrightLevels = setArrayFormat(brightLevels, 1000.0f); - mDarkLevels = setArrayFormat(darkLevels, 1000.0f); - mLuxLevels = setArrayFormat(luxLevels, 1.0f); + mBrighteningThresholds = setArrayFormat(brighteningThresholds, 1000.0f); + mDarkeningThresholds = setArrayFormat(darkeningThresholds, 1000.0f); + mThresholdLevels = setArrayFormat(thresholdLevels, 1.0f); } /** - * Return the brightening hysteresis threshold for the given lux level. + * Return the brightening hysteresis threshold for the given value level. */ - public float getBrighteningThreshold(float lux) { - float brightConstant = getReferenceLevel(lux, mBrightLevels); - float brightThreshold = lux * (1.0f + brightConstant); + float getBrighteningThreshold(float value) { + float brightConstant = getReferenceLevel(value, mBrighteningThresholds); + float brightThreshold = value * (1.0f + brightConstant); if (DEBUG) { - Slog.d(TAG, "bright hysteresis constant=: " + brightConstant + ", threshold=" - + brightThreshold + ", lux=" + lux); + Slog.d(TAG, "bright hysteresis constant=" + brightConstant + ", threshold=" + + brightThreshold + ", value=" + value); } return brightThreshold; } /** - * Return the darkening hysteresis threshold for the given lux level. + * Return the darkening hysteresis threshold for the given value level. */ - public float getDarkeningThreshold(float lux) { - float darkConstant = getReferenceLevel(lux, mDarkLevels); - float darkThreshold = lux * (1.0f - darkConstant); + float getDarkeningThreshold(float value) { + float darkConstant = getReferenceLevel(value, mDarkeningThresholds); + float darkThreshold = value * (1.0f - darkConstant); if (DEBUG) { Slog.d(TAG, "dark hysteresis constant=: " + darkConstant + ", threshold=" - + darkThreshold + ", lux=" + lux); + + darkThreshold + ", value=" + value); } return darkThreshold; } /** - * Return the hysteresis constant for the closest lux threshold value to the - * current illuminance from the given array. + * Return the hysteresis constant for the closest threshold value from the given array. */ - private float getReferenceLevel(float lux, float[] referenceLevels) { + private float getReferenceLevel(float value, float[] referenceLevels) { int index = 0; - while (mLuxLevels.length > index && lux >= mLuxLevels[index]) { + while (mThresholdLevels.length > index && value >= mThresholdLevels[index]) { ++index; } return referenceLevels[index]; @@ -105,10 +105,10 @@ final class HysteresisLevels { return levelArray; } - public void dump(PrintWriter pw) { + void dump(PrintWriter pw) { pw.println("HysteresisLevels"); - pw.println(" mBrightLevels=" + Arrays.toString(mBrightLevels)); - pw.println(" mDarkLevels=" + Arrays.toString(mDarkLevels)); - pw.println(" mLuxLevels=" + Arrays.toString(mLuxLevels)); + pw.println(" mBrighteningThresholds=" + Arrays.toString(mBrighteningThresholds)); + pw.println(" mDarkeningThresholds=" + Arrays.toString(mDarkeningThresholds)); + pw.println(" mThresholdLevels=" + Arrays.toString(mThresholdLevels)); } } diff --git a/services/core/java/com/android/server/location/GnssLocationProvider.java b/services/core/java/com/android/server/location/GnssLocationProvider.java index 809a48f2b4af..59a7cc8c04cb 100644 --- a/services/core/java/com/android/server/location/GnssLocationProvider.java +++ b/services/core/java/com/android/server/location/GnssLocationProvider.java @@ -810,12 +810,11 @@ public class GnssLocationProvider implements LocationProviderInterface, InjectNt // while IO initialization and registration is delegated to our internal handler // this approach is just fine because events are posted to our handler anyway mProperties = new Properties(); - sendMessage(INITIALIZE_HANDLER, 0, null); - - // Create a GPS net-initiated handler. + // Create a GPS net-initiated handler (also needed by handleInitialize) mNIHandler = new GpsNetInitiatedHandler(context, mNetInitiatedListener, mSuplEsEnabled); + sendMessage(INITIALIZE_HANDLER, 0, null); mListenerHelper = new GnssStatusListenerHelper(mHandler) { @Override diff --git a/services/core/java/com/android/server/locksettings/SP800Derive.java b/services/core/java/com/android/server/locksettings/SP800Derive.java new file mode 100644 index 000000000000..77561fc30db9 --- /dev/null +++ b/services/core/java/com/android/server/locksettings/SP800Derive.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2018 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.server.locksettings; + +import java.nio.ByteBuffer; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; + +/** + * Implementation of NIST SP800-108 + * "Recommendation for Key Derivation Using Pseudorandom Functions" + * Hardcoded: + * [PRF=HMAC_SHA256] + * [CTRLOCATION=BEFORE_FIXED] + * [RLEN=32_BITS] + * L = 256 + * L suffix: 32 bits + */ +class SP800Derive { + private final byte[] mKeyBytes; + + SP800Derive(byte[] keyBytes) { + mKeyBytes = keyBytes; + } + + private Mac getMac() { + try { + final Mac m = Mac.getInstance("HmacSHA256"); + m.init(new SecretKeySpec(mKeyBytes, m.getAlgorithm())); + return m; + } catch (InvalidKeyException | NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } + } + + private static void update32(Mac m, int v) { + m.update(ByteBuffer.allocate(Integer.BYTES).putInt(v).array()); + } + + /** + * Generate output from a single, fixed input. + */ + public byte[] fixedInput(byte[] fixedInput) { + final Mac m = getMac(); + update32(m, 1); // Hardwired counter value + m.update(fixedInput); + return m.doFinal(); + } + + /** + * Generate output from a label and context. We add a length field at the end of the context to + * disambiguate it from the length even in the presence of zero bytes. + */ + public byte[] withContext(byte[] label, byte[] context) { + final Mac m = getMac(); + // Hardwired counter value: 1 + update32(m, 1); // Hardwired counter value + m.update(label); + m.update((byte) 0); + m.update(context); + update32(m, context.length * 8); // Disambiguate context + update32(m, 256); // Hardwired output length + return m.doFinal(); + } +} diff --git a/services/core/java/com/android/server/locksettings/SyntheticPasswordManager.java b/services/core/java/com/android/server/locksettings/SyntheticPasswordManager.java index 596daeb1427b..d32c299074a9 100644 --- a/services/core/java/com/android/server/locksettings/SyntheticPasswordManager.java +++ b/services/core/java/com/android/server/locksettings/SyntheticPasswordManager.java @@ -26,9 +26,9 @@ import android.hardware.weaver.V1_0.WeaverConfig; import android.hardware.weaver.V1_0.WeaverReadResponse; import android.hardware.weaver.V1_0.WeaverReadStatus; import android.hardware.weaver.V1_0.WeaverStatus; -import android.security.GateKeeper; import android.os.RemoteException; import android.os.UserManager; +import android.security.GateKeeper; import android.service.gatekeeper.GateKeeperResponse; import android.service.gatekeeper.IGateKeeperService; import android.util.ArrayMap; @@ -102,7 +102,8 @@ public class SyntheticPasswordManager { private static final int INVALID_WEAVER_SLOT = -1; private static final byte SYNTHETIC_PASSWORD_VERSION_V1 = 1; - private static final byte SYNTHETIC_PASSWORD_VERSION = 2; + private static final byte SYNTHETIC_PASSWORD_VERSION_V2 = 2; + private static final byte SYNTHETIC_PASSWORD_VERSION_V3 = 3; private static final byte SYNTHETIC_PASSWORD_PASSWORD_BASED = 0; private static final byte SYNTHETIC_PASSWORD_TOKEN_BASED = 1; @@ -128,6 +129,8 @@ public class SyntheticPasswordManager { private static final byte[] PERSONALISATION_WEAVER_PASSWORD = "weaver-pwd".getBytes(); private static final byte[] PERSONALISATION_WEAVER_KEY = "weaver-key".getBytes(); private static final byte[] PERSONALISATION_WEAVER_TOKEN = "weaver-token".getBytes(); + private static final byte[] PERSONALISATION_CONTEXT = + "android-synthetic-password-personalization-context".getBytes(); static class AuthenticationResult { public AuthenticationToken authToken; @@ -136,6 +139,7 @@ public class SyntheticPasswordManager { } static class AuthenticationToken { + private final byte mVersion; /* * Here is the relationship between all three fields: * P0 and P1 are two randomly-generated blocks. P1 is stored on disk but P0 is not. @@ -146,29 +150,38 @@ public class SyntheticPasswordManager { private @Nullable byte[] P1; private @NonNull String syntheticPassword; + AuthenticationToken(byte version) { + mVersion = version; + } + + private byte[] derivePassword(byte[] personalization) { + if (mVersion == SYNTHETIC_PASSWORD_VERSION_V3) { + return (new SP800Derive(syntheticPassword.getBytes())) + .withContext(personalization, PERSONALISATION_CONTEXT); + } else { + return SyntheticPasswordCrypto.personalisedHash(personalization, + syntheticPassword.getBytes()); + } + } + public String deriveKeyStorePassword() { - return bytesToHex(SyntheticPasswordCrypto.personalisedHash( - PERSONALIZATION_KEY_STORE_PASSWORD, syntheticPassword.getBytes())); + return bytesToHex(derivePassword(PERSONALIZATION_KEY_STORE_PASSWORD)); } public byte[] deriveGkPassword() { - return SyntheticPasswordCrypto.personalisedHash(PERSONALIZATION_SP_GK_AUTH, - syntheticPassword.getBytes()); + return derivePassword(PERSONALIZATION_SP_GK_AUTH); } public byte[] deriveDiskEncryptionKey() { - return SyntheticPasswordCrypto.personalisedHash(PERSONALIZATION_FBE_KEY, - syntheticPassword.getBytes()); + return derivePassword(PERSONALIZATION_FBE_KEY); } public byte[] deriveVendorAuthSecret() { - return SyntheticPasswordCrypto.personalisedHash(PERSONALIZATION_AUTHSECRET_KEY, - syntheticPassword.getBytes()); + return derivePassword(PERSONALIZATION_AUTHSECRET_KEY); } public byte[] derivePasswordHashFactor() { - return SyntheticPasswordCrypto.personalisedHash(PERSONALIZATION_PASSWORD_HASH, - syntheticPassword.getBytes()); + return derivePassword(PERSONALIZATION_PASSWORD_HASH); } private void initialize(byte[] P0, byte[] P1) { @@ -185,7 +198,7 @@ public class SyntheticPasswordManager { } protected static AuthenticationToken create() { - AuthenticationToken result = new AuthenticationToken(); + AuthenticationToken result = new AuthenticationToken(SYNTHETIC_PASSWORD_VERSION_V3); result.initialize(secureRandom(SYNTHETIC_PASSWORD_LENGTH), secureRandom(SYNTHETIC_PASSWORD_LENGTH)); return result; @@ -802,7 +815,16 @@ public class SyntheticPasswordManager { } byte[] content = createSPBlob(getHandleName(handle), secret, applicationId, sid); byte[] blob = new byte[content.length + 1 + 1]; - blob[0] = SYNTHETIC_PASSWORD_VERSION; + /* + * We can upgrade from v1 to v2 because that's just a change in the way that + * the SP is stored. However, we can't upgrade to v3 because that is a change + * in the way that passwords are derived from the SP. + */ + if (authToken.mVersion == SYNTHETIC_PASSWORD_VERSION_V3) { + blob[0] = SYNTHETIC_PASSWORD_VERSION_V3; + } else { + blob[0] = SYNTHETIC_PASSWORD_VERSION_V2; + } blob[1] = type; System.arraycopy(content, 0, blob, 2, content.length); saveState(SP_BLOB_NAME, blob, handle, userId); @@ -940,7 +962,9 @@ public class SyntheticPasswordManager { return null; } final byte version = blob[0]; - if (version != SYNTHETIC_PASSWORD_VERSION && version != SYNTHETIC_PASSWORD_VERSION_V1) { + if (version != SYNTHETIC_PASSWORD_VERSION_V3 + && version != SYNTHETIC_PASSWORD_VERSION_V2 + && version != SYNTHETIC_PASSWORD_VERSION_V1) { throw new RuntimeException("Unknown blob version"); } if (blob[1] != type) { @@ -958,7 +982,7 @@ public class SyntheticPasswordManager { Log.e(TAG, "Fail to decrypt SP for user " + userId); return null; } - AuthenticationToken result = new AuthenticationToken(); + AuthenticationToken result = new AuthenticationToken(version); if (type == SYNTHETIC_PASSWORD_TOKEN_BASED) { if (!loadEscrowData(result, userId)) { Log.e(TAG, "User is not escrowable: " + userId); diff --git a/services/core/java/com/android/server/slice/SlicePermissionManager.java b/services/core/java/com/android/server/slice/SlicePermissionManager.java index 315d5e39c94b..1d1c28f5f9b7 100644 --- a/services/core/java/com/android/server/slice/SlicePermissionManager.java +++ b/services/core/java/com/android/server/slice/SlicePermissionManager.java @@ -175,18 +175,24 @@ public class SlicePermissionManager implements DirtyTracker { handlePersist(); } for (String file : new File(mSliceDir.getAbsolutePath()).list()) { - if (file.isEmpty()) continue; try (ParserHolder parser = getParser(file)) { - Persistable p; - while (parser.parser.getEventType() != XmlPullParser.START_TAG) { + Persistable p = null; + while (parser.parser.getEventType() != XmlPullParser.END_DOCUMENT) { + if (parser.parser.getEventType() == XmlPullParser.START_TAG) { + if (SliceClientPermissions.TAG_CLIENT.equals(parser.parser.getName())) { + p = SliceClientPermissions.createFrom(parser.parser, tracker); + } else { + p = SliceProviderPermissions.createFrom(parser.parser, tracker); + } + break; + } parser.parser.next(); } - if (SliceClientPermissions.TAG_CLIENT.equals(parser.parser.getName())) { - p = SliceClientPermissions.createFrom(parser.parser, tracker); + if (p != null) { + p.writeTo(out); } else { - p = SliceProviderPermissions.createFrom(parser.parser, tracker); + Slog.w(TAG, "Invalid or empty slice permissions file: " + file); } - p.writeTo(out); } } diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java index 547ab0ed443d..0d0004134eb6 100644 --- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java +++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java @@ -541,6 +541,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub */ private void extractColors(WallpaperData wallpaper) { String cropFile = null; + boolean defaultImageWallpaper = false; int wallpaperId; synchronized (mLock) { @@ -549,6 +550,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub || wallpaper.wallpaperComponent == null; if (imageWallpaper && wallpaper.cropFile != null && wallpaper.cropFile.exists()) { cropFile = wallpaper.cropFile.getAbsolutePath(); + } else if (imageWallpaper && !wallpaper.cropExists() && !wallpaper.sourceExists()) { + defaultImageWallpaper = true; } wallpaperId = wallpaper.wallpaperId; } @@ -560,6 +563,25 @@ public class WallpaperManagerService extends IWallpaperManager.Stub colors = WallpaperColors.fromBitmap(bitmap); bitmap.recycle(); } + } else if (defaultImageWallpaper) { + // There is no crop and source file because this is default image wallpaper. + try (final InputStream is = + WallpaperManager.openDefaultWallpaper(mContext, FLAG_SYSTEM)) { + if (is != null) { + try { + final BitmapFactory.Options options = new BitmapFactory.Options(); + final Bitmap bitmap = BitmapFactory.decodeStream(is, null, options); + if (bitmap != null) { + colors = WallpaperColors.fromBitmap(bitmap); + bitmap.recycle(); + } + } catch (OutOfMemoryError e) { + Slog.w(TAG, "Can't decode default wallpaper stream", e); + } + } + } catch (IOException e) { + Slog.w(TAG, "Can't close default wallpaper stream", e); + } } if (colors == null) { diff --git a/services/tests/servicestests/src/com/android/server/locksettings/SP800DeriveTests.java b/services/tests/servicestests/src/com/android/server/locksettings/SP800DeriveTests.java new file mode 100644 index 000000000000..fc2dcb9cc83b --- /dev/null +++ b/services/tests/servicestests/src/com/android/server/locksettings/SP800DeriveTests.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2017 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.server.locksettings; + +import android.test.AndroidTestCase; + +import com.android.internal.util.HexDump; + +public class SP800DeriveTests extends AndroidTestCase { + public void testFixedInput() throws Exception { + // CAVP: https://csrc.nist.gov/projects/cryptographic-algorithm-validation-program/key-derivation + byte[] keyBytes = HexDump.hexStringToByteArray( + "e204d6d466aad507ffaf6d6dab0a5b26" + + "152c9e21e764370464e360c8fbc765c6"); + SP800Derive sk = new SP800Derive(keyBytes); + byte[] fixedInput = HexDump.hexStringToByteArray( + "7b03b98d9f94b899e591f3ef264b71b1" + + "93fba7043c7e953cde23bc5384bc1a62" + + "93580115fae3495fd845dadbd02bd645" + + "5cf48d0f62b33e62364a3a80"); + byte[] res = sk.fixedInput(fixedInput); + assertEquals(( + "770dfab6a6a4a4bee0257ff335213f78" + + "d8287b4fd537d5c1fffa956910e7c779").toUpperCase(), HexDump.toHexString(res)); + } +} diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ScheduleCalendarTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ScheduleCalendarTest.java index c0fecaf8ecb3..042c9d99eb8c 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/ScheduleCalendarTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/ScheduleCalendarTest.java @@ -333,6 +333,17 @@ public class ScheduleCalendarTest extends UiServiceTestCase { } @Test + public void testMaybeSetNextAlarm_expiredOldAlarm() { + mScheduleInfo.exitAtAlarm = true; + mScheduleInfo.nextAlarm = 998; + mScheduleCalendar.setSchedule(mScheduleInfo); + + mScheduleCalendar.maybeSetNextAlarm(1000, 1001); + + assertEquals(1001, mScheduleInfo.nextAlarm); + } + + @Test @FlakyTest public void testIsInSchedule_inScheduleOvernight() { Calendar cal = new GregorianCalendar(); diff --git a/services/tests/uiservicestests/src/com/android/server/slice/SlicePermissionManagerTest.java b/services/tests/uiservicestests/src/com/android/server/slice/SlicePermissionManagerTest.java index b9c979bb3230..1872530baa7a 100644 --- a/services/tests/uiservicestests/src/com/android/server/slice/SlicePermissionManagerTest.java +++ b/services/tests/uiservicestests/src/com/android/server/slice/SlicePermissionManagerTest.java @@ -16,6 +16,7 @@ package com.android.server.slice; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import android.content.ContentProvider; import android.content.ContentResolver; @@ -25,6 +26,7 @@ import android.os.FileUtils; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; +import android.util.Log; import android.util.Xml.Encoding; import androidx.test.filters.SmallTest; @@ -47,10 +49,12 @@ import java.io.IOException; @RunWith(AndroidTestingRunner.class) @RunWithLooper public class SlicePermissionManagerTest extends UiServiceTestCase { + private static final String TAG = "SlicePerManTest"; @Test public void testGrant() { - File sliceDir = new File(mContext.getDataDir(), "system/slices"); + File sliceDir = new File(mContext.getCacheDir(), "testGrantSlices"); + Log.v(TAG, "testGrant: slice permissions stored in " + sliceDir.getAbsolutePath()); SlicePermissionManager permissions = new SlicePermissionManager(mContext, TestableLooper.get(this).getLooper(), sliceDir); Uri uri = new Builder().scheme(ContentResolver.SCHEME_CONTENT) @@ -60,11 +64,15 @@ public class SlicePermissionManagerTest extends UiServiceTestCase { permissions.grantSliceAccess("my.pkg", 0, "provider.pkg", 0, uri); assertTrue(permissions.hasPermission("my.pkg", 0, uri)); + + // Cleanup. + assertTrue(FileUtils.deleteContentsAndDir(sliceDir)); } @Test public void testBackup() throws XmlPullParserException, IOException { - File sliceDir = new File(mContext.getDataDir(), "system/slices"); + File sliceDir = new File(mContext.getCacheDir(), "testBackupSlices"); + Log.v(TAG, "testBackup: slice permissions stored in " + sliceDir.getAbsolutePath()); Uri uri = new Builder().scheme(ContentResolver.SCHEME_CONTENT) .authority("authority") .path("something").build(); @@ -91,7 +99,10 @@ public class SlicePermissionManagerTest extends UiServiceTestCase { TestableLooper.get(this).getLooper()); permissions.readRestore(parser); - assertTrue(permissions.hasFullAccess("com.android.mypkg", 10)); + if (!permissions.hasFullAccess("com.android.mypkg", 10)) { + fail("com.android.mypkg@10 did not have full access. backup file: " + + output.toString()); + } assertTrue(permissions.hasPermission("com.android.otherpkg", 0, ContentProvider.maybeAddUserId(uri, 1))); permissions.removePkg("com.android.lastpkg", 1); @@ -103,8 +114,9 @@ public class SlicePermissionManagerTest extends UiServiceTestCase { } @Test - public void testInvalid() throws Exception { - File sliceDir = new File(mContext.getCacheDir(), "slices-test"); + public void testInvalid() { + File sliceDir = new File(mContext.getCacheDir(), "testInvalidSlices"); + Log.v(TAG, "testInvalid: slice permissions stored in " + sliceDir.getAbsolutePath()); if (!sliceDir.exists()) { sliceDir.mkdir(); } @@ -119,7 +131,8 @@ public class SlicePermissionManagerTest extends UiServiceTestCase { @Override public void writeTo(XmlSerializer out) throws IOException { - throw new RuntimeException("this doesn't work"); + throw new RuntimeException("this RuntimeException inside junk.writeTo() " + + "should be caught and suppressed by surrounding code"); } }; diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java index e949e7490230..b0eb3163d48e 100644 --- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java +++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java @@ -69,8 +69,6 @@ import android.os.storage.StorageVolume; import android.provider.Settings; import android.service.usb.UsbDeviceManagerProto; import android.service.usb.UsbHandlerProto; -import android.sysprop.AdbProperties; -import android.sysprop.VoldProperties; import android.util.Pair; import android.util.Slog; @@ -286,8 +284,8 @@ public class UsbDeviceManager implements ActivityManagerInternal.ScreenObserver } mControlFds.put(UsbManager.FUNCTION_PTP, ptpFd); - boolean secureAdbEnabled = AdbProperties.secure().orElse(false); - boolean dataEncrypted = "1".equals(VoldProperties.decrypt().orElse("")); + boolean secureAdbEnabled = SystemProperties.getBoolean("ro.adb.secure", false); + boolean dataEncrypted = "1".equals(SystemProperties.get("vold.decrypt")); if (secureAdbEnabled && !dataEncrypted) { mDebuggingManager = new UsbDebuggingManager(context); } |