💅 style(manifest, launcher, gestures): remove deprecated DeviceAdmin permission and functionality
This commit is contained in:
9 files changed
+14
-151
No files matched your search
@@ -7,7 +7,7 @@
|
||||
|
||||
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.BIND_DEVICE_ADMIN" />
|
||||
|
||||
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
|
||||
|
||||
<!-- Permissions for app detection -->
|
||||
@@ -40,19 +40,7 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<receiver
|
||||
android:name=".utils.lunoxDeviceAdminReceiver"
|
||||
android:description="@string/device_admin_description"
|
||||
android:label="@string/device_admin_label"
|
||||
android:permission="android.permission.BIND_DEVICE_ADMIN"
|
||||
android:exported="true">
|
||||
<meta-data
|
||||
android:name="android.app.device_admin"
|
||||
android:resource="@xml/device_admin" />
|
||||
<intent-filter>
|
||||
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
|
||||
</application>
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ import io.github.sankalp.lunox.model.Apps;
|
||||
import io.github.sankalp.lunox.model.Shortcut;
|
||||
import io.github.sankalp.lunox.utils.CrashUtils;
|
||||
import io.github.sankalp.lunox.utils.DbUtils;
|
||||
import io.github.sankalp.lunox.utils.DeviceAdminManager;
|
||||
|
||||
import io.github.sankalp.lunox.utils.Gestures;
|
||||
import io.github.sankalp.lunox.utils.NotificationPanelManager;
|
||||
import io.github.sankalp.lunox.utils.ShortcutUtils;
|
||||
@@ -1211,11 +1211,7 @@ public class LauncherActivity extends Activity implements View.OnClickListener,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDoubleTap() {
|
||||
// Always lock the device on double tap
|
||||
DeviceAdminManager.lockDevice(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -33,13 +33,12 @@ import android.widget.Toast;
|
||||
import io.github.sankalp.lunox.LauncherActivity;
|
||||
import io.github.sankalp.lunox.R;
|
||||
import io.github.sankalp.lunox.utils.DbUtils;
|
||||
import io.github.sankalp.lunox.utils.DeviceAdminManager;
|
||||
|
||||
|
||||
public class PermissionDialog extends Dialog implements View.OnClickListener {
|
||||
|
||||
private final LauncherActivity context;
|
||||
private TextView usageAccessButton;
|
||||
private TextView deviceAdminButton;
|
||||
private TextView continueButton;
|
||||
|
||||
public PermissionDialog(Context context, LauncherActivity launcherActivity) {
|
||||
@@ -56,12 +55,10 @@ public class PermissionDialog extends Dialog implements View.OnClickListener {
|
||||
|
||||
// Initialize views
|
||||
usageAccessButton = findViewById(R.id.permission_usage_access);
|
||||
deviceAdminButton = findViewById(R.id.permission_device_admin);
|
||||
continueButton = findViewById(R.id.permission_continue);
|
||||
|
||||
// Set click listeners
|
||||
usageAccessButton.setOnClickListener(this);
|
||||
deviceAdminButton.setOnClickListener(this);
|
||||
continueButton.setOnClickListener(this);
|
||||
|
||||
// Update button states
|
||||
@@ -74,8 +71,6 @@ public class PermissionDialog extends Dialog implements View.OnClickListener {
|
||||
|
||||
if (id == R.id.permission_usage_access) {
|
||||
openUsageAccessSettings();
|
||||
} else if (id == R.id.permission_device_admin) {
|
||||
enableDeviceAdmin();
|
||||
} else if (id == R.id.permission_continue) {
|
||||
continueToLauncher();
|
||||
}
|
||||
@@ -94,28 +89,20 @@ public class PermissionDialog extends Dialog implements View.OnClickListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void enableDeviceAdmin() {
|
||||
try {
|
||||
DeviceAdminManager.requestDeviceAdminPermission(context);
|
||||
Toast.makeText(context, "Please enable Device Admin for Lunox", Toast.LENGTH_LONG).show();
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(context, "Unable to open Device Admin settings", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void continueToLauncher() {
|
||||
// Mark permission dialog as shown
|
||||
DbUtils.setPermissionDialogShown(true);
|
||||
|
||||
// Check if at least one permission is granted
|
||||
// Check if usage access permission is granted
|
||||
boolean hasUsageAccess = checkUsageAccessPermission();
|
||||
boolean hasDeviceAdmin = DeviceAdminManager.isDeviceAdminActive(context);
|
||||
|
||||
if (hasUsageAccess || hasDeviceAdmin) {
|
||||
if (hasUsageAccess) {
|
||||
dismiss();
|
||||
context.loadApps(); // Reload apps after permissions are granted
|
||||
} else {
|
||||
Toast.makeText(context, "Please grant at least one permission to continue", Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(context, "Please grant Usage Access permission to continue", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,22 +120,12 @@ public class PermissionDialog extends Dialog implements View.OnClickListener {
|
||||
// Update Usage Access button
|
||||
boolean hasUsageAccess = checkUsageAccessPermission();
|
||||
if (hasUsageAccess) {
|
||||
usageAccessButton.setText("Usage Access");
|
||||
usageAccessButton.setText("Usage Access ✓");
|
||||
usageAccessButton.setAlpha(0.7f);
|
||||
} else {
|
||||
usageAccessButton.setText("Enable Usage Access");
|
||||
usageAccessButton.setAlpha(1.0f);
|
||||
}
|
||||
|
||||
// Update Device Admin button
|
||||
boolean hasDeviceAdmin = DeviceAdminManager.isDeviceAdminActive(context);
|
||||
if (hasDeviceAdmin) {
|
||||
deviceAdminButton.setText("Device Admin");
|
||||
deviceAdminButton.setAlpha(0.7f);
|
||||
} else {
|
||||
deviceAdminButton.setText("Enable Device Admin");
|
||||
deviceAdminButton.setAlpha(1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
package io.github.sankalp.lunox.utils;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.widget.Toast;
|
||||
|
||||
import io.github.sankalp.lunox.R;
|
||||
|
||||
public class DeviceAdminManager {
|
||||
|
||||
private static final String TAG = "DeviceAdminManager";
|
||||
|
||||
public static boolean isDeviceAdminActive(Context context) {
|
||||
DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
ComponentName adminComponent = new ComponentName(context, io.github.sankalp.lunox.utils.lunoxDeviceAdminReceiver.class);
|
||||
return dpm.isAdminActive(adminComponent);
|
||||
}
|
||||
|
||||
public static void requestDeviceAdminPermission(Context context) {
|
||||
DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
ComponentName adminComponent = new ComponentName(context, io.github.sankalp.lunox.utils.lunoxDeviceAdminReceiver.class);
|
||||
|
||||
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
|
||||
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, adminComponent);
|
||||
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, context.getString(R.string.device_admin_description));
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
public static boolean lockDevice(Context context) {
|
||||
if (!isDeviceAdminActive(context)) {
|
||||
Toast.makeText(context, R.string.device_admin_disabled, Toast.LENGTH_SHORT).show();
|
||||
requestDeviceAdminPermission(context);
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
ComponentName adminComponent = new ComponentName(context, io.github.sankalp.lunox.utils.lunoxDeviceAdminReceiver.class);
|
||||
dpm.lockNow();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(context, "Failed to lock device", Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,11 +73,7 @@ public class Gestures extends GestureDetector.SimpleOnGestureListener {
|
||||
return consumed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDoubleTap(MotionEvent arg) {
|
||||
this.listener.onDoubleTap();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public enum Direction {
|
||||
@@ -86,8 +82,6 @@ public class Gestures extends GestureDetector.SimpleOnGestureListener {
|
||||
|
||||
public interface OnSwipeListener {
|
||||
void onSwipe(Direction direction);
|
||||
|
||||
void onDoubleTap();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package io.github.sankalp.lunox.utils;
|
||||
|
||||
import android.app.admin.DeviceAdminReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class lunoxDeviceAdminReceiver extends DeviceAdminReceiver {
|
||||
|
||||
@Override
|
||||
public void onEnabled(Context context, Intent intent) {
|
||||
super.onEnabled(context, intent);
|
||||
Toast.makeText(context, "Device Admin Enabled", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisabled(Context context, Intent intent) {
|
||||
super.onDisabled(context, intent);
|
||||
Toast.makeText(context, "Device Admin Disabled", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
@@ -61,19 +61,7 @@
|
||||
android:clickable="true"
|
||||
android:focusable="true" />
|
||||
|
||||
<!-- Device Admin Permission -->
|
||||
<TextView
|
||||
android:id="@+id/permission_device_admin"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:padding="15dp"
|
||||
android:layout_margin="5dp"
|
||||
android:text="Enable Device Admin"
|
||||
android:textSize="20sp"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:clickable="true"
|
||||
android:focusable="true" />
|
||||
|
||||
|
||||
<!-- Continue Button -->
|
||||
<TextView
|
||||
|
||||
@@ -91,14 +91,11 @@
|
||||
<string name="recently_first">Recently first</string>
|
||||
<string name="restart_launcher">Restart Launcher</string>
|
||||
|
||||
<string name="device_admin_label">Lunox Device Admin</string>
|
||||
<string name="device_admin_description">Required for double-tap to lock screen functionality</string>
|
||||
<string name="device_admin_enable">Enable Device Admin</string>
|
||||
<string name="device_admin_disabled">Device Admin is required for lock screen functionality</string>
|
||||
|
||||
|
||||
<!-- Permission Dialog Strings -->
|
||||
<string name="permission_dialog_title">Welcome to Lunox! 🚀</string>
|
||||
<string name="permission_dialog_message">To provide the best launcher experience, Lunox needs these permissions:\n\n<b>Usage Access</b> - Display all your apps\n<b>Device Admin</b> - Enable advanced features\n\nTap each permission below to enable it.</string>
|
||||
<string name="permission_dialog_message">To provide the best launcher experience, Lunox needs this permission:\n\n<b>Usage Access</b> - Display all your apps\n\nTap the permission below to enable it.</string>
|
||||
|
||||
|
||||
<!-- Frozen apps dialog title -->
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<uses-policies>
|
||||
<force-lock />
|
||||
</uses-policies>
|
||||
</device-admin>
|
||||
Reference in new issue
Block a user