导航菜单

页面标题

页面副标题

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

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

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


package com.user.a4keygen.policy.resetpassword;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.os.UserManager;
import android.util.Log;
import com.user.a4keygen.DeviceAdminReceiver;
import com.user.a4keygen.R;
import com.user.a4keygen.sharedprefrence.SharedPrefManager;
import com.user.a4keygen.util.IconUtils;

public class ResetPasswordService extends Service {
    private static final String ACTION_RESET_PASSWORD = "com.user.a4keygen.RESET_PASSWORD";
    private static final String NOTIFICATION_CHANNEL = "reset-password-notification";
    private static final int NOTIFICATION_FOREGROUND = 3;
    private static final int NOTIFICATION_RESET_RESULT = 2;
    private static final int NOTIFICATION_TAP_TO_RESET = 1;
    private static final String TAG = "ResetPasswordService";
    private DevicePolicyManager mDpm;
    private NotificationManager mNm;
    private BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d(ResetPasswordService.TAG, "onReceive: " + intent.toString());
            if ("android.intent.action.USER_UNLOCKED".equals(intent.getAction())) {
                ResetPasswordService.this.dismissNotification();
                ResetPasswordService resetPasswordService = ResetPasswordService.this;
                resetPasswordService.unregisterReceiver(resetPasswordService.receiver);
                ResetPasswordService.this.stopSelf();
                return;
            }
            if (ResetPasswordService.ACTION_RESET_PASSWORD.equals(intent.getAction())) {
                ResetPasswordService.this.doResetPassword(context);
            }
        }
    };

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

    public static class LockedBootCompletedReceiver extends BroadcastReceiver {
        private static final String TAG = "BootCompletedReceiver";

        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d(TAG, "onReceive: " + intent.toString());
            Intent intent2 = new Intent(context, (Class<?>) ResetPasswordService.class);
            intent2.setAction(intent.getAction());
            context.startForegroundService(intent2);
        }
    }

    @Override
    public void onCreate() {
        super.onCreate();
        this.mDpm = (DevicePolicyManager) getSystemService(DevicePolicyManager.class);
        this.mNm = (NotificationManager) getSystemService(NotificationManager.class);
    }

    @Override
    public int onStartCommand(Intent intent, int i, int i2) {
        createNotificationChannel();
        startForeground();
        if (((UserManager) getSystemService(UserManager.class)).isUserUnlocked() || getActiveResetPasswordToken() == null) {
            stopSelf();
            this.mNm.cancel(3);
            return 2;
        }
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.intent.action.USER_UNLOCKED");
        intentFilter.addAction(ACTION_RESET_PASSWORD);
        registerReceiver(this.receiver, intentFilter);
        return 3;
    }

    private void createNotificationChannel() {
        this.mNm.createNotificationChannel(new NotificationChannel(NOTIFICATION_CHANNEL, getString(R.string.app_name), 3));
    }

    private void startForeground() {
        startForeground(3, new Notification.Builder(this).setContentTitle(getString(R.string.app_name)).setContentText(getString(R.string.reset_password_foreground_notification)).setSmallIcon(IconUtils.getAppIcon()).setChannelId(NOTIFICATION_CHANNEL).build());
    }

    private byte[] getActiveResetPasswordToken() {
        byte[] loadPasswordResetTokenFromPreference = ResetPasswordWithTokenFragment.loadPasswordResetTokenFromPreference(this);
        if (loadPasswordResetTokenFromPreference == null) {
            return null;
        }
        if (this.mDpm.isResetPasswordTokenActive(DeviceAdminReceiver.getComponentName(this))) {
            return loadPasswordResetTokenFromPreference;
        }
        Log.i(TAG, "Token exists but is not activated.");
        return null;
    }

    public void doResetPassword(Context context) {
        boolean z;
        String password = SharedPrefManager.getInstance(context).getPassword();
        byte[] activeResetPasswordToken = getActiveResetPasswordToken();
        if (activeResetPasswordToken != null) {
            z = this.mDpm.resetPasswordWithToken(DeviceAdminReceiver.getComponentName(this), password, activeResetPasswordToken, 2);
        } else {
            Log.e(TAG, "Cannot reset password without token");
            z = false;
        }
        Notification.Builder channelId = new Notification.Builder(this).setContentTitle(getString(R.string.app_name)).setSmallIcon(IconUtils.getAppIcon()).setChannelId(NOTIFICATION_CHANNEL);
        if (z) {
            channelId.setContentText(getString(R.string.reset_password_with_token_succeed, new Object[]{"****"}));
            channelId.setOngoing(true);
        } else {
            channelId.setContentText(getString(R.string.reset_password_with_token_failed));
        }
        this.mNm.notify(2, channelId.build());
    }

    private void showNotification() {
        PendingIntent broadcast = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_RESET_PASSWORD), 33554432);
        this.mNm.notify(1, new Notification.Builder(this).setContentTitle(getString(R.string.app_name)).setContentText(getString(R.string.reset_password_notification)).setContentIntent(broadcast).setDeleteIntent(broadcast).setSmallIcon(IconUtils.getAppIcon()).setChannelId(NOTIFICATION_CHANNEL).build());
    }

    public void dismissNotification() {
        this.mNm.cancel(1);
        this.mNm.cancel(2);
    }
}