Skip to content

Commit

Permalink
V1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
CaramelFur committed Sep 12, 2021
1 parent 3eb3a11 commit 01e7fe7
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 187 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 29
buildToolsVersion '29.0.2'
compileSdkVersion 31
buildToolsVersion '31.0.0'

defaultConfig {
applicationId 'com.google.android.apps.photos'
minSdkVersion 29
targetSdkVersion 29
versionCode 1
versionName '1.0.0'
targetSdkVersion 31
versionCode 2
versionName '1.1.0'
}

/*signingConfigs {
Expand Down
88 changes: 56 additions & 32 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,35 +1,59 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.android.apps.photos">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.apps.photos">

<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">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="com.android.camera.action.REVIEW" />
<action android:name="android.provider.action.REVIEW" />
<action android:name="android.provider.action.REVIEW_SECURE" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="*/*" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:scheme="content" />
<data android:scheme="file" />
<data android:mimeType="image/*" />
<data android:mimeType="application/vnd.google.panorama360+jpg" />
<data android:mimeType="video/mpeg" />
<data android:mimeType="video/mpeg4" />
<data android:mimeType="video/mp4" />
<data android:mimeType="video/3gp" />
<data android:mimeType="video/3gpp" />
<data android:mimeType="video/3gpp2" />
<data android:mimeType="video/webm" />
<data android:mimeType="video/avi" />
<data android:mimeType="video/x-matroska" />
<data android:mimeType="video/quicktime" />
</intent-filter>
</activity>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<!--<service android:exported="true" android:name="com.google.android.apps.photos.cameraassistant.CameraAssistantService" />-->
</application>
<!-- This is here to make sure GPhotosShim has access to the gcam application -->
<queries>
<intent>
<action android:name="android.media.action.STILL_IMAGE_CAMERA" />
</intent>
</queries>

<application
android:allowBackup="false"
android:label="@string/app_name">
<activity
android:name="com.google.android.apps.photos.MainActivity"
android:clearTaskOnLaunch="true"
android:exported="true"
android:label="@string/app_name"
android:noHistory="true"
android:theme="@android:style/Theme.NoDisplay">
<intent-filter>
<action android:name="android.provider.action.REVIEW" />
<action android:name="android.provider.action.REVIEW_SECURE" />

<category android:name="android.intent.category.DEFAULT" />

<data android:scheme="*/*" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:scheme="content" />
<data android:scheme="file" />
<data android:mimeType="image/*" />
<data android:mimeType="video/*" />
<data android:mimeType="application/vnd.google.panorama360+jpg" />
</intent-filter>
</activity>

<!-- This is here to make sure that gcam has access to this application -->
<activity
android:name="com.google.android.apps.photos.BlankActivity"
android:clearTaskOnLaunch="true"
android:exported="true"
android:label="@string/app_name"
android:noHistory="true"
android:theme="@android:style/Theme.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>

<!-- I still have no clue what this service is supposed to do -->
<service
android:name="com.google.android.apps.photos.cameraassistant.CameraAssistantService"
android:exported="true"/>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.google.android.apps.photos;

import android.app.Activity;
import android.os.Bundle;

public class BlankActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
finish();
}
}
62 changes: 24 additions & 38 deletions app/src/main/java/com/google/android/apps/photos/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
import android.content.Intent;
import android.util.Log;
import android.net.Uri;
import android.content.ContentResolver;
import java.io.InputStream;
import java.net.URI;

import android.content.ContentProviderClient;
import android.os.ParcelFileDescriptor;
import java.io.File;
import android.database.Cursor;
import android.provider.MediaStore;
import android.content.Context;
Expand All @@ -20,71 +14,61 @@
import android.content.pm.PackageManager;

public class MainActivity extends Activity {

// Polling settings for checking if the URI is finsihed yet
private static final int waitMS = 100;
private static final int maximumSeconds = 30000;
private static final int iterations = maximumSeconds * 1000 / waitMS;

// Random integer to identify app in permission callback
private static final int PERMISSIONS_INT = 755009201;

private PendingIntent cameraRelaunchIntent;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);

Intent receivedIntent = getIntent();

// Extract all necessary information from the intent
// We store the relaunch intent in this class so it can be used in callbacks
// (In this case that is just the permission callback)
String SessionId = receivedIntent.getStringExtra("external_session_id");
Uri uri = Uri.parse(receivedIntent.getData().toString() + "?requireOriginal=1");
Uri uri = Uri.parse(receivedIntent.getData().toString());
String type = receivedIntent.getType();

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

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

// Make sure there is even a session id, the call is probably invalid if this is gone
if (SessionId == null) {
finish();
return;
}

// Make sure that we have the READ_EXTERNAL_STORAGE permission,
// we sadly need this permission to check if a URI is pending
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);
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSIONS_INT);

quit();
return;
}

Log.i("PhotosShim", "SessionId: '" + SessionId + "', URI:'" + uri + "', type: '" + type + "', processingURI: '"
+ processingURI + "'");

// Keep polling the URI to see if it has stopped being pending
boolean success = false;

for (int i = 0; i < iterations; i++) {
String absolut = MainActivity.getRealPathFromURI(getApplicationContext(), uri);
if (absolut == "")
break;

Log.i("PhotosShim", "URL: " + absolut);

String name = "";
try {
name = new File(absolut).getName();
} catch (Exception e) {
Log.e("PhotosShim", "Error creating file obj", e);
break;
}

if (name == "")
break;

if (!name.startsWith(".pending")) {
if (!isUriPending(getApplicationContext(), uri)) {
success = true;
break;
}

Log.i("PhotosShim", "Pending...");

try {
Thread.sleep(waitMS);
} catch (Exception e) {
Expand All @@ -98,6 +82,9 @@ protected void onCreate(Bundle savedInstanceState) {
return;
}

// If the URI is not pending anymore we send an implicit intent
// so you can now handle the image with any gallery you want

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "image/*");
Expand All @@ -114,7 +101,6 @@ private void quit() {
Log.e("PhotosShim", "Error sending intent", e);
}
finish();
return;
}

@Override
Expand All @@ -124,19 +110,19 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in
if (permissions.length == 0 || grantResults.length == 0)
return;

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

public static String getRealPathFromURI(Context context, Uri contentUri) {
public static boolean isUriPending(Context context, Uri contentUri) {
Cursor cursor = null;
String result = "";
boolean result;
try {
String[] proj = { MediaStore.Images.Media.DATA };
String[] proj = {MediaStore.Images.Media.IS_PENDING};
cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
cursor.moveToFirst();
int column_index = cursor.getColumnIndex(proj[0]);
result = cursor.getString(column_index);
int column_index_data = cursor.getColumnIndex(proj[0]);
result = cursor.getInt(column_index_data) != 0;
} finally {
if (cursor != null)
cursor.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,10 @@
import android.content.res.Configuration;

public class CameraAssistantService extends Service {

private final CameraAssistantServiceBind b = new CameraAssistantServiceBind(this);

@Override
public void onCreate() {
super.onCreate();
Log.i("DEBUGCAM", "DEBUGCAM: created");
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("DEBUGCAM", "DEBUGCAM: start flags " + flags + " id " + startId + " intent " + intent);
return Service.START_NOT_STICKY;
}

@Override
public IBinder onBind(Intent intent) {
Log.i("DEBUGCAM", "BOUND: " + intent + " with " + intent.getFlags());

return b;
}

@Override
public void onConfigurationChanged(Configuration config) {
Log.i("DEBUGCAM", "CONFIG CHANGE: " + config);
super.onConfigurationChanged(config);
}

@Override
public void onStart(Intent intent, int id) {
Log.i("DEBUGCAM", "START: " + intent + " with " + id);
super.onStart(intent, id);
}

@Override
public boolean onUnbind(Intent intent) {

Log.i("DEBUGCAM", "UNBIND: " + intent);
return false;
}

@Override
public void onTaskRemoved(Intent intent) {
Log.i("DEBUGCAM", "TASKREMOVE: " + intent);
super.onTaskRemoved(intent);
}

@Override
public void onDestroy() {
Log.i("DEBUGCAM", "DEBUGCAM: destroyed");
return null;
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 01e7fe7

Please sign in to comment.