Skip to content
Permalink
Browse files
Merge pull request #9256 from JosJuice/android-keep
Android: Add @keep annotation to things accessed using JNI
  • Loading branch information
leoetlino committed Nov 18, 2020
2 parents 8119318 + a8d385c commit b8bc6c3
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 5 deletions.
@@ -12,6 +12,7 @@
import android.view.Surface;
import android.widget.Toast;

import androidx.annotation.Keep;
import androidx.fragment.app.FragmentManager;

import org.dolphinemu.dolphinemu.activities.EmulationActivity;
@@ -264,6 +265,7 @@ private NativeLibrary()
* @param padID Ignored for now. Future use would be to pass rumble to a connected controller
* @param state Ignored for now since phone rumble can't just be 'turned' on/off
*/
@Keep
public static void rumble(int padID, double state)
{
final EmulationActivity emulationActivity = sEmulationActivity.get();
@@ -486,6 +488,7 @@ private static void CheckGameMetadataValid()

private static native String GetCurrentTitleDescriptionUnchecked();

@Keep
public static boolean displayAlertMsg(final String caption, final String text,
final boolean yesNo, final boolean isWarning, final boolean nonBlocking)
{
@@ -575,6 +578,7 @@ public static void clearEmulationActivity()
sEmulationActivity.clear();
}

@Keep
public static void finishEmulationActivity()
{
final EmulationActivity emulationActivity = sEmulationActivity.get();
@@ -589,6 +593,7 @@ public static void finishEmulationActivity()
}
}

@Keep
public static void updateTouchPointer()
{
final EmulationActivity emulationActivity = sEmulationActivity.get();
@@ -602,7 +607,8 @@ public static void updateTouchPointer()
}
}

private static void onTitleChanged()
@Keep
public static void onTitleChanged()
{
final EmulationActivity emulationActivity = sEmulationActivity.get();
if (emulationActivity == null)
@@ -615,6 +621,7 @@ private static void onTitleChanged()
}
}

@Keep
public static float getRenderSurfaceScale()
{
DisplayMetrics metrics = new DisplayMetrics();
@@ -2,10 +2,14 @@

import android.content.Context;

import androidx.annotation.Keep;

public class GameFile
{
private long mPointer; // Do not rename or move without editing the native code
@Keep
private long mPointer;

@Keep
private GameFile(long pointer)
{
mPointer = pointer;
@@ -4,6 +4,8 @@
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import androidx.annotation.Keep;

import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;

import java.io.File;
@@ -15,7 +17,8 @@
private static final String GAME_FOLDER_PATHS_PREFERENCE = "gameFolderPaths";
private static final Set<String> EMPTY_SET = new HashSet<>();

private long mPointer; // Do not rename or move without editing the native code
@Keep
private long mPointer;

public GameFileCache(String path)
{
@@ -3,6 +3,7 @@
import android.content.Context;
import android.os.Build;

import androidx.annotation.Keep;
import androidx.appcompat.app.AlertDialog;

import com.android.volley.Request;
@@ -61,6 +62,7 @@ private static void firstAnalyticsAdd(boolean enabled)
}
}

@Keep
public static void sendReport(String endpoint, byte[] data)
{
StringRequest request = new StringRequest(Request.Method.POST, endpoint,
@@ -76,6 +78,7 @@ public byte[] getBody()
VolleyUtil.getQueue().add(request);
}

@Keep
public static String getValue(String key)
{
switch (key)
@@ -1,6 +1,9 @@
package org.dolphinemu.dolphinemu.utils;

import androidx.annotation.Keep;

public interface CompressCallback
{
@Keep
boolean run(String text, float completion);
}
@@ -4,12 +4,15 @@
import android.net.Uri;
import android.provider.DocumentsContract;

import androidx.annotation.Keep;

import org.dolphinemu.dolphinemu.DolphinApplication;

import java.io.FileNotFoundException;

public class ContentHandler
{
@Keep
public static int openFd(String uri, String mode)
{
try
@@ -23,6 +26,7 @@ public static int openFd(String uri, String mode)
}
}

@Keep
public static boolean delete(String uri)
{
try
@@ -1,16 +1,21 @@
package org.dolphinemu.dolphinemu.utils;

import androidx.annotation.Keep;

import java.io.File;

// An in-memory copy of an INI file
public class IniFile
{
// This class is non-static to ensure that the IniFile parent does not get garbage collected
// while a section still is accessible. (The finalizer of IniFile deletes the native sections.)
@SuppressWarnings("InnerClassMayBeStatic")
public class Section
{
private long mPointer; // Do not rename or move without editing the native code
@Keep
private long mPointer;

@Keep
private Section(long pointer)
{
mPointer = pointer;
@@ -37,7 +42,8 @@ private Section(long pointer)
public native void setFloat(String key, float newFloat);
}

private long mPointer; // Do not rename or move without editing the native code
@Keep
private long mPointer;

public IniFile()
{
@@ -13,6 +13,8 @@
import android.hardware.usb.UsbManager;
import android.widget.Toast;

import androidx.annotation.Keep;

import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.services.USBPermService;

@@ -22,6 +24,8 @@
public class Java_GCAdapter
{
public static UsbManager manager;

@Keep
static byte[] controller_payload = new byte[37];

static UsbDeviceConnection usb_con;
@@ -63,11 +67,13 @@ public static void Shutdown()
usb_con.close();
}

@Keep
public static int GetFD()
{
return usb_con.getFileDescriptor();
}

@Keep
public static boolean QueryAdapter()
{
HashMap<String, UsbDevice> devices = manager.getDeviceList();
@@ -91,16 +97,19 @@ public static void InitAdapter()
usb_con.bulkTransfer(usb_out, init, init.length, 0);
}

@Keep
public static int Input()
{
return usb_con.bulkTransfer(usb_in, controller_payload, controller_payload.length, 16);
}

@Keep
public static int Output(byte[] rumble)
{
return usb_con.bulkTransfer(usb_out, rumble, 5, 16);
}

@Keep
public static boolean OpenAdapter()
{
HashMap<String, UsbDevice> devices = manager.getDeviceList();
@@ -10,6 +10,8 @@
import android.hardware.usb.UsbInterface;
import android.hardware.usb.UsbManager;

import androidx.annotation.Keep;

import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.services.USBPermService;

@@ -30,6 +32,7 @@
static UsbInterface[] usb_intf = new UsbInterface[MAX_WIIMOTES];
static UsbEndpoint[] usb_in = new UsbEndpoint[MAX_WIIMOTES];

@Keep
public static byte[][] wiimote_payload = new byte[MAX_WIIMOTES][MAX_PAYLOAD];

private static void RequestPermission()
@@ -62,6 +65,7 @@ private static void RequestPermission()
}
}

@Keep
public static boolean QueryAdapter()
{
HashMap<String, UsbDevice> devices = manager.getDeviceList();
@@ -80,11 +84,13 @@ public static boolean QueryAdapter()
return false;
}

@Keep
public static int Input(int index)
{
return usb_con.bulkTransfer(usb_in[index], wiimote_payload[index], MAX_PAYLOAD, TIMEOUT);
}

@Keep
public static int Output(int index, byte[] buf, int size)
{
byte report_number = buf[0];
@@ -114,6 +120,7 @@ public static int Output(int index, byte[] buf, int size)
return write + 1;
}

@Keep
public static boolean OpenAdapter()
{
// If the adapter is already open. Don't attempt to do it again

0 comments on commit b8bc6c3

Please sign in to comment.