Skip to content

Commit

Permalink
fix permission bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Renzo Duin committed Aug 5, 2021
1 parent ad48712 commit 3b38506
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 29 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ gen/

# Proguard folder generated by Eclipse
proguard/

# Sigining keys
signing

gradle*.properties
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "disabled"
}
17 changes: 17 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,21 @@ android {
versionCode 1
versionName '1.0.0'
}

/*signingConfigs {
release {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
// Optional, specify signing versions used
v3SigningEnabled true
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}*/
}
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.android.apps.photos">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission-sdk-23 android:name="android.permission.WRITE_MEDIA_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<application android:label="@string/app_name">
<activity android:name="com.google.android.apps.photos.MainActivity" android:exported="true" android:label="@string/app_name" android:theme="@android:style/Theme.NoDisplay">
Expand Down
50 changes: 43 additions & 7 deletions app/src/main/java/com/google/android/apps/photos/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@
import android.provider.MediaStore;
import android.content.Context;
import android.app.PendingIntent;
import android.Manifest;
import android.content.pm.PackageManager;

public class MainActivity extends Activity {

private static final int waitMS = 100;
private static final int maximumSeconds = 30000;
private static final int iterations = maximumSeconds * 1000 / waitMS;

private static final int PERMISSIONS_INT = 755009201;

private PendingIntent cameraRelaunchIntent;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -36,7 +42,20 @@ protected void onCreate(Bundle savedInstanceState) {

Uri processingURI = (Uri) receivedIntent.getParcelableExtra("processing_uri_intent_extra");

PendingIntent cameraRelaunchIntent = (PendingIntent) receivedIntent.getParcelableExtra("CAMERA_RELAUNCH_INTENT_EXTRA");
this.cameraRelaunchIntent = (PendingIntent) receivedIntent.getParcelableExtra("CAMERA_RELAUNCH_INTENT_EXTRA");

if (SessionId == null) {
finish();
return;
}

if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
Log.i("PhotosShim", "No permission, requesting them");

requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, PERMISSIONS_INT);

return;
}

Log.i("PhotosShim", "SessionId: '" + SessionId + "', URI:'" + uri + "', type: '" + type + "', processingURI: '"
+ processingURI + "'");
Expand Down Expand Up @@ -75,12 +94,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

if (!success) {
try {
cameraRelaunchIntent.send();
} catch (Exception e) {
Log.e("PhotosShim", "Error sending intent", e);
}
finish();
quit();
return;
}

Expand All @@ -92,6 +106,28 @@ protected void onCreate(Bundle savedInstanceState) {
finish();
}

private void quit() {
try {
if (this.cameraRelaunchIntent != null)
this.cameraRelaunchIntent.send();
} catch (Exception e) {
Log.e("PhotosShim", "Error sending intent", e);
}
finish();
return;
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode != PERMISSIONS_INT)
return;
if (permissions.length == 0 || grantResults.length == 0)
return;

if (permissions[0] == Manifest.permission.READ_EXTERNAL_STORAGE)
quit();
}

public static String getRealPathFromURI(Context context, Uri contentUri) {
Cursor cursor = null;
String result = "";
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

buildscript {
repositories {
jcenter()
mavenCentral()
google()
}
dependencies {
Expand All @@ -20,7 +20,7 @@ buildscript {

allprojects {
repositories {
jcenter()
mavenCentral()
google()
}
}
18 changes: 0 additions & 18 deletions gradle.properties

This file was deleted.

0 comments on commit 3b38506

Please sign in to comment.