From c2ba68df44aede0023bf02a9f1343f4b0d0a56df Mon Sep 17 00:00:00 2001 From: yury <jura@cp-lab.com> Date: Fri, 19 Aug 2016 14:50:18 +0000 Subject: [PATCH] * android: Added functions GetSystemProperty() and SystemApiLevel(). git-svn-id: trunk@34346 - --- .gitattributes | 1 + rtl/android/sysandroid.inc | 25 +++++++++++++++++++++++++ rtl/android/sysandroidh.inc | 19 +++++++++++++++++++ rtl/linux/system.pp | 6 +++++- 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 rtl/android/sysandroidh.inc diff --git a/.gitattributes b/.gitattributes index afdc09363a..b93f62676c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8352,6 +8352,7 @@ rtl/android/jvm/rtl.cfg svneol=native#text/plain rtl/android/mipsel/dllprt0.as svneol=native#text/plain rtl/android/mipsel/prt0.as svneol=native#text/plain rtl/android/sysandroid.inc svneol=native#text/plain +rtl/android/sysandroidh.inc svneol=native#text/plain rtl/android/unixandroid.inc svneol=native#text/plain rtl/arm/arm.inc svneol=native#text/plain rtl/arm/armdefines.inc svneol=native#text/plain diff --git a/rtl/android/sysandroid.inc b/rtl/android/sysandroid.inc index a416397e3a..84dc959e08 100644 --- a/rtl/android/sysandroid.inc +++ b/rtl/android/sysandroid.inc @@ -58,3 +58,28 @@ begin // Register the finalization routine atexit(@SysAndroidLibExit); end; + +function __system_property_get(name:Pchar; value:Pchar):longint;cdecl;external 'c' name '__system_property_get'; + +function GetSystemProperty(Name: PAnsiChar): shortstring; +begin + SetLength(Result, __system_property_get(Name, @Result[1])); +end; + +var + _ApiLevel: shortint = -1; + +function SystemApiLevel: shortint; +var + s: string; + c: integer; +begin + if _ApiLevel < 0 then + begin + s:=GetSystemProperty('ro.build.version.sdk'); + Val(s, _ApiLevel, c); + if c <> 0 then + _ApiLevel:=0; + end; + Result:=_ApiLevel; +end; diff --git a/rtl/android/sysandroidh.inc b/rtl/android/sysandroidh.inc new file mode 100644 index 0000000000..5422ab3d1a --- /dev/null +++ b/rtl/android/sysandroidh.inc @@ -0,0 +1,19 @@ +{ + This file is part of the Free Pascal run time library. + Copyright (c) 2016 by Yury Sidorov, + member of the Free Pascal development team. + + Android-specific part of the System unit. + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + **********************************************************************} + +// Returns an Android system property +function GetSystemProperty(Name: PAnsiChar): shortstring; +// Returns an Android API level of the current system +function SystemApiLevel: shortint; diff --git a/rtl/linux/system.pp b/rtl/linux/system.pp index c0c4d3baa4..4c978daed9 100644 --- a/rtl/linux/system.pp +++ b/rtl/linux/system.pp @@ -44,6 +44,10 @@ property cmdline:Pchar read get_cmdline; {$endif defined(CPUARM) or defined(CPUM68K) or (defined(CPUSPARC) and defined(VER2_6))} +{$ifdef android} + {$I sysandroidh.inc} +{$endif android} + {*****************************************************************************} implementation {*****************************************************************************} @@ -78,7 +82,7 @@ const calculated_cmdline:Pchar=nil; {$I system.inc} {$ifdef android} -{$I sysandroid.inc} + {$I sysandroid.inc} {$endif android} {*****************************************************************************