cosu
cosu copied to clipboard
App does not launch on restart, even after pinning (2-step solution)
Issue
cosu_codelab_complete
does not launch on device restart, even after pinning the app.
I've found a 2 step solution. I'm fairly confident about the first step, but the second feels like an awful kudge.
Platform
Target Device
- Model: X96mini (An AndroidTV set-top box) (AOSP-based?)
- Version: 7.1.2
- Kernel Version: 3.14.29
- Build: 20171202.09:30
Developer Platform
- Android Studio 3.1.1
- Build #AI-173.4697961, built on April 3, 2018
- JRE: 1.8.0_152-release-1024-b01 x86_64
- JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
- Mac OS X 10.13.4
Symptom1
Running cosu_lab_complete
generates the following warning in the logs:
04-22 02:06:26.233 4396-4408/system_process W/BroadcastQueue: Permission Denial: receiving Intent { act=android.intent.action.BOOT_COMPLETED flg=0x9000010 (has extras) } to com.google.codelabs.cosu/.DeviceAdminReceiver requires android.permission.RECEIVE_BOOT_COMPLETED due to sender null (uid 1000)
Solution to Symptom1
Modify the file cosu_codelab_complete/app/src/main/AndroidManifest.xml
to include the line
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
NOTE: Probably also need to amend the tutorial, step 8.
Symptom2
After applying the first fix, the app still won't launch. From the logs, it looks like it is trying...
04-22 02:15:37.711 4351-4661/system_process I/ActivityManager: Start proc 5555:com.google.codelabs.cosu/u0a56 for broadcast com.google.codelabs.cosu/.DeviceAdminReceiver
04-22 02:15:40.556 4351-4914/system_process I/ActivityManager: Killing 5555:com.google.codelabs.cosu/u0a56 (adj 902): empty #2
04-22 02:15:47.576 4351-4387/system_process I/ActivityManager: Start proc 5881:com.google.codelabs.cosu/u0a56 for broadcast com.google.codelabs.cosu/.DeviceAdminReceiver
04-22 02:15:48.202 4351-4914/system_process I/ActivityManager: Killing 5881:com.google.codelabs.cosu/u0a56 (adj 902): empty #2
04-22 02:15:48.864 4351-4387/system_process I/ActivityManager: Start proc 5981:com.google.codelabs.cosu/u0a56 for broadcast com.google.codelabs.cosu/.DeviceAdminReceiver
04-22 02:15:55.266 4351-4366/system_process I/ActivityManager: Killing 5981:com.google.codelabs.cosu/u0a56 (adj 902): empty #2
Solution to Symptom2
I added the following code to cosu_codelab_complete/app/src/main/java/com/google/codelabs/cosu/DeviceAdminReceiver.java
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG,"onReceive (" + intent.getAction() + ")");
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Log.i(TAG,"onReceive launch");
Intent activityIntent = new Intent(context, LockedActivity.class);
activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // runtime warning if not set
context.startActivity(activityIntent);
} else {
Log.i(TAG,"onReceive other");
super.onReceive(context, intent);
}
}
And now it works!
04-22 03:07:02.673 4366-4382/system_process I/ActivityManager: Start proc 5587:com.google.codelabs.cosu/u0a56 for broadcast com.google.codelabs.cosu/.DeviceAdminReceiver
04-22 03:07:02.674 5587-5587/com.google.codelabs.cosu I/art: Late-enabling -Xcheck:jni
04-22 03:07:02.769 5587-5587/com.google.codelabs.cosu W/System: ClassLoader referenced unknown path: /data/app/com.google.codelabs.cosu-2/lib/arm
04-22 03:07:02.832 5587-5587/com.google.codelabs.cosu I/DeviceAdminReceiver: onReceive (android.intent.action.BOOT_COMPLETED)
onReceive launch
04-22 03:07:02.838 4366-4382/system_process I/ActivityManager: START u0 {flg=0x10000000 cmp=com.google.codelabs.cosu/.LockedActivity} from uid 10056 on display 0
04-22 03:07:03.154 4366-4874/system_process I/PackageManager: Adding persistent preferred activity ComponentInfo{com.google.codelabs.cosu/com.google.codelabs.cosu.LockedActivity} for user 0:
Action: "android.intent.action.MAIN"
Category: "android.intent.category.HOME"
Category: "android.intent.category.DEFAULT"
AutoVerify=false
04-22 03:07:03.466 5587-5651/com.google.codelabs.cosu I/OpenGLRenderer: Initialized EGL, version 1.4
04-22 03:07:03.467 5587-5651/com.google.codelabs.cosu D/OpenGLRenderer: Swap behavior 1
04-22 03:07:03.579 4366-4416/system_process I/ActivityManager: Displayed com.google.codelabs.cosu/.LockedActivity: +688ms
04-22 03:07:11.764 5587-5587/com.google.codelabs.cosu I/DeviceAdminReceiver: onReceive (android.app.action.LOCK_TASK_ENTERING)
onReceive other
04-22 03:07:14.371 5587-5587/com.google.codelabs.cosu I/DeviceAdminReceiver: onReceive (android.app.action.NOTIFY_PENDING_SYSTEM_UPDATE)
onReceive other
04-22 03:07:15.402 5587-5587/com.google.codelabs.cosu I/DeviceAdminReceiver: onReceive (android.app.action.NOTIFY_PENDING_SYSTEM_UPDATE)
onReceive other