mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 18:43:49 +00:00
Be more explicit with mastersecret passing
This commit is contained in:
parent
d5cb804f90
commit
ed508a8def
@ -1,5 +1,6 @@
|
|||||||
package org.thoughtcrime.securesms.components;
|
package org.thoughtcrime.securesms.components;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
@ -15,6 +16,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
|||||||
import com.bumptech.glide.request.target.Target;
|
import com.bumptech.glide.request.target.Target;
|
||||||
import com.davemorrissey.labs.subscaleview.ImageSource;
|
import com.davemorrissey.labs.subscaleview.ImageSource;
|
||||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
|
||||||
|
import com.davemorrissey.labs.subscaleview.decoder.DecoderFactory;
|
||||||
import com.github.chrisbanes.photoview.PhotoView;
|
import com.github.chrisbanes.photoview.PhotoView;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
@ -55,11 +57,10 @@ public class ZoomingImageView extends FrameLayout {
|
|||||||
this.photoView = findViewById(R.id.image_view);
|
this.photoView = findViewById(R.id.image_view);
|
||||||
this.subsamplingImageView = findViewById(R.id.subsampling_image_view);
|
this.subsamplingImageView = findViewById(R.id.subsampling_image_view);
|
||||||
|
|
||||||
this.subsamplingImageView.setBitmapDecoderClass(AttachmentBitmapDecoder.class);
|
|
||||||
this.subsamplingImageView.setRegionDecoderClass(AttachmentRegionDecoder.class);
|
|
||||||
this.subsamplingImageView.setOrientation(SubsamplingScaleImageView.ORIENTATION_USE_EXIF);
|
this.subsamplingImageView.setOrientation(SubsamplingScaleImageView.ORIENTATION_USE_EXIF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("StaticFieldLeak")
|
||||||
public void setImageUri(@NonNull MasterSecret masterSecret, @NonNull GlideRequests glideRequests,
|
public void setImageUri(@NonNull MasterSecret masterSecret, @NonNull GlideRequests glideRequests,
|
||||||
@NonNull Uri uri, @NonNull String contentType)
|
@NonNull Uri uri, @NonNull String contentType)
|
||||||
{
|
{
|
||||||
@ -90,7 +91,7 @@ public class ZoomingImageView extends FrameLayout {
|
|||||||
setImageViewUri(masterSecret, glideRequests, uri);
|
setImageViewUri(masterSecret, glideRequests, uri);
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "Loading in subsampling image view...");
|
Log.w(TAG, "Loading in subsampling image view...");
|
||||||
setSubsamplingImageViewUri(uri);
|
setSubsamplingImageViewUri(masterSecret, uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
@ -107,7 +108,10 @@ public class ZoomingImageView extends FrameLayout {
|
|||||||
.into(photoView);
|
.into(photoView);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSubsamplingImageViewUri(@NonNull Uri uri) {
|
private void setSubsamplingImageViewUri(@NonNull MasterSecret masterSecret, @NonNull Uri uri) {
|
||||||
|
subsamplingImageView.setBitmapDecoderFactory(new AttachmentBitmapDecoderFactory(masterSecret));
|
||||||
|
subsamplingImageView.setRegionDecoderFactory(new AttachmentRegionDecoderFactory(masterSecret));
|
||||||
|
|
||||||
subsamplingImageView.setVisibility(View.VISIBLE);
|
subsamplingImageView.setVisibility(View.VISIBLE);
|
||||||
photoView.setVisibility(View.GONE);
|
photoView.setVisibility(View.GONE);
|
||||||
|
|
||||||
@ -118,4 +122,33 @@ public class ZoomingImageView extends FrameLayout {
|
|||||||
photoView.setImageDrawable(null);
|
photoView.setImageDrawable(null);
|
||||||
subsamplingImageView.recycle();
|
subsamplingImageView.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class AttachmentBitmapDecoderFactory implements DecoderFactory<AttachmentBitmapDecoder> {
|
||||||
|
|
||||||
|
private final MasterSecret masterSecret;
|
||||||
|
|
||||||
|
private AttachmentBitmapDecoderFactory(MasterSecret masterSecret) {
|
||||||
|
this.masterSecret = masterSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttachmentBitmapDecoder make() throws IllegalAccessException, InstantiationException {
|
||||||
|
return new AttachmentBitmapDecoder(masterSecret);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class AttachmentRegionDecoderFactory implements DecoderFactory<AttachmentRegionDecoder> {
|
||||||
|
|
||||||
|
private final MasterSecret masterSecret;
|
||||||
|
|
||||||
|
private AttachmentRegionDecoderFactory(@NonNull MasterSecret masterSecret) {
|
||||||
|
this.masterSecret = masterSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttachmentRegionDecoder make() throws IllegalAccessException, InstantiationException {
|
||||||
|
return new AttachmentRegionDecoder(masterSecret);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import android.graphics.Bitmap;
|
|||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.davemorrissey.labs.subscaleview.decoder.ImageDecoder;
|
import com.davemorrissey.labs.subscaleview.decoder.ImageDecoder;
|
||||||
import com.davemorrissey.labs.subscaleview.decoder.SkiaImageDecoder;
|
import com.davemorrissey.labs.subscaleview.decoder.SkiaImageDecoder;
|
||||||
@ -18,18 +19,18 @@ import java.io.InputStream;
|
|||||||
|
|
||||||
public class AttachmentBitmapDecoder implements ImageDecoder{
|
public class AttachmentBitmapDecoder implements ImageDecoder{
|
||||||
|
|
||||||
|
private final MasterSecret masterSecret;
|
||||||
|
|
||||||
|
public AttachmentBitmapDecoder(@NonNull MasterSecret masterSecret) {
|
||||||
|
this.masterSecret = masterSecret;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Bitmap decode(Context context, Uri uri) throws Exception {
|
public Bitmap decode(Context context, Uri uri) throws Exception {
|
||||||
if (!PartAuthority.isLocalUri(uri)) {
|
if (!PartAuthority.isLocalUri(uri)) {
|
||||||
return new SkiaImageDecoder().decode(context, uri);
|
return new SkiaImageDecoder().decode(context, uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
MasterSecret masterSecret = KeyCachingService.getMasterSecret(context);
|
|
||||||
|
|
||||||
if (masterSecret == null) {
|
|
||||||
throw new IllegalStateException("Can't decode without secret");
|
|
||||||
}
|
|
||||||
|
|
||||||
InputStream inputStream = PartAuthority.getAttachmentStream(context, masterSecret, uri);
|
InputStream inputStream = PartAuthority.getAttachmentStream(context, masterSecret, uri);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -8,8 +8,7 @@ import android.graphics.BitmapRegionDecoder;
|
|||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.RequiresApi;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.davemorrissey.labs.subscaleview.decoder.ImageRegionDecoder;
|
import com.davemorrissey.labs.subscaleview.decoder.ImageRegionDecoder;
|
||||||
@ -17,7 +16,6 @@ import com.davemorrissey.labs.subscaleview.decoder.SkiaImageRegionDecoder;
|
|||||||
|
|
||||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
@ -25,11 +23,16 @@ public class AttachmentRegionDecoder implements ImageRegionDecoder {
|
|||||||
|
|
||||||
private static final String TAG = AttachmentRegionDecoder.class.getName();
|
private static final String TAG = AttachmentRegionDecoder.class.getName();
|
||||||
|
|
||||||
|
private final MasterSecret masterSecret;
|
||||||
|
|
||||||
private SkiaImageRegionDecoder passthrough;
|
private SkiaImageRegionDecoder passthrough;
|
||||||
|
|
||||||
private BitmapRegionDecoder bitmapRegionDecoder;
|
private BitmapRegionDecoder bitmapRegionDecoder;
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.GINGERBREAD_MR1)
|
public AttachmentRegionDecoder(@NonNull MasterSecret masterSecret) {
|
||||||
|
this.masterSecret = masterSecret;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Point init(Context context, Uri uri) throws Exception {
|
public Point init(Context context, Uri uri) throws Exception {
|
||||||
Log.w(TAG, "Init!");
|
Log.w(TAG, "Init!");
|
||||||
@ -38,12 +41,6 @@ public class AttachmentRegionDecoder implements ImageRegionDecoder {
|
|||||||
return passthrough.init(context, uri);
|
return passthrough.init(context, uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
MasterSecret masterSecret = KeyCachingService.getMasterSecret(context);
|
|
||||||
|
|
||||||
if (masterSecret == null) {
|
|
||||||
throw new IllegalStateException("No master secret available...");
|
|
||||||
}
|
|
||||||
|
|
||||||
InputStream inputStream = PartAuthority.getAttachmentStream(context, masterSecret, uri);
|
InputStream inputStream = PartAuthority.getAttachmentStream(context, masterSecret, uri);
|
||||||
|
|
||||||
this.bitmapRegionDecoder = BitmapRegionDecoder.newInstance(inputStream, false);
|
this.bitmapRegionDecoder = BitmapRegionDecoder.newInstance(inputStream, false);
|
||||||
@ -52,7 +49,6 @@ public class AttachmentRegionDecoder implements ImageRegionDecoder {
|
|||||||
return new Point(bitmapRegionDecoder.getWidth(), bitmapRegionDecoder.getHeight());
|
return new Point(bitmapRegionDecoder.getWidth(), bitmapRegionDecoder.getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.GINGERBREAD_MR1)
|
|
||||||
@Override
|
@Override
|
||||||
public Bitmap decodeRegion(Rect rect, int sampleSize) {
|
public Bitmap decodeRegion(Rect rect, int sampleSize) {
|
||||||
Log.w(TAG, "Decode region: " + rect);
|
Log.w(TAG, "Decode region: " + rect);
|
||||||
@ -76,14 +72,12 @@ public class AttachmentRegionDecoder implements ImageRegionDecoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.GINGERBREAD_MR1)
|
|
||||||
public boolean isReady() {
|
public boolean isReady() {
|
||||||
Log.w(TAG, "isReady");
|
Log.w(TAG, "isReady");
|
||||||
return (passthrough != null && passthrough.isReady()) ||
|
return (passthrough != null && passthrough.isReady()) ||
|
||||||
(bitmapRegionDecoder != null && !bitmapRegionDecoder.isRecycled());
|
(bitmapRegionDecoder != null && !bitmapRegionDecoder.isRecycled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.GINGERBREAD_MR1)
|
|
||||||
public void recycle() {
|
public void recycle() {
|
||||||
if (passthrough != null) {
|
if (passthrough != null) {
|
||||||
passthrough.recycle();
|
passthrough.recycle();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user