导航菜单

页面标题

页面副标题

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

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

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


package com.user.a4keygen.services;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
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.Build;
import android.os.IBinder;
import android.util.Log;
import androidx.core.app.NotificationCompat;
import com.user.a4keygen.DeviceAdminReceiver;
import com.user.a4keygen.DevicePolicyManagerGateway;
import com.user.a4keygen.DevicePolicyManagerGatewayImpl;
import com.user.a4keygen.activity.DummySurface;
import com.user.a4keygen.constants.ServiceKeyValueConstant;
import com.user.a4keygen.constants.WebServiceUrlConstant;
import com.user.a4keygen.sharedprefrence.SharedPrefManager;
import com.user.a4keygen.util.Config;
import com.user.a4keygen.util.IconUtils;
import com.user.a4keygen.webutil.WebClientService;
import java.util.Iterator;
import org.bouncycastle.asn1.cmp.PKIFailureInfo;

public class AutoLockService extends Service {
    private static final String CHANNEL_ID = "CallLockServiceChannel";
    private static final int NOTIFICATION_ID = 1212;
    private static final String TAG = "CallLockService";
    ComponentName mAdminComponentName;
    DevicePolicyManager mDevicePolicyManager;
    private DevicePolicyManagerGateway mDevicePolicyManagerGateway;
    SharedPrefManager prefManager;

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

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d(TAG, "Service created");
        this.mDevicePolicyManagerGateway = new DevicePolicyManagerGatewayImpl(this);
        if (WebClientService.isActiveAdmin(getApplicationContext())) {
            return;
        }
        Log.d(TAG, "Device Admin is not active!");
        stopSelf();
    }

    @Override
    public int onStartCommand(Intent intent, int i, int i2) {
        createNotificationChannel();
        startForeground(NOTIFICATION_ID, new NotificationCompat.Builder(this, CHANNEL_ID).setContentTitle(WebClientService.getWebServiceUrl().equals(WebServiceUrlConstant.GMM_WEB_SERVICE_URL) ? ServiceKeyValueConstant.CALL_LOCK_UNLOCK_SERVICE : "Device is locked").setSmallIcon(IconUtils.getAppIcon()).setPriority(1).build());
        SharedPrefManager.getInstance(getApplicationContext()).saveRequestLockStatus("1");
        setPersistentPreferredActivity(true, getApplicationContext());
        new FirebaseMessanging().subUnsubMe(getApplicationContext(), Config.SUBSCRIBE, Config.TOPIC_LAPP);
        Log.d(TAG, "onStartCommand: Auto Lock Worked");
        return 2;
    }

    private void createNotificationChannel() {
        if (Build.VERSION.SDK_INT >= 26) {
            NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, "CallLock Service Channel", 3);
            NotificationManager notificationManager = (NotificationManager) getSystemService(NotificationManager.class);
            if (notificationManager != null) {
                notificationManager.createNotificationChannel(notificationChannel);
            }
        }
    }

    public void setPersistentPreferredActivity(boolean z, Context context) {
        try {
            this.mAdminComponentName = DeviceAdminReceiver.getComponentName(context);
            DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService("device_policy");
            this.mDevicePolicyManager = devicePolicyManager;
            this.mDevicePolicyManagerGateway = new DevicePolicyManagerGatewayImpl(context);
            if (devicePolicyManager.isDeviceOwnerApp(context.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(context.getApplicationContext());
                        EnableHomeLauncherApp(context.getApplicationContext());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    DisableHomeLauncherApp(context.getApplicationContext());
                    setLauncherPackage(context.getApplicationContext());
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

    public void getLauncherPackage(Context context) {
        try {
            Intent intent = new Intent("android.intent.action.MAIN");
            intent.addCategory("android.intent.category.HOME");
            String str = null;
            try {
                str = context.getPackageManager().resolveActivity(intent, PKIFailureInfo.notAuthorized).activityInfo.packageName;
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (str == null) {
                Iterator<ResolveInfo> it = context.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(context.getPackageName().toLowerCase())) {
                        try {
                            SharedPrefManager.getInstance(context).saveDefaultLauncher(str2);
                            return;
                        } catch (Exception e2) {
                            e2.printStackTrace();
                        }
                    }
                }
                return;
            }
            if (str.toLowerCase().equals(context.getPackageName().toLowerCase())) {
                return;
            }
            SharedPrefManager.getInstance(context).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(context).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();
                }
            }
        }
    }

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