Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7d01d2c6 authored by Jorim Jaggi's avatar Jorim Jaggi Committed by Android (Google) Code Review
Browse files

Merge "Fix API review: Camera prewarm" into mnc-dev

parents 11accf51 d944986f
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -26143,8 +26143,6 @@ package android.provider {
    method public static java.lang.String getVersion(android.content.Context);
    field public static final java.lang.String ACTION_IMAGE_CAPTURE = "android.media.action.IMAGE_CAPTURE";
    field public static final java.lang.String ACTION_IMAGE_CAPTURE_SECURE = "android.media.action.IMAGE_CAPTURE_SECURE";
    field public static final java.lang.String ACTION_STILL_IMAGE_CAMERA_COOLDOWN = "android.media.action.STILL_IMAGE_CAMERA_COOLDOWN";
    field public static final java.lang.String ACTION_STILL_IMAGE_CAMERA_PREWARM = "android.media.action.STILL_IMAGE_CAMERA_PREWARM";
    field public static final java.lang.String ACTION_VIDEO_CAPTURE = "android.media.action.VIDEO_CAPTURE";
    field public static final java.lang.String AUTHORITY = "media";
    field public static final java.lang.String EXTRA_DURATION_LIMIT = "android.intent.extra.durationLimit";
@@ -26172,6 +26170,7 @@ package android.provider {
    field public static final java.lang.String INTENT_ACTION_VIDEO_PLAY_FROM_SEARCH = "android.media.action.VIDEO_PLAY_FROM_SEARCH";
    field public static final java.lang.String MEDIA_IGNORE_FILENAME = ".nomedia";
    field public static final java.lang.String MEDIA_SCANNER_VOLUME = "volume";
    field public static final java.lang.String META_DATA_STILL_IMAGE_CAMERA_PREWARM_SERVICE = "android.media.still_image_camera_preview_service";
    field public static final java.lang.String UNKNOWN_STRING = "<unknown>";
  }
@@ -28730,6 +28729,13 @@ package android.service.dreams {
package android.service.media {
  public abstract class CameraPrewarmService extends android.app.Service {
    ctor public CameraPrewarmService();
    method public android.os.IBinder onBind(android.content.Intent);
    method public abstract void onCooldown(boolean);
    method public abstract void onPrewarm();
  }
  public abstract class MediaBrowserService extends android.app.Service {
    ctor public MediaBrowserService();
    method public void dump(java.io.FileDescriptor, java.io.PrintWriter, java.lang.String[]);
+8 −2
Original line number Diff line number Diff line
@@ -28072,8 +28072,6 @@ package android.provider {
    method public static java.lang.String getVersion(android.content.Context);
    field public static final java.lang.String ACTION_IMAGE_CAPTURE = "android.media.action.IMAGE_CAPTURE";
    field public static final java.lang.String ACTION_IMAGE_CAPTURE_SECURE = "android.media.action.IMAGE_CAPTURE_SECURE";
    field public static final java.lang.String ACTION_STILL_IMAGE_CAMERA_COOLDOWN = "android.media.action.STILL_IMAGE_CAMERA_COOLDOWN";
    field public static final java.lang.String ACTION_STILL_IMAGE_CAMERA_PREWARM = "android.media.action.STILL_IMAGE_CAMERA_PREWARM";
    field public static final java.lang.String ACTION_VIDEO_CAPTURE = "android.media.action.VIDEO_CAPTURE";
    field public static final java.lang.String AUTHORITY = "media";
    field public static final java.lang.String EXTRA_DURATION_LIMIT = "android.intent.extra.durationLimit";
@@ -28101,6 +28099,7 @@ package android.provider {
    field public static final java.lang.String INTENT_ACTION_VIDEO_PLAY_FROM_SEARCH = "android.media.action.VIDEO_PLAY_FROM_SEARCH";
    field public static final java.lang.String MEDIA_IGNORE_FILENAME = ".nomedia";
    field public static final java.lang.String MEDIA_SCANNER_VOLUME = "volume";
    field public static final java.lang.String META_DATA_STILL_IMAGE_CAMERA_PREWARM_SERVICE = "android.media.still_image_camera_preview_service";
    field public static final java.lang.String UNKNOWN_STRING = "<unknown>";
  }
@@ -30762,6 +30761,13 @@ package android.service.dreams {
package android.service.media {
  public abstract class CameraPrewarmService extends android.app.Service {
    ctor public CameraPrewarmService();
    method public android.os.IBinder onBind(android.content.Intent);
    method public abstract void onCooldown(boolean);
    method public abstract void onPrewarm();
  }
  public abstract class MediaBrowserService extends android.app.Service {
    ctor public MediaBrowserService();
    method public void dump(java.io.FileDescriptor, java.io.PrintWriter, java.lang.String[]);
+16 −24
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteException;
@@ -33,6 +34,7 @@ import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.service.media.CameraPrewarmService;
import android.util.Log;

import java.io.FileInputStream;
@@ -226,33 +228,24 @@ public final class MediaStore {
    public static final String INTENT_ACTION_STILL_IMAGE_CAMERA = "android.media.action.STILL_IMAGE_CAMERA";

    /**
     * The name of the Intent action used to indicate that a camera launch might be imminent. This
     * broadcast should be targeted to the package that is receiving
     * {@link #INTENT_ACTION_STILL_IMAGE_CAMERA} or
     * {@link #INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE}, depending on the context. If such
     * intent would launch the resolver activity, this broadcast should not be sent at all.
     * Name under which an activity handling {@link #INTENT_ACTION_STILL_IMAGE_CAMERA} or
     * {@link #INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE} publishes the service name for its prewarm
     * service.
     * <p>
     * A receiver of this broadcast should do the absolute minimum amount of work to initialize the
     * camera in order to reduce startup time in likely case that shortly after an actual camera
     * launch intent would be sent.
     * This meta-data should reference the fully qualified class name of the prewarm service
     * extending {@link CameraPrewarmService}.
     * <p>
     * In case the actual intent will not be fired, the target package will receive
     * {@link #ACTION_STILL_IMAGE_CAMERA_COOLDOWN}. However, it is recommended that the receiver
     * also implements a timeout to close the camera after receiving this intent, as there is no
     * guarantee that {@link #ACTION_STILL_IMAGE_CAMERA_COOLDOWN} will be delivered.
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_STILL_IMAGE_CAMERA_PREWARM = "android.media.action.STILL_IMAGE_CAMERA_PREWARM";

    /**
     * The name of the Intent action used to indicate that an imminent camera launch has been
     * cancelled by the user. This broadcast should be targeted to the package that has received
     * {@link #ACTION_STILL_IMAGE_CAMERA_PREWARM}.
     * The prewarm service will get bound and receive a prewarm signal
     * {@link CameraPrewarmService#onPrewarm()} when a camera launch intent fire might be imminent.
     * An application implementing a prewarm service should do the absolute minimum amount of work
     * to initialize the camera in order to reduce startup time in likely case that shortly after a
     * camera launch intent would be sent.
     * <p>
     * A receiver of this broadcast should close the camera immediately.
     * If the camera launch intent gets fired shortly after, the service will be unbound
     * asynchronously, without receiving
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_STILL_IMAGE_CAMERA_COOLDOWN = "android.media.action.STILL_IMAGE_CAMERA_COOLDOWN";
    public static final String META_DATA_STILL_IMAGE_CAMERA_PREWARM_SERVICE =
            "android.media.still_image_camera_preview_service";

    /**
     * The name of the Intent action used to launch a camera in still image mode
@@ -2268,5 +2261,4 @@ public final class MediaStore {
        }
        return null;
    }

}
+96 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 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 android.service.media;

import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;

/**
 * Extend this class to implement a camera prewarm service. See
 * {@link android.provider.MediaStore#META_DATA_STILL_IMAGE_CAMERA_PREWARM_SERVICE}.
 */
public abstract class CameraPrewarmService extends Service {

    /**
     * Intent action to bind the service as a prewarm service.
     * @hide
     */
    public static final String ACTION_PREWARM =
            "android.service.media.CameraPrewarmService.ACTION_PREWARM";

    /**
     * Message sent by the client indicating that the camera intent has been fired.
     * @hide
     */
    public static final int MSG_CAMERA_FIRED = 1;

    private final Handler mHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_CAMERA_FIRED:
                    mCameraIntentFired = true;
                    break;
                default:
                    super.handleMessage(msg);
            }
        }
    };
    private boolean mCameraIntentFired;

    @Override
    public IBinder onBind(Intent intent) {
        if (ACTION_PREWARM.equals(intent.getAction())) {
            onPrewarm();
            return new Messenger(mHandler).getBinder();
        } else {
            return null;
        }
    }

    @Override
    public boolean onUnbind(Intent intent) {
        if (ACTION_PREWARM.equals(intent.getAction())) {
            onCooldown(mCameraIntentFired);
        }
        return false;
    }

    /**
     * Called when the camera should be prewarmed.
     */
    public abstract void onPrewarm();

    /**
     * Called when prewarm phase is done, either because the camera launch intent has been fired
     * at this point or prewarm is no longer needed. A client should close the camera
     * immediately in the latter case.
     * <p>
     * In case the camera launch intent has been fired, there is no guarantee about the ordering
     * of these two events. Cooldown might happen either before or after the activity has been
     * created that handles the camera intent.
     *
     * @param cameraIntentFired Indicates whether the intent to launch the camera has been
     *                          fired.
     */
    public abstract void onCooldown(boolean cameraIntentFired);
}
+12 −1
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ public class KeyguardHostView extends FrameLayout implements SecurityCallback {
    protected ViewMediatorCallback mViewMediatorCallback;
    protected LockPatternUtils mLockPatternUtils;
    private OnDismissAction mDismissAction;
    private Runnable mCancelAction;

    private final KeyguardUpdateMonitorCallback mUpdateCallback =
            new KeyguardUpdateMonitorCallback() {
@@ -126,8 +127,17 @@ public class KeyguardHostView extends FrameLayout implements SecurityCallback {
     *
     * @param action
     */
    public void setOnDismissAction(OnDismissAction action) {
    public void setOnDismissAction(OnDismissAction action, Runnable cancelAction) {
        if (mCancelAction != null) {
            mCancelAction.run();
            mCancelAction = null;
        }
        mDismissAction = action;
        mCancelAction = cancelAction;
    }

    public void cancelDismissAction() {
        setOnDismissAction(null, null);
    }

    @Override
@@ -197,6 +207,7 @@ public class KeyguardHostView extends FrameLayout implements SecurityCallback {
        if (mDismissAction != null) {
            deferKeyguardDone = mDismissAction.onDismiss();
            mDismissAction = null;
            mCancelAction = null;
        }
        if (mViewMediatorCallback != null) {
            if (deferKeyguardDone) {
Loading