System setProperty and getProperty

3,978 views
Skip to first unread message

JimmyLi

unread,
Dec 21, 2010, 12:46:07 AM12/21/10
to android-platform
Hi,

In my package, I use System.setProperty to share information with
other modules so as to keep loosely coupled. In my package, the two
apis runs ok; But not ok in other packages, null returned while using
getProperty, in fact the setProperty was surely invoked some time
earlier. So what's the reason? Thanks!

BestRegards
JimmyLi

Raymond.Wen

unread,
Dec 21, 2010, 3:22:00 AM12/21/10
to android-...@googlegroups.com
Unlike native properties, properties set via java code aren't shared across process.

Best Regards,
Raymond Wen

http://rxwen.blogspot.com




--
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.


XC He

unread,
Dec 21, 2010, 3:39:22 AM12/21/10
to android-...@googlegroups.com
what you set in System.setProperty()?
are you sure you can get the right return when you call
System.getProperty() in same package?

or you have to go to system/core/init/property_service.c for
permission registration

2010/12/21 Raymond.Wen <rx.w...@gmail.com>:

Jiangyun Li

unread,
Dec 21, 2010, 3:48:18 AM12/21/10
to android-...@googlegroups.com
Hi,

The value of property I set is only a string. I could get the right return in my package while the property has ever been set. But null returned if other modules try to get this property!

Could you provide details for permission registration? Thanks very much!

BestRegards
JimmyLi

2010/12/21 XC He <schos...@gmail.com>

Raymond.Wen

unread,
Dec 21, 2010, 5:52:52 AM12/21/10
to android-...@googlegroups.com
If you setProperty in one package, it's only available in the process that runs the package. When you call getProperty in another package, which runs in a separate process, the property isn't there. And thus can't be retrieved.

The property system in java is a different thing from the property system in native code. Check this out:
http://rxwen.blogspot.com/2010/01/android-property-system.html


Best Regards,
Raymond Wen

http://rxwen.blogspot.com



Jiangyun Li

unread,
Dec 21, 2010, 6:57:41 AM12/21/10
to android-...@googlegroups.com
Dear Wen,

Thanks, get it!
So if I want to share information with other modules, native property is a good choice. But for my module, actually an apk, could not or not too much easily touch c code to use native property, and I'm reluctant to provide api for other apks, so any suggestions for sharing information between apks? Intent mechanism is a backup solution, any others?

Thanks very much!

BestRegards
JimmyLi

2010/12/21 Raymond.Wen <rx.w...@gmail.com>

Raymond.Wen

unread,
Dec 21, 2010, 7:51:43 AM12/21/10
to android-...@googlegroups.com
Native property isn't part of the public apis, so it's not intended to be used by external applications.
If both apks are owned by you, I think AIDL is a good choice.

Best Regards,
Raymond Wen

http://rxwen.blogspot.com



FrankG

unread,
Dec 21, 2010, 9:40:11 AM12/21/10
to android-platform
Hi Raymond,

I assume that he did no speak about the public API
and what you said is right for System.setProperty ..
but simply not true for andoird.os.SystemProperties which provides
of course the java api for the native property system.

In this respect the nice blog is simply not true. I.e. the Settings-
App
makes intensive use to control the system behaviour via system
properties.

The other question whether is is good to use system properties for
communication inside or between "normal apps", for this is think
intents
or aidl as you suggested is the better way.

This part "The property system in java is a different thing from the
property system in
native code." depends only from the used API ..

Good luck ! Frank


On 21 Dez., 13:51, "Raymond.Wen" <rx.wen...@gmail.com> wrote:
> Native property isn't part of the public apis, so it's not intended to be
> used by external applications.
> If both apks are owned by you, I think
> AIDL<http://developer.android.com/guide/developing/tools/aidl.html>is
> a good choice.
>
> Best Regards,
> Raymond Wen
>
> http://rxwen.blogspot.com
>
>
>
> On Tue, Dec 21, 2010 at 7:57 PM, Jiangyun Li <lijy...@gmail.com> wrote:
> > Dear Wen,
>
> > Thanks, get it!
> > So if I want to share information with other modules, native property is a
> > good choice. But for my module, actually an apk, could not or not too much
> > easily touch c code to use native property, and I'm reluctant to provide api
> > for other apks, so any suggestions for sharing information between apks?
> > Intent mechanism is a backup solution, any others?
>
> > Thanks very much!
>
> > BestRegards
> > JimmyLi
>
> > 2010/12/21 Raymond.Wen <rx.wen...@gmail.com>

Raymond.Wen

unread,
Dec 21, 2010, 7:56:51 PM12/21/10
to android-...@googlegroups.com
Hi Frank,

Thanks for pointing the SystemProperties class out. Andrew also mentioned it in the post.
I haven't figured out how to use it in an external java application. May be through reflection will do. Will try.


Best Regards,
Raymond Wen

http://rxwen.blogspot.com



Jiangyun Li

unread,
Dec 21, 2010, 9:26:28 PM12/21/10
to android-...@googlegroups.com
Hi Frank,

I choose SystemProperties.set/get to do that, but when I try to get property after invoking SystemProperties.set, it returns empty string, not null, why?
I just use this pair of apis in my apk, is there any initialization first?
Thanks!

BestRegards
JimmyLi

2010/12/22 Raymond.Wen <rx.w...@gmail.com>

Jiangyun Li

unread,
Dec 22, 2010, 3:18:05 AM12/22/10
to android-...@googlegroups.com
Hi,

It's ok now, Thanks Frank & Raymond!

BestRegards
JimmyLi

2010/12/22 Jiangyun Li <lij...@gmail.com>

Raymond.Wen

unread,
Dec 22, 2010, 5:37:33 AM12/22/10
to android-...@googlegroups.com
In what way did you manage to invoke these apis? Did you use any hacks?
Personally, I still consider it's not a good way to perform IPC between different apks with property.
1. The number of slots in property system is limited, if I recall correctly, around 250.
2. Once occupied, a slot can't be freed.
3. The api isn't intended for external usage.
So, if an application makes heavy use of properties, slots will be soon be exhausted. And system service may fail due to this. Another risk is the apk is bound to an internal api which may fail to work in any future version, thus break application compatibility.

Just my two cents, without knowing your actual situation. :)


Best Regards,
Raymond Wen

http://rxwen.blogspot.com



FrankG

unread,
Dec 22, 2010, 8:17:39 AM12/22/10
to android-platform
Hi Raimond,

I think currently you did not have so many System Properties.

BTW .. from where did you get the number 250 ?

> "3. The api isn't intended for external usage."

What do you mean by "external usage" ?

It seems that Jimmuy Lee wrote about a platform
extension ..

Yes of course, this may change .. but then core system apps
like Settings, adb and so one must be changed in
the same way ..

I cannot imagine that this stuff will change, as this would require
dramatically changes on the platform.

Good luck ! Frank


On 22 Dez., 11:37, "Raymond.Wen" <rx.wen...@gmail.com> wrote:
> In what way did you manage to invoke these apis? Did you use any hacks?
> Personally, I still consider it's not a good way to perform IPC between
> different apks with property.
> 1. The number of slots in property system is limited, if I recall correctly,
> around 250.
> 2. Once occupied, a slot can't be freed.
> 3. The api isn't intended for external usage.
> So, if an application makes heavy use of properties, slots will be soon be
> exhausted. And system service may fail due to this. Another risk is the apk
> is bound to an internal api which may fail to work in any future version,
> thus break application compatibility.
>
> Just my two cents, without knowing your actual situation. :)
>
> Best Regards,
> Raymond Wen
>
> http://rxwen.blogspot.com
>
>
>
> On Wed, Dec 22, 2010 at 4:18 PM, Jiangyun Li <lijy...@gmail.com> wrote:
> > Hi,
>
> > It's ok now, Thanks Frank & Raymond!
>
> > BestRegards
> > JimmyLi
>
> > 2010/12/22 Jiangyun Li <lijy...@gmail.com>
>
> > Hi Frank,
>
> >> I choose SystemProperties.set/get to do that, but when I try to get
> >> property after invoking SystemProperties.set, it returns empty string, not
> >> null, why?
> >> I just use this pair of apis in my apk, is there any initialization first?
> >> Thanks!
>
> >> BestRegards
> >> JimmyLi
>
> >> 2010/12/22 Raymond.Wen <rx.wen...@gmail.com>
>
> >> Hi Frank,
>
> >>> Thanks for pointing the SystemProperties class out. Andrew also mentioned
> >>> it in the post.
> >>> I haven't figured out how to use it in an external java application. May
> >>> be through reflection will do. Will try.
>
> >>> Best Regards,
> >>> Raymond Wen
>
> >>>http://rxwen.blogspot.com
>
> >>>> android-platfo...@googlegroups.com<android-platform%2Bunsubscrib­e...@googlegroups.com>
> >>>> .
> >>>> For more options, visit this group at
> >>>>http://groups.google.com/group/android-platform?hl=en.
>
> >>>  --
> >>> 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<android-platform%2Bunsubscrib­e...@googlegroups.com>
> >>> .
> >>> For more options, visit this group at
> >>>http://groups.google.com/group/android-platform?hl=en.
>
> >  --
> > 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<android-platform%2Bunsubscrib­e...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/android-platform?hl=en.- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

Raymond.Wen

unread,
Dec 22, 2010, 9:15:23 AM12/22/10
to android-...@googlegroups.com
Hi Frank,

I found the number from the source code. Be accurately, it's 247.

By external usage, I mean a standard application made by 3rd party. It's not good for an application intended to run different devices to rely on unstable apis. Of course, it's a different story if Jimmy is working on his own board or some platform stuffs.

Yes, I agree that this api is not likely to change. But I'd prefer to do things in the way that google guarantees to be stable. Anyway, we don't want to take the risk, unless we have no better choice.


Best Regards,
Raymond Wen

http://rxwen.blogspot.com



To unsubscribe from this group, send email to android-platfo...@googlegroups.com.

Jiangyun Li

unread,
Dec 22, 2010, 10:54:18 PM12/22/10
to android-...@googlegroups.com
Hi Frank & Raymond,

My case is only to provide a simple information, actually a string. According to this string, other APKs have different appearance. With your recommendations there are many solutions:
1. Intent mechanism: First other APKs send an intent to fetch the information string, then I send back an intent with it; I think this way is a little trivial and not efficient;
2. AIDL mechanism: As my module is just an app, actually just a homescreen, modified from android default Launcher app, so I donot want to do much modification to the architecture of it;
3. SystemProperties mechanism: I think this is the simplest way, I set and update the property in my module, the other APKs could get the information string at any time as needed;

When I changed the information string, Intent is a good choice to notify other APKs to change their appearance. On the other side, When some APK tries to get the information string so as to display corresponding appearance at the first time it runs, I think SystemProperties is a batter choice, as only one record, more efficient;

BestRegards
JimmyLi

2010/12/22 Raymond.Wen <rx.w...@gmail.com>
Hi Frank,

Tomei

unread,
Dec 23, 2010, 11:58:16 AM12/23/10
to android-platform
Jimmy,

Your app cannot use SystemProperties.put() unless it has one of the
few specific UID. You can see this in system/core/init/
property_service.c:

struct {
const char *prefix; unsigned int uid; unsigned int gid;
} property_perms[] = {
...
{ "hw.", AID_SYSTEM, 0 },
{ "sys.", AID_SYSTEM, 0 },
{ "service.", AID_SYSTEM, 0 },
{ "dhcp.", AID_DHCP, 0 },
{ "vpn.", AID_SYSTEM, 0 },
{ "vpn.", AID_VPN, 0 },
{ "debug.", AID_SHELL, 0 },
{ "log.", AID_SHELL, 0 },
....
{ NULL, 0, 0 }
};

If you're building your own platform, there is probably a painful way
to modify property_service.c to do what you want, but I would not
recommend it.

There is actually a little known method in the Andorid SDK that allows
any APK to create a world readable file (it can be read by any APKs).
So if you have one "main" APK that creates some shared settings, and
other APKs need to read these settings, you can try this:

SharedPreferences pref = mActivity.getSharedPreferences("foo",
Context.MODE_WORLD_READABLE);
SharedPreferences.Editor editor = pref.edit();
editor.putInt("junk", 0);
editor.commit();
File world_readable_file = mActivity.getFilesDir().getParent() + "/
shared_prefs/foo.xml";

FileOutputStream fout = new FileOutputStream(world_readable_file);
fout.write(....)

Other APKs can simply read this file using

FileInputStream fin = new FileInputStream("/data/data/
com.foobar.main/shared_prefs/foo.xml");

Hope this helps

On Dec 22, 7:54 pm, Jiangyun Li <lijy...@gmail.com> wrote:
> Hi Frank & Raymond,
>
> My case is only to provide a simple information, actually a string.
> According to this string, other APKs have different appearance. With your
> recommendations there are many solutions:
> 1. Intent mechanism: First other APKs send an intent to fetch the
> information string, then I send back an intent with it; I think this way is
> a little trivial and not efficient;
> 2. AIDL mechanism: As my module is just an app, actually just a homescreen,
> modified from android default Launcher app, so I donot want to do much
> modification to the architecture of it;
> 3. SystemProperties mechanism: I think this is the simplest way, I set and
> update the property in my module, the other APKs could get the information
> string at any time as needed;
>
> When I changed the information string, Intent is a good choice to notify
> other APKs to change their appearance. On the other side, When some APK
> tries to get the information string so as to display corresponding
> appearance at the first time it runs, I think SystemProperties is a batter
> choice, as only one record, more efficient;
>
> BestRegards
> JimmyLi
>
> 2010/12/22 Raymond.Wen <rx.wen...@gmail.com>
>
>
>
>
>
>
>
> > Hi Frank,
>
> > I found the number from the source code. Be accurately, it's 247.
>
> > By external usage, I mean a standard application made by 3rd party. It's
> > not good for an application intended to run different devices to rely on
> > unstable apis. Of course, it's a different story if Jimmy is working on his
> > own board or some platform stuffs.
>
> > Yes, I agree that this api is not likely to change. But I'd prefer to do
> > things in the way that google guarantees to be stable. Anyway, we don't want
> > to take the risk, unless we have no better choice.
>
> > Best Regards,
> > Raymond Wen
>
> >http://rxwen.blogspot.com
>
> >> > >http://groups.google.com/group/android-platform?hl=en.-Zitierten Text
> >> ausblenden -
>
> >> > - Zitierten Text anzeigen -
>
> >> --
> >> 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

FrankG

unread,
Dec 23, 2010, 3:15:37 PM12/23/10
to android-platform
Hello Tomei,

It sounds for me, that Jimmy Li works on a platform extension
and so creates System-Apps .

But you are right, that the first part of the name of the property
controls which uid is able to set them.
> ...
>
> Erfahren Sie mehr »- Zitierten Text ausblenden -

FrankG

unread,
Dec 23, 2010, 3:18:15 PM12/23/10
to android-platform
Hello Jimmy Li,

I don't think that intents are not efficient, better whether they are
appropriate
depends from your requirements. Maybe you need to save the string
state
over reboots ?

Good luck ! Frank


On 23 Dez., 04:54, Jiangyun Li <lijy...@gmail.com> wrote:
> Hi Frank & Raymond,
>
> My case is only to provide a simple information, actually a string.
> According to this string, other APKs have different appearance. With your
> recommendations there are many solutions:
> 1. Intent mechanism: First other APKs send an intent to fetch the
> information string, then I send back an intent with it; I think this way is
> a little trivial and not efficient;
> 2. AIDL mechanism: As my module is just an app, actually just a homescreen,
> modified from android default Launcher app, so I donot want to do much
> modification to the architecture of it;
> 3. SystemProperties mechanism: I think this is the simplest way, I set and
> update the property in my module, the other APKs could get the information
> string at any time as needed;
>
> When I changed the information string, Intent is a good choice to notify
> other APKs to change their appearance. On the other side, When some APK
> tries to get the information string so as to display corresponding
> appearance at the first time it runs, I think SystemProperties is a batter
> choice, as only one record, more efficient;
>
> BestRegards
> JimmyLi
>
> 2010/12/22 Raymond.Wen <rx.wen...@gmail.com>
>
>
>
> > Hi Frank,
>
> > I found the number from the source code. Be accurately, it's 247.
>
> > By external usage, I mean a standard application made by 3rd party. It's
> > not good for an application intended to run different devices to rely on
> > unstable apis. Of course, it's a different story if Jimmy is working on his
> > own board or some platform stuffs.
>
> > Yes, I agree that this api is not likely to change. But I'd prefer to do
> > things in the way that google guarantees to be stable. Anyway, we don't want
> > to take the risk, unless we have no better choice.
>
> > Best Regards,
> > Raymond Wen
>
> >http://rxwen.blogspot.com
>
> >> > >http://groups.google.com/group/android-platform?hl=en.-Zitierten Text

FrankG

unread,
Dec 23, 2010, 3:22:04 PM12/23/10
to android-platform
Hi Raymond,

I think the intention of Jimmy Li is an platform extension for a
certain
platform, not a solution for different devices. And most system
properties
you can only write, if the app is signed with the platform key .. so
such app
is device specific.

Where in the code you find the limitation to 247 ? Somewhee in
property_service.c ?

Good luck ! Frank
> > > >http://groups.google.com/group/android-platform?hl=en.-Zitierten Text

Raymond.Wen

unread,
Dec 23, 2010, 8:36:29 PM12/23/10
to android-...@googlegroups.com
Hi Frank,

Yes, it's defined as PA_COUNT_MAX in property_service.c.


Best Regards,
Raymond Wen

http://rxwen.blogspot.com



To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages