mirror of
				https://github.com/oxen-io/session-android.git
				synced 2025-11-04 01:01:22 +00:00 
			
		
		
		
	Remove deprecated <2.2 caching functionality that breaks modern devices.
This commit is contained in:
		@@ -16,17 +16,8 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
package org.thoughtcrime.securesms.service;
 | 
					package org.thoughtcrime.securesms.service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.lang.reflect.InvocationTargetException;
 | 
					 | 
				
			||||||
import java.lang.reflect.Method;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
 | 
					 | 
				
			||||||
import org.thoughtcrime.securesms.R;
 | 
					 | 
				
			||||||
import org.thoughtcrime.securesms.SecureSMS;
 | 
					 | 
				
			||||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import android.app.AlarmManager;
 | 
					import android.app.AlarmManager;
 | 
				
			||||||
import android.app.Notification;
 | 
					import android.app.Notification;
 | 
				
			||||||
import android.app.NotificationManager;
 | 
					 | 
				
			||||||
import android.app.PendingIntent;
 | 
					import android.app.PendingIntent;
 | 
				
			||||||
import android.app.Service;
 | 
					import android.app.Service;
 | 
				
			||||||
import android.content.Intent;
 | 
					import android.content.Intent;
 | 
				
			||||||
@@ -37,6 +28,11 @@ import android.os.SystemClock;
 | 
				
			|||||||
import android.preference.PreferenceManager;
 | 
					import android.preference.PreferenceManager;
 | 
				
			||||||
import android.util.Log;
 | 
					import android.util.Log;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
 | 
				
			||||||
 | 
					import org.thoughtcrime.securesms.R;
 | 
				
			||||||
 | 
					import org.thoughtcrime.securesms.SecureSMS;
 | 
				
			||||||
 | 
					import org.thoughtcrime.securesms.crypto.MasterSecret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Small service that stays running to keep a key cached in memory.
 | 
					 * Small service that stays running to keep a key cached in memory.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
@@ -56,16 +52,8 @@ public class KeyCachingService extends Service {
 | 
				
			|||||||
  public  static final String ACTIVITY_STOP_EVENT      = "org.thoughtcrime.securesms.service.action.ACTIVITY_STOP_EVENT";
 | 
					  public  static final String ACTIVITY_STOP_EVENT      = "org.thoughtcrime.securesms.service.action.ACTIVITY_STOP_EVENT";
 | 
				
			||||||
  public  static final String PREFERENCES_NAME         = "SecureSMS-Preferences";
 | 
					  public  static final String PREFERENCES_NAME         = "SecureSMS-Preferences";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private static final Class[] mStartForegroundSignature = new Class[] {int.class, Notification.class};
 | 
					 | 
				
			||||||
  private static final Class[] mStopForegroundSignature = new Class[] {boolean.class};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private PendingIntent pending;
 | 
					  private PendingIntent pending;
 | 
				
			||||||
  private NotificationManager notificationManager;
 | 
					 | 
				
			||||||
  private Method mStartForeground;
 | 
					 | 
				
			||||||
  private Method mStopForeground;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
  private Object[] mStartForegroundArgs = new Object[2];
 | 
					 | 
				
			||||||
  private Object[] mStopForegroundArgs  = new Object[1];
 | 
					 | 
				
			||||||
  private int activitiesRunning = 0;
 | 
					  private int activitiesRunning = 0;
 | 
				
			||||||
  private final IBinder binder  = new KeyCachingBinder();
 | 
					  private final IBinder binder  = new KeyCachingBinder();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -100,15 +88,6 @@ public class KeyCachingService extends Service {
 | 
				
			|||||||
  @Override
 | 
					  @Override
 | 
				
			||||||
  public void onCreate() {
 | 
					  public void onCreate() {
 | 
				
			||||||
    pending = PendingIntent.getService(this, 0, new Intent(PASSPHRASE_EXPIRED_EVENT, null, this, KeyCachingService.class), 0);
 | 
					    pending = PendingIntent.getService(this, 0, new Intent(PASSPHRASE_EXPIRED_EVENT, null, this, KeyCachingService.class), 0);
 | 
				
			||||||
    notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    try {
 | 
					 | 
				
			||||||
      mStartForeground = getClass().getMethod("startForeground", mStartForegroundSignature);
 | 
					 | 
				
			||||||
      mStopForeground  = getClass().getMethod("stopForeground", mStopForegroundSignature);
 | 
					 | 
				
			||||||
    } catch (NoSuchMethodException e) {
 | 
					 | 
				
			||||||
      // Running on an older platform.
 | 
					 | 
				
			||||||
      mStartForeground = mStopForeground = null;
 | 
					 | 
				
			||||||
    }        
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Override
 | 
					  @Override
 | 
				
			||||||
@@ -133,7 +112,7 @@ public class KeyCachingService extends Service {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  private void handleClearKey() {
 | 
					  private void handleClearKey() {
 | 
				
			||||||
    this.masterSecret = null;
 | 
					    this.masterSecret = null;
 | 
				
			||||||
    stopForegroundCompat(SERVICE_RUNNING_ID);		
 | 
					    stopForeground(true);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private void handlePassphraseExpired() {
 | 
					  private void handlePassphraseExpired() {
 | 
				
			||||||
@@ -166,8 +145,8 @@ public class KeyCachingService extends Service {
 | 
				
			|||||||
    PendingIntent launchIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
 | 
					    PendingIntent launchIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
 | 
				
			||||||
    notification.setLatestEventInfo(getApplicationContext(), "TextSecure Cached", "TextSecure Passphrase Cached", launchIntent);
 | 
					    notification.setLatestEventInfo(getApplicationContext(), "TextSecure Cached", "TextSecure Passphrase Cached", launchIntent);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    stopForegroundCompat(SERVICE_RUNNING_ID);
 | 
					    stopForeground(true);
 | 
				
			||||||
    startForegroundCompat(SERVICE_RUNNING_ID, notification);
 | 
					    startForeground(SERVICE_RUNNING_ID, notification);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private void broadcastNewSecret() {
 | 
					  private void broadcastNewSecret() {
 | 
				
			||||||
@@ -190,49 +169,4 @@ public class KeyCachingService extends Service {
 | 
				
			|||||||
      return KeyCachingService.this;
 | 
					      return KeyCachingService.this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  /**
 | 
					 | 
				
			||||||
   * This is a wrapper around the new startForeground method, using the older
 | 
					 | 
				
			||||||
   * APIs if it is not available.
 | 
					 | 
				
			||||||
   */
 | 
					 | 
				
			||||||
  private void startForegroundCompat(int id, Notification notification) {
 | 
					 | 
				
			||||||
    if (mStartForeground != null) {
 | 
					 | 
				
			||||||
      mStartForegroundArgs[0] = Integer.valueOf(id);
 | 
					 | 
				
			||||||
      mStartForegroundArgs[1] = notification;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      try {
 | 
					 | 
				
			||||||
        mStartForeground.invoke(this, mStartForegroundArgs);
 | 
					 | 
				
			||||||
      } catch (InvocationTargetException e) {
 | 
					 | 
				
			||||||
        Log.w("KeyCachingService", "Unable to invoke startForeground", e);
 | 
					 | 
				
			||||||
      } catch (IllegalAccessException e) {
 | 
					 | 
				
			||||||
        Log.w("KeyCachingService", "Unable to invoke startForeground", e);
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      return;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
    setForeground(true);
 | 
					 | 
				
			||||||
    notificationManager.notify(id, notification);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
  /**
 | 
					 | 
				
			||||||
   * This is a wrapper around the new stopForeground method, using the older
 | 
					 | 
				
			||||||
   * APIs if it is not available.
 | 
					 | 
				
			||||||
   */
 | 
					 | 
				
			||||||
  private void stopForegroundCompat(int id) {
 | 
					 | 
				
			||||||
    Log.w("KeyCachingService", "Calling stopForeground!");
 | 
					 | 
				
			||||||
    if (mStopForeground != null) {
 | 
					 | 
				
			||||||
      mStopForegroundArgs[0] = Boolean.TRUE;
 | 
					 | 
				
			||||||
      try {
 | 
					 | 
				
			||||||
        mStopForeground.invoke(this, mStopForegroundArgs);
 | 
					 | 
				
			||||||
      } catch (InvocationTargetException e) {
 | 
					 | 
				
			||||||
        Log.w("KeyCachingService", "Unable to invoke stopForeground", e);
 | 
					 | 
				
			||||||
      } catch (IllegalAccessException e) {
 | 
					 | 
				
			||||||
        Log.w("KeyCachingService", "Unable to invoke stopForeground", e);
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      return;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
    notificationManager.cancel(id);
 | 
					 | 
				
			||||||
    setForeground(false);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user