正在查看: Fix Locker v1.5 应用的 DeviceAdminReceiver.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Fix Locker v1.5 应用的 DeviceAdminReceiver.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.user.a4keygen;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Binder;
import android.os.PersistableBundle;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;
import android.widget.Toast;
import androidx.core.app.NotificationCompat;
import com.user.a4keygen.common.NotificationUtil;
import com.user.a4keygen.common.Util;
import com.user.a4keygen.provision.PostProvisioningTask;
import com.user.a4keygen.util.IconUtils;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
public class DeviceAdminReceiver extends android.app.admin.DeviceAdminReceiver {
public static final String ACTION_PASSWORD_REQUIREMENTS_CHANGED = "com.user.a4keygen.policy.PASSWORD_REQUIREMENTS_CHANGED";
private static final int CHANGE_PASSWORD_NOTIFICATION_ID = 101;
private static final String FAILED_PASSWORD_LOG_FILE = "failed_pw_attempts_timestamps.log";
private static final String LOGS_DIR = "logs";
private static final int PASSWORD_FAILED_NOTIFICATION_ID = 102;
private static final String TAG = "DeviceAdminReceiver";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
action.hashCode();
switch (action) {
case "android.app.action.PROFILE_OWNER_CHANGED":
onProfileOwnerChanged(context);
break;
case "android.app.action.DEVICE_OWNER_CHANGED":
onDeviceOwnerChanged(context);
break;
case "android.intent.action.BOOT_COMPLETED":
case "com.user.a4keygen.policy.PASSWORD_REQUIREMENTS_CHANGED":
updatePasswordConstraintNotification(context);
break;
default:
super.onReceive(context, intent);
break;
}
}
@Override
public void onOperationSafetyStateChanged(Context context, int i, boolean z) {
String string;
String string2;
Log.d(TAG, "onOperationSafetyStateChanged(): " + i + " = " + z);
if (z) {
string = context.getString(R.string.safe);
} else {
string = context.getString(R.string.unsafe);
}
if (i == 1) {
string2 = context.getString(R.string.unsafe_operation_reason_driving_distraction);
} else {
string2 = context.getString(R.string.unsafe_operation_reason_driving_undefined);
}
showToast(context, context.getString(R.string.safety_operations_change_message, string2, string));
}
@Override
public void onSecurityLogsAvailable(Context context, Intent intent) {
Log.i(TAG, "onSecurityLogsAvailable() called");
showToast(context, R.string.on_security_logs_available);
}
@Override
public void onNetworkLogsAvailable(Context context, Intent intent, long j, int i) {
CommonReceiverOperations.onNetworkLogsAvailable(context, getComponentName(context), j, i);
}
@Override
public void onProfileProvisioningComplete(Context context, Intent intent) {
System.out.println("COSU CHECK onProfileProvisioningComplete called");
PostProvisioningTask postProvisioningTask = new PostProvisioningTask(context);
if (postProvisioningTask.performPostProvisioningOperations(intent)) {
Intent postProvisioningLaunchIntent = postProvisioningTask.getPostProvisioningLaunchIntent(intent);
if (postProvisioningLaunchIntent != null) {
context.startActivity(postProvisioningLaunchIntent);
} else {
Log.e(TAG, "DeviceAdminReceiver.onProvisioningComplete() invoked, but ownership not assigned");
showToast(context, R.string.device_admin_receiver_failure);
}
}
}
@Override
public void onBugreportSharingDeclined(Context context, Intent intent) {
Log.i(TAG, "Bugreport sharing declined");
NotificationUtil.showNotification(context, R.string.bugreport_title, context.getString(R.string.bugreport_sharing_declined), 1);
}
@Override
public void onBugreportShared(final Context context, Intent intent, final String str) {
Log.i(TAG, "Bugreport shared, hash: " + str);
final Uri data = intent.getData();
Log.i(TAG, "Bugreport URI: " + data);
final BroadcastReceiver.PendingResult goAsync = goAsync();
new AsyncTask<Void, Void, String>() {
@Override
public String doInBackground(Void... voidArr) {
try {
FileInputStream fileInputStream = new FileInputStream(context.getContentResolver().openFileDescriptor(data, "r").getFileDescriptor());
File file = new File(context.getExternalFilesDir(null), data.getLastPathSegment());
Log.i(DeviceAdminReceiver.TAG, "Writing bugreport to " + file);
FileOutputStream fileOutputStream = new FileOutputStream(file);
byte[] bArr = new byte[1024];
long j = 0;
while (true) {
int read = fileInputStream.read(bArr);
if (read != -1) {
j += read;
fileOutputStream.write(bArr, 0, read);
} else {
fileInputStream.close();
fileOutputStream.close();
String string = context.getString(R.string.received_bugreport, file.getPath(), str, Long.valueOf(j));
Log.i(DeviceAdminReceiver.TAG, string);
return string;
}
}
} catch (IOException e) {
Log.e(DeviceAdminReceiver.TAG, e.getMessage());
return context.getString(R.string.received_bugreport_failed_retrieval);
}
}
@Override
public void onPostExecute(String str2) {
NotificationUtil.showNotification(context, R.string.bugreport_title, str2, 1);
goAsync.finish();
}
}.execute(new Void[0]);
}
@Override
public void onBugreportFailed(Context context, Intent intent, int i) {
String string;
if (i == 1) {
string = context.getString(R.string.bugreport_failure_file_no_longer_available);
} else {
string = context.getString(R.string.bugreport_failure_failed_completing);
}
Log.i(TAG, "Bugreport failed: " + string);
NotificationUtil.showNotification(context, R.string.bugreport_title, context.getString(R.string.bugreport_failure_message, string), 1);
}
@Override
public void onUserAdded(Context context, Intent intent, UserHandle userHandle) {
handleUserAction(context, userHandle, R.string.on_user_added_title, R.string.on_user_added_message, 3);
}
@Override
public void onUserRemoved(Context context, Intent intent, UserHandle userHandle) {
handleUserAction(context, userHandle, R.string.on_user_removed_title, R.string.on_user_removed_message, 4);
}
@Override
public void onUserStarted(Context context, Intent intent, UserHandle userHandle) {
handleUserAction(context, userHandle, R.string.on_user_started_title, R.string.on_user_started_message, 5);
}
@Override
public void onUserStopped(Context context, Intent intent, UserHandle userHandle) {
handleUserAction(context, userHandle, R.string.on_user_stopped_title, R.string.on_user_stopped_message, 6);
}
@Override
public void onUserSwitched(Context context, Intent intent, UserHandle userHandle) {
handleUserAction(context, userHandle, R.string.on_user_switched_title, R.string.on_user_switched_message, 7);
}
@Override
public void onSystemUpdatePending(Context context, Intent intent, long j) {
if (j != -1) {
showToast(context, "System update received at: " + new SimpleDateFormat("hh:mm:ss dd/MM/yyyy").format(new Date(j)));
}
}
@Override
public String onChoosePrivateKeyAlias(Context context, Intent intent, int i, Uri uri, String str) {
return CommonReceiverOperations.onChoosePrivateKeyAlias(context, i);
}
public static ComponentName getComponentName(Context context) {
return new ComponentName(context.getApplicationContext(), (Class<?>) DeviceAdminReceiver.class);
}
@Override
@Deprecated
public void onPasswordExpiring(Context context, Intent intent) {
onPasswordExpiring(context, intent, Process.myUserHandle());
}
@Override
public void onPasswordExpiring(Context context, Intent intent, UserHandle userHandle) {
if (Process.myUserHandle().equals(userHandle)) {
DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService("device_policy");
long currentTimeMillis = System.currentTimeMillis();
long passwordExpiration = devicePolicyManager.getPasswordExpiration(getComponentName(context));
NotificationUtil.showNotification(context, R.string.password_expired_title, context.getString((currentTimeMillis > passwordExpiration ? 1 : (currentTimeMillis == passwordExpiration ? 0 : -1)) >= 0 && (passwordExpiration > 0L ? 1 : (passwordExpiration == 0L ? 0 : -1)) != 0 ? R.string.password_expired_by_self : R.string.password_expired_by_others), 2);
}
}
@Override
@Deprecated
public void onPasswordFailed(Context context, Intent intent) {
onPasswordFailed(context, intent, Process.myUserHandle());
}
@Override
public void onPasswordFailed(Context context, Intent intent, UserHandle userHandle) {
String quantityString;
if (Process.myUserHandle().equals(userHandle)) {
DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService("device_policy");
int currentFailedPasswordAttempts = devicePolicyManager.getCurrentFailedPasswordAttempts();
int maximumFailedPasswordsForWipe = devicePolicyManager.getMaximumFailedPasswordsForWipe(null);
String quantityString2 = context.getResources().getQuantityString(R.plurals.password_failed_attempts_title, currentFailedPasswordAttempts, Integer.valueOf(currentFailedPasswordAttempts));
ArrayList<Date> failedPasswordAttempts = getFailedPasswordAttempts(context);
failedPasswordAttempts.add(new Date());
Collections.sort(failedPasswordAttempts, Collections.reverseOrder());
try {
saveFailedPasswordAttempts(context, failedPasswordAttempts);
} catch (IOException e) {
Log.e(TAG, "Unable to save failed password attempts", e);
}
if (maximumFailedPasswordsForWipe == 0) {
quantityString = context.getString(R.string.password_failed_no_limit_set);
} else {
quantityString = context.getResources().getQuantityString(R.plurals.password_failed_attempts_content, maximumFailedPasswordsForWipe, Integer.valueOf(maximumFailedPasswordsForWipe));
}
NotificationCompat.Builder notificationBuilder = NotificationUtil.getNotificationBuilder(context);
notificationBuilder.setSmallIcon(IconUtils.getAppIcon()).setTicker(quantityString2).setContentTitle(quantityString2).setContentText(quantityString).setContentIntent(PendingIntent.getActivity(context, -1, new Intent("android.app.action.SET_NEW_PASSWORD"), 33554432));
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
inboxStyle.setBigContentTitle(quantityString2);
DateFormat dateTimeInstance = SimpleDateFormat.getDateTimeInstance();
Iterator<Date> it = failedPasswordAttempts.iterator();
while (it.hasNext()) {
inboxStyle.addLine(dateTimeInstance.format(it.next()));
}
notificationBuilder.setStyle(inboxStyle);
((NotificationManager) context.getSystemService("notification")).notify(102, notificationBuilder.build());
}
}
@Override
@Deprecated
public void onPasswordSucceeded(Context context, Intent intent) {
onPasswordSucceeded(context, intent, Process.myUserHandle());
}
@Override
public void onPasswordSucceeded(Context context, Intent intent, UserHandle userHandle) {
if (Process.myUserHandle().equals(userHandle)) {
logFile(context).delete();
}
}
@Override
@Deprecated
public void onPasswordChanged(Context context, Intent intent) {
onPasswordChanged(context, intent, Process.myUserHandle());
}
@Override
public void onPasswordChanged(Context context, Intent intent, UserHandle userHandle) {
if (Process.myUserHandle().equals(userHandle)) {
updatePasswordConstraintNotification(context);
}
}
@Override
public void onEnabled(Context context, Intent intent) {
Log.i(TAG, "Device admin enabled in user with serial number: " + ((UserManager) context.getSystemService("user")).getSerialNumberForUser(Binder.getCallingUserHandle()));
}
private static File logFile(Context context) {
return new File(context.getDir(LOGS_DIR, 0), FAILED_PASSWORD_LOG_FILE);
}
private static ArrayList<Date> getFailedPasswordAttempts(Context context) {
FileInputStream fileInputStream;
String readLine;
File logFile = logFile(context);
ArrayList<Date> arrayList = new ArrayList<>();
if (!logFile.exists()) {
return arrayList;
}
FileInputStream fileInputStream2 = null;
fileInputStream2 = null;
fileInputStream2 = null;
try {
try {
try {
fileInputStream = new FileInputStream(logFile);
} catch (IOException e) {
Log.e(TAG, "Unable to close failed password attempts log file", e);
}
} catch (IOException e2) {
e = e2;
}
} catch (Throwable th) {
th = th;
}
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
while (true) {
readLine = bufferedReader.readLine();
if (readLine == 0 || readLine.length() <= 0) {
break;
}
arrayList.add(new Date(Long.parseLong(readLine)));
}
bufferedReader.close();
fileInputStream.close();
fileInputStream2 = readLine;
} catch (IOException e3) {
e = e3;
fileInputStream2 = fileInputStream;
Log.e(TAG, "Unable to read failed password attempts", e);
if (fileInputStream2 != null) {
fileInputStream2.close();
fileInputStream2 = fileInputStream2;
}
return arrayList;
} catch (Throwable th2) {
th = th2;
fileInputStream2 = fileInputStream;
if (fileInputStream2 != null) {
try {
fileInputStream2.close();
} catch (IOException e4) {
Log.e(TAG, "Unable to close failed password attempts log file", e4);
}
}
throw th;
}
return arrayList;
}
private static void saveFailedPasswordAttempts(Context context, ArrayList<Date> arrayList) throws IOException {
File logFile = logFile(context);
if (!logFile.exists()) {
logFile.createNewFile();
}
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(logFile)));
Iterator<Date> it = arrayList.iterator();
while (it.hasNext()) {
bufferedWriter.write(Long.toString(it.next().getTime()));
bufferedWriter.newLine();
}
bufferedWriter.close();
}
private static void updatePasswordConstraintNotification(Context context) {
DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService("device_policy");
UserManager userManager = (UserManager) context.getSystemService("user");
if (devicePolicyManager.isProfileOwnerApp(context.getPackageName()) || devicePolicyManager.isDeviceOwnerApp(context.getPackageName())) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService("notification");
ArrayList arrayList = new ArrayList();
if (!devicePolicyManager.isActivePasswordSufficient()) {
arrayList.add(context.getText(R.string.password_not_compliant_title));
}
if (userManager.hasUserRestriction("no_unified_password") && Util.isManagedProfileOwner(context) && isUsingUnifiedPassword(context).booleanValue()) {
arrayList.add(context.getText(R.string.separate_challenge_required_title));
}
if (!arrayList.isEmpty()) {
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
inboxStyle.setBigContentTitle(context.getText(R.string.set_new_password_notification_content));
Iterator it = arrayList.iterator();
while (it.hasNext()) {
inboxStyle.addLine((CharSequence) it.next());
}
NotificationCompat.Builder notificationBuilder = NotificationUtil.getNotificationBuilder(context);
notificationBuilder.setOngoing(true).setSmallIcon(IconUtils.getAppIcon()).setStyle(inboxStyle).setContentIntent(PendingIntent.getActivity(context, -1, new Intent("android.app.action.SET_NEW_PASSWORD"), 33554432));
notificationManager.notify(101, notificationBuilder.getNotification());
return;
}
notificationManager.cancel(101);
}
}
private static Boolean isUsingUnifiedPassword(Context context) {
if (Util.SDK_INT < 28) {
return false;
}
return Boolean.valueOf(((DevicePolicyManager) context.getSystemService(DevicePolicyManager.class)).isUsingUnifiedPassword(getComponentName(context)));
}
public static void sendPasswordRequirementsChanged(Context context) {
Intent intent = new Intent(ACTION_PASSWORD_REQUIREMENTS_CHANGED);
intent.setComponent(getComponentName(context));
context.sendBroadcast(intent);
}
private void onProfileOwnerChanged(Context context) {
Log.i(TAG, "onProfileOwnerChanged");
NotificationUtil.showNotification(context, R.string.transfer_ownership_profile_owner_changed_title, context.getString(R.string.transfer_ownership_profile_owner_changed_title), 8);
}
private void onDeviceOwnerChanged(Context context) {
Log.i(TAG, "onDeviceOwnerChanged");
NotificationUtil.showNotification(context, R.string.transfer_ownership_device_owner_changed_title, context.getString(R.string.transfer_ownership_device_owner_changed_title), 9);
}
@Override
public void onTransferOwnershipComplete(Context context, PersistableBundle persistableBundle) {
Log.i(TAG, "onTransferOwnershipComplete");
NotificationUtil.showNotification(context, R.string.transfer_ownership_complete_title, context.getString(R.string.transfer_ownership_complete_message, getComponentName(context)), 10);
}
@Override
public void onTransferAffiliatedProfileOwnershipComplete(Context context, UserHandle userHandle) {
Log.i(TAG, "onTransferAffiliatedProfileOwnershipComplete");
NotificationUtil.showNotification(context, R.string.transfer_ownership_affiliated_complete_title, context.getString(R.string.transfer_ownership_affiliated_complete_message, userHandle), 11);
}
private void handleUserAction(Context context, UserHandle userHandle, int i, int i2, int i3) {
String string = context.getString(i2, Long.valueOf(((UserManager) context.getSystemService("user")).getSerialNumberForUser(userHandle)));
Log.i(TAG, string);
NotificationUtil.showNotification(context, i, string, i3);
}
private void showToast(Context context, int i) {
showToast(context, context.getString(i));
}
private void showToast(Context context, String str) {
Log.v(TAG, "showToast():" + str);
Toast.makeText(context, str, 1).show();
}
}