diff options
Diffstat (limited to 'core/java')
17 files changed, 248 insertions, 146 deletions
diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java index a7099d4..e94cdae 100644 --- a/core/java/android/app/ActivityManagerNative.java +++ b/core/java/android/app/ActivityManagerNative.java @@ -17,7 +17,6 @@ package android.app; import android.app.ActivityManager.StackInfo; -import android.app.ProfilerInfo; import android.content.ComponentName; import android.content.IIntentReceiver; import android.content.IIntentSender; @@ -2210,17 +2209,12 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM return true; } - case GET_ACTIVITY_CONTAINER_TRANSACTION: { + case GET_ACTIVITY_DISPLAY_ID_TRANSACTION: { data.enforceInterface(IActivityManager.descriptor); IBinder activityToken = data.readStrongBinder(); - IActivityContainer activityContainer = getEnclosingActivityContainer(activityToken); + int displayId = getActivityDisplayId(activityToken); reply.writeNoException(); - if (activityContainer != null) { - reply.writeInt(1); - reply.writeStrongBinder(activityContainer.asBinder()); - } else { - reply.writeInt(0); - } + reply.writeInt(displayId); return true; } @@ -5250,26 +5244,21 @@ class ActivityManagerProxy implements IActivityManager reply.recycle(); } - public IActivityContainer getEnclosingActivityContainer(IBinder activityToken) - throws RemoteException { + @Override + public int getActivityDisplayId(IBinder activityToken) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); data.writeInterfaceToken(IActivityManager.descriptor); data.writeStrongBinder(activityToken); - mRemote.transact(GET_ACTIVITY_CONTAINER_TRANSACTION, data, reply, 0); + mRemote.transact(GET_ACTIVITY_DISPLAY_ID_TRANSACTION, data, reply, 0); reply.readException(); - final int result = reply.readInt(); - final IActivityContainer res; - if (result == 1) { - res = IActivityContainer.Stub.asInterface(reply.readStrongBinder()); - } else { - res = null; - } + final int displayId = reply.readInt(); data.recycle(); reply.recycle(); - return res; + return displayId; } + @Override public IBinder getHomeActivityToken() throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index bdd9e41..3a78734 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -2361,10 +2361,7 @@ public final class ActivityThread { final DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance(); try { - IActivityContainer container = - ActivityManagerNative.getDefault().getEnclosingActivityContainer(r.token); - final int displayId = - container == null ? Display.DEFAULT_DISPLAY : container.getDisplayId(); + final int displayId = ActivityManagerNative.getDefault().getActivityDisplayId(r.token); if (displayId > Display.DEFAULT_DISPLAY) { Display display = dm.getRealDisplay(displayId, r.token); baseContext = appContext.createDisplayContext(display); diff --git a/core/java/android/app/ActivityView.java b/core/java/android/app/ActivityView.java index 94ea2c5..a7864f4 100644 --- a/core/java/android/app/ActivityView.java +++ b/core/java/android/app/ActivityView.java @@ -16,6 +16,8 @@ package android.app; +import static android.app.ActivityManager.START_CANCELED; + import android.content.Context; import android.content.ContextWrapper; import android.content.IIntentSender; @@ -23,6 +25,7 @@ import android.content.Intent; import android.content.IntentSender; import android.graphics.SurfaceTexture; import android.os.IBinder; +import android.os.OperationCanceledException; import android.os.RemoteException; import android.util.AttributeSet; import android.util.DisplayMetrics; @@ -55,10 +58,6 @@ public class ActivityView extends ViewGroup { private int mLastVisibility; private ActivityViewCallback mActivityViewCallback; - // Only one IIntentSender or Intent may be queued at a time. Most recent one wins. - IIntentSender mQueuedPendingIntent; - Intent mQueuedIntent; - public ActivityView(Context context) { this(context, null); } @@ -167,14 +166,13 @@ public class ActivityView extends ViewGroup { if (mActivityContainer == null) { throw new IllegalStateException("Attempt to call startActivity after release"); } + if (mSurface == null) { + throw new IllegalStateException("Surface not yet created."); + } if (DEBUG) Log.v(TAG, "startActivity(): intent=" + intent + " " + (isAttachedToDisplay() ? "" : "not") + " attached"); - if (mSurface != null) { - mActivityContainer.startActivity(intent); - } else { - mActivityContainer.checkEmbeddedAllowed(intent); - mQueuedIntent = intent; - mQueuedPendingIntent = null; + if (mActivityContainer.startActivity(intent) == START_CANCELED) { + throw new OperationCanceledException(); } } @@ -182,15 +180,14 @@ public class ActivityView extends ViewGroup { if (mActivityContainer == null) { throw new IllegalStateException("Attempt to call startActivity after release"); } + if (mSurface == null) { + throw new IllegalStateException("Surface not yet created."); + } if (DEBUG) Log.v(TAG, "startActivityIntentSender(): intentSender=" + intentSender + " " + (isAttachedToDisplay() ? "" : "not") + " attached"); final IIntentSender iIntentSender = intentSender.getTarget(); - if (mSurface != null) { - mActivityContainer.startActivityIntentSender(iIntentSender); - } else { - mActivityContainer.checkEmbeddedAllowedIntentSender(iIntentSender); - mQueuedPendingIntent = iIntentSender; - mQueuedIntent = null; + if (mActivityContainer.startActivityIntentSender(iIntentSender) == START_CANCELED) { + throw new OperationCanceledException(); } } @@ -198,15 +195,14 @@ public class ActivityView extends ViewGroup { if (mActivityContainer == null) { throw new IllegalStateException("Attempt to call startActivity after release"); } + if (mSurface == null) { + throw new IllegalStateException("Surface not yet created."); + } if (DEBUG) Log.v(TAG, "startActivityPendingIntent(): PendingIntent=" + pendingIntent + " " + (isAttachedToDisplay() ? "" : "not") + " attached"); final IIntentSender iIntentSender = pendingIntent.getTarget(); - if (mSurface != null) { - mActivityContainer.startActivityIntentSender(iIntentSender); - } else { - mActivityContainer.checkEmbeddedAllowedIntentSender(iIntentSender); - mQueuedPendingIntent = iIntentSender; - mQueuedIntent = null; + if (mActivityContainer.startActivityIntentSender(iIntentSender) == START_CANCELED) { + throw new OperationCanceledException(); } } @@ -243,26 +239,24 @@ public class ActivityView extends ViewGroup { mSurface = null; throw new RuntimeException("ActivityView: Unable to create ActivityContainer. " + e); } - - if (DEBUG) Log.v(TAG, "attachToSurfaceWhenReady: " + (mQueuedIntent != null || - mQueuedPendingIntent != null ? "" : "no") + " queued intent"); - if (mQueuedIntent != null) { - mActivityContainer.startActivity(mQueuedIntent); - mQueuedIntent = null; - } else if (mQueuedPendingIntent != null) { - mActivityContainer.startActivityIntentSender(mQueuedPendingIntent); - mQueuedPendingIntent = null; - } } /** * Set the callback to use to report certain state changes. - * @param callback The callback to report events to. + * + * Note: If the surface has been created prior to this call being made, then + * ActivityViewCallback.onSurfaceAvailable will be called from within setCallback. + * + * @param callback The callback to report events to. * * @see ActivityViewCallback */ public void setCallback(ActivityViewCallback callback) { mActivityViewCallback = callback; + + if (mSurface != null) { + mActivityViewCallback.onSurfaceAvailable(this); + } } public static abstract class ActivityViewCallback { @@ -272,6 +266,16 @@ public class ActivityView extends ViewGroup { * have at most one callback registered. */ public abstract void onAllActivitiesComplete(ActivityView view); + /** + * Called when the surface is ready to be drawn to. Calling startActivity prior to this + * callback will result in an IllegalStateException. + */ + public abstract void onSurfaceAvailable(ActivityView view); + /** + * Called when the surface has been removed. Calling startActivity after this callback + * will result in an IllegalStateException. + */ + public abstract void onSurfaceDestroyed(ActivityView view); } private class ActivityViewSurfaceTextureListener implements SurfaceTextureListener { @@ -286,6 +290,9 @@ public class ActivityView extends ViewGroup { mWidth = width; mHeight = height; attachToSurfaceWhenReady(); + if (mActivityViewCallback != null) { + mActivityViewCallback.onSurfaceAvailable(ActivityView.this); + } } @Override @@ -311,6 +318,9 @@ public class ActivityView extends ViewGroup { throw new RuntimeException( "ActivityView: Unable to set surface of ActivityContainer. " + e); } + if (mActivityViewCallback != null) { + mActivityViewCallback.onSurfaceDestroyed(ActivityView.this); + } return true; } @@ -325,7 +335,7 @@ public class ActivityView extends ViewGroup { private final WeakReference<ActivityView> mActivityViewWeakReference; ActivityContainerCallback(ActivityView activityView) { - mActivityViewWeakReference = new WeakReference<ActivityView>(activityView); + mActivityViewWeakReference = new WeakReference<>(activityView); } @Override @@ -340,10 +350,15 @@ public class ActivityView extends ViewGroup { if (activityView != null) { final ActivityViewCallback callback = activityView.mActivityViewCallback; if (callback != null) { + final WeakReference<ActivityViewCallback> callbackRef = + new WeakReference<>(callback); activityView.post(new Runnable() { @Override public void run() { - callback.onAllActivitiesComplete(activityView); + ActivityViewCallback callback = callbackRef.get(); + if (callback != null) { + callback.onAllActivitiesComplete(activityView); + } } }); } @@ -391,24 +406,6 @@ public class ActivityView extends ViewGroup { } } - void checkEmbeddedAllowed(Intent intent) { - try { - mIActivityContainer.checkEmbeddedAllowed(intent); - } catch (RemoteException e) { - throw new RuntimeException( - "ActivityView: Unable to startActivity from Intent. " + e); - } - } - - void checkEmbeddedAllowedIntentSender(IIntentSender intentSender) { - try { - mIActivityContainer.checkEmbeddedAllowedIntentSender(intentSender); - } catch (RemoteException e) { - throw new RuntimeException( - "ActivityView: Unable to startActivity from IntentSender. " + e); - } - } - int getDisplayId() { try { return mIActivityContainer.getDisplayId(); diff --git a/core/java/android/app/IActivityContainer.aidl b/core/java/android/app/IActivityContainer.aidl index 52884f7..cc3b10c 100644 --- a/core/java/android/app/IActivityContainer.aidl +++ b/core/java/android/app/IActivityContainer.aidl @@ -29,8 +29,6 @@ interface IActivityContainer { void setSurface(in Surface surface, int width, int height, int density); int startActivity(in Intent intent); int startActivityIntentSender(in IIntentSender intentSender); - void checkEmbeddedAllowed(in Intent intent); - void checkEmbeddedAllowedIntentSender(in IIntentSender intentSender); int getDisplayId(); boolean injectEvent(in InputEvent event); void release(); diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java index 70c14c6..a138dbb 100644 --- a/core/java/android/app/IActivityManager.java +++ b/core/java/android/app/IActivityManager.java @@ -439,8 +439,7 @@ public interface IActivityManager extends IInterface { public void deleteActivityContainer(IActivityContainer container) throws RemoteException; - public IActivityContainer getEnclosingActivityContainer(IBinder activityToken) - throws RemoteException; + public int getActivityDisplayId(IBinder activityToken) throws RemoteException; public IBinder getHomeActivityToken() throws RemoteException; @@ -756,7 +755,7 @@ public interface IActivityManager extends IInterface { int GET_PERSISTED_URI_PERMISSIONS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+181; int APP_NOT_RESPONDING_VIA_PROVIDER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+182; int GET_HOME_ACTIVITY_TOKEN_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+183; - int GET_ACTIVITY_CONTAINER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+184; + int GET_ACTIVITY_DISPLAY_ID_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+184; int DELETE_ACTIVITY_CONTAINER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+185; diff --git a/core/java/android/app/admin/DeviceAdminReceiver.java b/core/java/android/app/admin/DeviceAdminReceiver.java index 381d851..c53e749 100644 --- a/core/java/android/app/admin/DeviceAdminReceiver.java +++ b/core/java/android/app/admin/DeviceAdminReceiver.java @@ -208,7 +208,8 @@ public class DeviceAdminReceiver extends BroadcastReceiver { * requested provisioning. In the device owner case the profile is the primary user. * The broadcast will also be limited to the {@link DeviceAdminReceiver} component * specified in the original intent or NFC bump that started the provisioning process - * (@see DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE). + * (see {@link DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE + * DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE}). * * <p>A device admin application which listens to this intent can find out if the device was * provisioned for the device owner or profile owner case by calling respectively @@ -225,8 +226,9 @@ public class DeviceAdminReceiver extends BroadcastReceiver { /** * Name under which a DevicePolicy component publishes information * about itself. This meta-data must reference an XML resource containing - * a device-admin tag. XXX TO DO: describe syntax. + * a device-admin tag. */ + // TO DO: describe syntax. public static final String DEVICE_ADMIN_META_DATA = "android.app.device_admin"; private DevicePolicyManager mManager; diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index cf06cb7..a01a96a 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -101,14 +101,14 @@ public class DevicePolicyManager { * device as a personal and corporate device. The user which provisioning is started from and * the managed profile share a launcher. * - * <p>This intent will typically be sent by a mobile device management application (mdm). - * Provisioning adds a managed profile and sets the mdm as the profile owner who has full - * control over the profile + * <p>This intent will typically be sent by a mobile device management application (MDM). + * Provisioning adds a managed profile and sets the MDM as the profile owner who has full + * control over the profile. * * <p>This intent must contain the extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. * * <p> When managed provisioning has completed, an intent of the type - * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the + * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the * managed profile. * * <p> If provisioning fails, the managedProfile is removed so the device returns to its @@ -2698,6 +2698,7 @@ public class DevicePolicyManager { * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins, * then it's up to the TrustAgent itself to aggregate the values from all device admins. * <p>Consult documentation for the specific TrustAgent to determine legal options parameters. + * @hide */ public void setTrustAgentConfiguration(ComponentName admin, ComponentName target, PersistableBundle configuration) { @@ -2724,6 +2725,7 @@ public class DevicePolicyManager { * for this {@param agent} or calls it with a null configuration, null is returned. * @param agent Which component to get enabled features for. * @return configuration for the given trust agent. + * @hide */ public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin, ComponentName agent) { diff --git a/core/java/android/hardware/display/DisplayManagerInternal.java b/core/java/android/hardware/display/DisplayManagerInternal.java index bb162153..adab9be 100644 --- a/core/java/android/hardware/display/DisplayManagerInternal.java +++ b/core/java/android/hardware/display/DisplayManagerInternal.java @@ -132,6 +132,19 @@ public abstract class DisplayManagerInternal { float requestedRefreshRate, boolean inTraversal); /** + * Applies an offset to the contents of a display, for example to avoid burn-in. + * <p> + * TODO: Technically this should be associated with a physical rather than logical + * display but this is good enough for now. + * </p> + * + * @param displayId The logical display id to update. + * @param x The X offset by which to shift the contents of the display. + * @param y The Y offset by which to shift the contents of the display. + */ + public abstract void setDisplayOffsets(int displayId, int x, int y); + + /** * Describes the requested power state of the display. * * This object is intended to describe the general characteristics of the diff --git a/core/java/android/os/IPowerManager.aidl b/core/java/android/os/IPowerManager.aidl index 16dac7d..f187934 100644 --- a/core/java/android/os/IPowerManager.aidl +++ b/core/java/android/os/IPowerManager.aidl @@ -50,6 +50,7 @@ interface IPowerManager void setStayOnSetting(int val); void boostScreenBrightness(long time); + boolean isScreenBrightnessBoosted(); // temporarily overrides the screen brightness settings to allow the user to // see the effect of a settings change without applying it immediately diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index d52dd30..0145c96 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -205,6 +205,20 @@ public final class PowerManager { public static final int DOZE_WAKE_LOCK = 0x00000040; /** + * Wake lock level: Keep the device awake enough to allow drawing to occur. + * <p> + * This is used by the window manager to allow applications to draw while the + * system is dozing. It currently has no effect unless the power manager is in + * the dozing state. + * </p><p> + * Requires the {@link android.Manifest.permission#DEVICE_POWER} permission. + * </p> + * + * {@hide} + */ + public static final int DRAW_WAKE_LOCK = 0x00000080; + + /** * Mask for the wake lock level component of a combined wake lock level and flags integer. * * @hide @@ -350,6 +364,12 @@ public final class PowerManager { public static final int GO_TO_SLEEP_REASON_HDMI = 5; /** + * Go to sleep reason code: Going to sleep due to the sleep button being pressed. + * @hide + */ + public static final int GO_TO_SLEEP_REASON_SLEEP_BUTTON = 6; + + /** * Go to sleep flag: Skip dozing state and directly go to full sleep. * @hide */ @@ -489,6 +509,7 @@ public final class PowerManager { case FULL_WAKE_LOCK: case PROXIMITY_SCREEN_OFF_WAKE_LOCK: case DOZE_WAKE_LOCK: + case DRAW_WAKE_LOCK: break; default: throw new IllegalArgumentException("Must specify a valid wake lock level."); @@ -691,6 +712,22 @@ public final class PowerManager { } /** + * Returns whether the screen brightness is currently boosted to maximum, caused by a call + * to {@link #boostScreenBrightness(long)}. + * @return {@code True} if the screen brightness is currently boosted. {@code False} otherwise. + * + * @hide + */ + @SystemApi + public boolean isScreenBrightnessBoosted() { + try { + return mService.isScreenBrightnessBoosted(); + } catch (RemoteException e) { + return false; + } + } + + /** * Sets the brightness of the backlights (screen, keyboard, button). * <p> * Requires the {@link android.Manifest.permission#DEVICE_POWER} permission. @@ -871,6 +908,16 @@ public final class PowerManager { public static final String EXTRA_POWER_SAVE_MODE = "mode"; /** + * Intent that is broadcast when the state of {@link #isScreenBrightnessBoosted()} has changed. + * This broadcast is only sent to registered receivers. + * + * @hide + **/ + @SystemApi + public static final String ACTION_SCREEN_BRIGHTNESS_BOOST_CHANGED + = "android.os.action.SCREEN_BRIGHTNESS_BOOST_CHANGED"; + + /** * A wake lock is a mechanism to indicate that your application needs * to have the device stay on. * <p> diff --git a/core/java/android/provider/MediaStore.java b/core/java/android/provider/MediaStore.java index 736ec54..5afbd6d 100644 --- a/core/java/android/provider/MediaStore.java +++ b/core/java/android/provider/MediaStore.java @@ -638,7 +638,6 @@ public final class MediaStore { static Bitmap getThumbnail(ContentResolver cr, long origId, long groupId, int kind, BitmapFactory.Options options, Uri baseUri, boolean isVideo) { Bitmap bitmap = null; - String filePath = null; // Log.v(TAG, "getThumbnail: origId="+origId+", kind="+kind+", isVideo="+isVideo); // If the magic is non-zero, we simply return thumbnail if it does exist. // querying MediaProvider and simply return thumbnail. @@ -710,18 +709,18 @@ public final class MediaStore { Uri uri = Uri.parse( baseUri.buildUpon().appendPath(String.valueOf(origId)) .toString().replaceFirst("thumbnails", "media")); - if (filePath == null) { - if (c != null) c.close(); - c = cr.query(uri, PROJECTION, null, null, null); - if (c == null || !c.moveToFirst()) { - return null; - } - filePath = c.getString(1); + if (c != null) c.close(); + c = cr.query(uri, PROJECTION, null, null, null); + if (c == null || !c.moveToFirst()) { + return null; } - if (isVideo) { - bitmap = ThumbnailUtils.createVideoThumbnail(filePath, kind); - } else { - bitmap = ThumbnailUtils.createImageThumbnail(filePath, kind); + String filePath = c.getString(1); + if (filePath != null) { + if (isVideo) { + bitmap = ThumbnailUtils.createVideoThumbnail(filePath, kind); + } else { + bitmap = ThumbnailUtils.createImageThumbnail(filePath, kind); + } } } } catch (SQLiteException ex) { diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java index 9496b53..d46b6f5 100644 --- a/core/java/android/service/wallpaper/WallpaperService.java +++ b/core/java/android/service/wallpaper/WallpaperService.java @@ -17,15 +17,12 @@ package android.service.wallpaper; import android.content.res.TypedArray; -import android.os.Build; import android.os.SystemProperties; -import android.util.DisplayMetrics; -import android.util.TypedValue; -import android.view.ViewRootImpl; import android.view.WindowInsets; import com.android.internal.R; import com.android.internal.os.HandlerCaller; +import com.android.internal.util.ScreenShapeHelper; import com.android.internal.view.BaseIWindow; import com.android.internal.view.BaseSurfaceHolder; @@ -64,8 +61,6 @@ import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; -import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN; - /** * A wallpaper service is responsible for showing a live wallpaper behind * applications that would like to sit on top of it. This service object @@ -160,7 +155,7 @@ public abstract class WallpaperService extends Service { WindowManager.LayoutParams.PRIVATE_FLAG_WANTS_OFFSET_NOTIFICATIONS; int mCurWindowFlags = mWindowFlags; int mCurWindowPrivateFlags = mWindowPrivateFlags; - TypedValue mOutsetBottom; + int mOutsetBottomPx; final Rect mVisibleInsets = new Rect(); final Rect mWinFrame = new Rect(); final Rect mOverscanInsets = new Rect(); @@ -173,8 +168,6 @@ public abstract class WallpaperService extends Service { final Rect mFinalStableInsets = new Rect(); final Configuration mConfiguration = new Configuration(); - private boolean mIsEmulator; - private boolean mIsCircularEmulator; private boolean mWindowIsRound; final WindowManager.LayoutParams mLayout @@ -639,23 +632,13 @@ public abstract class WallpaperService extends Service { final Display display = windowService.getDefaultDisplay(); final boolean shouldUseBottomOutset = display.getDisplayId() == Display.DEFAULT_DISPLAY; - if (shouldUseBottomOutset && windowStyle.hasValue( - R.styleable.Window_windowOutsetBottom)) { - if (mOutsetBottom == null) mOutsetBottom = new TypedValue(); - windowStyle.getValue(R.styleable.Window_windowOutsetBottom, - mOutsetBottom); - } else { - mOutsetBottom = null; + if (shouldUseBottomOutset) { + mOutsetBottomPx = ScreenShapeHelper.getWindowOutsetBottomPx( + getResources().getDisplayMetrics(), windowStyle); } - mWindowIsRound = getResources().getBoolean( - com.android.internal.R.bool.config_windowIsRound); + mWindowIsRound = ScreenShapeHelper.getWindowIsRound(getResources()); windowStyle.recycle(); - // detect emulator - mIsEmulator = Build.HARDWARE.contains("goldfish"); - mIsCircularEmulator = SystemProperties.getBoolean( - ViewRootImpl.PROPERTY_EMULATOR_CIRCULAR, false); - // Add window mLayout.type = mIWallpaperEngine.mWindowType; mLayout.gravity = Gravity.START|Gravity.TOP; @@ -785,18 +768,14 @@ public abstract class WallpaperService extends Service { mDispatchedOverscanInsets.set(mOverscanInsets); mDispatchedContentInsets.set(mContentInsets); mDispatchedStableInsets.set(mStableInsets); - final boolean isRound = (mIsEmulator && mIsCircularEmulator) - || mWindowIsRound; mFinalSystemInsets.set(mDispatchedOverscanInsets); mFinalStableInsets.set(mDispatchedStableInsets); - if (mOutsetBottom != null) { - final DisplayMetrics metrics = getResources().getDisplayMetrics(); + if (mOutsetBottomPx != 0) { mFinalSystemInsets.bottom = - ( (int) mOutsetBottom.getDimension(metrics) ) - + mIWallpaperEngine.mDisplayPadding.bottom; + mIWallpaperEngine.mDisplayPadding.bottom + mOutsetBottomPx; } WindowInsets insets = new WindowInsets(mFinalSystemInsets, - null, mFinalStableInsets, isRound); + null, mFinalStableInsets, mWindowIsRound); onApplyWindowInsets(insets); } diff --git a/core/java/android/view/IWindowSession.aidl b/core/java/android/view/IWindowSession.aidl index 7b13e84..63e1a85 100644 --- a/core/java/android/view/IWindowSession.aidl +++ b/core/java/android/view/IWindowSession.aidl @@ -197,4 +197,19 @@ interface IWindowSession { void onRectangleOnScreenRequested(IBinder token, in Rect rectangle); IWindowId getWindowId(IBinder window); + + /** + * When the system is dozing in a low-power partially suspended state, pokes a short + * lived wake lock and ensures that the display is ready to accept the next frame + * of content drawn in the window. + * + * This mechanism is bound to the window rather than to the display manager or the + * power manager so that the system can ensure that the window is actually visible + * and prevent runaway applications from draining the battery. This is similar to how + * FLAG_KEEP_SCREEN_ON works. + * + * This method is synchronous because it may need to acquire a wake lock before returning. + * The assumption is that this method will be called rather infrequently. + */ + void pokeDrawLock(IBinder window); } diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index e4d82b1..113ad8d 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -40,7 +40,6 @@ import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManager.DisplayListener; import android.media.AudioManager; import android.os.Binder; -import android.os.Build; import android.os.Bundle; import android.os.Debug; import android.os.Handler; @@ -77,6 +76,7 @@ import android.widget.Scroller; import com.android.internal.R; import com.android.internal.os.SomeArgs; import com.android.internal.policy.PolicyManager; +import com.android.internal.util.ScreenShapeHelper; import com.android.internal.view.BaseSurfaceHolder; import com.android.internal.view.RootViewSurfaceTaker; @@ -120,8 +120,10 @@ public final class ViewRootImpl implements ViewParent, private static final String PROPERTY_PROFILE_RENDERING = "viewroot.profile_rendering"; private static final String PROPERTY_MEDIA_DISABLED = "config.disable_media"; - // property used by emulator to determine display shape + // properties used by emulator to determine display shape public static final String PROPERTY_EMULATOR_CIRCULAR = "ro.emulator.circular"; + public static final String PROPERTY_EMULATOR_WIN_OUTSET_BOTTOM_PX = + "ro.emu.win_outset_bottom_px"; /** * Maximum time we allow the user to roll the trackball enough to generate @@ -332,8 +334,6 @@ public final class ViewRootImpl implements ViewParent, /** Set to true once doDie() has been called. */ private boolean mRemoved; - private boolean mIsEmulator; - private boolean mIsCircularEmulator; private final boolean mWindowIsRound; /** @@ -390,8 +390,7 @@ public final class ViewRootImpl implements ViewParent, mChoreographer = Choreographer.getInstance(); mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE); loadSystemProperties(); - mWindowIsRound = context.getResources().getBoolean( - com.android.internal.R.bool.config_windowIsRound); + mWindowIsRound = ScreenShapeHelper.getWindowIsRound(context.getResources()); } public static void addFirstDrawHandler(Runnable callback) { @@ -831,6 +830,7 @@ public final class ViewRootImpl implements ViewParent, final int newDisplayState = mDisplay.getState(); if (oldDisplayState != newDisplayState) { mAttachInfo.mDisplayState = newDisplayState; + pokeDrawLockIfNeeded(); if (oldDisplayState != Display.STATE_UNKNOWN) { final int oldScreenState = toViewScreenState(oldDisplayState); final int newScreenState = toViewScreenState(newDisplayState); @@ -861,6 +861,19 @@ public final class ViewRootImpl implements ViewParent, } }; + void pokeDrawLockIfNeeded() { + final int displayState = mAttachInfo.mDisplayState; + if (mView != null && mAdded && mTraversalScheduled + && (displayState == Display.STATE_DOZE + || displayState == Display.STATE_DOZE_SUSPEND)) { + try { + mWindowSession.pokeDrawLock(mWindow); + } catch (RemoteException ex) { + // System server died, oh well. + } + } + } + @Override public void requestFitSystemWindows() { checkThread(); @@ -1035,6 +1048,7 @@ public final class ViewRootImpl implements ViewParent, scheduleConsumeBatchedInput(); } notifyRendererOfFramePending(); + pokeDrawLockIfNeeded(); } } @@ -1208,10 +1222,9 @@ public final class ViewRootImpl implements ViewParent, void dispatchApplyInsets(View host) { mDispatchContentInsets.set(mAttachInfo.mContentInsets); mDispatchStableInsets.set(mAttachInfo.mStableInsets); - final boolean isRound = (mIsEmulator && mIsCircularEmulator) || mWindowIsRound; host.dispatchApplyWindowInsets(new WindowInsets( mDispatchContentInsets, null /* windowDecorInsets */, - mDispatchStableInsets, isRound)); + mDispatchStableInsets, mWindowIsRound)); } private void performTraversals() { @@ -5555,11 +5568,6 @@ public final class ViewRootImpl implements ViewParent, mHandler.sendEmptyMessageDelayed(MSG_INVALIDATE_WORLD, 200); } } - - // detect emulator - mIsEmulator = Build.HARDWARE.contains("goldfish"); - mIsCircularEmulator = - SystemProperties.getBoolean(PROPERTY_EMULATOR_CIRCULAR, false); } }); } diff --git a/core/java/android/widget/DatePickerCalendarDelegate.java b/core/java/android/widget/DatePickerCalendarDelegate.java index fc75346..1d50eb2 100755 --- a/core/java/android/widget/DatePickerCalendarDelegate.java +++ b/core/java/android/widget/DatePickerCalendarDelegate.java @@ -192,6 +192,7 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate i mYearPickerView = new YearPickerView(mContext); mYearPickerView.init(this); + mYearPickerView.setRange(mMinDate, mMaxDate); final int yearSelectedCircleColor = a.getColor(R.styleable.DatePicker_yearListSelectorColor, defaultHighlightColor); diff --git a/core/java/com/android/internal/util/ScreenShapeHelper.java b/core/java/com/android/internal/util/ScreenShapeHelper.java new file mode 100644 index 0000000..1bcc7a0 --- /dev/null +++ b/core/java/com/android/internal/util/ScreenShapeHelper.java @@ -0,0 +1,48 @@ +package com.android.internal.util; + +import android.content.res.Resources; +import android.content.res.TypedArray; +import android.os.Build; +import android.os.SystemProperties; +import android.util.DisplayMetrics; +import android.util.TypedValue; +import android.view.ViewRootImpl; + +import com.android.internal.R; + +/** + * @hide + */ +public class ScreenShapeHelper { + private static final boolean IS_EMULATOR = Build.HARDWARE.contains("goldfish"); + + /** + * Return the bottom pixel window outset of a window given its style attributes. + * @param displayMetrics Display metrics of the current device + * @param windowStyle Window style attributes for the window. + * @return An outset dimension in pixels or 0 if no outset should be applied. + */ + public static int getWindowOutsetBottomPx(DisplayMetrics displayMetrics, + TypedArray windowStyle) { + if (IS_EMULATOR) { + return SystemProperties.getInt(ViewRootImpl.PROPERTY_EMULATOR_WIN_OUTSET_BOTTOM_PX, 0); + } else if (windowStyle.hasValue(R.styleable.Window_windowOutsetBottom)) { + TypedValue outsetBottom = new TypedValue(); + windowStyle.getValue(R.styleable.Window_windowOutsetBottom, outsetBottom); + return (int) outsetBottom.getDimension(displayMetrics); + } + return 0; + } + + /** + * Get whether a device has has a round screen. + */ + public static boolean getWindowIsRound(Resources resources) { + if (IS_EMULATOR) { + return SystemProperties.getBoolean(ViewRootImpl.PROPERTY_EMULATOR_CIRCULAR, false); + } else { + return resources.getBoolean( + com.android.internal.R.bool.config_windowIsRound); + } + } +} diff --git a/core/java/com/android/internal/widget/SwipeDismissLayout.java b/core/java/com/android/internal/widget/SwipeDismissLayout.java index d617c05..89990c2 100644 --- a/core/java/com/android/internal/widget/SwipeDismissLayout.java +++ b/core/java/com/android/internal/widget/SwipeDismissLayout.java @@ -19,6 +19,7 @@ package com.android.internal.widget; import android.animation.TimeInterpolator; import android.app.Activity; import android.content.Context; +import android.content.res.TypedArray; import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; @@ -38,6 +39,7 @@ public class SwipeDismissLayout extends FrameLayout { private static final String TAG = "SwipeDismissLayout"; private static final float DISMISS_MIN_DRAG_WIDTH_RATIO = .33f; + private boolean mUseDynamicTranslucency = true; public interface OnDismissedListener { void onDismissed(SwipeDismissLayout layout); @@ -85,7 +87,7 @@ public class SwipeDismissLayout extends FrameLayout { // and temporarily disables translucency when it is fully visible. // As soon as the user starts swiping, we will re-enable // translucency. - if (getContext() instanceof Activity) { + if (mUseDynamicTranslucency && getContext() instanceof Activity) { ((Activity) getContext()).convertFromTranslucent(); } } @@ -117,6 +119,11 @@ public class SwipeDismissLayout extends FrameLayout { android.R.integer.config_shortAnimTime); mCancelInterpolator = new DecelerateInterpolator(1.5f); mDismissInterpolator = new AccelerateInterpolator(1.5f); + TypedArray a = context.getTheme().obtainStyledAttributes( + com.android.internal.R.styleable.Theme); + mUseDynamicTranslucency = !a.hasValue( + com.android.internal.R.styleable.Window_windowIsTranslucent); + a.recycle(); } public void setOnDismissedListener(OnDismissedListener listener) { @@ -230,7 +237,7 @@ public class SwipeDismissLayout extends FrameLayout { mLastX = ev.getRawX(); updateSwiping(ev); if (mSwiping) { - if (getContext() instanceof Activity) { + if (mUseDynamicTranslucency && getContext() instanceof Activity) { ((Activity) getContext()).convertToTranslucent(null, null); } setProgress(ev.getRawX() - mDownX); @@ -254,7 +261,7 @@ public class SwipeDismissLayout extends FrameLayout { } protected void cancel() { - if (getContext() instanceof Activity) { + if (mUseDynamicTranslucency && getContext() instanceof Activity) { ((Activity) getContext()).convertFromTranslucent(); } if (mProgressListener != null) { |