Skip to content

Commit d754c85

Browse files
author
Michael Stößer
committed
DroidPHP#53 1.8.1 App service starts, but server does not
Make a fix for Issue DroidPHP#53. The http-service will now start after Device boot. AndroidManifest.xml change version src\org\opendroidphp\app\services\OnBootReceiver.java modify onReceive(): execute the createForConnect CommandTask without opening a dialog src\org\opendroidphp\app\tasks\CommandTask.java modify Constructor and static method createForConnect: add an flag for creating a dialog src\org\opendroidphp\app\tasks\ProgressDialogTask.java modify Constructor: add an flag for creating a dialog, modify setters: add null-check src\org\opendroidphp\app\ui\HomeFragment.java modify onStart(): execute the createForConnect CommandTask
1 parent a77c665 commit d754c85

File tree

5 files changed

+80
-28
lines changed

5 files changed

+80
-28
lines changed

AndroidManifest.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
44
package="org.opendroidphp"
5-
android:versionCode="19000"
6-
android:versionName="1.9.0">
5+
android:versionCode="19001"
6+
android:versionName="1.9.1">
77

88
<uses-sdk
99
android:maxSdkVersion="19"

src/org/opendroidphp/app/services/OnBootReceiver.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.opendroidphp.app.services;
22

3+
import org.opendroidphp.app.tasks.CommandTask;
4+
35
import android.content.BroadcastReceiver;
46
import android.content.Context;
57
import android.content.Intent;
@@ -9,11 +11,23 @@
911
public class OnBootReceiver extends BroadcastReceiver {
1012
@Override
1113
public void onReceive(Context context, Intent intent) {
14+
1215
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
13-
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
16+
17+
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
1418
if (preferences.getBoolean("enable_server_on_boot", false)) {
15-
Intent i = new Intent(context, ServerService.class);
19+
20+
Intent i = new Intent(context, ServerService.class);
1621
context.startService(i);
22+
23+
final boolean enableSU = preferences.getBoolean("run_as_root", false);
24+
final String execName = preferences.getString("use_server_httpd", "lighttpd");
25+
final String bindPort = preferences.getString("server_port", "8080");
26+
27+
CommandTask task = CommandTask.createForConnect(context, execName, bindPort, false);
28+
task.enableSU(enableSU);
29+
task.execute();
30+
1731
}
1832
}
1933
if (intent.getAction().equals(Intent.ACTION_PACKAGE_REMOVED)) {

src/org/opendroidphp/app/tasks/CommandTask.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,30 @@ public CommandTask(Context context) {
3434
public CommandTask(Context context, String title, String message) {
3535
super(context, title, message);
3636
}
37+
38+
public CommandTask(Context context, String title, String message, boolean createDialog) {
39+
super(context, title, message, createDialog);
40+
}
3741

3842
public CommandTask(Context context, int titleResId, int messageResId) {
3943
super(context, context.getString(titleResId), context.getString(messageResId));
4044
}
45+
46+
public CommandTask(Context context, int titleResId, int messageResId, boolean createDialog) {
47+
super(context, context.getString(titleResId), context.getString(messageResId), createDialog);
48+
}
4149

4250
public static CommandTask createForConnect(final Context c, final String execName, final String bindPort) {
51+
return createForConnect(c, execName, bindPort, true);
52+
}
53+
public static CommandTask createForConnect(final Context c, final String execName, final String bindPort, final boolean createDialog) {
4354
List<String> command = Collections.unmodifiableList(new ArrayList<String>() {
4455
{
4556
add(CHANGE_PERMISSION.concat(Constants.INTERNAL_LOCATION + "/scripts/server-sh.sh"));
4657
add(String.format("%s/scripts/server-sh.sh %s %s", Constants.INTERNAL_LOCATION, execName, bindPort));
4758
}
4859
});
49-
CommandTask task = new CommandTask(c, R.string.server_loading, R.string.turning_on_server);
60+
CommandTask task = new CommandTask(c, R.string.server_loading, R.string.turning_on_server, createDialog);
5061
task.addCommand(command);
5162
task.setNotification(R.string.web_server_is_running);
5263
return task;

src/org/opendroidphp/app/tasks/ProgressDialogTask.java

+29-11
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,38 @@ public ProgressDialogTask() {
3030
}
3131

3232
public ProgressDialogTask(Context context) {
33-
this.context = context;
34-
handler.post(new Runnable() {
35-
@Override
36-
public void run() {
37-
createDialog().show();
38-
}
39-
});
33+
this(context, true);
4034
}
41-
35+
36+
public ProgressDialogTask(Context context, final boolean createDialog) {
37+
this.context = context;
38+
if(createDialog) {
39+
handler.post(new Runnable() {
40+
@Override
41+
public void run() {
42+
createDialog().show();
43+
}
44+
});
45+
}
46+
}
47+
4248
public ProgressDialogTask(Context context, String title, String message) {
43-
this(context);
49+
this(context, title, message, true);
50+
}
51+
52+
public ProgressDialogTask(Context context, String title, String message, boolean createDialog) {
53+
this(context, createDialog);
4454
this.title = title;
4555
this.message = message;
4656
}
4757

4858
public ProgressDialogTask(Context context, int titleResId, int messageResId) {
4959
this(context, context.getString(titleResId), context.getString(messageResId));
5060
}
61+
62+
public ProgressDialogTask(Context context, int titleResId, int messageResId, boolean createDialog) {
63+
this(context, context.getString(titleResId), context.getString(messageResId), createDialog);
64+
}
5165

5266
protected Dialog createDialog() {
5367

@@ -73,13 +87,17 @@ protected Dialog createDialog() {
7387

7488
public ProgressDialogTask setTitle(String title) {
7589
this.title = title;
76-
tv_title.setText(title);
90+
if(tv_title != null) {
91+
tv_title.setText(title);
92+
}
7793
return this;
7894
}
7995

8096
public ProgressDialogTask setMessage(String message) {
8197
this.message = message;
82-
tv_message.setText(message);
98+
if (tv_message != null) {
99+
tv_message.setText(message);
100+
}
83101
return this;
84102
}
85103

src/org/opendroidphp/app/ui/HomeFragment.java

+21-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
package org.opendroidphp.app.ui;
22

3+
import java.util.List;
4+
5+
import org.opendroidphp.R;
6+
import org.opendroidphp.app.Constants;
7+
import org.opendroidphp.app.common.utils.FileUtils;
8+
import org.opendroidphp.app.fragments.dialogs.DialogHelpers;
9+
import org.opendroidphp.app.listeners.OnInflationListener;
10+
import org.opendroidphp.app.services.ServerService;
11+
import org.opendroidphp.app.tasks.CommandTask;
12+
313
import android.app.Activity;
414
import android.app.NotificationManager;
515
import android.content.Context;
@@ -17,16 +27,6 @@
1727

1828
import com.actionbarsherlock.app.SherlockFragment;
1929

20-
import org.opendroidphp.R;
21-
import org.opendroidphp.app.Constants;
22-
import org.opendroidphp.app.common.utils.FileUtils;
23-
import org.opendroidphp.app.fragments.dialogs.DialogHelpers;
24-
import org.opendroidphp.app.listeners.OnInflationListener;
25-
import org.opendroidphp.app.services.ServerService;
26-
import org.opendroidphp.app.tasks.CommandTask;
27-
28-
import java.util.List;
29-
3030
import de.ankri.views.Switch;
3131
import eu.chainfire.libsuperuser.Shell;
3232

@@ -75,8 +75,17 @@ public void onSaveInstanceState(Bundle outState) {
7575
public void onStart() {
7676
super.onStart();
7777
if (preferences.getBoolean("enable_server_on_app_startup", false)) {
78-
getSherlockActivity().
79-
startService(new Intent(getSherlockActivity(), ServerService.class));
78+
79+
Context context = getSherlockActivity();
80+
context.startService(new Intent(context, ServerService.class));
81+
82+
final boolean enableSU = preferences.getBoolean("run_as_root", false);
83+
final String execName = preferences.getString("use_server_httpd", "lighttpd");
84+
final String bindPort = preferences.getString("server_port", "8080");
85+
86+
CommandTask task = CommandTask.createForConnect(context, execName, bindPort);
87+
task.enableSU(enableSU);
88+
task.execute();
8089
}
8190
new ConnectionListenerTask().execute();
8291
}

0 commit comments

Comments
 (0)