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

Commit af967184 authored by Ayush Sharma's avatar Ayush Sharma Committed by Android (Google) Code Review
Browse files

Merge "Add api to show dialog to switch to work profile"

parents 604d0842 5728fcb5
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.util.Slog;

import com.android.internal.telephony.IMms;
import com.android.internal.telephony.TelephonyPermissions;
import com.android.internal.telephony.util.TelephonyUtils;
import com.android.server.uri.NeededUriGrants;
import com.android.server.uri.UriGrantsManagerInternal;

@@ -342,7 +343,10 @@ public class MmsServiceBroker extends SystemService {
            // Check if user is associated with the subscription
            if (!TelephonyPermissions.checkSubscriptionAssociatedWithUser(mContext, subId,
                    Binder.getCallingUserHandle())) {
                // TODO(b/258629881): Display error dialog.
                if (TelephonyUtils.isUidForeground(mContext, Binder.getCallingUid())) {
                    TelephonyUtils.showErrorIfSubscriptionAssociatedWithManagedProfile(mContext,
                            subId);
                }
                return;
            }

+64 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import static android.telephony.Annotation.DataState;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ComponentInfo;
import android.content.pm.PackageManager;
@@ -26,10 +27,16 @@ import android.content.pm.ResolveInfo;
import android.os.Binder;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyFrameworkInitializer;
import android.telephony.TelephonyManager;
import android.util.Log;

import com.android.internal.telephony.ITelephony;

import java.io.PrintWriter;
import java.util.Collections;
@@ -43,6 +50,8 @@ import java.util.function.Supplier;
 * This class provides various util functions
 */
public final class TelephonyUtils {
    private static final String LOG_TAG = "TelephonyUtils";

    public static boolean IS_USER = "user".equals(android.os.Build.TYPE);
    public static boolean IS_DEBUGGABLE = SystemProperties.getInt("ro.debuggable", 0) == 1;

@@ -240,4 +249,59 @@ public final class TelephonyUtils {
        }
        return userHandle;
    }

    /**
     * Show switch to managed profile dialog if subscription is associated with managed profile.
     *
     * @param context Context object
     * @param subId   subscription id
     */
    public static void showErrorIfSubscriptionAssociatedWithManagedProfile(Context context,
            int subId) {
        final long token = Binder.clearCallingIdentity();
        try {
            SubscriptionManager subscriptionManager = context.getSystemService(
                    SubscriptionManager.class);
            UserHandle associatedUserHandle = subscriptionManager.getSubscriptionUserHandle(subId);
            UserManager um = context.getSystemService(UserManager.class);

            if (associatedUserHandle != null && um.isManagedProfile(
                    associatedUserHandle.getIdentifier())) {

                ITelephony iTelephony = ITelephony.Stub.asInterface(
                        TelephonyFrameworkInitializer
                                .getTelephonyServiceManager()
                                .getTelephonyServiceRegisterer()
                                .get());
                if (iTelephony != null) {
                    try {
                        iTelephony.showSwitchToManagedProfileDialog();
                    } catch (RemoteException e) {
                        Log.e(LOG_TAG, "Failed to launch switch to managed profile dialog.");
                    }
                }
            }
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    }

    /**
     * Check if the process with given uid is foreground.
     *
     * @param context context
     * @param uid     the caller uid
     * @return true if the process with uid is foreground, false otherwise.
     */
    public static boolean isUidForeground(Context context, int uid) {
        final long token = Binder.clearCallingIdentity();
        try {
            ActivityManager am = context.getSystemService(ActivityManager.class);
            boolean result = am != null && am.getUidImportance(uid)
                    == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
            return result;
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    }
}
 No newline at end of file
+5 −0
Original line number Diff line number Diff line
@@ -2208,6 +2208,11 @@ interface ITelephony {
    oneway void enqueueSmsPickResult(String callingPackage, String callingAttributeTag,
        IIntegerConsumer subIdResult);

    /**
     * Show error dialog to switch to managed profile.
     */
    oneway void showSwitchToManagedProfileDialog();

    /**
     * Returns the MMS user agent.
     */