DeviceOwnerReceiver: Add minimal support for device owner API

SessionInstaller can commit silent installs if the app is device owner. Implemented on
request of users.

This still needs user to set the app as device owner manually using ADB (only possible
if the device has no accounts setup yet).

Co-authored-by: Syuugo <pub@s1204.me>
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2024-04-24 15:41:26 +05:30
parent 00532f200e
commit 933b7b6886
7 changed files with 62 additions and 0 deletions

View File

@@ -58,6 +58,10 @@
android:name="android.hardware.gamepad"
android:required="false"/>
<uses-feature
android:name="android.software.device_admin"
android:required="false" />
<application
android:name=".AuroraApp"
android:allowBackup="true"
@@ -142,5 +146,18 @@
<receiver
android:name=".data.receiver.InstallerStatusReceiver"
android:exported="false" />
<!-- SessionInstaller (as device owner) -->
<receiver
android:name=".data.receiver.DeviceOwnerReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN"
android:exported="true">
<meta-data
android:name="android.app.device_admin"
android:resource="@xml/device_owner_receiver" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
</application>
</manifest>

View File

@@ -0,0 +1,5 @@
package com.aurora.store.data.receiver
import android.app.admin.DeviceAdminReceiver
class DeviceOwnerReceiver : DeviceAdminReceiver()

View File

@@ -47,6 +47,7 @@ object Preferences {
const val PREFERENCE_DOWNLOADS_CACHE_TIME = "PREFERENCE_DOWNLOADS_CACHE_TIME"
const val PREFERENCE_AUTO_DELETE = "PREFERENCE_AUTO_DELETE"
const val PREFERENCE_INSTALLATION_DEVICE_OWNER = "PREFERENCE_INSTALLATION_DEVICE_OWNER"
const val INSTALLATION_ABANDON_SESSION = "INSTALLATION_ABANDON_SESSION"
const val PREFERENCE_TOS_READ = "PREFERENCE_TOS_READ"

View File

@@ -19,6 +19,9 @@
package com.aurora.store.view.ui.preferences
import android.app.admin.DevicePolicyManager
import android.content.Context
import android.content.DialogInterface
import android.content.pm.PackageManager
import android.os.Bundle
import android.view.View
@@ -38,6 +41,7 @@ import com.aurora.store.util.CommonUtil
import com.aurora.store.util.Log
import com.aurora.store.util.PackageUtil
import com.aurora.store.util.Preferences
import com.aurora.store.util.Preferences.PREFERENCE_INSTALLATION_DEVICE_OWNER
import com.aurora.store.util.save
import com.aurora.store.view.custom.preference.AuroraListPreference
import com.topjohnwu.superuser.Shell
@@ -72,6 +76,27 @@ class InstallationPreference : BasePreferenceFragment() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.preferences_installation, rootKey)
findPreference<Preference>(PREFERENCE_INSTALLATION_DEVICE_OWNER)?.apply {
val packageName = context.packageName
val devicePolicyManager =
context.getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
isVisible = devicePolicyManager.isDeviceOwnerApp(packageName)
setOnPreferenceClickListener {
context.showDialog(
context.getString(R.string.pref_clear_device_owner_title),
context.getString(R.string.pref_clear_device_owner_desc),
{ _: DialogInterface, _: Int ->
@Suppress("DEPRECATION")
devicePolicyManager.clearDeviceOwnerApp(packageName)
activity?.recreate()
},
{ dialog: DialogInterface, _: Int -> dialog.dismiss() }
)
true
}
}
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

View File

@@ -439,4 +439,9 @@
<!-- DownloadPreference -->
<string name="pref_download_cache_title">Keep downloads cache</string>
<string name="pref_download_cache_summary">How long to preserve downloads cache (failed, cancelled and completed), in hours</string>
<!-- InstallationPreference -->
<string name="pref_clear_device_owner_title">Clear device owner</string>
<string name="pref_clear_device_owner_summary">Removes Aurora Store as the device owner app</string>
<string name="pref_clear_device_owner_desc">This will revoke session installer\'s permission to silently install app. Proceed with clearing device ownership?</string>
</resources>

View File

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<device-admin />

View File

@@ -41,6 +41,13 @@
app:summary="@string/pref_abandon_session_desc"
app:title="@string/pref_abandon_session" />
<Preference
app:iconSpaceReserved="false"
app:isPreferenceVisible="false"
app:key="PREFERENCE_INSTALLATION_DEVICE_OWNER"
app:summary="@string/pref_clear_device_owner_summary"
app:title="@string/pref_clear_device_owner_title" />
<ListPreference
app:defaultValue="0"
app:iconSpaceReserved="false"