diff options
| author | 2014-09-02 13:59:07 -0700 | |
|---|---|---|
| committer | 2014-09-02 13:59:07 -0700 | |
| commit | 3818c9261ceaa3a700ff984fbcd245faeede38d7 (patch) | |
| tree | 58367f09a2f33e36a48bd3d464da16a62ec342fe | |
| parent | d06cd2b1bd067e911d48c3b0c81a503c5772c98f (diff) | |
Add support for SW_CAMERA_LENS_COVER.
This allows for magic cover type accessories to launch the camera application.
Bug: 16034563
Change-Id: I0a46ef885737d964a1482c99f41145053d559faf
5 files changed, 83 insertions, 1 deletions
diff --git a/core/java/android/view/WindowManagerPolicy.java b/core/java/android/view/WindowManagerPolicy.java index 053fdd007e08..b7b12a867a75 100644 --- a/core/java/android/view/WindowManagerPolicy.java +++ b/core/java/android/view/WindowManagerPolicy.java @@ -379,6 +379,10 @@ public interface WindowManagerPolicy { public static final int LID_CLOSED = 0; public static final int LID_OPEN = 1; + public static final int CAMERA_LENS_COVER_ABSENT = -1; + public static final int CAMERA_LENS_UNCOVERED = 0; + public static final int CAMERA_LENS_COVERED = 1; + /** * Ask the window manager to re-evaluate the system UI flags. */ @@ -399,6 +403,11 @@ public interface WindowManagerPolicy { public int getLidState(); /** + * Returns a code that descripbes whether the camera lens is covered or not. + */ + public int getCameraLensCoverState(); + + /** * Switch the keyboard layout for the given device. * Direction should be +1 or -1 to go to the next or previous keyboard layout. */ @@ -951,7 +960,14 @@ public interface WindowManagerPolicy { * @param lidOpen True if the lid is now open. */ public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen); - + + /** + * Tell the policy that the camera lens has been covered or uncovered. + * @param whenNanos The time when the change occurred in uptime nanoseconds. + * @param lensCovered True if the lens is covered. + */ + public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered); + /** * Tell the policy if anyone is requesting that keyguard not come on. * diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index e382a9ff29eb..e8dc80062733 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -66,6 +66,7 @@ import android.os.SystemProperties; import android.os.UEventObserver; import android.os.UserHandle; import android.os.Vibrator; +import android.provider.MediaStore; import android.provider.Settings; import android.service.dreams.DreamManagerInternal; import android.service.dreams.DreamService; @@ -127,6 +128,9 @@ import static android.view.WindowManager.LayoutParams.*; import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; +import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT; +import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED; +import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED; /** * WindowManagerPolicy implementation for the Android phone UI. This @@ -315,6 +319,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { boolean mLanguageSwitchKeyPressed; int mLidState = LID_ABSENT; + int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT; boolean mHaveBuiltInKeyboard; boolean mSystemReady; @@ -1525,6 +1530,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { mLidState = mWindowManagerFuncs.getLidState(); } + private void readCameraLensCoverState() { + mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState(); + } + private boolean isHidden(int accessibilityMode) { switch (accessibilityMode) { case 1: @@ -4055,6 +4064,27 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } + @Override + public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { + int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED; + if (mCameraLensCoverState == lensCoverState) { + return; + } + if (mCameraLensCoverState == CAMERA_LENS_COVERED && + lensCoverState == CAMERA_LENS_UNCOVERED) { + Intent intent; + final boolean keyguardActive = mKeyguardDelegate == null ? false : + mKeyguardDelegate.isShowing(); + if (keyguardActive) { + intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE); + } else { + intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); + } + mContext.startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); + } + mCameraLensCoverState = lensCoverState; + } + void setHdmiPlugged(boolean plugged) { if (mHdmiPlugged != plugged) { mHdmiPlugged = plugged; @@ -5132,6 +5162,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null); mKeyguardDelegate.onSystemReady(); + readCameraLensCoverState(); updateUiMode(); synchronized (mLock) { updateOrientationListenerLp(); @@ -5783,6 +5814,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { pw.print(" mSystemBooted="); pw.println(mSystemBooted); pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); + pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState); pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 || mForceClearedSystemUiFlags != 0) { diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java index 93dceff809be..9e81149969fe 100644 --- a/services/core/java/com/android/server/input/InputManagerService.java +++ b/services/core/java/com/android/server/input/InputManagerService.java @@ -241,6 +241,9 @@ public class InputManagerService extends IInputManager.Stub /** Switch code: Headphone/Microphone Jack. When set, something is inserted. */ public static final int SW_JACK_PHYSICAL_INSERT = 0x07; + /** Switch code: Camera lens cover. When set the lens is covered. */ + public static final int SW_CAMERA_LENS_COVER = 0x09; + public static final int SW_LID_BIT = 1 << SW_LID; public static final int SW_KEYPAD_SLIDE_BIT = 1 << SW_KEYPAD_SLIDE; public static final int SW_HEADPHONE_INSERT_BIT = 1 << SW_HEADPHONE_INSERT; @@ -249,6 +252,7 @@ public class InputManagerService extends IInputManager.Stub public static final int SW_JACK_PHYSICAL_INSERT_BIT = 1 << SW_JACK_PHYSICAL_INSERT; public static final int SW_JACK_BITS = SW_HEADPHONE_INSERT_BIT | SW_MICROPHONE_INSERT_BIT | SW_JACK_PHYSICAL_INSERT_BIT | SW_LINEOUT_INSERT_BIT; + public static final int SW_CAMERA_LENS_COVER_BIT = 1 << SW_CAMERA_LENS_COVER; /** Whether to use the dev/input/event or uevent subsystem for the audio jack. */ final boolean mUseDevInputEventForAudioJack; @@ -1380,6 +1384,11 @@ public class InputManagerService extends IInputManager.Stub mWindowManagerCallbacks.notifyLidSwitchChanged(whenNanos, lidOpen); } + if ((switchMask & SW_CAMERA_LENS_COVER_BIT) != 0) { + final boolean lensCovered = ((switchValues & SW_CAMERA_LENS_COVER_BIT) == 0); + mWindowManagerCallbacks.notifyCameraLensCoverSwitchChanged(whenNanos, lensCovered); + } + if (mUseDevInputEventForAudioJack && (switchMask & SW_JACK_BITS) != 0) { mWiredAccessoryCallbacks.notifyWiredAccessoryChanged(whenNanos, switchValues, switchMask); @@ -1575,6 +1584,8 @@ public class InputManagerService extends IInputManager.Stub public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen); + public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered); + public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle); public long notifyANR(InputApplicationHandle inputApplicationHandle, diff --git a/services/core/java/com/android/server/wm/InputMonitor.java b/services/core/java/com/android/server/wm/InputMonitor.java index f02c0e67e050..d0f00d438862 100644 --- a/services/core/java/com/android/server/wm/InputMonitor.java +++ b/services/core/java/com/android/server/wm/InputMonitor.java @@ -352,6 +352,12 @@ final class InputMonitor implements InputManagerService.WindowManagerCallbacks { mService.mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); } + /* Notifies that the camera lens cover state has changed. */ + @Override + public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { + mService.mPolicy.notifyCameraLensCoverSwitchChanged(whenNanos, lensCovered); + } + /* Provides an opportunity for the window manager policy to intercept early key * processing as soon as the key has been read from the device. */ @Override diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index c70cb22750f4..36fd864e9936 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -5436,6 +5436,23 @@ public class WindowManagerService extends IWindowManager.Stub } } + // Called by window manager policy. Not exposed externally. + @Override + public int getCameraLensCoverState() { + int sw = mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, + InputManagerService.SW_CAMERA_LENS_COVER); + if (sw > 0) { + // Switch state: AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL. + return CAMERA_LENS_COVERED; + } else if (sw == 0) { + // Switch state: AKEY_STATE_UP. + return CAMERA_LENS_UNCOVERED; + } else { + // Switch state: AKEY_STATE_UNKNOWN. + return CAMERA_LENS_COVER_ABSENT; + } + } + // Called by window manager policy. Not exposed externally. @Override public void switchKeyboardLayout(int deviceId, int direction) { |