导航菜单

页面标题

页面副标题

Namma Yatri v3.3.7 - RemoteAssetsDownloader.java 源代码

正在查看: Namma Yatri v3.3.7 应用的 RemoteAssetsDownloader.java JAVA 源代码文件

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


package in.juspay.mobility.app;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.IBinder;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebViewClient;
import com.truecaller.android.sdk.legacy.TruecallerSdkScope;
import in.juspay.hyper.constants.Labels;
import in.juspay.hyper.constants.LogCategory;
import in.juspay.hypersdk.core.MerchantViewType;
import in.juspay.hypersdk.core.PaymentConstants;
import in.juspay.hypersdk.data.JuspayResponseHandler;
import in.juspay.hypersdk.ui.HyperPaymentsCallback;
import in.juspay.mobility.app.NotificationUtils;
import in.juspay.mobility.app.callbacks.CallBack;
import in.juspay.services.HyperServices;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.UUID;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class RemoteAssetsDownloader extends Service {
    private static ArrayList<CallBack> callBack = new ArrayList<>();
    HyperServices hyperServices;

    public static String appendSdkNameAndVersion(String str, Context context) {
        int lastIndexOf = str.lastIndexOf(46);
        String string = context.getString(context.getResources().getIdentifier(PaymentConstants.GODEL_VERSION, "string", context.getPackageName()));
        String string2 = context.getString(context.getResources().getIdentifier("godel_app_name", "string", context.getPackageName()));
        if (lastIndexOf <= 0 || lastIndexOf >= str.length() - 1) {
            return str + "_" + string2 + "_" + string;
        }
        return str.substring(0, lastIndexOf) + "_" + string2 + "_" + string + str.substring(lastIndexOf);
    }

    public static void deRegisterCallback(CallBack callBack2) {
        callBack.remove(callBack2);
    }

    public static void lambda$downloadFile$0(String str, Context context, String str2, Boolean bool, String str3) {
        try {
            HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
            httpURLConnection.setRequestMethod("GET");
            int responseCode = httpURLConnection.getResponseCode();
            if (responseCode == 200) {
                FileOutputStream fileOutputStream = new FileOutputStream(new File(context.getDir("juspay", 0), str2));
                InputStream inputStream = httpURLConnection.getInputStream();
                byte[] bArr = new byte[TruecallerSdkScope.FOOTER_TYPE_LATER];
                while (true) {
                    int read = inputStream.read(bArr);
                    if (read == -1) {
                        break;
                    } else {
                        fileOutputStream.write(bArr, 0, read);
                    }
                }
                inputStream.close();
                fileOutputStream.close();
                if (bool.booleanValue()) {
                    SharedPreferences sharedPreferences = context.getApplicationContext().getSharedPreferences(context.getApplicationContext().getString(R.string.preference_file_key), 0);
                    String string = sharedPreferences.getString("asset_metadata.json", "__failed");
                    if (!string.equals("__failed")) {
                        JSONObject jSONObject = new JSONObject(string);
                        jSONObject.remove(str3);
                        SharedPreferences.Editor edit = sharedPreferences.edit();
                        edit.putString("asset_metadata.json", jSONObject.toString());
                        edit.apply();
                    }
                }
            } else {
                System.out.println("Failed to download file. Response code: " + responseCode);
            }
            httpURLConnection.disconnect();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e2) {
            throw new RuntimeException(e2);
        }
    }

    public static void registerCallback(CallBack callBack2) {
        callBack.add(callBack2);
    }

    public void downloadFile(final String str, final String str2, final String str3, final Boolean bool, final Context context) throws InterruptedException {
        Thread thread = new Thread(new Runnable() {
            @Override
            public final void run() {
                RemoteAssetsDownloader.lambda$downloadFile$0(str, context, str2, bool, str3);
            }
        });
        thread.start();
        thread.join();
    }

    public String getService(String str) {
        return str.equals("USER") ? "in.yatri.consumer" : "in.yatri.provider";
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public void onDestroy() {
        stopSelf();
        callBack = new ArrayList<>();
        this.hyperServices = null;
        super.onDestroy();
    }

    @Override
    public int onStartCommand(Intent intent, int i, int i2) {
        if (intent == null) {
            return 2;
        }
        JSONObject jSONObject = new JSONObject();
        JSONObject jSONObject2 = new JSONObject();
        String stringExtra = intent.getStringExtra("merchantType");
        if (intent.getStringExtra("bundleType").equals(NotificationUtils.RequestSource.FCM)) {
            return updateBundle(intent, null, getApplicationContext());
        }
        if (this.hyperServices == null) {
            this.hyperServices = new HyperServices(this);
        }
        if (stringExtra == null || this.hyperServices.isInitialised()) {
            return 2;
        }
        try {
            jSONObject.put(PaymentConstants.CLIENT_ID_CAMEL, getResources().getString(R.string.client_id));
            jSONObject.put(PaymentConstants.MERCHANT_ID_CAMEL, getResources().getString(R.string.merchant_id));
            jSONObject.put(LogCategory.ACTION, Labels.HyperSdk.INITIATE);
            jSONObject.put("logLevel", 1);
            jSONObject.put("isBootable", false);
            jSONObject.put("bundleTimeOut", -1);
            jSONObject.put(PaymentConstants.ENV, "prod");
            jSONObject2.put("requestId", UUID.randomUUID());
            jSONObject2.put(PaymentConstants.SERVICE, getService(stringExtra));
            jSONObject2.put(PaymentConstants.BETA_ASSETS, false);
            jSONObject2.put(PaymentConstants.PAYLOAD, jSONObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        this.hyperServices.initiate(jSONObject2, new HyperPaymentsCallback() {
            @Override
            public WebViewClient createJuspaySafeWebViewClient() {
                return null;
            }

            @Override
            public View getMerchantView(ViewGroup viewGroup, MerchantViewType merchantViewType) {
                return null;
            }

            @Override
            public void onEvent(JSONObject jSONObject3, JuspayResponseHandler juspayResponseHandler) {
                String optString = jSONObject3.optString("event");
                System.out.println("onEvent -> " + jSONObject3);
                if (optString.equals(Labels.HyperSdk.TERMINATE)) {
                    RemoteAssetsDownloader.this.hyperServices.terminate();
                    RemoteAssetsDownloader.this.onDestroy();
                }
            }

            @Override
            public void onStartWaitingDialogCreated(View view) {
            }
        });
        return 2;
    }

    public int updateBundle(Intent intent, JSONObject jSONObject, Context context) {
        JSONObject jSONObject2;
        String str;
        String str2;
        String str3;
        String str4;
        if (intent != null) {
            try {
                jSONObject2 = new JSONObject(intent.getStringExtra(PaymentConstants.PAYLOAD));
            } catch (InterruptedException e) {
                e = e;
                throw new RuntimeException(e);
            } catch (JSONException e2) {
                e = e2;
                throw new RuntimeException(e);
            }
        } else {
            if (jSONObject == null) {
                return 2;
            }
            jSONObject2 = jSONObject;
        }
        JSONArray jSONArray = jSONObject2.has("urls") ? jSONObject2.getJSONArray("urls") : new JSONArray();
        int i = 0;
        while (true) {
            str = "";
            if (i >= jSONArray.length()) {
                break;
            }
            String string = jSONArray.getJSONObject(i).has(PaymentConstants.URL) ? jSONArray.getJSONObject(i).getString(PaymentConstants.URL) : "";
            int lastIndexOf = string.lastIndexOf("/");
            if (lastIndexOf != -1) {
                String substring = string.substring(lastIndexOf + 1);
                str2 = substring;
                str = appendSdkNameAndVersion(substring, context);
            } else {
                str2 = "";
            }
            String trim = jSONArray.getJSONObject(i).has("path") ? jSONArray.getJSONObject(i).getString("path").trim() : null;
            Boolean valueOf = Boolean.valueOf(jSONArray.getJSONObject(i).has("removeHash") && jSONArray.getJSONObject(i).getBoolean("removeHash"));
            if (trim == null || trim.length() == 0) {
                str3 = str;
            } else {
                if (trim.charAt(trim.length() - 1) == '/') {
                    str4 = trim + str;
                } else {
                    str4 = trim + '/' + str;
                }
                str3 = str4;
            }
            if (str3 != null) {
                downloadFile(string, str3, str2, valueOf, context);
            }
            i++;
        }
        String string2 = jSONObject2.has("description") ? jSONObject2.getString("description") : "";
        String string3 = jSONObject2.has("title") ? jSONObject2.getString("title") : "";
        str = jSONObject2.has("image") ? jSONObject2.getString("image") : "";
        JSONObject jSONObject3 = new JSONObject();
        jSONObject3.put("description", string2);
        jSONObject3.put("title", string3);
        jSONObject3.put("image", str);
        Iterator<CallBack> it = callBack.iterator();
        while (it.hasNext()) {
            it.next().bundleUpdatedCallBack("onBundleUpdated", jSONObject3);
        }
        new Handler().postDelayed(new Runnable() {
            @Override
            public final void run() {
                RemoteAssetsDownloader.this.onDestroy();
            }
        }, 3000L);
        return 2;
    }
}