summaryrefslogtreecommitdiffstats
path: root/src/com/cyanogenmod/samsungservicemode/OemCommands.java
blob: 63e1b34bb0679f1da2a8494f618f7b90096c369e (plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package com.cyanogenmod.samsungservicemode;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import android.content.Context;
import android.util.Log;

class OemCommands {

    private static final String TAG = "OemCommands";

    public static final char OEM_SERVM_FUNCTAG = 1;
    public static final char OEM_SM_ACTION = 0;
    public static final char OEM_SM_QUERY = 1;
    public static final char OEM_SM_DUMMY = 0;
    public static final char OEM_SM_ENTER_MODE_MESSAGE = 1;
    public static final char OEM_SM_END_MODE_MESSAGE = 2;
    public static final char OEM_SM_PROCESS_KEY_MESSAGE = 3;
    public static final char OEM_SM_GET_DISPLAY_DATA_MESSAGE = 4;
    public static final char OEM_SM_TYPE_TEST_MANUAL = 1;
    public static final char OEM_SM_TYPE_TEST_AUTO = 2;
    public static final char OEM_SM_TYPE_NAM_EDIT = 3;
    public static final char OEM_SM_TYPE_MONITOR = 4;
    public static final char OEM_SM_TYPE_PHONE_TEST = 5;
    public static final char OEM_SM_TYPE_SUB_ENTER = 0;
    public static final char OEM_SM_TYPE_SUB_SW_VERSION_ENTER = 1;
    public static final char OEM_SM_TYPE_SUB_FTA_SW_VERSION_ENTER = 2;
    public static final char OEM_SM_TYPE_SUB_FTA_HW_VERSION_ENTER = 3;
    public static final char OEM_SM_TYPE_SUB_ALL_VERSION_ENTER = 4;
    public static final char OEM_SM_TYPE_SUB_BATTERY_INFO_ENTER = 5;
    public static final char OEM_SM_TYPE_SUB_CIPHERING_PROTECTION_ENTER = 6;
    public static final char OEM_SM_TYPE_SUB_INTEGRITY_PROTECTION_ENTER = 7;
    public static final char OEM_SM_TYPE_SUB_IMEI_READ_ENTER = 8;
    public static final char OEM_SM_TYPE_SUB_BLUETOOTH_TEST_ENTER = 9;
    public static final char OEM_SM_TYPE_SUB_VIBRATOR_TEST_ENTER = 10;
    public static final char OEM_SM_TYPE_SUB_MELODY_TEST_ENTER = 11;
    public static final char OEM_SM_TYPE_SUB_MP3_TEST_ENTER = 12;
    public static final char OEM_SM_TYPE_SUB_FACTORY_RESET_ENTER = 13;
    public static final char OEM_SM_TYPE_SUB_FACTORY_PRECONFIG_ENTER = 14;
    public static final char OEM_SM_TYPE_SUB_TFS4_EXPLORE_ENTER = 15;
    public static final char OEM_SM_TYPE_SUB_RSC_FILE_VERSION_ENTER = 17;
    public static final char OEM_SM_TYPE_SUB_USB_DRIVER_ENTER = 18;
    public static final char OEM_SM_TYPE_SUB_USB_UART_DIAG_CONTROL_ENTER = 19;
    public static final char OEM_SM_TYPE_SUB_RRC_VERSION_ENTER = 20;
    public static final char OEM_SM_TYPE_SUB_GPSONE_SS_TEST_ENTER = 21;
    public static final char OEM_SM_TYPE_SUB_BAND_SEL_ENTER = 22;
    public static final char OEM_SM_TYPE_SUB_GCF_TESTMODE_ENTER = 23;
    public static final char OEM_SM_TYPE_SUB_GSM_FACTORY_AUDIO_LB_ENTER = 24;
    public static final char OEM_SM_TYPE_SUB_FACTORY_VF_TEST_ENTER = 25;
    public static final char OEM_SM_TYPE_SUB_TOTAL_CALL_TIME_INFO_ENTER = 26;
    public static final char OEM_SM_TYPE_SUB_SELLOUT_SMS_ENABLE_ENTER = 27;
    public static final char OEM_SM_TYPE_SUB_SELLOUT_SMS_DISABLE_ENTER = 28;
    public static final char OEM_SM_TYPE_SUB_SELLOUT_SMS_TEST_MODE_ON = 29;
    public static final char OEM_SM_TYPE_SUB_SELLOUT_SMS_PRODUCT_MODE_ON = 30;
    public static final char OEM_SM_TYPE_SUB_GET_SELLOUT_SMS_INFO_ENTER = 31;
    public static final char OEM_SM_TYPE_SUB_TST_AUTO_ANSWER_ENTER = 32;
    public static final char OEM_SM_TYPE_SUB_TST_NV_RESET_ENTER = 33;
    public static final char OEM_SM_TYPE_SUB_TST_FTA_SW_VERSION_ENTER = 4098;
    public static final char OEM_SM_TYPE_SUB_TST_FTA_HW_VERSION_ENTER = 4099;

    private int mApiVersion;

    private OemCommands(int apiVersion) {
        mApiVersion = apiVersion;
    }

    public static OemCommands getInstance(Context context) {
        int apiVersion = context.getResources().getInteger(R.integer.config_api_version);
        return new OemCommands(apiVersion);
    }

    public byte[] getEnterServiceModeData(int modeType, int subType, int query) {
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(baos);
            dos.writeByte(OEM_SERVM_FUNCTAG);
            dos.writeByte(OEM_SM_ENTER_MODE_MESSAGE);
            if (mApiVersion == 1) {
                dos.writeShort(7);
            } else if (mApiVersion == 2) {
                dos.writeShort(8);
                dos.writeByte(4);
            } else {
                throw new IllegalArgumentException("Invalid API version " + mApiVersion);
            }
            dos.writeByte(modeType);
            dos.writeByte(subType);
            dos.writeByte(query);
            return baos.toByteArray();
        } catch (IOException e) {
            Log.e(TAG, "", e);
        }
        return null;
    }

    public byte[] getEndServiceModeData(int modeType) {
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(baos);
            dos.writeByte(OEM_SERVM_FUNCTAG);
            dos.writeByte(OEM_SM_END_MODE_MESSAGE);
            if (mApiVersion == 1) {
                dos.writeShort(5);
            } else if (mApiVersion == 2) {
                dos.writeShort(6);
                dos.writeByte(4);
            } else {
                throw new IllegalArgumentException("Invalid API version " + mApiVersion);
            }
            dos.writeByte(modeType);
            return baos.toByteArray();
        } catch (IOException e) {
            Log.e(TAG, "", e);
        }
        return null;
    }

    public byte[] getPressKeyData(int keycode, int query) {
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(baos);
            dos.writeByte(OEM_SERVM_FUNCTAG);
            dos.writeByte(OEM_SM_PROCESS_KEY_MESSAGE);
            if (mApiVersion == 1) {
                dos.writeShort(6);
            } else if (mApiVersion == 2) {
                dos.writeShort(7);
                dos.writeByte(4);
            } else {
                throw new IllegalArgumentException("Invalid API version " + mApiVersion);
            }
            dos.writeByte(keycode);
            dos.writeByte(query);
            return baos.toByteArray();
        } catch (IOException e) {
            Log.e(TAG, "", e);
        }
        return null;
    }

}