Android Question Auto start app after self update

AscySoft

Active Member
Licensed User
Hello. Let me be direct.
I put the following code in manifest editor
B4X:
AddReceiverText(AutoStartApp, <intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
 </intent-filter>)
My "AutoStartApp" service is as simple as this
B4X:
#Region  Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
End Sub
Sub Service_Create
    Log("..........APP SELF UPDATED OK, RESTARTING...........")
    StartActivity(Main)
End Sub
Sub Service_Start (StartingIntent As Intent)
End Sub
Sub Service_Destroy
End Sub
That's it
Now, i test this on two phones (Note 3- Android 5, and another samsung A 2017 with Android 8)
In neither one of them the app will NOT start after self update (downloaded from server, installing using FileProvider all OK) but it refuse to restart after update.
Solution?
 

AscySoft

Active Member
Licensed User
Unfiltered logs give me no clue... My app package name is ascysoft.ascy
Action: android.intent.action.PACKAGE_REPLACED
Shame on you for calling the hidden API queryBroadcastReceivers(). Shame!

PkgInstallationReceiver, onReceive(), begin, action: android.intent.action.PACKAGE_REPLACED
onReceive() - Intent { act=android.intent.action.PACKAGE_REPLACED dat=package:ascysoft.ascy flg=0x4000010 (has extras) }
packageReplaced() - packageName: ascysoft.ascy oldUid: 10188 newUid:10188
received SARDEVICE_CP, callAction = on deviceID = 3 cableConnection = 0 option = NONE
filterNetworkStateForUid() uid: 10022 networkInfo: [type: MOBILE[LTE] - MOBILE, state: CONNECTED/CONNECTED, reason: connected, extra: live.vodafone.com, failover: false, available: true, roaming: false, metered: true]
enableDeviceForBackOff deviceID:1 deviceValue:1 mIsValidIntentForWifi:false
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to android/com.kddi.android.CpaNotiReceiver
For resource 0x7f080160, entry index(352) is beyond type entryCount(15)
Failure getting entry for 0x7f080160 (t=7 e=352) (error -75)
For resource 0x7f080160, entry index(352) is beyond type entryCount(15)
Failure getting entry for 0x7f080160 (t=7 e=352) (error -75)
KPU : put [com.samsung.android.dqagent] : 7472 K
Killing 16267:com.samsung.android.dqagent/1000 (adj 906): DHA:empty #17
Invalid searchable metadata for com.samsung.android.themestore/.activity.bixby.SearchActivityForBixby: Search label must be a resource reference.
For resource 0x7f0806ab, entry index(1707) is beyond type entryCount(15)
Failure getting entry for 0x7f0806ab (t=7 e=1707) (error -75)
For resource 0x7f0806ab, entry index(1707) is beyond type entryCount(15)
Failure getting entry for 0x7f0806ab (t=7 e=1707) (error -75)
filterNetworkStateForUid() uid: 10022 networkInfo: [type: MOBILE[LTE] - MOBILE, state: CONNECTED/CONNECTED, reason: connected, extra: live.vodafone.com, failover: false, available: true, roaming: false, metered: true]
onReceive()...
packageInstalledForSBAExternalStorage ascysoft.ascy
filterNetworkStateForUid() uid: 10022 networkInfo: [type: MOBILE[LTE] - MOBILE, state: CONNECTED/CONNECTED, reason: connected, extra: live.vodafone.com, failover: false, available: true, roaming: false, metered: true]
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to com.android.vending/com.google.android.finsky.packagemanager.impl.PackageMonitorReceiverImpl$RegisteredReceiver
Cancel Alarm calling from uid:10022 pid :3959 / op:pendingIntent{435d77f: PendingIntentRecord{4bc3b85 com.google.android.gms broadcastIntent}}
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to com.android.vending/com.google.android.finsky.instantapps.appmanagement.InstantAppRemoveMonitor
[SupervisedAccountIntentOperation] onHandleIntent(): android.intent.action.PACKAGE_ADDED
[Sync,SyncIntentOperation] Handling the intent: Intent { act=android.intent.action.PACKAGE_ADDED dat=package:ascysoft.ascy flg=0x4000010 cmp=com.google.android.gms/.chimera.GmsIntentOperationService (has extras) }.
action : android.intent.action.PACKAGE_REMOVED
replacing. ignore
mReceiver.onReceive :CALL_ACTION_CHANGED : SARDEVICE_CP, callAction = on deviceID = 3
SAR_GRIP
SAR_PROX
activateProx :: mProxEnabled true, mRCVEnabled false
could not check pending caller
getExternalStorageMountMode : 1
getExternalStorageMountMode : 3
getExternalStorageMountMode : final mountMode=1, uid : 10110, packageName : com.facebook.appmanager
isApplicationExternalStorageWhitelisted:com.facebook.appmanager user:0
isApplicationExternalStorageWhitelisted: DO is not enabled on user 0. Allowed.
package com.facebook.appmanager, user - 0 is SDcard whitelisted
isApplicationExternalStorageBlacklisted:com.facebook.appmanager user:0
isApplicationExternalStorageBlacklisted: DO is not enabled on user 0. Allowed.
isWhitelistProcess - Process is Whitelisted
SELinux selinux_android_compute_policy_index : Policy Index[2], Con:u:r:zygote:s0 RAM:SEPF_SM-A520F_8.0.0_0018, [-1 -1 -1 -1 0 1]
SELinux: seapp_context_lookup: seinfo=untrusted, level=s0:c512,c768, pkgname=com.facebook.appmanager
Added TimaKeyStore provider
Start proc 16876:com.facebook.appmanager/u0a110 for broadcast com.facebook.appmanager/com.facebook.oxygen.appmanager.common.packages.PackageEventReceiver
Broadcast completed: result=0
DSS on for com.facebook.appmanager and scale is 1.0
setEnabledSetting : userId = 0 packageName = com.google.android.gms cmp = com.google.android.gms.people.pub.PeopleProfileActionGatewayActivity newState = 1 callingPackage = 10022/com.google.android.gms
setInexact Intent (T:2/F:0/AC:false) 20190924T231735 - CU:10022/CP:3959
no shared libraies, dex_files: 1
IndexChimeraService.getServiceInterface callingPackage=com.google.android.gms componentName=AppsCorpus serviceId=36
ACRA init; reportURL: https://www.facebook.com/mobile/generic_android_crash_logs/659091980805095
ACRA is enabled for process com.facebook.appmanager, initializing...
Starting ANR detector for process: com.facebook.appmanager
ANRDetector= false
init start
Preparing SO source: com.facebook.soloader.e[root = lib flags = 2]
Preparing SO source: com.facebook.soloader.e[root = lib flags = 2]
Preparing SO source: com.facebook.soloader.d[root = lib-main flags = 1]
locked dso store /data/user/0/com.facebook.appmanager/lib-main
dso store is up-to-date: /data/user/0/com.facebook.appmanager/lib-main
releasing dso store lock for /data/user/0/com.facebook.appmanager/lib-main
init finish: 3 SO sources prepared
Invalid searchable metadata for com.samsung.android.themestore/.activity.bixby.SearchActivityForBixby: Search label must be a resource reference.
onPackageModified ascysoft.ascy
- hadPrintService false
- hasPrintService false
[user: 0] bindLocked()
getExternalStorageMountMode : 1
getExternalStorageMountMode : 3
getExternalStorageMountMode : final mountMode=1, uid : 10142, packageName : com.android.printspooler
isApplicationExternalStorageWhitelisted:com.android.printspooler user:0
isApplicationExternalStorageWhitelisted: DO is not enabled on user 0. Allowed.
package com.android.printspooler, user - 0 is SDcard whitelisted
isApplicationExternalStorageBlacklisted:com.android.printspooler user:0
isApplicationExternalStorageBlacklisted: DO is not enabled on user 0. Allowed.
No Network Security Config specified, using platform default
isWhitelistProcess - Process is Whitelisted
SELinux selinux_android_compute_policy_index : Policy Index[2], Con:u:r:zygote:s0 RAM:SEPF_SM-A520F_8.0.0_0018, [-1 -1 -1 -1 0 1]
Start proc 16896:com.android.printspooler/u0a142 for service com.android.printspooler/.model.PrintSpoolerService
bindLocked waiting. remainingMillis: 8000
SELinux: seapp_context_lookup: seinfo=release, level=s0:c512,c768, pkgname=com.android.printspooler
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to com.google.android.gms/.games.chimera.GamesSystemBroadcastReceiverProxy
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to com.google.android.gms/.chimera.GmsIntentOperationService$PersistentTrustedReceiver
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to com.google.android.googlequicksearchbox/com.google.android.apps.gsa.googlequicksearchbox.GelStubAppWatcher
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to com.microsoft.office.excel/com.microsoft.office.notification.SystemBroadcastReceiver
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to com.microsoft.office.excel/com.microsoft.android.crosssell.PackageStateReceiver
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to com.microsoft.office.powerpoint/com.microsoft.office.notification.SystemBroadcastReceiver
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to com.microsoft.office.powerpoint/com.microsoft.android.crosssell.PackageStateReceiver
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to com.microsoft.office.word/com.microsoft.office.notification.SystemBroadcastReceiver
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to com.microsoft.office.word/com.microsoft.android.crosssell.PackageStateReceiver
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to com.samsung.android.SettingsReceiver/.networkconnect.NetworkConnectReceiver

........

onDestroy
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REPLACED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to com.google.android.apps.photos/.account.full.FetchAccountPropertiesAppUpgradeBroadcastReceiver
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REPLACED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to com.google.android.apps.photos/.account.full.SyncAccountsForLoginBroadcastReceiver
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REPLACED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to com.google.android.apps.photos/.experiments.phenotype.full.PhenotypeAppUpgradeBroadcastReceiver
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REPLACED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to com.google.android.apps.photos/.notificationchannels.AppUpdateBroadcastReceiver
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REPLACED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to com.google.android.gms/.gass.chimera.PackageChangeBroadcastReceiver
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REPLACED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to com.google.android.gms/.chimera.GmsIntentOperationService$PersistentTrustedReceiver
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REPLACED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to com.google.android.googlequicksearchbox/com.google.android.apps.gsa.googlequicksearchbox.GelStubAppWatcher

Or it does appear thar Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REPLACED....
So app recieved intent for PACKAGE_REPLACED (I did tryed with both of them in manifest, first "MY_PACKAGE_REPLACED" then "PACKAGE_REPLACED")
But "not allowed"?? Why?
 

AscySoft

Active Member
Licensed User
keep MY_PACKAGE_REPLACED
Checked
Make sure to run the app before it is being replaced
Checked
and don't kill it
Checked, I show you the update/install sub
B4X:
Private Sub SendInstallIntent
    'Dim ApkName As String = "name.apk"' apk name here
    File.copy(ApkLocation, ApkName, Starter.Provider.SharedFolder, ApkName)'location of apk
    Dim i As Intent
    If phone.SdkVersion >= 24 Then
        i.Initialize("android.intent.action.INSTALL_PACKAGE", Starter.Provider.GetFileUri(ApkName))
        i.Flags = Bit.Or(i.Flags, 1) 'FLAG_GRANT_READ_URI_PERMISSION
    Else
        i.Initialize(i.ACTION_VIEW, "file://" & File.Combine(Starter.Provider.SharedFolder, ApkName))
        i.SetType("application/vnd.android.package-archive")
    End If
    StartActivity(i)
End Sub
Son, no kill...but no auto startup after that. The app updates correctly, but must be manually restarted.
 

udg

Expert
Licensed User
Did you check your code against the one in my old lib AppUpdate?
AFAIK, it still works nice with recent Android versions.
 
Last edited:

udg

Expert
Licensed User
Exactly. There are subs to check for an update, to download new apk and to ask the user to update; if the user allows for the update than a service starts the new apk.
Sorry, I'm not at my dev PC right now so I can't be more detailed or show useful code. But please just download the lib source and take the bits you're interested in out of it.
 

AscySoft

Active Member
Licensed User
I also have everithing in place and working, downloading, installing new app, but must be a line of code/perhaps in manifest editor/or something else that is not right. For now as I have no more time eighter I will leav it as it is, I will investigate further tomorrow. I am only intrested in "restart after REPLACE" app. Maybe @udg will bring more info about that.

PS: last relevant log display exactly this

Action: android.intent.action.PACKAGE_REPLACED
The DATA: package:ascysoft.ascy
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REPLACED dat=package:ascysoft.ascy flg=0x4000010 (has extras) } to com.sec.imsservice/com.sec.internal.tapi.service.receiver.PackageEventReceiver
 

udg

Expert
Licensed User
In post #5 above Erel suggests to remove PACKAGE_REPLACE and keep MY_PACKAGE_REPLACED.
In your post #10 we still can read PACKAGE_REPLACE
Is it the old error message?
 

Erel

Administrator
Staff member
Licensed User
Just made a simple test and it works fine.

It is not so simple to test it and see that it works. You need to use USB debug mode and the best way is to install the APK without running it:

This can be done with ADB:
c:\android-sdk-windows9\platform-tools\adb install -r 1.apk

Tested on Android 10. Note that you cannot start activities from the background on Android 10.
 

Attachments

udg

Expert
Licensed User
Hi Erel,
when you say "Note that you cannot start activities from the background on Android 10" does it mean that the following code won't execute any longer?
It is what's currently in the service used by AppUpdating (BTW, there's not yet a "Service.StopAutomaticForeground" instruction due to its age..I'd update the code one of these days).

B4X:
Sub Service_Start (StartingIntent As Intent)
'... other code
If StartingIntent.Action = "android.intent.action.MY_PACKAGE_REPLACED" Then
       If svcVerbose Then Log($"${TAB}Intent MY_PACKAGE_REPLACED received!"$)
       pkg = GetPackageName
       If svcVerbose Then Log($"${TAB}package: ${pkg}"$)
       MyAppReload
   End If
End Sub

Sub GetPackageName As String
   Dim r As Reflector
   Return r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
End Sub

Sub MyAppReload
   If svcVerbose Then Log("-- AppUpdating.NewInst2: processing MyAppReload")
   If IsPaused("main") Then
       StartActivity("main")
   End If
   'Dim In As Intent
   'StartActivity(pkg&"/.main")
End Sub
From your code it seems that what's now needed is simply a service to declare in Manifest and a StopAutomaticForeground instruction in its Start. Then the OS is supposed to do its magic.
If that's correct, would you like to explain better the sequence of actions? I mean, would it be MyService-Starter-Main or Starter-MyService-Main? Globals and Initializing code in Starter would be available at Main start?

Thank you
 

Erel

Administrator
Staff member
Licensed User
  • Like
Reactions: udg

AscySoft

Active Member
Licensed User
Just made a simple test and it works fine.
In my case it is not working,
I have Android 8, compiled in release mode, move "1.apk" resulting file (from Objects) to folder with "adb"
In command.com I did run twice
"adb install -r 1.apk"
nothing happend, just a simple install app was added in my app drower/louncher
I was expecting the app to open itself on the second install-replace adb command...
Unfiltred logs shows
Killing 31525:com.samsung.android.da.daagent/1000 (adj 906): DHA:empty #17
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REPLACED dat=package:b4a.example flg=0x4000010 (has extras) } to com.sec.android.app.samsungapps/com.samsung.android.iap.receiver.IapReceiver
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REPLACED dat=package:b4a.example flg=0x4000010 (has extras) } to com.sec.android.app.sbrowser/.webcontentsprovider.WebContentsProviderReceiver
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REPLACED dat=package:b4a.example flg=0x4000010 (has extras) } to com.sec.android.daemonapp/com.samsung.android.weather.daemon.receiver.ClearDataReceiver
Action: android.intent.action.PACKAGE_REPLACED
The DATA: package:b4a.example
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REPLACED dat=package:b4a.example flg=0x4000010 (has extras) } to com.sec.imsservice/com.sec.internal.tapi.service.receiver.PackageEventReceiver
So? What to do? Should I buy a Note 10 just to try it out? (just kidding)
 

udg

Expert
Licensed User
@udg are you able to test your previouse working library/app on Android 10
Unfortunately no. Sorry.
 
Top