Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Fully implemented device admin
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5ECF4ULT authored and FiryDragon1 committed May 26, 2020
1 parent 569e043 commit 7f17307
Showing 3 changed files with 89 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -54,6 +54,14 @@
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<receiver
android:name=".listeners.DeviceAdminListener"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
<action android:name="android.app.action.DEVICE_ADMIN_DISABLES" />
</intent-filter>
</receiver>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package at.tacticaldevc.oat.listeners;

import android.app.admin.DeviceAdminReceiver;
import android.content.Context;
import android.content.Intent;

import androidx.annotation.NonNull;

import at.tacticaldevc.oat.R;
import at.tacticaldevc.oat.utils.Prefs;

public class DeviceAdminListener extends DeviceAdminReceiver {

private static final DeviceAdminListener dal;

static {
dal = new DeviceAdminListener();
}

private DeviceAdminListener() {
}

public static DeviceAdminListener getDAObject() {
return dal;
}

@Override
public void onEnabled(@NonNull Context context, @NonNull Intent intent) {
super.onEnabled(context, intent);
Prefs.saveFeatureEnabledStatus(context, context.getString(R.string.oat_features_key_trigger_lockdown), true);
Prefs.saveFeatureEnabledStatus(context, context.getString(R.string.oat_features_key_lift_lockdown), true);
}

@Override
public void onDisabled(@NonNull Context context, @NonNull Intent intent) {
super.onDisabled(context, intent);
Prefs.saveFeatureEnabledStatus(context, context.getString(R.string.oat_features_key_trigger_lockdown), false);
Prefs.saveFeatureEnabledStatus(context, context.getString(R.string.oat_features_key_lift_lockdown), false);
}
}
41 changes: 41 additions & 0 deletions app/src/main/java/at/tacticaldevc/oat/utils/DA.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@
package at.tacticaldevc.oat.utils;

import android.app.admin.DevicePolicyManager;
import android.content.Context;

import at.tacticaldevc.oat.R;
import at.tacticaldevc.oat.listeners.DeviceAdminListener;

import static at.tacticaldevc.oat.utils.Ensurer.ensureNotNull;
import static at.tacticaldevc.oat.utils.Ensurer.ensureStringIsValid;

/**
* A helper class for device administration
*/
public class DA {

/**
* Activate the lockdown using DA
*
* @param ctx The application context
* @param phone A valid phone number in String representation
*/
public static void lockdown_activate(Context ctx, String phone) {
ensureNotNull(ctx, "Context");
ensureStringIsValid(phone, "Phone number");

if (Prefs.fetchFeatureEnabledStatus(ctx, ctx.getString(R.string.oat_features_key_trigger_lockdown))) {
DevicePolicyManager pol = DeviceAdminListener.getDAObject().getManager(ctx);
pol.lockNow();
}
}

/**
* Deactivate the lockdown using DA
*
* @param ctx The application context
* @param phone A valid phone number in String representation
*/
public static void lockdown_deactivate(Context ctx, String phone) {
ensureNotNull(ctx, "Context");
ensureStringIsValid(phone, "Phone number");

if (Prefs.fetchFeatureEnabledStatus(ctx, ctx.getString(R.string.oat_features_key_trigger_lockdown))) {
DevicePolicyManager pol = DeviceAdminListener.getDAObject().getManager(ctx);
pol.lockNow();
}
}
}

0 comments on commit 7f17307

Please sign in to comment.