Merge "Import translations. DO NOT MERGE" into klp-dev
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 684811c..fd28fa0 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -81,4 +81,6 @@
         <attr name="fillColor" format="color" />
         <attr name="fillColorSecondary" format="color" />
     </declare-styleable>
+
+    <attr name="apnPreferenceStyle" format="reference" />
 </resources>
diff --git a/res/values/themes.xml b/res/values/themes.xml
index 615988f..805214f 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -26,5 +26,6 @@
         <item name="@*android:preferenceListStyle">@style/PreferenceHeaderListSinglePane</item>
         <item name="@*android:preferenceFragmentListStyle">@style/PreferenceFragmentListSinglePane</item>
         <item name="@*android:preferenceFragmentPaddingSide">@dimen/settings_side_margin</item>
+        <item name="apnPreferenceStyle">@style/ApnPreference</item>
     </style>
 </resources>
diff --git a/src/com/android/settings/ApnPreference.java b/src/com/android/settings/ApnPreference.java
index 9d32a71..addb695 100644
--- a/src/com/android/settings/ApnPreference.java
+++ b/src/com/android/settings/ApnPreference.java
@@ -40,7 +40,7 @@
     }
 
     public ApnPreference(Context context, AttributeSet attrs) {
-        this(context, attrs, R.style.ApnPreference);
+        this(context, attrs, R.attr.apnPreferenceStyle);
     }
 
     public ApnPreference(Context context) {
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index df49cec..f365403 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -85,7 +85,7 @@
     private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
 
     private PackageManager mPM;
-    DevicePolicyManager mDPM;
+    private DevicePolicyManager mDPM;
 
     private ChooseLockSettingsHelper mChooseLockSettingsHelper;
     private LockPatternUtils mLockPatternUtils;
@@ -168,9 +168,6 @@
 
 
         // Add options for device encryption
-        DevicePolicyManager dpm =
-                (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
-
         mIsPrimary = UserHandle.myUserId() == UserHandle.USER_OWNER;
 
         if (!mIsPrimary) {
@@ -186,7 +183,7 @@
         }
 
         if (mIsPrimary) {
-            switch (dpm.getStorageEncryptionStatus()) {
+            switch (mDPM.getStorageEncryptionStatus()) {
             case DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE:
                 // The device is currently encrypted.
                 addPreferencesFromResource(R.xml.security_settings_encrypted);
@@ -264,8 +261,8 @@
 
         // Credential storage
         final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
+        mKeyStore = KeyStore.getInstance(); // needs to be initialized for onResume()
         if (!um.hasUserRestriction(UserManager.DISALLOW_CONFIG_CREDENTIALS)) {
-            mKeyStore = KeyStore.getInstance();
             Preference credentialStorageType = root.findPreference(KEY_CREDENTIAL_STORAGE_TYPE);
 
             final int storageSummaryRes =
diff --git a/src/com/android/settings/location/LocationSettings.java b/src/com/android/settings/location/LocationSettings.java
index 1c9409c..818ec2b 100644
--- a/src/com/android/settings/location/LocationSettings.java
+++ b/src/com/android/settings/location/LocationSettings.java
@@ -180,8 +180,8 @@
                 injector.reloadStatusMessages();
             }
         };
-        activity.registerReceiver(
-                mReceiver, new IntentFilter(SettingInjectorService.UPDATE_INTENT));
+        activity.registerReceiver(mReceiver,
+                new IntentFilter(SettingInjectorService.ACTION_INJECTED_SETTING_CHANGED));
 
         if (locationServices.size() > 0) {
             addPreferencesSorted(locationServices, categoryLocationServices);
diff --git a/src/com/android/settings/location/LocationSettingsBase.java b/src/com/android/settings/location/LocationSettingsBase.java
index 415e343..5637b25 100644
--- a/src/com/android/settings/location/LocationSettingsBase.java
+++ b/src/com/android/settings/location/LocationSettingsBase.java
@@ -17,7 +17,6 @@
 package com.android.settings.location;
 
 import android.content.ContentQueryMap;
-import android.content.ContentResolver;
 import android.content.Context;
 import android.database.Cursor;
 import android.os.UserManager;
@@ -79,13 +78,13 @@
         if (um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
             return;
         }
-        Settings.Secure.setLocationMode(getContentResolver(), mode);
+        Settings.Secure.putInt(getContentResolver(), Settings.Secure.LOCATION_MODE, mode);
         refreshLocationMode();
     }
 
     public void refreshLocationMode() {
-        ContentResolver res = getContentResolver();
-        int mode = Settings.Secure.getLocationMode(getContentResolver());
+        int mode = Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCATION_MODE,
+                Settings.Secure.LOCATION_MODE_OFF);
         onModeChanged(mode);
     }
 }
diff --git a/src/com/android/settings/location/SettingsInjector.java b/src/com/android/settings/location/SettingsInjector.java
index 532304d..22e2413 100644
--- a/src/com/android/settings/location/SettingsInjector.java
+++ b/src/com/android/settings/location/SettingsInjector.java
@@ -56,9 +56,6 @@
  * Code-sharing would require extracting {@link
  * android.content.pm.RegisteredServicesCache#parseServiceAttributes(android.content.res.Resources,
  * String, android.util.AttributeSet)} into an interface, which didn't seem worth it.
- *
- * TODO: register a broadcast receiver that calls updateUI() when it receives
- * {@link SettingInjectorService#UPDATE_INTENT}.
  */
 class SettingsInjector {
     static final String TAG = "SettingsInjector";
@@ -278,8 +275,8 @@
         /**
          * Settings whose status values need to be loaded. A set is used to prevent redundant loads
          * even if {@link #reloadStatusMessages()} is called many times in rapid succession (for
-         * example, if we receive a lot of
-         * {@link android.location.SettingInjectorService#UPDATE_INTENT} broadcasts).
+         * example, if we receive a lot of {@link
+         * android.location.SettingInjectorService#ACTION_INJECTED_SETTING_CHANGED} broadcasts).
          * <p/>
          * We use a linked hash set to ensure that when {@link #reloadStatusMessages()} is called,
          * any settings that haven't been loaded yet will finish loading before any already-loaded
@@ -386,12 +383,12 @@
                 @Override
                 public void handleMessage(Message msg) {
                     Bundle bundle = msg.getData();
-                    String status = bundle.getString(SettingInjectorService.STATUS_KEY);
+                    String summary = bundle.getString(SettingInjectorService.SUMMARY_KEY);
                     boolean enabled = bundle.getBoolean(SettingInjectorService.ENABLED_KEY, true);
                     if (Log.isLoggable(TAG, Log.DEBUG)) {
                         Log.d(TAG, setting + ": received " + msg + ", bundle: " + bundle);
                     }
-                    preference.setSummary(status);
+                    preference.setSummary(summary);
                     preference.setEnabled(enabled);
                     mHandler.sendMessage(
                             mHandler.obtainMessage(WHAT_RECEIVED_STATUS, Setting.this));
diff --git a/src/com/android/settings/users/AppRestrictionsFragment.java b/src/com/android/settings/users/AppRestrictionsFragment.java
index ff69f2b..96a7b47 100644
--- a/src/com/android/settings/users/AppRestrictionsFragment.java
+++ b/src/com/android/settings/users/AppRestrictionsFragment.java
@@ -479,13 +479,24 @@
                 PackageManager.GET_DISABLED_COMPONENTS | PackageManager.GET_UNINSTALLED_PACKAGES);
         for (ResolveInfo app : launchableApps) {
             if (app.activityInfo != null && app.activityInfo.applicationInfo != null) {
+                final String packageName = app.activityInfo.packageName;
                 int flags = app.activityInfo.applicationInfo.flags;
                 if ((flags & ApplicationInfo.FLAG_SYSTEM) != 0
                         || (flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
                     // System app
                     // Skip excluded packages
-                    if (excludePackages.contains(app.activityInfo.packageName)) continue;
-
+                    if (excludePackages.contains(packageName)) continue;
+                    int enabled = pm.getApplicationEnabledSetting(packageName);
+                    if (enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED
+                            || enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
+                        // Check if the app is already enabled for the target user
+                        ApplicationInfo targetUserAppInfo = getAppInfoForUser(packageName,
+                                0, mUser);
+                        if (targetUserAppInfo == null
+                                || (targetUserAppInfo.flags&ApplicationInfo.FLAG_INSTALLED) == 0) {
+                            continue;
+                        }
+                    }
                     SelectableAppInfo info = new SelectableAppInfo();
                     info.packageName = app.activityInfo.packageName;
                     info.appName = app.activityInfo.applicationInfo.loadLabel(pm);
@@ -499,6 +510,16 @@
         }
     }
 
+    private ApplicationInfo getAppInfoForUser(String packageName, int flags, UserHandle user) {
+        try {
+            ApplicationInfo targetUserAppInfo = mIPm.getApplicationInfo(packageName, flags,
+                    user.getIdentifier());
+            return targetUserAppInfo;
+        } catch (RemoteException re) {
+            return null;
+        }
+    }
+
     private class AppLoadingTask extends AsyncTask<Void, Void, Void> {
 
         @Override
@@ -567,6 +588,7 @@
             }
         }
 
+        // Get the list of apps already installed for the user
         mUserApps = null;
         try {
             mUserApps = ipm.getInstalledApplications(
@@ -590,6 +612,8 @@
                 }
             }
         }
+
+        // Sort the list of visible apps
         Collections.sort(mVisibleApps, new AppLabelComparator());
 
         // Remove dupes
diff --git a/src/com/android/settings/widget/SettingsAppWidgetProvider.java b/src/com/android/settings/widget/SettingsAppWidgetProvider.java
index 71994a9..da085f7 100644
--- a/src/com/android/settings/widget/SettingsAppWidgetProvider.java
+++ b/src/com/android/settings/widget/SettingsAppWidgetProvider.java
@@ -521,7 +521,8 @@
         @Override
         public int getActualState(Context context) {
             ContentResolver resolver = context.getContentResolver();
-            int currentLocationMode = Settings.Secure.getLocationMode(resolver);
+            int currentLocationMode = Settings.Secure.getInt(resolver,
+                    Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
             switch (currentLocationMode) {
                 case Settings.Secure.LOCATION_MODE_BATTERY_SAVING:
                 case Settings.Secure.LOCATION_MODE_OFF:
@@ -550,7 +551,7 @@
                         int mode = desiredState
                                 ? Settings.Secure.LOCATION_MODE_HIGH_ACCURACY
                                 : Settings.Secure.LOCATION_MODE_BATTERY_SAVING;
-                        Settings.Secure.setLocationMode(resolver, mode);
+                        Settings.Secure.putInt(resolver, Settings.Secure.LOCATION_MODE, mode);
                         return desiredState;
                     }