I need to do setprop but from an app.
Right now I'm trying to just run it as a shell command:
public class MainActivity extends AppCompatActivity {
private static final String TAG = "test:MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
exec("setprop service.adb.tcp.port 5555");
}
private void exec(String cmd) {
Process proc = null;
BufferedReader successResult = null;
BufferedReader errorResult = null;
Runtime runtime = Runtime.getRuntime();
Log.d(TAG, "exec command: " + cmd);
try {
proc = runtime.exec(cmd);
successResult = new BufferedReader(new InputStreamReader(proc.getInputStream()));
errorResult = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
String s;
while ((s = successResult.readLine()) != null) {
Log.d(TAG, "exec command: " + s);
}
while ((s = errorResult.readLine()) != null) {
Log.d(TAG, "exec command: " + s);
}
} catch (IOException e) {
Log.e(TAG, "Error running shell command:", e);
} finally {
try {
if (successResult != null) {
successResult.close();
}
if (errorResult != null) {
errorResult.close();
}
} catch (IOException e) {
Log.e(TAG, "Error running shell command:", e);
}
if (proc != null) {
proc.destroy();
}
}
}
}
This give me:
exec command: setprop service.adb.tcp.port 5555
exec command: setprop: failed to set property 'service.adb.tcp.port' to '5555'
How can I set a system property from an application?
Edit: Sorry, I should have I added my device is rooted and this app is a system app.