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

Commit e76b5478 authored by haiyangl's avatar haiyangl Committed by Linux Build Service Account
Browse files

Phone: Add headset notification when wired headset plugin

When wired headset is plugged in, show a notification on status bar,
and cancel such notification when the wired headset is plugged out.

Conflicts:
src/com/android/server/telecom/TtyManager.java
Change-Id: Iefb452e496d2f30a333f130f04742505b782b006
parent 2851080d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -41,4 +41,6 @@
    <string name="no_vm_number" msgid="4164780423805688336">"缺少语音信箱号码"</string>
    <string name="no_vm_number_msg" msgid="1300729501030053828">"SIM卡上未存储语音信箱号码。"</string>
    <string name="add_vm_number_str" msgid="4676479471644687453">"添加号码"</string>
    <string name="headset_plugin_view_text">耳机已插入到手机。</string>
    <string name="headset_plugin_view_title">耳机插入</string>
</resources>
+2 −0
Original line number Diff line number Diff line
@@ -41,4 +41,6 @@
    <string name="no_vm_number" msgid="4164780423805688336">"未填留言信箱號碼"</string>
    <string name="no_vm_number_msg" msgid="1300729501030053828">"SIM 卡中沒有儲存任何留言信箱號碼。"</string>
    <string name="add_vm_number_str" msgid="4676479471644687453">"新增電話號碼"</string>
    <string name="headset_plugin_view_text">耳機已插入到手機</string>
    <string name="headset_plugin_view_title">耳機插入</string>
</resources>
+2 −0
Original line number Diff line number Diff line
@@ -41,4 +41,6 @@
    <string name="no_vm_number" msgid="4164780423805688336">"遺失語音信箱號碼"</string>
    <string name="no_vm_number_msg" msgid="1300729501030053828">"SIM 卡中未儲存語音信箱號碼。"</string>
    <string name="add_vm_number_str" msgid="4676479471644687453">"新增號碼"</string>
    <string name="headset_plugin_view_text">耳機已插入到手機</string>
    <string name="headset_plugin_view_title">耳機插入</string>
</resources>
+3 −0
Original line number Diff line number Diff line
@@ -111,4 +111,7 @@

    <!-- DO NOT TRANSLATE. Hardcoded number used for restricted incoming phone numbers. -->
    <string name="handle_restricted">RESTRICTED</string>

    <string name="headset_plugin_view_text">Headset is plugged in.</string>
    <string name="headset_plugin_view_title">Headset</string>
</resources>
+41 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.server.telecom;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -33,12 +36,17 @@ final class TtyManager implements WiredHeadsetManager.Listener {
    private final WiredHeadsetManager mWiredHeadsetManager;
    private int mPreferredTtyMode = TelecomManager.TTY_MODE_OFF;
    private int mCurrentTtyMode = TelecomManager.TTY_MODE_OFF;
    protected NotificationManager mNotificationManager;

    static final int HEADSET_PLUGIN_NOTIFICATION = 1000;

    TtyManager(Context context, WiredHeadsetManager wiredHeadsetManager) {
        mContext = context;
        mWiredHeadsetManager = wiredHeadsetManager;
        mWiredHeadsetManager.addListener(this);

        mNotificationManager =
                (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
        mPreferredTtyMode = Settings.Secure.getInt(
                mContext.getContentResolver(),
                Settings.Secure.PREFERRED_TTY_MODE,
@@ -65,6 +73,12 @@ final class TtyManager implements WiredHeadsetManager.Listener {
    public void onWiredHeadsetPluggedInChanged(boolean oldIsPluggedIn, boolean newIsPluggedIn) {
        Log.v(this, "onWiredHeadsetPluggedInChanged");
        updateCurrentTtyMode();

        if (newIsPluggedIn) {
            showHeadSetPlugin();
        } else {
            cancelHeadSetPlugin();
        }
    }

    private void updateCurrentTtyMode() {
@@ -107,6 +121,33 @@ final class TtyManager implements WiredHeadsetManager.Listener {
        audioManager.setParameters("tty_mode=" + audioTtyMode);
    }

    void showHeadSetPlugin() {
        Log.v(TtyManager.this, "showHeadSetPlugin()...");

        String titleText = mContext.getString(
                R.string.headset_plugin_view_title);
        String expandedText = mContext.getString(
                R.string.headset_plugin_view_text);

        Notification notification = new Notification();
        notification.icon = android.R.drawable.stat_sys_headset;
        notification.flags |= Notification.FLAG_NO_CLEAR;
        notification.tickerText = titleText;

        // create the target network operators settings intent
        Intent intent = new Intent("android.intent.action.NO_ACTION");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0);

        notification.setLatestEventInfo(mContext, titleText, expandedText, pi);
        mNotificationManager.notify(HEADSET_PLUGIN_NOTIFICATION, notification);
    }

    void cancelHeadSetPlugin() {
        Log.v(TtyManager.this, "cancelHeadSetPlugin()...");
        mNotificationManager.cancel(HEADSET_PLUGIN_NOTIFICATION);
    }

    private final class TtyBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {