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; } }