Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sync Adapter not started on Xiaomi

I've written a sync adapter in Xamarin but there is a problem under Xiaomi MiUI.

There are two methods of sync adapter starting : one is "settings->accounts->synchronize" via phone, the other is in the application with the aid of ContentResolver.RequestSync().

First of all, I had to switch on the MiUI AutoStart for my application. Otherwise the security system wrote down error to log.

I/AutoStartManagerService: MIUILOG- Reject service :Intent { act=android.content.SyncAdapter cmp=com.fingrad.dashboard/.AdapterService (has extras) } userId : 0 uid : 10186 E/SyncManager: Bind attempt failed - target: ComponentInfo {com.fingrad.dashboard/com.fingrad.dashboard.AdapterService}

Nevertheless, the first method doesn’t work unless the application process is been already in the phone memory. The second method doesn’t work if the SyncAdapterService has not empty the Process attribute. See the example below.

[Service(Name = "com.fingrad.dashboard.SyncAdapterService"  
, Exported = true, Process = ":sync")] 
[IntentFilter(new[] { "android.content.SyncAdapter" })] 
[MetaData("android.content.SyncAdapter", Resource = "@xml/syncadapter")] 
class SyncAdapterService : Service

In other words, adapter doesn't work if any of conditions is true. 1) Adapter service has Process attribute 2) There is no application instance in the phone memory.

It's obvious that the source of problem is MiUI security. MiUI starting sync adapter, starts another process which doesn't have autostart permission. I've tried to set “Process="application default process name", but it hasn’t helped.

UPDATE P.S Time passed but problem remains. Redmi Note 4, MIUI 9.5, Android 7 and Redmi Note 3, MIUI 9.5, Android 6.

like image 686
Alexey Subbota Avatar asked May 12 '17 10:05

Alexey Subbota


1 Answers

I found out how to force MIUI start Sync Adapter. You have to do following:

  1. Open Settings -> Installed app
  2. Choose your application
  3. Switch on autostart
  4. Switch off any battery saver restrictions

enter image description here

like image 106
Alexey Subbota Avatar answered Sep 19 '22 16:09

Alexey Subbota