diff options
Diffstat (limited to 'java/com/android/dialer')
4 files changed, 31 insertions, 11 deletions
diff --git a/java/com/android/dialer/callcomposer/CameraComposerFragment.java b/java/com/android/dialer/callcomposer/CameraComposerFragment.java index d55f3222c..a5c65fd9d 100644 --- a/java/com/android/dialer/callcomposer/CameraComposerFragment.java +++ b/java/com/android/dialer/callcomposer/CameraComposerFragment.java @@ -18,13 +18,11 @@ package com.android.dialer.callcomposer; import android.Manifest; import android.content.Intent; -import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.graphics.drawable.Animatable; import android.hardware.Camera.CameraInfo; import android.net.Uri; import android.os.Bundle; -import android.preference.PreferenceManager; import android.provider.Settings; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -57,7 +55,6 @@ import com.android.dialer.util.PermissionsUtil; public class CameraComposerFragment extends CallComposerFragment implements CameraManagerListener, OnClickListener, CameraManager.MediaCallback { - private static final String CAMERA_PRIVACY_PREF = "camera_privacy_permission"; private static final String CAMERA_DIRECTION_KEY = "camera_direction"; private static final String CAMERA_URI_KEY = "camera_key"; @@ -134,11 +131,8 @@ public class CameraComposerFragment extends CallComposerFragment } private void setupCamera() { - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext()); - if (!preferences.getBoolean(CAMERA_PRIVACY_PREF, false)) { - Toast.makeText(getContext(), getString(R.string.camera_privacy_text), Toast.LENGTH_LONG) - .show(); - preferences.edit().putBoolean(CAMERA_PRIVACY_PREF, true).apply(); + if (!PermissionsUtil.hasCameraPrivacyToastShown(getContext())) { + PermissionsUtil.showCameraPermissionToast(getContext()); } CameraManager.get().setListener(this); preview.setShown(); @@ -403,6 +397,7 @@ public class CameraComposerFragment extends CallComposerFragment Logger.get(getContext()).logImpression(DialerImpression.Type.CAMERA_PERMISSION_GRANTED); LogUtil.i("CameraComposerFragment.onRequestPermissionsResult", "Permission granted."); permissionView.setVisibility(View.GONE); + PermissionsUtil.setCameraPrivacyToastShown(getContext()); setupCamera(); } else if (requestCode == CAMERA_PERMISSION) { Logger.get(getContext()).logImpression(DialerImpression.Type.CAMERA_PERMISSION_DENIED); diff --git a/java/com/android/dialer/theme/res/values/strings.xml b/java/com/android/dialer/theme/res/values/strings.xml index af61d3596..74cabadf7 100644 --- a/java/com/android/dialer/theme/res/values/strings.xml +++ b/java/com/android/dialer/theme/res/values/strings.xml @@ -30,9 +30,6 @@ used in the Launcher icon. --> <string name="launcherActivityLabel">Phone</string> - <!-- Text presented to the user explaining that we have enabled the camera permission automatically --> - <string name="camera_privacy_text">Camera permission enabled</string> - <!-- text on a button, Video call, as in to place a video call. --> <string name="video_call">Video call</string> diff --git a/java/com/android/dialer/util/PermissionsUtil.java b/java/com/android/dialer/util/PermissionsUtil.java index 34828317d..cb973680d 100644 --- a/java/com/android/dialer/util/PermissionsUtil.java +++ b/java/com/android/dialer/util/PermissionsUtil.java @@ -38,6 +38,7 @@ import android.content.pm.PackageManager; import android.support.annotation.NonNull; import android.support.v4.content.ContextCompat; import android.support.v4.content.LocalBroadcastManager; +import android.widget.Toast; import com.android.dialer.common.LogUtil; import java.util.ArrayList; import java.util.Arrays; @@ -47,6 +48,7 @@ import java.util.List; /** Utility class to help with runtime permissions. */ public class PermissionsUtil { + private static final String PREFERENCE_CAMERA_ALLOWED_BY_USER = "camera_allowed_by_user"; private static final String PERMISSION_PREFERENCE = "dialer_permissions"; private static final String CEQUINT_PERMISSION = "com.cequint.ecid.CALLER_ID_LOOKUP"; @@ -207,4 +209,28 @@ public class PermissionsUtil { } return permissionsCurrentlyDenied.toArray(new String[permissionsCurrentlyDenied.size()]); } + + /** + * Since we are granted the camera permission automatically as a first-party app, we need to show + * a toast to let users know the permission was granted for privacy reasons. + * + * @return true if we've already shown the camera privacy toast. + */ + public static boolean hasCameraPrivacyToastShown(@NonNull Context context) { + return DialerUtils.getDefaultSharedPreferenceForDeviceProtectedStorageContext(context) + .getBoolean(PREFERENCE_CAMERA_ALLOWED_BY_USER, false); + } + + public static void showCameraPermissionToast(@NonNull Context context) { + Toast.makeText(context, context.getString(R.string.camera_privacy_text), Toast.LENGTH_LONG) + .show(); + setCameraPrivacyToastShown(context); + } + + public static void setCameraPrivacyToastShown(@NonNull Context context) { + DialerUtils.getDefaultSharedPreferenceForDeviceProtectedStorageContext(context) + .edit() + .putBoolean(PREFERENCE_CAMERA_ALLOWED_BY_USER, true) + .apply(); + } } diff --git a/java/com/android/dialer/util/res/values/strings.xml b/java/com/android/dialer/util/res/values/strings.xml index 43ea6e31a..a4d944c19 100644 --- a/java/com/android/dialer/util/res/values/strings.xml +++ b/java/com/android/dialer/util/res/values/strings.xml @@ -39,4 +39,6 @@ <!-- Text for button which indicates that the user wants to proceed with an action. --> <string name="dialog_continue">Continue</string> + <!-- Text presented to the user explaining that we have enabled the camera permission automatically [CHAR LIMIT=NONE] --> + <string name="camera_privacy_text">Camera permission enabled</string> </resources> |