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

Commit 97d268fc authored by Danesh M's avatar Danesh M Committed by Abhisek Devkota
Browse files

Telecomm : Allow multiple default dialers

CYNGNOS-1096
Change-Id: Ied3fe36cf5249b9ab5a9f4bdd36f2ba6e76c538e
(cherry picked from commit 15d94d6a)
(cherry picked from commit abde5827)
parent 54b43035
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 The CyanogenMod 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.
-->

<resources>
    <!-- Class name for the default in-call UI Service [DO NOT TRANSLATE] -->
    <string-array name="incall_default_classes" translatable="false">
        <item>com.android.dialer/com.android.incallui.InCallServiceImpl</item>
    </string-array>

    <!-- Class name for the default main dialer activity [DO NOT TRANSLATE] -->
    <string-array name="dialer_default_classes" translatable="false">
        <item>com.android.dialer/com.android.dialer.DialtactsActivity</item>
    </string-array>
</resources>
+1 −3
Original line number Diff line number Diff line
@@ -154,9 +154,7 @@ public final class InCallController extends CallsManagerListenerBase {
        mContext = context;
        Resources resources = mContext.getResources();

        mInCallComponentName = new ComponentName(
                resources.getString(R.string.ui_default_package),
                resources.getString(R.string.incall_default_class));
        mInCallComponentName = TelephonyUtil.getInCallComponentName(context);
    }

    @Override
+2 −4
Original line number Diff line number Diff line
@@ -367,10 +367,8 @@ class NewOutgoingCallIntentBroadcaster {

    private void launchSystemDialer(Uri handle) {
        Intent systemDialerIntent = new Intent();
        final Resources resources = mContext.getResources();
        systemDialerIntent.setClassName(
                resources.getString(R.string.ui_default_package),
                resources.getString(R.string.dialer_default_class));
        systemDialerIntent.setComponent(
                TelephonyUtil.getDialerComponentName(mContext));
        systemDialerIntent.setAction(Intent.ACTION_DIAL);
        systemDialerIntent.setData(handle);
        systemDialerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+2 −8
Original line number Diff line number Diff line
@@ -501,10 +501,7 @@ public class TelecomService extends Service {
         */
        @Override
        public ComponentName getDefaultPhoneApp() {
            Resources resources = mContext.getResources();
            return new ComponentName(
                    resources.getString(R.string.ui_default_package),
                    resources.getString(R.string.dialer_default_class));
            return TelephonyUtil.getDialerComponentName(mContext);
        }

        /**
@@ -974,10 +971,7 @@ public class TelecomService extends Service {
    }

    private ComponentName getDefaultPhoneAppInternal() {
        Resources resources = mContext.getResources();
        return new ComponentName(
                resources.getString(R.string.ui_default_package),
                resources.getString(R.string.dialer_default_class));
        return TelephonyUtil.getDialerComponentName(mContext);
    }

    private TelephonyManager getTelephonyManager() {
+43 −0
Original line number Diff line number Diff line
@@ -18,11 +18,20 @@ package com.android.server.telecom;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.net.Uri;
import android.telecom.InCallService;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telephony.PhoneNumberUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Utilities to deal with the system telephony services. The system telephony services are treated
 * differently from 3rd party services in some situations (emergency calls, audio focus, etc...).
@@ -64,4 +73,38 @@ public final class TelephonyUtil {
        return handle != null && PhoneNumberUtils.isPotentialLocalEmergencyNumber(
                context, handle.getSchemeSpecificPart());
    }

    static ComponentName getDialerComponentName(Context context) {
        Resources resources = context.getResources();
        PackageManager packageManager = context.getPackageManager();
        Intent i = new Intent(Intent.ACTION_DIAL);
        List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(i, 0);
        List<String> entries = Arrays.asList(resources.getStringArray(
                R.array.dialer_default_classes));
        for (ResolveInfo info : resolveInfo) {
            ComponentName componentName = new ComponentName(info.activityInfo.packageName,
                    info.activityInfo.name);
            if (entries.contains(componentName.flattenToString())) {
                return componentName;
            }
        }
        return null;
    }

    static ComponentName getInCallComponentName(Context context) {
        Resources resources = context.getResources();
        PackageManager packageManager = context.getPackageManager();
        Intent i = new Intent(InCallService.SERVICE_INTERFACE);
        List<ResolveInfo> resolveInfo = packageManager.queryIntentServices(i, 0);
        List<String> entries = Arrays.asList(resources.getStringArray(
                R.array.incall_default_classes));
        for (ResolveInfo info : resolveInfo) {
            ComponentName componentName = new ComponentName(info.serviceInfo.packageName,
                    info.serviceInfo.name);
            if (entries.contains(componentName.flattenToString())) {
                return componentName;
            }
        }
        return null;
    }
}