Skip to content

Commit

Permalink
SamsungServiceMode: add support for OEM API version 2
Browse files Browse the repository at this point in the history
A new version of the ServiceMode API is found in Samsung I9082's 4.2.2 RIL

Change-Id: I8b6a05580ad034c38f2884866d62a57e4a999c4b
  • Loading branch information
pawitp committed Jan 28, 2014
1 parent 0bc66d8 commit 2e883df
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 14 deletions.
21 changes: 21 additions & 0 deletions res/values/config.xml
Original file line number Diff line number Diff line change
@@ -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>
8 changes: 5 additions & 3 deletions src/com/cyanogenmod/samsungservicemode/ExecuteReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,15 +35,16 @@ public void onReceive(Context context, Intent intent) {

// 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) {
Expand Down
45 changes: 39 additions & 6 deletions src/com/cyanogenmod/samsungservicemode/OemCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.DataOutputStream;
import java.io.IOException;

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

class OemCommands {
Expand Down Expand Up @@ -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);
Expand All @@ -76,13 +95,20 @@ public static byte[] getEnterServiceModeData(int modeType, int subType, int quer
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) {
Expand All @@ -91,13 +117,20 @@ public static byte[] getEndServiceModeData(int modeType) {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -59,10 +60,10 @@ public void handleMessage(Message msg) {
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);
Expand Down Expand Up @@ -154,6 +155,7 @@ public void onCreate(Bundle savedInstanceState) {
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);
Expand Down Expand Up @@ -301,14 +303,14 @@ public void onPause() {
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();
}
Expand All @@ -322,7 +324,7 @@ private void sendChar(char chr) {
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);
}

Expand Down

0 comments on commit 2e883df

Please sign in to comment.