rigelhope / omnidroid

Automatically exported from code.google.com/p/omnidroid
Apache License 2.0
0 stars 0 forks source link

Confirm that EventMonitoringService is running on Android phone startup #84

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a phone ringing ringing rule and make sure it is enabled.
2. Turn the phone off.
3. Turn the phone on again.
4. Call the android phone. (Make sure that omnidroid activity was never started 
since the phone was booted.)

What is the expected output? What do you see instead?
The phone ringing rule should be triggered.

Original issue reported on code.google.com by renc...@gmail.com on 17 Jun 2010 at 6:03

GoogleCodeExporter commented 8 years ago
Currently, there are 2 places that starts EventMonitoringService:

1. Starter.onReceive() through android.intent.action.BOOT_COMPLETED
2. ActivityMain.onCreate()

I have gathered logs where the emulator was set to automatically launch the 
main activity when the phone boots, and it looks like there are cases when 
BOOT_COMPLETED was not able to reach the Starter object (see log2.txt) and 
cases when it does (see log3.txt, and notice that EventMonitoringService was 
started twice here, because of BOOT_COMPLETED and ActivityMain)

I still have to check the case where the main activity was never started since 
the phone boot and if there will be problems.

Original comment by renc...@gmail.com on 17 Jun 2010 at 6:13

Attachments:

GoogleCodeExporter commented 8 years ago
From log2.txt:
==============
06-17 16:13:33.591: WARN/ActivityManager(56): Timeout of broadcast 
BroadcastRecord{438e21a8 android.intent.action.BOOT_COMPLETED} - 
receiver=android.os.BinderProxy@438fd600
06-17 16:13:33.591: WARN/ActivityManager(56): Receiver during timeout: 
ResolveInfo{438e1f18 com.android.providers.media.MediaScannerReceiver p=0 o=0 
m=0x108000}
06-17 16:13:33.601: DEBUG/HomeLoaders(99): load applications

06-17 16:13:33.711: DEBUG/HomeLoaders(99): loading user items
06-17 16:13:33.711: DEBUG/HomeLoaders(99):   --> starting workspace loader
06-17 16:13:33.811: DEBUG/HomeLoaders(99):   ----> running workspace loader (1)
06-17 16:13:34.061: INFO/ActivityManager(56): ANR in process: 
android.process.media
06-17 16:13:34.061: INFO/ActivityManager(56): Annotation: Broadcast of Intent { 
act=android.intent.action.BOOT_COMPLETED 
cmp=com.android.providers.media/.MediaScannerReceiver }

It looks like the BOOT_COMPLETE may have timed out?  This could indicate a bug 
with the emulator as opposed to Omnidroid.  It seems like testing for phone 
boot without the main activity may be difficult with the eclipse debugger.  I 
guess you can use the command line debugger?

Original comment by case.and...@gmail.com on 17 Jun 2010 at 9:44

GoogleCodeExporter commented 8 years ago
I have a dev phone.  I can set a rule on my phone and then restart it to see if 
it fires (I'm pretty sure it works, at least most the time).  Let me know if 
that will help.

Original comment by case.and...@gmail.com on 17 Jun 2010 at 9:45

GoogleCodeExporter commented 8 years ago
But there is also a similar log in log3.txt, but this time, the Starter object 
was able to receive it and start EventMonitoringService. I'll try checking out 
the emulator if it works, but I'll finish issue 46 first. I just discovered 
this potential problem while doing issue 46.

06-17 17:33:02.887: WARN/ActivityManager(56): Timeout of broadcast 
BroadcastRecord{438ce180 android.intent.action.BOOT_COMPLETED} - 
receiver=android.os.BinderProxy@439380b8
06-17 17:33:02.887: WARN/ActivityManager(56): Receiver during timeout: 
ResolveInfo{438cdf60 com.android.mms.transaction.MmsSystemEventReceiver p=0 o=0 
m=0x108000}
06-17 17:33:03.237: INFO/ActivityManager(56): ANR in process: com.android.mms
06-17 17:33:03.237: INFO/ActivityManager(56): Annotation: Broadcast of Intent { 
act=android.intent.action.BOOT_COMPLETED 
cmp=com.android.mms/.transaction.MmsSystemEventReceiver }
...
06-17 17:33:33.067: INFO/Starter(240): android.intent.action.BOOT_COMPLETED 
received.
06-17 17:33:33.607: INFO/EventMonitoringService(240): Started 
EventMonitoringService.

Original comment by renc...@gmail.com on 17 Jun 2010 at 10:04

GoogleCodeExporter commented 8 years ago
I hope this is just a problem on the emulator as the bug happens almost 60% of 
the time. It also looks like listening to the 
android.intent.action.BOOT_COMPLETED event is the standard way of starting a 
service on boot after doing a search on the internet. What bothers me is the 
code on ActivityMain.onCreate() that starts the EventMonitoringService, was it 
found out before that BOOT_COMPLETED does not always work, and patched it up 
with the code on onCreate()?

Original comment by renc...@gmail.com on 19 Jun 2010 at 3:49

GoogleCodeExporter commented 8 years ago
I am not sure if this is significant, but the difference I can see with the 
logs are:

log2 has (that log3 doesn't):
06-17 16:13:29.320: DEBUG/PackageManager(56):   Receivers: 
edu.nyu.cs.omnidroid.app.controller.bkgservice.Starter 
edu.nyu.cs.omnidroid.app.controller.bkgservice.BCReceiver

log3 has (that log2 doesn't):
06-17 17:33:30.727: INFO/ActivityManager(56): Start proc 
edu.nyu.cs.omnidroid.app for broadcast 
edu.nyu.cs.omnidroid.app/.controller.bkgservice.Starter: pid=240 uid=10022 
gids={1006, 3003, 1007}

Original comment by renc...@gmail.com on 20 Jun 2010 at 2:24

GoogleCodeExporter commented 8 years ago
What I can see so far is that the Android (or maybe just the API level 4 
Emulator) does not always send the BOOT_COMPLETED to the Receiver objects. And 
it also looks like Android does not provide other alternatives to start a 
service on device boot up...

Original comment by renc...@gmail.com on 20 Jun 2010 at 2:27

GoogleCodeExporter commented 8 years ago
Until this is substantiated I'm marking as invalid.  I think we can assume that 
Android sends this Broadcast.  If not it's probably an Android bug and not ours 
to deal with (until substantiated on hardware.)  If you would like a HW device 
to test this and/or other issues, feel free to stop by my office (WWH1023) and 
I'll hand one over.  Thanks for all the work! =)

Original comment by case.and...@gmail.com on 3 Jul 2010 at 6:44

GoogleCodeExporter commented 8 years ago
In that case, why is ActivityMain.onCreate() starting up EventMonitoring 
Service? Is it okay if we start it multiple times (1 on boot and 2 on 
ActivityMain)? You can even start it more than twice if you keep on doing click 
omnidroid app then back button repeatedly.

Original comment by renc...@gmail.com on 3 Jul 2010 at 2:22

GoogleCodeExporter commented 8 years ago
Sorry, I forgot about it being in ActivityMain.  Reopening.

I just did the following for testing of ON_BOOT_COMPLETED:

1) Saved a rule for "Time is -> Action -> Omnidroid -> Notify" so it will send 
a notification every minute.
2) Powered device off.  Powered device on.  Waited till time tick occurred to 
make sure notification was sent (it was).  Cleared notifications.  Repeated 
step 2 five times with success each time.

So I think ON_BOOT_COMPLETED probably is reliable and we just need to remove 
the EventMonitoring Service from ActivityMain.onCreate().

Original comment by case.and...@gmail.com on 3 Jul 2010 at 3:45

GoogleCodeExporter commented 8 years ago
If this is a problem for testing, it seems like Issue 67 will provide a way to 
make sure it's been started.

Original comment by case.and...@gmail.com on 3 Jul 2010 at 3:47

GoogleCodeExporter commented 8 years ago

Original comment by case.and...@gmail.com on 6 Jul 2010 at 2:21

GoogleCodeExporter commented 8 years ago
I guess we could just close this as issue 67(r805) just removed the 
EventMonitoringService startup at ActivityMain.

Original comment by renc...@gmail.com on 13 Jul 2010 at 4:58

GoogleCodeExporter commented 8 years ago
Agreed.  Closing.  If you notice that this is still a valid concern please 
re-open.

Original comment by case.and...@gmail.com on 13 Jul 2010 at 5:12

GoogleCodeExporter commented 8 years ago
Ren I think we needed this code for example because without it the service 
isn't started until the phone is rebooted.  But we want the service to start 
running immediately after install/upgrade.  With this code it was starting when 
the activity was started.

Original comment by case.and...@gmail.com on 14 Jul 2010 at 12:57

GoogleCodeExporter commented 8 years ago
You're right, there are still cases not covered, but I think doing it on 
ActivityMain.onCreate doesn't seem right... Or if we are doing it there, then 
we should  at least check if the service is already running...

Original comment by renc...@gmail.com on 14 Jul 2010 at 1:34

GoogleCodeExporter commented 8 years ago
this is why we have code reviews drew

check if it's not already running and check if omnidroid hasn't been disabled.

Original comment by sv767%ny...@gtempaccount.com on 14 Jul 2010 at 2:17

GoogleCodeExporter commented 8 years ago
We also need to check that the preference is set for it to be on as well.

Original comment by case.and...@gmail.com on 14 Jul 2010 at 2:25

GoogleCodeExporter commented 8 years ago
Something like this slapped into onCreate() for ActivityMain would probably do 
the trick:

// Make sure the background monitoring service is started the first start
SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this);
boolean firstRun = p.getBoolean(PREFERENCE_FIRST_RUN, true);
p.edit().putBoolean(PREFERENCE_FIRST_RUN, false).commit();
if (firstRun) {
  EventMonitoringService.startService(this);
}

Original comment by case.and...@gmail.com on 14 Jul 2010 at 2:32

GoogleCodeExporter commented 8 years ago
and where is this preference defined?

Original comment by salomeju...@yahoo.com on 14 Jul 2010 at 2:52

GoogleCodeExporter commented 8 years ago
Do you mean PREFERENCE_FIRST_RUN?  It just needs to be a unique string.  We 
don't need to define it anywhere else as nothing else will use this.  It 
defaults to true (see SharedPreferences.getBoolean()) on the first run (and 
will start Omnidroid, which should start on boot then-after), but after the 
first run, it will always be false.  So the final code would probably be closer 
to:

public static final String PREFERENCE_FIRST_RUN="firstrun"
...
// Make sure the background monitoring service is started the first start
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean firstRun = prefs.getBoolean(PREFERENCE_FIRST_RUN, true);
prefs.edit().putBoolean(PREFERENCE_FIRST_RUN, false).commit();
if (firstRun) {
  EventMonitoringService.startService(this);
}

Original comment by case.and...@gmail.com on 14 Jul 2010 at 3:08

GoogleCodeExporter commented 8 years ago

Original comment by case.and...@gmail.com on 14 Jul 2010 at 8:53

GoogleCodeExporter commented 8 years ago
Code I posted only takes the first run after install into account.  I also need 
to address on upgrade/re-install.

Original comment by case.and...@gmail.com on 15 Jul 2010 at 1:28

GoogleCodeExporter commented 8 years ago
why can't we start it from manifest file?

Original comment by sv767%ny...@gtempaccount.com on 15 Jul 2010 at 2:30

GoogleCodeExporter commented 8 years ago
I don't think you can do that in android.  If you know otherwise, please share.

Original comment by case.and...@gmail.com on 15 Jul 2010 at 3:02

GoogleCodeExporter commented 8 years ago
Awaiting code review: http://codereview.appspot.com/1848042/show

Original comment by case.and...@gmail.com on 16 Jul 2010 at 3:02

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r813.

Original comment by case.and...@gmail.com on 16 Jul 2010 at 12:56