This commit is contained in:
2013-12-09 12:32:07 +00:00
commit 55ca4db95a
51 changed files with 551 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
package at.sprinternet.mvnoroaming;
import java.io.IOException;
import android.util.Log;
public class ExecuteAsRoot {
public static boolean exec(String command) {
try {
Process process = Runtime.getRuntime().exec(
new String[] { "su", "-c", command });
process.waitFor();
} catch (IOException ex) {
Log.w("ROOT", "Can't get root access", ex);
return false;
} catch (InterruptedException ex) {
Log.w("ROOT", "Can't get root access", ex);
return false;
}
return true;
}
}

View File

@@ -0,0 +1,73 @@
package at.sprinternet.mvnoroaming;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.Toast;
public class MVNORoamingStatusChanger extends Activity {
private static final String PROVIDER_KEY = "mvno_provider";
private static final String REBOOTSERVICE_KEY = "mvno_setonreboot";
private static final String TAG = "MVNOroaming";
private EditText editTextProvider;
private Button buttonUpdate;
private Switch switchReboot;
private SharedPreferences prefs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mvno);
editTextProvider = (EditText) findViewById(R.id.editTextProvider);
buttonUpdate = (Button) findViewById(R.id.buttonUpdate);
switchReboot = (Switch) findViewById(R.id.switchReboot);
prefs = this.getSharedPreferences("at.sprinternet.mvnoroaming", Context.MODE_PRIVATE);
//set listeners
switchReboot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Log.v(TAG, "Switch State="+isChecked);
prefs.edit().putBoolean(REBOOTSERVICE_KEY, isChecked).commit();
}
});
buttonUpdate.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Log.v(TAG, "Button clicked");
prefs.edit().putString(PROVIDER_KEY, editTextProvider.getText().toString()).commit();
Boolean done = ExecuteAsRoot.exec("setprop gsm.sim.operator.alpha " + editTextProvider.getText().toString());
if(!done) {
Toast.makeText(getApplicationContext(), "Setting Service-Provider failed!", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Updated Service-Provider!", Toast.LENGTH_LONG).show();
}
}
});
//init gui
String currentProvider = "";
Boolean setOnReboot = true;
currentProvider = prefs.getString(PROVIDER_KEY, ""); // default: empty
setOnReboot = prefs.getBoolean(REBOOTSERVICE_KEY, true);
editTextProvider.setText(currentProvider);
switchReboot.setChecked(setOnReboot);
}
}

View File

@@ -0,0 +1,54 @@
package at.sprinternet.mvnoroaming;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
public class RebootService extends Service{
private static final String PROVIDER_KEY = "mvno_provider";
private static final String REBOOTSERVICE_KEY = "mvno_setonreboot";
private static final String TAG = "MVNOroaming";
private SharedPreferences prefs;
@Override
public void onCreate() {
super.onCreate();
prefs = this.getSharedPreferences("at.sprinternet.mvnoroaming", Context.MODE_PRIVATE);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
String currentProvider = prefs.getString(PROVIDER_KEY, null);
Boolean runOnReboot = prefs.getBoolean(REBOOTSERVICE_KEY, true);
if(runOnReboot && currentProvider != null && "".compareTo(currentProvider) != 0 ) {
Boolean done = ExecuteAsRoot.exec("setprop gsm.sim.operator.alpha " + currentProvider);
Log.v(TAG, "Setprop result:" + done);
if(!done) {
Toast.makeText(getApplicationContext(), "Setting Service-Provider failed!", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Updated Service-Provider!", Toast.LENGTH_LONG).show();
}
}
return Service.START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Log.v(TAG, "Service destroyed");
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
}

View File

@@ -0,0 +1,16 @@
package at.sprinternet.mvnoroaming;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class RebootServiceReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Intent serviceIntent = new Intent(context, RebootService.class);
context.startService(serviceIntent);
}
}
}