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

Commit 24ddbf5e authored by Brad Ebinger's avatar Brad Ebinger Committed by Gerrit Code Review
Browse files

Merge changes I06df2928,I70821964

* changes:
  Fixes ContactDiscoveryDialogFragmentTest
  Add new DialogFragment and Controller for capability discovery opt-in
parents aab7aca7 cacc9dd0
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -136,6 +136,8 @@
                  android:theme="@style/Theme.Settings.Home"
                  android:launchMode="singleTask">
            <intent-filter android:priority="1">
                <!-- Displays the MobileNetworkActivity and opt-in dialog for capability discovery. -->
                <action android:name="android.telephony.ims.action.SHOW_CAPABILITY_DISCOVERY_OPT_IN" />
                <action android:name="android.settings.NETWORK_OPERATOR_SETTINGS" />
                <action android:name="android.settings.DATA_ROAMING_SETTINGS" />
                <action android:name="android.settings.MMS_MESSAGE_SETTING" />
+13 −0
Original line number Diff line number Diff line
@@ -6990,6 +6990,19 @@
    <string name="enhanced_4g_lte_mode_summary">Use LTE services to improve voice and other communications (recommended)</string>
    <!-- Enhaced 4G LTE Mode summary for 4g calling.  [CHAR LIMIT=100] -->
    <string name="enhanced_4g_lte_mode_summary_4g_calling">Use 4G services to improve voice and other communications (recommended)</string>
    <!-- Title of a preference determining whether or not the user has enabled contact discovery,
         which is a service that uses the phone numbers in your contacts to determine if your
         contacts support advanced calling features, such as video calling. [CHAR LIMIT=50]-->
    <string name="contact_discovery_opt_in_title">Contact discovery</string>
    <!-- Summary of a preference determining whether or not the user has enabled contact discovery.
         [CHAR LIMIT=100] -->
    <string name="contact_discovery_opt_in_summary">Allows your carrier to discover which calling features your contacts support.</string>
    <!-- Title of the dialog shown when the user tries to enable Contact Discovery.
         [CHAR LIMIT=50] -->
    <string name="contact_discovery_opt_in_dialog_title">Enable contact discovery?</string>
    <!-- Text displayed in the dialog shown when the user tries to enable Contact Discovery.
         [CHAR LIMIT=NONE]-->
    <string name="contact_discovery_opt_in_dialog_message">Enabling this feature will allow your carrier access to phone numbers in your contacts in order to discover which calling features they support.</string>
    <!-- Preferred network type title.  [CHAR LIMIT=50] -->
    <string name="preferred_network_type_title">Preferred network type</string>
    <!-- Preferred network type summary.  [CHAR LIMIT=100] -->
+7 −0
Original line number Diff line number Diff line
@@ -52,6 +52,13 @@
        android:summary="@string/enhanced_4g_lte_mode_summary"
        settings:controller="com.android.settings.network.telephony.Enhanced4gLtePreferenceController"/>

    <SwitchPreference
        android:key="contact_discovery_opt_in"
        android:title="@string/contact_discovery_opt_in_title"
        android:persistent="false"
        android:summary="@string/contact_discovery_opt_in_summary"
        settings:controller="com.android.settings.network.telephony.ContactDiscoveryPreferenceController"/>

    <ListPreference
        android:key="preferred_network_mode_key"
        android:title="@string/preferred_network_mode_title"
+7 −0
Original line number Diff line number Diff line
@@ -98,6 +98,13 @@
            android:summary="@string/enhanced_4g_lte_mode_summary"
            settings:controller="com.android.settings.network.telephony.Enhanced4gLtePreferenceController"/>

        <SwitchPreference
            android:key="contact_discovery_opt_in"
            android:title="@string/contact_discovery_opt_in_title"
            android:persistent="false"
            android:summary="@string/contact_discovery_opt_in_summary"
            settings:controller="com.android.settings.network.telephony.ContactDiscoveryPreferenceController"/>

        <ListPreference
            android:key="preferred_network_mode_key"
            android:title="@string/preferred_network_mode_title"
+104 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.network.telephony;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.telephony.ims.ImsManager;
import android.telephony.ims.ImsRcsManager;

import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.FragmentManager;

import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;

/**
 * Fragment for the "Contact Discovery" dialog that appears when the user enables
 * "Contact Discovery" in MobileNetworkSettings or an application starts MobileNetworkSettings with
 * {@link ImsRcsManager#ACTION_SHOW_CAPABILITY_DISCOVERY_OPT_IN}.
 */
public class ContactDiscoveryDialogFragment extends InstrumentedDialogFragment
        implements DialogInterface.OnClickListener {

    private static final String SUB_ID_KEY = "sub_id_key";
    private static final String DIALOG_TAG = "discovery_dialog:";

    private int mSubId;
    private ImsManager mImsManager;

    /**
     * Create a new Fragment, which will create a new Dialog when
     * {@link #show(FragmentManager, String)} is called.
     * @param subId The subscription ID to associate with this Dialog.
     * @return a new instance of ContactDiscoveryDialogFragment.
     */
    public static ContactDiscoveryDialogFragment newInstance(int subId) {
        final ContactDiscoveryDialogFragment dialogFragment = new ContactDiscoveryDialogFragment();
        final Bundle args = new Bundle();
        args.putInt(SUB_ID_KEY, subId);
        dialogFragment.setArguments(args);

        return dialogFragment;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        final Bundle args = getArguments();
        mSubId = args.getInt(SUB_ID_KEY);
        mImsManager = getImsManager(context);
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
        final int title = R.string.contact_discovery_opt_in_dialog_title;
        int message = R.string.contact_discovery_opt_in_dialog_message;
        builder.setMessage(getResources().getString(message))
                .setTitle(title)
                .setIconAttribute(android.R.attr.alertDialogIcon)
                .setPositiveButton(android.R.string.ok, this)
                .setNegativeButton(android.R.string.cancel, this);
        return builder.create();
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        // let the host know that the positive button has been clicked
        if (which == dialog.BUTTON_POSITIVE) {
            MobileNetworkUtils.setContactDiscoveryEnabled(mImsManager, mSubId, true /*isEnabled*/);
        }
    }

    @Override
    public int getMetricsCategory() {
        return METRICS_CATEGORY_UNKNOWN;
    }

    @VisibleForTesting
    public ImsManager getImsManager(Context context) {
        return context.getSystemService(ImsManager.class);
    }

    public static String getFragmentTag(int subId) {
        return DIALOG_TAG + subId;
    }
}
Loading