1 /** 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.phone.settings; 18 19 import android.app.ActionBar; 20 import android.os.Bundle; 21 import android.os.UserManager; 22 import android.preference.PreferenceActivity; 23 import android.util.Log; 24 import android.view.MenuItem; 25 import android.widget.Toast; 26 27 import com.android.internal.telephony.flags.Flags; 28 import com.android.phone.R; 29 30 public class PhoneAccountSettingsActivity extends PreferenceActivity { 31 private static final String LOG_TAG = "PhoneAccountSettingsActivity"; 32 33 @Override onCreate(Bundle icicle)34 protected void onCreate(Bundle icicle) { 35 super.onCreate(icicle); 36 37 // Make sure we are running as an admin/work user. 38 UserManager userManager = getSystemService(UserManager.class); 39 if (!userManager.isAdminUser() && !userManager.isManagedProfile()) { 40 Toast.makeText(this, R.string.phone_account_settings_user_restriction, 41 Toast.LENGTH_SHORT).show(); 42 finish(); 43 return; 44 } 45 46 // Make sure mobile network configs are not restricted. 47 if (Flags.ensureAccessToCallSettingsIsRestricted() && 48 userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { 49 Log.i(LOG_TAG, "Mobile network configs are restricted, disabling phone account " 50 + "settings"); 51 Toast.makeText(this, R.string.phone_account_no_config_mobile_networks, 52 Toast.LENGTH_SHORT).show(); 53 finish(); 54 return; 55 } 56 57 getWindow().addSystemFlags( 58 android.view.WindowManager.LayoutParams 59 .SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); 60 final ActionBar actionBar = getActionBar(); 61 if (actionBar != null) { 62 actionBar.setTitle(R.string.phone_accounts); 63 } 64 getFragmentManager().beginTransaction().replace( 65 android.R.id.content, new PhoneAccountSettingsFragment()).commit(); 66 } 67 68 @Override onOptionsItemSelected(MenuItem item)69 public boolean onOptionsItemSelected(MenuItem item) { 70 if (item.getItemId() == android.R.id.home) { 71 onBackPressed(); 72 return true; 73 } 74 return super.onOptionsItemSelected(item); 75 } 76 } 77