导航菜单

页面标题

页面副标题

SpeedCash v6.5.1482 - BBDownloadManager.java 源代码

正在查看: SpeedCash v6.5.1482 应用的 BBDownloadManager.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.bm.sc.bebasbayar.service;

import android.app.IntentService;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.AudioAttributes;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.webkit.MimeTypeMap;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import com.bm.sc.bebasbayar.R;
import com.bm.sc.bebasbayar.handler.FirebaseProcessor;
import com.bm.sc.bebasbayar.handler.MessageComposer;
import com.bm.sc.bebasbayar.handler.MessageSender;
import com.bm.sc.bebasbayar.handler.network.DownloadProgressInterceptor;
import com.bm.sc.bebasbayar.handler.network.DownloadProgressResponseBody;
import com.bm.sc.bebasbayar.iface.MessageProcess;
import com.bm.sc.bebasbayar.message.BaseMessage;
import com.bm.sc.bebasbayar.message.MPMessage;
import com.bm.sc.bebasbayar.message.ServiceMessage;
import com.bm.sc.bebasbayar.setting.ApiConfig;
import com.bm.sc.bebasbayar.setting.session.AppSession;
import com.bm.sc.util.android.Imagery;
import com.bm.sc.util.common.Var;
import com.google.firebase.perf.network.FirebasePerfOkHttpClient;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.jetbrains.annotations.NotNull;

public class BBDownloadManager extends IntentService {
    public static final String FILENAME_TAG = "file:name:tag";
    public static final String SERVICE_MESSAGE_TAG = "service:message:tag";
    public static final String TITLE_TAG = "title:tag";
    public static final String URL_TAG = "url:tag";

    public class a implements DownloadProgressResponseBody.DownloadProgressListener {
        public final int a;
        public final NotificationCompat.Builder b;
        public final NotificationManager c;

        public a(int i, NotificationCompat.Builder builder, NotificationManager notificationManager) {
            this.a = i;
            this.b = builder;
            this.c = notificationManager;
        }

        @Override
        public void onDownloadProgress(long j, long j2, boolean z) {
            BBDownloadManager.this.h(100, (int) ((j / j2) * 100), this.a, this.b, this.c);
        }

        @Override
        public void onDownloadStart(long j) {
        }
    }

    public class b implements Callback {
        public final Bundle a;
        public final int b;
        public final String c;

        public b(Bundle bundle, int i, String str) {
            this.a = bundle;
            this.b = i;
            this.c = str;
        }

        public void onFailure(@NotNull Call call, @NotNull IOException iOException) {
            BBDownloadManager.this.g(this.a, this.b, BBDownloadManager.this.getString(R.string.error_download_file, this.c) + " " + iOException.getMessage());
        }

        public void onResponse(@NotNull Call call, @NotNull Response response) {
            try {
                String str = BBDownloadManager.createFileName() + this.c;
                File file = new File(BBDownloadManager.this.getApplicationContext().getCacheDir().toString() + "/" + str);
                ResponseBody body = response.body();
                if (body != null) {
                    InputStream byteStream = body.byteStream();
                    FileOutputStream fileOutputStream = new FileOutputStream(file);
                    byte[] bArr = new byte[1024];
                    while (true) {
                        int read = byteStream.read(bArr);
                        if (read == -1) {
                            break;
                        }
                        Arrays.toString(bArr);
                        fileOutputStream.write(bArr, 0, read);
                    }
                    fileOutputStream.close();
                    byteStream.close();
                    body.close();
                    int i = Build.VERSION.SDK_INT;
                    Uri uriForFile = i >= 24 ? FileProvider.getUriForFile(BBDownloadManager.this, "com.bm.sc.bebasbayar.provider", file) : Uri.fromFile(file);
                    String fileExtensionFromUrl = MimeTypeMap.getFileExtensionFromUrl(uriForFile.toString());
                    Intent intent = new Intent();
                    intent.setAction("android.intent.action.VIEW");
                    intent.setDataAndType(uriForFile, MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtensionFromUrl));
                    intent.setFlags(268435457);
                    PendingIntent activity = i >= 31 ? PendingIntent.getActivity(BBDownloadManager.this, 0, intent, 1140850688) : PendingIntent.getActivity(BBDownloadManager.this, 0, intent, 1140850688);
                    String string = this.a.getString(BBDownloadManager.TITLE_TAG) != null ? this.a.getString(BBDownloadManager.TITLE_TAG) : BBDownloadManager.this.getString(R.string.title_download_invoice);
                    if (i >= 30) {
                        FileInputStream fileInputStream = new FileInputStream(BBDownloadManager.this.getApplicationContext().getDatabasePath(file.toString()));
                        File file2 = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/" + str);
                        FileOutputStream fileOutputStream2 = new FileOutputStream(file2);
                        BBDownloadManager bBDownloadManager = BBDownloadManager.this;
                        bBDownloadManager.copyFile(fileInputStream, fileOutputStream2, bBDownloadManager.getApplicationContext(), activity, this.b, string, false, file2);
                        return;
                    }
                    FileInputStream fileInputStream2 = new FileInputStream(BBDownloadManager.this.getApplicationContext().getDatabasePath(file.toString()));
                    File file3 = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/" + str);
                    FileOutputStream fileOutputStream3 = new FileOutputStream(file3);
                    BBDownloadManager bBDownloadManager2 = BBDownloadManager.this;
                    bBDownloadManager2.copyFile(fileInputStream2, fileOutputStream3, bBDownloadManager2.getApplicationContext(), activity, this.b, string, false, file3);
                }
            } catch (Exception e) {
                if (ApiConfig.isLoggable()) {
                    e.getMessage();
                }
                BBDownloadManager.this.g(this.a, this.b, BBDownloadManager.this.getString(R.string.error_download_file, this.c) + " " + e.getMessage());
            }
        }
    }

    public class c implements MessageProcess {
        public final NotificationCompat.Builder a;
        public final NotificationManager b;
        public final int c;
        public final Bundle d;

        public c(NotificationCompat.Builder builder, NotificationManager notificationManager, int i, Bundle bundle) {
            this.a = builder;
            this.b = notificationManager;
            this.c = i;
            this.d = bundle;
        }

        @Override
        public void afterProcess(BaseMessage baseMessage) {
            boolean z = false;
            this.a.setProgress(0, 0, false);
            NotificationManager notificationManager = this.b;
            if (notificationManager != null) {
                notificationManager.notify(this.c, this.a.build());
            } else {
                NotificationManagerCompat from = NotificationManagerCompat.from(BBDownloadManager.this);
                if (ContextCompat.checkSelfPermission(BBDownloadManager.this.getApplicationContext(), "android.permission.POST_NOTIFICATIONS") != 0) {
                    return;
                } else {
                    from.notify(this.c, this.a.build());
                }
            }
            String var = Var.toString(baseMessage.getItem(MPMessage.INDEX_DESC), "");
            BBDownloadManager bBDownloadManager = BBDownloadManager.this;
            Bundle bundle = this.d;
            int i = this.c;
            if (baseMessage.getItem(MPMessage.INDEX_RC) != null && baseMessage.getItem(MPMessage.INDEX_RC).equals("00") && !var.isEmpty()) {
                z = true;
            }
            bBDownloadManager.f(bundle, i, var, z);
        }

        @Override
        public void backgroundProcess(long j, long j2, boolean z) {
        }

        @Override
        public void preProcess() {
            this.a.setProgress(0, 0, true);
            NotificationManager notificationManager = this.b;
            if (notificationManager != null) {
                notificationManager.notify(this.c, this.a.build());
                return;
            }
            NotificationManagerCompat from = NotificationManagerCompat.from(BBDownloadManager.this);
            if (ContextCompat.checkSelfPermission(BBDownloadManager.this.getApplicationContext(), "android.permission.POST_NOTIFICATIONS") != 0) {
                return;
            }
            from.notify(this.c, this.a.build());
        }
    }

    public BBDownloadManager() {
        super("BBDownloadManager");
    }

    public static String createFileName() {
        Date date = new Date(System.currentTimeMillis());
        return new SimpleDateFormat("yyyymmdd-HHmmss", Locale.getDefault()).format(date) + "-";
    }

    public void copyFile(java.io.FileInputStream r15, java.io.FileOutputStream r16, android.content.Context r17, android.app.PendingIntent r18, int r19, java.lang.String r20, boolean r21, java.io.File r22) throws java.io.IOException {
        throw new UnsupportedOperationException("Method not decompiled: com.bm.sc.bebasbayar.service.BBDownloadManager.copyFile(java.io.FileInputStream, java.io.FileOutputStream, android.content.Context, android.app.PendingIntent, int, java.lang.String, boolean, java.io.File):void");
    }

    public final void d(String str, String str2, Bundle bundle) {
        Uri defaultUri;
        String string;
        Bitmap decodeResource = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_round);
        NotificationManager notificationManager = (NotificationManager) getSystemService("notification");
        if (new AppSession(getApplicationContext()).isEnableSoundSpeedCash()) {
            defaultUri = Uri.parse("android.resource://" + getApplicationContext().getPackageName() + "/" + R.raw.sc_ringtone);
        } else {
            defaultUri = RingtoneManager.getDefaultUri(2);
        }
        if (Build.VERSION.SDK_INT > 25 && notificationManager != null) {
            NotificationChannel notificationChannel = new NotificationChannel(getString(2132017323), getString(2132017323), 3);
            k83.a(notificationChannel, defaultUri, new AudioAttributes.Builder().setContentType(4).setUsage(10).build());
            l73.a(notificationManager, notificationChannel);
        }
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(2132017323));
        if (bundle.getString(TITLE_TAG) != null) {
            string = bundle.getString(TITLE_TAG);
            builder.setSmallIcon(R.mipmap.ic_launcher_round);
        } else {
            string = getString(R.string.title_download_invoice);
            builder.setSmallIcon(R.drawable.ic_picture_as_pdf_white_36dp);
        }
        builder.setContentTitle(string).setContentText(getString(R.string.process_download_file, str2)).setLargeIcon(decodeResource);
        int currentTimeMillis = (int) System.currentTimeMillis();
        h(0, 0, currentTimeMillis, builder, notificationManager);
        OkHttpClient.Builder addNetworkInterceptor = new OkHttpClient.Builder().addNetworkInterceptor(new DownloadProgressInterceptor(new a(currentTimeMillis, builder, notificationManager)));
        addNetworkInterceptor.followRedirects(true).followSslRedirects(true);
        FirebasePerfOkHttpClient.enqueue(addNetworkInterceptor.build().newCall(new Request.Builder().url(str).build()), new b(bundle, currentTimeMillis, str2));
    }

    public final void e(Bundle bundle, ServiceMessage serviceMessage) {
        String string;
        int mid = serviceMessage.getMid();
        String string2 = bundle.getString(FILENAME_TAG, "-");
        String service = serviceMessage.getService();
        Bitmap decodeResource = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_round);
        NotificationManager notificationManager = (NotificationManager) getSystemService("notification");
        Uri parse = new AppSession(getApplicationContext()).isEnableSoundSpeedCash() ? Uri.parse("android.resource://" + getApplicationContext().getPackageName() + "/" + R.raw.sc_ringtone) : RingtoneManager.getDefaultUri(2);
        if (Build.VERSION.SDK_INT > 25 && notificationManager != null) {
            NotificationChannel notificationChannel = new NotificationChannel(getString(2132017323), getString(2132017323), 3);
            k83.a(notificationChannel, parse, new AudioAttributes.Builder().setContentType(4).setUsage(10).build());
            l73.a(notificationManager, notificationChannel);
        }
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(2132017323));
        if (bundle.getString(TITLE_TAG) != null) {
            string = bundle.getString(TITLE_TAG);
            builder.setSmallIcon(R.mipmap.ic_launcher_round);
        } else {
            string = getString(R.string.title_download_invoice);
            builder.setSmallIcon(R.drawable.ic_picture_as_pdf_white_36dp);
        }
        builder.setContentTitle(string).setContentText(getString(R.string.process_download_file, string2)).setLargeIcon(decodeResource);
        MessageComposer messageComposer = new MessageComposer(1, "index.php/services/" + service);
        messageComposer.setRequest_method(MessageComposer.POST);
        messageComposer.setData_type(1);
        messageComposer.setIs_credential(false);
        messageComposer.setIs_encrypted(false);
        messageComposer.setShowProgressRegular(false);
        messageComposer.setRead_timeout(120);
        for (Map.Entry<String, Serializable> entry : serviceMessage.entrySet()) {
            messageComposer.addMessage(entry.getKey(), entry.getValue());
        }
        messageComposer.setMessageProcess(new c(builder, notificationManager, mid, bundle));
        new MessageSender(this, messageComposer).execute();
    }

    public final void f(Bundle bundle, int i, String str, boolean z) {
        File file;
        String string = bundle.getString(FILENAME_TAG, "-");
        if (!z) {
            g(bundle, i, getString(R.string.error_download_file, string));
            return;
        }
        try {
            file = Imagery.createFileFromBase64(str, string);
        } catch (IOException unused) {
            file = null;
        }
        if (file == null) {
            g(bundle, i, getString(R.string.error_write_file));
            return;
        }
        Uri fromFile = Uri.fromFile(file);
        String fileExtensionFromUrl = MimeTypeMap.getFileExtensionFromUrl(fromFile.toString());
        Intent intent = new Intent();
        intent.setAction("android.intent.action.VIEW");
        intent.setDataAndType(fromFile, MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtensionFromUrl));
        FirebaseProcessor.sendNotification(this, Build.VERSION.SDK_INT >= 31 ? PendingIntent.getActivity(this, 0, intent, 1140850688) : PendingIntent.getActivity(this, 0, intent, 1140850688), i, bundle.getString(TITLE_TAG) != null ? bundle.getString(TITLE_TAG) : getString(R.string.title_download_invoice), getString(R.string.info_download_finished, file.getName()), false);
    }

    public final void g(Bundle bundle, int i, String str) {
        String string;
        Intent intent = new Intent(this, getClass());
        intent.putExtras(bundle);
        NotificationManager notificationManager = (NotificationManager) getSystemService("notification");
        if (notificationManager != null) {
            notificationManager.cancel(i);
            if (Build.VERSION.SDK_INT > 25) {
                l73.a(notificationManager, new NotificationChannel(getString(2132017323), getString(2132017323), 3));
            }
        }
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(2132017323));
        PendingIntent service = Build.VERSION.SDK_INT >= 31 ? PendingIntent.getService(this, 0, intent, 335544320) : PendingIntent.getService(this, 0, intent, 335544320);
        if (bundle.getString(TITLE_TAG) != null) {
            string = bundle.getString(TITLE_TAG);
            builder.setSmallIcon(R.mipmap.ic_launcher_round);
        } else {
            string = getString(R.string.title_download_invoice);
            builder.setSmallIcon(R.drawable.ic_picture_as_pdf_white_36dp);
        }
        builder.setContentTitle(string).setContentText(str).setContentInfo(str).addAction(new NotificationCompat.Action(R.drawable.ic_refresh_white_24dp, "Ulangi", service));
        if (notificationManager != null) {
            notificationManager.notify(i + 1, builder.build());
            return;
        }
        NotificationManagerCompat from = NotificationManagerCompat.from(this);
        if (ContextCompat.checkSelfPermission(this, "android.permission.POST_NOTIFICATIONS") != 0) {
            return;
        }
        from.notify(i + 1, builder.build());
    }

    public final void h(int i, int i2, int i3, NotificationCompat.Builder builder, NotificationManager notificationManager) {
        builder.setProgress(i, i2, true);
        if (notificationManager != null) {
            notificationManager.notify(i3, builder.build());
            return;
        }
        NotificationManagerCompat from = NotificationManagerCompat.from(this);
        if (ContextCompat.checkSelfPermission(this, "android.permission.POST_NOTIFICATIONS") != 0) {
            return;
        }
        from.notify(i3, builder.build());
    }

    @Override
    public void onHandleIntent(Intent intent) {
        Bundle extras = intent != null ? intent.getExtras() : null;
        if (extras != null) {
            if (!extras.getString(URL_TAG, "").isEmpty()) {
                d(extras.getString(URL_TAG), extras.getString(FILENAME_TAG), extras);
                return;
            }
            Serializable serializable = extras.getSerializable(SERVICE_MESSAGE_TAG);
            if (serializable instanceof HashMap) {
                try {
                    e(extras, new ServiceMessage((HashMap) serializable));
                } catch (Exception unused) {
                }
            }
        }
    }
}