diff options
Diffstat (limited to 'src/com/android/server/telecom/UserUtil.java')
-rw-r--r-- | src/com/android/server/telecom/UserUtil.java | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/com/android/server/telecom/UserUtil.java b/src/com/android/server/telecom/UserUtil.java index a30440139..d0a561ad9 100644 --- a/src/com/android/server/telecom/UserUtil.java +++ b/src/com/android/server/telecom/UserUtil.java @@ -16,10 +16,16 @@ package com.android.server.telecom; +import android.app.admin.DevicePolicyManager; import android.content.Context; +import android.content.Intent; import android.content.pm.UserInfo; +import android.net.Uri; import android.os.UserHandle; import android.os.UserManager; +import android.telecom.Log; + +import com.android.server.telecom.components.ErrorDialogActivity; public final class UserUtil { @@ -40,4 +46,57 @@ public final class UserUtil { UserInfo userInfo = getUserInfoFromUserHandle(context, userHandle); return userInfo != null && userInfo.profileGroupId != userInfo.id; } + + public static void showErrorDialogForRestrictedOutgoingCall(Context context, + int stringId, String tag, String reason) { + final Intent intent = new Intent(context, ErrorDialogActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.putExtra(ErrorDialogActivity.ERROR_MESSAGE_ID_EXTRA, stringId); + context.startActivityAsUser(intent, UserHandle.CURRENT); + Log.w(tag, "Rejecting non-emergency phone call because " + + reason); + } + + public static boolean hasOutgoingCallsUserRestriction(Context context, + UserHandle userHandle, Uri handle, boolean isSelfManaged, String tag) { + // Set handle for conference calls. Refer to {@link Connection#ADHOC_CONFERENCE_ADDRESS}. + if (handle == null) { + handle = Uri.parse("tel:conf-factory"); + } + + if(!isSelfManaged) { + // Check DISALLOW_OUTGOING_CALLS restriction. Note: We are skipping this + // check in a managed profile user because this check can always be bypassed + // by copying and pasting the phone number into the personal dialer. + if (!UserUtil.isManagedProfile(context, userHandle)) { + // Only emergency calls are allowed for users with the DISALLOW_OUTGOING_CALLS + // restriction. + if (!TelephonyUtil.shouldProcessAsEmergency(context, handle)) { + final UserManager userManager = + (UserManager) context.getSystemService(Context.USER_SERVICE); + if (userManager.hasBaseUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS, + userHandle)) { + String reason = "of DISALLOW_OUTGOING_CALLS restriction"; + showErrorDialogForRestrictedOutgoingCall(context, + R.string.outgoing_call_not_allowed_user_restriction, tag, reason); + return true; + } else if (userManager.hasUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS, + userHandle)) { + final DevicePolicyManager dpm = + context.getSystemService(DevicePolicyManager.class); + if (dpm == null) { + return true; + } + final Intent adminSupportIntent = dpm.createAdminSupportIntent( + UserManager.DISALLOW_OUTGOING_CALLS); + if (adminSupportIntent != null) { + context.startActivityAsUser(adminSupportIntent, userHandle); + } + return true; + } + } + } + } + return false; + } } |