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

Commit 4d4686c9 authored by Yorke Lee's avatar Yorke Lee Committed by Android Git Automerger
Browse files

am 66086aa7: am 1542179b: Merge "Add hidden methods to set/get default dialer...

am 66086aa7: am 1542179b: Merge "Add hidden methods to set/get default dialer across users" into mnc-dev

* commit '66086aa7':
  Add hidden methods to set/get default dialer across users
parents 8b7c3f2a 66086aa7
Loading
Loading
Loading
Loading
+41 −10
Original line number Original line Diff line number Diff line
@@ -14,6 +14,7 @@


package android.telecom;
package android.telecom;


import android.app.ActivityManager;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ActivityInfo;
@@ -35,15 +36,27 @@ public class DefaultDialerManager {
    private static final String TAG = "DefaultDialerManager";
    private static final String TAG = "DefaultDialerManager";


    /**
    /**
     * Sets the specified package name as the default dialer application. The caller of this method
     * Sets the specified package name as the default dialer application for the current user.
     * needs to have permission to write to secure settings.
     * The caller of this method needs to have permission to write to secure settings and
     * manage users on the device.
     *
     *
     * @hide
     * @hide
     * */
     * */
    public static void setDefaultDialerApplication(Context context, String packageName) {
    public static void setDefaultDialerApplication(Context context, String packageName) {
        setDefaultDialerApplication(context, packageName, ActivityManager.getCurrentUser());
    }

    /**
     * Sets the specified package name as the default dialer application for the specified user.
     * The caller of this method needs to have permission to write to secure settings and
     * manage users on the device.
     *
     * @hide
     * */
    public static void setDefaultDialerApplication(Context context, String packageName, int user) {
        // Get old package name
        // Get old package name
        String oldPackageName = Settings.Secure.getString(context.getContentResolver(),
        String oldPackageName = Settings.Secure.getStringForUser(context.getContentResolver(),
                Settings.Secure.DIALER_DEFAULT_APPLICATION);
                Settings.Secure.DIALER_DEFAULT_APPLICATION, user);


        if (packageName != null && oldPackageName != null && packageName.equals(oldPackageName)) {
        if (packageName != null && oldPackageName != null && packageName.equals(oldPackageName)) {
            // No change
            // No change
@@ -55,26 +68,44 @@ public class DefaultDialerManager {


        if (packageNames.contains(packageName)) {
        if (packageNames.contains(packageName)) {
            // Update the secure setting.
            // Update the secure setting.
            Settings.Secure.putString(context.getContentResolver(),
            Settings.Secure.putStringForUser(context.getContentResolver(),
                    Settings.Secure.DIALER_DEFAULT_APPLICATION, packageName);
                    Settings.Secure.DIALER_DEFAULT_APPLICATION, packageName, user);
        }
        }
    }
    }


    /**
    /**
     * Returns the installed dialer application that will be used to receive incoming calls, and is
     * Returns the installed dialer application for the current user that will be used to receive
     * allowed to make emergency calls.
     * incoming calls, and is allowed to make emergency calls.
     *
     *
     * The application will be returned in order of preference:
     * The application will be returned in order of preference:
     * 1) User selected phone application (if still installed)
     * 1) User selected phone application (if still installed)
     * 2) Pre-installed system dialer (if not disabled)
     * 2) Pre-installed system dialer (if not disabled)
     * 3) Null
     * 3) Null
     *
     *
     * The caller of this method needs to have permission to manage users on the device.
     *
     * @hide
     * @hide
     * */
     * */
    public static String getDefaultDialerApplication(Context context) {
    public static String getDefaultDialerApplication(Context context) {
        String defaultPackageName = Settings.Secure.getString(context.getContentResolver(),
        return getDefaultDialerApplication(context, ActivityManager.getCurrentUser());
                Settings.Secure.DIALER_DEFAULT_APPLICATION);
    }


    /**
     * Returns the installed dialer application for the specified user that will be used to receive
     * incoming calls, and is allowed to make emergency calls.
     *
     * The application will be returned in order of preference:
     * 1) User selected phone application (if still installed)
     * 2) Pre-installed system dialer (if not disabled)
     * 3) Null
     *
     * The caller of this method needs to have permission to manage users on the device.
     *
     * @hide
     * */
    public static String getDefaultDialerApplication(Context context, int user) {
        String defaultPackageName = Settings.Secure.getStringForUser(context.getContentResolver(),
                Settings.Secure.DIALER_DEFAULT_APPLICATION, user);


        final List<String> packageNames = getInstalledDialerApplications(context);
        final List<String> packageNames = getInstalledDialerApplications(context);