1 /* Communication module for Android terminals. -*- c-file-style: "GNU" -*-
2
3 Copyright (C) 2023 Free Software Foundation, Inc.
4
5 This file is part of GNU Emacs.
6
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or (at
10 your option) any later version.
11
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
19
20 package org.gnu.emacs;
21
22 import java.io.File;
23 import java.io.FileFilter;
24
25 import android.content.Context;
26
27 import android.app.Application;
28 import android.util.Log;
29
30 public final class EmacsApplication extends Application
31 {
32 private static final String TAG = "EmacsApplication";
33
34 /* The name of the dump file to use. */
35 public static String dumpFileName;
36
37 public static void
38 findDumpFile (Context context)
39 {
40 File filesDirectory;
41 File[] allFiles;
42 String wantedDumpFile;
43 int i;
44
45 wantedDumpFile = ("emacs-" + EmacsNative.getFingerprint ()
46 + ".pdmp");
47
48 /* Obtain a list of all files ending with ``.pdmp''. Then, look
49 for a file named ``emacs-<fingerprint>.pdmp'' and delete the
50 rest. */
51 filesDirectory = context.getFilesDir ();
52
53 allFiles = filesDirectory.listFiles (new FileFilter () {
54 @Override
55 public boolean
56 accept (File file)
57 {
58 return (!file.isDirectory ()
59 && file.getName ().endsWith (".pdmp"));
60 }
61 });
62
63 if (allFiles == null)
64 return;
65
66 /* Now try to find the right dump file. */
67 for (i = 0; i < allFiles.length; ++i)
68 {
69 if (allFiles[i].getName ().equals (wantedDumpFile))
70 dumpFileName = allFiles[i].getAbsolutePath ();
71 else
72 /* Delete this outdated dump file. */
73 allFiles[i].delete ();
74 }
75 }
76
77 @Override
78 public void
79 onCreate ()
80 {
81 /* Block signals which don't interest the current thread and its
82 descendants created by the system. The original signal mask
83 will be restored for the Emacs thread in `initEmacs'. */
84 EmacsNative.setupSystemThread ();
85
86 /* Locate a suitable dump file. */
87 findDumpFile (this);
88
89 /* Start the rest of the application. */
90 super.onCreate ();
91 }
92 };