diff options
author | Pawit Pornkitprasan <p.pawit@gmail.com> | 2014-01-13 19:00:54 +0700 |
---|---|---|
committer | Pawit Pornkitprasan <p.pawit@gmail.com> | 2014-01-28 12:34:35 +0700 |
commit | 2e883df2c5aa2433eebf9e4dae125164a575849c (patch) | |
tree | 9f69d565a3ff8ad27ca822c194456e2c5bb54e54 | |
parent | 0bc66d827355b4d7ec5f2285f20315b443c58410 (diff) | |
download | android_packages_apps_SamsungServiceMode-2e883df2c5aa2433eebf9e4dae125164a575849c.tar.gz android_packages_apps_SamsungServiceMode-2e883df2c5aa2433eebf9e4dae125164a575849c.tar.bz2 android_packages_apps_SamsungServiceMode-2e883df2c5aa2433eebf9e4dae125164a575849c.zip |
SamsungServiceMode: add support for OEM API version 2
A new version of the ServiceMode API is found in Samsung I9082's 4.2.2 RIL
Change-Id: I8b6a05580ad034c38f2884866d62a57e4a999c4b
4 files changed, 72 insertions, 14 deletions
diff --git a/res/values/config.xml b/res/values/config.xml new file mode 100644 index 0000000..31000ad --- /dev/null +++ b/res/values/config.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 The CyanogenMod Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<resources> + <!-- Service Mode API version. Below is just a rough guideline, use what works. + Version 1: Found in < 4.2 ROMs + Version 2: Found in JellyBean 4.2 ROMs--> + <integer name="config_api_version">1</integer> +</resources> diff --git a/src/com/cyanogenmod/samsungservicemode/ExecuteReceiver.java b/src/com/cyanogenmod/samsungservicemode/ExecuteReceiver.java index 246bdc7..f9b16ec 100644 --- a/src/com/cyanogenmod/samsungservicemode/ExecuteReceiver.java +++ b/src/com/cyanogenmod/samsungservicemode/ExecuteReceiver.java @@ -18,6 +18,7 @@ public class ExecuteReceiver extends BroadcastReceiver { public static final String KEY_DATA = "data"; private Phone mPhone; + private OemCommands mOemCommands; private Handler mHandler = new Handler(); @Override @@ -34,15 +35,16 @@ public class ExecuteReceiver extends BroadcastReceiver { // Initialize mPhone = PhoneFactory.getDefaultPhone(); + mOemCommands = OemCommands.getInstance(context); // Send requests - sendRequest(OemCommands.getEnterServiceModeData(modeType, subType, OemCommands.OEM_SM_ACTION)); + sendRequest(mOemCommands.getEnterServiceModeData(modeType, subType, OemCommands.OEM_SM_ACTION)); for (char chr : data.toCharArray()) { - sendRequest(OemCommands.getPressKeyData(chr, OemCommands.OEM_SM_ACTION)); + sendRequest(mOemCommands.getPressKeyData(chr, OemCommands.OEM_SM_ACTION)); } - sendRequest(OemCommands.getEndServiceModeData(modeType)); + sendRequest(mOemCommands.getEndServiceModeData(modeType)); } private void sendRequest(byte[] data) { diff --git a/src/com/cyanogenmod/samsungservicemode/OemCommands.java b/src/com/cyanogenmod/samsungservicemode/OemCommands.java index ccc2d48..63e1b34 100644 --- a/src/com/cyanogenmod/samsungservicemode/OemCommands.java +++ b/src/com/cyanogenmod/samsungservicemode/OemCommands.java @@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; +import android.content.Context; import android.util.Log; class OemCommands { @@ -59,13 +60,31 @@ class OemCommands { 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; - public static byte[] getEnterServiceModeData(int modeType, int subType, int query) { + 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); - dos.writeShort(7); + 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); @@ -76,13 +95,20 @@ class OemCommands { return null; } - public static byte[] getEndServiceModeData(int modeType) { + 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); - dos.writeShort(5); + 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) { @@ -91,13 +117,20 @@ class OemCommands { return null; } - public static byte[] getPressKeyData(int keycode, int query) { + 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); - dos.writeShort(6); + 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(); diff --git a/src/com/cyanogenmod/samsungservicemode/SamsungServiceModeActivity.java b/src/com/cyanogenmod/samsungservicemode/SamsungServiceModeActivity.java index 1901c7b..c08b400 100644 --- a/src/com/cyanogenmod/samsungservicemode/SamsungServiceModeActivity.java +++ b/src/com/cyanogenmod/samsungservicemode/SamsungServiceModeActivity.java @@ -49,6 +49,7 @@ public class SamsungServiceModeActivity extends Activity implements AdapterView. private String mFirstPageHead; private Phone mPhone; + private OemCommands mOemCommands; private Handler mHandler = new Handler() { @Override @@ -59,10 +60,10 @@ public class SamsungServiceModeActivity extends Activity implements AdapterView. byte[] data = null; switch(mCurrentSvcMode) { case OemCommands.OEM_SM_ENTER_MODE_MESSAGE: - data = OemCommands.getEnterServiceModeData(0, 0, OemCommands.OEM_SM_QUERY); + data = mOemCommands.getEnterServiceModeData(0, 0, OemCommands.OEM_SM_QUERY); break; case OemCommands.OEM_SM_PROCESS_KEY_MESSAGE: - data = OemCommands.getPressKeyData('\0', OemCommands.OEM_SM_QUERY); + data = mOemCommands.getPressKeyData('\0', OemCommands.OEM_SM_QUERY); break; default: Log.e(TAG, "Unknown mode: " + mCurrentSvcMode); @@ -154,6 +155,7 @@ public class SamsungServiceModeActivity extends Activity implements AdapterView. mListView.setOnItemClickListener(this); mPhone = PhoneFactory.getDefaultPhone(); + mOemCommands = OemCommands.getInstance(this); // Go to the page specified by the code used to enter service mode String code = getIntent().getStringExtra(EXTRA_SECRET_CODE); @@ -301,14 +303,14 @@ public class SamsungServiceModeActivity extends Activity implements AdapterView. private void enterServiceMode(int modeType, int subType) { mCurrentSvcMode = OemCommands.OEM_SM_ENTER_MODE_MESSAGE; mCurrentModeType = modeType; - byte[] data = OemCommands.getEnterServiceModeData(modeType, subType, OemCommands.OEM_SM_ACTION); + byte[] data = mOemCommands.getEnterServiceModeData(modeType, subType, OemCommands.OEM_SM_ACTION); sendRequest(data, ID_SERVICE_MODE_REQUEST); } private void endServiceMode() { mCurrentSvcMode = OemCommands.OEM_SM_END_MODE_MESSAGE; mHandler.removeMessages(ID_SERVICE_MODE_REFRESH); - byte[] data = OemCommands.getEndServiceModeData(mCurrentModeType); + byte[] data = mOemCommands.getEndServiceModeData(mCurrentModeType); sendRequest(data, ID_SERVICE_MODE_END); finish(); } @@ -322,7 +324,7 @@ public class SamsungServiceModeActivity extends Activity implements AdapterView. chr = '*'; } - byte[] data = OemCommands.getPressKeyData(chr, OemCommands.OEM_SM_ACTION); + byte[] data = mOemCommands.getPressKeyData(chr, OemCommands.OEM_SM_ACTION); sendRequest(data, ID_SERVICE_MODE_REQUEST); } |