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

Commit 3dac0226 authored by Amith Yamasani's avatar Amith Yamasani Committed by Android (Google) Code Review
Browse files

Merge "Show power menu on tablets." into jb-dev

parents 48c22c84 7ee994d7
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -23,9 +23,6 @@
    <!-- see comment in values/config.xml -->
    <dimen name="config_prefDialogWidth">440dp</dimen>

    <!-- see comment in values/config.xml -->
    <integer name="config_longPressOnPowerBehavior">2</integer>

    <!-- see comment in values/config.xml -->
    <integer name="config_longPressOnHomeBehavior">0</integer>

+0 −3
Original line number Diff line number Diff line
@@ -20,9 +20,6 @@
<!-- These resources are around just to allow their values to be customized
     for different hardware and product builds. -->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <!-- see comment in values/config.xml -->
    <integer name="config_longPressOnPowerBehavior">2</integer>

    <!-- Enable lockscreen rotation -->
    <bool name="config_enableLockScreenRotation">true</bool>

+3 −0
Original line number Diff line number Diff line
@@ -1303,6 +1303,9 @@
  <java-symbol type="string" name="global_actions_airplane_mode_off_status" />
  <java-symbol type="string" name="global_actions_airplane_mode_on_status" />
  <java-symbol type="string" name="global_actions_toggle_airplane_mode" />
  <java-symbol type="string" name="global_action_silent_mode_off_status" />
  <java-symbol type="string" name="global_action_silent_mode_on_status" />
  <java-symbol type="string" name="global_action_toggle_silent_mode" />
  <java-symbol type="string" name="invalidPuk" />
  <java-symbol type="string" name="keyguard_password_enter_pin_code" />
  <java-symbol type="string" name="keyguard_password_enter_puk_code" />
+90 −17
Original line number Diff line number Diff line
@@ -28,7 +28,9 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.UserInfo;
import android.database.ContentObserver;
import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
@@ -73,7 +75,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
    private ArrayList<Action> mItems;
    private AlertDialog mDialog;

    private SilentModeAction mSilentModeAction;
    private Action mSilentModeAction;
    private ToggleAction mAirplaneModeOn;

    private MyAdapter mAdapter;
@@ -82,6 +84,8 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
    private boolean mDeviceProvisioned = false;
    private ToggleAction.State mAirplaneState = ToggleAction.State.Off;
    private boolean mIsWaitingForEcmExit = false;
    private boolean mHasTelephony;
    private boolean mHasVibrator;

    private IWindowManager mIWindowManager;

@@ -104,6 +108,14 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
        TelephonyManager telephonyManager =
                (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
        ConnectivityManager cm = (ConnectivityManager)
                context.getSystemService(Context.CONNECTIVITY_SERVICE);
        mHasTelephony = cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
        mContext.getContentResolver().registerContentObserver(
                Settings.System.getUriFor(Settings.System.AIRPLANE_MODE_ON), true,
                mAirplaneModeObserver);
        Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
        mHasVibrator = vibrator != null && vibrator.hasVibrator();
    }

    /**
@@ -130,13 +142,18 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
        mDialog.show();
        mDialog.getWindow().getDecorView().setSystemUiVisibility(View.STATUS_BAR_DISABLE_EXPAND);
    }

    /**
     * Create the global actions dialog.
     * @return A new dialog.
     */
    private AlertDialog createDialog() {
        mSilentModeAction = new SilentModeAction(mContext, mAudioManager, mHandler);

        // Simple toggle style if there's no vibrator, otherwise use a tri-state
        if (!mHasVibrator) {
            mSilentModeAction = new SilentModeToggleAction();
        } else {
            mSilentModeAction = new SilentModeTriStateAction(mContext, mAudioManager, mHandler);
        }
        mAirplaneModeOn = new ToggleAction(
                R.drawable.ic_lock_airplane_mode,
                R.drawable.ic_lock_airplane_mode_off,
@@ -145,7 +162,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
                R.string.global_actions_airplane_mode_off_status) {

            void onToggle(boolean on) {
                if (Boolean.parseBoolean(
                if (mHasTelephony && Boolean.parseBoolean(
                        SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
                    mIsWaitingForEcmExit = true;
                    // Launch ECM exit dialog
@@ -160,6 +177,8 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac

            @Override
            protected void changeStateFromPress(boolean buttonOn) {
                if (!mHasTelephony) return;

                // In ECM mode airplane state cannot be changed
                if (!(Boolean.parseBoolean(
                        SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE)))) {
@@ -176,6 +195,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
                return false;
            }
        };
        onAirplaneModeChanged();

        mItems = new ArrayList<Action>();

@@ -247,6 +267,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
                mItems.add(switchToUser);
            }
        }

        mAdapter = new MyAdapter();

        final AlertDialog.Builder ab = new AlertDialog.Builder(mContext);
@@ -273,8 +294,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
    }

    private void prepareDialog() {
        final boolean silentModeOn =
                mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
        refreshSilentMode();
        mAirplaneModeOn.updateState(mAirplaneState);
        mAdapter.notifyDataSetChanged();
        if (mKeyguardShowing) {
@@ -288,6 +308,15 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
        }
    }

    private void refreshSilentMode() {
        if (!mHasVibrator) {
            final boolean silentModeOn =
                    mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
            ((ToggleAction)mSilentModeAction).updateState(
                    silentModeOn ? ToggleAction.State.On : ToggleAction.State.Off);
        }
    }

    /** {@inheritDoc} */
    public void onDismiss(DialogInterface dialog) {
        if (SHOW_SILENT_TOGGLE) {
@@ -297,7 +326,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac

    /** {@inheritDoc} */
    public void onClick(DialogInterface dialog, int which) {
        if (!(mAdapter.getItem(which) instanceof SilentModeAction)) {
        if (!(mAdapter.getItem(which) instanceof SilentModeTriStateAction)) {
            dialog.dismiss();
        }
        mAdapter.getItem(which).onPress();
@@ -495,12 +524,12 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
         */
        public ToggleAction(int enabledIconResId,
                int disabledIconResid,
                int essage,
                int message,
                int enabledStatusMessageResId,
                int disabledStatusMessageResId) {
            mEnabledIconResId = enabledIconResId;
            mDisabledIconResid = disabledIconResid;
            mMessageResId = essage;
            mMessageResId = message;
            mEnabledStatusMessageResId = enabledStatusMessageResId;
            mDisabledStatusMessageResId = disabledStatusMessageResId;
        }
@@ -583,21 +612,44 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
        }
    }

    private static class SilentModeAction implements Action, View.OnClickListener {
    private class SilentModeToggleAction extends ToggleAction {
        public SilentModeToggleAction() {
            super(R.drawable.ic_audio_vol_mute,
                    R.drawable.ic_audio_vol,
                    R.string.global_action_toggle_silent_mode,
                    R.string.global_action_silent_mode_on_status,
                    R.string.global_action_silent_mode_off_status);
        }

        void onToggle(boolean on) {
            if (on) {
                mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
            } else {
                mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            }
        }

        public boolean showDuringKeyguard() {
            return true;
        }

        public boolean showBeforeProvisioning() {
            return false;
        }
    }

    private static class SilentModeTriStateAction implements Action, View.OnClickListener {

        private final int[] ITEM_IDS = { R.id.option1, R.id.option2, R.id.option3 };

        private final AudioManager mAudioManager;
        private final Handler mHandler;
        private final boolean mHasVibrator;
        private final Context mContext;

        SilentModeAction(Context context, AudioManager audioManager, Handler handler) {
        SilentModeTriStateAction(Context context, AudioManager audioManager, Handler handler) {
            mAudioManager = audioManager;
            mHandler = handler;
            mContext = context;
            Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
            mHasVibrator = vibrator != null && vibrator.hasVibrator();
        }

        private int ringerModeToIndex(int ringerMode) {
@@ -621,9 +673,6 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
                // Set up click handler
                itemView.setTag(i);
                itemView.setOnClickListener(this);
                if (itemView.getId() == R.id.option2 && !mHasVibrator) {
                    itemView.setVisibility(View.GONE);
                }
            }
            return v;
        }
@@ -683,6 +732,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
    PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
        @Override
        public void onServiceStateChanged(ServiceState serviceState) {
            if (!mHasTelephony) return;
            final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
            mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off;
            mAirplaneModeOn.updateState(mAirplaneState);
@@ -699,6 +749,13 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
        }
    };

    private ContentObserver mAirplaneModeObserver = new ContentObserver(new Handler()) {
        @Override
        public void onChange(boolean selfChange) {
            onAirplaneModeChanged();
        }
    };

    private static final int MESSAGE_DISMISS = 0;
    private static final int MESSAGE_REFRESH = 1;
    private static final int MESSAGE_SHOW = 2;
@@ -713,6 +770,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
                }
                break;
            case MESSAGE_REFRESH:
                refreshSilentMode();
                mAdapter.notifyDataSetChanged();
                break;
            case MESSAGE_SHOW:
@@ -722,6 +780,18 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
        }
    };

    private void onAirplaneModeChanged() {
        // Let the service state callbacks handle the state.
        if (mHasTelephony) return;

        boolean airplaneModeOn = Settings.System.getInt(
                mContext.getContentResolver(),
                Settings.System.AIRPLANE_MODE_ON,
                0) == 1;
        mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
        mAirplaneModeOn.updateState(mAirplaneState);
    }

    /**
     * Change the airplane mode system setting
     */
@@ -734,6 +804,9 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
        intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
        intent.putExtra("state", on);
        mContext.sendBroadcast(intent);
        if (!mHasTelephony) {
            mAirplaneState = on ? ToggleAction.State.On : ToggleAction.State.Off;
        }
    }

    private IWindowManager getWindowManager() {