Merge "Do not use hidden API SystemProperties.set"
diff --git a/src/com/android/phone/CallFeaturesSetting.java b/src/com/android/phone/CallFeaturesSetting.java
index 320fc24..29df8b8 100644
--- a/src/com/android/phone/CallFeaturesSetting.java
+++ b/src/com/android/phone/CallFeaturesSetting.java
@@ -202,7 +202,8 @@
         if (DBG) log("onCreate: Intent is " + getIntent());
 
         // Make sure we are running as an admin user.
-        if (!UserManager.get(this).isAdminUser()) {
+        UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
+        if (!userManager.isAdminUser()) {
             Toast.makeText(this, R.string.call_settings_admin_user_only,
                     Toast.LENGTH_SHORT).show();
             finish();
diff --git a/src/com/android/phone/EmergencyDialer.java b/src/com/android/phone/EmergencyDialer.java
index f5c14b9..c20281a 100644
--- a/src/com/android/phone/EmergencyDialer.java
+++ b/src/com/android/phone/EmergencyDialer.java
@@ -70,9 +70,6 @@
 import android.view.accessibility.AccessibilityEvent;
 import android.widget.TextView;
 
-import com.android.phone.EmergencyDialerMetricsLogger.DialedFrom;
-import com.android.phone.EmergencyDialerMetricsLogger.PhoneNumberType;
-import com.android.phone.EmergencyDialerMetricsLogger.UiModeErrorCode;
 import com.android.phone.common.dialpad.DialpadKeyButton;
 import com.android.phone.common.util.ViewUtil;
 import com.android.phone.common.widget.ResizingTextEditText;
@@ -221,8 +218,6 @@
     private int mEntryType;
     private ShortcutViewUtils.Config mShortcutViewConfig;
 
-    private EmergencyDialerMetricsLogger mMetricsLogger;
-
     @Override
     public void beforeTextChanged(CharSequence s, int start, int count, int after) {
         // Do nothing
@@ -257,8 +252,6 @@
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
 
-        mMetricsLogger = new EmergencyDialerMetricsLogger(this);
-
         mEntryType = getIntent().getIntExtra(EXTRA_ENTRY_TYPE, ENTRY_TYPE_UNKNOWN);
         Log.d(LOG_TAG, "Launched from " + entryTypeToString(mEntryType));
 
@@ -498,10 +491,6 @@
         if (!TextUtils.isEmpty(phoneNumber)) {
             if (DBG) Log.d(LOG_TAG, "dial emergency number: " + Rlog.pii(LOG_TAG, phoneNumber));
 
-            // Write metrics when user has intention to make a call from a shortcut button.
-            mMetricsLogger.logPlaceCall(DialedFrom.SHORTCUT, PhoneNumberType.HAS_SHORTCUT,
-                    mShortcutViewConfig.getPhoneInfo());
-
             placeCall(phoneNumber, ParcelableCallAnalytics.CALL_SOURCE_EMERGENCY_SHORTCUT,
                     mShortcutViewConfig.getPhoneInfo());
         } else {
@@ -638,10 +627,6 @@
     protected void onStart() {
         super.onStart();
 
-        mMetricsLogger.logLaunchEmergencyDialer(mEntryType,
-                mShortcutViewConfig.isEnabled() ? UiModeErrorCode.SUCCESS
-                        : UiModeErrorCode.UNSPECIFIED_ERROR);
-
         if (mShortcutViewConfig.isEnabled()) {
             // Shortcut view doesn't support dark text theme.
             mBackgroundDrawable.setColor(Color.BLACK);
@@ -745,28 +730,20 @@
         // nothing and just returns input number.
         mLastNumber = PhoneNumberUtils.convertToEmergencyNumber(this, mLastNumber);
 
-        @DialedFrom final int dialedFrom =
-                mShortcutViewConfig.isEnabled() ? DialedFrom.FASTER_LAUNCHER_DIALPAD
-                        : DialedFrom.TRADITIONAL_DIALPAD;
-        @PhoneNumberType final int phoneNumberType;
-
         boolean isEmergencyNumber;
         ShortcutViewUtils.PhoneInfo phoneToMakeCall = null;
         if (mShortcutAdapter != null && mShortcutAdapter.hasShortcut(mLastNumber)) {
             isEmergencyNumber = true;
             phoneToMakeCall = mShortcutViewConfig.getPhoneInfo();
-            phoneNumberType = PhoneNumberType.HAS_SHORTCUT;
         } else if (mShortcutViewConfig.hasPromotedEmergencyNumber(mLastNumber)) {
             // If a number from SIM/network/... is categoried as police/ambulance/fire,
             // hasPromotedEmergencyNumber() will return true, but it maybe not promoted as a
             // shortcut button because a number provided by database has higher priority.
             isEmergencyNumber = true;
             phoneToMakeCall = mShortcutViewConfig.getPhoneInfo();
-            phoneNumberType = PhoneNumberType.NO_SHORTCUT;
         } else {
             isEmergencyNumber = getSystemService(TelephonyManager.class)
                     .isEmergencyNumber(mLastNumber);
-            phoneNumberType = PhoneNumberType.NO_SHORTCUT;
         }
 
         if (isEmergencyNumber) {
@@ -779,19 +756,11 @@
                 return;
             }
 
-            // Write metrics when user has intention to make a call from dialpad
-            mMetricsLogger.logPlaceCall(dialedFrom, phoneNumberType, phoneToMakeCall);
-
             placeCall(mLastNumber, ParcelableCallAnalytics.CALL_SOURCE_EMERGENCY_DIALPAD,
                     phoneToMakeCall);
         } else {
             if (DBG) Log.d(LOG_TAG, "rejecting bad requested number " + mLastNumber);
 
-            // Write metrics when user has intention to make a call of a non-emergency number, even
-            // this number is rejected.
-            mMetricsLogger.logPlaceCall(dialedFrom, PhoneNumberType.NOT_EMERGENCY_NUMBER,
-                    phoneToMakeCall);
-
             showDialog(BAD_EMERGENCY_NUMBER_DIALOG);
         }
         mDigits.getText().delete(0, mDigits.getText().length());
diff --git a/src/com/android/phone/EmergencyDialerMetricsLogger.java b/src/com/android/phone/EmergencyDialerMetricsLogger.java
deleted file mode 100644
index b9ba352..0000000
--- a/src/com/android/phone/EmergencyDialerMetricsLogger.java
+++ /dev/null
@@ -1,289 +0,0 @@
-/*
- * Copyright (C) 2019 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.phone;
-
-import android.annotation.IntDef;
-import android.app.KeyguardManager;
-import android.content.Context;
-import android.metrics.LogMaker;
-import android.os.Build;
-import android.telephony.TelephonyManager;
-import android.util.Log;
-
-import androidx.annotation.Nullable;
-
-import com.android.internal.logging.MetricsLogger;
-import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-/**
- * EmergencyCallMetricsLogger is a utility to collect metrics of emergency calls
- */
-class EmergencyDialerMetricsLogger {
-    private static final String LOG_TAG = "EmergencyDialerLogger";
-
-    @IntDef({
-            DialedFrom.TRADITIONAL_DIALPAD,
-            DialedFrom.SHORTCUT,
-            DialedFrom.FASTER_LAUNCHER_DIALPAD,
-    })
-    @Retention(RetentionPolicy.SOURCE)
-    @interface DialedFrom {
-        int TRADITIONAL_DIALPAD = 0;
-        int SHORTCUT = 1;
-        int FASTER_LAUNCHER_DIALPAD = 2;
-    }
-
-    @IntDef({
-            LaunchedFrom.UNDEFINED,
-            LaunchedFrom.LOCK_SCREEN,
-            LaunchedFrom.POWER_KEY_MENU,
-    })
-    @Retention(RetentionPolicy.SOURCE)
-    @interface LaunchedFrom {
-        int UNDEFINED = 0;
-        int LOCK_SCREEN = 1;
-        int POWER_KEY_MENU = 2;
-    }
-
-    @IntDef({
-            PhoneNumberType.HAS_SHORTCUT,
-            PhoneNumberType.NO_SHORTCUT,
-            PhoneNumberType.NOT_EMERGENCY_NUMBER,
-    })
-    @Retention(RetentionPolicy.SOURCE)
-    @interface PhoneNumberType {
-        int HAS_SHORTCUT = 0;
-        int NO_SHORTCUT = 1;
-        int NOT_EMERGENCY_NUMBER = 2;
-    }
-
-    @IntDef({
-            UiModeErrorCode.UNSPECIFIED_ERROR,
-            UiModeErrorCode.SUCCESS,
-            UiModeErrorCode.CONFIG_ENTRY_POINT,
-            UiModeErrorCode.CONFIG_SIM_OPERATOR,
-            UiModeErrorCode.UNSUPPORTED_COUNTRY,
-            UiModeErrorCode.AIRPLANE_MODE,
-            UiModeErrorCode.NO_PROMOTED_NUMBER,
-            UiModeErrorCode.NO_CAPABLE_PHONE,
-    })
-    @Retention(RetentionPolicy.SOURCE)
-    @interface UiModeErrorCode {
-        int UNSPECIFIED_ERROR = -1;
-        int SUCCESS = 0;
-        int CONFIG_ENTRY_POINT = 1;
-        int CONFIG_SIM_OPERATOR = 2;
-        int UNSUPPORTED_COUNTRY = 3;
-        int AIRPLANE_MODE = 4;
-        int NO_PROMOTED_NUMBER = 5;
-        int NO_CAPABLE_PHONE = 6;
-    }
-
-    private class TelephonyInfo {
-        private final String mNetworkCountryIso;
-        private final String mNetworkOperator;
-
-        TelephonyInfo(String networkCountryIso, String networkOperator) {
-            mNetworkCountryIso = networkCountryIso;
-            mNetworkOperator = networkOperator;
-        }
-    }
-
-    private final MetricsLogger mMetricsLogger = new MetricsLogger();
-
-    private final Context mAppContext;
-
-    @LaunchedFrom
-    private int mLaunchedFrom;
-    @UiModeErrorCode
-    private int mUiModeErrorCode;
-
-    EmergencyDialerMetricsLogger(Context context) {
-        mAppContext = context.getApplicationContext();
-    }
-
-    /**
-     * Log when Emergency Dialer is launched.
-     * - Where the user launch Emergency Dialer from.
-     * - Whether shortcut view is enabled, and the reason why it's not enabled.
-     *
-     * @param entryType
-     * @param uiModeErrorCode
-     */
-    public void logLaunchEmergencyDialer(int entryType,
-            @UiModeErrorCode int uiModeErrorCode) {
-        final @EmergencyDialerMetricsLogger.LaunchedFrom int launchedFrom;
-        if (entryType == EmergencyDialer.ENTRY_TYPE_LOCKSCREEN_BUTTON) {
-            launchedFrom = EmergencyDialerMetricsLogger.LaunchedFrom.LOCK_SCREEN;
-        } else if (entryType == EmergencyDialer.ENTRY_TYPE_POWER_MENU) {
-            launchedFrom = EmergencyDialerMetricsLogger.LaunchedFrom.POWER_KEY_MENU;
-        } else {
-            launchedFrom = EmergencyDialerMetricsLogger.LaunchedFrom.UNDEFINED;
-        }
-
-        mLaunchedFrom = launchedFrom;
-        mUiModeErrorCode = uiModeErrorCode;
-    }
-
-    /**
-     * Log when user tring to place an emergency call.
-     * - Which UI (traditional dialpad, shortcut button, dialpad in shortcut view) the user place
-     *   the call from.
-     * - The number is promoted in shortcut view or not, or not even an emergency number?
-     * - Whether the device is locked.
-     * - Network country ISO and network operator.
-     *
-     * @param dialedFrom
-     * @param phoneNumberType
-     * @param phoneInfo
-     */
-    public void logPlaceCall(@DialedFrom int dialedFrom,
-            @PhoneNumberType int phoneNumberType,
-            @Nullable ShortcutViewUtils.PhoneInfo phoneInfo) {
-        TelephonyInfo telephonyInfo = getTelephonyInfo(phoneNumberType, phoneInfo);
-        final KeyguardManager keyguard = mAppContext.getSystemService(KeyguardManager.class);
-
-        logBeforeMakeCall(dialedFrom, phoneNumberType, keyguard.isKeyguardLocked(),
-                telephonyInfo.mNetworkCountryIso, telephonyInfo.mNetworkOperator);
-    }
-
-    private TelephonyInfo getTelephonyInfo(@PhoneNumberType int phoneNumberType,
-            @Nullable ShortcutViewUtils.PhoneInfo phoneInfo) {
-        final TelephonyManager telephonyManager = mAppContext.getSystemService(
-                TelephonyManager.class);
-        final TelephonyManager subTelephonyManager;
-        final String networkCountryIso;
-        final String networkOperator;
-        if (phoneNumberType == PhoneNumberType.HAS_SHORTCUT && phoneInfo != null) {
-            subTelephonyManager = telephonyManager.createForSubscriptionId(phoneInfo.getSubId());
-            networkCountryIso = phoneInfo.getCountryIso();
-        } else {
-            // No specific phone to make this call. Take information of default network.
-            subTelephonyManager = null;
-            networkCountryIso = telephonyManager.getNetworkCountryIso();
-        }
-        if (subTelephonyManager != null) {
-            networkOperator = subTelephonyManager.getNetworkOperator();
-        } else {
-            // This could be:
-            // - No specific phone to make this call.
-            // - Subscription changed! Maybe the device roamed to another network?
-            // Take information of default network.
-            networkOperator = telephonyManager.getNetworkOperator();
-        }
-
-        return new TelephonyInfo(networkCountryIso, networkOperator);
-    }
-
-    private void logBeforeMakeCall(@DialedFrom int dialedFrom,
-            @PhoneNumberType int phoneNumberType,
-            boolean isDeviceLocked,
-            String networkCountryIso,
-            String networkOperator) {
-        if (Log.isLoggable(LOG_TAG, Log.DEBUG)) {
-            Log.d(LOG_TAG, "EmergencyDialer session: dialedFrom=" + dialFromToString(dialedFrom)
-                    + ", launchedFrom=" + launchedFromToString(mLaunchedFrom)
-                    + ", uimode=" + uiModeErrorCodeToString(mUiModeErrorCode)
-                    + ", type=" + phoneNumberTypeToString(phoneNumberType)
-                    + ", locked=" + isDeviceLocked
-                    + ", country=" + networkCountryIso
-                    + ", operator=" + networkOperator);
-        }
-        mMetricsLogger.write(new LogMaker(MetricsEvent.EMERGENCY_DIALER_MAKE_CALL_V2)
-                .setType(MetricsEvent.TYPE_ACTION)
-                .setSubtype(dialedFrom)
-                .addTaggedData(MetricsEvent.FIELD_EMERGENCY_DIALER_LAUNCH_FROM, mLaunchedFrom)
-                .addTaggedData(MetricsEvent.FIELD_EMERGENCY_DIALER_UI_MODE_ERROR_CODE,
-                        mUiModeErrorCode)
-                .addTaggedData(MetricsEvent.FIELD_EMERGENCY_DIALER_PHONE_NUMBER_TYPE,
-                        phoneNumberType)
-                .addTaggedData(MetricsEvent.FIELD_EMERGENCY_DIALER_IS_DEVICE_LOCKED,
-                        isDeviceLocked ? 1 : 0)
-                .addTaggedData(MetricsEvent.FIELD_EMERGENCY_DIALER_NETWORK_COUNTRY_ISO,
-                        networkCountryIso)
-                .addTaggedData(MetricsEvent.FIELD_EMERGENCY_DIALER_NETWORK_OPERATOR,
-                        networkOperator)
-                .addTaggedData(MetricsEvent.FIELD_EMERGENCY_DIALER_RADIO_VERSION,
-                        Build.getRadioVersion())
-        );
-    }
-
-    private String dialFromToString(@DialedFrom int dialedFrom) {
-        switch (dialedFrom) {
-            case DialedFrom.TRADITIONAL_DIALPAD:
-                return "traditional";
-            case DialedFrom.SHORTCUT:
-                return "shortcut";
-            case DialedFrom.FASTER_LAUNCHER_DIALPAD:
-                return "dialpad";
-            default:
-                return "unknown_error";
-        }
-    }
-
-    private String launchedFromToString(@LaunchedFrom int launchedFrom) {
-        switch (launchedFrom) {
-            case LaunchedFrom.UNDEFINED:
-                return "undefined";
-            case LaunchedFrom.LOCK_SCREEN:
-                return "lockscreen";
-            case LaunchedFrom.POWER_KEY_MENU:
-                return "powermenu";
-            default:
-                return "unknown_error";
-        }
-    }
-
-    private String phoneNumberTypeToString(@PhoneNumberType int phoneNumberType) {
-        switch (phoneNumberType) {
-            case PhoneNumberType.HAS_SHORTCUT:
-                return "has_shortcut";
-            case PhoneNumberType.NO_SHORTCUT:
-                return "no_shortcut";
-            case PhoneNumberType.NOT_EMERGENCY_NUMBER:
-                return "not_emergency";
-            default:
-                return "unknown_error";
-        }
-    }
-
-    private String uiModeErrorCodeToString(@UiModeErrorCode int uiModeErrorCode) {
-        switch (uiModeErrorCode) {
-            case UiModeErrorCode.UNSPECIFIED_ERROR:
-                return "unspecified_error";
-            case UiModeErrorCode.SUCCESS:
-                return "success";
-            case UiModeErrorCode.CONFIG_ENTRY_POINT:
-                return "config_entry_point";
-            case UiModeErrorCode.CONFIG_SIM_OPERATOR:
-                return "config_sim_operator";
-            case UiModeErrorCode.UNSUPPORTED_COUNTRY:
-                return "unsupported_country";
-            case UiModeErrorCode.AIRPLANE_MODE:
-                return "airplane_mode";
-            case UiModeErrorCode.NO_PROMOTED_NUMBER:
-                return "no_promoted_number";
-            case UiModeErrorCode.NO_CAPABLE_PHONE:
-                return "no_capable_phone";
-            default:
-                return "unknown_error";
-        }
-    }
-}
diff --git a/src/com/android/phone/EmergencyInfoGroup.java b/src/com/android/phone/EmergencyInfoGroup.java
index 9e7121d..186de03 100644
--- a/src/com/android/phone/EmergencyInfoGroup.java
+++ b/src/com/android/phone/EmergencyInfoGroup.java
@@ -153,7 +153,7 @@
     private Drawable getCircularUserIcon() {
         final UserManager userManager = (UserManager) getContext().getSystemService(
                 Context.USER_SERVICE);
-        Bitmap bitmapUserIcon = userManager.getUserIcon(UserHandle.getCallingUserId());
+        Bitmap bitmapUserIcon = userManager.getUserIcon();
 
         if (bitmapUserIcon == null) {
             // get default user icon.
diff --git a/src/com/android/phone/EmergencyShortcutButton.java b/src/com/android/phone/EmergencyShortcutButton.java
index f77595b..9e51e82 100644
--- a/src/com/android/phone/EmergencyShortcutButton.java
+++ b/src/com/android/phone/EmergencyShortcutButton.java
@@ -19,8 +19,6 @@
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
 import android.content.Context;
-import android.metrics.LogMaker;
-import android.os.SystemClock;
 import android.util.AttributeSet;
 import android.view.MotionEvent;
 import android.view.View;
@@ -32,9 +30,6 @@
 
 import androidx.annotation.NonNull;
 
-import com.android.internal.logging.MetricsLogger;
-import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-
 /**
  * Emergency shortcut button displays a local emergency phone number information(including phone
  * number, and phone type). To decrease false clicking, it need to click twice to confirm to place
@@ -66,12 +61,6 @@
 
     private boolean mConfirmViewHiding;
 
-    /**
-     * The time, in millis, since boot when user taps on shortcut button to reveal confirm view.
-     * This is used for metrics when calculating the interval between reveal tap and confirm tap.
-     */
-    private long mTimeOfRevealTapInMillis = 0;
-
     public EmergencyShortcutButton(Context context, AttributeSet attrs) {
         super(context, attrs);
     }
@@ -209,15 +198,6 @@
                 }
                 break;
             case R.id.emergency_call_confirm_view:
-                if (mTimeOfRevealTapInMillis != 0) {
-                    long timeBetweenTwoTaps =
-                            SystemClock.elapsedRealtime() - mTimeOfRevealTapInMillis;
-                    // Reset reveal time to zero for next reveal-confirm taps pair.
-                    mTimeOfRevealTapInMillis = 0;
-
-                    writeMetricsForConfirmTap(timeBetweenTwoTaps);
-                }
-
                 if (mOnConfirmClickListener != null) {
                     mOnConfirmClickListener.onConfirmClick(this);
                 }
@@ -229,7 +209,6 @@
         mConfirmViewHiding = false;
 
         mConfirmView.setVisibility(View.VISIBLE);
-        mTimeOfRevealTapInMillis = SystemClock.elapsedRealtime();
         int centerX = mCallNumberInfoView.getLeft() + mCallNumberInfoView.getWidth() / 2;
         int centerY = mCallNumberInfoView.getTop() + mCallNumberInfoView.getHeight() / 2;
         Animator reveal = ViewAnimationUtils.createCircularReveal(
@@ -266,8 +245,6 @@
             @Override
             public void onAnimationEnd(Animator animation) {
                 mConfirmView.setVisibility(INVISIBLE);
-                // Reset reveal time to zero for next reveal-confirm taps pair.
-                mTimeOfRevealTapInMillis = 0;
             }
         });
         reveal.start();
@@ -282,12 +259,4 @@
             hideSelectedButton();
         }
     };
-
-    private void writeMetricsForConfirmTap(long timeBetweenTwoTaps) {
-        LogMaker logContent = new LogMaker(MetricsEvent.EMERGENCY_DIALER_SHORTCUT_CONFIRM_TAP)
-                .setType(MetricsEvent.TYPE_ACTION)
-                .addTaggedData(MetricsEvent.FIELD_EMERGENCY_DIALER_SHORTCUT_TAPS_INTERVAL,
-                        timeBetweenTwoTaps);
-        MetricsLogger.action(logContent);
-    }
 }
diff --git a/src/com/android/phone/NotificationMgr.java b/src/com/android/phone/NotificationMgr.java
index bb1e293..475cc1f 100644
--- a/src/com/android/phone/NotificationMgr.java
+++ b/src/com/android/phone/NotificationMgr.java
@@ -379,7 +379,7 @@
             for (int i = 0; i < users.size(); i++) {
                 final UserInfo user = users.get(i);
                 final UserHandle userHandle = user.getUserHandle();
-                if (!mUserManager.hasUserRestriction(
+                if (!hasUserRestriction(
                         UserManager.DISALLOW_OUTGOING_CALLS, userHandle)
                         && !user.isManagedProfile()) {
                     if (!maybeSendVoicemailNotificationUsingDefaultDialer(phone, vmCount, vmNumber,
@@ -397,7 +397,7 @@
             for (int i = 0; i < users.size(); i++) {
                 final UserInfo user = users.get(i);
                 final UserHandle userHandle = user.getUserHandle();
-                if (!mUserManager.hasUserRestriction(
+                if (!hasUserRestriction(
                         UserManager.DISALLOW_OUTGOING_CALLS, userHandle)
                         && !user.isManagedProfile()) {
                     if (!maybeSendVoicemailNotificationUsingDefaultDialer(phone, 0, null, null,
@@ -412,6 +412,12 @@
         }
     }
 
+    private boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
+        final List<UserManager.EnforcingUser> sources = mUserManager
+                .getUserRestrictionSources(restrictionKey, userHandle);
+        return (sources != null && !sources.isEmpty());
+    }
+
     /**
      * Sends a broadcast with the voicemail notification information to the default dialer. This
      * method is also used to indicate to the default dialer when to clear the
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index a51a2d6..c46d09b 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -39,7 +39,6 @@
 import android.os.PowerManager;
 import android.os.SystemClock;
 import android.os.SystemProperties;
-import android.os.UpdateLock;
 import android.os.UserManager;
 import android.preference.PreferenceManager;
 import android.provider.Settings;
@@ -188,8 +187,6 @@
     private PowerManager.WakeLock mPartialWakeLock;
     private KeyguardManager mKeyguardManager;
 
-    private UpdateLock mUpdateLock;
-
     private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
     private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
 
@@ -275,7 +272,8 @@
                     // not want this running if the device is still in the FBE encrypted state.
                     // This is the same procedure that is triggered in the SipIncomingCallReceiver
                     // upon BOOT_COMPLETED.
-                    UserManager userManager = UserManager.get(sMe);
+                    UserManager userManager =
+                            (UserManager) sMe.getSystemService(Context.USER_SERVICE);
                     if (userManager != null && userManager.isUserUnlocked()) {
                         SipUtil.startSipService();
                     }
@@ -348,12 +346,6 @@
 
             mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
 
-            // Get UpdateLock to suppress system-update related events (e.g. dialog show-up)
-            // during phone calls.
-            mUpdateLock = new UpdateLock("phone");
-
-            if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock);
-
             // Create the CallerInfoCache singleton, which remembers custom ring tone and
             // send-to-voicemail settings.
             //
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 15818ec..cfbcafb 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -62,6 +62,7 @@
 import android.telecom.PhoneAccount;
 import android.telecom.PhoneAccountHandle;
 import android.telecom.TelecomManager;
+import android.telephony.Annotation.ApnType;
 import android.telephony.CarrierConfigManager;
 import android.telephony.CarrierRestrictionRules;
 import android.telephony.CellIdentity;
@@ -94,7 +95,6 @@
 import android.telephony.VisualVoicemailSmsFilterSettings;
 import android.telephony.cdma.CdmaCellLocation;
 import android.telephony.data.ApnSetting;
-import android.telephony.data.ApnSetting.ApnType;
 import android.telephony.emergency.EmergencyNumber;
 import android.telephony.gsm.GsmCellLocation;
 import android.telephony.ims.ImsException;
@@ -2927,18 +2927,19 @@
         if (!SubscriptionManager.isValidSubscriptionId(subId)) {
             throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
         }
-        Binder.withCleanCallingIdentity(() -> {
-            try {
-                // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
-                ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
-                        .removeRegistrationCallbackForSubscription(c, subId);
-            } catch (ImsException e) {
-                Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
-                        + "is inactive, ignoring unregister.");
-                // If the subscription is no longer active, just return, since the callback
-                // will already have been removed internally.
-            }
-        });
+        final long token = Binder.clearCallingIdentity();
+        try {
+            // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
+            ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
+                    .removeRegistrationCallbackForSubscription(c, subId);
+        } catch (ImsException e) {
+            Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
+                    + "is inactive, ignoring unregister.");
+            // If the subscription is no longer active, just return, since the callback
+            // will already have been removed internally.
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
     }
 
     /**
@@ -3032,22 +3033,23 @@
     @Override
     public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
         enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
-
         if (!SubscriptionManager.isValidSubscriptionId(subId)) {
             throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
         }
-        Binder.withCleanCallingIdentity(() -> {
-            try {
-                // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
-                ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
+
+        final long token = Binder.clearCallingIdentity();
+        try {
+            // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
+            ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
                         .removeCapabilitiesCallbackForSubscription(c, subId);
-            } catch (ImsException e) {
-                Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
-                        + "is inactive, ignoring unregister.");
-                // If the subscription is no longer active, just return, since the callback
-                // will already have been removed internally.
-            }
-        });
+        } catch (ImsException e) {
+            Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
+                     + "is inactive, ignoring unregister.");
+             // If the subscription is no longer active, just return, since the callback
+             // will already have been removed internally.
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
     }
 
     @Override
diff --git a/src/com/android/phone/euicc/EuiccUiDispatcherActivity.java b/src/com/android/phone/euicc/EuiccUiDispatcherActivity.java
index 7c7b75d..4c85818 100644
--- a/src/com/android/phone/euicc/EuiccUiDispatcherActivity.java
+++ b/src/com/android/phone/euicc/EuiccUiDispatcherActivity.java
@@ -153,7 +153,7 @@
             mPackageManager.revokeDefaultPermissionsFromLuiApps(luiAppsArray, getUserId());
         } catch (RemoteException e) {
             Log.e(TAG, "Failed to revoke LUI app permissions.");
-            throw e.rethrowAsRuntimeException();
+            throw new RuntimeException(e);
         }
     }
 
diff --git a/src/com/android/services/telephony/EmergencyTonePlayer.java b/src/com/android/services/telephony/EmergencyTonePlayer.java
index 8e26349..431f8d7 100644
--- a/src/com/android/services/telephony/EmergencyTonePlayer.java
+++ b/src/com/android/services/telephony/EmergencyTonePlayer.java
@@ -23,7 +23,6 @@
 import android.media.AudioAttributes;
 import android.media.AudioManager;
 import android.media.ToneGenerator;
-import android.os.SystemVibrator;
 import android.os.Vibrator;
 import android.provider.Settings;
 
@@ -49,11 +48,9 @@
                 .setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
                 .build();
 
-    // We don't rely on getSystemService(Context.VIBRATOR_SERVICE) to make sure that this vibrator
-    // object will be isolated from others.
-    private final Vibrator mVibrator = new SystemVibrator();
     private final Context mContext;
     private final AudioManager mAudioManager;
+    private final Vibrator mVibrator;
 
     private ToneGenerator mToneGenerator;
     private int mSavedInCallVolume;
@@ -62,6 +59,7 @@
     EmergencyTonePlayer(Context context) {
         mContext = context;
         mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
+        mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
     }
 
     public void start() {
diff --git a/src/com/android/services/telephony/TelecomAccountRegistry.java b/src/com/android/services/telephony/TelecomAccountRegistry.java
index 1e681e8..2e923ec 100644
--- a/src/com/android/services/telephony/TelecomAccountRegistry.java
+++ b/src/com/android/services/telephony/TelecomAccountRegistry.java
@@ -803,8 +803,10 @@
                 Log.i(this, "User changed, re-registering phone accounts.");
 
                 int userHandleId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
-                UserHandle currentUserHandle = new UserHandle(userHandleId);
-                mIsPrimaryUser = UserManager.get(mContext).getPrimaryUser().getUserHandle()
+                UserHandle currentUserHandle = UserHandle.of(userHandleId);
+                UserManager userManager =
+                        (UserManager) context.getSystemService(Context.USER_SERVICE);
+                mIsPrimaryUser = userManager.getPrimaryUser().getUserHandle()
                         .equals(currentUserHandle);
 
                 // Any time the user changes, re-register the accounts.