导航菜单

页面标题

页面副标题

Loan Locker v1.5 - LocationControlForegroundService.java 源代码

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

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


package com.user.a4keygen.services;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Intent;
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.constants.ServiceKeyValueConstant;
import com.user.a4keygen.constants.WebServiceUrlConstant;
import com.user.a4keygen.util.IconUtils;
import com.user.a4keygen.webutil.WebClientService;

public class LocationControlForegroundService extends Service {
    private static final String CHANNEL_ID = "LocationControlServiceChannel";
    private static final int NOTIFICATION_ID = 103;
    private static final String TAG = "LocationControlService";
    private ComponentName adminComponent;
    private DevicePolicyManager dpm;
    public DevicePolicyManagerGateway mDevicePolicyManagerGateway;

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

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d(TAG, "Service created");
        this.dpm = (DevicePolicyManager) getApplicationContext().getSystemService("device_policy");
        this.adminComponent = new ComponentName(getApplicationContext(), (Class<?>) DeviceAdminReceiver.class);
        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) {
        Boolean valueOf = Boolean.valueOf(intent.getBooleanExtra("ALLOW_TEMP_LOCATION", false));
        createNotificationChannel();
        startForeground(103, new NotificationCompat.Builder(this, CHANNEL_ID).setContentTitle("Enabling LCT").setSmallIcon(IconUtils.getAppIcon()).setPriority(1).build());
        if (valueOf.booleanValue()) {
            regainLocationControl();
            return 2;
        }
        allowUserToEnableLocation();
        return 2;
    }

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

    private void regainLocationControl() {
        Log.d(TAG, "Regaining control of location settings");
        if (Build.VERSION.SDK_INT >= 30) {
            this.dpm.setLocationEnabled(this.adminComponent, true);
            this.mDevicePolicyManagerGateway.setUserRestriction("no_config_location", true);
            Log.d(TAG, "Location restriction re-applied. User cannot change location settings.");
            createNotification("Lct On");
        }
    }

    private void allowUserToEnableLocation() {
        Log.d(TAG, "Temporarily allowing user to enable location");
        if (Build.VERSION.SDK_INT >= 30) {
            this.mDevicePolicyManagerGateway.setUserRestriction("no_config_location", false);
            createNotification("You can now manage your location settings.");
        }
    }

    private void createNotification(String str) {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID);
        boolean equals = WebClientService.getWebServiceUrl().equals(WebServiceUrlConstant.GMM_WEB_SERVICE_URL);
        String str2 = ServiceKeyValueConstant.LOCATION_OFF_SERVICE;
        NotificationCompat.Builder contentTitle = builder.setContentTitle(equals ? ServiceKeyValueConstant.LOCATION_OFF_SERVICE : "LCT Control");
        if (!WebClientService.getWebServiceUrl().equals(WebServiceUrlConstant.GMM_WEB_SERVICE_URL)) {
            str2 = "LCT Control";
        }
        Notification build = contentTitle.setContentText(str2).setSmallIcon(IconUtils.getAppIcon()).setPriority(1).build();
        NotificationManager notificationManager = (NotificationManager) getSystemService("notification");
        if (notificationManager != null) {
            notificationManager.notify(103, build);
        }
    }

    @Override
    public void onDestroy() {
        Log.d(TAG, "Service destroyed");
        super.onDestroy();
    }
}