Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dffdc502 authored by haiyangl's avatar haiyangl Committed by kaiyiz
Browse files

Keyguard: Disable "Emergency call" button in OOS state

For CTA LAB new requirement, there should be no "Emergency call" on
lock screen in OOS state.

Do not show emergency button when service state is STATE_OUT_OF_SERVICE
and isEmergencyOnly is false since it can't make emergency call.

Change-Id: Ieb0e130c24469aaae181cfdce9d62739e285362d
CRs-Fixed: 669191
parent 1d149af0
Loading
Loading
Loading
Loading
+28 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.content.Intent;
import android.os.PowerManager;
import android.os.SystemClock;
import android.os.UserHandle;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.util.AttributeSet;
import android.view.View;
@@ -32,6 +33,10 @@ import android.widget.Button;
import com.android.internal.telephony.IccCardConstants.State;
import com.android.internal.widget.LockPatternUtils;

import java.util.HashMap;
import java.util.Iterator;


/**
 * This class implements a smart emergency button that updates itself based
 * on telephony state.  When the phone is idle, it is an emergency call button.
@@ -42,6 +47,7 @@ public class EmergencyButton extends Button {

    private static final int EMERGENCY_CALL_TIMEOUT = 10000; // screen timeout after starting e.d.
    private static final String ACTION_EMERGENCY_DIAL = "com.android.phone.EmergencyDialer.DIAL";
    private HashMap<Long, ServiceState> mServiceState = new HashMap<Long, ServiceState>();

    KeyguardUpdateMonitorCallback mInfoCallback = new KeyguardUpdateMonitorCallback() {

@@ -55,6 +61,12 @@ public class EmergencyButton extends Button {
        public void onPhoneStateChanged(int phoneState) {
            updateEmergencyCallButton(phoneState);
        }

        void onServiceStateChanged(ServiceState state, long sub) {
            mServiceState.put(sub, state);
            int phoneState = KeyguardUpdateMonitor.getInstance(mContext).getPhoneState();
            updateEmergencyCallButton(phoneState);
        }
    };
    private LockPatternUtils mLockPatternUtils;
    private PowerManager mPowerManager;
@@ -90,9 +102,23 @@ public class EmergencyButton extends Button {
            }
        });
        int phoneState = KeyguardUpdateMonitor.getInstance(mContext).getPhoneState();
        mServiceState = KeyguardUpdateMonitor.getInstance(mContext).getServiceStates();
        updateEmergencyCallButton(phoneState);
    }

    private boolean canMakeEmergencyCall() {
        Iterator iter = mServiceState.entrySet().iterator();
        while (iter.hasNext()) {
            HashMap.Entry entry = (HashMap.Entry) iter.next();
            ServiceState state = (ServiceState) entry.getValue();
            if ((state != null) && (state.isEmergencyOnly() ||
                    state.getVoiceRegState() != ServiceState.STATE_OUT_OF_SERVICE)) {
                return true;
            }
        }
        return false;
    }

    /**
     * Shows the emergency dialer or returns the user to the existing call.
     */
@@ -129,8 +155,8 @@ public class EmergencyButton extends Button {
                        mContext.getResources().getBoolean(R.bool.config_showEmergencyButton);
            }
        }
        if (getContext().getResources().getBoolean(R.bool.icccardexist_hide_emergencybutton)) {
            enabled = false;
        if (mContext.getResources().getBoolean(R.bool.config_showEmergencyButton)) {
            enabled = enabled && canMakeEmergencyCall();
        }
        mLockPatternUtils.updateEmergencyCallButtonState(this, enabled, false);
    }
+21 −0
Original line number Diff line number Diff line
@@ -248,6 +248,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
                case MSG_SUBINFO_CONTENT_CHANGE:
                    handleSubInfoContentChange((SubInfoContent) msg.obj);
                    break;
                case MSG_SERVICE_STATE_CHANGED:
                    handleServiceStateChanged((ServiceState) msg.obj, (long) msg.arg1);
                    break;
            }
        }
    };
@@ -461,6 +464,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
                        mShowSpn.get(subId) + " showPlmn:" + mShowPlmn.get(subId) +
                        " mServiceState: " + mServiceState.get(subId));
                mHandler.sendMessage(mHandler.obtainMessage(MSG_CARRIER_INFO_UPDATE, subId));

                final Message message = mHandler.obtainMessage(
                        MSG_SERVICE_STATE_CHANGED, mServiceState.get(subId));
                message.arg1 = (int) subId;
                mHandler.sendMessage(message);
            } else if (Intent.ACTION_LOCALE_CHANGED.equals(action)) {
                Log.d(TAG, "Received CONFIGURATION_CHANGED intent");
                for (int i = 0; i < mNumPhones; i++) {
@@ -1125,6 +1133,15 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
        }
    }

    private void handleServiceStateChanged(ServiceState state, long sub) {
        for (int i = 0; i < mCallbacks.size(); i++) {
            KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
            if (cb != null) {
                cb.onServiceStateChanged(state, sub);
            }
        }
    }

    /**
     * Handle {@link #MSG_CLOCK_VISIBILITY_CHANGED}
     */
@@ -1337,6 +1354,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
        return mSimState.get(subId);
    }

    public HashMap<Long, ServiceState> getServiceStates() {
        return mServiceState;
    }

    /**
     * Report that the user successfully entered the SIM PIN or PUK/SIM PIN so we
     * have the information earlier than waiting for the intent
+6 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.admin.DevicePolicyManager;
import android.graphics.Bitmap;
import android.media.AudioManager;
import android.os.SystemClock;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.view.WindowManagerPolicy;

@@ -134,6 +135,11 @@ public class KeyguardUpdateMonitorCallback {
     */
    public void onSimStateChanged(long subId, IccCardConstants.State simState) {}

    /**
     * Called when the sevice state changes.
     */
    void onServiceStateChanged(ServiceState state, long sub) { }

    /**
     * Called when a user is removed.
     */