Adjust dump file location under Android
* java/org/gnu/emacs/EmacsApplication.java (EmacsApplication) <apkFileName>: New field. (getApkFile): Move from EmacsService.java. (findDumpFile): If the dump file is older than the APK, delete it irrespective of whether the checksums agree. (onCreate): Initialize apkFileName. * java/org/gnu/emacs/EmacsService.java (onCreate): Use EmacsApplication.apkFileName. * src/android.c (android_on_low_memory): Correct arguments to Fclear_image_cache. * src/image.c (Fclear_image_cache): Check that animation_cache is always a cons.
This commit is contained in:
parent
fff9b6e37a
commit
e56e9c1954
4 changed files with 73 additions and 37 deletions
|
@ -25,19 +25,61 @@
|
|||
import android.content.Context;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager.ApplicationInfoFlags;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public final class EmacsApplication extends Application
|
||||
{
|
||||
private static final String TAG = "EmacsApplication";
|
||||
|
||||
/* The name of the dump file to use. */
|
||||
/* The name of the dump file to use, or NULL if this Emacs binary
|
||||
has yet to be dumped. */
|
||||
public static String dumpFileName;
|
||||
|
||||
/* The name of the APK file housing Emacs, or NULL if it could not
|
||||
be ascertained. */
|
||||
public static String apkFileName;
|
||||
|
||||
@SuppressWarnings ("deprecation")
|
||||
private String
|
||||
getApkFile ()
|
||||
{
|
||||
PackageManager manager;
|
||||
ApplicationInfo info;
|
||||
|
||||
manager = getPackageManager ();
|
||||
|
||||
try
|
||||
{
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU)
|
||||
info = manager.getApplicationInfo ("org.gnu.emacs", 0);
|
||||
else
|
||||
info = manager.getApplicationInfo ("org.gnu.emacs",
|
||||
ApplicationInfoFlags.of (0));
|
||||
|
||||
/* Return an empty string upon failure. */
|
||||
|
||||
if (info.sourceDir != null)
|
||||
return info.sourceDir;
|
||||
|
||||
return null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void
|
||||
findDumpFile (Context context)
|
||||
{
|
||||
File filesDirectory;
|
||||
File filesDirectory, apk;
|
||||
File[] allFiles;
|
||||
String wantedDumpFile;
|
||||
int i;
|
||||
|
@ -67,7 +109,29 @@ public final class EmacsApplication extends Application
|
|||
for (i = 0; i < allFiles.length; ++i)
|
||||
{
|
||||
if (allFiles[i].getName ().equals (wantedDumpFile))
|
||||
dumpFileName = allFiles[i].getAbsolutePath ();
|
||||
{
|
||||
/* Compare the last modified time of the dumpfile with
|
||||
that of apkFileName, the time at which Emacs was
|
||||
installed. Delete it if the dump file was created
|
||||
before Emacs was installed, even if the C signature
|
||||
(representing libemacs.so) remains identical. */
|
||||
|
||||
if (apkFileName != null)
|
||||
{
|
||||
apk = new File (apkFileName);
|
||||
|
||||
if (apk.lastModified ()
|
||||
> allFiles[i].lastModified ())
|
||||
{
|
||||
allFiles[i].delete ();
|
||||
|
||||
/* Don't set the dump file name in this case. */
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
dumpFileName = allFiles[i].getAbsolutePath ();
|
||||
}
|
||||
else
|
||||
/* Delete this outdated dump file. */
|
||||
allFiles[i].delete ();
|
||||
|
@ -83,6 +147,9 @@ public final class EmacsApplication extends Application
|
|||
will be restored for the Emacs thread in `initEmacs'. */
|
||||
EmacsNative.setupSystemThread ();
|
||||
|
||||
/* Establish the name of the APK. */
|
||||
apkFileName = getApkFile ();
|
||||
|
||||
/* Locate a suitable dump file. */
|
||||
findDumpFile (this);
|
||||
|
||||
|
|
|
@ -53,8 +53,6 @@
|
|||
import android.content.IntentFilter;
|
||||
import android.content.UriPermission;
|
||||
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager.ApplicationInfoFlags;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import android.content.res.AssetManager;
|
||||
|
@ -193,36 +191,6 @@ public final class EmacsService extends Service
|
|||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings ("deprecation")
|
||||
private String
|
||||
getApkFile ()
|
||||
{
|
||||
PackageManager manager;
|
||||
ApplicationInfo info;
|
||||
|
||||
manager = getPackageManager ();
|
||||
|
||||
try
|
||||
{
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU)
|
||||
info = manager.getApplicationInfo ("org.gnu.emacs", 0);
|
||||
else
|
||||
info = manager.getApplicationInfo ("org.gnu.emacs",
|
||||
ApplicationInfoFlags.of (0));
|
||||
|
||||
/* Return an empty string upon failure. */
|
||||
|
||||
if (info.sourceDir != null)
|
||||
return info.sourceDir;
|
||||
|
||||
return "";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the display density, adjusted in accord with the user's
|
||||
text scaling preferences. */
|
||||
|
||||
|
@ -288,7 +256,7 @@ public final class EmacsService extends Service
|
|||
/* Now provide this application's apk file, so a recursive
|
||||
invocation of app_process (through android-emacs) can
|
||||
find EmacsNoninteractive. */
|
||||
classPath = getApkFile ();
|
||||
classPath = EmacsApplication.apkFileName;
|
||||
|
||||
Log.d (TAG, "Initializing Emacs, where filesDir = " + filesDir
|
||||
+ ", libDir = " + libDir + ", and classPath = " + classPath
|
||||
|
|
|
@ -1965,7 +1965,7 @@ NATIVE_NAME (shutDownEmacs) (JNIEnv *env, jobject object)
|
|||
static void
|
||||
android_on_low_memory (void *closure)
|
||||
{
|
||||
Fclear_image_cache (Qt, Qt);
|
||||
Fclear_image_cache (Qt, Qnil);
|
||||
garbage_collect ();
|
||||
}
|
||||
|
||||
|
|
|
@ -2342,6 +2342,7 @@ evicted. */)
|
|||
{
|
||||
if (!NILP (animation_cache))
|
||||
{
|
||||
CHECK_CONS (animation_cache);
|
||||
#if defined (HAVE_WEBP) || defined (HAVE_GIF)
|
||||
anim_prune_animation_cache (XCDR (animation_cache));
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue