Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/android/phoenix/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ android {
}
playStoreNormal {
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 35
versionCode getPlayStoreVersionCode()
versionName getPlayStoreVersionName()

Expand All @@ -83,7 +83,7 @@ android {
}
playStorePlus {
minSdkVersion 26
targetSdkVersion 30
targetSdkVersion 35
versionCode getPlayStoreVersionCode()
versionName getPlayStoreVersionName()

Expand Down Expand Up @@ -153,7 +153,7 @@ android {
}
}

def playCore = 'com.google.android.play:core:1.8.0'
def playCore = 'com.google.android.play:core:1.10.3'

dependencies {
playStoreNormalImplementation playCore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.retroarch.browser.mainmenu;

import com.retroarch.BuildConfig;
import com.retroarch.browser.preferences.util.UserPreferences;
import com.retroarch.browser.retroactivity.RetroActivityFuture;

Expand Down Expand Up @@ -116,15 +117,15 @@ public void onClick(DialogInterface dialog, int which)
public void finalStartup()
{
Intent retro = new Intent(this, RetroActivityFuture.class);

if (RetroActivityFuture.isRunning) {
// RetroActivity is already running - just bring it to front
retro.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
} else {
// RetroActivity not running - full setup with parameters
retro.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

startRetroActivity(
retro,
null,
Expand All @@ -134,11 +135,11 @@ public void finalStartup()
getApplicationInfo().dataDir,
getApplicationInfo().sourceDir);
}

startActivity(retro);
finish();
}


@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
Expand Down Expand Up @@ -178,8 +179,8 @@ public static void startRetroActivity(Intent retro, String contentPath, String c
retro.putExtra("IME", imePath);
retro.putExtra("DATADIR", dataDirPath);
retro.putExtra("APK", dataSourcePath);
retro.putExtra("SDCARD", Environment.getExternalStorageDirectory().getAbsolutePath());
String external = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + PACKAGE_NAME + "/files";
retro.putExtra("SDCARD", BuildConfig.PLAY_STORE_BUILD ? external : Environment.getExternalStorageDirectory().getAbsolutePath());
retro.putExtra("EXTERNAL", external);
}

Expand All @@ -195,6 +196,9 @@ public void onCreate(Bundle savedInstanceState)

UserPreferences.updateConfigFile(this);

checkRuntimePermissions();
if (BuildConfig.PLAY_STORE_BUILD)
finalStartup();
else
checkRuntimePermissions();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
import android.graphics.Point;
import android.os.Build;
import android.os.CancellationSignal;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.provider.DocumentsContract;
import android.provider.DocumentsContract.Document;
import android.provider.DocumentsContract.Root;
import android.provider.DocumentsProvider;
import android.webkit.MimeTypeMap;

import com.retroarch.BuildConfig;
import com.retroarch.R;

import java.io.File;
Expand All @@ -35,11 +38,13 @@
* offering two different ways of accessing your stored data. This would be confusing for users."
* - http://developer.android.com/guide/topics/providers/document-provider.html#43
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class RetroDocumentsProvider extends DocumentsProvider {

private static final String ALL_MIME_TYPES = "*/*";

private String DOCUMENTS_AUTHORITY;

// The default columns to return information about a root if no specific
// columns are requested in a query.
private static final String[] DEFAULT_ROOT_PROJECTION = new String[]{
Expand All @@ -66,19 +71,44 @@ public class RetroDocumentsProvider extends DocumentsProvider {

@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
final File BASE_DIR = new File(getContext().getFilesDir().getParent());
final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_ROOT_PROJECTION);
@SuppressWarnings("ConstantConditions") final String applicationName = getContext().getString(R.string.app_name);

final MatrixCursor.RowBuilder row = result.newRow();
row.add(Root.COLUMN_ROOT_ID, getDocIdForFile(BASE_DIR));
row.add(Root.COLUMN_DOCUMENT_ID, getDocIdForFile(BASE_DIR));
row.add(Root.COLUMN_SUMMARY, null);
row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_SEARCH | Root.FLAG_SUPPORTS_IS_CHILD);
row.add(Root.COLUMN_TITLE, applicationName);
row.add(Root.COLUMN_MIME_TYPES, ALL_MIME_TYPES);
row.add(Root.COLUMN_AVAILABLE_BYTES, BASE_DIR.getFreeSpace());
row.add(Root.COLUMN_ICON, R.mipmap.ic_launcher);
if (BuildConfig.PLAY_STORE_BUILD) {
final File CORE_DIR = new File(getContext().getFilesDir().getParent());
final MatrixCursor.RowBuilder core = result.newRow();
core.add(Root.COLUMN_ROOT_ID, getDocIdForFile(CORE_DIR));
core.add(Root.COLUMN_DOCUMENT_ID, getDocIdForFile(CORE_DIR));
core.add(Root.COLUMN_SUMMARY, "Core Data");
core.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_SEARCH | Root.FLAG_SUPPORTS_IS_CHILD);
core.add(Root.COLUMN_TITLE, applicationName);
core.add(Root.COLUMN_MIME_TYPES, ALL_MIME_TYPES);
core.add(Root.COLUMN_AVAILABLE_BYTES, CORE_DIR.getFreeSpace());
core.add(Root.COLUMN_ICON, R.mipmap.ic_launcher);

final File USER_DIR = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + getContext().getPackageName() + "/files/RetroArch");
final MatrixCursor.RowBuilder user = result.newRow();
user.add(Root.COLUMN_ROOT_ID, getDocIdForFile(USER_DIR));
user.add(Root.COLUMN_DOCUMENT_ID, getDocIdForFile(USER_DIR));
user.add(Root.COLUMN_SUMMARY, "User Data");
user.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_SEARCH | Root.FLAG_SUPPORTS_IS_CHILD);
user.add(Root.COLUMN_TITLE, applicationName);
user.add(Root.COLUMN_MIME_TYPES, ALL_MIME_TYPES);
user.add(Root.COLUMN_AVAILABLE_BYTES, USER_DIR.getFreeSpace());
user.add(Root.COLUMN_ICON, R.mipmap.ic_launcher);
} else {
final File BASE_DIR = new File(getContext().getFilesDir().getParent());
final MatrixCursor.RowBuilder row = result.newRow();
row.add(Root.COLUMN_ROOT_ID, getDocIdForFile(BASE_DIR));
row.add(Root.COLUMN_DOCUMENT_ID, getDocIdForFile(BASE_DIR));
row.add(Root.COLUMN_SUMMARY, null);
row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_SEARCH | Root.FLAG_SUPPORTS_IS_CHILD);
row.add(Root.COLUMN_TITLE, applicationName);
row.add(Root.COLUMN_MIME_TYPES, ALL_MIME_TYPES);
row.add(Root.COLUMN_AVAILABLE_BYTES, BASE_DIR.getFreeSpace());
row.add(Root.COLUMN_ICON, R.mipmap.ic_launcher);
}

return result;
}

Expand All @@ -89,13 +119,44 @@ public Cursor queryDocument(String documentId, String[] projection) throws FileN
return result;
}

@Override
public String moveDocument(String sourceDocumentId, String sourceParentDocumentId, String targetParentDocumentId) throws FileNotFoundException {
File sourceFile = getFileForDocId(sourceDocumentId);
File targetParentFile = getFileForDocId(targetParentDocumentId);
File destination = new File(targetParentFile, sourceFile.getName());

boolean success = sourceFile.renameTo(destination);
if(!success){
throw new FileNotFoundException("Failed to move file " + sourceDocumentId + " to " + targetParentDocumentId);
}

getContext().getContentResolver().notifyChange(DocumentsContract.buildTreeDocumentUri(DOCUMENTS_AUTHORITY, sourceParentDocumentId), null);
getContext().getContentResolver().notifyChange(DocumentsContract.buildTreeDocumentUri(DOCUMENTS_AUTHORITY, targetParentDocumentId), null);
return getDocIdForFile(destination);
}

@Override
public String renameDocument(String documentId, String displayName) throws FileNotFoundException{
File document = getFileForDocId(documentId);
File destination = new File(document.getParentFile(), displayName);

boolean success = document.renameTo(destination);
if(!success){
throw new FileNotFoundException("Failed to rename file " + documentId + " to " + displayName);
}

getContext().getContentResolver().notifyChange(DocumentsContract.buildTreeDocumentUri(DOCUMENTS_AUTHORITY, getDocIdForFile(document.getParentFile())), null);
return getDocIdForFile(destination);
}

@Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException {
final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION);
final File parent = getFileForDocId(parentDocumentId);
for (File file : parent.listFiles()) {
includeFile(result, null, file);
}
result.setNotificationUri(getContext().getContentResolver(), DocumentsContract.buildTreeDocumentUri(DOCUMENTS_AUTHORITY, parentDocumentId));
return result;
}

Expand All @@ -115,6 +176,7 @@ public AssetFileDescriptor openDocumentThumbnail(String documentId, Point sizeHi

@Override
public boolean onCreate() {
DOCUMENTS_AUTHORITY = getContext().getPackageName() + ".documents";
return true;
}

Expand All @@ -138,14 +200,25 @@ public String createDocument(String parentDocumentId, String mimeType, String di
} catch (IOException e) {
throw new FileNotFoundException("Failed to create document with id " + newFile.getPath());
}
getContext().getContentResolver().notifyChange(DocumentsContract.buildTreeDocumentUri(DOCUMENTS_AUTHORITY, parentDocumentId), null);
return newFile.getPath();
}

@Override
public void deleteDocument(String documentId) throws FileNotFoundException {
File file = getFileForDocId(documentId);
if (!file.delete()) {
throw new FileNotFoundException("Failed to delete document with id " + documentId);
rm_r(file);
getContext().getContentResolver().notifyChange(DocumentsContract.buildTreeDocumentUri(DOCUMENTS_AUTHORITY, getDocIdForFile(file.getParentFile())), null);
}

void rm_r (File file) throws FileNotFoundException{
if(file.isDirectory()){
for(File child : file.listFiles()) {
rm_r(child);
}
}
if(!file.delete()){
throw new FileNotFoundException("Could not delete file " + file.getPath());
}
}

Expand Down Expand Up @@ -248,11 +321,11 @@ private void includeFile(MatrixCursor result, String docId, File file)

int flags = 0;
if (file.isDirectory()) {
if (file.canWrite()) flags |= Document.FLAG_DIR_SUPPORTS_CREATE;
} else if (file.canWrite()) {
flags |= Document.FLAG_SUPPORTS_WRITE;
if (file.canWrite()) flags |= Document.FLAG_DIR_SUPPORTS_CREATE | Document.FLAG_SUPPORTS_RENAME;
} else {
if (file.canWrite()) flags |= Document.FLAG_SUPPORTS_WRITE | Document.FLAG_SUPPORTS_RENAME;
}
if (file.getParentFile().canWrite()) flags |= Document.FLAG_SUPPORTS_DELETE;
if (file.getParentFile().canWrite()) flags |= Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_MOVE;

final String displayName = file.getName();
final String mimeType = getMimeType(file);
Expand Down
6 changes: 6 additions & 0 deletions pkg/android/phoenix/src/playStoreNormal/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="remove"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" tools:node="remove"/>
<application tools:remove="requestLegacyExternalStorage"/>
</manifest>
6 changes: 6 additions & 0 deletions pkg/android/phoenix/src/playStorePlus/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="remove"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" tools:node="remove"/>
<application tools:remove="requestLegacyExternalStorage"/>
</manifest>
Loading