[go: nahoru, domu]

1package com.android.server.wifi.hotspot2.omadm;
2
3import java.io.EOFException;
4import java.io.IOException;
5import java.io.InputStream;
6import java.io.OutputStream;
7import java.nio.charset.StandardCharsets;
8
9public class OMAConstants {
10    private OMAConstants() {
11    }
12
13    public static final String MOVersion = "1.0";
14    public static final String PPS_URN = "urn:wfa:mo:hotspot2dot0-perprovidersubscription:1.0";
15    public static final String DevInfoURN = "urn:oma:mo:oma-dm-devinfo:1.0";
16    public static final String DevDetailURN = "urn:oma:mo:oma-dm-devdetail:1.0";
17    public static final String DevDetailXURN = "urn:wfa:mo-ext:hotspot2dot0-devdetail-ext:1.0";
18
19    public static final String[] SupportedMO_URNs = {
20            PPS_URN, DevInfoURN, DevDetailURN, DevDetailXURN
21    };
22
23    public static final String SppMOAttribute = "spp:moURN";
24    public static final String TAG_PostDevData = "spp:sppPostDevData";
25    public static final String TAG_SupportedVersions = "spp:supportedSPPVersions";
26    public static final String TAG_SupportedMOs = "spp:supportedMOList";
27    public static final String TAG_UpdateResponse = "spp:sppUpdateResponse";
28    public static final String TAG_MOContainer = "spp:moContainer";
29    public static final String TAG_Version = "spp:sppVersion";
30
31    public static final String TAG_SessionID = "spp:sessionID";
32    public static final String TAG_Status = "spp:sppStatus";
33    public static final String TAG_Error = "spp:sppError";
34
35    public static final String SyncMLVersionTag = "VerDTD";
36    public static final String OMAVersion = "1.2";
37    public static final String SyncML = "syncml:dmddf1.2";
38
39    private static final byte[] INDENT = new byte[1024];
40
41    public static void serializeString(String s, OutputStream out) throws IOException {
42        byte[] octets = s.getBytes(StandardCharsets.UTF_8);
43        byte[] prefix = String.format("%x:", octets.length).getBytes(StandardCharsets.UTF_8);
44        out.write(prefix);
45        out.write(octets);
46    }
47
48    public static void indent(int level, OutputStream out) throws IOException {
49        out.write(INDENT, 0, level);
50    }
51
52    public static String deserializeString(InputStream in) throws IOException {
53        StringBuilder prefix = new StringBuilder();
54        for (; ; ) {
55            byte b = (byte) in.read();
56            if (b == '.')
57                return null;
58            else if (b == ':')
59                break;
60            else if (b > ' ')
61                prefix.append((char) b);
62        }
63        int length = Integer.parseInt(prefix.toString(), 16);
64        byte[] octets = new byte[length];
65        int offset = 0;
66        while (offset < octets.length) {
67            int amount = in.read(octets, offset, octets.length - offset);
68            if (amount <= 0)
69                throw new EOFException();
70            offset += amount;
71        }
72        return new String(octets, StandardCharsets.UTF_8);
73    }
74
75    public static String readURN(InputStream in) throws IOException {
76        StringBuilder urn = new StringBuilder();
77
78        for (; ; ) {
79            byte b = (byte) in.read();
80            if (b == ')')
81                break;
82            urn.append((char) b);
83        }
84        return urn.toString();
85    }
86}
87