summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Wang <jaywang@codeaurora.org>2016-07-20 01:11:05 (GMT)
committerSteve Kondik <steve@cyngn.com>2016-08-18 22:07:20 (GMT)
commit7d7a688e13c9ae8e958387ba0207c7a4af0e4df0 (patch)
tree666b825fc98eb5dbcb7f71bd9cd83448b7c74db8
parent219fbf4d3d7c47039c79822af26bace2849375e4 (diff)
downloadandroid_packages_apps_Snap-7d7a688e13c9ae8e958387ba0207c7a4af0e4df0.zip
android_packages_apps_Snap-7d7a688e13c9ae8e958387ba0207c7a4af0e4df0.tar.gz
android_packages_apps_Snap-7d7a688e13c9ae8e958387ba0207c7a4af0e4df0.tar.bz2
SnapdragonCamera: Remove custom location permission request window
When user enables the GPS locaion setting, use Android's run-time permission request interface to get the permission. Change-Id: Ib17171aeff5ccf20e2b00da08243dee1a3383611 CRs-Fixed: 1038039
-rw-r--r--src/com/android/camera/CameraActivity.java34
-rw-r--r--src/com/android/camera/CameraModule.java4
-rw-r--r--src/com/android/camera/LocationManager.java45
-rw-r--r--src/com/android/camera/PhotoMenu.java5
-rw-r--r--src/com/android/camera/PhotoModule.java24
-rw-r--r--src/com/android/camera/PhotoUI.java42
-rw-r--r--src/com/android/camera/VideoMenu.java5
-rw-r--r--src/com/android/camera/VideoModule.java26
-rw-r--r--src/com/android/camera/WideAnglePanoramaModule.java18
9 files changed, 136 insertions, 67 deletions
diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java
index a22a7ae..0e0978d 100644
--- a/src/com/android/camera/CameraActivity.java
+++ b/src/com/android/camera/CameraActivity.java
@@ -162,6 +162,9 @@ public class CameraActivity extends Activity
private static final int HIDE_ACTION_BAR = 1;
private static final long SHOW_ACTION_BAR_TIMEOUT_MS = 3000;
+ /** Permission request code */
+ private static final int PERMISSIONS_REQUEST_ACCESS_COARSE_LOCATION = 1;
+
/** Whether onResume should reset the view to the preview. */
private boolean mResetToPreviewOnResume = true;
@@ -1971,6 +1974,37 @@ public class CameraActivity extends Activity
return mInCameraApp;
}
+ public void requestLocationPermission() {
+ if (checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION)
+ != PackageManager.PERMISSION_GRANTED) {
+ Log.v(TAG, "Request Location permission");
+ mCurrentModule.waitingLocationPermissionResult(true);
+ requestPermissions(
+ new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
+ PERMISSIONS_REQUEST_ACCESS_COARSE_LOCATION);
+ }
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode,
+ String permissions[], int[] grantResults) {
+ switch (requestCode) {
+ case PERMISSIONS_REQUEST_ACCESS_COARSE_LOCATION: {
+ // If request is cancelled, the result arrays are empty.
+ mCurrentModule.waitingLocationPermissionResult(false);
+ if (grantResults.length > 0
+ && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ Log.v(TAG, "Location permission is granted");
+ mCurrentModule.enableRecordingLocation(true);
+ } else {
+ Log.w(TAG, "Location permission is denied");
+ mCurrentModule.enableRecordingLocation(false);
+ }
+ break;
+ }
+ }
+ }
+
@Override
public void onModuleSelected(int moduleIndex) {
if (mCurrentModuleIndex == moduleIndex) {
diff --git a/src/com/android/camera/CameraModule.java b/src/com/android/camera/CameraModule.java
index 2c8f5a9..9de1674 100644
--- a/src/com/android/camera/CameraModule.java
+++ b/src/com/android/camera/CameraModule.java
@@ -70,4 +70,8 @@ public interface CameraModule {
public void resizeForPreviewAspectRatio();
public void onSwitchSavePath();
+
+ public void waitingLocationPermissionResult(boolean waiting);
+
+ public void enableRecordingLocation(boolean enable);
}
diff --git a/src/com/android/camera/LocationManager.java b/src/com/android/camera/LocationManager.java
index fcf21b6..49009d7 100644
--- a/src/com/android/camera/LocationManager.java
+++ b/src/com/android/camera/LocationManager.java
@@ -26,12 +26,14 @@ import android.util.Log;
* A class that handles everything about location.
*/
public class LocationManager {
- private static final String TAG = "LocationManager";
+ public static final int LOC_MNGR_ERR_PERM_DENY = 1;
+ private static final String TAG = "LocationManager";
private Context mContext;
private Listener mListener;
private android.location.LocationManager mLocationManager;
private boolean mRecordLocation;
+ private boolean mWaitingLocPermResult = false;
LocationListener [] mLocationListeners = new LocationListener[] {
new LocationListener(android.location.LocationManager.GPS_PROVIDER),
@@ -39,9 +41,8 @@ public class LocationManager {
};
public interface Listener {
- public void showGpsOnScreenIndicator(boolean hasSignal);
- public void hideGpsOnScreenIndicator();
- }
+ public void onErrorListener(int error);
+ }
public LocationManager(Context context, Listener listener) {
mContext = context;
@@ -62,15 +63,23 @@ public class LocationManager {
public void recordLocation(boolean recordLocation) {
if (mRecordLocation != recordLocation) {
- mRecordLocation = recordLocation;
- if (recordLocation) {
- startReceivingLocationUpdates();
- } else {
- stopReceivingLocationUpdates();
+ /* Don't change the location until permission request
+ result is received */
+ if (!mWaitingLocPermResult) {
+ mRecordLocation = recordLocation;
+ if (recordLocation) {
+ startReceivingLocationUpdates();
+ } else {
+ stopReceivingLocationUpdates();
+ }
}
}
}
+ public void waitingLocationPermissionResult(boolean waitingResult) {
+ mWaitingLocPermResult = waitingResult;
+ }
+
private void startReceivingLocationUpdates() {
if (mLocationManager == null) {
mLocationManager = (android.location.LocationManager)
@@ -85,6 +94,9 @@ public class LocationManager {
mLocationListeners[1]);
} catch (SecurityException ex) {
Log.i(TAG, "fail to request location update, ignore", ex);
+ if (mListener != null) mListener.onErrorListener(LOC_MNGR_ERR_PERM_DENY);
+ recordLocation(false);
+ return;
} catch (IllegalArgumentException ex) {
Log.d(TAG, "provider does not exist " + ex.getMessage());
}
@@ -94,9 +106,11 @@ public class LocationManager {
1000,
0F,
mLocationListeners[0]);
- if (mListener != null) mListener.showGpsOnScreenIndicator(false);
} catch (SecurityException ex) {
Log.i(TAG, "fail to request location update, ignore", ex);
+ if (mListener != null) mListener.onErrorListener(LOC_MNGR_ERR_PERM_DENY);
+ recordLocation(false);
+ return;
} catch (IllegalArgumentException ex) {
Log.d(TAG, "provider does not exist " + ex.getMessage());
}
@@ -115,7 +129,6 @@ public class LocationManager {
}
Log.d(TAG, "stopReceivingLocationUpdates");
}
- if (mListener != null) mListener.hideGpsOnScreenIndicator();
}
private class LocationListener
@@ -136,12 +149,6 @@ public class LocationManager {
// Hack to filter out 0.0,0.0 locations
return;
}
- // If GPS is available before start camera, we won't get status
- // update so update GPS indicator when we receive data.
- if (mListener != null && mRecordLocation &&
- android.location.LocationManager.GPS_PROVIDER.equals(mProvider)) {
- mListener.showGpsOnScreenIndicator(true);
- }
if (!mValid) {
Log.d(TAG, "Got first location.");
}
@@ -165,10 +172,6 @@ public class LocationManager {
case LocationProvider.OUT_OF_SERVICE:
case LocationProvider.TEMPORARILY_UNAVAILABLE: {
mValid = false;
- if (mListener != null && mRecordLocation &&
- android.location.LocationManager.GPS_PROVIDER.equals(provider)) {
- mListener.showGpsOnScreenIndicator(false);
- }
break;
}
}
diff --git a/src/com/android/camera/PhotoMenu.java b/src/com/android/camera/PhotoMenu.java
index 6b40e0c..df278a9 100644
--- a/src/com/android/camera/PhotoMenu.java
+++ b/src/com/android/camera/PhotoMenu.java
@@ -1181,6 +1181,11 @@ public class PhotoMenu extends MenuController
}
updateFilterModeIcon(pref, pref);
+
+ if (same(pref, CameraSettings.KEY_RECORD_LOCATION, "on")) {
+ mActivity.requestLocationPermission();
+ }
+
super.onSettingChanged(pref);
}
diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java
index ea717a4..e12ffc5 100644
--- a/src/com/android/camera/PhotoModule.java
+++ b/src/com/android/camera/PhotoModule.java
@@ -110,6 +110,7 @@ public class PhotoModule
ShutterButton.OnShutterButtonListener,
MediaSaveService.Listener,
OnCountDownFinishedListener,
+ LocationManager.Listener,
SensorEventListener {
private static final String TAG = "CAM_PhotoModule";
@@ -571,7 +572,7 @@ public class PhotoModule
mUI = new PhotoUI(activity, this, parent);
initializeControlByIntent();
mQuickCapture = mActivity.getIntent().getBooleanExtra(EXTRA_QUICK_CAPTURE, false);
- mLocationManager = new LocationManager(mActivity, mUI);
+ mLocationManager = new LocationManager(mActivity, this);
mSensorManager = (SensorManager)(mActivity.getSystemService(Context.SENSOR_SERVICE));
Storage.setSaveSDCard(
@@ -620,13 +621,23 @@ public class PhotoModule
}
mLocationPromptTriggered = true;
- mUI.showLocationDialog();
+
+ /* Enable the location at the begining, always.
+ If the user denies the permission, it will be disabled
+ right away due to exception */
+ enableRecordingLocation(true);
+ }
+
+ @Override
+ public void waitingLocationPermissionResult(boolean result) {
+ mLocationManager.waitingLocationPermissionResult(result);
}
@Override
public void enableRecordingLocation(boolean enable) {
setLocationPreference(enable ? RecordLocationPreference.VALUE_ON
: RecordLocationPreference.VALUE_OFF);
+ mLocationManager.recordLocation(enable);
}
@Override
@@ -672,7 +683,9 @@ public class PhotoModule
.apply();
// TODO: Fix this to use the actual onSharedPreferencesChanged listener
// instead of invoking manually
- onSharedPreferenceChanged();
+ if (mUI.mMenuInitialized) {
+ onSharedPreferenceChanged();
+ }
}
private void onCameraOpened() {
@@ -4732,4 +4745,9 @@ public class PhotoModule
return ((mCameraState == LONGSHOT) && (mLongshotSnapNum == mReceivedSnapNum) &&
!mLongshotActive);
}
+
+ @Override
+ public void onErrorListener(int error) {
+ enableRecordingLocation(false);
+ }
}
diff --git a/src/com/android/camera/PhotoUI.java b/src/com/android/camera/PhotoUI.java
index 7762d14..bacffe6 100644
--- a/src/com/android/camera/PhotoUI.java
+++ b/src/com/android/camera/PhotoUI.java
@@ -79,7 +79,6 @@ import com.android.camera.util.CameraUtil;
public class PhotoUI implements PieListener,
PreviewGestures.SingleTapListener,
SurfaceHolder.Callback,
- LocationManager.Listener,
CameraRootView.MyDisplayListener,
CameraManager.CameraFaceDetectionCallback {
@@ -648,41 +647,6 @@ public class PhotoUI implements PieListener,
}
}
- public void showLocationDialog() {
- mLocationDialog = new AlertDialog.Builder(mActivity)
- .setTitle(R.string.remember_location_title)
- .setMessage(R.string.remember_location_prompt)
- .setPositiveButton(R.string.remember_location_yes,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int arg1) {
- mController.enableRecordingLocation(true);
- mLocationDialog = null;
- }
- })
- .setNegativeButton(R.string.remember_location_no,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int arg1) {
- dialog.cancel();
- }
- })
- .setOnCancelListener(new DialogInterface.OnCancelListener() {
- @Override
- public void onCancel(DialogInterface dialog) {
- mController.enableRecordingLocation(false);
- mLocationDialog = null;
- }
- })
- .setOnDismissListener(new DialogInterface.OnDismissListener() {
- @Override
- public void onDismiss(DialogInterface dialog) {
- mActivity.setSystemBarsVisibility(false);
- }
- })
- .show();
- }
-
public void initializeZoom(Camera.Parameters params) {
if ((params == null) || !params.isZoomSupported()
|| (mZoomRenderer == null)) return;
@@ -698,12 +662,6 @@ public class PhotoUI implements PieListener,
}
}
- @Override
- public void showGpsOnScreenIndicator(boolean hasSignal) { }
-
- @Override
- public void hideGpsOnScreenIndicator() { }
-
public void overrideSettings(final String ... keyvalues) {
if (mMenu == null)
return;
diff --git a/src/com/android/camera/VideoMenu.java b/src/com/android/camera/VideoMenu.java
index 196adba..0da3e11 100644
--- a/src/com/android/camera/VideoMenu.java
+++ b/src/com/android/camera/VideoMenu.java
@@ -800,6 +800,11 @@ public class VideoMenu extends MenuController
}
setPreference(CameraSettings.KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL, defaultValue);
}
+
+ if (notSame(pref, CameraSettings.KEY_RECORD_LOCATION, "off")) {
+ mActivity.requestLocationPermission();
+ }
+
super.onSettingChanged(pref);
}
diff --git a/src/com/android/camera/VideoModule.java b/src/com/android/camera/VideoModule.java
index a9e6074..ed20b91 100644
--- a/src/com/android/camera/VideoModule.java
+++ b/src/com/android/camera/VideoModule.java
@@ -85,6 +85,7 @@ public class VideoModule implements CameraModule,
FocusOverlayManager.Listener,
CameraPreference.OnPreferenceChangedListener,
ShutterButton.OnShutterButtonListener,
+ LocationManager.Listener,
MediaRecorder.OnErrorListener,
MediaRecorder.OnInfoListener {
@@ -497,7 +498,7 @@ public class VideoModule implements CameraModule,
mUI.setPrefChangedListener(this);
mQuickCapture = mActivity.getIntent().getBooleanExtra(EXTRA_QUICK_CAPTURE, false);
- mLocationManager = new LocationManager(mActivity, null);
+ mLocationManager = new LocationManager(mActivity, this);
mUI.setOrientationIndicator(0, false);
setDisplayOrientation();
@@ -564,6 +565,23 @@ public class VideoModule implements CameraModule,
}
}
+ @Override
+ public void waitingLocationPermissionResult(boolean result) {
+ mLocationManager.waitingLocationPermissionResult(result);
+ }
+
+ @Override
+ public void enableRecordingLocation(boolean enable) {
+ String value = (enable ? RecordLocationPreference.VALUE_ON
+ : RecordLocationPreference.VALUE_OFF);
+ if (mPreferences != null) {
+ mPreferences.edit()
+ .putString(CameraSettings.KEY_RECORD_LOCATION, value)
+ .apply();
+ }
+ mLocationManager.recordLocation(enable);
+ }
+
// SingleTapListener
// Preview area is touched. Take a picture.
@Override
@@ -3011,4 +3029,10 @@ public class VideoModule implements CameraModule,
resumeVideoRecording();
}
+ @Override
+ public void onErrorListener(int error) {
+ enableRecordingLocation(false);
+ }
+
}
+
diff --git a/src/com/android/camera/WideAnglePanoramaModule.java b/src/com/android/camera/WideAnglePanoramaModule.java
index 647e67e..6068ef2 100644
--- a/src/com/android/camera/WideAnglePanoramaModule.java
+++ b/src/com/android/camera/WideAnglePanoramaModule.java
@@ -895,6 +895,24 @@ public class WideAnglePanoramaModule
}
@Override
+ public void waitingLocationPermissionResult(boolean result) {
+ mLocationManager.waitingLocationPermissionResult(result);
+ }
+
+ @Override
+ public void enableRecordingLocation(boolean enable) {
+ String value = (enable ? RecordLocationPreference.VALUE_ON
+ : RecordLocationPreference.VALUE_OFF);
+ if (mPreferences != null) {
+ mPreferences.edit()
+ .putString(CameraSettings.KEY_RECORD_LOCATION, value)
+ .apply();
+ }
+
+ mLocationManager.recordLocation(enable);
+ }
+
+ @Override
public void onPauseBeforeSuper() {
mPaused = true;
if (mLocationManager != null) mLocationManager.recordLocation(false);