diff options
| author | Po Lu | 2023-11-12 11:44:58 +0800 |
|---|---|---|
| committer | Po Lu | 2023-11-12 11:44:58 +0800 |
| commit | e56e9c19545f43c35dec85fa650f3799c6e9c308 (patch) | |
| tree | d94351fc316ffbaca9ba0e82b29b65f51b1d8923 /java | |
| parent | fff9b6e37aaf7da22cf803441b96f47ddd92a027 (diff) | |
| download | emacs-e56e9c19545f43c35dec85fa650f3799c6e9c308.tar.gz emacs-e56e9c19545f43c35dec85fa650f3799c6e9c308.zip | |
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.
Diffstat (limited to 'java')
| -rw-r--r-- | java/org/gnu/emacs/EmacsApplication.java | 73 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsService.java | 34 |
2 files changed, 71 insertions, 36 deletions
diff --git a/java/org/gnu/emacs/EmacsApplication.java b/java/org/gnu/emacs/EmacsApplication.java index 8afa5bcedb4..d70f16346e5 100644 --- a/java/org/gnu/emacs/EmacsApplication.java +++ b/java/org/gnu/emacs/EmacsApplication.java | |||
| @@ -25,19 +25,61 @@ import java.io.FileFilter; | |||
| 25 | import android.content.Context; | 25 | import android.content.Context; |
| 26 | 26 | ||
| 27 | import android.app.Application; | 27 | import android.app.Application; |
| 28 | |||
| 29 | import android.content.pm.ApplicationInfo; | ||
| 30 | import android.content.pm.PackageManager.ApplicationInfoFlags; | ||
| 31 | import android.content.pm.PackageManager; | ||
| 32 | |||
| 33 | import android.os.Build; | ||
| 34 | |||
| 28 | import android.util.Log; | 35 | import android.util.Log; |
| 29 | 36 | ||
| 30 | public final class EmacsApplication extends Application | 37 | public final class EmacsApplication extends Application |
| 31 | { | 38 | { |
| 32 | private static final String TAG = "EmacsApplication"; | 39 | private static final String TAG = "EmacsApplication"; |
| 33 | 40 | ||
| 34 | /* The name of the dump file to use. */ | 41 | /* The name of the dump file to use, or NULL if this Emacs binary |
| 42 | has yet to be dumped. */ | ||
| 35 | public static String dumpFileName; | 43 | public static String dumpFileName; |
| 36 | 44 | ||
| 45 | /* The name of the APK file housing Emacs, or NULL if it could not | ||
| 46 | be ascertained. */ | ||
| 47 | public static String apkFileName; | ||
| 48 | |||
| 49 | @SuppressWarnings ("deprecation") | ||
| 50 | private String | ||
| 51 | getApkFile () | ||
| 52 | { | ||
| 53 | PackageManager manager; | ||
| 54 | ApplicationInfo info; | ||
| 55 | |||
| 56 | manager = getPackageManager (); | ||
| 57 | |||
| 58 | try | ||
| 59 | { | ||
| 60 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) | ||
| 61 | info = manager.getApplicationInfo ("org.gnu.emacs", 0); | ||
| 62 | else | ||
| 63 | info = manager.getApplicationInfo ("org.gnu.emacs", | ||
| 64 | ApplicationInfoFlags.of (0)); | ||
| 65 | |||
| 66 | /* Return an empty string upon failure. */ | ||
| 67 | |||
| 68 | if (info.sourceDir != null) | ||
| 69 | return info.sourceDir; | ||
| 70 | |||
| 71 | return null; | ||
| 72 | } | ||
| 73 | catch (Exception e) | ||
| 74 | { | ||
| 75 | return null; | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 37 | public static void | 79 | public static void |
| 38 | findDumpFile (Context context) | 80 | findDumpFile (Context context) |
| 39 | { | 81 | { |
| 40 | File filesDirectory; | 82 | File filesDirectory, apk; |
| 41 | File[] allFiles; | 83 | File[] allFiles; |
| 42 | String wantedDumpFile; | 84 | String wantedDumpFile; |
| 43 | int i; | 85 | int i; |
| @@ -67,7 +109,29 @@ public final class EmacsApplication extends Application | |||
| 67 | for (i = 0; i < allFiles.length; ++i) | 109 | for (i = 0; i < allFiles.length; ++i) |
| 68 | { | 110 | { |
| 69 | if (allFiles[i].getName ().equals (wantedDumpFile)) | 111 | if (allFiles[i].getName ().equals (wantedDumpFile)) |
| 70 | dumpFileName = allFiles[i].getAbsolutePath (); | 112 | { |
| 113 | /* Compare the last modified time of the dumpfile with | ||
| 114 | that of apkFileName, the time at which Emacs was | ||
| 115 | installed. Delete it if the dump file was created | ||
| 116 | before Emacs was installed, even if the C signature | ||
| 117 | (representing libemacs.so) remains identical. */ | ||
| 118 | |||
| 119 | if (apkFileName != null) | ||
| 120 | { | ||
| 121 | apk = new File (apkFileName); | ||
| 122 | |||
| 123 | if (apk.lastModified () | ||
| 124 | > allFiles[i].lastModified ()) | ||
| 125 | { | ||
| 126 | allFiles[i].delete (); | ||
| 127 | |||
| 128 | /* Don't set the dump file name in this case. */ | ||
| 129 | continue; | ||
| 130 | } | ||
| 131 | } | ||
| 132 | |||
| 133 | dumpFileName = allFiles[i].getAbsolutePath (); | ||
| 134 | } | ||
| 71 | else | 135 | else |
| 72 | /* Delete this outdated dump file. */ | 136 | /* Delete this outdated dump file. */ |
| 73 | allFiles[i].delete (); | 137 | allFiles[i].delete (); |
| @@ -83,6 +147,9 @@ public final class EmacsApplication extends Application | |||
| 83 | will be restored for the Emacs thread in `initEmacs'. */ | 147 | will be restored for the Emacs thread in `initEmacs'. */ |
| 84 | EmacsNative.setupSystemThread (); | 148 | EmacsNative.setupSystemThread (); |
| 85 | 149 | ||
| 150 | /* Establish the name of the APK. */ | ||
| 151 | apkFileName = getApkFile (); | ||
| 152 | |||
| 86 | /* Locate a suitable dump file. */ | 153 | /* Locate a suitable dump file. */ |
| 87 | findDumpFile (this); | 154 | findDumpFile (this); |
| 88 | 155 | ||
diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java index 1aac1a6c4dd..5bd1dcc5a88 100644 --- a/java/org/gnu/emacs/EmacsService.java +++ b/java/org/gnu/emacs/EmacsService.java | |||
| @@ -53,8 +53,6 @@ import android.content.Intent; | |||
| 53 | import android.content.IntentFilter; | 53 | import android.content.IntentFilter; |
| 54 | import android.content.UriPermission; | 54 | import android.content.UriPermission; |
| 55 | 55 | ||
| 56 | import android.content.pm.ApplicationInfo; | ||
| 57 | import android.content.pm.PackageManager.ApplicationInfoFlags; | ||
| 58 | import android.content.pm.PackageManager; | 56 | import android.content.pm.PackageManager; |
| 59 | 57 | ||
| 60 | import android.content.res.AssetManager; | 58 | import android.content.res.AssetManager; |
| @@ -193,36 +191,6 @@ public final class EmacsService extends Service | |||
| 193 | return null; | 191 | return null; |
| 194 | } | 192 | } |
| 195 | 193 | ||
| 196 | @SuppressWarnings ("deprecation") | ||
| 197 | private String | ||
| 198 | getApkFile () | ||
| 199 | { | ||
| 200 | PackageManager manager; | ||
| 201 | ApplicationInfo info; | ||
| 202 | |||
| 203 | manager = getPackageManager (); | ||
| 204 | |||
| 205 | try | ||
| 206 | { | ||
| 207 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) | ||
| 208 | info = manager.getApplicationInfo ("org.gnu.emacs", 0); | ||
| 209 | else | ||
| 210 | info = manager.getApplicationInfo ("org.gnu.emacs", | ||
| 211 | ApplicationInfoFlags.of (0)); | ||
| 212 | |||
| 213 | /* Return an empty string upon failure. */ | ||
| 214 | |||
| 215 | if (info.sourceDir != null) | ||
| 216 | return info.sourceDir; | ||
| 217 | |||
| 218 | return ""; | ||
| 219 | } | ||
| 220 | catch (Exception e) | ||
| 221 | { | ||
| 222 | return ""; | ||
| 223 | } | ||
| 224 | } | ||
| 225 | |||
| 226 | /* Return the display density, adjusted in accord with the user's | 194 | /* Return the display density, adjusted in accord with the user's |
| 227 | text scaling preferences. */ | 195 | text scaling preferences. */ |
| 228 | 196 | ||
| @@ -288,7 +256,7 @@ public final class EmacsService extends Service | |||
| 288 | /* Now provide this application's apk file, so a recursive | 256 | /* Now provide this application's apk file, so a recursive |
| 289 | invocation of app_process (through android-emacs) can | 257 | invocation of app_process (through android-emacs) can |
| 290 | find EmacsNoninteractive. */ | 258 | find EmacsNoninteractive. */ |
| 291 | classPath = getApkFile (); | 259 | classPath = EmacsApplication.apkFileName; |
| 292 | 260 | ||
| 293 | Log.d (TAG, "Initializing Emacs, where filesDir = " + filesDir | 261 | Log.d (TAG, "Initializing Emacs, where filesDir = " + filesDir |
| 294 | + ", libDir = " + libDir + ", and classPath = " + classPath | 262 | + ", libDir = " + libDir + ", and classPath = " + classPath |