diff options
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/statusbar')
7 files changed, 467 insertions, 184 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java index 54e8815..73f1aa4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java @@ -22,11 +22,9 @@ import android.app.Notification; import android.app.PendingIntent; import android.app.TaskStackBuilder; import android.content.BroadcastReceiver; -import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.ServiceConnection; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; @@ -79,8 +77,6 @@ import com.android.systemui.R; import com.android.systemui.RecentsComponent; import com.android.systemui.SearchPanelView; import com.android.systemui.SystemUI; -import com.android.systemui.keyguard.KeyguardService; -import com.android.systemui.keyguard.KeyguardStatusBarBinder; import com.android.systemui.statusbar.phone.KeyguardTouchDelegate; import java.util.ArrayList; @@ -176,12 +172,6 @@ public abstract class BaseStatusBar extends SystemUI implements protected int mZenMode; - protected KeyguardStatusBarBinder mKeyguardService; - - public IStatusBarService getStatusBarService() { - return mBarService; - } - public boolean isDeviceProvisioned() { return mDeviceProvisioned; } @@ -320,7 +310,6 @@ public abstract class BaseStatusBar extends SystemUI implements createAndAddWindows(); - startKeyguardService(); disable(switches[0]); setSystemUiVisibility(switches[1], 0xffffffff); topAppWindowChanged(switches[2] != 0); @@ -371,25 +360,6 @@ public abstract class BaseStatusBar extends SystemUI implements updateRelatedUserCache(); } - private void startKeyguardService() { - Intent intent = new Intent(mContext, KeyguardService.class); - intent.setAction(KeyguardService.ACTION_STATUS_BAR_BIND); - if (!mContext.bindService(intent, new ServiceConnection() { - @Override - public void onServiceConnected(ComponentName name, IBinder service) { - mKeyguardService = (KeyguardStatusBarBinder) service; - mKeyguardService.register(mCommandQueue); - } - - @Override - public void onServiceDisconnected(ComponentName name) { - mKeyguardService = null; - } - }, Context.BIND_AUTO_CREATE)) { - throw new RuntimeException("Couldn't bind status bar keyguard."); - } - } - public void userSwitched(int newUserId) { // should be overridden } @@ -1363,7 +1333,7 @@ public abstract class BaseStatusBar extends SystemUI implements boolean interrupt = (isFullscreen || (isHighPriority && (isNoisy || hasTicker))) && isAllowed && mPowerManager.isScreenOn() - && !keyguard.isShowingAndNotHidden() + && !keyguard.isShowingAndNotOccluded() && !keyguard.isInputRestricted(); try { interrupt = interrupt && !mDreamManager.isDreaming(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java index cf6f60c..bbbe8fa 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java @@ -57,7 +57,6 @@ public class CommandQueue extends IStatusBar.Stub { private static final int MSG_PRELOAD_RECENT_APPS = 14 << MSG_SHIFT; private static final int MSG_CANCEL_PRELOAD_RECENT_APPS = 15 << MSG_SHIFT; private static final int MSG_SET_WINDOW_STATE = 16 << MSG_SHIFT; - private static final int MSG_SET_KEYGUARD_SHOWN = 17 << MSG_SHIFT; public static final int FLAG_EXCLUDE_NONE = 0; public static final int FLAG_EXCLUDE_SEARCH_PANEL = 1 << 0; @@ -100,8 +99,7 @@ public class CommandQueue extends IStatusBar.Stub { public void hideSearchPanel(); public void cancelPreloadRecentApps(); public void setWindowState(int window, int state); - public void setKeyguardShown(boolean showKeyguard, IKeyguardShowCallback callback, - boolean updateWindowFlags); + } public CommandQueue(Callbacks callbacks, StatusBarIconList list) { @@ -236,14 +234,6 @@ public class CommandQueue extends IStatusBar.Stub { } } - public void setKeyguardShown(boolean showKeyguard, IKeyguardShowCallback callback, - boolean updateWindowFlags) { - synchronized (mList) { - mHandler.removeMessages(MSG_SET_KEYGUARD_SHOWN); - mHandler.obtainMessage(MSG_SET_KEYGUARD_SHOWN, - showKeyguard ? 1 : 0, updateWindowFlags ? 1 : 0, callback).sendToTarget(); - } - } private final class H extends Handler { public void handleMessage(Message msg) { @@ -325,10 +315,7 @@ public class CommandQueue extends IStatusBar.Stub { case MSG_SET_WINDOW_STATE: mCallbacks.setWindowState(msg.arg1, msg.arg2); break; - case MSG_SET_KEYGUARD_SHOWN: - mCallbacks.setKeyguardShown(msg.arg1 != 0, (IKeyguardShowCallback) msg.obj, - msg.arg2 != 0); - break; + } } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardTouchDelegate.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardTouchDelegate.java index 1ea920d..68eaf51 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardTouchDelegate.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardTouchDelegate.java @@ -140,16 +140,16 @@ public class KeyguardTouchDelegate { return false; } - public boolean isShowingAndNotHidden() { + public boolean isShowingAndNotOccluded() { final IKeyguardService service = mService; if (service != null) { try { - return service.isShowingAndNotHidden(); + return service.isShowingAndNotOccluded(); } catch (RemoteException e) { Slog.w(TAG , "Remote Exception", e); } } else { - Slog.w(TAG, "isShowingAndNotHidden(): NO SERVICE!"); + Slog.w(TAG, "isShowingAndNotOccluded(): NO SERVICE!"); } return false; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index 44f5e3a..bdcf83c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -35,9 +35,11 @@ import android.app.Notification; import android.app.PendingIntent; import android.app.StatusBarManager; import android.content.BroadcastReceiver; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.ServiceConnection; import android.content.res.Configuration; import android.content.res.Resources; import android.database.ContentObserver; @@ -93,6 +95,8 @@ import com.android.systemui.DemoMode; import com.android.systemui.EventLogTags; import com.android.systemui.R; import com.android.systemui.SwipeHelper; +import com.android.systemui.keyguard.KeyguardService; +import com.android.systemui.keyguard.KeyguardStatusBarBinder; import com.android.systemui.statusbar.BaseStatusBar; import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.statusbar.GestureRecorder; @@ -183,6 +187,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { StatusBarWindowView mStatusBarWindow; PhoneStatusBarView mStatusBarView; private int mStatusBarWindowState = WINDOW_STATE_SHOWING; + private StatusBarWindowManager mStatusBarWindowManager; int mPixelFormat; Object mQueueLock = new Object(); @@ -274,6 +279,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { DisplayMetrics mDisplayMetrics = new DisplayMetrics(); + protected KeyguardStatusBarBinder mKeyguardService; // XXX: gesture research private final GestureRecorder mGestureRec = DEBUG_GESTURES ? new GestureRecorder("/sdcard/statusbar_gestures.dat") @@ -356,12 +362,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { } }}; - private boolean mKeyguardShowing; - - private ViewGroup mKeyguard; - - private Button mDismissKeyguard; - @Override public void setZenMode(int mode) { super.setZenMode(mode); @@ -393,6 +393,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { Settings.Global.getUriFor(SETTING_HEADS_UP_TICKER), true, mHeadsUpObserver); } + startKeyguard(); } // ================================================================================ @@ -443,7 +444,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { } }); - mKeyguard = (ViewGroup) mStatusBarWindow.findViewById(R.id.keyguard); if (!ActivityManager.isHighEndGfx()) { mStatusBarWindow.setBackground(null); mNotificationPanel.setBackground(new FastColorDrawable(context.getResources().getColor( @@ -712,6 +712,29 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { return mStatusBarView; } + private void startKeyguard() { + + // Create the connection to KeyguardService. + Intent intent = new Intent(mContext, KeyguardService.class); + intent.setAction(KeyguardService.ACTION_STATUS_BAR_BIND); + if (!mContext.bindService(intent, new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName name, IBinder service) { + mKeyguardService = (KeyguardStatusBarBinder) service; + mKeyguardService.registerStatusBar(PhoneStatusBar.this, mStatusBarWindow, + mStatusBarWindowManager); + } + + @Override + public void onServiceDisconnected(ComponentName name) { + if (DEBUG) Log.v(TAG, "Keyguard disconnected."); + mKeyguardService = null; + } + }, Context.BIND_AUTO_CREATE)) { + throw new RuntimeException("Couldn't bind status bar keyguard."); + } + } + @Override protected void onShowSearchPanel() { if (mNavigationBarView != null) { @@ -789,10 +812,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { } } - protected int getStatusBarGravity() { - return Gravity.TOP | Gravity.FILL_HORIZONTAL; - } - public int getStatusBarHeight() { if (mNaturalBarHeight < 0) { final Resources res = mContext.getResources(); @@ -1508,30 +1527,13 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { // Expand the window to encompass the full screen in anticipation of the drag. // This is only possible to do atomically because the status bar is at the top of the screen! - expandWindow(); + mStatusBarWindowManager.setStatusBarExpanded(true); visibilityChanged(true); setInteracting(StatusBarManager.WINDOW_STATUS_BAR, true); } - private void expandWindow() { - WindowManager.LayoutParams lp = (WindowManager.LayoutParams) mStatusBarWindow.getLayoutParams(); - lp.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; - lp.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; - lp.height = ViewGroup.LayoutParams.MATCH_PARENT; - mWindowManager.updateViewLayout(mStatusBarWindow, lp); - } - - private void releaseFocus() { - if (mStatusBarWindow == null) return; - WindowManager.LayoutParams lp = - (WindowManager.LayoutParams) mStatusBarWindow.getLayoutParams(); - lp.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; - lp.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; - mWindowManager.updateViewLayout(mStatusBarWindow, lp); - } - public void animateCollapsePanels() { animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE); } @@ -1544,7 +1546,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { } // release focus immediately to kick off focus change transition - releaseFocus(); + mStatusBarWindowManager.setStatusBarFocusable(false); if ((flags & CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL) == 0) { mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL); @@ -1556,7 +1558,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { mHandler.sendEmptyMessage(MSG_CLOSE_SEARCH_PANEL); } - if (mStatusBarWindow != null && !mKeyguardShowing) { + if (mStatusBarWindow != null) { mStatusBarWindow.cancelExpandHelper(); mStatusBarView.collapseAllPanels(true); } @@ -1768,7 +1770,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { if (SPEW) Log.d(TAG, "makeExpandedInvisible: mExpandedVisible=" + mExpandedVisible + " mExpandedVisible=" + mExpandedVisible); - if (!mExpandedVisible || mStatusBarWindow == null || mKeyguardShowing) { + if (!mExpandedVisible || mStatusBarWindow == null) { return; } @@ -1802,7 +1804,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { visibilityChanged(false); // Shrink the window to the size of the status bar only - contractWindow(); + mStatusBarWindowManager.setStatusBarExpanded(false); if ((mDisabled & StatusBarManager.DISABLE_NOTIFICATION_ICONS) == 0) { setNotificationIconVisibility(true, com.android.internal.R.anim.fade_in); @@ -1819,15 +1821,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false); } - private void contractWindow() { - WindowManager.LayoutParams lp = - (WindowManager.LayoutParams) mStatusBarWindow.getLayoutParams(); - lp.height = getStatusBarHeight(); - lp.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; - lp.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; - mWindowManager.updateViewLayout(mStatusBarWindow, lp); - } - /** * Enables or disables layers on the children of the notifications pile. * @@ -1936,7 +1929,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { && mStatusBarWindowState != state) { mStatusBarWindowState = state; if (DEBUG_WINDOW_STATE) Log.d(TAG, "Status bar " + windowStateToString(state)); - if (!showing && !mKeyguardShowing) { + if (!showing) { mStatusBarView.collapseAllPanels(false); } } @@ -2361,29 +2354,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { } private void addStatusBarWindow() { - // Put up the view - final int height = getStatusBarHeight(); - - // Now that the status bar window encompasses the sliding panel and its - // translucent backdrop, the entire thing is made TRANSLUCENT and is - // hardware-accelerated. - final WindowManager.LayoutParams lp = new WindowManager.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - height, - WindowManager.LayoutParams.TYPE_STATUS_BAR, - WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE - | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING - | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH - | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, - PixelFormat.TRANSLUCENT); - - lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; - lp.gravity = getStatusBarGravity(); - lp.setTitle("StatusBar"); - lp.packageName = mContext.getPackageName(); - makeStatusBarView(); - mWindowManager.addView(mStatusBarWindow, lp); + mStatusBarWindowManager = new StatusBarWindowManager(mContext); + mStatusBarWindowManager.add(mStatusBarWindow, getStatusBarHeight()); } void setNotificationIconVisibility(boolean visible, int anim) { @@ -2692,67 +2665,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { } } - @Override - public void setKeyguardShown(boolean showKeyguard, final IKeyguardShowCallback callback, - boolean updateWindowFlags) { - mKeyguardShowing = showKeyguard; - if (updateWindowFlags) { - WindowManager.LayoutParams lp = - (WindowManager.LayoutParams) mStatusBarWindow.getLayoutParams(); - if (showKeyguard) { - lp.flags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; - lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; - } else { - lp.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; - lp.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; - } - mWindowManager.updateViewLayout(mStatusBarWindow, lp); - } - if (!showKeyguard) { - mKeyguard.setVisibility(View.GONE); - mKeyguard.removeAllViews(); - contractWindow(); - } else { - expandWindow(); - mKeyguard.setVisibility(View.VISIBLE); - KeyguardSimpleHostView view = (KeyguardSimpleHostView) LayoutInflater.from(mContext) - .inflate(R.layout.keyguard_simple_host_view, mKeyguard, false); - mKeyguard.addView(view); - view.setOnDismissAction(new KeyguardHostView.OnDismissAction() { - @Override - public boolean onDismiss() { - contractWindow(); - if (mKeyguardService != null) { - mKeyguardService.dismissKeyguard(); - } - return false; - } - }); - view.show(); - } - if (callback != null) { - mStatusBarView.getViewTreeObserver().addOnPreDrawListener( - new ViewTreeObserver.OnPreDrawListener() { - @Override - public boolean onPreDraw() { - mStatusBarView.getViewTreeObserver().removeOnPreDrawListener(this); - mStatusBarView.post(new Runnable() { - @Override - public void run() { - try { - callback.onShown(mStatusBarWindow.getWindowToken()); - } catch (RemoteException e) { - Log.e(TAG, "Could not call show callback", e); - } - } - }); - return true; - } - }); - } - - } - /** * Reload some of our resources when the configuration changes. * diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java new file mode 100644 index 0000000..74549ae --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java @@ -0,0 +1,227 @@ +/* + * Copyright (C) 2014 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.systemui.statusbar.phone; + +import android.content.Context; +import android.os.Bundle; +import android.os.IBinder; +import android.os.RemoteException; +import android.util.Log; +import android.util.Slog; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewTreeObserver; + +import com.android.internal.policy.IKeyguardShowCallback; +import com.android.internal.widget.LockPatternUtils; +import com.android.keyguard.KeyguardSimpleHostView; +import com.android.keyguard.R; +import com.android.keyguard.ViewMediatorCallback; +import com.android.systemui.keyguard.KeyguardViewMediator; + +/** + * Manages creating, showing, hiding and resetting the keyguard within the status bar. Calls back + * via {@link ViewMediatorCallback} to poke the wake lock and report that the keyguard is done, + * which is in turn, reported to this class by the current + * {@link com.android.keyguard.KeyguardViewBase}. + */ +public class StatusBarKeyguardViewManager { + private static String TAG = "StatusBarKeyguardViewManager"; + + private final Context mContext; + + private LockPatternUtils mLockPatternUtils; + private ViewMediatorCallback mViewMediatorCallback; + private PhoneStatusBar mPhoneStatusBar; + + private KeyguardSimpleHostView mKeyguardView; + private ViewGroup mRoot; + private ViewGroup mContainer; + private StatusBarWindowManager mStatusBarWindowManager; + + private boolean mScreenOn = false; + private boolean mShowOnRegister; + + public StatusBarKeyguardViewManager(Context context, ViewMediatorCallback callback, + LockPatternUtils lockPatternUtils) { + mContext = context; + mViewMediatorCallback = callback; + mLockPatternUtils = lockPatternUtils; + + } + + public void registerStatusBar(PhoneStatusBar phoneStatusBar, + ViewGroup container, StatusBarWindowManager statusBarWindowManager) { + mPhoneStatusBar = phoneStatusBar; + mContainer = container; + mStatusBarWindowManager = statusBarWindowManager; + if (mShowOnRegister) { + mShowOnRegister = false; + show(null); + if (mScreenOn) { + onScreenTurnedOn(null); + } + } + } + + /** + * Show the keyguard. Will handle creating and attaching to the view manager + * lazily. + */ + public void show(Bundle options) { + if (mStatusBarWindowManager != null) { + ensureView(); + mStatusBarWindowManager.setKeyguardShowing(true); + mKeyguardView.requestFocus(); + } else { + mShowOnRegister = true; + } + } + + private void ensureView() { + if (mRoot == null) { + inflateView(); + } + } + + private void inflateView() { + removeView(); + mRoot = (ViewGroup) LayoutInflater.from(mContext).inflate(R.layout.keyguard_bouncer, null); + mKeyguardView = (KeyguardSimpleHostView) mRoot.findViewById(R.id.keyguard_host_view); + mKeyguardView.setLockPatternUtils(mLockPatternUtils); + mKeyguardView.setViewMediatorCallback(mViewMediatorCallback); + mContainer.addView(mRoot, mContainer.getChildCount()); + mRoot.setSystemUiVisibility(View.STATUS_BAR_DISABLE_HOME); + } + + private void removeView() { + if (mRoot != null && mRoot.getParent() == mContainer) { + mContainer.removeView(mRoot); + mRoot = null; + } + } + + /** + * Reset the state of the view. + */ + public void reset() { + inflateView(); + } + + public void onScreenTurnedOff() { + mScreenOn = false; + if (mKeyguardView != null) { + mKeyguardView.onScreenTurnedOff(); + } + } + + public void onScreenTurnedOn(final IKeyguardShowCallback callback) { + mScreenOn = true; + if (mKeyguardView != null) { + mKeyguardView.onScreenTurnedOn(); + if (callback != null) { + callbackAfterDraw(callback); + } + } else { + try { + if (callback != null) { + callback.onShown(null); + } + } catch (RemoteException e) { + Slog.w(TAG, "Exception calling onShown():", e); + } + } + } + + private void callbackAfterDraw(final IKeyguardShowCallback callback) { + mKeyguardView.post(new Runnable() { + @Override + public void run() { + try { + callback.onShown(mKeyguardView.getWindowToken()); + } catch (RemoteException e) { + Slog.w(TAG, "Exception calling onShown():", e); + } + } + }); + } + + public void verifyUnlock() { + show(null); + mKeyguardView.verifyUnlock(); + } + + public void setNeedsInput(boolean needsInput) { + if (mStatusBarWindowManager != null) { + mStatusBarWindowManager.setKeyguardNeedsInput(needsInput); + } + } + + public void updateUserActivityTimeout() { + + // Use the user activity timeout requested by the keyguard view, if any. + if (mKeyguardView != null) { + long timeout = mKeyguardView.getUserActivityTimeout(); + if (timeout >= 0) { + mStatusBarWindowManager.setKeyguardUserActivityTimeout(timeout); + return; + } + } + + // Otherwise, use the default timeout. + mStatusBarWindowManager.setKeyguardUserActivityTimeout( + KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS); + } + + public void setOccluded(boolean occluded) { + if (mStatusBarWindowManager != null) { + mStatusBarWindowManager.setKeyguardOccluded(occluded); + } + } + + /** + * Hides the keyguard view + */ + public void hide() { + if (mPhoneStatusBar != null) { + mStatusBarWindowManager.setKeyguardShowing(false); + if (mKeyguardView != null) { + mKeyguardView.cleanUp(); + mViewMediatorCallback.keyguardGone(); + } + removeView(); + } + mShowOnRegister = false; + } + + /** + * Dismisses the keyguard by going to the next screen or making it gone. + */ + public void dismiss() { + if (mScreenOn) { + mKeyguardView.dismiss(); + } + } + + /** + * @return Whether the keyguard is showing + */ + public boolean isShowing() { + return mRoot != null && mRoot.getVisibility() == View.VISIBLE; + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java new file mode 100644 index 0000000..e418ac5 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java @@ -0,0 +1,192 @@ +/* + * Copyright (C) 2014 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.systemui.statusbar.phone; + +import android.app.ActionBar; +import android.content.Context; +import android.content.pm.ActivityInfo; +import android.content.res.Resources; +import android.graphics.PixelFormat; +import android.os.SystemProperties; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.view.WindowManager; + +import com.android.keyguard.R; + +/** + * Encapsulates all logic for the status bar window state management. + */ +public class StatusBarWindowManager { + + private final Context mContext; + private final WindowManager mWindowManager; + private View mStatusBarView; + private WindowManager.LayoutParams mLp; + private int mBarHeight; + private final boolean mKeyguardScreenRotation; + + private final State mCurrentState = new State(); + + public StatusBarWindowManager(Context context) { + mContext = context; + mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); + mKeyguardScreenRotation = shouldEnableKeyguardScreenRotation(); + } + + private boolean shouldEnableKeyguardScreenRotation() { + Resources res = mContext.getResources(); + return SystemProperties.getBoolean("lockscreen.rot_override", false) + || res.getBoolean(R.bool.config_enableLockScreenRotation); + } + + /** + * Adds the status bar view to the window manager. + * + * @param statusBarView The view to add. + * @param barHeight The height of the status bar in collapsed state. + */ + public void add(View statusBarView, int barHeight) { + + // Now that the status bar window encompasses the sliding panel and its + // translucent backdrop, the entire thing is made TRANSLUCENT and is + // hardware-accelerated. + mLp = new WindowManager.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + barHeight, + WindowManager.LayoutParams.TYPE_STATUS_BAR, + WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE + | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING + | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH + | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH + | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION + | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, + PixelFormat.TRANSLUCENT); + + mLp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; + mLp.gravity = Gravity.TOP | Gravity.FILL_HORIZONTAL; + mLp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; + mLp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY; + mLp.setTitle("StatusBar"); + mLp.packageName = mContext.getPackageName(); + mStatusBarView = statusBarView; + mBarHeight = barHeight; + mWindowManager.addView(mStatusBarView, mLp); + } + + private void applyKeyguardFlags(State state) { + if (state.keyguardShowing) { + mLp.flags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; + mLp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; + } else { + mLp.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; + mLp.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; + } + } + + private void adjustScreenOrientation(State state) { + if (!state.isKeyguardShowingAndNotOccluded() || mKeyguardScreenRotation) { + mLp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER; + } else { + mLp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; + } + } + + private void applyFocusableFlag(State state) { + if (state.isKeyguardShowingAndNotOccluded() && state.keyguardNeedsInput) { + mLp.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; + mLp.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; + } else if (state.isKeyguardShowingAndNotOccluded() || state.statusBarFocusable) { + mLp.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; + mLp.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; + } else { + mLp.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; + mLp.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; + } + } + + private void applyHeight(State state) { + boolean expanded = state.isKeyguardShowingAndNotOccluded() || state.statusBarExpanded; + if (expanded) { + mLp.height = ViewGroup.LayoutParams.MATCH_PARENT; + } else { + mLp.height = mBarHeight; + } + } + + private void applyUserActivityTimeout(State state) { + if (state.isKeyguardShowingAndNotOccluded()) { + mLp.userActivityTimeout = state.keyguardUserActivityTimeout; + } else { + mLp.userActivityTimeout = -1; + } + } + + private void apply(State state) { + applyKeyguardFlags(state); + applyFocusableFlag(state); + adjustScreenOrientation(state); + applyHeight(state); + applyUserActivityTimeout(state); + mWindowManager.updateViewLayout(mStatusBarView, mLp); + } + + public void setKeyguardShowing(boolean showing) { + mCurrentState.keyguardShowing = showing; + apply(mCurrentState); + } + + public void setKeyguardOccluded(boolean occluded) { + mCurrentState.keyguardOccluded = occluded; + apply(mCurrentState); + } + + public void setKeyguardNeedsInput(boolean needsInput) { + mCurrentState.keyguardNeedsInput = needsInput; + apply(mCurrentState); + } + + public void setStatusBarExpanded(boolean expanded) { + mCurrentState.statusBarExpanded = expanded; + mCurrentState.statusBarFocusable = expanded; + apply(mCurrentState); + } + + public void setStatusBarFocusable(boolean focusable) { + mCurrentState.statusBarFocusable = focusable; + apply(mCurrentState); + } + + public void setKeyguardUserActivityTimeout(long timeout) { + mCurrentState.keyguardUserActivityTimeout = timeout; + apply(mCurrentState); + } + + private static class State { + boolean keyguardShowing; + boolean keyguardOccluded; + boolean keyguardNeedsInput; + boolean statusBarExpanded; + boolean statusBarFocusable; + long keyguardUserActivityTimeout; + + private boolean isKeyguardShowingAndNotOccluded() { + return keyguardShowing && !keyguardOccluded; + } + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java index 2dc3373..a57a7b5 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java @@ -94,15 +94,6 @@ public class TvStatusBar extends BaseStatusBar { } @Override - public void setKeyguardShown(boolean showKeyguard, IKeyguardShowCallback callback, - boolean updateKeyguardFlags) { - } - - @Override - protected void createAndAddWindows() { - } - - @Override protected WindowManager.LayoutParams getSearchLayoutParams( LayoutParams layoutParams) { return null; @@ -151,6 +142,10 @@ public class TvStatusBar extends BaseStatusBar { } @Override + protected void createAndAddWindows() { + } + + @Override protected void refreshLayout(int layoutDirection) { } |