Loading src/main/java/org/torproject/android/service/OrbotConstants.java +4 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,10 @@ public interface OrbotConstants { * {@link Intent} send by Orbot with {@code ON/OFF/STARTING/STOPPING} status */ String ACTION_STATUS = "org.torproject.android.intent.action.STATUS"; String ACTION_CHECK_RUNNING_SYNC = "org.torproject.android.intent.action.CHECK_RUNNING_SYNC"; String ACTION_RUNNING_SYNC = "org.torproject.android.intent.action.RUNNING_SYNC"; /** * {@code String} that contains a status constant: {@link #STATUS_ON}, * {@link #STATUS_OFF}, {@link #STATUS_STARTING}, or Loading src/main/java/org/torproject/android/service/OrbotService.java +15 −0 Original line number Diff line number Diff line Loading @@ -101,6 +101,7 @@ public class OrbotService extends VpnService implements OrbotConstants { //we should randomly sort alBridges so we don't have the same bridge order each time final Random bridgeSelectRandom = new Random(System.nanoTime()); ActionBroadcastReceiver mActionBroadcastReceiver; private IsServiceRunningBroadcastReceiver mIsServiceRunningBroadcastReceiver; private String mCurrentStatus = STATUS_OFF; TorControlConnection conn = null; private ServiceConnection torServiceConnection; Loading Loading @@ -249,6 +250,7 @@ public class OrbotService extends VpnService implements OrbotConstants { public void onDestroy() { try { unregisterReceiver(mActionBroadcastReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(mIsServiceRunningBroadcastReceiver); } catch (IllegalArgumentException iae) { //not registered yet } Loading Loading @@ -480,6 +482,11 @@ public class OrbotService extends VpnService implements OrbotConstants { mActionBroadcastReceiver = new ActionBroadcastReceiver(); registerReceiver(mActionBroadcastReceiver, filter); mIsServiceRunningBroadcastReceiver = new IsServiceRunningBroadcastReceiver(); LocalBroadcastManager.getInstance(this).registerReceiver( mIsServiceRunningBroadcastReceiver, new IntentFilter(ACTION_CHECK_RUNNING_SYNC)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) createNotificationChannel(); Loading Loading @@ -1505,4 +1512,12 @@ public class OrbotService extends VpnService implements OrbotConstants { LocalBroadcastManager.getInstance(OrbotService.this).sendBroadcast(localStatus); // update the activity with what's new } private class IsServiceRunningBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent resIntent = new Intent(ACTION_RUNNING_SYNC); resIntent.putExtra(EXTRA_STATUS, mCurrentStatus); LocalBroadcastManager.getInstance(context).sendBroadcastSync(resIntent); } } } Loading
src/main/java/org/torproject/android/service/OrbotConstants.java +4 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,10 @@ public interface OrbotConstants { * {@link Intent} send by Orbot with {@code ON/OFF/STARTING/STOPPING} status */ String ACTION_STATUS = "org.torproject.android.intent.action.STATUS"; String ACTION_CHECK_RUNNING_SYNC = "org.torproject.android.intent.action.CHECK_RUNNING_SYNC"; String ACTION_RUNNING_SYNC = "org.torproject.android.intent.action.RUNNING_SYNC"; /** * {@code String} that contains a status constant: {@link #STATUS_ON}, * {@link #STATUS_OFF}, {@link #STATUS_STARTING}, or Loading
src/main/java/org/torproject/android/service/OrbotService.java +15 −0 Original line number Diff line number Diff line Loading @@ -101,6 +101,7 @@ public class OrbotService extends VpnService implements OrbotConstants { //we should randomly sort alBridges so we don't have the same bridge order each time final Random bridgeSelectRandom = new Random(System.nanoTime()); ActionBroadcastReceiver mActionBroadcastReceiver; private IsServiceRunningBroadcastReceiver mIsServiceRunningBroadcastReceiver; private String mCurrentStatus = STATUS_OFF; TorControlConnection conn = null; private ServiceConnection torServiceConnection; Loading Loading @@ -249,6 +250,7 @@ public class OrbotService extends VpnService implements OrbotConstants { public void onDestroy() { try { unregisterReceiver(mActionBroadcastReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(mIsServiceRunningBroadcastReceiver); } catch (IllegalArgumentException iae) { //not registered yet } Loading Loading @@ -480,6 +482,11 @@ public class OrbotService extends VpnService implements OrbotConstants { mActionBroadcastReceiver = new ActionBroadcastReceiver(); registerReceiver(mActionBroadcastReceiver, filter); mIsServiceRunningBroadcastReceiver = new IsServiceRunningBroadcastReceiver(); LocalBroadcastManager.getInstance(this).registerReceiver( mIsServiceRunningBroadcastReceiver, new IntentFilter(ACTION_CHECK_RUNNING_SYNC)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) createNotificationChannel(); Loading Loading @@ -1505,4 +1512,12 @@ public class OrbotService extends VpnService implements OrbotConstants { LocalBroadcastManager.getInstance(OrbotService.this).sendBroadcast(localStatus); // update the activity with what's new } private class IsServiceRunningBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent resIntent = new Intent(ACTION_RUNNING_SYNC); resIntent.putExtra(EXTRA_STATUS, mCurrentStatus); LocalBroadcastManager.getInstance(context).sendBroadcastSync(resIntent); } } }