Merge "Fix unmount up button" into nyc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 3af57fe..1f0d5d7 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2888,6 +2888,18 @@
                         android:value="true" />
         </activity>
 
+        <activity android:name=".WebViewImplementation"
+                  android:exported="true"
+                  android:excludeFromRecents="true"
+                  android:theme="@*android:style/Theme.Material.Light.Dialog.Alert">
+            <intent-filter>
+                <action android:name="android.settings.WEBVIEW_SETTINGS" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+            <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+                android:value="true" />
+        </activity>
+
         <service
             android:name=".SettingsDumpService"
             android:exported="true"
diff --git a/res/layout/setup_choose_lock_pattern_common.xml b/res/layout/setup_choose_lock_pattern_common.xml
index 857f244..0a38637 100644
--- a/res/layout/setup_choose_lock_pattern_common.xml
+++ b/res/layout/setup_choose_lock_pattern_common.xml
@@ -21,6 +21,7 @@
     xmlns:settings="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:layout="@layout/setup_choose_lock_pattern_template"
     settings:suwBackgroundTile="@drawable/setup_illustration_tile"
     settings:suwHeaderText="@string/wifi_setup_wizard_title"
     settings:suwIllustrationHorizontalTile="@drawable/setup_illustration_horizontal_tile"
@@ -43,11 +44,11 @@
 
             <TextView android:id="@+id/headerText"
                 android:layout_width="match_parent"
-                android:layout_height="0dip"
+                android:layout_height="wrap_content"
                 android:layout_weight="1"
+                android:minLines="2"
                 android:gravity="center"
-                android:minHeight="50dip"
-                android:textSize="18sp"/>
+                android:textSize="18sp" />
 
             <Button android:id="@+id/retryButton"
                 style="@android:style/Widget.Material.Button.Borderless.Colored"
@@ -59,8 +60,7 @@
             <com.android.internal.widget.LockPatternView android:id="@+id/lockPattern"
                 android:layout_width="match_parent"
                 android:layout_height="0dip"
-                android:layout_weight="4"
-                android:background="@color/lock_pattern_background"/>
+                android:layout_weight="4" />
 
         </LinearLayout>
 
diff --git a/res/values-sw360dp/aliases.xml b/res/values-sw360dp/aliases.xml
new file mode 100644
index 0000000..a10585b
--- /dev/null
+++ b/res/values-sw360dp/aliases.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2016 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.
+-->
+
+<resources>
+     <item name="setup_choose_lock_pattern_template" type="layout">@layout/suw_template</item>
+</resources>
+
diff --git a/res/values/aliases.xml b/res/values/aliases.xml
index 0901157..a783c79 100644
--- a/res/values/aliases.xml
+++ b/res/values/aliases.xml
@@ -23,5 +23,6 @@
      <item name="fingerprint_enroll_finish" type="layout">@layout/fingerprint_enroll_finish_base</item>
      <item name="setup_choose_lock_pattern" type="layout">@layout/setup_choose_lock_pattern_common</item>
      <item name="setup_fingerprint_enroll_find_sensor" type="layout">@layout/setup_fingerprint_enroll_find_sensor_base</item>
+     <item name="setup_choose_lock_pattern_template" type="layout">@layout/suw_template_short</item>
 </resources>
 
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index 2b96dbe..1fd8451 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -749,7 +749,7 @@
             ArrayList<String> options = new ArrayList<String>();
             ArrayList<String> values = new ArrayList<String>();
             for(int n = 0; n < providers.length; n++) {
-                if (isPackageEnabled(providers[n].packageName)) {
+                if (Utils.isPackageEnabled(getActivity(), providers[n].packageName)) {
                     options.add(providers[n].description);
                     values.add(providers[n].packageName);
                 }
@@ -1929,15 +1929,6 @@
                 requestCode, resources.getString(R.string.oem_unlock_enable));
     }
 
-    private boolean isPackageEnabled(String packageName) {
-        try {
-            return getActivity().getPackageManager().getApplicationInfo(packageName, 0).enabled;
-        } catch (NameNotFoundException e) {
-            // Thrown by PackageManager.getApplicationInfo if the package does not exist
-        }
-        return false;
-    }
-
     @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
         if (HDCP_CHECKING_KEY.equals(preference.getKey())) {
diff --git a/src/com/android/settings/MonitoringCertInfoActivity.java b/src/com/android/settings/MonitoringCertInfoActivity.java
index 9df3413..8ad9d83 100644
--- a/src/com/android/settings/MonitoringCertInfoActivity.java
+++ b/src/com/android/settings/MonitoringCertInfoActivity.java
@@ -29,15 +29,20 @@
 
 /**
  * Activity that shows a dialog explaining that a CA cert is allowing someone to monitor network
- * traffic. This activity should be launched for the user into which the CA cert is installed.
+ * traffic. This activity should be launched for the user into which the CA cert is installed
+ * unless Intent.EXTRA_USER_ID is provided.
  */
 public class MonitoringCertInfoActivity extends Activity implements OnClickListener,
         OnDismissListener {
 
+    private int mUserId;
+
     @Override
     protected void onCreate(Bundle savedStates) {
         super.onCreate(savedStates);
 
+        mUserId = getIntent().getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
+
         DevicePolicyManager dpm = getSystemService(DevicePolicyManager.class);
         final int numberOfCertificates = getIntent().getIntExtra(
                 Settings.EXTRA_NUMBER_OF_CERTIFICATES, 1);
@@ -53,7 +58,7 @@
         builder.setNeutralButton(R.string.cancel, null);
         builder.setOnDismissListener(this);
 
-        if (dpm.getProfileOwner() != null) {
+        if (dpm.getProfileOwnerAsUser(mUserId) != null) {
             builder.setMessage(getResources().getQuantityString(R.plurals.ssl_ca_cert_info_message,
                     numberOfCertificates, dpm.getProfileOwnerName()));
         } else if (dpm.getDeviceOwnerComponentOnCallingUser() != null) {
@@ -73,7 +78,7 @@
     public void onClick(DialogInterface dialog, int which) {
         Intent intent = new Intent(android.provider.Settings.ACTION_TRUSTED_CREDENTIALS_USER);
         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
-        intent.putExtra(TrustedCredentialsSettings.ARG_SHOW_NEW_FOR_USER, UserHandle.myUserId());
+        intent.putExtra(TrustedCredentialsSettings.ARG_SHOW_NEW_FOR_USER, mUserId);
         startActivity(intent);
         finish();
     }
diff --git a/src/com/android/settings/TrustedCredentialsDialogBuilder.java b/src/com/android/settings/TrustedCredentialsDialogBuilder.java
index ed2ab09..2508d8c 100644
--- a/src/com/android/settings/TrustedCredentialsDialogBuilder.java
+++ b/src/com/android/settings/TrustedCredentialsDialogBuilder.java
@@ -43,6 +43,7 @@
     public interface DelegateInterface {
         List<X509Certificate> getX509CertsFromCertHolder(CertHolder certHolder);
         void removeOrInstallCert(CertHolder certHolder);
+        boolean startConfirmCredentialIfNotConfirmed(int userId);
     }
 
     private final DialogEventHandler mDialogEventHandler;
@@ -144,8 +145,10 @@
 
         private void onClickTrust() {
             CertHolder certHolder = getCurrentCertInfo();
-            mDpm.approveCaCert(certHolder.getAlias(), certHolder.getUserId(), true);
-            nextOrDismiss();
+            if (!mDelegate.startConfirmCredentialIfNotConfirmed(certHolder.getUserId())) {
+                mDpm.approveCaCert(certHolder.getAlias(), certHolder.getUserId(), true);
+                nextOrDismiss();
+            }
         }
 
         private void onClickRemove() {
diff --git a/src/com/android/settings/TrustedCredentialsSettings.java b/src/com/android/settings/TrustedCredentialsSettings.java
index e7ab406..c630ed6 100644
--- a/src/com/android/settings/TrustedCredentialsSettings.java
+++ b/src/com/android/settings/TrustedCredentialsSettings.java
@@ -17,6 +17,7 @@
 package com.android.settings;
 
 import android.annotation.UiThread;
+import android.app.Activity;
 import android.app.KeyguardManager;
 import android.app.admin.DevicePolicyManager;
 import android.content.BroadcastReceiver;
@@ -79,8 +80,10 @@
     private KeyguardManager mKeyguardManager;
     private int mTrustAllCaUserId;
 
-
+    private static final String SAVED_CONFIRMED_CREDENTIAL_USERS = "ConfirmedCredentialUsers";
+    private static final String SAVED_CONFIRMING_CREDENTIAL_USER = "ConfirmingCredentialUser";
     private static final String USER_ACTION = "com.android.settings.TRUSTED_CREDENTIALS_USER";
+    private static final int REQUEST_CONFIRM_CREDENTIALS = 1;
 
     @Override
     protected int getMetricsCategory() {
@@ -154,6 +157,8 @@
     private TabHost mTabHost;
     private ArrayList<GroupAdapter> mGroupAdapters = new ArrayList<>(2);
     private AliasOperation mAliasOperation;
+    private ArraySet<Integer> mConfirmedCredentialUsers;
+    private int mConfirmingCredentialUser;
     private Set<AdapterData.AliasLoader> mAliasLoaders = new ArraySet<AdapterData.AliasLoader>(2);
     private final SparseArray<KeyChainConnection>
             mKeyChainConnectionByProfileId = new SparseArray<KeyChainConnection>();
@@ -182,6 +187,17 @@
                 .getSystemService(Context.KEYGUARD_SERVICE);
         mTrustAllCaUserId = getActivity().getIntent().getIntExtra(ARG_SHOW_NEW_FOR_USER,
                 UserHandle.USER_NULL);
+        mConfirmedCredentialUsers = new ArraySet<>(2);
+        mConfirmingCredentialUser = UserHandle.USER_NULL;
+        if (savedInstanceState != null) {
+            mConfirmingCredentialUser = savedInstanceState.getInt(SAVED_CONFIRMING_CREDENTIAL_USER,
+                    UserHandle.USER_NULL);
+            ArrayList<Integer> users = savedInstanceState.getIntegerArrayList(
+                    SAVED_CONFIRMED_CREDENTIAL_USERS);
+            if (users != null) {
+                mConfirmedCredentialUsers.addAll(users);
+            }
+        }
 
         IntentFilter filter = new IntentFilter();
         filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
@@ -190,6 +206,14 @@
         getActivity().registerReceiver(mWorkProfileChangedReceiver, filter);
     }
 
+    @Override
+    public void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+        outState.putIntegerArrayList(SAVED_CONFIRMED_CREDENTIAL_USERS, new ArrayList<>(
+                mConfirmedCredentialUsers));
+        outState.putInt(SAVED_CONFIRMING_CREDENTIAL_USER, mConfirmingCredentialUser);
+    }
+
     @Override public View onCreateView(
             LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
         mTabHost = (TabHost) inflater.inflate(R.layout.trusted_credentials, parent, false);
@@ -219,6 +243,16 @@
         super.onDestroy();
     }
 
+    @Override
+    public void onActivityResult(int requestCode, int resultCode, Intent data) {
+        if (requestCode == REQUEST_CONFIRM_CREDENTIALS) {
+            if (resultCode == Activity.RESULT_OK) {
+                mConfirmedCredentialUsers.add(mConfirmingCredentialUser);
+            }
+            mConfirmingCredentialUser = UserHandle.USER_NULL;
+        }
+    }
+
     private void closeKeyChainConnections() {
         final int n = mKeyChainConnectionByProfileId.size();
         for (int i = 0; i < n; ++i) {
@@ -262,14 +296,18 @@
     }
 
     /**
-     * Start work challenge activity. TODO: Move and refactor this method as a util function.
+     * Start work challenge activity.
+     * @return true if screenlock exists
      */
-    private void startWorkChallenge(int userId) {
+    private boolean startConfirmCredential(int userId) {
         final Intent newIntent = mKeyguardManager.createConfirmDeviceCredentialIntent(null, null,
                 userId);
-        newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
-                | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_CLEAR_TASK);
-        getActivity().startActivity(newIntent);
+        if (newIntent == null) {
+            return false;
+        }
+        mConfirmingCredentialUser = userId;
+        startActivityForResult(newIntent, REQUEST_CONFIRM_CREDENTIALS);
+        return true;
     }
 
     /**
@@ -303,7 +341,8 @@
         }
         @Override
         public CertHolder getChild(int groupPosition, int childPosition) {
-            return mData.mCertHoldersByUserId.get(getUserIdByGroup(groupPosition)).get(childPosition);
+            return mData.mCertHoldersByUserId.get(getUserIdByGroup(groupPosition)).get(
+                    childPosition);
         }
         @Override
         public long getGroupId(int groupPosition) {
@@ -386,18 +425,27 @@
         }
 
         public boolean checkGroupExpandableAndStartWarningActivity(int groupPosition) {
+            return checkGroupExpandableAndStartWarningActivity(groupPosition, true);
+        }
+
+        public boolean checkGroupExpandableAndStartWarningActivity(int groupPosition,
+                boolean startActivity) {
             final UserHandle groupUser = getGroup(groupPosition);
             final int groupUserId = groupUser.getIdentifier();
             if (mUserManager.isQuietModeEnabled(groupUser)) {
                 final Intent intent = UnlaunchableAppActivity.createInQuietModeDialogIntent(
                         groupUserId);
-                getActivity().startActivity(intent);
+                if (startActivity) {
+                    getActivity().startActivity(intent);
+                }
                 return false;
             } else if (!mUserManager.isUserUnlocked(groupUser)) {
                 final LockPatternUtils lockPatternUtils = new LockPatternUtils(
                         getActivity());
                 if (lockPatternUtils.isSeparateProfileChallengeEnabled(groupUserId)) {
-                    startWorkChallenge(groupUserId);
+                    if (startActivity) {
+                        startConfirmCredential(groupUserId);
+                    }
                     return false;
                 }
             }
@@ -548,7 +596,8 @@
         }
 
         public void prepare() {
-            mIsListExpanded = checkGroupExpandableAndStartWarningActivity();
+            mIsListExpanded = mParent.checkGroupExpandableAndStartWarningActivity(mGroupPosition,
+                    false /* startActivity */);
             refreshViews();
         }
 
@@ -890,6 +939,15 @@
         new AliasOperation(certHolder).execute();
     }
 
+    @Override
+    public boolean startConfirmCredentialIfNotConfirmed(int userId) {
+        if (mConfirmedCredentialUsers.contains(userId)) {
+            // Credential has been confirmed. Don't start activity.
+            return false;
+        }
+        return startConfirmCredential(userId);
+    }
+
     private class AliasOperation extends AsyncTask<Void, Void, Boolean> {
         private final CertHolder mCertHolder;
 
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index d972e07..4eaad7d 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -36,6 +36,7 @@
 import android.content.pm.IPackageManager;
 import android.content.pm.IntentFilterVerificationInfo;
 import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.pm.ResolveInfo;
 import android.content.pm.UserInfo;
 import android.content.res.Resources;
@@ -87,7 +88,6 @@
 import android.view.animation.AnimationUtils;
 import android.widget.ListView;
 import android.widget.TabWidget;
-
 import com.android.internal.app.UnlaunchableAppActivity;
 import com.android.internal.util.UserIcons;
 
@@ -1137,5 +1137,14 @@
         }
         return null;
     }
+
+    public static boolean isPackageEnabled(Context context, String packageName) {
+        try {
+            return context.getPackageManager().getApplicationInfo(packageName, 0).enabled;
+        } catch (NameNotFoundException e) {
+            // Thrown by PackageManager.getApplicationInfo if the package does not exist
+        }
+        return false;
+    }
 }
 
diff --git a/src/com/android/settings/WebViewImplementation.java b/src/com/android/settings/WebViewImplementation.java
new file mode 100644
index 0000000..c949a39
--- /dev/null
+++ b/src/com/android/settings/WebViewImplementation.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2016 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.settings;
+
+import android.annotation.Nullable;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnCancelListener;
+import android.content.DialogInterface.OnClickListener;
+import android.content.DialogInterface.OnDismissListener;
+import android.os.Bundle;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.UserManager;
+import android.util.Log;
+import android.webkit.IWebViewUpdateService;
+import android.webkit.WebViewProviderInfo;
+import com.android.internal.logging.MetricsProto.MetricsEvent;
+
+import java.util.ArrayList;
+
+public class WebViewImplementation extends InstrumentedActivity implements
+        OnCancelListener, OnDismissListener {
+
+    private static final String TAG = "WebViewImplementation";
+
+    private IWebViewUpdateService mWebViewUpdateService;
+
+    @Override
+    protected void onCreate(@Nullable Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        if (!UserManager.get(this).isAdminUser()) {
+            finish();
+            return;
+        }
+        mWebViewUpdateService  =
+                IWebViewUpdateService.Stub.asInterface(ServiceManager.getService("webviewupdate"));
+        try {
+            WebViewProviderInfo[] providers = mWebViewUpdateService.getValidWebViewPackages();
+            if (providers == null) {
+                Log.e(TAG, "No WebView providers available");
+                finish();
+                return;
+            }
+
+            String currentValue = mWebViewUpdateService.getCurrentWebViewPackageName();
+            if (currentValue == null) {
+                currentValue = "";
+            }
+
+            int currentIndex = -1;
+            ArrayList<String> options = new ArrayList<>();
+            final ArrayList<String> values = new ArrayList<>();
+            for (WebViewProviderInfo provider : providers) {
+                if (Utils.isPackageEnabled(this, provider.packageName)) {
+                    options.add(provider.description);
+                    values.add(provider.packageName);
+                    if (currentValue.contentEquals(provider.packageName)) {
+                        currentIndex = values.size() - 1;
+                    }
+                }
+            }
+
+            new AlertDialog.Builder(this)
+                    .setTitle(R.string.select_webview_provider_dialog_title)
+                    .setSingleChoiceItems(options.toArray(new String[0]), currentIndex,
+                            new OnClickListener() {
+                        @Override
+                        public void onClick(DialogInterface dialog, int which) {
+                            try {
+                                mWebViewUpdateService.changeProviderAndSetting(values.get(which));
+                            } catch (RemoteException e) {
+                                Log.w(TAG, "Problem reaching webviewupdate service", e);
+                            }
+                            finish();
+                        }
+                    }).setNegativeButton(android.R.string.cancel, null)
+                    .setOnCancelListener(this)
+                    .setOnDismissListener(this)
+                    .show();
+        } catch (RemoteException e) {
+            Log.w(TAG, "Problem reaching webviewupdate service", e);
+            finish();
+        }
+    }
+
+    @Override
+    protected int getMetricsCategory() {
+        return MetricsEvent.WEBVIEW_IMPLEMENTATION;
+    }
+
+    @Override
+    public void onCancel(DialogInterface dialog) {
+        finish();
+    }
+
+    @Override
+    public void onDismiss(DialogInterface dialog) {
+        finish();
+    }
+}
diff --git a/src/com/android/settings/applications/AppStateAppOpsBridge.java b/src/com/android/settings/applications/AppStateAppOpsBridge.java
index 59af46d..cfbb2fc 100644
--- a/src/com/android/settings/applications/AppStateAppOpsBridge.java
+++ b/src/com/android/settings/applications/AppStateAppOpsBridge.java
@@ -92,7 +92,8 @@
                 .getUserId(uid)));
         try {
             permissionState.packageInfo = mIPackageManager.getPackageInfo(pkg,
-                    PackageManager.GET_PERMISSIONS, permissionState.userHandle.getIdentifier());
+                    PackageManager.GET_PERMISSIONS | PackageManager.MATCH_UNINSTALLED_PACKAGES,
+                    permissionState.userHandle.getIdentifier());
             // Check static permission state (whatever that is declared in package manifest)
             String[] requestedPermissions = permissionState.packageInfo.requestedPermissions;
             int[] permissionFlags = permissionState.packageInfo.requestedPermissionsFlags;
diff --git a/src/com/android/settings/applications/ConfirmConvertToFbe.java b/src/com/android/settings/applications/ConfirmConvertToFbe.java
index 3687c05..76dcabc 100644
--- a/src/com/android/settings/applications/ConfirmConvertToFbe.java
+++ b/src/com/android/settings/applications/ConfirmConvertToFbe.java
@@ -23,9 +23,11 @@
 import android.view.ViewGroup;
 import android.widget.Button;
 
+import com.android.internal.logging.MetricsProto.MetricsEvent;
 import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
 
-public class ConfirmConvertToFbe extends Fragment {
+public class ConfirmConvertToFbe extends SettingsPreferenceFragment {
     static final String TAG = "ConfirmConvertToFBE";
 
     @Override
@@ -45,4 +47,9 @@
 
         return rootView;
     }
+
+    @Override
+    protected int getMetricsCategory() {
+        return MetricsEvent.CONVERT_FBE_CONFIRM;
+    }
 }
diff --git a/src/com/android/settings/applications/ConvertToFbe.java b/src/com/android/settings/applications/ConvertToFbe.java
index f32c52b..c1e6576 100644
--- a/src/com/android/settings/applications/ConvertToFbe.java
+++ b/src/com/android/settings/applications/ConvertToFbe.java
@@ -16,27 +16,24 @@
 package com.android.settings.applications;
 
 import android.app.Activity;
-import android.app.Fragment;
-import android.content.res.Resources;
 import android.content.Intent;
+import android.content.res.Resources;
 import android.os.Bundle;
-import android.os.RecoverySystem;
-import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.Button;
 
-import com.android.settings.applications.ConfirmConvertToFbe;
+import com.android.internal.logging.MetricsProto;
+import com.android.internal.logging.MetricsProto.MetricsEvent;
 import com.android.settings.ChooseLockSettingsHelper;
-import com.android.settings.SettingsActivity;
 import com.android.settings.R;
-
-import java.io.IOException;
+import com.android.settings.SettingsActivity;
+import com.android.settings.SettingsPreferenceFragment;
 
 /* Class to prompt for conversion of userdata to file based encryption
  */
-public class ConvertToFbe extends Fragment {
+public class ConvertToFbe extends SettingsPreferenceFragment {
     static final String TAG = "ConvertToFBE";
     static final String CONVERT_FBE_EXTRA = "ConvertFBE";
     private static final int KEYGUARD_REQUEST = 55;
@@ -85,4 +82,9 @@
         sa.startPreferencePanel(ConfirmConvertToFbe.class.getName(), null,
                                 R.string.convert_to_file_encryption, null, null, 0);
     }
+
+    @Override
+    protected int getMetricsCategory() {
+        return MetricsEvent.CONVERT_FBE;
+    }
 }
diff --git a/src/com/android/settings/applications/RunningServices.java b/src/com/android/settings/applications/RunningServices.java
index 1841f13..f50f3ad 100644
--- a/src/com/android/settings/applications/RunningServices.java
+++ b/src/com/android/settings/applications/RunningServices.java
@@ -24,10 +24,12 @@
 import android.view.View;
 import android.view.ViewGroup;
 
+import com.android.internal.logging.MetricsProto.MetricsEvent;
 import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
 import com.android.settings.Utils;
 
-public class RunningServices extends Fragment {
+public class RunningServices extends SettingsPreferenceFragment {
 
     private static final int SHOW_RUNNING_SERVICES = 1;
     private static final int SHOW_BACKGROUND_PROCESSES = 2;
@@ -105,6 +107,11 @@
         mOptionsMenu.findItem(SHOW_BACKGROUND_PROCESSES).setVisible(!showingBackground);
     }
 
+    @Override
+    protected int getMetricsCategory() {
+        return MetricsEvent.RUNNING_SERVICES;
+    }
+
     private final Runnable mRunningProcessesAvail = new Runnable() {
         @Override
         public void run() {
diff --git a/src/com/android/settings/dashboard/DashboardSummary.java b/src/com/android/settings/dashboard/DashboardSummary.java
index 67004e7..18b941c 100644
--- a/src/com/android/settings/dashboard/DashboardSummary.java
+++ b/src/com/android/settings/dashboard/DashboardSummary.java
@@ -142,6 +142,9 @@
                 MetricsLogger.hidden(getContext(), c.getMetricsConstant());
             }
         }
+        if (mAdapter.getSuggestions() == null) {
+            return;
+        }
         for (Tile suggestion : mAdapter.getSuggestions()) {
             MetricsLogger.action(getContext(), MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
                     DashboardAdapter.getSuggestionIdentifier(getContext(), suggestion));