Merge "SnapdragonCamera: fix invoke camera failture caused by permissions" into camera.lnx.1.0-dev.1.0
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index e316ee6..6ec0df3 100755
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -54,18 +54,6 @@
             android:taskAffinity="com.android.camera.CameraActivity"
             android:theme="@style/Theme.Camera"
             android:windowSoftInputMode="stateAlwaysHidden|adjustPan" >
-            <intent-filter>
-                <action android:name="android.media.action.IMAGE_CAPTURE" />
-                <category android:name="android.intent.category.DEFAULT" />
-            </intent-filter>
-            <intent-filter>
-                <action android:name="android.media.action.STILL_IMAGE_CAMERA" />
-                <category android:name="android.intent.category.DEFAULT" />
-            </intent-filter>
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.DEFAULT" />
-            </intent-filter>
 
             <meta-data
                 android:name="com.android.keyguard.layout"
@@ -95,13 +83,33 @@
             </intent-filter>
         </activity-alias>
 
+        <activity-alias
+            android:name="com.android.camera.PhotoCamera"
+            android:icon="@mipmap/ic_launcher_camera"
+            android:label="@string/snapcam_app_name"
+            android:launchMode="singleTop"
+            android:targetActivity="com.android.camera.PermissionsActivity">
+            <intent-filter>
+                <action android:name="android.media.action.IMAGE_CAPTURE" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+            <intent-filter>
+                <action android:name="android.media.action.STILL_IMAGE_CAMERA" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+        </activity-alias>
+
         <!-- Video camera and capture use the Camcorder label and icon. -->
         <activity-alias
             android:name="com.android.camera.VideoCamera"
             android:icon="@mipmap/ic_launcher_video_camera"
             android:label="@string/video_camera_label"
             android:launchMode="singleTop"
-            android:targetActivity="com.android.camera.CameraActivity">
+            android:targetActivity="com.android.camera.PermissionsActivity">
             <intent-filter>
                 <action android:name="android.media.action.VIDEO_CAMERA" />
                 <category android:name="android.intent.category.DEFAULT" />
diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java
index 1ebc3f0..e5c24ff 100755
--- a/src/com/android/camera/CameraActivity.java
+++ b/src/com/android/camera/CameraActivity.java
@@ -1681,8 +1681,7 @@
         } else {
             mHasCriticalPermissions = false;
         }
-        if ((checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) ||
-                !mHasCriticalPermissions) {
+        if (!mHasCriticalPermissions) {
             final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
             boolean isRequestShown = prefs.getBoolean(CameraSettings.KEY_REQUEST_PERMISSION, false);
             if(!isRequestShown || !mHasCriticalPermissions) {
diff --git a/src/com/android/camera/PermissionsActivity.java b/src/com/android/camera/PermissionsActivity.java
index c5e43e5..5ebe720 100644
--- a/src/com/android/camera/PermissionsActivity.java
+++ b/src/com/android/camera/PermissionsActivity.java
@@ -33,16 +33,20 @@
     private boolean mFlagHasMicrophonePermission;
     private boolean mFlagHasStoragePermission;
     private boolean mCriticalPermissionDenied;
+    private Intent mIntent;
+    private boolean mIsReturnResult;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+        mIntent = getIntent();
+        mIsReturnResult = false;
     }
 
     @Override
     protected void onResume() {
         super.onResume();
-        if (!mCriticalPermissionDenied) {
+        if (!mCriticalPermissionDenied && !mIsReturnResult) {
             mNumPermissionsToRequest = 0;
             checkPermissions();
         } else {
@@ -160,9 +164,16 @@
     }
 
     private void handlePermissionsSuccess() {
-        Intent intent = new Intent(this, CameraActivity.class);
-        startActivity(intent);
-        finish();
+        if (mIntent != null) {
+           mIsReturnResult = true;
+           mIntent.setClass(this, CameraActivity.class);
+           startActivityForResult(mIntent, 1);
+        } else {
+           mIsReturnResult = false;
+           Intent intent = new Intent(this, CameraActivity.class);
+           startActivity(intent);
+           finish();
+        }
     }
 
     private void handlePermissionsFailure() {
@@ -187,4 +198,11 @@
                 })
                 .show();
     }
+
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+        super.onActivityResult(requestCode, resultCode, data);
+        setResult(resultCode, data);
+        finish();
+    }
 }