Service that runs only at first boot

1,626 views
Skip to first unread message

Sameer Khan

unread,
Jul 5, 2011, 2:24:45 AM7/5/11
to android-platform
Hi,

I am trying to write a service that would be triggered the first time
a phone is booted and is disabled forever thereafter which means it
should not kick up even after factory resets. Any ideas if this is
possible in Android?

Regards,
Sameer

Looong

unread,
Jul 5, 2011, 5:46:30 AM7/5/11
to android-...@googlegroups.com
Hi Sameer,
You can add a broadcast receiver to receive ON_BOOT_COMPLETE, and use a variable to mark whether this is the first boot after flash image, this variable value can be saved in a file which should be not cleared even if factory reset. FYI.


--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To post to this group, send email to android-...@googlegroups.com.
To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.


Christopher Tate

unread,
Jul 5, 2011, 7:56:51 PM7/5/11
to android-...@googlegroups.com

You cannot do this. A factory reset does exactly that -- it returns the device to its initial fresh-from-the-factory state. No software on the device can distinguish between the first setup and subsequent post-reset setups.

Why do you need to do this? If your initial boot handler does not run after a factory reset, then the new phone execution sequence will not be the same as when the device is set up after being given or resold to a new owner.

--
christopher tate
android framework engineer

AppCoder

unread,
Jul 7, 2011, 5:55:12 PM7/7/11
to android-platform


On Jul 5, 4:56 pm, Christopher Tate <ct...@google.com> wrote:
> On Jul 4, 2011 11:24 PM, "Sameer Khan" <sameerkha...@gmail.com> wrote:
>
>
>
> > I am trying to write a service that would be triggered the first time
> > a phone is booted and is disabled forever thereafter which means it
> > should not kick up even after factory resets. Any ideas if this is
> > possible in Android?
>
> You cannot do this. ..........................................................................

You can, you just need to store/query your "has my one time code
run key" someplace other than the phone.

Christopher Tate

unread,
Jul 7, 2011, 6:00:42 PM7/7/11
to android-...@googlegroups.com

... but then something on the phone has to run on first post-wipe boot
in order to query whatever location that is to decide whether to run!
Yes, you can use an off-device data store to decide whether to do some
sort of heavy once-ever processing [though again, I don't know why you
would do that given that it interferes with the owners' ability to
donate / resell / gift the phone], but *on-device* you're still doing
the same thing: using a service that does at least *some* minimal
amount of work at boot after each time the device has been factory
reset.

Sameer Khan

unread,
Jul 8, 2011, 10:41:36 AM7/8/11
to android-platform
Thanks guys!

We needed this info because we want to maintain a count of our devices
in the field (and avoid sending this info on a factory reset). This
req. could be considered in the future releases of Android wherein a
region of memory persists after factory resets. Maybe this region
could store the no. of factory resets, unlocked count, some OEM data,
etc and accessible only to an OEM.

-Sameer Khan

On Jul 8, 3:00 am, Christopher Tate <ct...@google.com> wrote:

Name Less, the Jedi

unread,
Jul 8, 2011, 10:52:59 AM7/8/11
to android-...@googlegroups.com


2011/7/8 Sameer Khan <sameer...@gmail.com>

Thanks guys!

We needed this info because we want to maintain a count of our devices
in the field (and avoid sending this info on a factory reset). This
req. could be considered in the future releases of Android wherein a
region of memory persists after factory resets. Maybe this region
could store the no. of factory resets, unlocked count, some OEM data,
etc and accessible only to an OEM.


I think that better way would be to allow this service to run on each and every factory reset and send Device ID along other info. On the DB side you could just drop records having device id that is already in the database (or you can keep count of factory resets =o))

I would rather want factory reset to clean all and everything. Really there is no reason to leave some potentially dangerous areas (think malware or something like this).


--
Name Less, the Jedi
Just a friendly Jedi Knight

AppCoder

unread,
Jul 8, 2011, 12:32:22 PM7/8/11
to android-platform


On Jul 7, 3:00 pm, Christopher Tate <ct...@google.com> wrote:
> On Thu, Jul 7, 2011 at 2:55 PM, AppCoder <dan.schm...@gmail.com> wrote:
> > On Jul 5, 4:56 pm, Christopher Tate <ct...@google.com> wrote:
> >> On Jul 4, 2011 11:24 PM, "Sameer Khan" <sameerkha...@gmail.com> wrote:
>
> >> > I am trying to write a service that would be triggered the first time
> >> > a phone is booted and is disabled forever thereafter which means it
> >> > should not kick up even after factory resets. Any ideas if this is
> >> > possible in Android?
>
> >> You cannot do this. ..........................................................................
>
> > You can, you just need to store/query your "has my one time code
> > run key" someplace other than the phone.
>
> ... but then something on the phone has to run on first post-wipe boot
> in order to query whatever location that is to decide whether to run!

Yes, but that doesn't have to be the service he doesn't want to run,
so he can do what he asked for, run a service only once on the phone.
It takes a support service that checks off phone to see if it should
run
his code, but it can be done even if you didn't see how or why he
would
want to.

Dianne Hackborn

unread,
Jul 8, 2011, 1:56:35 PM7/8/11
to android-...@googlegroups.com
There will not be a future version of the platform that does this.  If anything, potentially identifying information will be even more locked down.  The point of a factory reset is to put the device into its out-of-box state, cleanly wiped, so it can be safely given to someone else.  This isn't going to change.

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To post to this group, send email to android-...@googlegroups.com.
To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.




--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Sameer Khan

unread,
Oct 5, 2012, 8:19:27 AM10/5/12
to android-...@googlegroups.com
Just wanted to share with the group...

We achieved it by creating an NV item which would be set and reset however needed but would persist over factory resets. Similar to the way IMEI, Serial numbers, etc. that are set into a device (ofcourse these are during production time) but they are not erased over factory resets.

-Sameer Khan
Reply all
Reply to author
Forward
0 new messages