Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeviceAdminReceiver.onProfileProvisioningComplete() not getting called on when managed profile is created #196

Open
mddanishansari opened this issue Jan 11, 2024 · 1 comment

Comments

@mddanishansari
Copy link

This issue is not related to android-testdpc itself but related to DeviceAdminReceiver class.

I have done exactly the same things in my app as in testdpc app to create a work profile but as the title says DeviceAdminReceiver.onProfileProvisioningComplete() is never getting called.

This issue is even acknowledged in android-testdpc source code but given some issue link which I don't know how to open because it is not a valid link. I also tried opening https://issuetracker.google.com/issues/177617306 but for some reason I don't have access to view that issue.

I want to understand if this is a know issue, what's the workaround or some alternative?

@oianmol
Copy link

oianmol commented Apr 25, 2024

in this case we need to create a separate activity which will be started by the OS, and we can execute the post provision task there itself.

       <activity
            android:name=".ui.CompletionActivity"
            android:directBootAware="true"
            android:excludeFromRecents="true"
            android:exported="true"
            android:permission="android.permission.BIND_DEVICE_ADMIN">
            <intent-filter>
                <action android:name="android.app.action.PROVISIONING_SUCCESSFUL" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

well something like this, I just discovered it, maybe not 100% correct but worth a try!

class CompletionActivity : ComponentActivity() {
    private val postProvisionJob: PostProvisionJob by inject()
    private val devicePolicyManager: DevicePolicyManager by inject()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (Util.isProfileOwner(this)) {        // This is true only after DevicePolicyManager.setProfileEnabled().
            showToast(
                this,
                javaClass.getSimpleName() + " should not be started after provisioning."
            )
            return
        }

        if (!postProvisionJob.invoke(intent)) {
            return
        }

        getPostProvisioningLaunchIntent(intent, this, devicePolicyManager)?.let { launchIntent ->
            startActivity(launchIntent)
        } ?: run {
            showToast(
                this,
                "CompletionActivity.onProvisioningComplete() invoked, but ownership " + "not assigned"
            )
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants