zoukankan      html  css  js  c++  java
  • 解决低电量自动关机时如果有来电自动关断电话

    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);
                        }
                    }
                });
            }
        }

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

  • 相关阅读:
    JavaScript中的this相关
    Git进阶操作_1
    Git基本操作_5
    Git基本操作_4
    Git基本操作_3
    Git基本操作_2
    利用Python发送SMTP邮件
    Python JWT使用
    Python中的Asyncio 异步编程
    Python中的抽象类和接口类
  • 原文地址:https://www.cnblogs.com/bill-technology/p/4130812.html
Copyright © 2011-2022 走看看