sedhUGRiW
3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package org.freedesktop.gstreamer;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.content.Context;
import android.content.res.AssetManager;
public class GStreamer {
private static native void nativeInit(Context context) throws Exception;
public static void init(Context context) throws Exception {
nativeInit(context);
copyFonts(context);
@INCLUDE_CA_CERTIFICATES@ copyCaCertificates(context);
}
private static void copyFonts(Context context) {
AssetManager assetManager = context.getAssets();
File filesDir = context.getFilesDir();
File fontsFCDir = new File (filesDir, "fontconfig");
File fontsDir = new File (fontsFCDir, "fonts");
File fontsCfg = new File (fontsFCDir, "fonts.conf");
fontsDir.mkdirs();
try {
/* Copy the config file */
copyFile (assetManager, "fontconfig/fonts.conf", fontsCfg);
/* Copy the fonts */
for(String filename : assetManager.list("fontconfig/fonts/truetype")) {
File font = new File(fontsDir, filename);
copyFile (assetManager, "fontconfig/fonts/truetype/" + filename, font);
}
} catch (IOException e) {
e.printStackTrace();
}
}
@INCLUDE_CA_CERTIFICATES@ private static void copyCaCertificates(Context context) {
@INCLUDE_CA_CERTIFICATES@ AssetManager assetManager = context.getAssets();
@INCLUDE_CA_CERTIFICATES@ File filesDir = context.getFilesDir();
@INCLUDE_CA_CERTIFICATES@ File sslDir = new File (filesDir, "ssl");
@INCLUDE_CA_CERTIFICATES@ File certsDir = new File (sslDir, "certs");
@INCLUDE_CA_CERTIFICATES@ File certs = new File (certsDir, "ca-certificates.crt");
@INCLUDE_CA_CERTIFICATES@
@INCLUDE_CA_CERTIFICATES@ certsDir.mkdirs();
@INCLUDE_CA_CERTIFICATES@
@INCLUDE_CA_CERTIFICATES@ try {
@INCLUDE_CA_CERTIFICATES@ /* Copy the certificates file */
@INCLUDE_CA_CERTIFICATES@ copyFile (assetManager, "ssl/certs/ca-certificates.crt", certs);
@INCLUDE_CA_CERTIFICATES@ } catch (IOException e) {
@INCLUDE_CA_CERTIFICATES@ e.printStackTrace();
@INCLUDE_CA_CERTIFICATES@ }
@INCLUDE_CA_CERTIFICATES@ }
@INCLUDE_COPY_FILE@ private static void copyFile(AssetManager assetManager, String assetPath, File outFile) throws IOException {
@INCLUDE_COPY_FILE@ InputStream in;
@INCLUDE_COPY_FILE@ OutputStream out;
@INCLUDE_COPY_FILE@ byte[] buffer = new byte[1024];
@INCLUDE_COPY_FILE@ int read;
@INCLUDE_COPY_FILE@
@INCLUDE_COPY_FILE@ if (outFile.exists())
@INCLUDE_COPY_FILE@ outFile.delete();
@INCLUDE_COPY_FILE@
@INCLUDE_COPY_FILE@ in = assetManager.open(assetPath);
@INCLUDE_COPY_FILE@ out = new FileOutputStream (outFile);
@INCLUDE_COPY_FILE@ while((read = in.read(buffer)) != -1){
@INCLUDE_COPY_FILE@ out.write(buffer, 0, read);
@INCLUDE_COPY_FILE@ }
@INCLUDE_COPY_FILE@ in.close();
@INCLUDE_COPY_FILE@ out.flush();
@INCLUDE_COPY_FILE@ out.close();
@INCLUDE_COPY_FILE@ }
}