Notification fix and change in finding existing process
- Only build expanded notification on supported platforms - If service is re-created() try to find existing process then, and don't wait for bind() from client
This commit is contained in:
parent
387e74ec7c
commit
c517d0fcee
|
@ -237,6 +237,42 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
Intent intent = new Intent(TorService.this, Orbot.class);
|
Intent intent = new Intent(TorService.this, Orbot.class);
|
||||||
PendingIntent pendIntent = PendingIntent.getActivity(TorService.this, 0, intent, 0);
|
PendingIntent pendIntent = PendingIntent.getActivity(TorService.this, 0, intent, 0);
|
||||||
|
|
||||||
|
if (mNotifyBuilder == null)
|
||||||
|
{
|
||||||
|
|
||||||
|
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
|
if (mNotifyBuilder == null)
|
||||||
|
{
|
||||||
|
mNotifyBuilder = new NotificationCompat.Builder(this)
|
||||||
|
.setContentTitle(getString(R.string.app_name))
|
||||||
|
.setSmallIcon(R.drawable.ic_stat_tor);
|
||||||
|
|
||||||
|
mNotifyBuilder.setContentIntent(pendIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
mNotifyBuilder.setContentText(notifyMsg);
|
||||||
|
mNotifyBuilder.setSmallIcon(icon);
|
||||||
|
|
||||||
|
if (notifyType != NOTIFY_ID)
|
||||||
|
{
|
||||||
|
mNotifyBuilder.setTicker(notifyMsg);
|
||||||
|
// mNotifyBuilder.setLights(Color.GREEN, 1000, 1000);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mNotifyBuilder.setTicker(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
mNotifyBuilder.setOngoing(prefPersistNotifications);
|
||||||
|
|
||||||
|
mNotification = mNotifyBuilder.build();
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= 16) {
|
||||||
|
|
||||||
|
|
||||||
// Create remote view that needs to be set as bigContentView for the notification.
|
// Create remote view that needs to be set as bigContentView for the notification.
|
||||||
RemoteViews expandedView = new RemoteViews(this.getPackageName(),
|
RemoteViews expandedView = new RemoteViews(this.getPackageName(),
|
||||||
R.layout.layout_notification_expanded);
|
R.layout.layout_notification_expanded);
|
||||||
|
@ -284,41 +320,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
// expandedView.setTextViewText(R.id.info, infoMessage.toString());
|
// expandedView.setTextViewText(R.id.info, infoMessage.toString());
|
||||||
// expandedView.setOnClickPendingIntent(R.id._tor_notificationBT, pendIntent);
|
// expandedView.setOnClickPendingIntent(R.id._tor_notificationBT, pendIntent);
|
||||||
expandedView.setImageViewResource(R.id.icon, icon);
|
expandedView.setImageViewResource(R.id.icon, icon);
|
||||||
|
|
||||||
if (mNotifyBuilder == null)
|
|
||||||
{
|
|
||||||
|
|
||||||
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
|
||||||
|
|
||||||
if (mNotifyBuilder == null)
|
|
||||||
{
|
|
||||||
mNotifyBuilder = new NotificationCompat.Builder(this)
|
|
||||||
.setContentTitle(getString(R.string.app_name))
|
|
||||||
.setSmallIcon(R.drawable.ic_stat_tor);
|
|
||||||
|
|
||||||
mNotifyBuilder.setContentIntent(pendIntent);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
mNotifyBuilder.setContentText(notifyMsg);
|
|
||||||
mNotifyBuilder.setSmallIcon(icon);
|
|
||||||
|
|
||||||
if (notifyType != NOTIFY_ID)
|
|
||||||
{
|
|
||||||
mNotifyBuilder.setTicker(notifyMsg);
|
|
||||||
// mNotifyBuilder.setLights(Color.GREEN, 1000, 1000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mNotifyBuilder.setTicker(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
mNotifyBuilder.setOngoing(prefPersistNotifications);
|
|
||||||
|
|
||||||
mNotification = mNotifyBuilder.build();
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= 16) {
|
|
||||||
mNotification.bigContentView = expandedView;
|
mNotification.bigContentView = expandedView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -565,8 +566,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
||||||
// android.os.Debug.waitForDebugger();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
initBinariesAndDirectories();
|
initBinariesAndDirectories();
|
||||||
|
@ -577,6 +576,23 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
Log.e(TAG, "Error installing Orbot binaries",e);
|
Log.e(TAG, "Error installing Orbot binaries",e);
|
||||||
logNotice("There was an error installing Orbot binaries");
|
logNotice("There was an error installing Orbot binaries");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mExecutor.execute(new Runnable ()
|
||||||
|
{
|
||||||
|
public void run ()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
findExistingProc ();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.e(TAG,"error onBind",e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initBinariesAndDirectories () throws Exception
|
private void initBinariesAndDirectories () throws Exception
|
||||||
|
@ -971,7 +987,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
private synchronized int initControlConnection (int maxTries) throws Exception, RuntimeException
|
private synchronized int initControlConnection (int maxTries) throws Exception, RuntimeException
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int controlPort = getControlPort();
|
int controlPort = -1;
|
||||||
File fileCookie = new File(appCacheHome, TOR_CONTROL_COOKIE);
|
File fileCookie = new File(appCacheHome, TOR_CONTROL_COOKIE);
|
||||||
|
|
||||||
if (conn != null)
|
if (conn != null)
|
||||||
|
@ -1088,11 +1104,18 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
result = Integer.parseInt(lineParts[1]);
|
result = Integer.parseInt(lineParts[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bufferedReader.close();
|
bufferedReader.close();
|
||||||
|
|
||||||
|
//store last valid control port
|
||||||
|
SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
|
||||||
|
prefs.edit().putInt("controlport", result).commit();
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logNotice("Control Port config file does not yet exist (waiting for tor): " + fileControlPort.getCanonicalPath());
|
logNotice("Control Port config file does not yet exist (waiting for tor): " + fileControlPort.getCanonicalPath());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1492,21 +1515,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
|
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
|
|
||||||
mExecutor.execute(new Runnable ()
|
|
||||||
{
|
|
||||||
public void run ()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
findExistingProc ();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.e(TAG,"error onBind",e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return mBinder;
|
return mBinder;
|
||||||
}
|
}
|
||||||
|
@ -1798,8 +1806,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
|
|
||||||
boolean doNetworKSleep = prefs.getBoolean(TorConstants.PREF_DISABLE_NETWORK, true);
|
boolean doNetworKSleep = prefs.getBoolean(TorConstants.PREF_DISABLE_NETWORK, true);
|
||||||
|
|
||||||
if (doNetworKSleep && mBinder != null)
|
|
||||||
{
|
|
||||||
final ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
final ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
final NetworkInfo netInfo = cm.getActiveNetworkInfo();
|
final NetworkInfo netInfo = cm.getActiveNetworkInfo();
|
||||||
|
|
||||||
|
@ -1812,9 +1818,14 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
mConnectivity = false;
|
mConnectivity = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (doNetworKSleep)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
|
if (mBinder != null)
|
||||||
|
{
|
||||||
mBinder.updateConfiguration("DisableNetwork", mConnectivity ? "0" : "1", false);
|
mBinder.updateConfiguration("DisableNetwork", mConnectivity ? "0" : "1", false);
|
||||||
mBinder.saveConfiguration();
|
mBinder.saveConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
if (currentStatus == STATUS_ON)
|
if (currentStatus == STATUS_ON)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue