Merge "Prevent recents from closing while moving PiP to fullscreen." into nyc-dev
diff --git a/api/current.txt b/api/current.txt
index 61345fd..7fe5728 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -29146,7 +29146,6 @@
field public static final int RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY = 1; // 0x1
field public static final deprecated int SCREEN_BRIGHT_WAKE_LOCK = 10; // 0xa
field public static final deprecated int SCREEN_DIM_WAKE_LOCK = 6; // 0x6
- field public static final int SUSTAINED_PERFORMANCE_WAKE_LOCK = 256; // 0x100
}
public final class PowerManager.WakeLock {
@@ -43630,6 +43629,7 @@
method public void setSharedElementsUseOverlay(boolean);
method public void setSoftInputMode(int);
method public abstract void setStatusBarColor(int);
+ method public void setSustainedPerformanceMode(boolean);
method public abstract void setTitle(java.lang.CharSequence);
method public abstract deprecated void setTitleColor(int);
method public void setTransitionBackgroundFadeDuration(long);
@@ -58086,6 +58086,7 @@
method public java.lang.Object clone();
method public java.util.Set<java.util.Map.Entry<K, V>> entrySet();
method public void forEach(java.util.function.BiConsumer<? super K, ? super V>);
+ method public void replaceAll(java.util.function.BiFunction<? super K, ? super V, ? extends V>);
}
public class IllegalFormatCodePointException extends java.util.IllegalFormatException {
@@ -59068,6 +59069,8 @@
method public java.util.NavigableSet<K> navigableKeySet();
method public java.util.Map.Entry<K, V> pollFirstEntry();
method public java.util.Map.Entry<K, V> pollLastEntry();
+ method public boolean replace(K, V, V);
+ method public V replace(K, V);
method public void replaceAll(java.util.function.BiFunction<? super K, ? super V, ? extends V>);
method public java.util.NavigableMap<K, V> subMap(K, boolean, K, boolean);
method public java.util.SortedMap<K, V> subMap(K, K);
diff --git a/api/system-current.txt b/api/system-current.txt
index d44e157..dfaae6b 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -31574,7 +31574,6 @@
field public static final int RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY = 1; // 0x1
field public static final deprecated int SCREEN_BRIGHT_WAKE_LOCK = 10; // 0xa
field public static final deprecated int SCREEN_DIM_WAKE_LOCK = 6; // 0x6
- field public static final int SUSTAINED_PERFORMANCE_WAKE_LOCK = 256; // 0x100
field public static final int USER_ACTIVITY_EVENT_ACCESSIBILITY = 3; // 0x3
field public static final int USER_ACTIVITY_EVENT_BUTTON = 1; // 0x1
field public static final int USER_ACTIVITY_EVENT_OTHER = 0; // 0x0
@@ -46579,6 +46578,7 @@
method public void setSharedElementsUseOverlay(boolean);
method public void setSoftInputMode(int);
method public abstract void setStatusBarColor(int);
+ method public void setSustainedPerformanceMode(boolean);
method public abstract void setTitle(java.lang.CharSequence);
method public abstract deprecated void setTitleColor(int);
method public void setTransitionBackgroundFadeDuration(long);
@@ -61392,6 +61392,7 @@
method public java.lang.Object clone();
method public java.util.Set<java.util.Map.Entry<K, V>> entrySet();
method public void forEach(java.util.function.BiConsumer<? super K, ? super V>);
+ method public void replaceAll(java.util.function.BiFunction<? super K, ? super V, ? extends V>);
}
public class IllegalFormatCodePointException extends java.util.IllegalFormatException {
@@ -62374,6 +62375,8 @@
method public java.util.NavigableSet<K> navigableKeySet();
method public java.util.Map.Entry<K, V> pollFirstEntry();
method public java.util.Map.Entry<K, V> pollLastEntry();
+ method public boolean replace(K, V, V);
+ method public V replace(K, V);
method public void replaceAll(java.util.function.BiFunction<? super K, ? super V, ? extends V>);
method public java.util.NavigableMap<K, V> subMap(K, boolean, K, boolean);
method public java.util.SortedMap<K, V> subMap(K, K);
diff --git a/api/test-current.txt b/api/test-current.txt
index 4020993..88031cf 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -29214,7 +29214,6 @@
field public static final int RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY = 1; // 0x1
field public static final deprecated int SCREEN_BRIGHT_WAKE_LOCK = 10; // 0xa
field public static final deprecated int SCREEN_DIM_WAKE_LOCK = 6; // 0x6
- field public static final int SUSTAINED_PERFORMANCE_WAKE_LOCK = 256; // 0x100
}
public final class PowerManager.WakeLock {
@@ -43707,6 +43706,7 @@
method public void setSharedElementsUseOverlay(boolean);
method public void setSoftInputMode(int);
method public abstract void setStatusBarColor(int);
+ method public void setSustainedPerformanceMode(boolean);
method public abstract void setTitle(java.lang.CharSequence);
method public abstract deprecated void setTitleColor(int);
method public void setTransitionBackgroundFadeDuration(long);
@@ -58164,6 +58164,7 @@
method public java.lang.Object clone();
method public java.util.Set<java.util.Map.Entry<K, V>> entrySet();
method public void forEach(java.util.function.BiConsumer<? super K, ? super V>);
+ method public void replaceAll(java.util.function.BiFunction<? super K, ? super V, ? extends V>);
}
public class IllegalFormatCodePointException extends java.util.IllegalFormatException {
@@ -59146,6 +59147,8 @@
method public java.util.NavigableSet<K> navigableKeySet();
method public java.util.Map.Entry<K, V> pollFirstEntry();
method public java.util.Map.Entry<K, V> pollLastEntry();
+ method public boolean replace(K, V, V);
+ method public V replace(K, V);
method public void replaceAll(java.util.function.BiFunction<? super K, ? super V, ? extends V>);
method public java.util.NavigableMap<K, V> subMap(K, boolean, K, boolean);
method public java.util.SortedMap<K, V> subMap(K, K);
diff --git a/core/java/android/app/IWallpaperManager.aidl b/core/java/android/app/IWallpaperManager.aidl
index 2fc6533..a42aed6 100644
--- a/core/java/android/app/IWallpaperManager.aidl
+++ b/core/java/android/app/IWallpaperManager.aidl
@@ -43,7 +43,8 @@
* new wallpaper content is ready to display.
*/
ParcelFileDescriptor setWallpaper(String name, in String callingPackage,
- in Rect cropHint, out Bundle extras, int which, IWallpaperManagerCallback completion);
+ in Rect cropHint, boolean allowBackup, out Bundle extras, int which,
+ IWallpaperManagerCallback completion);
/**
* Set the live wallpaper. This only affects the system wallpaper.
@@ -125,6 +126,11 @@
boolean isWallpaperSettingAllowed(in String callingPackage);
/*
+ * Backup: is the current system wallpaper image eligible for off-device backup?
+ */
+ boolean isWallpaperBackupEligible(int userId);
+
+ /*
* Keyguard: register a callback for being notified that lock-state relevant
* wallpaper content has changed.
*/
diff --git a/core/java/android/app/ResourcesManager.java b/core/java/android/app/ResourcesManager.java
index aef92cf..d8a3d4f 100644
--- a/core/java/android/app/ResourcesManager.java
+++ b/core/java/android/app/ResourcesManager.java
@@ -224,7 +224,7 @@
* @return a new AssetManager.
*/
@VisibleForTesting
- protected AssetManager createAssetManager(@NonNull final ResourcesKey key) {
+ protected @NonNull AssetManager createAssetManager(@NonNull final ResourcesKey key) {
AssetManager assets = new AssetManager();
// resDir can be null if the 'android' package is creating a new Resources object.
@@ -232,14 +232,15 @@
// already.
if (key.mResDir != null) {
if (assets.addAssetPath(key.mResDir) == 0) {
- return null;
+ throw new IllegalArgumentException("failed to add asset path " + key.mResDir);
}
}
if (key.mSplitResDirs != null) {
for (final String splitResDir : key.mSplitResDirs) {
if (assets.addAssetPath(splitResDir) == 0) {
- return null;
+ throw new IllegalArgumentException(
+ "failed to add split asset path " + splitResDir);
}
}
}
diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java
index 72b9318..18a5593 100644
--- a/core/java/android/app/WallpaperManager.java
+++ b/core/java/android/app/WallpaperManager.java
@@ -1,5 +1,5 @@
/*
-h * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2009 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.
@@ -875,7 +875,7 @@
/* Set the wallpaper to the default values */
ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(
"res:" + resources.getResourceName(resid),
- mContext.getOpPackageName(), null, result, which, completion);
+ mContext.getOpPackageName(), null, false, result, which, completion);
if (fd != null) {
FileOutputStream fos = null;
boolean ok = false;
@@ -985,7 +985,8 @@
final WallpaperSetCompletion completion = new WallpaperSetCompletion();
try {
ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null,
- mContext.getOpPackageName(), visibleCropHint, result, which, completion);
+ mContext.getOpPackageName(), visibleCropHint, allowBackup,
+ result, which, completion);
if (fd != null) {
FileOutputStream fos = null;
try {
@@ -1102,7 +1103,8 @@
final WallpaperSetCompletion completion = new WallpaperSetCompletion();
try {
ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null,
- mContext.getOpPackageName(), visibleCropHint, result, which, completion);
+ mContext.getOpPackageName(), visibleCropHint, allowBackup,
+ result, which, completion);
if (fd != null) {
FileOutputStream fos = null;
try {
@@ -1565,6 +1567,25 @@
}
}
+ /**
+ * Is the current system wallpaper eligible for backup?
+ *
+ * Only the OS itself may use this method.
+ * @hide
+ */
+ public boolean isWallpaperBackupEligible() {
+ if (sGlobals.mService == null) {
+ Log.w(TAG, "WallpaperService not running");
+ return false;
+ }
+ try {
+ return sGlobals.mService.isWallpaperBackupEligible(mContext.getUserId());
+ } catch (RemoteException e) {
+ Log.e(TAG, "Exception querying wallpaper backup eligibility: " + e.getMessage());
+ }
+ return false;
+ }
+
// Private completion callback for setWallpaper() synchronization
private class WallpaperSetCompletion extends IWallpaperManagerCallback.Stub {
final CountDownLatch mLatch;
diff --git a/core/java/android/hardware/camera2/impl/CameraCaptureSessionImpl.java b/core/java/android/hardware/camera2/impl/CameraCaptureSessionImpl.java
index 5573896..6736d34 100644
--- a/core/java/android/hardware/camera2/impl/CameraCaptureSessionImpl.java
+++ b/core/java/android/hardware/camera2/impl/CameraCaptureSessionImpl.java
@@ -628,7 +628,12 @@
* close the camera further by unconfiguring and then firing {@code onClosed}.</p>
*/
private void finishPendingSequence(int sequenceId) {
- mSequenceDrainer.taskFinished(sequenceId);
+ try {
+ mSequenceDrainer.taskFinished(sequenceId);
+ } catch (IllegalStateException e) {
+ // Workaround for b/27870771
+ Log.w(TAG, e.getMessage());
+ }
}
private class SequenceDrainListener implements TaskDrainer.DrainListener {
diff --git a/core/java/android/hardware/fingerprint/FingerprintManager.java b/core/java/android/hardware/fingerprint/FingerprintManager.java
index 271ec79..1ff2e8a 100644
--- a/core/java/android/hardware/fingerprint/FingerprintManager.java
+++ b/core/java/android/hardware/fingerprint/FingerprintManager.java
@@ -590,7 +590,7 @@
if (mService != null) try {
mRemovalCallback = callback;
mRemovalFingerprint = fp;
- mService.remove(mToken, fp.getFingerId(), userId, mServiceReceiver);
+ mService.remove(mToken, fp.getFingerId(), fp.getGroupId(), userId, mServiceReceiver);
} catch (RemoteException e) {
Log.w(TAG, "Remote exception in remove: ", e);
if (callback != null) {
@@ -810,11 +810,13 @@
if (mRemovalCallback != null) {
int reqFingerId = mRemovalFingerprint.getFingerId();
int reqGroupId = mRemovalFingerprint.getGroupId();
- if (reqFingerId != 0 && fingerId != reqFingerId) {
+ if (reqFingerId != 0 && fingerId != 0 && fingerId != reqFingerId) {
Log.w(TAG, "Finger id didn't match: " + fingerId + " != " + reqFingerId);
+ return;
}
if (groupId != reqGroupId) {
Log.w(TAG, "Group id didn't match: " + groupId + " != " + reqGroupId);
+ return;
}
mRemovalCallback.onRemovalSucceeded(new Fingerprint(null, groupId, fingerId,
deviceId));
diff --git a/core/java/android/hardware/fingerprint/IFingerprintService.aidl b/core/java/android/hardware/fingerprint/IFingerprintService.aidl
index d7915e3..a83397a 100644
--- a/core/java/android/hardware/fingerprint/IFingerprintService.aidl
+++ b/core/java/android/hardware/fingerprint/IFingerprintService.aidl
@@ -41,7 +41,8 @@
void cancelEnrollment(IBinder token);
// Any errors resulting from this call will be returned to the listener
- void remove(IBinder token, int fingerId, int groupId, IFingerprintServiceReceiver receiver);
+ void remove(IBinder token, int fingerId, int groupId, int userId,
+ IFingerprintServiceReceiver receiver);
// Rename the fingerprint specified by fingerId and groupId to the given name
void rename(int fingerId, int groupId, String name);
diff --git a/core/java/android/hardware/location/ContextHubManager.java b/core/java/android/hardware/location/ContextHubManager.java
index 89edaa9..0c3d4b3 100644
--- a/core/java/android/hardware/location/ContextHubManager.java
+++ b/core/java/android/hardware/location/ContextHubManager.java
@@ -43,6 +43,12 @@
private Handler mCallbackHandler;
/**
+ * @deprecated Use {@code mCallback} instead.
+ */
+ @Deprecated
+ private ICallback mLocalCallback;
+
+ /**
* An interface to receive asynchronous communication from the context hub.
*/
public abstract static class Callback {
@@ -64,6 +70,24 @@
}
/**
+ * @deprecated Use {@link Callback} instead.
+ * @hide
+ */
+ @Deprecated
+ public interface ICallback {
+ /**
+ * Callback function called on message receipt from context hub.
+ *
+ * @param hubHandle Handle (system-wide unique identifier) of the hub of the message.
+ * @param nanoAppHandle Handle (unique identifier) for app instance that sent the message.
+ * @param message The context hub message.
+ *
+ * @see ContextHubMessage
+ */
+ void onMessageReceipt(int hubHandle, int nanoAppHandle, ContextHubMessage message);
+ }
+
+ /**
* Get a handle to all the context hubs in the system
* @return array of context hub handles
*/
@@ -223,6 +247,20 @@
}
/**
+ * @deprecated Use {@link #registerCallback(Callback)} instead.
+ * @hide
+ */
+ @Deprecated
+ public int registerCallback(ICallback callback) {
+ if (mLocalCallback != null) {
+ Log.w(TAG, "Max number of local callbacks reached!");
+ return -1;
+ }
+ mLocalCallback = callback;
+ return 0;
+ }
+
+ /**
* Set a callback to receive messages from the context hub
*
* @param callback Callback object
@@ -266,6 +304,19 @@
return 0;
}
+ /**
+ * @deprecated Use {@link #unregisterCallback(Callback)} instead.
+ * @hide
+ */
+ public synchronized int unregisterCallback(ICallback callback) {
+ if (callback != mLocalCallback) {
+ Log.w(TAG, "Cannot recognize local callback!");
+ return -1;
+ }
+ mLocalCallback = null;
+ return 0;
+ }
+
private IContextHubCallback.Stub mClientCallback = new IContextHubCallback.Stub() {
@Override
public void onMessageReceipt(final int hubId, final int nanoAppId,
@@ -282,6 +333,12 @@
}
});
}
+ } else if (mLocalCallback != null) {
+ // we always ensure that mCallback takes precedence, because mLocalCallback is only
+ // for internal compatibility
+ synchronized (this) {
+ mLocalCallback.onMessageReceipt(hubId, nanoAppId, message);
+ }
} else {
Log.d(TAG, "Context hub manager client callback is NULL");
}
diff --git a/core/java/android/hardware/location/ContextHubService.java b/core/java/android/hardware/location/ContextHubService.java
index 2b9b974..8176189 100644
--- a/core/java/android/hardware/location/ContextHubService.java
+++ b/core/java/android/hardware/location/ContextHubService.java
@@ -19,6 +19,7 @@
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
+import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.util.Log;
@@ -57,19 +58,17 @@
private static final int OS_APP_INSTANCE = -1;
private final Context mContext;
-
- private HashMap<Integer, NanoAppInstanceInfo> mNanoAppHash;
- private ContextHubInfo[] mContextHubInfo;
- private IContextHubCallback mCallback;
+ private final HashMap<Integer, NanoAppInstanceInfo> mNanoAppHash = new HashMap<>();
+ private final ContextHubInfo[] mContextHubInfo;
+ private final RemoteCallbackList<IContextHubCallback> mCallbacksList =
+ new RemoteCallbackList<>();
private native int nativeSendMessage(int[] header, byte[] data);
private native ContextHubInfo[] nativeInitialize();
-
public ContextHubService(Context context) {
mContext = context;
mContextHubInfo = nativeInitialize();
- mNanoAppHash = new HashMap<Integer, NanoAppInstanceInfo>();
for (int i = 0; i < mContextHubInfo.length; i++) {
Log.d(TAG, "ContextHub[" + i + "] id: " + mContextHubInfo[i].getId()
@@ -80,9 +79,7 @@
@Override
public int registerCallback(IContextHubCallback callback) throws RemoteException {
checkPermissions();
- synchronized (this) {
- mCallback = callback;
- }
+ mCallbacksList.register(callback);
return 0;
}
@@ -237,26 +234,26 @@
if (header == null || data == null || header.length < MSG_HEADER_SIZE) {
return -1;
}
-
- synchronized (this) {
- if (mCallback != null) {
- ContextHubMessage msg = new ContextHubMessage(header[MSG_FIELD_TYPE],
- header[MSG_FIELD_VERSION],
- data);
-
- try {
- mCallback.onMessageReceipt(header[MSG_FIELD_HUB_HANDLE],
- header[MSG_FIELD_APP_INSTANCE],
- msg);
- } catch (Exception e) {
- Log.w(TAG, "Exception " + e + " when calling remote callback");
- return -1;
- }
- } else {
- Log.d(TAG, "Message Callback is NULL");
+ int callbacksCount = mCallbacksList.beginBroadcast();
+ if (callbacksCount < 1) {
+ Log.v(TAG, "No message callbacks registered.");
+ return 0;
+ }
+ ContextHubMessage message =
+ new ContextHubMessage(header[MSG_FIELD_TYPE], header[MSG_FIELD_VERSION], data);
+ for (int i = 0; i < callbacksCount; ++i) {
+ IContextHubCallback callback = mCallbacksList.getBroadcastItem(i);
+ try {
+ callback.onMessageReceipt(
+ header[MSG_FIELD_HUB_HANDLE],
+ header[MSG_FIELD_APP_INSTANCE],
+ message);
+ } catch (RemoteException e) {
+ Log.i(TAG, "Exception (" + e + ") calling remote callback (" + callback + ").");
+ continue;
}
}
-
+ mCallbacksList.finishBroadcast();
return 0;
}
diff --git a/core/java/android/hardware/location/NanoAppInstanceInfo.java b/core/java/android/hardware/location/NanoAppInstanceInfo.java
index e842ec6..71a5a88 100644
--- a/core/java/android/hardware/location/NanoAppInstanceInfo.java
+++ b/core/java/android/hardware/location/NanoAppInstanceInfo.java
@@ -17,10 +17,14 @@
package android.hardware.location;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
+import libcore.util.EmptyArray;
+
/**
* @hide
*/
@@ -43,6 +47,8 @@
private int mHandle;
public NanoAppInstanceInfo() {
+ mNeededSensors = EmptyArray.INT;
+ mOutputEvents = EmptyArray.INT;
}
/**
@@ -193,6 +199,7 @@
*
* @return int[] all the required sensors needed by this app
*/
+ @NonNull
public int[] getNeededSensors() {
return mNeededSensors;
}
@@ -204,8 +211,8 @@
*
* @hide
*/
- public void setNeededSensors(int[] neededSensors) {
- mNeededSensors = neededSensors;
+ public void setNeededSensors(@Nullable int[] neededSensors) {
+ mNeededSensors = neededSensors != null ? neededSensors : EmptyArray.INT;
}
/**
@@ -213,6 +220,7 @@
*
* @return all the events that can be generated by this app
*/
+ @NonNull
public int[] getOutputEvents() {
return mOutputEvents;
}
@@ -225,8 +233,8 @@
*
* @hide
*/
- public void setOutputEvents(int[] outputEvents) {
- mOutputEvents = outputEvents;
+ public void setOutputEvents(@Nullable int[] outputEvents) {
+ mOutputEvents = outputEvents != null ? outputEvents : EmptyArray.INT;
}
/**
@@ -280,12 +288,12 @@
mNeededWriteMemBytes = in.readInt();
mNeededExecMemBytes = in.readInt();
- int mNeededSensorsLength = in.readInt();
- mNeededSensors = new int[mNeededSensorsLength];
+ int neededSensorsLength = in.readInt();
+ mNeededSensors = new int[neededSensorsLength];
in.readIntArray(mNeededSensors);
- int mOutputEventsLength = in.readInt();
- mOutputEvents = new int[mOutputEventsLength];
+ int outputEventsLength = in.readInt();
+ mOutputEvents = new int[outputEventsLength];
in.readIntArray(mOutputEvents);
}
@@ -303,9 +311,9 @@
out.writeInt(mNeededWriteMemBytes);
out.writeInt(mNeededExecMemBytes);
+ // arrays are never null
out.writeInt(mNeededSensors.length);
out.writeIntArray(mNeededSensors);
-
out.writeInt(mOutputEvents.length);
out.writeIntArray(mOutputEvents);
}
diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java
index 92edc62..16d90de 100644
--- a/core/java/android/os/PowerManager.java
+++ b/core/java/android/os/PowerManager.java
@@ -219,15 +219,6 @@
public static final int DRAW_WAKE_LOCK = 0x00000080;
/**
- * Wake lock level: Enables Sustained Performance Mode.
- * <p>
- * This is used by Gaming and VR applications to ensure the device
- * will provide consistent performance over a large amount of time.
- * </p>
- */
- public static final int SUSTAINED_PERFORMANCE_WAKE_LOCK = 0x00000100;
-
- /**
* Mask for the wake lock level component of a combined wake lock level and flags integer.
*
* @hide
@@ -559,7 +550,6 @@
case PROXIMITY_SCREEN_OFF_WAKE_LOCK:
case DOZE_WAKE_LOCK:
case DRAW_WAKE_LOCK:
- case SUSTAINED_PERFORMANCE_WAKE_LOCK:
break;
default:
throw new IllegalArgumentException("Must specify a valid wake lock level.");
diff --git a/core/java/android/os/PowerManagerInternal.java b/core/java/android/os/PowerManagerInternal.java
index 9801e1b..b3cf710 100644
--- a/core/java/android/os/PowerManagerInternal.java
+++ b/core/java/android/os/PowerManagerInternal.java
@@ -55,12 +55,16 @@
/**
- * Power hint: The user is interacting with the device. The corresponding data field must be
+ * Power hint:
+ * Interaction: The user is interacting with the device. The corresponding data field must be
* the expected duration of the fling, or 0 if unknown.
*
- * This must be kept in sync with the values in hardware/libhardware/include/hardware/power.h
+ * Sustained Performance Mode: Enable/Disables Sustained Performance Mode.
+ *
+ * These must be kept in sync with the values in hardware/libhardware/include/hardware/power.h
*/
public static final int POWER_HINT_INTERACTION = 2;
+ public static final int POWER_HINT_SUSTAINED_PERFORMANCE_MODE = 6;
public static String wakefulnessToString(int wakefulness) {
switch (wakefulness) {
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 6b60f47..d80d4be 100755
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -6043,6 +6043,33 @@
public static final String ENABLED_VR_LISTENERS = "enabled_vr_listeners";
/**
+ * Behavior of the display while in VR mode.
+ *
+ * One of {@link #VR_DISPLAY_MODE_LOW_PERSISTENCE} or {@link #VR_DISPLAY_MODE_OFF}.
+ *
+ * @hide
+ */
+ public static final String VR_DISPLAY_MODE = "vr_display_mode";
+
+ /**
+ * Lower the display persistence while the system is in VR mode.
+ *
+ * @see PackageManager#FEATURE_VR_MODE_HIGH_PERFORMANCE
+ *
+ * @hide.
+ */
+ public static final int VR_DISPLAY_MODE_LOW_PERSISTENCE = 0;
+
+ /**
+ * Do not alter the display persistence while the system is in VR mode.
+ *
+ * @see PackageManager#FEATURE_VR_MODE_HIGH_PERFORMANCE
+ *
+ * @hide.
+ */
+ public static final int VR_DISPLAY_MODE_OFF = 1;
+
+ /**
* This are the settings to be backed up.
*
* NOTE: Settings are backed up and restored in the order they appear
diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java
index 2f3f0bf..5135657 100644
--- a/core/java/android/view/Window.java
+++ b/core/java/android/view/Window.java
@@ -1177,6 +1177,15 @@
return false;
}
+ /* Sets the Sustained Performance requirement for the calling window.
+ * @param enable disables or enables the mode.
+ */
+ public void setSustainedPerformanceMode(boolean enable) {
+ setPrivateFlags(enable
+ ? WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE : 0,
+ WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE);
+ }
+
private boolean isOutOfBounds(Context context, MotionEvent event) {
final int x = (int) event.getX();
final int y = (int) event.getY();
diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java
index 89e146b..54e9942 100644
--- a/core/java/android/view/WindowManager.java
+++ b/core/java/android/view/WindowManager.java
@@ -1247,6 +1247,13 @@
public static final int PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND = 0x00020000;
/**
+ * Flag to indicate that this window needs Sustained Performance Mode if
+ * the device supports it.
+ * @hide
+ */
+ public static final int PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE = 0x00020000;
+
+ /**
* Control flags that are private to the platform.
* @hide
*/
diff --git a/core/java/com/android/server/backup/SystemBackupAgent.java b/core/java/com/android/server/backup/SystemBackupAgent.java
index 2d12fcd..3e45309 100644
--- a/core/java/com/android/server/backup/SystemBackupAgent.java
+++ b/core/java/com/android/server/backup/SystemBackupAgent.java
@@ -76,26 +76,6 @@
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
ParcelFileDescriptor newState) throws IOException {
- // We only back up the data under the current "wallpaper" schema with metadata
- IWallpaperManager wallpaper = (IWallpaperManager)ServiceManager.getService(
- Context.WALLPAPER_SERVICE);
- String[] files = new String[] { WALLPAPER_IMAGE, WALLPAPER_INFO };
- String[] keys = new String[] { WALLPAPER_IMAGE_KEY, WALLPAPER_INFO_KEY };
- if (wallpaper != null) {
- try {
- final String wallpaperName = wallpaper.getName();
- if (wallpaperName != null && wallpaperName.length() > 0) {
- // When the wallpaper has a name, back up the info by itself.
- // TODO: Don't rely on the innards of the service object like this!
- // TODO: Send a delete for any stored wallpaper image in this case?
- files = new String[] { WALLPAPER_INFO };
- keys = new String[] { WALLPAPER_INFO_KEY };
- }
- } catch (RemoteException re) {
- Slog.e(TAG, "Couldn't get wallpaper name\n" + re);
- }
- }
- addHelper(WALLPAPER_HELPER, new WallpaperBackupHelper(this, files, keys));
addHelper(SYNC_SETTINGS_HELPER, new AccountSyncSettingsBackupHelper(this));
addHelper(PREFERRED_HELPER, new PreferredActivityBackupHelper());
addHelper(NOTIFICATION_HELPER, new NotificationBackupHelper(this));
@@ -107,30 +87,20 @@
@Override
public void onFullBackup(FullBackupDataOutput data) throws IOException {
- // At present we back up only the wallpaper
- fullWallpaperBackup(data);
- }
-
- private void fullWallpaperBackup(FullBackupDataOutput output) {
- // Back up the data files directly. We do them in this specific order --
- // info file followed by image -- because then we need take no special
- // steps during restore; the restore will happen properly when the individual
- // files are restored piecemeal.
- FullBackup.backupToTar(getPackageName(), FullBackup.ROOT_TREE_TOKEN, null,
- WALLPAPER_INFO_DIR, WALLPAPER_INFO, output);
- FullBackup.backupToTar(getPackageName(), FullBackup.ROOT_TREE_TOKEN, null,
- WALLPAPER_IMAGE_DIR, WALLPAPER_IMAGE, output);
+ // At present we don't back up anything
}
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
throws IOException {
+ // Slot in a restore helper for the older wallpaper backup schema to support restore
+ // from devices still generating data in that format.
mWallpaperHelper = new WallpaperBackupHelper(this,
new String[] { WALLPAPER_IMAGE, WALLPAPER_INFO },
new String[] { WALLPAPER_IMAGE_KEY, WALLPAPER_INFO_KEY} );
addHelper(WALLPAPER_HELPER, mWallpaperHelper);
- // On restore, we also support a previous data schema "system_files"
+ // On restore, we also support a long-ago wallpaper data schema "system_files"
addHelper("system_files", new WallpaperBackupHelper(this,
new String[] { WALLPAPER_IMAGE },
new String[] { WALLPAPER_IMAGE_KEY} ));
diff --git a/media/java/android/media/midi/MidiDevice.java b/media/java/android/media/midi/MidiDevice.java
index e4588fe..da44ca6 100644
--- a/media/java/android/media/midi/MidiDevice.java
+++ b/media/java/android/media/midi/MidiDevice.java
@@ -42,6 +42,7 @@
private final IMidiManager mMidiManager;
private final IBinder mClientToken;
private final IBinder mDeviceToken;
+ private boolean mIsDeviceClosed;
private final CloseGuard mGuard = CloseGuard.get();
@@ -123,6 +124,9 @@
* or null in case of failure.
*/
public MidiInputPort openInputPort(int portNumber) {
+ if (mIsDeviceClosed) {
+ return null;
+ }
try {
IBinder token = new Binder();
ParcelFileDescriptor pfd = mDeviceServer.openInputPort(token, portNumber);
@@ -146,6 +150,9 @@
* or null in case of failure.
*/
public MidiOutputPort openOutputPort(int portNumber) {
+ if (mIsDeviceClosed) {
+ return null;
+ }
try {
IBinder token = new Binder();
ParcelFileDescriptor pfd = mDeviceServer.openOutputPort(token, portNumber);
@@ -175,12 +182,15 @@
if (outputPortNumber < 0 || outputPortNumber >= mDeviceInfo.getOutputPortCount()) {
throw new IllegalArgumentException("outputPortNumber out of range");
}
+ if (mIsDeviceClosed) {
+ return null;
+ }
ParcelFileDescriptor pfd = inputPort.claimFileDescriptor();
if (pfd == null) {
return null;
}
- try {
+ try {
IBinder token = new Binder();
int calleePid = mDeviceServer.connectPorts(token, pfd, outputPortNumber);
// If the service is a different Process then it will duplicate the pfd
@@ -202,11 +212,14 @@
@Override
public void close() throws IOException {
synchronized (mGuard) {
- mGuard.close();
- try {
- mMidiManager.closeDevice(mClientToken, mDeviceToken);
- } catch (RemoteException e) {
- Log.e(TAG, "RemoteException in closeDevice");
+ if (!mIsDeviceClosed) {
+ mGuard.close();
+ mIsDeviceClosed = true;
+ try {
+ mMidiManager.closeDevice(mClientToken, mDeviceToken);
+ } catch (RemoteException e) {
+ Log.e(TAG, "RemoteException in closeDevice");
+ }
}
}
}
diff --git a/packages/Shell/src/com/android/shell/BugreportProgressService.java b/packages/Shell/src/com/android/shell/BugreportProgressService.java
index ec3a7fc..7023a1a 100644
--- a/packages/Shell/src/com/android/shell/BugreportProgressService.java
+++ b/packages/Shell/src/com/android/shell/BugreportProgressService.java
@@ -198,6 +198,11 @@
private File mScreenshotsDir;
/**
+ * id of the notification used to set service on foreground.
+ */
+ private int mForegroundId = -1;
+
+ /**
* Flag indicating whether a screenshot is being taken.
* <p>
* This is the only state that is shared between the 2 handlers and hence must have synchronized
@@ -257,6 +262,7 @@
writer.printf("No monitored processes");
return;
}
+ writer.printf("Foreground id: %d\n\n", mForegroundId);
writer.printf("Monitored dumpstate processes\n");
writer.printf("-----------------------------\n");
for (int i = 0; i < size; i++) {
@@ -479,10 +485,21 @@
return;
}
if (DEBUG) {
- Log.d(TAG, "Sending 'Progress' notification for id " + info.id + "(pid " + info.pid
+ Log.d(TAG, "Sending 'Progress' notification for id " + info.id + " (pid " + info.pid
+ "): " + percentageText);
}
- NotificationManager.from(mContext).notify(TAG, info.id, notification);
+ sendForegroundabledNotification(info.id, notification);
+ }
+
+ private void sendForegroundabledNotification(int id, Notification notification) {
+ if (mForegroundId >= 0) {
+ if (DEBUG) Log.d(TAG, "Already running as foreground service");
+ NotificationManager.from(mContext).notify(id, notification);
+ } else {
+ mForegroundId = id;
+ Log.d(TAG, "Start running as foreground service on id " + mForegroundId);
+ startForeground(mForegroundId, notification);
+ }
}
/**
@@ -506,8 +523,10 @@
Log.d(TAG, "Removing ID " + id);
mProcesses.remove(id);
}
- Log.v(TAG, "stopProgress(" + id + "): cancel notification");
- NotificationManager.from(mContext).cancel(TAG, id);
+ // Must stop foreground service first, otherwise notif.cancel() will fail below.
+ stopForegroundWhenDone(id);
+ Log.d(TAG, "stopProgress(" + id + "): cancel notification");
+ NotificationManager.from(mContext).cancel(id);
stopSelfWhenDone();
}
@@ -625,7 +644,7 @@
Log.w(TAG, "launchBugreportInfoDialog(): canceling notification because id " + id
+ " was not found");
// TODO: add test case to make sure notification is canceled.
- NotificationManager.from(mContext).cancel(TAG, id);
+ NotificationManager.from(mContext).cancel(id);
return;
}
@@ -648,7 +667,7 @@
Log.w(TAG, "takeScreenshot(): canceling notification because id " + id
+ " was not found");
// TODO: add test case to make sure notification is canceled.
- NotificationManager.from(mContext).cancel(TAG, id);
+ NotificationManager.from(mContext).cancel(id);
return;
}
setTakingScreenshot(true);
@@ -731,7 +750,7 @@
if (info.finished) {
Log.d(TAG, "Screenshot finished after bugreport; updating share notification");
info.renameScreenshots(mScreenshotsDir);
- sendBugreportNotification(mContext, info, mTakingScreenshot);
+ sendBugreportNotification(info, mTakingScreenshot);
}
msg = mContext.getString(R.string.bugreport_screenshot_taken);
} else {
@@ -753,6 +772,33 @@
}
/**
+ * Stop running on foreground once there is no more active bugreports being watched.
+ */
+ private void stopForegroundWhenDone(int id) {
+ if (id != mForegroundId) {
+ Log.d(TAG, "stopForegroundWhenDone(" + id + "): ignoring since foreground id is "
+ + mForegroundId);
+ return;
+ }
+
+ Log.d(TAG, "detaching foreground from id " + mForegroundId);
+ stopForeground(Service.STOP_FOREGROUND_DETACH);
+ mForegroundId = -1;
+
+ // Might need to restart foreground using a new notification id.
+ final int total = mProcesses.size();
+ if (total > 0) {
+ for (int i = 0; i < total; i++) {
+ final BugreportInfo info = mProcesses.valueAt(i);
+ if (!info.finished) {
+ updateProgress(info);
+ break;
+ }
+ }
+ }
+ }
+
+ /**
* Finishes the service when it's not monitoring any more processes.
*/
private void stopSelfWhenDone() {
@@ -797,6 +843,9 @@
}
info.finished = true;
+ // Stop running on foreground, otherwise share notification cannot be dismissed.
+ stopForegroundWhenDone(id);
+
final Configuration conf = mContext.getResources().getConfiguration();
if ((conf.uiMode & Configuration.UI_MODE_TYPE_MASK) != Configuration.UI_MODE_TYPE_WATCH) {
triggerLocalNotification(mContext, info);
@@ -820,10 +869,10 @@
boolean isPlainText = info.bugreportFile.getName().toLowerCase().endsWith(".txt");
if (!isPlainText) {
// Already zipped, send it right away.
- sendBugreportNotification(context, info, mTakingScreenshot);
+ sendBugreportNotification(info, mTakingScreenshot);
} else {
// Asynchronously zip the file first, then send it.
- sendZippedBugreportNotification(context, info, mTakingScreenshot);
+ sendZippedBugreportNotification(info, mTakingScreenshot);
}
}
@@ -905,7 +954,7 @@
Log.v(TAG, "shareBugReport(): id " + id + " info = " + info);
}
- addDetailsToZipFile(mContext, info);
+ addDetailsToZipFile(info);
final Intent sendIntent = buildSendIntent(mContext, info);
if (sendIntent == null) {
@@ -934,36 +983,35 @@
/**
* Sends a notification indicating the bugreport has finished so use can share it.
*/
- private static void sendBugreportNotification(Context context, BugreportInfo info,
- boolean takingScreenshot) {
+ private void sendBugreportNotification(BugreportInfo info, boolean takingScreenshot) {
// Since adding the details can take a while, do it before notifying user.
- addDetailsToZipFile(context, info);
+ addDetailsToZipFile(info);
final Intent shareIntent = new Intent(INTENT_BUGREPORT_SHARE);
- shareIntent.setClass(context, BugreportProgressService.class);
+ shareIntent.setClass(mContext, BugreportProgressService.class);
shareIntent.setAction(INTENT_BUGREPORT_SHARE);
shareIntent.putExtra(EXTRA_ID, info.id);
shareIntent.putExtra(EXTRA_INFO, info);
- final String title = context.getString(R.string.bugreport_finished_title, info.id);
+ final String title = mContext.getString(R.string.bugreport_finished_title, info.id);
final String content = takingScreenshot ?
- context.getString(R.string.bugreport_finished_pending_screenshot_text)
- : context.getString(R.string.bugreport_finished_text);
- final Notification.Builder builder = newBaseNotification(context)
+ mContext.getString(R.string.bugreport_finished_pending_screenshot_text)
+ : mContext.getString(R.string.bugreport_finished_text);
+ final Notification.Builder builder = newBaseNotification(mContext)
.setContentTitle(title)
.setTicker(title)
.setContentText(content)
- .setContentIntent(PendingIntent.getService(context, info.id, shareIntent,
+ .setContentIntent(PendingIntent.getService(mContext, info.id, shareIntent,
PendingIntent.FLAG_UPDATE_CURRENT))
- .setDeleteIntent(newCancelIntent(context, info));
+ .setDeleteIntent(newCancelIntent(mContext, info));
if (!TextUtils.isEmpty(info.name)) {
builder.setSubText(info.name);
}
Log.v(TAG, "Sending 'Share' notification for ID " + info.id + ": " + title);
- NotificationManager.from(context).notify(TAG, info.id, builder.build());
+ NotificationManager.from(mContext).notify(info.id, builder.build());
}
/**
@@ -971,14 +1019,14 @@
* finishes - at this point there is nothing to be done other than waiting, hence it has no
* pending action.
*/
- private static void sendBugreportBeingUpdatedNotification(Context context, int id) {
+ private void sendBugreportBeingUpdatedNotification(Context context, int id) {
final String title = context.getString(R.string.bugreport_updating_title);
final Notification.Builder builder = newBaseNotification(context)
.setContentTitle(title)
.setTicker(title)
.setContentText(context.getString(R.string.bugreport_updating_wait));
Log.v(TAG, "Sending 'Updating zip' notification for ID " + id + ": " + title);
- NotificationManager.from(context).notify(TAG, id, builder.build());
+ sendForegroundabledNotification(id, builder.build());
}
private static Notification.Builder newBaseNotification(Context context) {
@@ -999,13 +1047,13 @@
/**
* Sends a zipped bugreport notification.
*/
- private static void sendZippedBugreportNotification(final Context context,
- final BugreportInfo info, final boolean takingScreenshot) {
+ private void sendZippedBugreportNotification( final BugreportInfo info,
+ final boolean takingScreenshot) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
zipBugreport(info);
- sendBugreportNotification(context, info, takingScreenshot);
+ sendBugreportNotification(info, takingScreenshot);
return null;
}
}.execute();
@@ -1043,7 +1091,7 @@
* If user provided a title, it will be saved into a {@code title.txt} entry; similarly, the
* description will be saved on {@code description.txt}.
*/
- private static void addDetailsToZipFile(Context context, BugreportInfo info) {
+ private void addDetailsToZipFile(BugreportInfo info) {
if (info.bugreportFile == null) {
// One possible reason is a bug in the Parcelization code.
Log.wtf(TAG, "addDetailsToZipFile(): no bugreportFile on " + info);
@@ -1061,7 +1109,8 @@
// It's not possible to add a new entry into an existing file, so we need to create a new
// zip, copy all entries, then rename it.
- sendBugreportBeingUpdatedNotification(context, info.id); // ...and that takes time
+ sendBugreportBeingUpdatedNotification(mContext, info.id); // ...and that takes time
+
final File dir = info.bugreportFile.getParentFile();
final File tmpZip = new File(dir, "tmp-" + info.bugreportFile.getName());
Log.d(TAG, "Writing temporary zip file (" + tmpZip + ") with title and/or description");
@@ -1090,6 +1139,7 @@
// Make sure it only tries to add details once, even it fails the first time.
info.addedDetailsToZip = true;
info.addingDetailsToZip = false;
+ stopForegroundWhenDone(info.id);
}
if (!tmpZip.renameTo(info.bugreportFile)) {
diff --git a/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java b/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java
index f76fb26..07c1546 100644
--- a/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java
+++ b/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java
@@ -241,14 +241,6 @@
}
public void testProgress_takeExtraScreenshot() throws Exception {
- takeExtraScreenshotTest(false);
- }
-
- public void testProgress_takeExtraScreenshotServiceDiesAfterScreenshotTaken() throws Exception {
- takeExtraScreenshotTest(true);
- }
-
- private void takeExtraScreenshotTest(boolean serviceDies) throws Exception {
resetProperties();
sendBugreportStarted(1000);
@@ -259,11 +251,6 @@
sendBugreportFinished(ID, mPlainTextPath, mScreenshotPath);
- if (serviceDies) {
- waitShareNotification(ID);
- killService();
- }
-
Bundle extras = acceptBugreportAndGetSharedIntent(ID);
assertActionSendMultiple(extras, BUGREPORT_CONTENT, SCREENSHOT_CONTENT, ID, PID, ZIP_FILE,
NAME, NO_TITLE, NO_DESCRIPTION, 1, RENAMED_SCREENSHOTS);
@@ -272,14 +259,6 @@
}
public void testScreenshotFinishesAfterBugreport() throws Exception {
- screenshotFinishesAfterBugreportTest(false);
- }
-
- public void testScreenshotFinishesAfterBugreportAndServiceDiesBeforeSharing() throws Exception {
- screenshotFinishesAfterBugreportTest(true);
- }
-
- private void screenshotFinishesAfterBugreportTest(boolean serviceDies) throws Exception {
resetProperties();
sendBugreportStarted(1000);
@@ -291,10 +270,6 @@
// There's no indication in the UI about the screenshot finish, so just sleep like a baby...
Thread.sleep(SAFE_SCREENSHOT_DELAY * DateUtils.SECOND_IN_MILLIS);
- if (serviceDies) {
- killService();
- }
-
Bundle extras = acceptBugreportAndGetSharedIntent(ID);
assertActionSendMultiple(extras, BUGREPORT_CONTENT, NO_SCREENSHOT, ID, PID, ZIP_FILE,
NAME, NO_TITLE, NO_DESCRIPTION, 1, RENAMED_SCREENSHOTS);
@@ -562,7 +537,7 @@
public void testShareBugreportAfterServiceDies() throws Exception {
sendBugreportFinished(NO_ID, mPlainTextPath, NO_SCREENSHOT);
- killService();
+ waitForService(false);
Bundle extras = acceptBugreportAndGetSharedIntent(NO_ID);
assertActionSendMultiple(extras, BUGREPORT_CONTENT, NO_SCREENSHOT);
}
@@ -841,15 +816,6 @@
assertFalse("Service '" + service + "' is still running", isServiceRunning(service));
}
- private void killService() {
- waitForService(true);
- Log.v(TAG, "Stopping service");
- boolean stopped = mContext.stopService(new Intent(mContext, BugreportProgressService.class));
- Log.d(TAG, "stopService returned " + stopped);
- waitForService(false);
- assertServiceNotRunning(); // Sanity check.
- }
-
private boolean isServiceRunning(String name) {
ActivityManager manager = (ActivityManager) mContext
.getSystemService(Context.ACTIVITY_SERVICE);
@@ -878,12 +844,6 @@
Thread.currentThread().interrupt();
}
}
- if (!expectRunning) {
- // Typically happens when service is waiting for a screenshot to finish.
- Log.w(TAG, "Service didn't stop; try to kill it again");
- killService();
- return;
- }
fail("Service status didn't change to " + expectRunning);
}
diff --git a/packages/SystemUI/res/layout/notification_guts.xml b/packages/SystemUI/res/layout/notification_guts.xml
index e1424f0..f60a3b6 100644
--- a/packages/SystemUI/res/layout/notification_guts.xml
+++ b/packages/SystemUI/res/layout/notification_guts.xml
@@ -63,6 +63,7 @@
android:id="@+id/importance_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:layout_marginStart="-6dp"
android:paddingTop="4dp"
android:paddingEnd="8dp" >
<RadioButton
diff --git a/packages/SystemUI/res/layout/remote_input.xml b/packages/SystemUI/res/layout/remote_input.xml
index 7460201..2db97a6 100644
--- a/packages/SystemUI/res/layout/remote_input.xml
+++ b/packages/SystemUI/res/layout/remote_input.xml
@@ -22,8 +22,7 @@
android:theme="@style/systemui_theme_remote_input"
android:id="@+id/remote_input"
android:layout_height="match_parent"
- android:layout_width="match_parent"
- android:paddingEnd="12dp">
+ android:layout_width="match_parent">
<view class="com.android.systemui.statusbar.policy.RemoteInputView$RemoteEditText"
android:id="@+id/remote_input_text"
@@ -48,19 +47,17 @@
<FrameLayout
android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:paddingTop="2dp"
- android:paddingBottom="4dp">
+ android:layout_height="match_parent"
+ android:layout_gravity="center_vertical">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingStart="12dp"
- android:paddingEnd="12dp"
- android:paddingTop="12dp"
- android:paddingBottom="12dp"
+ android:paddingEnd="24dp"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp"
android:id="@+id/remote_input_send"
android:src="@drawable/ic_send"
android:contentDescription="@*android:string/ime_action_send"
@@ -72,6 +69,7 @@
android:id="@+id/remote_input_progress"
android:layout_width="24dp"
android:layout_height="24dp"
+ android:layout_marginEnd="6dp"
android:layout_gravity="center"
android:visibility="invisible"
android:indeterminate="true"
diff --git a/packages/SystemUI/res/layout/volume_dialog.xml b/packages/SystemUI/res/layout/volume_dialog.xml
index baec8ef..d3f2a25 100644
--- a/packages/SystemUI/res/layout/volume_dialog.xml
+++ b/packages/SystemUI/res/layout/volume_dialog.xml
@@ -29,15 +29,10 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="8dp"
- android:paddingStart="8dp">
+ android:paddingStart="8dp"
+ android:animateLayoutChanges="true" >
<!-- volume rows added and removed here! :-) -->
- <LinearLayout
- android:id="@+id/volume_row_container"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginEnd="@dimen/volume_button_size"
- android:orientation="vertical"/>
<include layout="@layout/volume_zen_footer" />
diff --git a/packages/SystemUI/res/layout/volume_dialog_row.xml b/packages/SystemUI/res/layout/volume_dialog_row.xml
index 57bac41..f0ae1c9 100644
--- a/packages/SystemUI/res/layout/volume_dialog_row.xml
+++ b/packages/SystemUI/res/layout/volume_dialog_row.xml
@@ -18,7 +18,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
- android:id="@+id/volume_dialog_row" >
+ android:id="@+id/volume_dialog_row"
+ android:paddingEnd="@dimen/volume_button_size" >
<TextView
android:id="@+id/volume_row_header"
diff --git a/packages/SystemUI/res/values/styles.xml b/packages/SystemUI/res/values/styles.xml
index aeb484f..5e8162e 100644
--- a/packages/SystemUI/res/values/styles.xml
+++ b/packages/SystemUI/res/values/styles.xml
@@ -350,7 +350,7 @@
</style>
<style name="TextAppearance.NotificationGuts.Radio">
- <item name="android:alpha">.87</item>
+ <item name="android:alpha">.54</item>
</style>
<style name="TextAppearance.NotificationGuts.Button">
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java
index 557f166..ecd1772 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java
@@ -105,7 +105,6 @@
return false;
}
});
- mEditText.setOnClickListener(this);
mEditText.addTextChangedListener(this);
mEditText.setInnerFocusable(false);
mEditText.mRemoteInputView = this;
@@ -148,15 +147,19 @@
@Override
public void onClick(View v) {
- if (v == mEditText) {
- if (!mEditText.isFocusable()) {
- focus();
- }
- } else if (v == mSendButton) {
+ if (v == mSendButton) {
sendRemoteInput();
}
}
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ super.onTouchEvent(event);
+
+ // We never want for a touch to escape to an outer view or one we covered.
+ return true;
+ }
+
public void onDefocus() {
mController.removeRemoteInput(mEntry);
mEntry.remoteInputText = mEditText.getText();
diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialog.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialog.java
index 91a8493..de70139 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialog.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialog.java
@@ -100,7 +100,6 @@
private CustomDialog mDialog;
private ViewGroup mDialogView;
private ViewGroup mDialogContentView;
- private ViewGroup mVolumeRowContainer;
private ImageButton mExpandButton;
private final List<VolumeRow> mRows = new ArrayList<>();
private final SpTexts mSpTexts;
@@ -207,8 +206,6 @@
}
});
mDialogContentView = (ViewGroup) mDialog.findViewById(R.id.volume_dialog_content);
- mVolumeRowContainer =
- (ViewGroup) mDialogContentView.findViewById(R.id.volume_row_container);
mExpanded = false;
mExpandButton = (ImageButton) mDialogView.findViewById(R.id.volume_expand_button);
mExpandButton.setOnClickListener(mClickExpand);
@@ -309,7 +306,7 @@
if (!mRows.isEmpty()) {
addSpacer(row);
}
- mVolumeRowContainer.addView(row.view);
+ mDialogContentView.addView(row.view, mDialogContentView.getChildCount() - 2);
mRows.add(row);
}
@@ -321,7 +318,7 @@
if (i > 0) {
addSpacer(row);
}
- mVolumeRowContainer.addView(row.view);
+ mDialogContentView.addView(row.view, mDialogContentView.getChildCount() - 2);
}
}
@@ -332,7 +329,7 @@
.getDimensionPixelSize(R.dimen.volume_slider_interspacing);
final LinearLayout.LayoutParams lp =
new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, h);
- mVolumeRowContainer.addView(v, lp);
+ mDialogContentView.addView(v, mDialogContentView.getChildCount() - 2, lp);
row.space = v;
}
@@ -613,8 +610,8 @@
if (row.ss == null || !row.ss.dynamic) continue;
if (!mDynamic.get(row.stream)) {
mRows.remove(i);
- mVolumeRowContainer.removeView(row.view);
- mVolumeRowContainer.removeView(row.space);
+ mDialogContentView.removeView(row.view);
+ mDialogContentView.removeView(row.space);
}
}
}
diff --git a/packages/WallpaperBackup/Android.mk b/packages/WallpaperBackup/Android.mk
new file mode 100644
index 0000000..cf04249
--- /dev/null
+++ b/packages/WallpaperBackup/Android.mk
@@ -0,0 +1,34 @@
+#
+# Copyright (C) 2016 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.
+#
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PROGUARD_FLAG_FILES := proguard.flags
+
+LOCAL_PACKAGE_NAME := WallpaperBackup
+LOCAL_CERTIFICATE := platform
+LOCAL_PRIVILEGED_MODULE := false
+
+include $(BUILD_PACKAGE)
+
+########################
+include $(call all-makefiles-under,$(LOCAL_PATH))
+
diff --git a/packages/WallpaperBackup/AndroidManifest.xml b/packages/WallpaperBackup/AndroidManifest.xml
new file mode 100644
index 0000000..b8cea20
--- /dev/null
+++ b/packages/WallpaperBackup/AndroidManifest.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+ * Copyright (c) 2016 Google Inc.
+ *
+ * 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.
+ */
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.wallpaperbackup"
+ android:sharedUserId="android.uid.system" >
+
+ <application android:allowClearUserData="false"
+ android:process="system"
+ android:killAfterRestore="false"
+ android:allowBackup="true"
+ android:backupAgent=".WallpaperBackupAgent"
+ android:fullBackupOnly="true" >
+ </application>
+</manifest>
diff --git a/packages/WallpaperBackup/proguard.flags b/packages/WallpaperBackup/proguard.flags
new file mode 100644
index 0000000..247e6ef
--- /dev/null
+++ b/packages/WallpaperBackup/proguard.flags
@@ -0,0 +1 @@
+-keep class com.android.wallpaperbackup.WallpaperBackupAgent
diff --git a/packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java b/packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java
new file mode 100644
index 0000000..2f79079
--- /dev/null
+++ b/packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2016 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.wallpaperbackup;
+
+import android.app.WallpaperManager;
+import android.app.backup.BackupAgent;
+import android.app.backup.BackupDataInput;
+import android.app.backup.BackupDataOutput;
+import android.app.backup.FullBackupDataOutput;
+import android.content.Context;
+import android.os.Environment;
+import android.os.ParcelFileDescriptor;
+import android.os.UserHandle;
+import android.system.Os;
+import android.util.Slog;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public class WallpaperBackupAgent extends BackupAgent {
+ private static final String TAG = "WallpaperBackup";
+ private static final boolean DEBUG = false;
+
+ // NB: must be kept in sync with WallpaperManagerService but has no
+ // compile-time visiblity.
+
+ // Target filenames within the system's wallpaper directory
+ static final String WALLPAPER = "wallpaper_orig";
+ static final String WALLPAPER_INFO = "wallpaper_info.xml";
+
+ // Names of our local-data stage files/links
+ static final String IMAGE_STAGE = "wallpaper-stage";
+ static final String INFO_STAGE = "wallpaper-info-stage";
+ static final String EMPTY_SENTINEL = "empty";
+
+ private File mWallpaperInfo; // wallpaper metadata file
+ private File mWallpaperFile; // primary wallpaper image file
+
+ private WallpaperManager mWm;
+
+ @Override
+ public void onCreate() {
+ if (DEBUG) {
+ Slog.v(TAG, "onCreate()");
+ }
+
+ File wallpaperDir = Environment.getUserSystemDirectory(UserHandle.USER_SYSTEM);
+ mWallpaperInfo = new File(wallpaperDir, WALLPAPER_INFO);
+ mWallpaperFile = new File(wallpaperDir, WALLPAPER);
+ mWm = (WallpaperManager) getSystemService(Context.WALLPAPER_SERVICE);
+ }
+
+ @Override
+ public void onFullBackup(FullBackupDataOutput data) throws IOException {
+ // To avoid data duplication and disk churn, use links as the stage.
+ final File filesDir = getFilesDir();
+ final File infoStage = new File(filesDir, INFO_STAGE);
+ final File imageStage = new File (filesDir, IMAGE_STAGE);
+ final File empty = new File (filesDir, EMPTY_SENTINEL);
+
+ try {
+ // We always back up this 'empty' file to ensure that the absence of
+ // storable wallpaper imagery still produces a non-empty backup data
+ // stream, otherwise it'd simply be ignored in preflight.
+ FileOutputStream touch = new FileOutputStream(empty);
+ touch.close();
+ fullBackupFile(empty, data);
+
+ // only back up the wallpaper if we've been told it's allowed
+ if (mWm.isWallpaperBackupEligible()) {
+ if (DEBUG) {
+ Slog.v(TAG, "Wallpaper is backup-eligible; linking & writing");
+ }
+ Os.link(mWallpaperInfo.getCanonicalPath(), infoStage.getCanonicalPath());
+ fullBackupFile(infoStage, data);
+ Os.link(mWallpaperFile.getCanonicalPath(), imageStage.getCanonicalPath());
+ fullBackupFile(imageStage, data);
+ } else {
+ if (DEBUG) {
+ Slog.v(TAG, "Wallpaper not backup-eligible; writing no data");
+ }
+ }
+ } catch (Exception e) {
+ Slog.e(TAG, "Unable to back up wallpaper: " + e.getMessage());
+ } finally {
+ if (DEBUG) {
+ Slog.v(TAG, "Removing backup stage links");
+ }
+ infoStage.delete();
+ imageStage.delete();
+ }
+ }
+
+ // We use the default onRestoreFile() implementation that will recreate our stage files,
+ // then postprocess in onRestoreFinished() to move them on top of the live data.
+ //
+ // NOTE: this relies on our local files dir being on the same filesystem as the live
+ // system wallpaper data. If this is not the case then an actual copy operation will
+ // be needed.
+ @Override
+ public void onRestoreFinished() {
+ if (DEBUG) {
+ Slog.v(TAG, "onRestoreFinished()");
+ }
+ final File infoStage = new File(getFilesDir(), INFO_STAGE);
+ final File imageStage = new File (getFilesDir(), IMAGE_STAGE);
+
+ try {
+ // It is valid for the imagery to be absent; it means that we were not permitted
+ // to back up the original image on the source device.
+ if (imageStage.exists()) {
+ if (DEBUG) {
+ Slog.v(TAG, "Got restored wallpaper; renaming into place");
+ }
+ // Rename the image file into place last because that is the trigger for
+ // the wallpaper observer to generate a new crop/scale
+ Os.rename(infoStage.getCanonicalPath(), mWallpaperInfo.getCanonicalPath());
+ Os.rename(imageStage.getCanonicalPath(), mWallpaperFile.getCanonicalPath());
+ }
+ } catch (Exception e) {
+ Slog.e(TAG, "Unable to restore wallpaper: " + e.getMessage());
+ mWm.clearWallpaper(WallpaperManager.FLAG_SYSTEM, UserHandle.USER_SYSTEM);
+ } finally {
+ // These "should" not exist because of the renames, but make sure
+ // in case of errors/exceptions/etc.
+ if (DEBUG) {
+ Slog.v(TAG, "Removing restore stage files");
+ }
+ infoStage.delete();
+ imageStage.delete();
+ }
+ }
+
+ //
+ // Key/value API: abstract, so required, but not used
+ //
+
+ @Override
+ public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
+ ParcelFileDescriptor newState) throws IOException {
+ // Intentionally blank
+ }
+
+ @Override
+ public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
+ throws IOException {
+ // Intentionally blank
+ }
+}
\ No newline at end of file
diff --git a/services/core/java/com/android/server/am/TaskPersister.java b/services/core/java/com/android/server/am/TaskPersister.java
index a2472ac..48fecd5 100644
--- a/services/core/java/com/android/server/am/TaskPersister.java
+++ b/services/core/java/com/android/server/am/TaskPersister.java
@@ -17,8 +17,6 @@
package com.android.server.am;
import android.annotation.NonNull;
-import android.annotation.Nullable;
-import android.app.ActivityManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Debug;
@@ -519,7 +517,7 @@
if (DEBUG) Slog.d(TAG, "removeObsoleteFiles: persistentTaskIds=" + persistentTaskIds +
" files=" + files);
if (files == null) {
- Slog.e(TAG, "File error accessing recents directory (too many files open?).");
+ Slog.e(TAG, "File error accessing recents directory (directory doesn't exist?).");
return;
}
for (int fileNdx = 0; fileNdx < files.length; ++fileNdx) {
@@ -597,15 +595,12 @@
}
static File getUserImagesDir(int userId) {
- File userImagesDir = new File(Environment.getDataSystemCeDirectory(userId), IMAGES_DIRNAME);
+ return new File(Environment.getDataSystemCeDirectory(userId), IMAGES_DIRNAME);
+ }
- if (!userImagesDir.exists()) {
- if (!userImagesDir.mkdir()) {
- Slog.e(TAG, "Failure creating images directory for user " + userId + ": "
- + userImagesDir);
- }
- }
- return userImagesDir;
+ private static boolean createParentDirectory(String filePath) {
+ File parentDir = new File(filePath).getParentFile();
+ return parentDir.exists() || parentDir.mkdirs();
}
private class LazyTaskWriterThread extends Thread {
@@ -693,6 +688,10 @@
if (item instanceof ImageWriteQueueItem) {
ImageWriteQueueItem imageWriteQueueItem = (ImageWriteQueueItem) item;
final String filePath = imageWriteQueueItem.mFilePath;
+ if (!createParentDirectory(filePath)) {
+ Slog.e(TAG, "Error while creating images directory for file: " + filePath);
+ continue;
+ }
final Bitmap bitmap = imageWriteQueueItem.mImage;
if (DEBUG) Slog.d(TAG, "writing bitmap: filename=" + filePath);
FileOutputStream imageFile = null;
diff --git a/services/core/java/com/android/server/fingerprint/ClientMonitor.java b/services/core/java/com/android/server/fingerprint/ClientMonitor.java
index 45b6d3e..8163b79 100644
--- a/services/core/java/com/android/server/fingerprint/ClientMonitor.java
+++ b/services/core/java/com/android/server/fingerprint/ClientMonitor.java
@@ -38,7 +38,7 @@
protected static final boolean DEBUG = FingerprintService.DEBUG;
private IBinder mToken;
private IFingerprintServiceReceiver mReceiver;
- private int mCallingUserId;
+ private int mTargetUserId;
private int mGroupId;
private boolean mIsRestricted; // True if client does not have MANAGE_FINGERPRINT permission
private String mOwner;
@@ -50,20 +50,20 @@
* @param halDeviceId the HAL device ID of the associated fingerprint hardware
* @param token a unique token for the client
* @param receiver recipient of related events (e.g. authentication)
- * @param callingUserId user id of calling user
+ * @param userId target user id for operation
* @param groupId groupId for the fingerprint set
* @param restricted whether or not client has the {@link Manifest#MANAGE_FINGERPRINT}
* permission
* @param owner name of the client that owns this
*/
public ClientMonitor(Context context, long halDeviceId, IBinder token,
- IFingerprintServiceReceiver receiver, int callingUserId, int groupId,boolean restricted,
+ IFingerprintServiceReceiver receiver, int userId, int groupId,boolean restricted,
String owner) {
mContext = context;
mHalDeviceId = halDeviceId;
mToken = token;
mReceiver = receiver;
- mCallingUserId = callingUserId;
+ mTargetUserId = userId;
mGroupId = groupId;
mIsRestricted = restricted;
mOwner = owner;
@@ -197,8 +197,8 @@
return mIsRestricted;
}
- public final int getCallingUserId() {
- return mCallingUserId;
+ public final int getTargetUserId() {
+ return mTargetUserId;
}
public final int getGroupId() {
diff --git a/services/core/java/com/android/server/fingerprint/EnumerateClient.java b/services/core/java/com/android/server/fingerprint/EnumerateClient.java
index e826fee..52dbd5d 100644
--- a/services/core/java/com/android/server/fingerprint/EnumerateClient.java
+++ b/services/core/java/com/android/server/fingerprint/EnumerateClient.java
@@ -41,7 +41,7 @@
try {
final int result = daemon.enumerate();
if (result != 0) {
- Slog.w(TAG, "start enumerate for user " + getCallingUserId()
+ Slog.w(TAG, "start enumerate for user " + getTargetUserId()
+ " failed, result=" + result);
onError(FingerprintManager.FINGERPRINT_ERROR_HW_UNAVAILABLE);
return result;
diff --git a/services/core/java/com/android/server/fingerprint/FingerprintService.java b/services/core/java/com/android/server/fingerprint/FingerprintService.java
index fcf7bf5..9a2db8e 100644
--- a/services/core/java/com/android/server/fingerprint/FingerprintService.java
+++ b/services/core/java/com/android/server/fingerprint/FingerprintService.java
@@ -356,7 +356,7 @@
}
}
- void startRemove(IBinder token, int fingerId, int callingUserId, int groupId,
+ void startRemove(IBinder token, int fingerId, int groupId, int userId,
IFingerprintServiceReceiver receiver, boolean restricted) {
IFingerprintDaemon daemon = getFingerprintDaemon();
if (daemon == null) {
@@ -364,7 +364,7 @@
return;
}
RemovalClient client = new RemovalClient(getContext(), mHalDeviceId, token,
- receiver, callingUserId, groupId, fingerId, restricted, token.toString()) {
+ receiver, fingerId, groupId, userId, restricted, token.toString()) {
@Override
public void notifyUserActivity() {
FingerprintService.this.userActivity();
@@ -794,14 +794,13 @@
@Override // Binder call
public void remove(final IBinder token, final int fingerId, final int groupId,
- final IFingerprintServiceReceiver receiver) {
+ final int userId, final IFingerprintServiceReceiver receiver) {
checkPermission(MANAGE_FINGERPRINT); // TODO: Maybe have another permission
final boolean restricted = isRestricted();
- final int callingUserId = UserHandle.getCallingUserId();
mHandler.post(new Runnable() {
@Override
public void run() {
- startRemove(token, fingerId, callingUserId, groupId, receiver, restricted);
+ startRemove(token, fingerId, groupId, userId, receiver, restricted);
}
});
diff --git a/services/core/java/com/android/server/fingerprint/RemovalClient.java b/services/core/java/com/android/server/fingerprint/RemovalClient.java
index ffa3c3f..bcf2264 100644
--- a/services/core/java/com/android/server/fingerprint/RemovalClient.java
+++ b/services/core/java/com/android/server/fingerprint/RemovalClient.java
@@ -30,14 +30,12 @@
*/
public abstract class RemovalClient extends ClientMonitor {
private int mFingerId;
- private int mUserIdForRemove;
public RemovalClient(Context context, long halDeviceId, IBinder token,
- IFingerprintServiceReceiver receiver, int userId, int groupId, int fingerId,
+ IFingerprintServiceReceiver receiver, int fingerId, int groupId, int userId,
boolean restricted, String owner) {
super(context, halDeviceId, token, receiver, userId, groupId, restricted, owner);
mFingerId = fingerId;
- mUserIdForRemove = userId;
}
@Override
@@ -72,25 +70,21 @@
*/
private boolean sendRemoved(int fingerId, int groupId) {
IFingerprintServiceReceiver receiver = getReceiver();
- if (receiver == null)
- return true; // client not listening
try {
- receiver.onRemoved(getHalDeviceId(), fingerId, groupId);
- return fingerId == 0;
+ if (receiver != null) {
+ receiver.onRemoved(getHalDeviceId(), fingerId, groupId);
+ }
} catch (RemoteException e) {
Slog.w(TAG, "Failed to notify Removed:", e);
}
- return false;
+ return fingerId == 0;
}
@Override
public boolean onRemoved(int fingerId, int groupId) {
if (fingerId != 0) {
- if (fingerId != mFingerId)
FingerprintUtils.getInstance().removeFingerprintIdForUser(getContext(), fingerId,
- mUserIdForRemove);
- } else {
- mUserIdForRemove = UserHandle.USER_NULL;
+ getTargetUserId());
}
return sendRemoved(fingerId, getGroupId());
}
diff --git a/services/core/java/com/android/server/lights/LightsService.java b/services/core/java/com/android/server/lights/LightsService.java
index 5953dde..07048a4 100644
--- a/services/core/java/com/android/server/lights/LightsService.java
+++ b/services/core/java/com/android/server/lights/LightsService.java
@@ -17,16 +17,16 @@
package com.android.server.lights;
import com.android.server.SystemService;
-import com.android.server.vr.VrManagerInternal;
import com.android.server.vr.VrManagerService;
-import com.android.server.vr.VrStateListener;
+import android.app.ActivityManager;
import android.content.Context;
import android.os.Handler;
-import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
import android.os.Trace;
+import android.os.UserHandle;
+import android.provider.Settings;
import android.service.vr.IVrManager;
import android.service.vr.IVrStateCallbacks;
import android.util.Slog;
@@ -36,6 +36,7 @@
static final boolean DEBUG = false;
final LightImpl mLights[] = new LightImpl[LightsManager.LIGHT_ID_COUNT];
+ private boolean mVrModeEnabled;
private final class LightImpl extends Light {
@@ -179,17 +180,34 @@
}
}
+ private int getVrDisplayMode() {
+ int currentUser = ActivityManager.getCurrentUser();
+ return Settings.Secure.getIntForUser(getContext().getContentResolver(),
+ Settings.Secure.VR_DISPLAY_MODE,
+ /*default*/Settings.Secure.VR_DISPLAY_MODE_LOW_PERSISTENCE,
+ currentUser);
+ }
+
private final IVrStateCallbacks mVrStateCallbacks = new IVrStateCallbacks.Stub() {
@Override
public void onVrStateChanged(boolean enabled) throws RemoteException {
LightImpl l = mLights[LightsManager.LIGHT_ID_BACKLIGHT];
- if (enabled) {
- if (DEBUG) Slog.v(TAG, "VR mode enabled, setting brightness to low persistence");
- l.enableLowPersistence();
+ int vrDisplayMode = getVrDisplayMode();
+ // User leaves VR mode before altering display settings.
+ if (enabled && vrDisplayMode == Settings.Secure.VR_DISPLAY_MODE_LOW_PERSISTENCE) {
+ if (!mVrModeEnabled) {
+ if (DEBUG)
+ Slog.v(TAG, "VR mode enabled, setting brightness to low persistence");
+ l.enableLowPersistence();
+ mVrModeEnabled = true;
+ }
} else {
- if (DEBUG) Slog.v(TAG, "VR mode disabled, resetting brightnes");
- l.disableLowPersistence();
+ if (mVrModeEnabled) {
+ if (DEBUG) Slog.v(TAG, "VR mode disabled, resetting brightnes");
+ l.disableLowPersistence();
+ mVrModeEnabled = false;
+ }
}
}
};
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java
index 8cd536d..12a2d2e 100644
--- a/services/core/java/com/android/server/power/PowerManagerService.java
+++ b/services/core/java/com/android/server/power/PowerManagerService.java
@@ -143,7 +143,6 @@
private static final int WAKE_LOCK_STAY_AWAKE = 1 << 5; // only set if already awake
private static final int WAKE_LOCK_DOZE = 1 << 6;
private static final int WAKE_LOCK_DRAW = 1 << 7;
- private static final int WAKE_LOCK_SUSTAINED_PERFORMANCE = 1 << 8;
// Summarizes the user activity state.
private static final int USER_ACTIVITY_SCREEN_BRIGHT = 1 << 0;
@@ -162,7 +161,6 @@
// Power hints defined in hardware/libhardware/include/hardware/power.h.
private static final int POWER_HINT_LOW_POWER = 5;
- private static final int POWER_HINT_SUSTAINED_PERFORMANCE = 6;
private static final int POWER_HINT_VR_MODE = 7;
// Power features defined in hardware/libhardware/include/hardware/power.h.
@@ -470,9 +468,6 @@
// True if we are currently in light device idle mode.
private boolean mLightDeviceIdleMode;
- // True if we are currently in sustained performance mode.
- private boolean mSustainedPerformanceMode;
-
// Set of app ids that we will always respect the wake locks for.
int[] mDeviceIdleWhitelist = new int[0];
@@ -481,8 +476,6 @@
private final SparseIntArray mUidState = new SparseIntArray();
- private final SparseIntArray mSustainedPerformanceUid = new SparseIntArray();
-
// True if theater mode is enabled
private boolean mTheaterModeEnabled;
@@ -879,12 +872,6 @@
throw new IllegalArgumentException("Wake lock is already dead.");
}
mWakeLocks.add(wakeLock);
-
- if ((flags & PowerManager.WAKE_LOCK_LEVEL_MASK)
- == PowerManager.SUSTAINED_PERFORMANCE_WAKE_LOCK) {
- int numberWakelock = mSustainedPerformanceUid.get(uid);
- mSustainedPerformanceUid.put(uid, numberWakelock + 1);
- }
setWakeLockDisabledStateLocked(wakeLock);
notifyAcquire = true;
}
@@ -953,17 +940,6 @@
mRequestWaitForNegativeProximity = true;
}
-
- if ((wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK)
- == PowerManager.SUSTAINED_PERFORMANCE_WAKE_LOCK) {
- int numberWakelock = mSustainedPerformanceUid.get(wakeLock.mOwnerUid);
- if (numberWakelock == 1) {
- mSustainedPerformanceUid.delete(wakeLock.mOwnerUid);
- } else {
- mSustainedPerformanceUid.put(wakeLock.mOwnerUid, numberWakelock - 1);
- }
- }
-
wakeLock.mLock.unlinkToDeath(wakeLock, 0);
removeWakeLockLocked(wakeLock, index);
}
@@ -1586,10 +1562,6 @@
break;
case PowerManager.DRAW_WAKE_LOCK:
mWakeLockSummary |= WAKE_LOCK_DRAW;
- case PowerManager.SUSTAINED_PERFORMANCE_WAKE_LOCK:
- if (!wakeLock.mDisabled) {
- mWakeLockSummary |= WAKE_LOCK_SUSTAINED_PERFORMANCE;
- }
break;
}
}
@@ -2288,14 +2260,6 @@
if (autoSuspend && mDecoupleHalAutoSuspendModeFromDisplayConfig) {
setHalAutoSuspendModeLocked(true);
}
-
- if (mSustainedPerformanceMode
- && (mWakeLockSummary & WAKE_LOCK_SUSTAINED_PERFORMANCE) == 0) {
- setSustainedPerformanceModeLocked(false);
- } else if (!mSustainedPerformanceMode
- && (mWakeLockSummary & WAKE_LOCK_SUSTAINED_PERFORMANCE) != 0) {
- setSustainedPerformanceModeLocked(true);
- }
}
/**
@@ -2394,12 +2358,6 @@
}
}
- private void setSustainedPerformanceModeLocked(boolean mode) {
- mSustainedPerformanceMode = mode;
- powerHintInternal(POWER_HINT_SUSTAINED_PERFORMANCE,
- mSustainedPerformanceMode ? 1 : 0);
- }
-
boolean isDeviceIdleModeInternal() {
synchronized (mLock) {
return mDeviceIdleMode;
@@ -2531,7 +2489,7 @@
void updateUidProcStateInternal(int uid, int procState) {
synchronized (mLock) {
mUidState.put(uid, procState);
- if (mDeviceIdleMode || mSustainedPerformanceUid.get(uid) != 0) {
+ if (mDeviceIdleMode) {
updateWakeLockDisabledStatesLocked();
}
}
@@ -2552,9 +2510,7 @@
for (int i = 0; i < numWakeLocks; i++) {
final WakeLock wakeLock = mWakeLocks.get(i);
if ((wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK)
- == PowerManager.PARTIAL_WAKE_LOCK
- || (wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK)
- == PowerManager.SUSTAINED_PERFORMANCE_WAKE_LOCK) {
+ == PowerManager.PARTIAL_WAKE_LOCK) {
if (setWakeLockDisabledStateLocked(wakeLock)) {
changed = true;
if (wakeLock.mDisabled) {
@@ -2573,9 +2529,9 @@
}
private boolean setWakeLockDisabledStateLocked(WakeLock wakeLock) {
- boolean disabled = false;
if ((wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK)
== PowerManager.PARTIAL_WAKE_LOCK) {
+ boolean disabled = false;
if (mDeviceIdleMode) {
final int appid = UserHandle.getAppId(wakeLock.mOwnerUid);
// If we are in idle mode, we will ignore all partial wake locks that are
@@ -2589,16 +2545,10 @@
disabled = true;
}
}
- } else if ((wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK)
- == PowerManager.SUSTAINED_PERFORMANCE_WAKE_LOCK
- && mUidState.get(wakeLock.mOwnerUid,
- ActivityManager.PROCESS_STATE_CACHED_EMPTY)
- > ActivityManager.PROCESS_STATE_TOP) {
- disabled = true;
- }
- if (wakeLock.mDisabled != disabled) {
- wakeLock.mDisabled = disabled;
- return true;
+ if (wakeLock.mDisabled != disabled) {
+ wakeLock.mDisabled = disabled;
+ return true;
+ }
}
return false;
}
@@ -2806,7 +2756,6 @@
pw.println(" mBatteryLevelLow=" + mBatteryLevelLow);
pw.println(" mLightDeviceIdleMode=" + mLightDeviceIdleMode);
pw.println(" mDeviceIdleMode=" + mDeviceIdleMode);
- pw.println(" mSustainedPerformanceMode=" + mSustainedPerformanceMode);
pw.println(" mDeviceIdleWhitelist=" + Arrays.toString(mDeviceIdleWhitelist));
pw.println(" mDeviceIdleTempWhitelist=" + Arrays.toString(mDeviceIdleTempWhitelist));
pw.println(" mLastWakeTime=" + TimeUtils.formatUptime(mLastWakeTime));
@@ -2921,14 +2870,6 @@
pw.println();
pw.println("Display Power: " + mDisplayPowerCallbacks);
- pw.println();
- pw.println("Sustained Performance UIDs:");
- for (int i=0; i<mSustainedPerformanceUid.size(); i++) {
- pw.print(" UID "); UserHandle.formatUid(pw, mSustainedPerformanceUid.keyAt(i));
- pw.print(": "); pw.println(mSustainedPerformanceUid.valueAt(i));
- }
-
-
wcd = mWirelessChargerDetector;
}
diff --git a/services/core/java/com/android/server/tv/TvInputManagerService.java b/services/core/java/com/android/server/tv/TvInputManagerService.java
index 30442bc..e13ee13 100644
--- a/services/core/java/com/android/server/tv/TvInputManagerService.java
+++ b/services/core/java/com/android/server/tv/TvInputManagerService.java
@@ -161,8 +161,10 @@
PackageMonitor monitor = new PackageMonitor() {
private void buildTvInputList(String[] packages) {
synchronized (mLock) {
- buildTvInputListLocked(getChangingUserId(), packages);
- buildTvContentRatingSystemListLocked(getChangingUserId());
+ if (mCurrentUserId == getChangingUserId()) {
+ buildTvInputListLocked(mCurrentUserId, packages);
+ buildTvContentRatingSystemListLocked(mCurrentUserId);
+ }
}
}
diff --git a/services/core/java/com/android/server/vr/EnabledComponentsObserver.java b/services/core/java/com/android/server/vr/EnabledComponentsObserver.java
index 30194bf..249a076 100644
--- a/services/core/java/com/android/server/vr/EnabledComponentsObserver.java
+++ b/services/core/java/com/android/server/vr/EnabledComponentsObserver.java
@@ -212,7 +212,7 @@
if (userManager == null) {
return null;
}
- return userManager.getProfileIdsWithDisabled(ActivityManager.getCurrentUser());
+ return userManager.getEnabledProfileIds(ActivityManager.getCurrentUser());
}
public static ArraySet<ComponentName> loadComponentNames(PackageManager pm, int userId,
diff --git a/services/core/java/com/android/server/vr/SettingsObserver.java b/services/core/java/com/android/server/vr/SettingsObserver.java
index ce76863..3d1227d 100644
--- a/services/core/java/com/android/server/vr/SettingsObserver.java
+++ b/services/core/java/com/android/server/vr/SettingsObserver.java
@@ -38,7 +38,7 @@
public class SettingsObserver {
private final String mSecureSettingName;
- private final BroadcastReceiver mSettingRestorReceiver;
+ private final BroadcastReceiver mSettingRestoreReceiver;
private final ContentObserver mContentObserver;
private final Set<SettingChangeListener> mSettingsListeners = new ArraySet<>();
@@ -67,7 +67,7 @@
@NonNull final Uri settingUri, @NonNull final String secureSettingName) {
mSecureSettingName = secureSettingName;
- mSettingRestorReceiver = new BroadcastReceiver() {
+ mSettingRestoreReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_SETTING_RESTORED.equals(intent.getAction())) {
@@ -117,7 +117,6 @@
*/
public void addListener(@NonNull SettingChangeListener listener) {
mSettingsListeners.add(listener);
-
}
/**
diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
index 91b6914..d6ace91 100644
--- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
+++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
@@ -34,7 +34,6 @@
import android.app.WallpaperInfo;
import android.app.WallpaperManager;
import android.app.admin.DevicePolicyManager;
-import android.app.backup.BackupManager;
import android.app.backup.WallpaperBackupHelper;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -61,6 +60,7 @@
import android.os.FileUtils;
import android.os.IBinder;
import android.os.IRemoteCallback;
+import android.os.Process;
import android.os.ParcelFileDescriptor;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
@@ -205,7 +205,8 @@
if (path == null) {
return;
}
- final boolean written = (event == CLOSE_WRITE || event == MOVED_TO);
+ final boolean moved = (event == MOVED_TO);
+ final boolean written = (event == CLOSE_WRITE || moved);
final File changedFile = new File(mWallpaperDir, path);
// System and system+lock changes happen on the system wallpaper input file;
@@ -224,13 +225,6 @@
+ " written=" + written);
}
synchronized (mLock) {
- if (sysWallpaperChanged || mWallpaperInfoFile.equals(changedFile)) {
- // changing the wallpaper means we'll need to back up the new one
- long origId = Binder.clearCallingIdentity();
- BackupManager bm = new BackupManager(mContext);
- bm.dataChanged();
- Binder.restoreCallingIdentity(origId);
- }
if (sysWallpaperChanged || lockWallpaperChanged) {
notifyCallbacksLocked(wallpaper);
if (wallpaper.wallpaperComponent == null
@@ -244,6 +238,14 @@
if (DEBUG) {
Slog.v(TAG, "Wallpaper written; generating crop");
}
+ if (moved) {
+ // This is a restore, so generate the crop using any just-restored new
+ // crop guidelines, making sure to preserve our local dimension hints.
+ if (DEBUG) {
+ Slog.v(TAG, "moved-to, therefore restore; reloading metadata");
+ }
+ loadSettingsLocked(wallpaper.userId, true);
+ }
generateCrop(wallpaper);
if (DEBUG) {
Slog.v(TAG, "Crop done; invoking completion callback");
@@ -491,6 +493,11 @@
IWallpaperManagerCallback setComplete;
/**
+ * Is the OS allowed to back up this wallpaper imagery?
+ */
+ boolean allowBackup;
+
+ /**
* Resource name if using a picture from the wallpaper gallery
*/
String name = "";
@@ -811,7 +818,7 @@
mMonitor = new MyPackageMonitor();
mMonitor.register(context, null, UserHandle.ALL, true);
getWallpaperDir(UserHandle.USER_SYSTEM).mkdirs();
- loadSettingsLocked(UserHandle.USER_SYSTEM);
+ loadSettingsLocked(UserHandle.USER_SYSTEM, false);
}
private static File getWallpaperDir(int userId) {
@@ -1024,7 +1031,7 @@
wallpaper = mWallpaperMap.get(userId);
if (wallpaper == null) {
// Might need to bring it in the first time to establish our rewrite
- loadSettingsLocked(userId);
+ loadSettingsLocked(userId, false);
wallpaper = mWallpaperMap.get(userId);
}
}
@@ -1102,7 +1109,7 @@
WallpaperData wd = mWallpaperMap.get(user.id);
if (wd == null) {
// User hasn't started yet, so load her settings to peek at the wallpaper
- loadSettingsLocked(user.id);
+ loadSettingsLocked(user.id, false);
wd = mWallpaperMap.get(user.id);
}
if (wd != null && name.equals(wd.name)) {
@@ -1235,7 +1242,7 @@
if (wallpaper == null) {
// common case, this is the first lookup post-boot of the system or
// unified lock, so we bring up the saved state lazily now and recheck.
- loadSettingsLocked(wallpaperUserId);
+ loadSettingsLocked(wallpaperUserId, false);
wallpaper = whichSet.get(wallpaperUserId);
if (wallpaper == null) {
return null;
@@ -1304,7 +1311,8 @@
@Override
public ParcelFileDescriptor setWallpaper(String name, String callingPackage,
- Rect cropHint, Bundle extras, int which, IWallpaperManagerCallback completion) {
+ Rect cropHint, boolean allowBackup, Bundle extras, int which,
+ IWallpaperManagerCallback completion) {
checkPermission(android.Manifest.permission.SET_WALLPAPER);
if ((which & (FLAG_LOCK|FLAG_SYSTEM)) == 0) {
@@ -1342,6 +1350,9 @@
wallpaper.whichPending = which;
wallpaper.setComplete = completion;
wallpaper.cropHint.set(cropHint);
+ if ((which & FLAG_SYSTEM) != 0) {
+ wallpaper.allowBackup = allowBackup;
+ }
}
return pfd;
} finally {
@@ -1651,6 +1662,16 @@
return !um.hasUserRestriction(UserManager.DISALLOW_SET_WALLPAPER);
}
+ @Override
+ public boolean isWallpaperBackupEligible(int userId) {
+ if (Binder.getCallingUid() != Process.SYSTEM_UID) {
+ throw new SecurityException("Only the system may call isWallpaperBackupEligible");
+ }
+
+ WallpaperData wallpaper = getWallpaperSafeLocked(userId, FLAG_SYSTEM);
+ return (wallpaper != null) ? wallpaper.allowBackup : false;
+ }
+
private static JournaledFile makeJournaledFile(int userId) {
final String base = new File(getWallpaperDir(userId), WALLPAPER_INFO).getAbsolutePath();
return new JournaledFile(new File(base), new File(base + ".tmp"));
@@ -1721,6 +1742,11 @@
out.attribute(null, "component",
wallpaper.wallpaperComponent.flattenToShortString());
}
+
+ if (wallpaper.allowBackup) {
+ out.attribute(null, "backup", "true");
+ }
+
out.endTag(null, tag);
}
@@ -1764,7 +1790,7 @@
if (wallpaper == null) {
// common case, this is the first lookup post-boot of the system or
// unified lock, so we bring up the saved state lazily now and recheck.
- loadSettingsLocked(userId);
+ loadSettingsLocked(userId, false);
wallpaper = whichSet.get(userId);
// if it's still null here, this is a lock-only operation and there is not
// yet a lock-only wallpaper set for this user, so we need to establish
@@ -1788,7 +1814,7 @@
return wallpaper;
}
- private void loadSettingsLocked(int userId) {
+ private void loadSettingsLocked(int userId, boolean keepDimensionHints) {
if (DEBUG) Slog.v(TAG, "loadSettingsLocked");
JournaledFile journal = makeJournaledFile(userId);
@@ -1801,6 +1827,7 @@
WallpaperData wallpaper = mWallpaperMap.get(userId);
if (wallpaper == null) {
wallpaper = new WallpaperData(userId, WALLPAPER, WALLPAPER_CROP);
+ wallpaper.allowBackup = true;
mWallpaperMap.put(userId, wallpaper);
if (!wallpaper.cropExists()) {
generateCrop(wallpaper);
@@ -1819,7 +1846,7 @@
String tag = parser.getName();
if ("wp".equals(tag)) {
// Common to system + lock wallpapers
- parseWallpaperAttributes(parser, wallpaper);
+ parseWallpaperAttributes(parser, wallpaper, keepDimensionHints);
// A system wallpaper might also be a live wallpaper
String comp = parser.getAttributeValue(null, "component");
@@ -1848,7 +1875,7 @@
WALLPAPER_LOCK_ORIG, WALLPAPER_LOCK_CROP);
mLockWallpaperMap.put(userId, lockWallpaper);
}
- parseWallpaperAttributes(parser, lockWallpaper);
+ parseWallpaperAttributes(parser, lockWallpaper, false);
}
}
} while (type != XmlPullParser.END_DOCUMENT);
@@ -1909,7 +1936,8 @@
}
}
- private void parseWallpaperAttributes(XmlPullParser parser, WallpaperData wallpaper) {
+ private void parseWallpaperAttributes(XmlPullParser parser, WallpaperData wallpaper,
+ boolean keepDimensionHints) {
final String idString = parser.getAttributeValue(null, "id");
if (idString != null) {
final int id = wallpaper.wallpaperId = Integer.parseInt(idString);
@@ -1920,9 +1948,11 @@
wallpaper.wallpaperId = makeWallpaperIdLocked();
}
- wallpaper.width = Integer.parseInt(parser.getAttributeValue(null, "width"));
- wallpaper.height = Integer.parseInt(parser
- .getAttributeValue(null, "height"));
+ if (!keepDimensionHints) {
+ wallpaper.width = Integer.parseInt(parser.getAttributeValue(null, "width"));
+ wallpaper.height = Integer.parseInt(parser
+ .getAttributeValue(null, "height"));
+ }
wallpaper.cropHint.left = getAttributeInt(parser, "cropLeft", 0);
wallpaper.cropHint.top = getAttributeInt(parser, "cropTop", 0);
wallpaper.cropHint.right = getAttributeInt(parser, "cropRight", 0);
@@ -1932,6 +1962,7 @@
wallpaper.padding.right = getAttributeInt(parser, "paddingRight", 0);
wallpaper.padding.bottom = getAttributeInt(parser, "paddingBottom", 0);
wallpaper.name = parser.getAttributeValue(null, "name");
+ wallpaper.allowBackup = "true".equals(parser.getAttributeValue(null, "backup"));
}
private int getMaximumSizeDimension() {
@@ -1952,9 +1983,10 @@
WallpaperData wallpaper = null;
boolean success = false;
synchronized (mLock) {
- loadSettingsLocked(UserHandle.USER_SYSTEM);
+ loadSettingsLocked(UserHandle.USER_SYSTEM, false);
wallpaper = mWallpaperMap.get(UserHandle.USER_SYSTEM);
wallpaper.wallpaperId = makeWallpaperIdLocked(); // always bump id at restore
+ wallpaper.allowBackup = true; // by definition if it was restored
if (wallpaper.nextWallpaperComponent != null
&& !wallpaper.nextWallpaperComponent.equals(mImageWallpaper)) {
if (!bindWallpaperComponentLocked(wallpaper.nextWallpaperComponent, false, false,
diff --git a/services/core/java/com/android/server/wm/DockedStackDividerController.java b/services/core/java/com/android/server/wm/DockedStackDividerController.java
index b90d0d1..8a003de 100644
--- a/services/core/java/com/android/server/wm/DockedStackDividerController.java
+++ b/services/core/java/com/android/server/wm/DockedStackDividerController.java
@@ -116,6 +116,11 @@
private boolean mAnimatingForIme;
private boolean mAdjustedForIme;
private WindowState mDelayedImeWin;
+ private boolean mAdjustedForDivider;
+ private float mDividerAnimationStart;
+ private float mDividerAnimationTarget;
+ private float mLastAnimationProgress;
+ private float mLastDividerProgress;
DockedStackDividerController(WindowManagerService service, DisplayContent displayContent) {
mService = service;
@@ -208,16 +213,18 @@
return mLastVisibility;
}
- void setAdjustedForIme(boolean adjusted, boolean animate, WindowState imeWin) {
- if (mAdjustedForIme != adjusted) {
- mAdjustedForIme = adjusted;
+ void setAdjustedForIme(
+ boolean adjustedForIme, boolean adjustedForDivider,
+ boolean animate, WindowState imeWin) {
+ if (mAdjustedForIme != adjustedForIme || mAdjustedForDivider != adjustedForDivider) {
if (animate) {
- startImeAdjustAnimation(adjusted, imeWin);
+ startImeAdjustAnimation(adjustedForIme, adjustedForDivider, imeWin);
} else {
-
// Animation might be delayed, so only notify if we don't run an animation.
- notifyAdjustedForImeChanged(adjusted, 0 /* duration */);
+ notifyAdjustedForImeChanged(adjustedForIme || adjustedForDivider, 0 /* duration */);
}
+ mAdjustedForIme = adjustedForIme;
+ mAdjustedForDivider = adjustedForDivider;
}
}
@@ -457,11 +464,25 @@
mAnimationTarget = to;
}
- private void startImeAdjustAnimation(boolean adjusted, WindowState imeWin) {
+ private void startImeAdjustAnimation(
+ boolean adjustedForIme, boolean adjustedForDivider, WindowState imeWin) {
mAnimatingForIme = true;
mAnimationStarted = false;
- mAnimationStart = adjusted ? 0 : 1;
- mAnimationTarget = adjusted ? 1 : 0;
+
+ // If we're not in an animation, the starting point depends on whether we're adjusted
+ // or not. If we're already in an animation, we start from where the current animation
+ // left off, so that the motion doesn't look discontinuous.
+ if (!mAnimatingForIme) {
+ mAnimationStart = mAdjustedForIme ? 1 : 0;
+ mDividerAnimationStart = mAdjustedForDivider ? 1 : 0;
+ mLastAnimationProgress = mAnimationStart;
+ mLastDividerProgress = mDividerAnimationStart;
+ } else {
+ mAnimationStart = mLastAnimationProgress;
+ mDividerAnimationStart = mLastDividerProgress;
+ }
+ mAnimationTarget = adjustedForIme ? 1 : 0;
+ mDividerAnimationTarget = adjustedForDivider ? 1 : 0;
final ArrayList<TaskStack> stacks = mDisplayContent.getStacks();
for (int i = stacks.size() - 1; i >= 0; --i) {
@@ -492,10 +513,12 @@
if (mDelayedImeWin != null) {
mDelayedImeWin.mWinAnimator.endDelayingAnimationStart();
}
- notifyAdjustedForImeChanged(adjusted, IME_ADJUST_ANIM_DURATION);
+ notifyAdjustedForImeChanged(
+ adjustedForIme || adjustedForDivider, IME_ADJUST_ANIM_DURATION);
};
} else {
- notifyAdjustedForImeChanged(adjusted, IME_ADJUST_ANIM_DURATION);
+ notifyAdjustedForImeChanged(
+ adjustedForIme || adjustedForDivider, IME_ADJUST_ANIM_DURATION);
}
}
@@ -539,11 +562,15 @@
for (int i = stacks.size() - 1; i >= 0; --i) {
final TaskStack stack = stacks.get(i);
if (stack != null && stack.isAdjustedForIme()) {
- if (t >= 1f && mAnimationTarget == 0f) {
+ if (t >= 1f && mAnimationTarget == 0f && mDividerAnimationTarget == 0f) {
stack.resetAdjustedForIme(true /* adjustBoundsNow */);
updated = true;
} else {
- updated |= stack.updateAdjustForIme(getInterpolatedAnimationValue(t),
+ mLastAnimationProgress = getInterpolatedAnimationValue(t);
+ mLastDividerProgress = getInterpolatedDividerValue(t);
+ updated |= stack.updateAdjustForIme(
+ mLastAnimationProgress,
+ mLastDividerProgress,
false /* force */);
}
if (t >= 1f) {
@@ -555,6 +582,8 @@
mService.mWindowPlacerLocked.performSurfacePlacement();
}
if (t >= 1.0f) {
+ mLastAnimationProgress = mAnimationTarget;
+ mLastDividerProgress = mDividerAnimationTarget;
mAnimatingForIme = false;
return false;
} else {
@@ -596,6 +625,10 @@
return t * mAnimationTarget + (1 - t) * mAnimationStart;
}
+ private float getInterpolatedDividerValue(float t) {
+ return t * mDividerAnimationTarget + (1 - t) * mDividerAnimationStart;
+ }
+
/**
* Gets the amount how much to minimize a stack depending on the interpolated fraction t.
*/
diff --git a/services/core/java/com/android/server/wm/TaskStack.java b/services/core/java/com/android/server/wm/TaskStack.java
index 1fd2b1f..a289855 100644
--- a/services/core/java/com/android/server/wm/TaskStack.java
+++ b/services/core/java/com/android/server/wm/TaskStack.java
@@ -126,6 +126,7 @@
private WindowState mImeWin;
private float mMinimizeAmount;
private float mAdjustImeAmount;
+ private float mAdjustDividerAmount;
private final int mDockedStackMinimizeThickness;
// If this is true, we are in the bounds animating mode.
@@ -853,7 +854,8 @@
if (!mAdjustedForIme) {
mAdjustedForIme = true;
mAdjustImeAmount = 0f;
- updateAdjustForIme(0f, true /* force */);
+ mAdjustDividerAmount = 0f;
+ updateAdjustForIme(0f, 0f, true /* force */);
}
}
@@ -873,9 +875,11 @@
*
* @return true if a traversal should be performed after the adjustment.
*/
- boolean updateAdjustForIme(float adjustAmount, boolean force) {
- if (adjustAmount != mAdjustImeAmount || force) {
+ boolean updateAdjustForIme(float adjustAmount, float adjustDividerAmount, boolean force) {
+ if (adjustAmount != mAdjustImeAmount
+ || adjustDividerAmount != mAdjustDividerAmount || force) {
mAdjustImeAmount = adjustAmount;
+ mAdjustDividerAmount = adjustDividerAmount;
updateAdjustedBounds();
return isVisibleForUserLocked();
} else {
@@ -895,6 +899,7 @@
mAdjustedForIme = false;
mImeGoingAway = false;
mAdjustImeAmount = 0f;
+ mAdjustDividerAmount = 0f;
updateAdjustedBounds();
mService.setResizeDimLayer(false, mStackId, 1.0f);
} else {
@@ -992,25 +997,27 @@
(int) (mAdjustImeAmount * bottom + (1 - mAdjustImeAmount) * mBounds.bottom);
mFullyAdjustedImeBounds.set(mBounds);
} else {
- final int top;
- final boolean isFocusedStack = mService.getFocusedStackLocked() == this;
- if (isFocusedStack) {
- // If this stack is docked on bottom and has focus, we shift it up so that it's not
- // occluded by IME. We try to move it up by the height of the IME window, but only
- // to the extent that leaves at least 30% of the top stack visible.
- final int minTopStackBottom =
- getMinTopStackBottom(displayContentRect, mBounds.top - dividerWidth);
- top = Math.max(
- mBounds.top - yOffset, minTopStackBottom + dividerWidthInactive);
- } else {
- // If this stack is docked on bottom but doesn't have focus, we don't need to adjust
- // for IME, but still need to apply a small adjustment due to the thinner divider.
- top = mBounds.top - dividerWidth + dividerWidthInactive;
- }
+ // When the stack is on bottom and has no focus, it's only adjusted for divider width.
+ final int dividerWidthDelta = dividerWidthInactive - dividerWidth;
+
+ // When the stack is on bottom and has focus, it needs to be moved up so as to
+ // not occluded by IME, and at the same time adjusted for divider width.
+ // We try to move it up by the height of the IME window, but only to the extent
+ // that leaves at least 30% of the top stack visible.
+ // 'top' is where the top of bottom stack will move to in this case.
+ final int topBeforeImeAdjust = mBounds.top - dividerWidth + dividerWidthInactive;
+ final int minTopStackBottom =
+ getMinTopStackBottom(displayContentRect, mBounds.top - dividerWidth);
+ final int top = Math.max(
+ mBounds.top - yOffset, minTopStackBottom + dividerWidthInactive);
mTmpAdjustedBounds.set(mBounds);
- mTmpAdjustedBounds.top =
- (int) (mAdjustImeAmount * top + (1 - mAdjustImeAmount) * mBounds.top);
+ // Account for the adjustment for IME and divider width separately.
+ // (top - topBeforeImeAdjust) is the amount of movement due to IME only,
+ // and dividerWidthDelta is due to divider width change only.
+ mTmpAdjustedBounds.top = mBounds.top +
+ (int) (mAdjustImeAmount * (top - topBeforeImeAdjust) +
+ mAdjustDividerAmount * dividerWidthDelta);
mFullyAdjustedImeBounds.set(mBounds);
mFullyAdjustedImeBounds.top = top;
mFullyAdjustedImeBounds.bottom = top + mBounds.height();
@@ -1082,9 +1089,10 @@
}
setAdjustedBounds(mTmpAdjustedBounds);
- final boolean isFocusedStack = mService.getFocusedStackLocked() == this;
- if (mAdjustedForIme && adjust && !isFocusedStack) {
- final float alpha = mAdjustImeAmount * IME_ADJUST_DIM_AMOUNT;
+ final boolean isImeTarget = (mService.getImeTargetStackLocked() == this);
+ if (mAdjustedForIme && adjust && !isImeTarget) {
+ final float alpha = Math.max(mAdjustImeAmount, mAdjustDividerAmount)
+ * IME_ADJUST_DIM_AMOUNT;
mService.setResizeDimLayer(true, mStackId, alpha);
}
}
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index 38f12a1..9994af3 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -7455,27 +7455,38 @@
void adjustForImeIfNeeded(final DisplayContent displayContent) {
final WindowState imeWin = mInputMethodWindow;
- final TaskStack focusedStack = getFocusedStackLocked();
+ final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw();
final boolean dockVisible = isStackVisibleLocked(DOCKED_STACK_ID);
- if (imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
- && dockVisible && focusedStack != null) {
- final boolean isFocusOnBottom = focusedStack.getDockSide() == DOCKED_BOTTOM;
+ final TaskStack imeTargetStack = getImeTargetStackLocked();
+
+ // The divider could be adjusted for IME position, or be thinner than usual,
+ // or both. There are three possible cases:
+ // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
+ // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
+ // - If IME is not visible, divider is not moved and is normal width.
+
+ if (imeVisible && dockVisible && imeTargetStack != null) {
+ final boolean isFocusOnBottom = imeTargetStack.getDockSide() == DOCKED_BOTTOM;
final ArrayList<TaskStack> stacks = displayContent.getStacks();
for (int i = stacks.size() - 1; i >= 0; --i) {
final TaskStack stack = stacks.get(i);
final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
if (stack.isVisibleLocked() && (isFocusOnBottom || isDockedOnBottom)) {
stack.setAdjustedForIme(imeWin);
+ } else {
+ stack.resetAdjustedForIme(false);
}
}
- displayContent.mDividerControllerLocked.setAdjustedForIme(true, true, imeWin);
+ displayContent.mDividerControllerLocked.setAdjustedForIme(
+ isFocusOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin);
} else {
final ArrayList<TaskStack> stacks = displayContent.getStacks();
for (int i = stacks.size() - 1; i >= 0; --i) {
final TaskStack stack = stacks.get(i);
stack.resetAdjustedForIme(!dockVisible);
}
- displayContent.mDividerControllerLocked.setAdjustedForIme(false, dockVisible, imeWin);
+ displayContent.mDividerControllerLocked.setAdjustedForIme(
+ false /*ime*/, false /*divider*/, dockVisible /*animate*/, null);
}
}
@@ -7608,8 +7619,10 @@
return mCurrentFocus;
}
- TaskStack getFocusedStackLocked() {
- return mCurrentFocus != null ? mCurrentFocus.getStack() : null;
+ TaskStack getImeTargetStackLocked() {
+ // Don't use WindowState.getStack() because it returns home stack for system windows.
+ Task imeTask = mInputMethodTarget != null ? mInputMethodTarget.getTask() : null;
+ return imeTask != null ? imeTask.mStack : null;
}
private void showAuditSafeModeNotification() {
@@ -9354,7 +9367,6 @@
WindowState newFocus = computeFocusedWindowLocked();
if (mCurrentFocus != newFocus) {
Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "wmUpdateFocus");
- TaskStack oldFocusedStack = getFocusedStackLocked();
// This check makes sure that we don't already have the focus
// change message pending.
mH.removeMessages(H.REPORT_FOCUS_CHANGE);
@@ -9376,7 +9388,6 @@
mLosingFocus.remove(newFocus);
int focusChanged = mPolicy.focusChangedLw(oldFocus, newFocus);
- TaskStack newFocusedStack = getFocusedStackLocked();
if (imWindowChanged && oldFocus != mInputMethodWindow) {
// Focus of the input method window changed. Perform layout if needed.
@@ -9406,18 +9417,6 @@
mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows);
}
- // TODO: Reset and re-apply IME adjustment if needed when stack focus changed.
- // This makes sure divider starts an animation from pre-adjust position to final
- // position. Ideally we want to skip the reset and animation from current position
- // directly to final position.
- final WindowState imeWin = mInputMethodWindow;
- if (oldFocusedStack != null) {
- oldFocusedStack.resetAdjustedForIme(true);
- }
- if (newFocusedStack != null) {
- newFocusedStack.resetAdjustedForIme(true);
- }
- displayContent.mDividerControllerLocked.setAdjustedForIme(false, false, imeWin);
adjustForImeIfNeeded(displayContent);
Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
diff --git a/services/core/java/com/android/server/wm/WindowSurfacePlacer.java b/services/core/java/com/android/server/wm/WindowSurfacePlacer.java
index 1e6c585..928fcc0 100644
--- a/services/core/java/com/android/server/wm/WindowSurfacePlacer.java
+++ b/services/core/java/com/android/server/wm/WindowSurfacePlacer.java
@@ -8,6 +8,7 @@
import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
+import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE;
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
@@ -128,6 +129,9 @@
private boolean mTraversalScheduled;
private int mDeferDepth = 0;
+ private boolean mSustainedPerformanceModeEnabled = false;
+ private boolean mSustainedPerformanceModeCurrent = false;
+
private static final class LayerAndToken {
public int layer;
public AppWindowToken token;
@@ -288,7 +292,7 @@
mButtonBrightness = -1;
mUserActivityTimeout = -1;
mObscureApplicationContentOnSecondaryDisplays = false;
-
+ mSustainedPerformanceModeCurrent = false;
mService.mTransactionSequence++;
final DisplayContent defaultDisplay = mService.getDefaultDisplayContentLocked();
@@ -487,6 +491,13 @@
mUserActivityTimeout);
}
+ if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) {
+ mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent;
+ mService.mPowerManagerInternal.powerHint(
+ mService.mPowerManagerInternal.POWER_HINT_SUSTAINED_PERFORMANCE_MODE,
+ (mSustainedPerformanceModeEnabled ? 1 : 0));
+ }
+
if (mService.mTurnOnScreen) {
if (mService.mAllowTheaterModeWakeFromLayout
|| Settings.Global.getInt(mService.mContext.getContentResolver(),
@@ -1409,6 +1420,7 @@
final LayoutParams attrs = w.mAttrs;
final int attrFlags = attrs.flags;
final boolean canBeSeen = w.isDisplayedLw();
+ final int privateflags = attrs.privateFlags;
if (canBeSeen && w.isObscuringFullscreen(dispInfo)) {
// This window completely covers everything behind it,
@@ -1469,6 +1481,9 @@
&& w.mAttrs.preferredDisplayModeId != 0) {
mPreferredModeId = w.mAttrs.preferredDisplayModeId;
}
+ if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) {
+ mSustainedPerformanceModeCurrent = true;
+ }
}
}
}
diff --git a/services/core/jni/com_android_server_location_FlpHardwareProvider.cpp b/services/core/jni/com_android_server_location_FlpHardwareProvider.cpp
index 774577d..8ea9bfc 100644
--- a/services/core/jni/com_android_server_location_FlpHardwareProvider.cpp
+++ b/services/core/jni/com_android_server_location_FlpHardwareProvider.cpp
@@ -661,6 +661,16 @@
TranslateToObject(lastLocation, locationObject);
}
+ // sCallbacksObject is created when FlpHardwareProvider on Java side is
+ // initialized. Sometimes the hardware may call this function before the Java
+ // side is ready. In order to prevent the system crash, check whether
+ // sCallbacksObj has been created. If not, simply ignore this event from
+ // hardware.
+ if (sCallbacksObj == NULL) {
+ ALOGE("FlpHardwareProvider hasn't been initialized.");
+ return;
+ }
+
sCallbackEnv->CallVoidMethod(
sCallbacksObj,
sOnGeofenceMonitorStatus,
diff --git a/services/core/jni/com_android_server_location_GnssLocationProvider.cpp b/services/core/jni/com_android_server_location_GnssLocationProvider.cpp
index 058b631..c5c90e0 100644
--- a/services/core/jni/com_android_server_location_GnssLocationProvider.cpp
+++ b/services/core/jni/com_android_server_location_GnssLocationProvider.cpp
@@ -1194,7 +1194,7 @@
JavaObject object(env, "android/location/GnssMeasurement");
GpsMeasurementFlags flags = measurement->flags;
SET(Svid, static_cast<int32_t>(measurement->prn));
- if (measurement->prn >= 1 || measurement->prn <= 32) {
+ if (measurement->prn >= 1 && measurement->prn <= 32) {
SET(ConstellationType, static_cast<int32_t>(GNSS_CONSTELLATION_GPS));
} else {
ALOGD("Unknown constellation type with Svid = %d.", measurement->prn);
diff --git a/services/tests/servicestests/src/com/android/server/accounts/AccountManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/accounts/AccountManagerServiceTest.java
index 4468857..ef9739d 100644
--- a/services/tests/servicestests/src/com/android/server/accounts/AccountManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/accounts/AccountManagerServiceTest.java
@@ -32,6 +32,7 @@
import android.content.pm.RegisteredServicesCache.ServiceInfo;
import android.content.pm.RegisteredServicesCacheListener;
import android.content.pm.UserInfo;
+import android.database.Cursor;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
@@ -64,15 +65,14 @@
Context realTestContext = getContext();
Context mockContext = new MyMockContext(realTestContext);
setContext(mockContext);
- mAms = new MyAccountManagerService(getContext(),
- new MyMockPackageManager(), new MockAccountAuthenticatorCache(), realTestContext);
+ mAms = createAccountManagerService(mockContext, realTestContext);
}
@Override
protected void tearDown() throws Exception {
- new File(mAms.getCeDatabaseName(UserHandle.USER_SYSTEM)).delete();
- new File(mAms.getDeDatabaseName(UserHandle.USER_SYSTEM)).delete();
- new File(mAms.getPreNDatabaseName(UserHandle.USER_SYSTEM)).delete();
+ SQLiteDatabase.deleteDatabase(new File(mAms.getCeDatabaseName(UserHandle.USER_SYSTEM)));
+ SQLiteDatabase.deleteDatabase(new File(mAms.getDeDatabaseName(UserHandle.USER_SYSTEM)));
+ SQLiteDatabase.deleteDatabase(new File(mAms.getPreNDatabaseName(UserHandle.USER_SYSTEM)));
super.tearDown();
}
@@ -88,7 +88,7 @@
}
public void testCheckAddAccount() throws Exception {
- unlockUser(UserHandle.USER_SYSTEM);
+ unlockSystemUser();
Account a11 = new Account("account1", "type1");
Account a21 = new Account("account2", "type1");
Account a31 = new Account("account3", "type1");
@@ -129,7 +129,7 @@
}
public void testPasswords() throws Exception {
- unlockUser(UserHandle.USER_SYSTEM);
+ unlockSystemUser();
Account a11 = new Account("account1", "type1");
Account a12 = new Account("account1", "type2");
mAms.addAccountExplicitly(a11, "p11", null);
@@ -145,7 +145,7 @@
}
public void testUserdata() throws Exception {
- unlockUser(UserHandle.USER_SYSTEM);
+ unlockSystemUser();
Account a11 = new Account("account1", "type1");
Bundle u11 = new Bundle();
u11.putString("a", "a_a11");
@@ -178,7 +178,7 @@
}
public void testAuthtokens() throws Exception {
- unlockUser(UserHandle.USER_SYSTEM);
+ unlockSystemUser();
Account a11 = new Account("account1", "type1");
Account a12 = new Account("account1", "type2");
mAms.addAccountExplicitly(a11, "p11", null);
@@ -211,10 +211,89 @@
assertNull(mAms.peekAuthToken(a12, "att2"));
}
- private void unlockUser(int userId) {
+ public void testRemovedAccountSync() throws Exception {
+ unlockSystemUser();
+ Account a1 = new Account("account1", "type1");
+ Account a2 = new Account("account2", "type2");
+ mAms.addAccountExplicitly(a1, "p1", null);
+ mAms.addAccountExplicitly(a2, "p2", null);
+
+ Context originalContext = ((MyMockContext)getContext()).mTestContext;
+ // create a separate instance of AMS. It initially assumes that user0 is locked
+ AccountManagerService ams2 = createAccountManagerService(getContext(), originalContext);
+
+ // Verify that account can be removed when user is locked
+ ams2.removeAccountInternal(a1);
+ Account[] accounts = ams2.getAccounts(UserHandle.USER_SYSTEM, mContext.getOpPackageName());
+ assertEquals(1, accounts.length);
+ assertEquals("Only a2 should be returned", a2, accounts[0]);
+
+ // Verify that CE db file is unchanged and still has 2 accounts
+ String ceDatabaseName = mAms.getCeDatabaseName(UserHandle.USER_SYSTEM);
+ int accountsNumber = readNumberOfAccountsFromDbFile(originalContext, ceDatabaseName);
+ assertEquals("CE database should still have 2 accounts", 2, accountsNumber);
+
+ // Unlock the user and verify that db has been updated
+ ams2.onUserUnlocked(newIntentForUser(UserHandle.USER_SYSTEM));
+ accountsNumber = readNumberOfAccountsFromDbFile(originalContext, ceDatabaseName);
+ assertEquals("CE database should now have 1 account", 2, accountsNumber);
+ accounts = ams2.getAccounts(UserHandle.USER_SYSTEM, mContext.getOpPackageName());
+ assertEquals(1, accounts.length);
+ assertEquals("Only a2 should be returned", a2, accounts[0]);
+ }
+
+ public void testPreNDatabaseMigration() throws Exception {
+ String preNDatabaseName = mAms.getPreNDatabaseName(UserHandle.USER_SYSTEM);
+ Context originalContext = ((MyMockContext) getContext()).mTestContext;
+ PreNTestDatabaseHelper.createV4Database(originalContext, preNDatabaseName);
+ // Assert that database was created with 1 account
+ int n = readNumberOfAccountsFromDbFile(originalContext, preNDatabaseName);
+ assertEquals("pre-N database should have 1 account", 1, n);
+
+ // Start testing
+ unlockSystemUser();
+ Account[] accounts = mAms.getAccounts(null, mContext.getOpPackageName());
+ assertEquals("1 account should be migrated", 1, accounts.length);
+ assertEquals(PreNTestDatabaseHelper.ACCOUNT_NAME, accounts[0].name);
+ assertEquals(PreNTestDatabaseHelper.ACCOUNT_PASSWORD, mAms.getPassword(accounts[0]));
+ assertEquals("Authtoken should be migrated",
+ PreNTestDatabaseHelper.TOKEN_STRING,
+ mAms.peekAuthToken(accounts[0], PreNTestDatabaseHelper.TOKEN_TYPE));
+
+ assertFalse("pre-N database file should be removed but was found at " + preNDatabaseName,
+ new File(preNDatabaseName).exists());
+
+ // Verify that ce/de files are present
+ String deDatabaseName = mAms.getDeDatabaseName(UserHandle.USER_SYSTEM);
+ String ceDatabaseName = mAms.getCeDatabaseName(UserHandle.USER_SYSTEM);
+ assertTrue("DE database file should be created at " + deDatabaseName,
+ new File(deDatabaseName).exists());
+ assertTrue("CE database file should be created at " + ceDatabaseName,
+ new File(ceDatabaseName).exists());
+ }
+
+ private int readNumberOfAccountsFromDbFile(Context context, String dbName) {
+ SQLiteDatabase ceDb = context.openOrCreateDatabase(dbName, 0, null);
+ try (Cursor cursor = ceDb.rawQuery("SELECT count(*) FROM accounts", null)) {
+ assertTrue(cursor.moveToNext());
+ return cursor.getInt(0);
+ }
+ }
+
+ private AccountManagerService createAccountManagerService(Context mockContext,
+ Context realContext) {
+ return new MyAccountManagerService(mockContext,
+ new MyMockPackageManager(), new MockAccountAuthenticatorCache(), realContext);
+ }
+
+ private void unlockSystemUser() {
+ mAms.onUserUnlocked(newIntentForUser(UserHandle.USER_SYSTEM));
+ }
+
+ private static Intent newIntentForUser(int userId) {
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
- mAms.onUserUnlocked(intent);
+ return intent;
}
static public class MockAccountAuthenticatorCache implements IAccountAuthenticatorCache {
@@ -264,11 +343,13 @@
private Context mTestContext;
private AppOpsManager mAppOpsManager;
private UserManager mUserManager;
+ private PackageManager mPackageManager;
public MyMockContext(Context testContext) {
this.mTestContext = testContext;
this.mAppOpsManager = mock(AppOpsManager.class);
this.mUserManager = mock(UserManager.class);
+ this.mPackageManager = mock(PackageManager.class);
final UserInfo ui = new UserInfo(UserHandle.USER_SYSTEM, "user0", 0);
when(mUserManager.getUserInfo(eq(ui.id))).thenReturn(ui);
}
@@ -279,6 +360,11 @@
}
@Override
+ public PackageManager getPackageManager() {
+ return mPackageManager;
+ }
+
+ @Override
public Object getSystemService(String name) {
if (Context.APP_OPS_SERVICE.equals(name)) {
return mAppOpsManager;
diff --git a/services/tests/servicestests/src/com/android/server/accounts/PreNTestDatabaseHelper.java b/services/tests/servicestests/src/com/android/server/accounts/PreNTestDatabaseHelper.java
new file mode 100644
index 0000000..97adbe6
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/accounts/PreNTestDatabaseHelper.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2016 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.accounts;
+
+import android.content.Context;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+
+/**
+ * Helper class for emulating pre-N database
+ */
+class PreNTestDatabaseHelper extends SQLiteOpenHelper {
+
+ public static final String TOKEN_STRING = "token-string-123";
+ public static final String ACCOUNT_TYPE = "type1";
+ public static final String ACCOUNT_NAME = "account@" + ACCOUNT_TYPE;
+ public static final String ACCOUNT_PASSWORD = "Password";
+ public static final String TOKEN_TYPE = "SID";
+
+ public PreNTestDatabaseHelper(Context context, String name) {
+ super(context, name, null, 4);
+ }
+
+ @Override
+ public void onCreate(SQLiteDatabase db) {
+ db.execSQL("CREATE TABLE accounts ( "
+ + "_id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ + "name TEXT NOT NULL, "
+ + "type TEXT NOT NULL, "
+ + "password TEXT, "
+ + "UNIQUE(name, type))");
+ db.execSQL("INSERT INTO accounts (name, type, password) VALUES "
+ + "('" + ACCOUNT_NAME + "', '" + ACCOUNT_TYPE + "', '" + ACCOUNT_PASSWORD + "')");
+
+ db.execSQL("CREATE TABLE authtokens ( "
+ + "_id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ + "accounts_id INTEGER NOT NULL, "
+ + "type TEXT NOT NULL, "
+ + "authtoken TEXT, "
+ + "UNIQUE (accounts_id, type ))");
+ db.execSQL("INSERT INTO authtokens (accounts_id, type, authtoken) VALUES "
+ + "(1, '" + TOKEN_TYPE + "', '" + TOKEN_STRING + "')");
+
+ db.execSQL("CREATE TABLE grants ( "
+ + "accounts_id INTEGER NOT NULL, "
+ + "auth_token_type STRING NOT NULL, "
+ + "uid INTEGER NOT NULL, "
+ + "UNIQUE (accounts_id,auth_token_type,uid))");
+
+ db.execSQL("CREATE TABLE extras ( "
+ + "_id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ + "accounts_id INTEGER, "
+ + "key TEXT NOT NULL, "
+ + "value TEXT, "
+ + "UNIQUE(accounts_id , key))");
+
+ db.execSQL("CREATE TABLE meta ( "
+ + "key TEXT PRIMARY KEY NOT NULL, "
+ + "value TEXT)");
+
+ db.execSQL(""
+ + " CREATE TRIGGER accountsDelete DELETE ON accounts "
+ + " BEGIN"
+ + " DELETE FROM authtokens"
+ + " WHERE accounts_id=OLD._id;"
+ + " DELETE FROM extras"
+ + " WHERE accounts_id=OLD._id;"
+ + " DELETE FROM grants"
+ + " WHERE accounts_id=OLD._id;"
+ + " END");
+ }
+
+ @Override
+ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+ throw new UnsupportedOperationException("Upgrade of test database is not supported");
+ }
+
+ public static void createV4Database(Context context, String name) {
+ PreNTestDatabaseHelper helper = new PreNTestDatabaseHelper(context, name);
+ helper.getWritableDatabase();
+ helper.close();
+ }
+
+}