create String constants for Intent actions and extras
Following the Android system naming convention, this uses constants for the action and extra names for Intents. This makes it much easier to track which "log" is which, since there are "log" actions, extras, and messages.
This commit is contained in:
parent
fd23da5237
commit
f09379d86c
|
@ -105,14 +105,14 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon
|
|||
|
||||
doLayout();
|
||||
|
||||
// Register to receive messages.
|
||||
// We are registering an observer (mMessageReceiver) to receive Intents
|
||||
// with actions named "custom-event-name".
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
|
||||
new IntentFilter("status"));
|
||||
/* receive the internal status broadcasts, which are separate from the public
|
||||
* status broadcasts to prevent other apps from sending fake/wrong status
|
||||
* info to this app */
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
|
||||
new IntentFilter(TorServiceConstants.LOCAL_ACTION_STATUS));
|
||||
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
|
||||
new IntentFilter("log"));
|
||||
new IntentFilter(TorServiceConstants.LOCAL_ACTION_LOG));
|
||||
|
||||
mHandler.postDelayed(new Runnable ()
|
||||
{
|
||||
|
@ -155,9 +155,9 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon
|
|||
public void onReceive(Context context, Intent intent) {
|
||||
// Get extra data included in the Intent
|
||||
|
||||
if (intent.hasExtra("log"))
|
||||
if (intent.hasExtra(TorServiceConstants.LOCAL_EXTRA_LOG))
|
||||
{
|
||||
String log = intent.getStringExtra("log");
|
||||
String log = intent.getStringExtra(TorServiceConstants.LOCAL_EXTRA_LOG);
|
||||
updateStatus(log);
|
||||
}
|
||||
else if (intent.hasExtra("up"))
|
||||
|
@ -175,9 +175,9 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon
|
|||
mHandler.sendMessage(msg);
|
||||
|
||||
}
|
||||
else if (intent.hasExtra("status"))
|
||||
else if (intent.hasExtra(TorServiceConstants.EXTRA_STATUS))
|
||||
{
|
||||
torStatus = intent.getStringExtra("status");
|
||||
torStatus = intent.getStringExtra(TorServiceConstants.EXTRA_STATUS);
|
||||
updateStatus("");
|
||||
}
|
||||
|
||||
|
|
|
@ -2083,7 +2083,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
|||
{
|
||||
|
||||
|
||||
Intent intent = new Intent("log");
|
||||
Intent intent = new Intent(LOCAL_ACTION_LOG);
|
||||
// You can also include some extra data.
|
||||
intent.putExtra("up",upload);
|
||||
intent.putExtra("down",download);
|
||||
|
@ -2100,19 +2100,17 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
|||
{
|
||||
|
||||
|
||||
Intent intent = new Intent("log");
|
||||
Intent intent = new Intent(LOCAL_ACTION_LOG);
|
||||
// You can also include some extra data.
|
||||
intent.putExtra("log", logMessage);
|
||||
intent.putExtra(LOCAL_EXTRA_LOG, logMessage);
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
|
||||
|
||||
}
|
||||
|
||||
private void sendCallbackStatus(String currentStatus) {
|
||||
Intent intent = new Intent("status"); // TODO rename to proper action
|
||||
// You can also include some extra data.
|
||||
intent.putExtra("status", currentStatus);
|
||||
Intent intent = new Intent(ACTION_STATUS);
|
||||
intent.putExtra(EXTRA_STATUS, currentStatus);
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -67,6 +67,12 @@ public interface TorServiceConstants {
|
|||
//control port
|
||||
public final static String TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE = "Bootstrapped 100%";
|
||||
|
||||
public final static String ACTION_STATUS = "org.torproject.android.intent.action.STATUS";
|
||||
public final static String EXTRA_STATUS = "org.torproject.android.intent.extra.STATUS";
|
||||
public final static String LOCAL_ACTION_STATUS = "status";
|
||||
public final static String LOCAL_ACTION_LOG = "log";
|
||||
public final static String LOCAL_EXTRA_LOG = "log";
|
||||
|
||||
public final static String STATUS_OFF = "OFF";
|
||||
public final static String STATUS_ON = "ON";
|
||||
public final static String STATUS_CONNECTING = "CONNECTING";
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
package org.torproject.android.ui;
|
||||
|
||||
import org.torproject.android.OrbotConstants;
|
||||
import org.torproject.android.service.TorServiceConstants;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
|
@ -23,7 +24,7 @@ public class OrbotLogActivity extends Activity implements OrbotConstants
|
|||
|
||||
doLayout();
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
|
||||
new IntentFilter("log"));
|
||||
new IntentFilter(TorServiceConstants.LOCAL_ACTION_LOG));
|
||||
|
||||
|
||||
}
|
||||
|
@ -38,9 +39,9 @@ public class OrbotLogActivity extends Activity implements OrbotConstants
|
|||
public void onReceive(Context context, Intent intent) {
|
||||
// Get extra data included in the Intent
|
||||
|
||||
if (intent.hasExtra("log"))
|
||||
if (intent.hasExtra(TorServiceConstants.LOCAL_EXTRA_LOG))
|
||||
{
|
||||
String log = intent.getStringExtra("log");
|
||||
String log = intent.getStringExtra(TorServiceConstants.LOCAL_EXTRA_LOG);
|
||||
updateStatus(log);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue