fix handling of foreground intent starts, and set bg start off by default

This commit is contained in:
Nathan Freitas 2015-06-22 12:37:51 -04:00
parent e132a79a61
commit 225ad9d1ac
2 changed files with 22 additions and 13 deletions

View File

@ -23,7 +23,7 @@ android:enabled="true"
android:title="@string/pref_use_expanded_notifications_title"/> android:title="@string/pref_use_expanded_notifications_title"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="true" android:defaultValue="false"
android:key="pref_allow_background_starts" android:key="pref_allow_background_starts"
android:summary="@string/pref_allow_background_starts_summary" android:summary="@string/pref_allow_background_starts_summary"
android:title="@string/pref_allow_background_starts_title"/> android:title="@string/pref_allow_background_starts_title"/>

View File

@ -99,6 +99,10 @@ public class OrbotMainActivity extends Activity
private final static int STATUS_UPDATE = 1; private final static int STATUS_UPDATE = 1;
private static final int MESSAGE_TRAFFIC_COUNT = 2; private static final int MESSAGE_TRAFFIC_COUNT = 2;
public final static String INTENT_ACTION_REQUEST_HIDDEN_SERVICE = "org.torproject.android.REQUEST_HS_PORT";
public final static String INTENT_ACTION_REQUEST_START_TOR = "org.torproject.android.START_TOR";
/** Called when the activity is first created. */ /** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -501,8 +505,7 @@ public class OrbotMainActivity extends Activity
} }
} }
private synchronized void handleIntents () private synchronized void handleIntents ()
{ {
if (getIntent() == null) if (getIntent() == null)
@ -518,7 +521,7 @@ public class OrbotMainActivity extends Activity
if (action == null) if (action == null)
return; return;
if (action.equals("org.torproject.android.REQUEST_HS_PORT")) if (action.equals(INTENT_ACTION_REQUEST_HIDDEN_SERVICE))
{ {
final int hiddenServicePortRequest = getIntent().getIntExtra("hs_port", -1); final int hiddenServicePortRequest = getIntent().getIntExtra("hs_port", -1);
@ -558,21 +561,24 @@ public class OrbotMainActivity extends Activity
return; //don't null the setIntent() as we need it later return; //don't null the setIntent() as we need it later
} }
else if (action.equals("org.torproject.android.START_TOR")) else if (action.equals(INTENT_ACTION_REQUEST_START_TOR))
{ {
autoStartFromIntent = true; autoStartFromIntent = true;
startTor(); startTor();
Intent resultIntent; if (Prefs.allowBackgroundStarts())
if (lastStatusIntent == null) { {
resultIntent = new Intent(intent); Intent resultIntent;
} else { if (lastStatusIntent == null) {
resultIntent = lastStatusIntent; resultIntent = new Intent(intent);
} else {
resultIntent = lastStatusIntent;
}
resultIntent.putExtra(TorServiceConstants.EXTRA_STATUS, torStatus);
setResult(RESULT_OK, resultIntent);
finish();
} }
resultIntent.putExtra(TorServiceConstants.EXTRA_STATUS, torStatus);
setResult(RESULT_OK, resultIntent);
finish();
} }
else if (action.equals(Intent.ACTION_VIEW)) else if (action.equals(Intent.ACTION_VIEW))
@ -1086,6 +1092,9 @@ public class OrbotMainActivity extends Activity
if (autoStartFromIntent) if (autoStartFromIntent)
{ {
autoStartFromIntent = false; autoStartFromIntent = false;
Intent resultIntent = lastStatusIntent;
resultIntent.putExtra(TorServiceConstants.EXTRA_STATUS, torStatus);
setResult(RESULT_OK, resultIntent);
finish(); finish();
Log.d(TAG, "autoStartFromIntent finish"); Log.d(TAG, "autoStartFromIntent finish");
} }