Alexey Subbota
Alexey Subbota

Reputation: 972

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.

Upvotes: 5

Views: 2303

Answers (3)

ilyamuromets
ilyamuromets

Reputation: 413

In additional to the accepted answer, there are one option that solve problem: in Developer options enable Turn on MIUI optimization checkbox.

Upvotes: 0

Sartaj Roshan
Sartaj Roshan

Reputation: 202

You have two option to fix this issue

1 ONE


     <service
            android:name="com.example.android.datasync.SyncService"
            android:exported="true"
            android:process=":sync">
        <intent-filter>
            <action android:name="android.content.SyncAdapter"/>
        </intent-filter>
        <meta-data android:name="android.content.SyncAdapter"
                android:resource="@xml/syncadapter" />
     </service>

Remove android:process=":sync" from android manifest

2 TWO

You have to do following:

  • Open Settings -> Installed app
  • Choose your application
  • Switch on autostart
  • Done

Upvotes: 1

Alexey Subbota
Alexey Subbota

Reputation: 972

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

Upvotes: 9

Related Questions