解决低电量自动关机时如果有来电自动关断电话

来源:互联网 发布:日本美工刀片 编辑:程序博客网 时间:2024/06/02 14:16

1.问题描述:

    低电量时,由于系统已经无法继续提供通话服务,为了不影响通话服务质量或其它问题,因此在自动关机时应自动挂断电话

2.解决思路:

    在低电量自动关机时,如果此时有来电,调用挂断电话的接口,挂断电话。

3.实现方式:

    BatteryService.java

    private void shutdownIfNoPowerLocked() {
        // shut down gracefully if our battery is critically low and we are not powered.
        // wait until the system has booted before attempting to display the shutdown dialog.
        if (mBatteryProps.batteryLevel == 0 && !isPoweredLocked(BatteryManager.BATTERY_PLUGGED_ANY)) {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    if (ActivityManagerNative.isSystemReady()) {
                        if (FeatureOption.MTK_IPO_SUPPORT == true) {
                            SystemProperties.set("sys.ipo.battlow","1");
                        }


                        try {
                            ITelephony iTelephony = ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE));
                            if (iTelephony != null) {
                                iTelephony.endCall();
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }


                        Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
                        intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        mContext.startActivityAsUser(intent, UserHandle.CURRENT);
                    }
                }
            });
        }
    }

注!红色部分为功能实现部分。

10 0
原创粉丝点击