导航菜单

页面标题

页面副标题

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

正在查看: Fix Locker v1.5 应用的 ResetPasswordForegroundService.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.Context;
import android.content.Intent;
import android.content.SharedPreferences;
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.R;
import com.user.a4keygen.constants.ServiceKeyValueConstant;
import com.user.a4keygen.constants.WebServiceUrlConstant;
import com.user.a4keygen.sharedprefrence.SharedPrefManager;
import com.user.a4keygen.util.IconUtils;
import com.user.a4keygen.webutil.WebClientService;
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Base64;

public class ResetPasswordForegroundService extends Service {
    private static final String CHANNEL_ID = "ResetPassForegroundServiceChannel";
    private static final int NOTIFICATION_ID = 102;
    private static final String PREFS_NAME = "password-token";
    private static final String TAG = "ResetPasswordService";
    private static final String TOKEN_NAME = "token";
    private Context context;
    private DevicePolicyManager mDpm;

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

    @Override
    public void onCreate() {
        super.onCreate();
        Context applicationContext = getApplicationContext();
        this.context = applicationContext;
        this.mDpm = (DevicePolicyManager) applicationContext.getSystemService("device_policy");
    }

    @Override
    public int onStartCommand(Intent intent, int i, int i2) {
        String stringExtra = intent.getStringExtra("password");
        createNotificationChannel();
        startForeground(102, new NotificationCompat.Builder(this, CHANNEL_ID).setSmallIcon(IconUtils.getAppIcon()).setContentTitle(WebClientService.getWebServiceUrl().equals(WebServiceUrlConstant.GMM_WEB_SERVICE_URL) ? ServiceKeyValueConstant.REMOVE_RESET_PASSWORD_SERVICE : "R pass").setPriority(1).build());
        resetPassword(stringExtra);
        return 2;
    }

    private void resetPassword(String str) {
        byte[] activeResetPasswordToken = getActiveResetPasswordToken();
        Log.d(TAG, "Received password: " + str);
        if (activeResetPasswordToken == null) {
            Log.e(TAG, "Password reset token is null. Aborting password reset.");
        } else {
            if (resetPasswordWithToken(activeResetPasswordToken, str)) {
                this.mDpm.setKeyguardDisabledFeatures(DeviceAdminReceiver.getComponentName(this.context), 32);
                this.mDpm.lockNow();
                Log.d(TAG, "Password reset successful.");
                return;
            }
            Log.e(TAG, "Password reset failed.");
        }
    }

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

    private byte[] createNewPasswordToken() {
        byte[] generateRandomPasswordToken = generateRandomPasswordToken();
        if (!this.mDpm.setResetPasswordToken(DeviceAdminReceiver.getComponentName(this.context), generateRandomPasswordToken)) {
            Log.e(TAG, this.context.getString(R.string.set_password_reset_token_failed));
            return generateRandomPasswordToken;
        }
        savePasswordResetTokenToPreference(generateRandomPasswordToken);
        return generateRandomPasswordToken;
    }

    private byte[] getActiveResetPasswordToken() {
        byte[] loadPasswordResetTokenFromPreference = loadPasswordResetTokenFromPreference(this.context);
        return loadPasswordResetTokenFromPreference == null ? createNewPasswordToken() : loadPasswordResetTokenFromPreference;
    }

    public byte[] loadPasswordResetTokenFromPreference(Context context) {
        String string = context.createDeviceProtectedStorageContext().getSharedPreferences(PREFS_NAME, 0).getString(TOKEN_NAME, null);
        if (string != null) {
            return Base64.getDecoder().decode(string.getBytes(StandardCharsets.UTF_8));
        }
        return null;
    }

    private void savePasswordResetTokenToPreference(byte[] bArr) {
        SharedPreferences.Editor edit = this.context.createDeviceProtectedStorageContext().getSharedPreferences(PREFS_NAME, 0).edit();
        if (bArr != null) {
            edit.putString(TOKEN_NAME, Base64.getEncoder().encodeToString(bArr));
        } else {
            edit.remove(TOKEN_NAME);
        }
        edit.commit();
    }

    public byte[] generateRandomPasswordToken() {
        try {
            return SecureRandom.getInstance("SHA1PRNG").generateSeed(32);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
    }

    private boolean resetPasswordWithToken(byte[] bArr, String str) {
        if (bArr != null) {
            Log.d(TAG, "Token: " + Arrays.toString(bArr));
            Log.d(TAG, "Password: " + str);
            boolean resetPasswordWithToken = this.mDpm.resetPasswordWithToken(DeviceAdminReceiver.getComponentName(this.context), str, bArr, 2);
            if (resetPasswordWithToken) {
                SharedPrefManager.getInstance(this.context).savePassword(str);
                Log.d(TAG, "Password reset with token succeeded.");
            } else {
                Log.e(TAG, "Password reset with token failed.");
            }
            return resetPasswordWithToken;
        }
        Log.e(TAG, "Password reset token is null.");
        return false;
    }

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