Android Custom Launcher startActivity () blocks intent BOOT_COMPLETED

I am currently working on a custom ROM (based on CyanogenMod 11.0), the purpose of which is to implement a custom β€œkiosk mode”. For this, I have three components in one application (with system privileges): a service that processes changes in the status / navigation panel and disconnects the power key. A receiver that only starts the service after receiving a BOOT_COMPLETED signal. HomeIntentWrapper acts as a launcher and launches only one user view.

The problem I'm currently facing is that the startActivity(...) HomeIntentWrapper in HomeIntentWrapper somehow blocks the boot of the system further, and the BOOT_COMPLETED intent BOOT_COMPLETED never sent.

I confirmed this with the adb shell dumpsys activity , which tells me:

 mStartedUsers: User #0: mState=BOOTING 

It also does not show the BOOT_COMPLETED broadcast ever sent.

Now, if the user clicks the Home button, the intent is BOOT_COMPLETED , and mState switches to RUNNING .

If I do not start the activity in HomeIntentWrapper , the target is sent. What am I doing wrong here?

AndroidManifest.xml:

 <manifest coreApp="true"> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <application android:allowBackup="true" android:persistent="true" > <service android:name="Service" android:process=":service" > </intent-filter> </service> <receiver android:name="Receiver" android:process=":receiver" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> <activity android:name="HomeIntentWrapper" android:process=":launcher" > <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> 

Recipient:

 public class Receiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { context.startService(new Intent(context, Service.class)); } } 

HomeIntentWrapper:

 public class HomeIntentWrapper extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); startApp(); } @Override protected void onResume() { super.onResume(); startApp(); } private void startApp() { SharedPreferences sharedPrefs = getSharedPreferences(getString(R.string.settings_file), Context.MODE_MULTI_PROCESS); String customAppIntentString = sharedPrefs.getString(getString(R.string.settings_custom_intent), ""); if(customAppIntentString.equals("") == false) { try { Intent intent = Intent.getIntent(customAppIntentString); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } catch(java.net.URISyntaxException e) { // Intentionally } } } } 
+5
source share
1 answer

Root cause: finishBooting () is not called because Home Activity is not on top of the stack.

http://androidxref.com/4.4.4_r1/xref/frameworks/base/services/java/com/android/server/am/ActivityStackSupervisor.java

Line: 1811 Line: 1883-1886 Line: 1934-1940

Decision:

Do not cause activity to start until Boot_Completed is received.

+3
source

Source: https://habr.com/ru/post/1202751/


All Articles