Phone account settings restrict user visibility.

The phone account settings page is accessible by secondary/guest users.
This behavior contradicts what is seen in general settings (SIM settings
are unaccessible via 'Network & internet'). As a result, a
secondary/guest user can change the call preference for the admin.

Restricting access to the activity for only admin/work users will allow
these two settings configs to function in par with one another.

Fixes: 277073811
Test: Manual (access is restricted only for secondary/guest users)
Change-Id: I342aa1ac4aa967b8e28ed020410beaddd2516f4b
(cherry picked from commit 2718701a0d8bfc41300d1fff6d949fb86cb298c6)
Merged-In: I342aa1ac4aa967b8e28ed020410beaddd2516f4b
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 680eb22..5804aff 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -289,6 +289,8 @@
     <string name="updating_title">Call settings</string>
     <!-- Toast in Call settings when asked to launch settings for a secondary user -->
     <string name="call_settings_admin_user_only">Call settings can only be changed by the admin user.</string>
+    <!-- Toast in Phone Account settings when asked to launch settings for a secondary/guest user -->
+    <string name="phone_account_settings_user_restriction">Phone account settings can only be changed by the admin or work user.</string>
     <!-- Title of the "Call settings" settings screen, with a text label identifying which SIM the settings are for. -->
     <string name="call_settings_with_label">Settings (<xliff:g id="subscriptionlabel" example="Mock Carrier">%s</xliff:g>)</string>
     <!-- Title of the alert dialog displayed if an error occurs while updating Call settings -->
diff --git a/src/com/android/phone/settings/PhoneAccountSettingsActivity.java b/src/com/android/phone/settings/PhoneAccountSettingsActivity.java
index e15be39..12cc667 100644
--- a/src/com/android/phone/settings/PhoneAccountSettingsActivity.java
+++ b/src/com/android/phone/settings/PhoneAccountSettingsActivity.java
@@ -18,9 +18,10 @@
 
 import android.app.ActionBar;
 import android.os.Bundle;
+import android.os.UserManager;
 import android.preference.PreferenceActivity;
 import android.view.MenuItem;
-import android.view.WindowManager;
+import android.widget.Toast;
 
 import com.android.phone.R;
 
@@ -29,6 +30,16 @@
     @Override
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
+
+        // Make sure we are running as an admin/work user.
+        UserManager userManager = getSystemService(UserManager.class);
+        if (!userManager.isAdminUser() && !userManager.isManagedProfile()) {
+            Toast.makeText(this, R.string.phone_account_settings_user_restriction,
+                    Toast.LENGTH_SHORT).show();
+            finish();
+            return;
+        }
+
         getWindow().addSystemFlags(
                 android.view.WindowManager.LayoutParams
                         .SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);