androidandroid-intentandroid-manifestandroid-screen-pinning

COSU: Cannot find Activity any more after pin and then restart


I'm developing an App that can be Screen Pinned aka Corporate Owned Single Use aka Lock Task Mode.

If I pin it and then:

I get the following error:

[homtom-ht3_pro-0123456789ABCDEF]: E/AndroidRuntime: FATAL EXCEPTION: main
                                                     Process: com.xx.yyy, PID: 7928
                                                     java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xx.yyy/com.xx.yyy.activities.LauncherActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.xx.yyy/com.xx.yy.activities.StartActivity}; have you declared this activity in your AndroidManifest.xml?
                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2534)
                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2614)
                                                         at android.app.ActivityThread.access$800(ActivityThread.java:178)
                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
                                                         at android.os.Handler.dispatchMessage(Handler.java:111)
                                                         at android.os.Looper.loop(Looper.java:194)
                                                         at android.app.ActivityThread.main(ActivityThread.java:5643)
                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                         at java.lang.reflect.Method.invoke(Method.java:372)
                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
                                                      Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.xx.yyy/com.xx.yyy.activities.StartActivity}; have you declared this activity in your AndroidManifest.xml?
                                                         at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1788)
                                                         at android.app.Instrumentation.execStartActivity(Instrumentation.java:1512)
                                                         at android.app.Activity.startActivityForResult(Activity.java:3809)
                                                         at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
                                                         at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
                                                         at android.app.Activity.startActivityForResult(Activity.java:3760)
                                                         at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
                                                         at android.app.Activity.startActivity(Activity.java:4090)
                                                         at android.app.Activity.startActivity(Activity.java:4058)
                                                         at com.xx.yyy.activities.LauncherActivity.onCreate(LauncherActivity.java:16)
                                                         at android.app.Activity.performCreate(Activity.java:6099)
                                                         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2481)
                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2614) 
                                                         at android.app.ActivityThread.access$800(ActivityThread.java:178) 
                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470) 
                                                         at android.os.Handler.dispatchMessage(Handler.java:111) 
                                                         at android.os.Looper.loop(Looper.java:194) 
                                                         at android.app.ActivityThread.main(ActivityThread.java:5643) 
                                                         at java.lang.reflect.Method.invoke(Native Method) 
                                                         at java.lang.reflect.Method.invoke(Method.java:372) 
                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) 
                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 

This is my Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xx.yyy">



    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <receiver
            android:name=".receivers.DeviceAdminReceiver"
            android:description="@string/app_name"
            android:label="@string/app_name"
            android:permission="android.permission.BIND_DEVICE_ADMIN">
            <meta-data
                android:name="android.app.device_admin"
                android:resource="@xml/device_admin_receiver" />

            <intent-filter>
                <action android:name="android.intent.action.DEVICE_ADMIN_ENABLED" />
                <action android:name="android.intent.action.PROFILE_PROVISIONING_COMPLETE" />
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

        <activity android:name=".activities.LauncherActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".activities.StartActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

    </application>

</manifest>

If I don't ever pin the app I can restart/upgrade&run it many times I want.

The nice thing is that is not even possible to uninstall the app because it has been configured as Device Owner, and so, it cannot be uninstalled unless a factory reset.

I dont understand how is possible that my activity disappears after an app restart. Can be something related to the intent category or action?

If anyone else encountered this behavior can tell me I will submit an issue to the bug report site.

Thanks.

EDIT 18/3

I think maybe this is happening because at a certain point, I kill the home category activity that in my case is the missing StartActivity in question, and it is not restarted even if I restart the app.


Solution

  • Found the solution in my COSU disable pinning implementation, I was doing:

    PackageManager mPackageManager = getApplicationContext().getPackageManager();;
    mPackageManager.setComponentEnabledSetting(
            new ComponentName(getApplicationContext(), StartActivity.class),
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
    

    to disable the pinning on device boot, but this actually disable the specified component.

    The correct implementation would be:

    PackageManager mPackageManager = getApplicationContext().getPackageManager();;
    mPackageManager.setComponentEnabledSetting(
            new ComponentName(getApplicationContext(), StartActivity.class),
            PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
            PackageManager.DONT_KILL_APP);