This repository has been archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
569e043
commit 7f17307
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
app/src/main/java/at/tacticaldevc/oat/listeners/DeviceAdminListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |