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

Commit 8fc9246c authored by Fang Yunong's avatar Fang Yunong Committed by Gerrit - the friendly Code Review server
Browse files

Add switch button in Settings for Wi-Fi Call.

RootCause:
Wifi calling could control in Settings.

Solution:
Create WFCPreference, and be used to display error message
and control WFC work.

Change-Id: I4bf5bcbd9702857a65cd399b0dbb7b7ff47e2b83
CRs-Fixed: 1039278
parent b3b21d49
Loading
Loading
Loading
Loading
+77 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2016, The Linux Foundation. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above
      copyright notice, this list of conditions and the following
      disclaimer in the documentation and/or other materials provided
      with the distribution.
    * Neither the name of The Linux Foundation nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:attr/activatedBackgroundIndicator"
    android:gravity="center_vertical"
    android:minHeight="48dp"
    android:paddingEnd="?android:attr/scrollbarSize" >

    <RelativeLayout
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_marginStart="15dip"
        android:layout_marginEnd="6dip"
        android:layout_marginTop="6dip"
        android:layout_marginBottom="6dip"
        android:layout_weight="1">

        <TextView android:id="@+id/subtitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:text="@string/wifi_calling_settings_title"
            android:textAppearance="?android:attr/textAppearanceListItem"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal" />

        <TextView android:id="@+id/subsummary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/subtitle"
            android:layout_alignStart="@+id/subtitle"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorSecondary"
            android:maxLines="4" />

    </RelativeLayout>

    <Switch
        android:id="@+id/switchWidget"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:clickable="true"
        android:focusable="false"
        android:padding="8dip" />

</LinearLayout>
 No newline at end of file
+5 −8
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2016, The Linux Foundation. All rights reserved.-->

<!-- Copyright (C) 2008 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,17 +36,12 @@
        settings:keywords="@string/keywords_wifi_calling"
        android:fragment="com.android.settings.WifiCallingSettings" />

    <PreferenceScreen
    <com.android.settings.WFCPreference
        android:key="wifi_calling_enhanced_settings"
        android:title="@string/wifi_calling_settings_title"
        android:summaryOff="@null"
        android:summaryOn="@null"
        android:persistent="false">
        <intent
            android:action="android.intent.action.MAIN"
            android:targetPackage="com.qualcomm.qti.wfcservice"
            android:targetClass="com.qualcomm.qti.wfcservice.WifiCallingEnhancedSettings" />
    </PreferenceScreen>
        android:persistent="false"
        android:layout="@layout/wfc_checkbox" />

    <com.android.settingslib.RestrictedPreference
        android:fragment="com.android.settings.nfc.AndroidBeam"
+98 −0
Original line number Diff line number Diff line
/*
Copyright (c) 2016, The Linux Foundation. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above
      copyright notice, this list of conditions and the following
      disclaimer in the documentation and/or other materials provided
      with the distribution.
    * Neither the name of The Linux Foundation nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.android.settings;

import android.content.Context;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Switch;
import android.widget.TextView;

public class WFCPreference extends Preference implements OnCheckedChangeListener {

    private Switch mSwitch;
    private TextView mSubSummary;
    private Context mContext;
    private boolean mSwitchEnabled;
    private CharSequence remainSummary;

    public WFCPreference(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mContext = context;
    }

    public WFCPreference(Context context, AttributeSet attrs) {
        this(context, attrs, com.android.internal.R.attr.switchPreferenceStyle);
        mContext = context;
    }

    public WFCPreference(Context context) {
        this(context, null);
        mContext = context;
    }

    @Override
    public void onBindViewHolder(PreferenceViewHolder view) {
        super.onBindViewHolder(view);
        mSubSummary = (TextView) view.findViewById(R.id.subsummary);
        mSubSummary.setText(remainSummary);
        mSwitch = (Switch) view.findViewById(R.id.switchWidget);
        mSwitch.setOnCheckedChangeListener(this);
        setChecked(mSwitchEnabled);
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        callChangeListener(isChecked);
        mSwitchEnabled = isChecked;
    }

    public void setSummary(CharSequence summary) {
        if (mSubSummary == null) {
            remainSummary = summary;
            return;
        }
        mSubSummary.setText(summary);
    }

    public void setChecked(boolean state) {
        if (mSwitch != null) {
            mSwitch.setOnCheckedChangeListener(null);
            mSwitch.setChecked(state);
            mSwitch.setOnCheckedChangeListener(this);
        }
        mSwitchEnabled=state;
    }
}
+84 −17
Original line number Diff line number Diff line
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.*/

/*
 * Copyright (C) 2009 The Android Open Source Project
 *
@@ -84,6 +86,10 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
    private static final String KEY_WFC_SETTINGS = "wifi_calling_settings";
    private static final String KEY_WFC_ENHANCED_SETTINGS = "wifi_calling_enhanced_settings";

    private static final String ACTION_WIFI_CALL_ON = "com.android.wificall.TURNON";
    private static final String ACTION_WIFI_CALL_OFF = "com.android.wificall.TURNOFF";
    private static final String WIFI_CALLING_PREFERRED = "preference";

    public static final String EXIT_ECM_RESULT = "exit_ecm_result";
    public static final int REQUEST_CODE_EXIT_ECM = 1;

@@ -102,10 +108,11 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
    private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
    private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";

    private PreferenceScreen mButtonWfc;
    private Preference mButtonWfc;
    private boolean mEnhancedWFCSettingsEnabled = false;

    private IWFCService mWFCService;

    private ServiceConnection mConnection = new ServiceConnection() {

        public void onServiceConnected(ComponentName className, IBinder service) {
@@ -124,15 +131,25 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
    };

    private IWFCServiceCB mCallback = new IWFCServiceCB.Stub() {
        public void updateWFCMessage(String s) {
            if (!mEnhancedWFCSettingsEnabled || (s == null)) {
        public void updateWFCMessage(String errorCode) {
            if (!mEnhancedWFCSettingsEnabled || (errorCode == null)) {
                if(DEBUG) Log.e(TAG, "updateWFCMessage fail.");
                return ;
            }
            getActivity().runOnUiThread(new Runnable() {
                public void run() {
                    if (DEBUG) Log.d(TAG, "new UI thread.");
                    mButtonWfc.setSummary(s);
                    try {
                        if (mWFCService.getWifiCallingStatus()) {
                            if (mButtonWfc instanceof WFCPreference) {
                                ((WFCPreference) mButtonWfc).setSummary(errorCode);
                            } else {
                                mButtonWfc.setSummary(errorCode);
                            }
                        }
                    } catch (RemoteException r) {
                        Log.e(TAG, "getWifiCallingStatus RemoteException");
                    }
                }
            });

@@ -303,6 +320,14 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
        return MetricsEvent.WIRELESS;
    }

    private void broadcastWifiCallingStatus(Context ctx, boolean isTurnOn, int preference) {
        if(DEBUG) Log.d(TAG, "broadcastWifiCallingStatus:");
        Intent intent = new Intent(isTurnOn ? ACTION_WIFI_CALL_ON
                    : ACTION_WIFI_CALL_OFF);
        intent.putExtra(WIFI_CALLING_PREFERRED, preference);
        ctx.sendBroadcast(intent);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
@@ -332,21 +357,52 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
        mEnhancedWFCSettingsEnabled = getActivity().getResources().getBoolean(
                    R.bool.wifi_call_enhanced_setting);
        if (mEnhancedWFCSettingsEnabled) {
            mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_ENHANCED_SETTINGS);
            mButtonWfc = (WFCPreference) findPreference(KEY_WFC_ENHANCED_SETTINGS);
            removePreference(KEY_WFC_SETTINGS);
            mButtonWfc.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                public boolean onPreferenceClick(Preference preference) {
                    Intent intent = new Intent();
                    intent.setAction("android.intent.action.MAIN");
                    intent.setPackage("com.qualcomm.qti.wfcservice");
                    intent.setClassName("com.qualcomm.qti.wfcservice",
                            "com.qualcomm.qti.wfcservice.WifiCallingEnhancedSettings");
                    mButtonWfc.setIntent(intent);
                    return false;
                }
            });

            mButtonWfc.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference, Object value) {
                    int wfcPreference = -1;
                    try {
                        wfcPreference = mWFCService.getWifiCallingPreference();
                    } catch (RemoteException re) {
                        Log.e(TAG, "getWifiCallingPreference RemoteException");
                        return false;
                    }

                    boolean isChecked = (Boolean) value;

                    try {
                        mWFCService.setWifiCalling(isChecked, wfcPreference);
                    } catch (RemoteException r) {
                        Log.e(TAG, "setWifiCalling RemoteException");
                    }

                    if (!isChecked) {
                        ((WFCPreference) preference).setSummary(R.string.disabled);
                    }

                    broadcastWifiCallingStatus(getActivity(), isChecked, wfcPreference);
                    return false;
                }
            });
        } else {
            mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS);
            removePreference(KEY_WFC_ENHANCED_SETTINGS);
        }

        if (mEnhancedWFCSettingsEnabled) {
            //bind WFC service
            final Intent intentWfc = new Intent();
            intentWfc.setAction("com.qualcomm.qti.wfcservice.IWFCService");
            intentWfc.setPackage("com.qualcomm.qti.wfcservice");
            activity.bindService(intentWfc, mConnection, Context.BIND_AUTO_CREATE);
        }

        String toggleable = Settings.Global.getString(activity.getContentResolver(),
                Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);

@@ -475,6 +531,14 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
    public void onResume() {
        super.onResume();

        if (mEnhancedWFCSettingsEnabled && mWFCService == null) {
            //bind WFC service
            final Intent intentWfc = new Intent();
            intentWfc.setAction("com.qualcomm.qti.wfcservice.IWFCService");
            intentWfc.setPackage("com.qualcomm.qti.wfcservice");
            getActivity().bindService(intentWfc, mConnection, Context.BIND_AUTO_CREATE);
        }

        mAirplaneModeEnabler.resume();
        if (mNfcEnabler != null) {
            mNfcEnabler.resume();
@@ -489,9 +553,12 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
                       context, ImsManager.getWfcMode(context)));
            } else {
                if (!ImsManager.isWfcEnabledByUser(context)) {
                    mButtonWfc.setSummary(R.string.disabled);
                    ((WFCPreference) mButtonWfc).setChecked(false);
                    ((WFCPreference) mButtonWfc).setSummary(R.string.disabled);
                } else {
                    mButtonWfc.setSummary(SystemProperties.get("sys.wificall.status.msg"));
                    ((WFCPreference) mButtonWfc).setChecked(true);
                    ((WFCPreference) mButtonWfc).setSummary(
                            SystemProperties.get("sys.wificall.status.msg"));
                }
            }
        } else {
+3 −0
Original line number Diff line number Diff line
@@ -35,5 +35,8 @@ import org.codeaurora.wfcservice.IWFCServiceCB;
interface IWFCService {
    void registerCallback(IWFCServiceCB cb);
    void unregisterCallback(IWFCServiceCB cb);
    void setWifiCalling(boolean state, int preference);
    boolean getWifiCallingStatus();
    int getWifiCallingPreference();
}