导航菜单

页面标题

页面副标题

Fix Locker v1.5 - FirebaseMessanging.java 源代码

正在查看: Fix Locker v1.5 应用的 FirebaseMessanging.java JAVA 源代码文件

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


package com.user.a4keygen.services;

import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import androidx.work.Constraints;
import androidx.work.Data;
import androidx.work.ExistingPeriodicWorkPolicy;
import androidx.work.NetworkType;
import androidx.work.OneTimeWorkRequest;
import androidx.work.OutOfQuotaPolicy;
import androidx.work.PeriodicWorkRequest;
import androidx.work.WorkManager;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.google.gson.JsonObject;
import com.user.a4keygen.BuildConfig;
import com.user.a4keygen.DeviceAdminReceiver;
import com.user.a4keygen.DevicePolicyManagerGateway;
import com.user.a4keygen.DevicePolicyManagerGatewayImpl;
import com.user.a4keygen.activity.AppUpdateActivity;
import com.user.a4keygen.activity.DummySurface;
import com.user.a4keygen.activity.EmiReminderScreenActivity;
import com.user.a4keygen.constants.ServiceKeyValueConstant;
import com.user.a4keygen.constants.WebServiceUrlConstant;
import com.user.a4keygen.model.CommonResponseModel;
import com.user.a4keygen.network.ApiClient;
import com.user.a4keygen.network.ApiInterface;
import com.user.a4keygen.receiver.TokenVerificationWorker;
import com.user.a4keygen.sharedprefrence.SharedPrefManager;
import com.user.a4keygen.util.AppUtil;
import com.user.a4keygen.util.Config;
import com.user.a4keygen.util.NotificationHelper;
import com.user.a4keygen.webutil.WebClientService;
import java.net.URLDecoder;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import org.bouncycastle.asn1.cmp.PKIFailureInfo;
import org.bouncycastle.i18n.MessageBundle;
import org.json.JSONObject;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class FirebaseMessanging extends FirebaseMessagingService {
    private static final String TAG = "FirebaseMessanging";
    String contactNumber;
    String decodeUrlImage;
    private DevicePolicyManager dpm;
    ComponentName mAdminComponentName;
    DevicePolicyManager mDevicePolicyManager;
    private DevicePolicyManagerGateway mDevicePolicyManagerGateway;
    Handler mHandler = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(Message message) {
        }
    };
    String urlDecodedApkDownload;

    @Override
    public void onNewToken(String str) {
        Log.d(TAG, "Refreshed token: " + str);
        System.out.println("tokentoken = " + str);
        storeToken(str);
    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        try {
            if (remoteMessage.getData().size() > 0) {
                JSONObject jSONObject = new JSONObject(remoteMessage.getData().get("body"));
                FirebaseAnalytics firebaseAnalytics = FirebaseAnalytics.getInstance(this);
                Bundle bundle = new Bundle();
                bundle.putString(TAG, AppUtil.getAndroidId(getApplicationContext()));
                firebaseAnalytics.logEvent(TAG, bundle);
                String optString = jSONObject.optString(MessageBundle.TITLE_ENTRY);
                System.out.println("title = " + optString);
                if ("LApp".equalsIgnoreCase(optString)) {
                    Intent intent = new Intent(this, (Class<?>) GenericApiService.class);
                    intent.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "ML_L");
                    intent.putExtra(ServiceKeyValueConstant.AckSer, "Mobile Lock Fcm Arrived");
                    getApplicationContext().startForegroundService(intent);
                    try {
                        String optString2 = jSONObject.optString("dealerMsg");
                        if (!WebClientService.isNull(optString2)) {
                            SharedPrefManager.getInstance(getApplicationContext()).saveDealerMessage(optString2);
                        } else {
                            SharedPrefManager.getInstance(getApplicationContext()).saveDealerMessage("");
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    SharedPrefManager.getInstance(getApplicationContext()).saveRequestLockStatus("1");
                    subUnsubMe(getApplicationContext(), Config.SUBSCRIBE, Config.TOPIC_LAPP);
                    setPersistentPreferredActivity(true, getApplicationContext());
                    this.dpm = (DevicePolicyManager) getSystemService("device_policy");
                    if (WebClientService.isActiveAdmin(getApplicationContext())) {
                        this.dpm.lockNow();
                        return;
                    }
                    return;
                }
                if ("advertisement".equalsIgnoreCase(optString)) {
                    String optString3 = jSONObject.optString("image");
                    String optString4 = jSONObject.optString("message");
                    if (!WebClientService.isNull(optString3)) {
                        this.decodeUrlImage = URLDecoder.decode(optString3, "UTF-8");
                    }
                    NotificationHelper.addNotification(getApplicationContext(), optString4, this.decodeUrlImage);
                    return;
                }
                if ("UpdateApp".equalsIgnoreCase(optString)) {
                    Intent intent2 = new Intent(this, (Class<?>) GenericApiService.class);
                    intent2.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "UA");
                    intent2.putExtra(ServiceKeyValueConstant.AckSer, "App Update Fcm Arrived");
                    getApplicationContext().startForegroundService(intent2);
                    String optString5 = jSONObject.optString("url");
                    if (WebClientService.isNull(optString5)) {
                        return;
                    }
                    this.urlDecodedApkDownload = URLDecoder.decode(optString5, "UTF-8");
                    Intent intent3 = new Intent(this, (Class<?>) AutoAppUpdateForeGroundService.class);
                    intent3.putExtra(AppUpdateActivity.APK_DOWNLOAD_URL, this.urlDecodedApkDownload);
                    getApplicationContext().startForegroundService(intent3);
                    return;
                }
                if ("remind".equalsIgnoreCase(optString)) {
                    String optString6 = jSONObject.optString("sound");
                    String optString7 = jSONObject.optString("url");
                    String optString8 = jSONObject.optString("message");
                    System.out.println("sound = " + optString6);
                    if (!optString6.equals("Y") && !optString6.equals("N")) {
                        if (optString6.equals("getLCTN")) {
                            Intent intent4 = new Intent(this, (Class<?>) GenericApiService.class);
                            intent4.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "GL");
                            intent4.putExtra(ServiceKeyValueConstant.AckSer, "Get Location Fcm Arrived");
                            getApplicationContext().startForegroundService(intent4);
                            getLocationWorker();
                            return;
                        }
                        if (optString6.equals("LocationOn")) {
                            Intent intent5 = new Intent(this, (Class<?>) GenericApiService.class);
                            intent5.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "LON");
                            intent5.putExtra(ServiceKeyValueConstant.AckSer, "Location On Fcm Arrived");
                            getApplicationContext().startForegroundService(intent5);
                            Intent intent6 = new Intent(this, (Class<?>) LocationControlForegroundService.class);
                            intent6.putExtra("ALLOW_TEMP_LOCATION", true);
                            startForegroundService(intent6);
                            return;
                        }
                        if (optString6.equals("LocationOff")) {
                            Intent intent7 = new Intent(this, (Class<?>) GenericApiService.class);
                            intent7.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "LOF");
                            intent7.putExtra(ServiceKeyValueConstant.AckSer, "Location Off Fcm Arrived");
                            getApplicationContext().startForegroundService(intent7);
                            Intent intent8 = new Intent(this, (Class<?>) LocationControlForegroundService.class);
                            intent8.putExtra("ALLOW_TEMP_LOCATION", false);
                            startForegroundService(intent8);
                            return;
                        }
                        if (optString6.equals("GetUserPhonNum")) {
                            Intent intent9 = new Intent(this, (Class<?>) GenericApiService.class);
                            intent9.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "GC");
                            intent9.putExtra(ServiceKeyValueConstant.AckSer, "Get Contact Number Fcm Arrived");
                            getApplicationContext().startForegroundService(intent9);
                            getContactWorker();
                            return;
                        }
                        if (optString6.equals("getLCTNMsgLink")) {
                            Intent intent10 = new Intent(this, (Class<?>) GenericApiService.class);
                            intent10.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "GC_OVM");
                            intent10.putExtra(ServiceKeyValueConstant.AckSer, "Location via msg Fcm Arrived");
                            getApplicationContext().startForegroundService(intent10);
                            getApplicationContext().startForegroundService(new Intent(this, (Class<?>) LocationViaMsgForeService.class));
                            return;
                        }
                        if (optString6.equals("GetUserPhonNumMsg")) {
                            Intent intent11 = new Intent(this, (Class<?>) GenericApiService.class);
                            intent11.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "GC_VM");
                            intent11.putExtra(ServiceKeyValueConstant.AckSer, "Contact via Message Fcm Arrived");
                            getApplicationContext().startForegroundService(intent11);
                            getApplicationContext().startForegroundService(new Intent(this, (Class<?>) GetOfflineContactService.class));
                            return;
                        }
                        if (optString6.equals("AppLock")) {
                            Intent intent12 = new Intent(this, (Class<?>) GenericApiService.class);
                            intent12.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "AL_L");
                            intent12.putExtra(ServiceKeyValueConstant.AckSer, "App lock fcm Fcm Arrived");
                            getApplicationContext().startForegroundService(intent12);
                            Intent intent13 = new Intent(this, (Class<?>) AppLockService.class);
                            intent13.putExtra("AppLock", true);
                            startForegroundService(intent13);
                            return;
                        }
                        if (optString6.equals("AppUnLock")) {
                            Intent intent14 = new Intent(this, (Class<?>) GenericApiService.class);
                            intent14.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "AL_UL");
                            intent14.putExtra(ServiceKeyValueConstant.AckSer, "App Unlock fcm Fcm Arrived");
                            getApplicationContext().startForegroundService(intent14);
                            Intent intent15 = new Intent(this, (Class<?>) AppLockService.class);
                            intent15.putExtra("AppLock", false);
                            startForegroundService(intent15);
                            return;
                        }
                        if (optString6.equals("Reboot")) {
                            Intent intent16 = new Intent(this, (Class<?>) GenericApiService.class);
                            intent16.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "RD");
                            intent16.putExtra(ServiceKeyValueConstant.AckSer, "Reboot Device Fcm Arrived");
                            getApplicationContext().startForegroundService(intent16);
                            getApplicationContext().startForegroundService(new Intent(this, (Class<?>) RebootService.class));
                            return;
                        }
                        if (optString6.equals("CameraLock")) {
                            Intent intent17 = new Intent(this, (Class<?>) GenericApiService.class);
                            intent17.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "CH");
                            intent17.putExtra(ServiceKeyValueConstant.AckSer, "Camera lock Fcm Arrived");
                            getApplicationContext().startForegroundService(intent17);
                            Intent intent18 = new Intent(this, (Class<?>) CameraForegroundService.class);
                            intent18.putExtra("CameraLock", true);
                            startForegroundService(intent18);
                            return;
                        }
                        if (optString6.equals("CameraUnLock")) {
                            Intent intent19 = new Intent(this, (Class<?>) GenericApiService.class);
                            intent19.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "CU");
                            intent19.putExtra(ServiceKeyValueConstant.AckSer, "Camera Unlock Fcm Arrived");
                            getApplicationContext().startForegroundService(intent19);
                            Intent intent20 = new Intent(this, (Class<?>) CameraForegroundService.class);
                            intent20.putExtra("CameraLock", false);
                            startForegroundService(intent20);
                            return;
                        }
                        if (optString6.equals("CallLock")) {
                            Intent intent21 = new Intent(this, (Class<?>) GenericApiService.class);
                            intent21.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "CL_L");
                            intent21.putExtra(ServiceKeyValueConstant.AckSer, "Call Lock Fcm Arrived");
                            getApplicationContext().startForegroundService(intent21);
                            Intent intent22 = new Intent(this, (Class<?>) CallLockService.class);
                            intent22.putExtra("CallLock", true);
                            startForegroundService(intent22);
                            return;
                        }
                        if (optString6.equals("CallUnLock")) {
                            Intent intent23 = new Intent(this, (Class<?>) GenericApiService.class);
                            intent23.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "CL_UL");
                            intent23.putExtra(ServiceKeyValueConstant.AckSer, "Call Unlock Fcm Arrived");
                            getApplicationContext().startForegroundService(intent23);
                            Intent intent24 = new Intent(this, (Class<?>) CallLockService.class);
                            intent24.putExtra("CallLock", false);
                            startForegroundService(intent24);
                            return;
                        }
                        if (optString6.equals("WallPaperOn")) {
                            Intent intent25 = new Intent(this, (Class<?>) GenericApiService.class);
                            intent25.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "WP_S");
                            intent25.putExtra(ServiceKeyValueConstant.AckSer, "Wall paper On Fcm Arrived");
                            getApplicationContext().startForegroundService(intent25);
                            Intent intent26 = new Intent(this, (Class<?>) WallpaperForeService.class);
                            intent26.putExtra("WallPaper", true);
                            startForegroundService(intent26);
                            return;
                        }
                        if (optString6.equals("WallPaperOFF")) {
                            Intent intent27 = new Intent(this, (Class<?>) GenericApiService.class);
                            intent27.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "WP_R");
                            intent27.putExtra(ServiceKeyValueConstant.AckSer, "Wall paper off Fcm Arrived");
                            getApplicationContext().startForegroundService(intent27);
                            Intent intent28 = new Intent(this, (Class<?>) WallpaperForeService.class);
                            intent28.putExtra("WallPaper", false);
                            startForegroundService(intent28);
                            return;
                        }
                        if (optString6.equals("reset_password")) {
                            Intent intent29 = new Intent(this, (Class<?>) GenericApiService.class);
                            intent29.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "RP");
                            intent29.putExtra(ServiceKeyValueConstant.AckSer, "Reset Password Fcm Arrived");
                            getApplicationContext().startForegroundService(intent29);
                            Intent intent30 = new Intent(this, (Class<?>) ResetPasswordForegroundService.class);
                            intent30.putExtra("password", removePass(optString8));
                            startForegroundService(intent30);
                            return;
                        }
                        if (optString6.equals("remove_password")) {
                            Intent intent31 = new Intent(this, (Class<?>) GenericApiService.class);
                            intent31.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "RP");
                            intent31.putExtra(ServiceKeyValueConstant.AckSer, "Remove Password Fcm Arrived");
                            getApplicationContext().startForegroundService(intent31);
                            getApplicationContext().startForegroundService(new Intent(this, (Class<?>) PasswordRemovalService.class));
                            return;
                        }
                        if (optString6.equals("AppHide")) {
                            Intent intent32 = new Intent(this, (Class<?>) GenericApiService.class);
                            intent32.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "AH");
                            intent32.putExtra(ServiceKeyValueConstant.AckSer, "App HIde Fcm Arrived");
                            getApplicationContext().startForegroundService(intent32);
                            Intent intent33 = new Intent(this, (Class<?>) AppHideService.class);
                            intent33.putExtra("APPHIDE", true);
                            startForegroundService(intent33);
                            return;
                        }
                        if (optString6.equals("AppUnhide")) {
                            Intent intent34 = new Intent(this, (Class<?>) GenericApiService.class);
                            intent34.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "AU");
                            intent34.putExtra(ServiceKeyValueConstant.AckSer, "App UnHIde Fcm Arrived");
                            getApplicationContext().startForegroundService(intent34);
                            Intent intent35 = new Intent(this, (Class<?>) AppHideService.class);
                            intent35.putExtra("APPHIDE", false);
                            startForegroundService(intent35);
                            return;
                        }
                        if (optString6.equals("GetCallHistory")) {
                            startForegroundService(new Intent(this, (Class<?>) GetCallHistoryService.class));
                            return;
                        }
                        return;
                    }
                    Intent intent36 = new Intent(this, (Class<?>) GenericApiService.class);
                    intent36.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "ER_SC");
                    intent36.putExtra(ServiceKeyValueConstant.AckSer, "Emi Reminder Fcm Arrived");
                    getApplicationContext().startForegroundService(intent36);
                    Intent intent37 = new Intent(getApplicationContext(), (Class<?>) EmiReminderScreenActivity.class);
                    intent37.setFlags(268435456);
                    intent37.putExtra("sound", optString6);
                    intent37.putExtra("url", optString7);
                    startActivity(intent37);
                    return;
                }
                if ("ActApp".equalsIgnoreCase(optString)) {
                    SharedPrefManager.getInstance(getApplicationContext()).saveUninstallStatus("N");
                    setReEnableApp(true, getApplicationContext(), false);
                    Intent intent38 = new Intent(this, (Class<?>) GenericApiService.class);
                    intent38.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "A");
                    intent38.putExtra(ServiceKeyValueConstant.AckSer, "App Activated Fcm Arrived");
                    getApplicationContext().startForegroundService(intent38);
                    return;
                }
                if ("DctApp".equalsIgnoreCase(optString)) {
                    SharedPrefManager.getInstance(getApplicationContext()).saveUninstallStatus("Y");
                    setReEnableApp(false, getApplicationContext(), false);
                    Intent intent39 = new Intent(this, (Class<?>) GenericApiService.class);
                    intent39.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "D");
                    intent39.putExtra(ServiceKeyValueConstant.AckSer, "App DActivated FCM Arrived");
                    getApplicationContext().startForegroundService(intent39);
                    return;
                }
                SharedPrefManager.getInstance(getApplicationContext()).saveDeviceLockStatus("Q");
                SharedPrefManager.getInstance(getApplicationContext()).saveRequestLockStatus("0");
                if ("UniApp".equalsIgnoreCase(optString)) {
                    SharedPrefManager.getInstance(getApplicationContext()).saveUninstallStatus("Y");
                    setReEnableApp(false, getApplicationContext(), true);
                    Intent intent40 = new Intent(this, (Class<?>) GenericApiService.class);
                    intent40.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "RA");
                    intent40.putExtra(ServiceKeyValueConstant.AckSer, "Removed Fcm Arrived");
                    getApplicationContext().startForegroundService(intent40);
                } else if ("DisUniApp".equalsIgnoreCase(optString)) {
                    SharedPrefManager.getInstance(getApplicationContext()).saveUninstallStatus("N");
                    setReEnableApp(true, getApplicationContext(), false);
                }
                Intent intent41 = new Intent(this, (Class<?>) GenericApiService.class);
                intent41.putExtra(ServiceKeyValueConstant.GEN_F_SERVICE, "ML_UL");
                intent41.putExtra(ServiceKeyValueConstant.AckSer, "Unlocked Fcm Arrived");
                getApplicationContext().startForegroundService(intent41);
                setPersistentPreferredActivity(false, getApplicationContext());
                subUnsubMe(getApplicationContext(), Config.UNSUBSCRIBE, Config.TOPIC_LAPP);
                getApplicationContext().startForegroundService(new Intent(this, (Class<?>) AuthenticationFeedBackService.class));
            }
        } catch (Exception e2) {
            e2.printStackTrace();
            workerThread();
        }
    }

    private void getContactWorker() {
        getApplicationContext().startForegroundService(new Intent(this, (Class<?>) ContactForegroundService.class));
    }

    private void getLocationWorker() {
        getApplicationContext().startForegroundService(new Intent(this, (Class<?>) LocationForegroundService.class));
    }

    private void cameraHideUnhide(boolean z) {
        WorkManager.getInstance(getApplicationContext()).enqueue(new OneTimeWorkRequest.Builder(CameraWorker.class).setInputData(new Data.Builder().putBoolean("camera_key", z).build()).setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST).build());
    }

    public static String removePass(String str) {
        return str.endsWith("pass") ? str.substring(0, str.length() - 4) : str;
    }

    private void enableUnInstallOption() {
        this.dpm = (DevicePolicyManager) getSystemService("device_policy");
        ComponentName componentName = DeviceAdminReceiver.getComponentName(getApplicationContext());
        this.mAdminComponentName = componentName;
        this.dpm.setUninstallBlocked(componentName, BuildConfig.APPLICATION_ID, false);
        ((DevicePolicyManager) getApplicationContext().getSystemService("device_policy")).removeActiveAdmin(new ComponentName(getApplicationContext(), (Class<?>) DeviceAdminReceiver.class));
    }

    void workerThread() {
        this.mHandler.obtainMessage(0).sendToTarget();
    }

    private void storeToken(String str) {
        SharedPrefManager.getInstance(getApplicationContext()).saveDeviceToken(str);
        if (WebClientService.isNull(SharedPrefManager.getInstance(getApplicationContext()).getUserId())) {
            return;
        }
        onSaveTokenOnRemote();
    }

    private void onSaveTokenOnRemote() {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("id", SharedPrefManager.getInstance(getApplicationContext()).getUserId());
        jsonObject.addProperty("token", SharedPrefManager.getInstance(getApplicationContext()).getDeviceToken());
        ((ApiInterface) ApiClient.getInstance(this).getClient().create(ApiInterface.class)).tokenUpdate(jsonObject).enqueue(new Callback<CommonResponseModel>() {
            public void onResponse(Call<CommonResponseModel> call, Response<CommonResponseModel> response) {
                if (response.isSuccessful()) {
                    SharedPrefManager.getInstance(FirebaseMessanging.this.getApplicationContext()).setTokenSynced(true);
                    WorkManager.getInstance(FirebaseMessanging.this.getApplicationContext()).cancelUniqueWork("token_update_retry");
                    Log.d("TAG", "Token update successful. Worker cancelled.");
                } else {
                    Log.e("TAG", "Token update failed from server. Scheduling retry.");
                    SharedPrefManager.getInstance(FirebaseMessanging.this.getApplicationContext()).setTokenSynced(false);
                    FirebaseMessanging.this.scheduleRetryWorker();
                }
            }

            public void onFailure(Call<CommonResponseModel> call, Throwable th) {
                Log.e("TAG", "Token update failed due to network. Scheduling retry.");
                SharedPrefManager.getInstance(FirebaseMessanging.this.getApplicationContext()).setTokenSynced(false);
                FirebaseMessanging.this.scheduleRetryWorker();
            }
        });
    }

    public void scheduleRetryWorker() {
        WorkManager.getInstance(getApplicationContext()).enqueueUniquePeriodicWork("token_update_retry", ExistingPeriodicWorkPolicy.REPLACE, new PeriodicWorkRequest.Builder(TokenVerificationWorker.class, 30L, TimeUnit.MINUTES).setConstraints(new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).setRequiresBatteryNotLow(false).setRequiresStorageNotLow(false).setRequiresCharging(false).setRequiresDeviceIdle(false).build()).setInitialDelay(30L, TimeUnit.MINUTES).build());
    }

    public void subUnsubMe(Context context, String str, String str2) {
        FirebaseMessaging firebaseMessaging = FirebaseMessaging.getInstance();
        final FirebaseAnalytics firebaseAnalytics = FirebaseAnalytics.getInstance(this);
        final Bundle bundle = new Bundle();
        bundle.putString("AndroidId", AppUtil.getAndroidId(context));
        bundle.putString("DeviceInfo", AppUtil.getDeviceName());
        bundle.putString("TranType", str);
        bundle.putString("DeviceLStatus", SharedPrefManager.getInstance(context).getDeviceLockStatus());
        bundle.putString("DeviceReqLStatus", SharedPrefManager.getInstance(context).getRequestLockStatus());
        if (str.equals(Config.SUBSCRIBE)) {
            firebaseMessaging.subscribeToTopic(str2).addOnCompleteListener(new OnCompleteListener<Void>() {
                public void onComplete(Task<Void> task) {
                    String str3 = !task.isSuccessful() ? "Subscribed Failed" : "Subscribed Successfully";
                    bundle.putString("TranStatus", str3);
                    Log.e("TAG", str3);
                    firebaseAnalytics.logEvent(FirebaseAnalytics.Event.JOIN_GROUP, bundle);
                }
            }).addOnFailureListener(new OnFailureListener() {
                public void onFailure(Exception exc) {
                    bundle.putString("TranFailureEx", exc.getMessage());
                    firebaseAnalytics.logEvent(FirebaseAnalytics.Event.JOIN_GROUP, bundle);
                }
            });
        } else if (str.equals(Config.UNSUBSCRIBE)) {
            firebaseMessaging.unsubscribeFromTopic(str2).addOnCompleteListener(new OnCompleteListener<Void>() {
                public void onComplete(Task<Void> task) {
                    String str3 = !task.isSuccessful() ? "UnSubscribed Failed" : "UnSubscribed Successfully";
                    bundle.putString("TranStatus", str3);
                    Log.e("TAG", str3);
                    firebaseAnalytics.logEvent(FirebaseAnalytics.Event.JOIN_GROUP, bundle);
                }
            }).addOnFailureListener(new OnFailureListener() {
                public void onFailure(Exception exc) {
                    bundle.putString("TranFailureEx", exc.getMessage());
                    firebaseAnalytics.logEvent(FirebaseAnalytics.Event.JOIN_GROUP, bundle);
                }
            });
        }
        Log.e(TAG, bundle.toString());
    }

    public void setPersistentPreferredActivity(boolean z, Context context) {
        try {
            this.mAdminComponentName = DeviceAdminReceiver.getComponentName(getApplicationContext());
            DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService("device_policy");
            this.mDevicePolicyManager = devicePolicyManager;
            this.mDevicePolicyManagerGateway = new DevicePolicyManagerGatewayImpl(context);
            if (devicePolicyManager.isDeviceOwnerApp(getPackageName())) {
                this.mDevicePolicyManager.setStatusBarDisabled(this.mAdminComponentName, z);
                this.mDevicePolicyManager.setCameraDisabled(this.mAdminComponentName, z);
                this.mDevicePolicyManagerGateway.setUserRestriction("no_adjust_volume", z);
                this.mDevicePolicyManagerGateway.setUserRestriction("no_install_apps", z);
                this.mDevicePolicyManagerGateway.setUserRestriction("no_uninstall_apps", z);
                this.mDevicePolicyManagerGateway.setUserRestriction("no_usb_file_transfer", z);
                if (z) {
                    try {
                        getLauncherPackage();
                        EnableHomeLauncherApp(getApplicationContext());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    DisableHomeLauncherApp(getApplicationContext());
                    setLauncherPackage(getApplicationContext());
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

    public void getLauncherPackage() {
        try {
            Intent intent = new Intent("android.intent.action.MAIN");
            intent.addCategory("android.intent.category.HOME");
            String str = null;
            try {
                str = getPackageManager().resolveActivity(intent, PKIFailureInfo.notAuthorized).activityInfo.packageName;
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (str == null) {
                Iterator<ResolveInfo> it = getPackageManager().queryIntentActivities(new Intent("android.intent.action.MAIN").addCategory("android.intent.category.HOME"), PKIFailureInfo.notAuthorized).iterator();
                while (it.hasNext()) {
                    String str2 = it.next().activityInfo.packageName;
                    if (str2 != null && !str2.toLowerCase().equals(getPackageName().toLowerCase())) {
                        try {
                            SharedPrefManager.getInstance(getApplicationContext()).saveDefaultLauncher(str2);
                            return;
                        } catch (Exception e2) {
                            e2.printStackTrace();
                        }
                    }
                }
                return;
            }
            if (str.toLowerCase().equals(getPackageName().toLowerCase())) {
                return;
            }
            SharedPrefManager.getInstance(getApplicationContext()).saveDefaultLauncher(str);
        } catch (Exception e3) {
            e3.printStackTrace();
        }
    }

    private void EnableHomeLauncherApp(Context context) {
        try {
            PackageManager packageManager = context.getPackageManager();
            ComponentName componentName = new ComponentName(context, (Class<?>) DummySurface.class);
            packageManager.setComponentEnabledSetting(componentName, 1, 1);
            Intent intent = new Intent("android.intent.action.MAIN");
            intent.addCategory("android.intent.category.HOME");
            intent.addCategory("android.intent.category.DEFAULT");
            intent.setFlags(268435456);
            intent.setComponent(componentName);
            context.startActivity(intent);
            IntentFilter intentFilter = new IntentFilter("android.intent.action.MAIN");
            intentFilter.addCategory("android.intent.category.HOME");
            intentFilter.addCategory("android.intent.category.DEFAULT");
            this.mDevicePolicyManager.addPersistentPreferredActivity(this.mAdminComponentName, intentFilter, new ComponentName(context.getPackageName(), DummySurface.class.getName()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void DisableHomeLauncherApp(Context context) {
        try {
            PackageManager packageManager = context.getPackageManager();
            ComponentName componentName = new ComponentName(context, (Class<?>) DummySurface.class);
            packageManager.setComponentEnabledSetting(componentName, 2, 1);
            Intent intent = new Intent("android.intent.action.MAIN");
            intent.addCategory("android.intent.category.HOME");
            intent.addCategory("android.intent.category.DEFAULT");
            intent.setFlags(268435456);
            intent.setComponent(componentName);
            context.startActivity(intent);
            if (this.mDevicePolicyManager == null || this.mAdminComponentName == null) {
                this.mAdminComponentName = DeviceAdminReceiver.getComponentName(context);
                this.mDevicePolicyManager = (DevicePolicyManager) context.getSystemService("device_policy");
            }
            this.mDevicePolicyManager.clearPackagePersistentPreferredActivities(this.mAdminComponentName, context.getPackageName());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void setLauncherPackage(Context context) {
        String defaultLauncher = SharedPrefManager.getInstance(getApplicationContext()).getDefaultLauncher();
        if (!defaultLauncher.isEmpty()) {
            Intent intent = new Intent("android.intent.action.MAIN");
            intent.addCategory("android.intent.category.HOME");
            intent.addCategory("android.intent.category.DEFAULT");
            intent.setPackage(defaultLauncher);
            intent.setFlags(268435456);
            try {
                context.startActivity(intent);
                return;
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }
        }
        PackageManager packageManager = context.getPackageManager();
        for (ResolveInfo resolveInfo : packageManager.queryIntentActivities(new Intent("android.intent.action.MAIN").addCategory("android.intent.category.HOME"), PKIFailureInfo.notAuthorized)) {
            if (!context.getPackageName().equals(resolveInfo.activityInfo.packageName)) {
                try {
                    Intent launchIntentForPackage = packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName);
                    if (launchIntentForPackage != null) {
                        launchIntentForPackage.setFlags(268435456);
                        context.startActivity(launchIntentForPackage);
                        return;
                    }
                    continue;
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
            }
        }
    }

    private void setReEnableApp(boolean z, Context context, boolean z2) {
        DevicePolicyManager devicePolicyManager;
        if (!WebClientService.isNull(this.mDevicePolicyManager)) {
            this.mDevicePolicyManagerGateway = new DevicePolicyManagerGatewayImpl(context);
        } else {
            this.mDevicePolicyManager = (DevicePolicyManager) getSystemService("device_policy");
            this.mDevicePolicyManagerGateway = new DevicePolicyManagerGatewayImpl(context);
        }
        this.mDevicePolicyManagerGateway.setUserRestriction("no_add_user", z);
        this.mDevicePolicyManagerGateway.setUserRestriction("no_remove_user", z);
        this.mDevicePolicyManagerGateway.setUserRestriction("no_add_managed_profile", z);
        this.mDevicePolicyManagerGateway.setUserRestriction("no_user_switch", z);
        this.mDevicePolicyManagerGateway.setUserRestriction("no_safe_boot", z);
        if (!WebClientService.isAppTesting) {
            this.mDevicePolicyManagerGateway.setUserRestriction("no_debugging_features", z);
        }
        this.mDevicePolicyManagerGateway.setUserRestriction("no_factory_reset", z);
        this.mDevicePolicyManagerGateway.setUserRestriction("no_usb_file_transfer", z);
        if (z2 && (devicePolicyManager = this.mDevicePolicyManager) != null) {
            if (devicePolicyManager.isDeviceOwnerApp(getPackageName())) {
                try {
                    this.mDevicePolicyManager.clearDeviceOwnerApp(getPackageName());
                    System.out.println("Device Owner Cleared Successfully.");
                    if (!this.mDevicePolicyManager.isDeviceOwnerApp(getPackageName())) {
                        System.out.println("Confirmed: App is no longer device owner.");
                        if (WebClientService.getWebServiceUrl().equals(WebServiceUrlConstant.ADVANCE_FINANCE_URL_PROD) || WebClientService.getWebServiceUrl().equals("http://103.196.193.4/advancefinance-ws-v1.0/") || WebClientService.getWebServiceUrl().equals("http://advancefinance.in/advancefinance-ws-v1.0_test/")) {
                            sendFeedbackUserRemoved();
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    System.out.println("Error clearing device owner: " + e.getMessage());
                }
            } else {
                System.out.println("Not a device owner already.");
                if (WebClientService.getWebServiceUrl().equals(WebServiceUrlConstant.ADVANCE_FINANCE_URL_PROD) || WebClientService.getWebServiceUrl().equals("http://103.196.193.4/advancefinance-ws-v1.0/") || WebClientService.getWebServiceUrl().equals("http://advancefinance.in/advancefinance-ws-v1.0_test/")) {
                    sendFeedbackUserRemoved();
                }
            }
        }
        sendFrpConfigChangedBroadcastIfNeeded();
    }

    private void sendFeedbackUserRemoved() {
        System.out.println("Sending API feedback: Device owner removed.");
        try {
            ((ApiInterface) ApiClient.getInstance(getApplicationContext()).getClient().create(ApiInterface.class)).sendUserRemoveFeedback(SharedPrefManager.getInstance(getApplicationContext()).getUserId(), "R").enqueue(new Callback<CommonResponseModel>() {
                public void onResponse(Call<CommonResponseModel> call, Response<CommonResponseModel> response) {
                    if (response.isSuccessful() && "S".equals(((CommonResponseModel) response.body()).getStatus())) {
                        Log.d("UserRemove", "User removal confirmation sent successfully");
                    } else {
                        Log.d("UserRemove", "API failed");
                    }
                }

                public void onFailure(Call<CommonResponseModel> call, Throwable th) {
                    Log.d("UserRemove", "API call failed: " + th.getMessage());
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void sendFrpConfigChangedBroadcastIfNeeded() {
        if (WebClientService.getWebServiceUrl().equals(WebServiceUrlConstant.ADVANCE_FINANCE_URL_PROD) || WebClientService.getWebServiceUrl().equals("https://advancefinance.in/advancefinance-ws-v1.0/") || WebClientService.getWebServiceUrl().equals(WebServiceUrlConstant.EMI_SATHI_URL_PROD) || WebClientService.getWebServiceUrl().equals("https://emisathi.in/emisathi-ws-v1.0/") || WebClientService.getWebServiceUrl().equals("http://a4keygen.com/afourkeygen-ws-v1.0/") || WebClientService.getWebServiceUrl().equals("https://a4keygen.com/afourkeygen-ws-v1.0/") || WebClientService.getWebServiceUrl().equals(WebServiceUrlConstant.BRILLIANT_EMI_URL) || WebClientService.getWebServiceUrl().equals("https://brillantemilocker.com/brillantemilocker-ws-v1.0/") || WebClientService.getWebServiceUrl().equals(WebServiceUrlConstant.FIX_LOCKER_PROD_URL) || WebClientService.getWebServiceUrl().equals("https://fixlock.in/fixlocker-ws-v1.0/") || WebClientService.getWebServiceUrl().equals(WebServiceUrlConstant.EMI_RECOVERY_URL_PROD) || WebClientService.getWebServiceUrl().equals(WebServiceUrlConstant.EMI_RECOVERY_URL_PROD) || WebClientService.getWebServiceUrl().equals(WebServiceUrlConstant.BD_LOCKER_PROD_URL) || WebClientService.getWebServiceUrl().equals(WebServiceUrlConstant.BD_LOCKER_PROD_URL)) {
            try {
                Intent intent = new Intent("com.google.android.gms.auth.FRP_CONFIG_CHANGED");
                intent.setPackage("com.google.android.gms");
                intent.addFlags(268435456);
                sendBroadcast(intent);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}