Gray out location setting in secure camera

Bug: 7532731
Change-Id: I1f0c0341c226a79e4a3e50c8e3a6053c2b46a4f1
diff --git a/src/com/android/camera/PhotoController.java b/src/com/android/camera/PhotoController.java
index 26e8a36..2872867 100644
--- a/src/com/android/camera/PhotoController.java
+++ b/src/com/android/camera/PhotoController.java
@@ -152,6 +152,10 @@
                 R.layout.more_setting_popup, null, false);
         popup.setSettingChangedListener(this);
         popup.initialize(mPreferenceGroup, mOtherKeys);
+        if (mActivity.isSecureCamera()) {
+            // Prevent location preference from getting changed in secure camera mode
+            popup.setPreferenceEnabled(CameraSettings.KEY_RECORD_LOCATION, false);
+        }
         mPopup = popup;
     }
 
diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java
index 0a76b91..e767e73 100644
--- a/src/com/android/camera/PhotoModule.java
+++ b/src/com/android/camera/PhotoModule.java
@@ -483,6 +483,7 @@
         if (RecordLocationPreference.isSet(mPreferences)) {
             return;
         }
+        if (mActivity.isSecureCamera()) return;
         // Check if the back camera exists
         int backCameraId = CameraHolder.instance().getBackCameraId();
         if (backCameraId == -1) {
diff --git a/src/com/android/camera/VideoController.java b/src/com/android/camera/VideoController.java
index d78f0c5..d84c1ad 100644
--- a/src/com/android/camera/VideoController.java
+++ b/src/com/android/camera/VideoController.java
@@ -139,6 +139,10 @@
                 R.layout.more_setting_popup, null, false);
         popup.setSettingChangedListener(this);
         popup.initialize(mPreferenceGroup, mOtherKeys);
+        if (mActivity.isSecureCamera()) {
+            // Prevent location preference from getting changed in secure camera mode
+            popup.setPreferenceEnabled(CameraSettings.KEY_RECORD_LOCATION, false);
+        }
         mPopup = popup;
     }
 
diff --git a/src/com/android/camera/ui/MoreSettingPopup.java b/src/com/android/camera/ui/MoreSettingPopup.java
index 918d113..0fbe79b 100644
--- a/src/com/android/camera/ui/MoreSettingPopup.java
+++ b/src/com/android/camera/ui/MoreSettingPopup.java
@@ -136,6 +136,20 @@
         }
     }
 
+    // When preferences are disabled, we will display them grayed out. Users
+    // will not be able to change the disabled preferences, but they can still see
+    // the current value of the preferences
+    public void setPreferenceEnabled(String key, boolean enable) {
+        int count = mEnabled == null ? 0 : mEnabled.length;
+        for (int j = 0; j < count; j++) {
+            ListPreference pref = mListItem.get(j);
+            if (pref != null && key.equals(pref.getKey())) {
+                mEnabled[j] = enable;
+                break;
+            }
+        }
+    }
+
     public void onSettingChanged(ListPreference pref) {
         if (mListener != null) {
             mListener.onSettingChanged(pref);