记录了系统锁屏控制的代码片段, 可以从比较高的层次进行锁屏控制。

各种上层接口会调用到KeyguardViewMediator::doKeyguardLocked()进行锁屏。Mediator设计模式?

In doKeyguardLocked()@KeyguardViewMediator.java
It can be seen that if system reboots abnormally, and nothing disable the screen lock, and sim card sits there, the first lock screen will be ignored.

650    private void KeyguardViewMediator::doKeyguardLocked() {651        // if another app is disabling us, don't show652        if (!mExternallyEnabled) {653            if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled");654655            // note: we *should* set mNeedToReshowWhenReenabled=true here, but that makes656            // for an occasional ugly flicker in this situation:657            // 1) receive a call with the screen on (no keyguard) or make a call658            // 2) screen times out659            // 3) user hits key to turn screen back on660            // instead, we reenable the keyguard when we know the screen is off and the call661            // ends (see the broadcast receiver below)662            // TODO: clean this up when we have better support at the window manager level663            // for apps that wish to be on top of the keyguard664            return;665        }666667        // if the keyguard is already showing, don't bother668        if (mKeyguardViewManager.isShowing()) {669            if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing");670            return;671        }672673        // if the setup wizard hasn't run yet, don't show674        final boolean provisioned = mUpdateMonitor.isDeviceProvisioned();675        final IccCard.State[] state;676        int numPhones = TelephonyManager.getDefault().getPhoneCount();677        state = new IccCard.State[numPhones];678        boolean lockedOrMissing = false;679        boolean isPinLockedFlag = false;680        for (int i = 0; i < numPhones; i++) {681            state[i] = mUpdateMonitor.getSimState(i);682            lockedOrMissing = lockedOrMissing || isLockedOrMissing(state[i]);683            isPinLockedFlag = isPinLockedFlag || isPinLockedFun(state[i]);684            if (lockedOrMissing) break;685        }686687        if (!lockedOrMissing && !provisioned) {688            if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned"689                    + " and the sim is not locked or missing");690            return;691        }692693        if (mLockPatternUtils.isLockScreenDisabled() && !lockedOrMissing) {694            if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off");695            return;696        }697698699        mySingleton obj = mySingleton.getInstance();700        if (obj.isAbnormalBootup()) {701            if(obj.getAbnormal()==0)// avoid 1st abnormal screenLock702             {703                  obj.addAbnormal();// set to true704                  Log.d(TAG, "KeyGuardViewMediator.java doKeyguardLocked() obj.getAbnormal()="+obj.getAbnormal());705                  return ;706             }707708            // abnormal reboot and PIN_REQUIRED will not show Locked screen , if pin pass , isPinLockedFlag turn false , will unlock this "if()"709             if(isPinLockedFlag && obj.getAbnormal()==1){710                 obj.addAbnormal();// set to true711                  Log.d(TAG, "KeyGuardViewMediator.java doKeyguardLocked() obj.getAbnormal()="+obj.getAbnormal());712                 return;713              }714             Log.d(TAG, "Showing the lock screen");715      }716717718        if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen");719        showLocked();720    }

calls ==>

798    /**799     * Send message to keyguard telling it to show itself800     * @see #handleShow()801     */802    private void showLocked() {803        if (DEBUG) Log.d(TAG, "showLocked");804        // ensure we stay awake until we are finished displaying the keyguard805        mShowKeyguardWakeLock.acquire();806        Message msg = mHandler.obtainMessage(SHOW);807        mHandler.sendMessage(msg);808    }

message handler |=>

1104    /**1105     * This handler will be associated with the policy thread, which will also1106     * be the UI thread of the keyguard.  Since the apis of the policy, and therefore1107     * this class, can be called by other threads, any action that directly1108     * interacts with the keyguard ui should be posted to this handler, rather1109     * than called directly.1110     */1111    private Handler mHandler = new Handler() {1112        @Override1113        public void handleMessage(Message msg) {1114            switch (msg.what) {1115                case TIMEOUT:1116                    handleTimeout(msg.arg1);1117                    return ;1118                case SHOW:1119                    handleShow();1120                    return ;1121                case HIDE:1122                    handleHide();1123                    return ;1124                case RESET:1125                    handleReset();1126                    return ;1127                case VERIFY_UNLOCK:1128                    handleVerifyUnlock();1129                    return;1130                case NOTIFY_SCREEN_OFF:1131                    handleNotifyScreenOff();1132                    return;1133                case NOTIFY_SCREEN_ON:1134                    handleNotifyScreenOn((KeyguardViewManager.ShowListener)msg.obj);1135                    return;1136                case WAKE_WHEN_READY:1137                    handleWakeWhenReady(msg.arg1);1138                    return;1139                case KEYGUARD_DONE:1140                1141                    ScreenStatusNotification(KEYGUARD_DONE);1142                    1143                    handleKeyguardDone(msg.arg1 != 0);1144                    return;1145                case KEYGUARD_DONE_DRAWING:1146                    handleKeyguardDoneDrawing();1147                    return;1148                case KEYGUARD_DONE_AUTHENTICATING:1149                    keyguardDone(true);1150                    return;1151                case SET_HIDDEN:1152                    handleSetHidden(msg.arg1 != 0);1153                    break;1154                case KEYGUARD_TIMEOUT:1155                    synchronized (KeyguardViewMediator.this) {1156                        doKeyguardLocked();1157                    }1158                    break;1159            }1160        }1161    };

calls ==>

1248    /**1249     * Handle message sent by {@link #showLocked}.1250     * @see #SHOW1251     */1252    private void handleShow() {1253        synchronized (KeyguardViewMediator.this) {1254            if (DEBUG) Log.d(TAG, "handleShow");1255            if (!mSystemReady) return;12561257            mKeyguardViewManager.show();1258            mShowing = true;1259            updateActivityLockScreenState();1260            adjustUserActivityLocked();1261            adjustStatusBarLocked();1262            try {1263                ActivityManagerNative.getDefault().closeSystemDialogs("lock");1264            } catch (RemoteException e) {1265            }12661267            // Do this at the end to not slow down display of the keyguard.1268            playSounds(true);12691270            mShowKeyguardWakeLock.release();1271        }1272    }

calls==>

KeyguardViewManager::show() to show lock screen.

END


更多相关文章

  1. Android——Activity之间传递 实体类(Bean)
  2. android 获取程序的安装时间
  3. Android(安卓)微信分享,分享到朋友圈与分享到好友,以及微信登陆
  4. Android(安卓)的网络编程(4)-HttpClient接口
  5. GPS 研究(Android2.3)
  6. MTK平台camera bsp学习之camera HW架构篇
  7. Android控件笔记——使用RadioGroup和RadioButton实现单选效果
  8. Android(安卓)客户端Socket 实现及简单封装。
  9. Android有用代码片段(零)

随机推荐

  1. 掌握PHP语言对接抖音快手小红书视频/图片
  2. PHP+MySql实现简单的留言板功能
  3. 阿里云PHP SMS短信服务验证码发送方法详
  4. 直击php中static,const与define的使用区
  5. 详解php版阿里云OSS图片上传类
  6. 全栈工程师看过来!PHP Javascript语法对照
  7. php array_combine()函数实例详解
  8. 示例php+mysql查询实现无限下级分类树输
  9. 一起看看PHP执行普通shell命令流程
  10. 实现PHP+Mysql无限分类的方法