pax_global_header00006660000000000000000000000064120400422550014504gustar00rootroot0000000000000052 comment=e2eeaec0b793863df6dc244bfaf65b19b03cde02 phonefsod-0.1+git20121018/000077500000000000000000000000001204004225500147275ustar00rootroot00000000000000phonefsod-0.1+git20121018/AUTHORS000066400000000000000000000004571204004225500160050ustar00rootroot00000000000000- Marc-Olivier Barre - Julien Cassignol - Andreas Engelbredt Dalsgaard - Lukas Märdian Based on openmoko_dialer2 by: - Michael 'Mickey' Lauer - Tony Guan phonefsod-0.1+git20121018/COPYING000066400000000000000000000432541204004225500157720ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. phonefsod-0.1+git20121018/ChangeLog000066400000000000000000000000451204004225500165000ustar00rootroot00000000000000for history please refer to git log phonefsod-0.1+git20121018/INSTALL000066400000000000000000000224501204004225500157630ustar00rootroot00000000000000Installation Instructions ************************* Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. This file is free documentation; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. Basic Installation ================== Briefly, the shell commands `./configure; make; make install' should configure, build, and install this package. The following more-detailed instructions are generic; see the `README' file for instructions specific to this package. The `configure' shell script attempts to guess correct values for various system-dependent variables used during compilation. It uses those values to create a `Makefile' in each directory of the package. It may also create one or more `.h' files containing system-dependent definitions. Finally, it creates a shell script `config.status' that you can run in the future to recreate the current configuration, and a file `config.log' containing compiler output (useful mainly for debugging `configure'). It can also use an optional file (typically called `config.cache' and enabled with `--cache-file=config.cache' or simply `-C') that saves the results of its tests to speed up reconfiguring. Caching is disabled by default to prevent problems with accidental use of stale cache files. If you need to do unusual things to compile the package, please try to figure out how `configure' could check whether to do them, and mail diffs or instructions to the address given in the `README' so they can be considered for the next release. If you are using the cache, and at some point `config.cache' contains results you don't want to keep, you may remove or edit it. The file `configure.ac' (or `configure.in') is used to create `configure' by a program called `autoconf'. You need `configure.ac' if you want to change it or regenerate `configure' using a newer version of `autoconf'. The simplest way to compile this package is: 1. `cd' to the directory containing the package's source code and type `./configure' to configure the package for your system. Running `configure' might take a while. While running, it prints some messages telling which features it is checking for. 2. Type `make' to compile the package. 3. Optionally, type `make check' to run any self-tests that come with the package. 4. Type `make install' to install the programs and any data files and documentation. 5. You can remove the program binaries and object files from the source code directory by typing `make clean'. To also remove the files that `configure' created (so you can compile the package for a different kind of computer), type `make distclean'. There is also a `make maintainer-clean' target, but that is intended mainly for the package's developers. If you use it, you may have to get all sorts of other programs in order to regenerate files that came with the distribution. 6. Often, you can also type `make uninstall' to remove the installed files again. Compilers and Options ===================== Some systems require unusual options for compilation or linking that the `configure' script does not know about. Run `./configure --help' for details on some of the pertinent environment variables. You can give `configure' initial values for configuration parameters by setting variables in the command line or in the environment. Here is an example: ./configure CC=c99 CFLAGS=-g LIBS=-lposix *Note Defining Variables::, for more details. Compiling For Multiple Architectures ==================================== You can compile the package for more than one kind of computer at the same time, by placing the object files for each architecture in their own directory. To do this, you can use GNU `make'. `cd' to the directory where you want the object files and executables to go and run the `configure' script. `configure' automatically checks for the source code in the directory that `configure' is in and in `..'. With a non-GNU `make', it is safer to compile the package for one architecture at a time in the source code directory. After you have installed the package for one architecture, use `make distclean' before reconfiguring for another architecture. Installation Names ================== By default, `make install' installs the package's commands under `/usr/local/bin', include files under `/usr/local/include', etc. You can specify an installation prefix other than `/usr/local' by giving `configure' the option `--prefix=PREFIX'. You can specify separate installation prefixes for architecture-specific files and architecture-independent files. If you pass the option `--exec-prefix=PREFIX' to `configure', the package uses PREFIX as the prefix for installing programs and libraries. Documentation and other data files still use the regular prefix. In addition, if you use an unusual directory layout you can give options like `--bindir=DIR' to specify different values for particular kinds of files. Run `configure --help' for a list of the directories you can set and what kinds of files go in them. If the package supports it, you can cause programs to be installed with an extra prefix or suffix on their names by giving `configure' the option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. Optional Features ================= Some packages pay attention to `--enable-FEATURE' options to `configure', where FEATURE indicates an optional part of the package. They may also pay attention to `--with-PACKAGE' options, where PACKAGE is something like `gnu-as' or `x' (for the X Window System). The `README' should mention any `--enable-' and `--with-' options that the package recognizes. For packages that use the X Window System, `configure' can usually find the X include and library files automatically, but if it doesn't, you can use the `configure' options `--x-includes=DIR' and `--x-libraries=DIR' to specify their locations. Specifying the System Type ========================== There may be some features `configure' cannot figure out automatically, but needs to determine by the type of machine the package will run on. Usually, assuming the package is built to be run on the _same_ architectures, `configure' can figure that out, but if it prints a message saying it cannot guess the machine type, give it the `--build=TYPE' option. TYPE can either be a short name for the system type, such as `sun4', or a canonical name which has the form: CPU-COMPANY-SYSTEM where SYSTEM can have one of these forms: OS KERNEL-OS See the file `config.sub' for the possible values of each field. If `config.sub' isn't included in this package, then this package doesn't need to know the machine type. If you are _building_ compiler tools for cross-compiling, you should use the option `--target=TYPE' to select the type of system they will produce code for. If you want to _use_ a cross compiler, that generates code for a platform different from the build platform, you should specify the "host" platform (i.e., that on which the generated programs will eventually be run) with `--host=TYPE'. Sharing Defaults ================ If you want to set default values for `configure' scripts to share, you can create a site shell script called `config.site' that gives default values for variables like `CC', `cache_file', and `prefix'. `configure' looks for `PREFIX/share/config.site' if it exists, then `PREFIX/etc/config.site' if it exists. Or, you can set the `CONFIG_SITE' environment variable to the location of the site script. A warning: not all `configure' scripts look for a site script. Defining Variables ================== Variables not defined in a site shell script can be set in the environment passed to `configure'. However, some packages may run configure again during the build, and the customized values of these variables may be lost. In order to avoid this problem, you should set them in the `configure' command line, using `VAR=value'. For example: ./configure CC=/usr/local2/bin/gcc causes the specified `gcc' to be used as the C compiler (unless it is overridden in the site shell script). Unfortunately, this technique does not work for `CONFIG_SHELL' due to an Autoconf bug. Until the bug is fixed you can use this workaround: CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash `configure' Invocation ====================== `configure' recognizes the following options to control how it operates. `--help' `-h' Print a summary of the options to `configure', and exit. `--version' `-V' Print the version of Autoconf used to generate the `configure' script, and exit. `--cache-file=FILE' Enable the cache: use and save the results of the tests in FILE, traditionally `config.cache'. FILE defaults to `/dev/null' to disable caching. `--config-cache' `-C' Alias for `--cache-file=config.cache'. `--quiet' `--silent' `-q' Do not print messages saying which checks are being made. To suppress all normal output, redirect it to `/dev/null' (any error messages will still be shown). `--srcdir=DIR' Look for the package's source code in directory DIR. Usually `configure' can determine that directory automatically. `configure' also accepts some other, not widely useful, options. Run `configure --help' for more details. phonefsod-0.1+git20121018/Makefile.am000066400000000000000000000003361204004225500167650ustar00rootroot00000000000000SUBDIRS = src data MAINTAINERCLEANFILES = \ Makefile.in Makefile aclocal.m4 config.guess \ config.h.in config.sub configure install-sh \ ltconfig ltmain.sh missing mkinstalldirs \ stamp-h.in acconfig.h stamp-h depcomp phonefsod-0.1+git20121018/NEWS000066400000000000000000000000001204004225500154140ustar00rootroot00000000000000phonefsod-0.1+git20121018/README000066400000000000000000000001251204004225500156050ustar00rootroot00000000000000This is the SHR phone daemon interacting with FSO and calling into phoneuid for GUI. phonefsod-0.1+git20121018/autogen.sh000077500000000000000000000002001204004225500167200ustar00rootroot00000000000000#! /bin/sh autoreconf -v --install || exit 1 glib-gettextize --force --copy || exit 1 ./configure --enable-maintainer-mode "$@" phonefsod-0.1+git20121018/configure.ac000066400000000000000000000006771204004225500172270ustar00rootroot00000000000000# get rid of that stupid cache mechanism rm -f config.cache AC_INIT(phonefsod, 0.1, http://shr-project.org/) AC_PREREQ(2.52) AC_CONFIG_SRCDIR(configure.ac) AC_ISC_POSIX AM_INIT_AUTOMAKE(1.6 dist-bzip2) AM_CONFIG_HEADER(config.h) AC_PROG_CC AC_HEADER_STDC PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.29.3 gio-2.0 >= 2.29.3 shr-glib-1.0 fso-glib-1.0 ) AC_SUBST(GLIB_CFLAGS) AC_SUBST(GLIB_LIBS) AC_OUTPUT([ Makefile src/Makefile data/Makefile ]) phonefsod-0.1+git20121018/data/000077500000000000000000000000001204004225500156405ustar00rootroot00000000000000phonefsod-0.1+git20121018/data/Makefile.am000066400000000000000000000003561204004225500177000ustar00rootroot00000000000000MAINTAINERCLEANFILES = Makefile.in dist_sysconf_DATA = phonefsod.conf dbus_systemdir = $(sysconfdir)/dbus-1/system.d init_scriptsdir = $(sysconfdir)/init.d dbus_system_DATA = dbus-1/phonefsod.conf init_scripts_SCRIPTS = init.d/phonefsod phonefsod-0.1+git20121018/data/dbus-1/000077500000000000000000000000001204004225500167335ustar00rootroot00000000000000phonefsod-0.1+git20121018/data/dbus-1/phonefsod.conf000066400000000000000000000004051204004225500215660ustar00rootroot00000000000000 phonefsod-0.1+git20121018/data/init.d/000077500000000000000000000000001204004225500170255ustar00rootroot00000000000000phonefsod-0.1+git20121018/data/init.d/phonefsod000066400000000000000000000016721204004225500207430ustar00rootroot00000000000000#! /bin/sh # # phonefsod -- This shell script starts and stops the SHR Phone FSO daemon. # # chkconfig: 345 90 20 # description: phonefsod is the GSM resource handling daemon of SHR # processname: phonefsod PATH=/bin:/usr/bin:/sbin:/usr/sbin NAME=phonefsod [ -f /etc/default/rcS ] && . /etc/default/rcS case "$1" in start) echo -n "Starting SHR Phone FSO daemon: " start-stop-daemon --start --pidfile /var/run/${NAME}.pid --background -x /usr/bin/${NAME} if [ $? = 0 ]; then echo "(ok)" else echo "(failed)" fi ;; stop) echo -n "Stopping SHR Phone FSO daemon: " start-stop-daemon --stop --pidfile /var/run/${NAME}.pid --oknodo echo "(done)" ;; restart|force-reload) $0 stop $0 start ;; *) echo "Usage: /etc/init.d/phonefsod {start|stop|restart|force-reload}" exit 1 ;; esac exit 0 phonefsod-0.1+git20121018/data/phonefsod.conf000066400000000000000000000035541204004225500205030ustar00rootroot00000000000000 [logging] log_level=INFO log_file=/var/log/phonefsod.log [gsm] # should phonefsod try to activate GSM offline_mode=false # time in seconds how long (at a maximum) suspend should be blocked # after start to give the thing time to activate and register GSM # (-1 to disable that) inhibit_suspend_on_startup_time=360 # after how many seconds should reregistering the network be tried # (eg. after being without network coverage) gsm_reregister_timeout=60 # automatically show incoming new messages show_incoming_sms=true # do we want to show our number for outgoing calls # valid values are "on", "off" and "network" calling_identification=network # if you want your pin to be automatically sent put it here # pin=1234 [idle] # default brightness to set on startup default_brightness=80 # do we want to dim the screen together with the idle states? # one of the following values: # never: completely disable screen dimming # onbat: only dim, when phone is running on battery # always: always dim dim_screen=always # what is the minimum brightness to show - lower turns backlight off minimum_brightness=2 # dim screen on idle state dim_idle_percent=50 # dim screen on idle_dim state dim_idle_dim_percent=25 # dim screen on idle_prelock state dim_idle_prelock_percent=0 # when to show idle screen # a list of comma separated flags with the following meaning: # aux: toggle idle screen by pressing AUX # lock: automatically show idle screen in idle_lock idle state # suspend: automatically show idle screen when phone is suspended # phone: do even show it during active calls idle_screen=aux,lock,suspend # when to automatically suspend the device (one of: never, normal, always) auto_suspend=normal [settings] # when to show quick settings # true: show quick settings on POWER clicked (detected by FSO) # false: dont't show quick settings on POWER clicked #quick_settings_power=true phonefsod-0.1+git20121018/src/000077500000000000000000000000001204004225500155165ustar00rootroot00000000000000phonefsod-0.1+git20121018/src/Makefile.am000066400000000000000000000006561204004225500175610ustar00rootroot00000000000000MAINTAINERCLEANFILES = Makefile.in bin_PROGRAMS = phonefsod phonefsod_SOURCES = \ phonefsod.c \ phonefsod-fso.c \ phonefsod-fso.h \ phonefsod-dbus.c \ phonefsod-dbus.h \ phonefsod-dbus-common.h phonefsod_CFLAGS = \ -DDATADIR=\"$(datadir)\" \ -DPKGDATADIR=\"$(pkgdatadir)\" \ -DPHONEFSOD_CONFIG=\"$(sysconfdir)/phonefsod.conf\" \ -DG_LOG_DOMAIN=\"phonefsod\" \ @GLIB_CFLAGS@ \ -ggdb phonefsod_LDADD = @GLIB_LIBS@ phonefsod-0.1+git20121018/src/phonefsod-dbus-common.h000066400000000000000000000076671204004225500221150ustar00rootroot00000000000000/* * Copyright (C) 2009-2012 * Authors (alphabetical) : * Klaus 'mrmoku' Kurzmann * Lukas 'slyon' Märdian * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Public License as published by * the Free Software Foundation; version 2 of the license or any later version. * * 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. See the * GNU Lesser Public License for more details. */ #ifndef _PHONEFSOD_DBUS_COMMON_H #define _PHONEFSOD_DBUS_COMMON_H /* phonefsod */ #define PHONEFSOD_SERVICE "org.shr.phonefso" #define PHONEFSOD_PATH "/org/shr/phonefso" #define PHONEFSOD_USAGE_INTERFACE PHONEFSOD_SERVICE ".Usage" #define PHONEFSOD_USAGE_PATH PHONEFSOD_PATH "/Usage" /* phoneuid */ #define PHONEUID_SERVICE "org.shr.phoneui" #define PHONEUID_PATH "/org/shr/phoneui" #define PHONEUID_CALL_MANAGEMENT_INTERFACE PHONEUID_SERVICE ".CallManagement" #define PHONEUID_DIALER_INTERFACE PHONEUID_SERVICE ".Dialer" #define PHONEUID_NOTIFICATION_INTERFACE PHONEUID_SERVICE ".Notification" #define PHONEUID_CONTACTS_INTERFACE PHONEUID_SERVICE ".Contacts" #define PHONEUID_MESSAGES_INTERFACE PHONEUID_SERVICE ".Messages" #define PHONEUID_PHONE_LOG_INTERFACE PHONEUID_SERVICE ".PhoneLog" #define PHONEUID_IDLE_SCREEN_INTERFACE PHONEUID_SERVICE ".IdleScreen" #define PHONEUID_CALL_MANAGEMENT_PATH PHONEUID_PATH "/CallManagement" #define PHONEUID_DIALER_PATH PHONEUID_PATH "/Dialer" #define PHONEUID_NOTIFICATION_PATH PHONEUID_PATH "/Notification" #define PHONEUID_CONTACTS_PATH PHONEUID_PATH "/Contacts" #define PHONEUID_MESSAGES_PATH PHONEUID_PATH "/Messages" #define PHONEUID_PHONE_LOG_PATH PHONEUID_PATH "/PhoneLog" #define PHONEUID_IDLE_SCREEN_PATH PHONEUID_PATH "/IdleScreen" #define PHONEUID_SETTINGS_PATH PHONEUID_PATH "/Settings" /* freesmartphone.org */ #define FSO_USAGE_SERVICE "org.freesmartphone.ousaged" #define FSO_USAGE_PATH "/org/freesmartphone/Usage" #define FSO_USAGE_IFACE "org.freesmartphone.Usage" #define FSO_GSM_SERVICE "org.freesmartphone.ogsmd" #define FSO_GSM_DEVICE_PATH "/org/freesmartphone/GSM/Device" #define FSO_GSM_DEVICE_IFACE "org.freesmartphone.GSM.Device" #define FSO_GSM_SIM_IFACE "org.freesmartphone.GSM.SIM" #define FSO_GSM_NETWORK_IFACE "org.freesmartphone.GSM.Network" #define FSO_GSM_PDP_IFACE "org.freesmartphone.GSM.PDP" #define FSO_GSM_CALL_IFACE "org.freesmartphone.GSM.Call" #define FSO_PIM_SERVICE "org.freesmartphone.opimd" #define FSO_PIM_MESSAGES_PATH "/org/freesmartphone/PIM/Messages" #define FSO_PIM_MESSAGES_IFACE "org.freesmartphone.PIM.Messages" #define FSO_DEVICE_SERVICE "org.freesmartphone.odeviced" #define FSO_DEVICE_IDLE_NOTIFIER_PATH "/org/freesmartphone/Device/IdleNotifier/0" #define FSO_DEVICE_IDLE_NOTIFIER_IFACE "org.freesmartphone.Device.IdleNotifier" #define FSO_DEVICE_INPUT_PATH "/org/freesmartphone/Device/Input" #define FSO_DEVICE_INPUT_IFACE "org.freesmartphone.Device.Input" #define FSO_DEVICE_DISPLAY_PATH "/org/freesmartphone/Device/Display/0" #define FSO_DEVICE_DISPLAY_IFACE "org.freesmartphone.Device.Display" #define FSO_DEVICE_POWER_SUPPLY_PATH "/org/freesmartphone/Device/PowerSupply" #define FSO_DEVICE_POWER_SUPPLY_IFACE "org.freesmartphone.Device.PowerSupply" #endif phonefsod-0.1+git20121018/src/phonefsod-dbus.c000066400000000000000000000400511204004225500206020ustar00rootroot00000000000000/* * Copyright (C) 2009-2012 * Authors (alphabetical) : * Klaus 'mrmoku' Kurzmann * Lukas 'slyon' Märdian * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Public License as published by * the Free Software Foundation; version 2 of the license or any later version. * * 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. See the * GNU Lesser Public License for more details. */ #include #include #include #include "phonefsod-dbus.h" #include "phonefsod-dbus-common.h" #include "phonefsod-fso.h" #include "phonefsod-globals.h" static guint phonefsod_owner_id = 0; static guint phoneuid_watcher_id = 0; static PhonefsoUsage *usage; /* phonefso - dbus method handlers */ static gboolean _set_offline_mode(PhonefsoUsage *object, GDBusMethodInvocation *invocation, gboolean state, gpointer user_data); static gboolean _get_offline_mode(PhonefsoUsage *object, GDBusMethodInvocation *invocation, gpointer user_data); static gboolean _set_default_brightness(PhonefsoUsage *object, GDBusMethodInvocation *invocation, int brightness, gpointer user_data); static gboolean _get_default_brightness(PhonefsoUsage *object, GDBusMethodInvocation *invocation, gpointer user_data); static gboolean _set_pdp_credentials(PhonefsoUsage *object, GDBusMethodInvocation *invocation, const char *apn, const char *user, const char *password, gpointer user_data); static gboolean _set_pin(PhonefsoUsage *object, GDBusMethodInvocation *invocation, const char *pin, gboolean save, gpointer user_data); /* private helper functions */ static void _write_pdp_credentials_to_config(void); static void _write_default_brightness_to_config(void); static void _write_offline_mode_to_config(void); /* g_bus_own_name callbacks */ static void _on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer user_data); static void _on_name_acquired (GDBusConnection *connection, const gchar *name, gpointer user_data); static void _on_name_lost (GDBusConnection *connection, const gchar *name, gpointer user_data); /* g_bus_watch_proxy callbacks */ static void _on_phoneuid_appeared(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data); static void _on_phoneuid_vanished(GDBusConnection *connection, const gchar *name, gpointer user_data); static gint _show_sim_auth(); /* handle dbus errors */ static void _handle_dbus_error(GError *error, const gchar *msg); static int _handle_phoneuid_proxy_error(GError *error, const gchar *iface); int phonefsod_dbus_setup() { GError *error = NULL; system_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); if (error) { g_error("%d: %s", error->code, error->message); g_error_free(error); return 0; } phonefsod_owner_id = g_bus_own_name_on_connection (system_bus, PHONEFSOD_SERVICE, G_BUS_NAME_OWNER_FLAGS_REPLACE | G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT, _on_bus_acquired, _on_name_acquired, _on_name_lost, NULL); phoneuid_watcher_id = g_bus_watch_name_on_connection (system_bus, PHONEUID_SERVICE, G_BUS_NAME_WATCHER_FLAGS_NONE, _on_phoneuid_appeared, _on_phoneuid_vanished, NULL, NULL); phoneui.notification = phoneui_notification_proxy_new_sync (system_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, PHONEUID_SERVICE, PHONEUID_NOTIFICATION_PATH, NULL, &error); if (!_handle_phoneuid_proxy_error(error, PHONEUID_NOTIFICATION_PATH)) return 0; phoneui.call_management = phoneui_call_management_proxy_new_sync (system_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, PHONEUID_SERVICE, PHONEUID_CALL_MANAGEMENT_PATH, NULL, &error); if (!_handle_phoneuid_proxy_error(error, PHONEUID_CALL_MANAGEMENT_PATH)) return 0; phoneui.idle_screen = phoneui_idle_screen_proxy_new_sync (system_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, PHONEUID_SERVICE, PHONEUID_IDLE_SCREEN_PATH, NULL, &error); if (!_handle_phoneuid_proxy_error(error, PHONEUID_IDLE_SCREEN_PATH)) return 0; phoneui.settings = phoneui_settings_proxy_new_sync (system_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, PHONEUID_SERVICE, PHONEUID_SETTINGS_PATH, NULL, &error); if (!_handle_phoneuid_proxy_error(error, PHONEUID_SETTINGS_PATH)) return 0; phoneui.messages = phoneui_messages_proxy_new_sync (system_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, PHONEUID_SERVICE, PHONEUID_MESSAGES_PATH, NULL, &error); if (!_handle_phoneuid_proxy_error(error, PHONEUID_MESSAGES_PATH)) return 0; /* connect and init FSO */ if (!fso_init()) return 0; return 1; } void phonefsod_dbus_shutdown() { g_bus_unown_name(phonefsod_owner_id); g_object_unref(system_bus); } /* handlers for g_bus_own_name */ static void _on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer user_data) { /* This is where we'd export some objects on the bus */ GError *error = NULL; g_debug("Yo, on the bus :-) (%s)", name); usage = phonefso_usage_skeleton_new(); g_signal_connect(usage, "handle-set-offline-mode", G_CALLBACK(_set_offline_mode), NULL); g_signal_connect(usage, "handle-get-offline-mode", G_CALLBACK(_get_offline_mode), NULL); g_signal_connect(usage, "handle-set-default-brightness", G_CALLBACK(_set_default_brightness), NULL); g_signal_connect(usage, "handle-get-default-brightness", G_CALLBACK(_get_default_brightness), NULL); g_signal_connect(usage, "handle-set-pdp-credentials", G_CALLBACK(_set_pdp_credentials), NULL); g_signal_connect(usage, "handle-set-pin", G_CALLBACK(_set_pin), NULL); g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(usage), connection, PHONEFSOD_USAGE_PATH, &error); if (error) { g_critical("Failed to register %s: %s", PHONEFSOD_USAGE_PATH, error->message); g_error_free(error); } } static void _on_name_acquired (GDBusConnection *connection, const gchar *name, gpointer user_data) { g_debug ("Acquired the name %s on the system bus\n", name); } static void _on_name_lost (GDBusConnection *connection, const gchar *name, gpointer user_data) { g_debug ("Lost the name %s on the system bus\n", name); } /* handlers for g_bus_watch_name */ static void _on_phoneuid_appeared(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data) { g_debug("yeah, phoneuid is on the bus (%s)", name_owner); if (sim_auth_needed && phoneui.notification) { g_timeout_add_seconds(2, _show_sim_auth, NULL); } } static void _on_phoneuid_vanished(GDBusConnection *connection, const gchar *name, gpointer user_data) { g_message("!!! ouch, phoneuid is gone - telephony won't work anymore !!!"); } static gint _show_sim_auth() { g_debug("showing PIN dialog"); phoneui_notification_call_display_sim_auth (phoneui.notification, 0, NULL, phoneui_show_sim_auth_cb, NULL); } /* method call handlers */ static gboolean _set_offline_mode(PhonefsoUsage *object, GDBusMethodInvocation *invocation, gboolean state, gpointer user_data) { if (offline_mode ^ state) { offline_mode = state; _write_offline_mode_to_config(); fso_set_functionality(); } phonefso_usage_complete_set_offline_mode(object, invocation); return TRUE; } static gboolean _get_offline_mode(PhonefsoUsage *object, GDBusMethodInvocation *invocation, gpointer user_data) { phonefso_usage_complete_get_offline_mode(object, invocation, offline_mode); return TRUE; } static gboolean _set_default_brightness(PhonefsoUsage *object, GDBusMethodInvocation *invocation, int brightness, gpointer user_data) { default_brightness = brightness; _write_default_brightness_to_config(); fso_dimit(100, DIM_SCREEN_ALWAYS); phonefso_usage_complete_set_default_brightness(object, invocation); } static gboolean _get_default_brightness(PhonefsoUsage *object, GDBusMethodInvocation *invocation, gpointer user_data) { phonefso_usage_complete_get_default_brightness(object, invocation, default_brightness); return TRUE; } static gboolean _set_pdp_credentials(PhonefsoUsage *object, GDBusMethodInvocation *invocation, const char *apn, const char *user, const char *password, gpointer user_data) { if (pdp_apn) { free(pdp_apn); } pdp_apn = strdup(apn); if (pdp_user) { free(pdp_user); } pdp_user = strdup(user); if (pdp_password) { free(pdp_password); } pdp_password = strdup(password); _write_pdp_credentials_to_config(); fso_pdp_set_credentials(); phonefso_usage_complete_set_pdp_credentials(object, invocation); return TRUE; } static gboolean _set_pin(PhonefsoUsage *object, GDBusMethodInvocation *invocation, const char *pin, gboolean save, gpointer user_data) { if (sim_pin) free(sim_pin); sim_pin = strdup(pin); fso_set_functionality(); if (save) { /* TODO: save to config... maybe including ident of SIM * to be able to save PINs for multiple SIMs */ } phonefso_usage_complete_set_pin(object, invocation); return TRUE; } /* private helpers */ static void _write_offline_mode_to_config(void) { GError *error = NULL; GKeyFile *keyfile; GKeyFileFlags flags; gsize size; char *config_data; keyfile = g_key_file_new(); flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS; if (g_key_file_load_from_file (keyfile, PHONEFSOD_CONFIG, flags, &error)) { g_key_file_set_boolean(keyfile, "gsm", "offline_mode", offline_mode); config_data = g_key_file_to_data(keyfile, &size, NULL); if (!config_data) { g_message("could not convert config data to write \ offline mode to config"); } else { if (!g_file_set_contents(PHONEFSOD_CONFIG, config_data, size, &error)) { g_warning("failed writing offline mode \ to config: %s", error->message); g_error_free(error); } g_free(config_data); } } if (keyfile) g_key_file_free(keyfile); } static void _write_default_brightness_to_config(void) { GError *error = NULL; GKeyFile *keyfile; GKeyFileFlags flags; gsize size; char *config_data; keyfile = g_key_file_new(); flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS; if (g_key_file_load_from_file (keyfile, PHONEFSOD_CONFIG, flags, &error)) { g_key_file_set_integer(keyfile, "idle", "default_brightness", default_brightness); config_data = g_key_file_to_data(keyfile, &size, NULL); if (!config_data) { g_message("could not convert config data to write \ default brightness to config"); } else { if (!g_file_set_contents(PHONEFSOD_CONFIG, config_data, size, &error)) { g_warning("failed writing default brightness \ to config: %s", error->message); g_error_free(error); } g_free(config_data); } } if (keyfile) g_key_file_free(keyfile); } static void _write_pdp_credentials_to_config(void) { GError *error = NULL; GKeyFile *keyfile; GKeyFileFlags flags; gsize size; char *config_data; keyfile = g_key_file_new(); flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS; if (g_key_file_load_from_file (keyfile, PHONEFSOD_CONFIG, flags, &error)) { g_key_file_set_string(keyfile, "gsm", "pdp_apn", pdp_apn); g_key_file_set_string(keyfile, "gsm", "pdp_user", pdp_user); g_key_file_set_string(keyfile, "gsm", "pdp_password", pdp_password); config_data = g_key_file_to_data(keyfile, &size, NULL); if (!config_data) { g_message("could not convert config data to write \ default brightness to config"); } else { if (!g_file_set_contents(PHONEFSOD_CONFIG, config_data, size, &error)) { g_warning("failed writing pdp credentials \ to config: %s", error->message); g_error_free(error); } g_free(config_data); } } if (keyfile) g_key_file_free(keyfile); } /* phoneuid - dbus callbacks */ void phoneui_show_incoming_cb(GObject *source, GAsyncResult *res, gpointer data) { GError *error = NULL; phoneui_call_management_call_display_incoming_finish (PHONEUI_CALL_MANAGEMENT(source), res, &error); _handle_dbus_error(error, "failed showing incoming call"); } void phoneui_hide_incoming_cb(GObject *source, GAsyncResult *res, gpointer data) { GError *error = NULL; phoneui_call_management_call_hide_incoming_finish (PHONEUI_CALL_MANAGEMENT(source), res, &error); _handle_dbus_error(error, "failed hiding incoming call"); } void phoneui_show_outgoing_cb(GObject *source, GAsyncResult *res, gpointer data) { GError *error = NULL; phoneui_call_management_call_display_outgoing_finish (PHONEUI_CALL_MANAGEMENT(source), res, &error); _handle_dbus_error(error, "failed showing outgoing call"); } void phoneui_hide_outgoing_cb(GObject *source, GAsyncResult *res, gpointer data) { GError *error = NULL; phoneui_call_management_call_hide_outgoing_finish (PHONEUI_CALL_MANAGEMENT(source), res, &error); _handle_dbus_error(error, "failed hiding outgoing call"); } void phoneui_display_message_cb(GObject *source, GAsyncResult *res, gpointer data) { GError *error = NULL; phoneui_messages_call_display_message_finish (PHONEUI_MESSAGES(source), res, &error); _handle_dbus_error(error, "failed displaying message"); } void phoneui_show_dialog_cb(GObject *source, GAsyncResult *res, gpointer data) { GError *error = NULL; phoneui_notification_call_display_dialog_finish (PHONEUI_NOTIFICATION(source), res, &error); _handle_dbus_error(error, "failed displaying dialog"); } void phoneui_show_sim_auth_cb(GObject *source, GAsyncResult *res, gpointer data) { GError *error = NULL; phoneui_notification_call_display_sim_auth_finish (PHONEUI_NOTIFICATION(source), res, &error); /* if showing sim auth worked... and _only_ then */ if (!error) sim_auth_needed = FALSE; _handle_dbus_error(error, "failed displaying sim auth"); } void phoneui_hide_sim_auth_cb(GObject *source, GAsyncResult *res, gpointer data) { GError *error = NULL; phoneui_notification_call_hide_sim_auth_finish (PHONEUI_NOTIFICATION(source), res, &error); _handle_dbus_error(error, "failed hiding sim auth"); } void phoneui_show_ussd_cb(GObject *source, GAsyncResult *res, gpointer data) { GError *error = NULL; phoneui_notification_call_display_ussd_finish (PHONEUI_NOTIFICATION(source), res, &error); _handle_dbus_error(error, "failed displaying ussd"); } void phoneui_show_idle_cb(GObject *source, GAsyncResult *res, gpointer data) { GError *error = NULL; phoneui_idle_screen_call_display_finish (PHONEUI_IDLE_SCREEN(source), res, &error); _handle_dbus_error(error, "failed displaying idle screen"); } void phoneui_hide_idle_cb(GObject *source, GAsyncResult *res, gpointer data) { GError *error = NULL; phoneui_idle_screen_call_hide_finish (PHONEUI_IDLE_SCREEN(source), res, &error); _handle_dbus_error(error, "failed hiding idle screen"); } void phoneui_toggle_idle_cb(GObject *source, GAsyncResult *res, gpointer data) { GError *error = NULL; phoneui_idle_screen_call_toggle_finish (PHONEUI_IDLE_SCREEN(source), res, &error); _handle_dbus_error(error, "failed toggling idle screen"); } void phoneui_show_quick_settings_cb(GObject *source, GAsyncResult *res, gpointer data) { GError *error = NULL; phoneui_settings_call_display_quick_settings_finish (PHONEUI_SETTINGS(source), res, &error); _handle_dbus_error(error, "failed showing quick settings"); } void phoneui_activate_screensaver_cb(GObject *source, GAsyncResult *res, gpointer data) { GError *error = NULL; phoneui_idle_screen_call_activate_screensaver_finish (PHONEUI_IDLE_SCREEN(source), res, &error); _handle_dbus_error(error, "failed activating screensaver"); } void phoneui_deactivate_screensaver_cb(GObject *source, GAsyncResult *res, gpointer data) { GError *error = NULL; phoneui_idle_screen_call_deactivate_screensaver_finish (PHONEUI_IDLE_SCREEN(source), res, &error); _handle_dbus_error(error, "failed deactivating screensaver"); } void _handle_dbus_error(GError* error, const gchar* msg) { if (error) { g_critical("%s: (%d) %s", msg, error->code, error->message); g_error_free(error); } } int _handle_phoneuid_proxy_error(GError *error, const gchar *iface) { if (error) { g_warning("getting proxy for %s failed: (%d) %s", iface, error->code, error->message); g_error_free(error); error = NULL; return 0; } return 1; } phonefsod-0.1+git20121018/src/phonefsod-dbus.h000066400000000000000000000040311204004225500206050ustar00rootroot00000000000000/* * Copyright (C) 2009-2012 * Authors (alphabetical) : * Klaus 'mrmoku' Kurzmann * Lukas 'slyon' Märdian * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Public License as published by * the Free Software Foundation; version 2 of the license or any later version. * * 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. See the * GNU Lesser Public License for more details. */ #ifndef _PHONEFSOD_DBUS_H #define _PHONEFSOD_DBUS_H #include int phonefsod_dbus_setup(); void phonefsod_dbus_shutdown(); /* phoneuid - dbus callbacks */ void phoneui_show_incoming_cb(GObject *source, GAsyncResult *res, gpointer data); void phoneui_hide_incoming_cb(GObject *source, GAsyncResult *res, gpointer data); void phoneui_show_outgoing_cb(GObject *source, GAsyncResult *res, gpointer data); void phoneui_hide_outgoing_cb(GObject *source, GAsyncResult *res, gpointer data); void phoneui_display_message_cb(GObject *source, GAsyncResult *res, gpointer data); void phoneui_show_dialog_cb(GObject *source, GAsyncResult *res, gpointer data); void phoneui_show_sim_auth_cb(GObject *source, GAsyncResult *res, gpointer data); void phoneui_hide_sim_auth_cb(GObject *source, GAsyncResult *res, gpointer data); void phoneui_show_ussd_cb(GObject *source, GAsyncResult *res, gpointer data); void phoneui_show_idle_cb(GObject *source, GAsyncResult *res, gpointer data); void phoneui_hide_idle_cb(GObject *source, GAsyncResult *res, gpointer data); void phoneui_toggle_idle_cb(GObject *source, GAsyncResult *res, gpointer data); void phoneui_activate_screensaver_cb(GObject *source, GAsyncResult *res, gpointer data); void phoneui_deactivate_screensaver_cb(GObject *source, GAsyncResult *res, gpointer data); void phoneui_show_quick_settings_cb(GObject *source, GAsyncResult *res, gpointer data); #endif phonefsod-0.1+git20121018/src/phonefsod-fso.c000066400000000000000000000730361204004225500204450ustar00rootroot00000000000000/* * Copyright (C) 2009-2012 * Authors (alphabetical) : * Klaus 'mrmoku' Kurzmann * Lukas 'slyon' Märdian * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Public License as published by * the Free Software Foundation; version 2 of the license or any later version. * * 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. See the * GNU Lesser Public License for more details. */ #include #include #include #include #include #include #include #include "phonefsod-dbus.h" #include "phonefsod-fso.h" #include "phonefsod-globals.h" #include "phonefsod-dbus-common.h" #define MIN_SIM_SLOTS_FREE 1 struct _fso { FreeSmartphoneUsage *usage; FreeSmartphoneGSMSIM * gsm_sim; FreeSmartphoneGSMCall *gsm_call; FreeSmartphoneGSMDevice *gsm_device; FreeSmartphoneGSMNetwork *gsm_network; FreeSmartphoneGSMPDP *gsm_pdp; FreeSmartphoneDeviceIdleNotifier *idle_notifier; FreeSmartphoneDeviceInput *input; FreeSmartphoneDeviceDisplay *display; FreeSmartphoneDevicePowerSupply *power_supply; FreeSmartphonePIMMessages *pim_messages; }; static struct _fso fso; enum PhoneUiDialogType { PHONEUI_DIALOG_ERROR_DO_NOT_USE = 0, // This value is used for checking if we get a wrong pointer out of a HashTable. // So do not use it, and leave it first in this enum. ( because 0 == NULL ) PHONEUI_DIALOG_MESSAGE_STORAGE_FULL, PHONEUI_DIALOG_SIM_NOT_PRESENT }; typedef struct { int id; } call_t; static gboolean show_sim_not_present = TRUE; static gboolean sim_ready = FALSE; static gboolean gsm_request_running = FALSE; static gboolean gsm_available = FALSE; static gboolean func_is_set = FALSE; static gboolean sim_check_needed = TRUE; static time_t startup_time = 0; static call_t *incoming_calls = NULL; static call_t *outgoing_calls = NULL; static int incoming_calls_size = 0; static int outgoing_calls_size = 0; static gboolean display_state = FALSE; static gboolean _fso_list_resources(); static gboolean _fso_request_gsm(); static void _fso_suspend(); static void _stop_startup(); static void _startup_check(); static gint _fso_sim_info(); /* dbus method callbacks */ static void _list_resources_callback(GObject *source, GAsyncResult *res, gpointer data); static void _request_resource_callback(GObject *source, GAsyncResult *res, gpointer data); static void _going_offline_callback(GObject *source, GAsyncResult *res, gpointer data); static void _going_online_callback(GObject *source, GAsyncResult *res, gpointer data); static void _gsm_sim_ready_status_callback(GObject *source, GAsyncResult *res, gpointer data); static void _gsm_sim_sim_info_callback(GObject *source, GAsyncResult *res, gpointer data); static void _set_functionality_callback(GObject *source, GAsyncResult *res, gpointer data); static void _get_power_status_callback(GObject *source, GAsyncResult *res, gpointer data); static void _get_idle_state_callback(GObject *source, GAsyncResult *res, gpointer data); /* dbus signal handlers */ static void _usage_resource_available_handler(GSource *source, char *resource, gboolean availability, gpointer data); static void _usage_resource_changed_handler(GSource *source, char *resource, gboolean state, GHashTable *attributes, gpointer data); static void _usage_system_action_handler(GSource* source, FreeSmartphoneUsageSystemAction action, gpointer data); static void _gsm_sim_ready_status_handler(GSource *source, gboolean status, gpointer data); static void _gsm_device_status_handler(GSource *source, FreeSmartphoneGSMDeviceStatus status, gpointer data); static void _device_idle_notifier_state_handler(GSource *source, FreeSmartphoneDeviceIdleState state, gpointer data); static void _device_input_event_handler(GSource *source, char *src, FreeSmartphoneDeviceInputState state, int duration, gpointer data); static void _gsm_call_status_handler(GSource *source, int call_id, int status, GHashTable *properties, gpointer data); static void _pim_incoming_message_handler(GSource *source, char *message_path, gpointer data); static void _gsm_network_incoming_ussd_handler(GSource *source, int mode, char *message, gpointer data); static void _gsm_network_status_handler(GSource *source, GHashTable *status, gpointer data); /* call management */ static void _call_add(call_t ** calls, int *size, int id); static int _call_check(call_t * calls, int *size, int id); static void _call_remove(call_t ** calls, int *size, int id); static gpointer _dbus_proxy(GType type, const gchar *obj, const gchar *path, const gchar *iface) { GError *error = NULL; gpointer ret; ret = g_initable_new(type, NULL, &error, "g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, "g-name", obj, "g-bus-type", G_BUS_TYPE_SYSTEM, "g-object-path", path, "g-interface-name", iface, NULL); if (error) { g_warning("failed to connect to %s: %s", path, error->message); g_error_free(error); return NULL; } return ret; } gboolean fso_init() { sim_auth_needed = FALSE; if (!offline_mode) { g_message("Inhibiting suspend during startup phase (max %ds)", inhibit_suspend_on_startup_time); startup_time = time(NULL); } fso_connect_usage(); fso_connect_gsm(); fso_connect_pim(); fso_connect_device(); /* send fsogsmd a ping to dbus-activate it, if not running yet */ /* if (fso.gsm_device) free_smartphone_gsm_device_get_device_status(fso.gsm_device, NULL, NULL);*/ g_debug("Done connecting to FSO"); return TRUE; } void fso_connect_usage() { g_debug("connecting to %s", FSO_USAGE_SERVICE); fso.usage = (FreeSmartphoneUsage *) (_dbus_proxy (FREE_SMARTPHONE_TYPE_USAGE_PROXY, FSO_USAGE_SERVICE, FSO_USAGE_PATH, FSO_USAGE_IFACE) ); if (fso.usage) { g_signal_connect(G_OBJECT(fso.usage), "resource-changed", G_CALLBACK(_usage_resource_changed_handler), NULL); g_signal_connect(G_OBJECT(fso.usage), "resource-available", G_CALLBACK(_usage_resource_available_handler), NULL); g_signal_connect(G_OBJECT(fso.usage), "system-action", G_CALLBACK(_usage_system_action_handler), NULL); g_debug("Connected to FSO/Usage"); } } void fso_connect_gsm() { g_debug("connecting to %s", FSO_GSM_SERVICE); fso.gsm_device = (FreeSmartphoneGSMDevice *) (_dbus_proxy (FREE_SMARTPHONE_GSM_TYPE_DEVICE_PROXY, FSO_GSM_SERVICE, FSO_GSM_DEVICE_PATH, FSO_GSM_DEVICE_IFACE) ); if (fso.gsm_device) { g_debug("Connected to FSO/GSM/Device"); g_signal_connect(G_OBJECT(fso.gsm_device), "device-status", G_CALLBACK(_gsm_device_status_handler), NULL); } fso.gsm_sim = (FreeSmartphoneGSMSIM *) (_dbus_proxy (FREE_SMARTPHONE_GSM_TYPE_SIM_PROXY, FSO_GSM_SERVICE, FSO_GSM_DEVICE_PATH, FSO_GSM_SIM_IFACE) ); fso.gsm_network = (FreeSmartphoneGSMNetwork *) (_dbus_proxy (FREE_SMARTPHONE_GSM_TYPE_NETWORK_PROXY, FSO_GSM_SERVICE, FSO_GSM_DEVICE_PATH, FSO_GSM_NETWORK_IFACE) ); if (fso.gsm_network) { g_signal_connect(G_OBJECT(fso.gsm_network), "status", G_CALLBACK(_gsm_network_status_handler), NULL); g_signal_connect(G_OBJECT(fso.gsm_network), "incoming-ussd", G_CALLBACK(_gsm_network_incoming_ussd_handler), NULL); g_debug("Connected to FSO/GSM/Network"); } fso.gsm_pdp = (FreeSmartphoneGSMPDP *) (_dbus_proxy (FREE_SMARTPHONE_GSM_TYPE_PDP_PROXY, FSO_GSM_SERVICE, FSO_GSM_DEVICE_PATH, FSO_GSM_PDP_IFACE) ); fso.gsm_call = (FreeSmartphoneGSMCall *) (_dbus_proxy (FREE_SMARTPHONE_GSM_TYPE_CALL_PROXY, FSO_GSM_SERVICE, FSO_GSM_DEVICE_PATH, FSO_GSM_CALL_IFACE) ); if (fso.gsm_call) { g_signal_connect(G_OBJECT(fso.gsm_call), "call-status", G_CALLBACK(_gsm_call_status_handler), NULL); g_debug("Connected to FSO/GSM/Call"); } } void fso_connect_pim() { g_debug("connecting to %s", FSO_PIM_SERVICE); fso.pim_messages = (FreeSmartphonePIMMessages *) (_dbus_proxy (FREE_SMARTPHONE_PIM_TYPE_MESSAGES_PROXY, FSO_PIM_SERVICE, FSO_PIM_MESSAGES_PATH, FSO_PIM_MESSAGES_IFACE) ); if (fso.pim_messages) { g_signal_connect(G_OBJECT(fso.pim_messages), "incoming-message", G_CALLBACK(_pim_incoming_message_handler), NULL); g_debug("Connected to FSO/PIM/Messages"); } } void fso_connect_device() { g_debug("connecting to %s", FSO_DEVICE_SERVICE); fso.idle_notifier = (FreeSmartphoneDeviceIdleNotifier *) (_dbus_proxy (FREE_SMARTPHONE_DEVICE_TYPE_IDLE_NOTIFIER_PROXY, FSO_DEVICE_SERVICE, FSO_DEVICE_IDLE_NOTIFIER_PATH, FSO_DEVICE_IDLE_NOTIFIER_IFACE) ); if (fso.idle_notifier) { g_signal_connect(G_OBJECT(fso.idle_notifier), "state", G_CALLBACK(_device_idle_notifier_state_handler), NULL); g_debug("Connected to FSO/Device/IdleNotifier"); } fso.input = (FreeSmartphoneDeviceInput *) (_dbus_proxy (FREE_SMARTPHONE_DEVICE_TYPE_INPUT_PROXY, FSO_DEVICE_SERVICE, FSO_DEVICE_INPUT_PATH, FSO_DEVICE_INPUT_IFACE) ); if (fso.input) { g_signal_connect(G_OBJECT(fso.input), "event", G_CALLBACK(_device_input_event_handler), NULL); g_debug("Connected to FSO/Device/Input"); } fso.display = (FreeSmartphoneDeviceDisplay *) (_dbus_proxy (FREE_SMARTPHONE_DEVICE_TYPE_DISPLAY_PROXY, FSO_DEVICE_SERVICE, FSO_DEVICE_DISPLAY_PATH, FSO_DEVICE_DISPLAY_IFACE) ); if (fso.display) { g_debug("Connected to FSO/Device/Display"); } fso.power_supply = (FreeSmartphoneDevicePowerSupply *) (_dbus_proxy (FREE_SMARTPHONE_DEVICE_TYPE_POWER_SUPPLY_PROXY, FSO_DEVICE_SERVICE, FSO_DEVICE_POWER_SUPPLY_PATH, FSO_DEVICE_POWER_SUPPLY_IFACE) ); if (fso.power_supply) { g_debug("Connected to FSO/Device/PowerSupply"); } } gboolean fso_startup() { g_debug("FSO starting up"); /* we only have to list the resources when we did * not yet handle it due to a resource available * signal for the GSM resource */ if (!gsm_request_running && !gsm_available) { _fso_list_resources(); } fso_dimit(100, DIM_SCREEN_ALWAYS); return FALSE; } static void _fso_dim_screen(int percent) { int b = default_brightness * percent / 100; if (b > 100) { b = 100; } else if (b < minimum_brightness) { b = 0; } free_smartphone_device_display_set_brightness (fso.display, b, NULL, NULL); if (b == 0) { phoneui_idle_screen_call_activate_screensaver (phoneui.idle_screen, NULL, phoneui_activate_screensaver_cb, NULL); } else { phoneui_idle_screen_call_deactivate_screensaver (phoneui.idle_screen, NULL, phoneui_deactivate_screensaver_cb, NULL); } } static void _get_power_status_for_dimming_callback(GObject *source, GAsyncResult *res, gpointer data) { (void) source; GError *error = NULL; FreeSmartphoneDevicePowerStatus status; status = free_smartphone_device_power_supply_get_power_status_finish (fso.power_supply, res, &error); g_debug("PowerStatus is %d", status); if (error == NULL && (status == FREE_SMARTPHONE_DEVICE_POWER_STATUS_AC || status == FREE_SMARTPHONE_DEVICE_POWER_STATUS_CHARGING)) { g_debug("not suspending due to charging or battery full"); return; } _fso_dim_screen(GPOINTER_TO_INT(data)); } void fso_dimit(int percent, int dim) { /* -1 means dimming disabled */ if (dim == DIM_SCREEN_NEVER || percent < 0) return; /* for dimming only on bat we have to check * if power is plugged in */ if (dim == DIM_SCREEN_ONBAT) { free_smartphone_device_power_supply_get_power_status (fso.power_supply, _get_power_status_for_dimming_callback, GINT_TO_POINTER(percent)); return; } _fso_dim_screen(percent); } gboolean fso_set_functionality() { if (offline_mode) { _stop_startup(); free_smartphone_gsm_device_set_functionality (fso.gsm_device, "airplane", FALSE, sim_pin ? sim_pin : "", _set_functionality_callback, NULL); } else { free_smartphone_gsm_device_set_functionality (fso.gsm_device, "full", TRUE, sim_pin ? sim_pin : "", _set_functionality_callback, NULL); } return FALSE; } void fso_pdp_set_credentials() { if (!pdp_apn || !pdp_user || !pdp_password) return; free_smartphone_gsm_pdp_set_credentials (fso.gsm_pdp, pdp_apn, pdp_user, pdp_password, NULL, NULL); } static gboolean _fso_list_resources() { free_smartphone_usage_list_resources(fso.usage, _list_resources_callback, NULL); return FALSE; } static gboolean _fso_request_gsm() { if (gsm_request_running) { /* do not request GSM twice */ g_warning("GSM request still running..."); } else if (gsm_available) { /* only request GSM if we know it is available */ g_debug("Request GSM resource"); gsm_request_running = TRUE; free_smartphone_usage_request_resource(fso.usage, "GSM", _request_resource_callback, NULL); } else { g_warning("Not requesting GSM as it is not available"); } _startup_check(); return FALSE; } static void _fso_suspend(void) { if (auto_suspend == SUSPEND_NEVER || startup_time > 0 || incoming_calls_size > 0 || outgoing_calls_size > 0) { return; } /* for normal suspend behaviour we have to check * if power is plugged in */ if (auto_suspend == SUSPEND_NORMAL) { free_smartphone_device_power_supply_get_power_status (fso.power_supply, _get_power_status_callback, NULL); return; } free_smartphone_usage_suspend(fso.usage, NULL, NULL); } static gint _fso_sim_info() { free_smartphone_gsm_sim_get_sim_info (fso.gsm_sim, _gsm_sim_sim_info_callback, NULL); return 0; } /* --- dbus callbacks --- */ static void _list_resources_callback(GObject *source, GAsyncResult *res, gpointer data) { char **resources; int count; GError *error = NULL; /* if we successfully got a list of resources... * check if GSM is within them and request it if * so, otherwise wait for ResourceAvailable signal */ g_debug("list_resources_callback()"); resources = free_smartphone_usage_list_resources_finish (fso.usage, res, &count, &error); _startup_check(); if (error) { if (error->code == G_DBUS_ERROR_SERVICE_UNKNOWN) { g_critical("fsousaged not installed: %s", error->message); } else { g_message("error - retrying in 1s: (%d) %s", error->code, error->message); g_timeout_add(1000, _fso_list_resources, NULL); } g_error_free(error); return; } if (resources) { int i = 0; while (resources[i] != NULL) { g_debug("Resource %s available", resources[i]); if (!strcmp(resources[i], "GSM")) { gsm_available = TRUE; break; } i++; } if (gsm_available) _fso_request_gsm(); } } static void _request_resource_callback(GObject *source, GAsyncResult *res, gpointer data) { (void) data; GError *error = NULL; g_debug("_request_resource_callback()"); gsm_request_running = FALSE; _startup_check(); free_smartphone_usage_request_resource_finish(fso.usage, res, &error); if (error == NULL) { /* nothing to do when there is no error * the signal handler for ResourceChanged * will do the rest */ return; } if (error->domain == FREE_SMARTPHONE_USAGE_ERROR && error->code == FREE_SMARTPHONE_USAGE_ERROR_USER_EXISTS) { g_message("we already requested GSM!!!"); return; } /* we only request the GSM resource if it is actually * available... if this does not work we retry it after * some timeout ... */ g_debug("request resource error, try again in 1s"); g_debug("error: %s %s %d", error->message, g_quark_to_string(error->domain), error->code); g_timeout_add(1000, _fso_request_gsm, NULL); } static void _set_functionality_callback(GObject *source, GAsyncResult *res, gpointer data) { (void) data; GError *error = NULL; free_smartphone_gsm_device_set_functionality_finish(fso.gsm_device, res, &error); if (error) { g_warning("SetFunctionality gave an error: %s", error->message); _startup_check(); g_error_free(error); return; } func_is_set = TRUE; } static void _get_power_status_callback(GObject *source, GAsyncResult *res, gpointer data) { (void) source; (void) data; GError *error = NULL; FreeSmartphoneDevicePowerStatus status; status = free_smartphone_device_power_supply_get_power_status_finish (fso.power_supply, res, &error); g_debug("PowerStatus is %d", status); if (error == NULL && (status == FREE_SMARTPHONE_DEVICE_POWER_STATUS_AC || status == FREE_SMARTPHONE_DEVICE_POWER_STATUS_CHARGING)) { g_debug("not suspending due to charging or battery full"); return; } free_smartphone_usage_suspend(fso.usage, NULL, NULL); } static void _get_idle_state_callback(GObject* source, GAsyncResult* res, gpointer data) { (void) source; (void) data; GError *error = NULL; FreeSmartphoneDeviceIdleState state; state = free_smartphone_device_idle_notifier_get_state_finish (fso.idle_notifier, res, &error); if (error) { g_warning("IdleState error: (%d) %s", error->code, error->message); g_error_free(error); return; } g_debug("Current IdleState is %s", free_smartphone_device_idle_state_to_string(state)); if (state == FREE_SMARTPHONE_DEVICE_IDLE_STATE_SUSPEND) { _fso_suspend(); } } static void _gsm_sim_sim_info_callback(GObject* source, GAsyncResult* res, gpointer data) { (void) source; (void) data; GError *error = NULL; GHashTable *info; int slots_total = -1, slots_used = -1; GVariant *tmp; info = free_smartphone_gsm_sim_get_sim_info_finish(fso.gsm_sim, res, &error); if (error) { g_warning("Failed getting SIM info: (%d) %s", error->code, error->message); g_error_free(error); return; } tmp = g_hash_table_lookup(info, "slots"); if (tmp) { slots_total = g_variant_get_int32(tmp); g_debug("SimInfo has slots total = %d", slots_total); } tmp = g_hash_table_lookup(info, "used"); if (tmp) { slots_used = g_variant_get_int32(tmp); g_debug("SimInfo has slots used = %d", slots_used); } if (slots_total == -1 || slots_used == -1) { g_debug("SimInfo has no slots and/or used properties - retrying later"); g_timeout_add_seconds(3, _fso_sim_info, NULL); } else { sim_check_needed = FALSE; if (slots_total - slots_used < MIN_SIM_SLOTS_FREE) { g_message("No more free slots for messages on SIM!"); // TODO: verify if one free slot is needed for receiving // messages and remove this dialog if not phoneui_notification_call_display_dialog (phoneui.notification, PHONEUI_DIALOG_MESSAGE_STORAGE_FULL, NULL, phoneui_show_dialog_cb, NULL); } else { g_debug("SIM has %d free slots for messages", slots_total - slots_used); } } g_hash_table_unref(info); } /* dbus signal handlers */ static void _usage_resource_available_handler(GSource *source, char *name, gboolean availability, gpointer data) { (void) source; (void) data; g_debug("resource %s is now %s", name, availability ? "available" : "vanished"); if (strcmp(name, "GSM") == 0) { gsm_available = availability; if (gsm_available) { _fso_request_gsm(); } else { gsm_request_running = FALSE; } } } static void _gsm_device_status_callback(GObject* source, GAsyncResult* res, gpointer data) { GError *error = NULL; FreeSmartphoneGSMDeviceStatus status; status = free_smartphone_gsm_device_get_device_status_finish ((FreeSmartphoneGSMDevice *)source, res, &error); if (error) { g_warning("%d: %s", error->code, error->message); g_error_free(error); return; } _gsm_device_status_handler(NULL, status, NULL); } static void _usage_resource_changed_handler(GSource *source, char *name, gboolean state, GHashTable * attributes, gpointer data) { (void) source; (void) data; GVariant *tmp; g_debug("resource %s is now %s", name, state ? "enabled" : "disabled"); tmp = g_hash_table_lookup(attributes, "policy"); if (tmp) g_debug(" policy: %s", g_variant_get_string(tmp, NULL)); tmp = g_hash_table_lookup(attributes, "refcount"); if (tmp) g_debug(" refcount: %d", g_variant_get_int32(tmp)); if (strcmp(name, "Display") == 0) { g_debug("Display state state changed: %s", state ? "enabled" : "disabled"); display_state = state; /* if something requests the Display resource we have * to undim it */ if (display_state) { fso_dimit(100, DIM_SCREEN_ALWAYS); } return; } if (strcmp(name, "GSM") == 0) { free_smartphone_gsm_device_get_device_status (fso.gsm_device, _gsm_device_status_callback, NULL); return; } } static void _usage_system_action_handler(GSource *source, FreeSmartphoneUsageSystemAction action, gpointer data) { g_debug("SystemAction: %d", action); /* show the IdleScreen if configured to do so on suspend */ if (action == FREE_SMARTPHONE_USAGE_SYSTEM_ACTION_SUSPEND && idle_screen & IDLE_SCREEN_SUSPEND) { phoneui_idle_screen_call_display (phoneui.idle_screen, NULL, phoneui_show_idle_cb, NULL); } } static void _device_idle_notifier_state_handler(GSource *source, FreeSmartphoneDeviceIdleState state, gpointer data) { (void) source; (void) data; /* while Display resource is requested nothing to do */ if (display_state && state != FREE_SMARTPHONE_DEVICE_IDLE_STATE_BUSY) { g_debug("Not handling Idle while Display is requested"); return; } switch (state) { case FREE_SMARTPHONE_DEVICE_IDLE_STATE_BUSY: fso_dimit(100, dim_screen); break; case FREE_SMARTPHONE_DEVICE_IDLE_STATE_IDLE: fso_dimit(dim_idle_percent, dim_screen); break; case FREE_SMARTPHONE_DEVICE_IDLE_STATE_IDLE_DIM: fso_dimit(dim_idle_dim_percent, dim_screen); break; case FREE_SMARTPHONE_DEVICE_IDLE_STATE_IDLE_PRELOCK: fso_dimit(dim_idle_prelock_percent, dim_screen); break; case FREE_SMARTPHONE_DEVICE_IDLE_STATE_LOCK: if (idle_screen & IDLE_SCREEN_LOCK && ((idle_screen & IDLE_SCREEN_PHONE) || ((incoming_calls_size == 0) && (outgoing_calls_size == 0)))) { phoneui_idle_screen_call_display (phoneui.idle_screen, NULL, phoneui_show_idle_cb, NULL); } break; case FREE_SMARTPHONE_DEVICE_IDLE_STATE_SUSPEND: _fso_suspend(); break; } } static void _device_input_event_handler(GSource *source, char *src, FreeSmartphoneDeviceInputState state, int duration, gpointer data) { (void) source; (void) data; g_debug("INPUT EVENT: %s - %d - %d", src, state, duration); if (idle_screen & IDLE_SCREEN_AUX && !strcmp(src, "AUX") && state == FREE_SMARTPHONE_DEVICE_INPUT_STATE_RELEASED) { phoneui_idle_screen_call_toggle(phoneui.idle_screen, NULL, phoneui_toggle_idle_cb, NULL); } if (quick_settings_power && !strcmp(src, "POWER") && state == FREE_SMARTPHONE_DEVICE_INPUT_STATE_RELEASED) { phoneui_settings_call_display_quick_settings(phoneui.settings, NULL, phoneui_show_quick_settings_cb, NULL); } } static void _gsm_call_status_handler(GSource *source, int call_id, int status, GHashTable *properties, gpointer data) { g_debug("call status handler called, id: %d, status: %d", call_id, status); GVariant *peerNumber = g_hash_table_lookup(properties, "peer"); gchar *number; if (peerNumber != NULL) { gsize len; number = g_variant_dup_string(peerNumber, &len); /* FIXME: fix the ugly " bug * we potentially waste a couple of bytes, fix it in a normal manner*/ if (number[0] == '"') { gchar *tmp; tmp = strdup(number); strcpy(number, &tmp[1]); len--; } if (len > 0 && number[len - 1] == '"') { number[len - 1] = '\0'; } } else { number = "*****"; } switch (status) { case FREE_SMARTPHONE_GSM_CALL_STATUS_INCOMING: g_debug("incoming call"); if (_call_check(incoming_calls, &incoming_calls_size, call_id) == -1) { _call_add(&incoming_calls, &incoming_calls_size, call_id); fso_dimit(100, DIM_SCREEN_ALWAYS); free_smartphone_usage_request_resource (fso.usage, "CPU", NULL, NULL); phoneui_call_management_call_display_incoming (phoneui.call_management, call_id, status, number, NULL, phoneui_show_incoming_cb, NULL); } break; case FREE_SMARTPHONE_GSM_CALL_STATUS_OUTGOING: g_debug("outgoing call"); if (_call_check(outgoing_calls, &outgoing_calls_size, call_id) == -1) { _call_add(&outgoing_calls, &outgoing_calls_size, call_id); free_smartphone_usage_request_resource (fso.usage, "CPU", NULL, NULL); phoneui_call_management_call_display_outgoing (phoneui.call_management, call_id, status, number, NULL, phoneui_show_outgoing_cb, NULL); } break; case FREE_SMARTPHONE_GSM_CALL_STATUS_RELEASE: g_debug("release call"); if (_call_check(incoming_calls, &incoming_calls_size, call_id) != -1) { _call_remove(&incoming_calls, &incoming_calls_size, call_id); phoneui_call_management_call_hide_incoming (phoneui.call_management, call_id, NULL, phoneui_hide_incoming_cb, NULL); } if (_call_check(outgoing_calls, &outgoing_calls_size, call_id) != -1) { _call_remove(&outgoing_calls, &outgoing_calls_size, call_id); phoneui_call_management_call_hide_outgoing (phoneui.call_management, call_id, NULL, phoneui_hide_outgoing_cb, NULL); } if (incoming_calls_size == 0 && outgoing_calls_size == 0) { free_smartphone_usage_release_resource (fso.usage, "CPU", NULL, NULL); } break; case FREE_SMARTPHONE_GSM_CALL_STATUS_HELD: g_debug("held call"); break; case FREE_SMARTPHONE_GSM_CALL_STATUS_ACTIVE: g_debug("active call"); break; default: g_debug("Unknown CallStatus"); break; } } static void _gsm_device_status_handler(GSource *source, FreeSmartphoneGSMDeviceStatus status, gpointer data) { (void) data; (void) source; g_debug("_gsm_device_status_handler: status=%s", free_smartphone_gsm_device_status_to_string(status)); if (status == FREE_SMARTPHONE_GSM_DEVICE_STATUS_ALIVE_NO_SIM) { if (show_sim_not_present) { phoneui_notification_call_display_dialog (phoneui.notification, PHONEUI_DIALOG_SIM_NOT_PRESENT, NULL, phoneui_show_dialog_cb, NULL); show_sim_not_present = FALSE; } } else if (status == FREE_SMARTPHONE_GSM_DEVICE_STATUS_ALIVE_SIM_LOCKED) { if (sim_pin) { fso_set_functionality(); } else { g_debug("SIM auth needed... showing PIN dialog"); sim_auth_needed = TRUE; phoneui_notification_call_display_sim_auth (phoneui.notification, status, NULL, phoneui_show_sim_auth_cb, NULL); } } else if (status == FREE_SMARTPHONE_GSM_DEVICE_STATUS_ALIVE_SIM_READY) { g_debug("SIM is alive-sim-ready"); sim_auth_needed = FALSE; if (!func_is_set) { fso_set_functionality(); } if (sim_check_needed) { g_timeout_add_seconds(2, _fso_sim_info, NULL); } } else if (status == FREE_SMARTPHONE_GSM_DEVICE_STATUS_ALIVE_REGISTERED) { g_debug("alive-registered"); fso_pdp_set_credentials(); free_smartphone_gsm_network_set_calling_identification (fso.gsm_network, calling_identification, NULL, NULL); } } static void _pim_incoming_message_handler(GSource *source, char *message_path, gpointer data) { (void) source; (void) data; g_debug("fso_incoming_message_handler(%s)", message_path); if (show_incoming_sms) { phoneui_messages_call_display_message (phoneui.messages, message_path, NULL, phoneui_display_message_cb, NULL); } /* check if there is still a free slot for the next SMS */ free_smartphone_gsm_sim_get_sim_info (fso.gsm_sim, _gsm_sim_sim_info_callback, NULL); } static void _gsm_network_incoming_ussd_handler(GSource *source, int mode, char *message, gpointer data) { (void) source; (void) data; g_debug("fso_incoming_ussd_handler(mode=%d, message=%s)", mode, message); phoneui_notification_call_display_ussd (phoneui.notification, mode, message, NULL, phoneui_show_ussd_cb, NULL); } static void _gsm_network_status_handler(GSource *source, GHashTable *status, gpointer data) { (void) source; (void) data; if (!status) { g_debug("got no status from NetworkStatus?!"); return; } /* right now we use this signal only to check if it registered on startup to reset the startup time... nothing to do if it is already reset */ if (startup_time == -1) { return; } GVariant *tmp = g_hash_table_lookup(status, "registration"); if (tmp) { const char *registration = g_variant_get_string(tmp, NULL); g_debug("fso_network_status_handler(registration=%s)", registration); if (strcmp(registration, "unregistered")) { g_message("Ending startup phase due to successfull registration"); _stop_startup(); return; } } else { g_debug("got NetworkStatus without registration?!?"); } _startup_check(); } static void _stop_startup() { startup_time = -1; /* we have to check the current idle state... and if it is suspend then we have to suspend... otherwise it would never suspend without touching the screen */ g_debug("Getting current IdleState to see if we have to suspend"); free_smartphone_device_idle_notifier_get_state(fso.idle_notifier, _get_idle_state_callback, NULL); } static void _startup_check() { time_t now; if (startup_time == -1) { return; } now = time(NULL); if (now - startup_time > inhibit_suspend_on_startup_time) { g_message("Ending startup phase due to time out"); _stop_startup(); } } /* call management */ static void _call_add(call_t ** calls, int *size, int id) { g_debug("_call_add(%d)", id); (*size)++; if (*size == 1) *calls = malloc(sizeof(call_t)); else *calls = realloc(*calls, sizeof(call_t) * (*size)); (*calls)[(*size) - 1].id = id; } static int _call_check(call_t * calls, int *size, int id) { int i; g_debug("_call_check(%d)", id); for (i = 0; i < (*size); i++) { if (calls[i].id == id) return i; } return -1; } static void _call_remove(call_t ** calls, int *size, int id) { g_debug("_call_remove(%d)", id); if (*size == 1) { free(*calls); (*size)--; *calls = NULL; } else { int place = _call_check(*calls, size, id); if (place >= 0) { int i = place; for (i = place; i + 1 < (*size); i++) { (*calls)[i].id = (*calls)[i + 1].id; } (*size)--; *calls = realloc(*calls, sizeof(call_t) * (*size)); } } } phonefsod-0.1+git20121018/src/phonefsod-fso.h000066400000000000000000000020241204004225500204370ustar00rootroot00000000000000/* * Copyright (C) 2009-2010 * Authors (alphabetical) : * Klaus 'mrmoku' Kurzmann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Public License as published by * the Free Software Foundation; version 2 of the license or any later version. * * 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. See the * GNU Lesser Public License for more details. */ #ifndef _PHONEFSOD_FSO_H #define _PHONEFSOD_FSO_H #include gboolean fso_init(); void fso_connect_usage(); void fso_connect_gsm(); void fso_connect_pim(); void fso_connect_device(); gboolean fso_startup(); void fso_dimit(int percent, int dim); void fso_get_resource_state(const char *resource, void (*callback)(GError *, gboolean, gpointer), gpointer data); gboolean fso_set_functionality(); void fso_pdp_set_credentials(); #endif phonefsod-0.1+git20121018/src/phonefsod-globals.h000066400000000000000000000034151204004225500213000ustar00rootroot00000000000000/* * Copyright (C) 2009-2012 * Authors (alphabetical) : * Klaus 'mrmoku' Kurzmann * Lukas 'slyon' Märdian * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Public License as published by * the Free Software Foundation; version 2 of the license or any later version. * * 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. See the * GNU Lesser Public License for more details. */ #ifndef _PHONEFSOD_GLOBALS_H #define _PHONEFSOD_GLOBALS_H #include #include #include gboolean offline_mode; gboolean quick_settings_power; gboolean sim_auth_needed; int inhibit_suspend_on_startup_time; gboolean show_incoming_sms; int gsm_reregister_timeout; FreeSmartphoneGSMCallingIdentificationStatus calling_identification; char *pdp_apn; char *pdp_user; char *pdp_password; char *sim_pin; int default_brightness; int minimum_brightness; int dim_idle_percent; int dim_idle_dim_percent; int dim_idle_prelock_percent; enum DimScreenMode { DIM_SCREEN_NEVER, DIM_SCREEN_ONBAT, DIM_SCREEN_ALWAYS } dim_screen; enum IdleScreenMode { IDLE_SCREEN_NEVER = 0, IDLE_SCREEN_AUX = 1, IDLE_SCREEN_LOCK = 2, IDLE_SCREEN_PHONE = 4, IDLE_SCREEN_SUSPEND = 8 } idle_screen; enum AutoSuspendMode { SUSPEND_NEVER = 0, SUSPEND_NORMAL, SUSPEND_ALWAYS } auto_suspend; GDBusConnection *system_bus; struct SPhoneui { PhoneuiCallManagement *call_management; PhoneuiMessages *messages; PhoneuiNotification *notification; PhoneuiIdleScreen *idle_screen; PhoneuiSettings *settings; } phoneui; #endif phonefsod-0.1+git20121018/src/phonefsod.c000066400000000000000000000552311204004225500176550ustar00rootroot00000000000000/* * Copyright (C) 2009-2012 * Authors (alphabetical) : * Klaus 'mrmoku' Kurzmann * Lukas 'slyon' Märdian * * glib daemon framework * James Scott Jr. * Copyright (C) 2008 James Scott, Jr. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Public License as published by * the Free Software Foundation; version 2 of the license or any later version. * * 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. See the * GNU Lesser Public License for more details. */ #include #include #include /* umask() */ #include /* umask() */ #include /* open() */ #include #include /* daemon(), sleep(), exit() */ #include #include #include #include #include #include #include #include #include "phonefsod-dbus.h" #include "phonefsod-fso.h" #include "phonefsod-globals.h" /* Program Standards passed from compiler */ #ifndef PACKAGE_VERSION #define PACKAGE_VERSION "0.1.0" #endif #ifndef PACKAGE_NAME #define PACKAGE_NAME "phonefsod" #endif #ifndef PACKAGE_PIDFILE #define PACKAGE_PIDFILE "/var/run/"PACKAGE_NAME".pid" #endif #ifndef EXIT_ERROR #define EXIT_ERROR -1 #endif // FIXME: ugly !!! #define LOGFILE "/var/log/phonefsod.log" #define DEFAULT_DEBUG_LEVEL "INFO" /* defines for config defaults */ #define MINIMUM_GSM_REREGISTER_TIMEOUT 60 #define DEFAULT_GSM_REREGISTER_TIMEOUT 200 #define DEFAULT_DEFAULT_BRIGHTNESS 100 #define DEFAULT_MINIMUM_BRIGHTNESS 10 /* global variable used to indicate that * program exit is desired 1=run, 0=exit */ static volatile gint gd_flag_exit = 1; /* Target user id */ static gchar *gd_pch_effective_userid = NULL; /* PID Filename */ static gchar *gd_pch_pid_filename = NULL; /* Debug flag */ static gint i_debug = 0; /* Force overwrite of pidfile */ static gboolean gd_b_force = FALSE; /* Version flag */ static gboolean gd_b_version = FALSE; /* file stream for the logfile */ static FILE *logfile = NULL; /* handle for notification on config changes */ static int notify; static GLogLevelFlags log_flags; /* Local Routines */ static gpointer _thread_handle_signals(gpointer arg); static gint _process_signals(siginfo_t *signal_info); static gint _handle_command_line(int argc, char **argv, GOptionContext **context); static gint _daemonize(gchar *pidfilename); static void _log_handler(const gchar *domain, GLogLevelFlags level, const gchar *message, gpointer userdata); extern int main (int argc, char *argv[]); static void _log_handler(const gchar *domain, GLogLevelFlags level, const gchar *message, gpointer userdata) { char *levelstr; char date_str[30]; struct timeval tv; struct tm ptime; if (!(log_flags & G_LOG_LEVEL_MASK & level)) { return; } gettimeofday(&tv, NULL); localtime_r(&tv.tv_sec, &ptime); strftime(date_str, 30, "%Y.%m.%d %T", &ptime); switch (level) { case G_LOG_LEVEL_ERROR: levelstr = "ERROR"; break; case G_LOG_LEVEL_CRITICAL: levelstr = "CRITICAL"; break; case G_LOG_LEVEL_WARNING: levelstr = "WARNING"; break; case G_LOG_LEVEL_MESSAGE: levelstr = "MESSAGE"; break; case G_LOG_LEVEL_INFO: levelstr = "INFO"; break; case G_LOG_LEVEL_DEBUG: levelstr = "DEBUG"; break; default: levelstr = ""; break; } fprintf(logfile, "%s.%06d [%s]\t%s: %s\n", date_str, (int) tv.tv_usec, domain, levelstr, message); fflush(logfile); } static void _load_config() { GKeyFile *keyfile; GKeyFileFlags flags; GError *error = NULL; char *debug_level = NULL; char *logpath = NULL; char *s = NULL; /* Read the phonefsod preferences */ keyfile = g_key_file_new(); flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS; if (g_key_file_load_from_file (keyfile, PHONEFSOD_CONFIG, flags, &error)) { /* --- [logging] --- */ logpath = g_key_file_get_string(keyfile, "logging", "log_file", NULL); debug_level = g_key_file_get_string(keyfile, "logging", "log_level", NULL); /* --- [gsm] --- */ offline_mode = g_key_file_get_boolean(keyfile, "gsm", "offline_mode", &error); if (error) { offline_mode = FALSE; g_error_free(error); error = NULL; } inhibit_suspend_on_startup_time = g_key_file_get_integer(keyfile, "gsm", "inhibit_suspend_on_startup_time", &error); if (error) { inhibit_suspend_on_startup_time = 360; g_error_free(error); error = NULL; } show_incoming_sms = g_key_file_get_boolean(keyfile, "gsm", "show_incoming_sms", &error); if (error) { show_incoming_sms = TRUE; g_error_free(error); error = NULL; } gsm_reregister_timeout = g_key_file_get_integer(keyfile, "gsm", "reregister_timeout", &error); if (error) { gsm_reregister_timeout = DEFAULT_GSM_REREGISTER_TIMEOUT; g_error_free(error); error = NULL; } /* ensure a sane value for the timeout... minimum is 60s */ else if (gsm_reregister_timeout < MINIMUM_GSM_REREGISTER_TIMEOUT) { g_message("invalid reregister_timeout - setting to %ds", MINIMUM_GSM_REREGISTER_TIMEOUT); gsm_reregister_timeout = MINIMUM_GSM_REREGISTER_TIMEOUT; } s = g_key_file_get_string(keyfile, "gsm", "calling_identification", &error); if (error) { calling_identification = FREE_SMARTPHONE_GSM_CALLING_IDENTIFICATION_STATUS_NETWORK; g_error_free(error); error = NULL; } else { if (!strncmp("off", s, 3)) { calling_identification = FREE_SMARTPHONE_GSM_CALLING_IDENTIFICATION_STATUS_OFF; } else if (!strncmp("on", s, 2)) { calling_identification = FREE_SMARTPHONE_GSM_CALLING_IDENTIFICATION_STATUS_ON; } else if (!strncmp("network", s, 7)) { calling_identification = FREE_SMARTPHONE_GSM_CALLING_IDENTIFICATION_STATUS_NETWORK; } else { g_warning("Invalid value '%s' for calling_identification in [gsm] section of %s", s, PHONEFSOD_CONFIG); g_message("Defaulting to network"); calling_identification = FREE_SMARTPHONE_GSM_CALLING_IDENTIFICATION_STATUS_NETWORK; } } pdp_apn = g_key_file_get_string(keyfile, "gsm", "pdp_apn", &error); if (error) { g_error_free(error); error = NULL; } pdp_user = g_key_file_get_string(keyfile, "gsm", "pdp_user", &error); if (error) { g_error_free(error); error = NULL; } pdp_password = g_key_file_get_string(keyfile, "gsm", "pdp_password", &error); if (error) { g_error_free(error); error = NULL; } sim_pin = g_key_file_get_string(keyfile, "gsm", "pin", &error); if (error) { g_error_free(error); error = NULL; } /* --- [idle] --- */ default_brightness = g_key_file_get_integer(keyfile, "idle", "default_brightness", &error); if (error) { default_brightness = DEFAULT_DEFAULT_BRIGHTNESS; g_error_free(error); error = NULL; } s = g_key_file_get_string(keyfile, "idle", "dim_screen", &error); if (error) { dim_screen = DIM_SCREEN_ALWAYS; g_error_free(error); error = NULL; } else { if (!strncmp("never", s, 5)) { dim_screen = DIM_SCREEN_NEVER; } else if (!strncmp("onbat", s, 5)) { dim_screen = DIM_SCREEN_ONBAT; } else if (!strncmp("always", s, 6)) { dim_screen = DIM_SCREEN_ALWAYS; } else { g_warning("Invalid value '%s' for dim_screen in [idle] section of %s", s, PHONEFSOD_CONFIG); g_message("Defaulting to DIM_SCREEN_ALWAYS"); dim_screen = DIM_SCREEN_ALWAYS; } } minimum_brightness = g_key_file_get_integer(keyfile, "idle", "minimum_brightness", &error); if (error) { minimum_brightness = DEFAULT_MINIMUM_BRIGHTNESS; g_error_free(error); error = NULL; } dim_idle_percent = g_key_file_get_integer(keyfile, "idle", "dim_idle_percent", &error); if (error) { dim_idle_percent = -1; g_error_free(error); error = NULL; } dim_idle_dim_percent = g_key_file_get_integer(keyfile, "idle", "dim_idle_dim_percent", &error); if (error) { dim_idle_dim_percent = -1; g_error_free(error); error = NULL; } dim_idle_prelock_percent = g_key_file_get_integer(keyfile, "idle", "dim_idle_prelock_percent", &error); if (error) { dim_idle_prelock_percent = -1; g_error_free(error); error = NULL; } s = g_key_file_get_string(keyfile, "idle", "idle_screen", &error); if (error) { g_debug("no idle_screen found in config - defaulting to lock,aux,suspend"); idle_screen = IDLE_SCREEN_LOCK | IDLE_SCREEN_AUX | IDLE_SCREEN_SUSPEND; g_error_free(error); error = NULL; } else { int i; gchar **flags = g_strsplit(s, ",", 0); idle_screen = IDLE_SCREEN_NEVER; for (i = 0; flags[i]; i++) { if (strcmp(flags[i], "lock") == 0) { g_debug("adding LOCK to idle_screen"); idle_screen |= IDLE_SCREEN_LOCK; } else if (strcmp(flags[i], "aux") == 0) { g_debug("adding AUX to idle_scren"); idle_screen |= IDLE_SCREEN_AUX; } else if (strcmp(flags[i], "phone") == 0) { g_debug("adding PHONE to idle_screen"); idle_screen |= IDLE_SCREEN_PHONE; } else if (strcmp(flags[i], "suspend") == 0) { g_debug("adding SUSPEND to idle_screen"); idle_screen |= IDLE_SCREEN_SUSPEND; } } g_strfreev(flags); free(s); } s = g_key_file_get_string(keyfile, "idle", "auto_suspend", &error); if (error) { auto_suspend = SUSPEND_NORMAL; g_error_free(error); error = NULL; } else if (strcmp(s, "never") == 0) { auto_suspend = SUSPEND_NEVER; } else if (strcmp(s, "always") == 0) { auto_suspend = SUSPEND_ALWAYS; } else { auto_suspend = SUSPEND_NORMAL; } /* --- [settings] --- */ quick_settings_power = g_key_file_get_boolean(keyfile, "settings", "quick_settings_power", &error); if (error) { quick_settings_power = FALSE; g_error_free(error); error = NULL; } if (s) free(s); g_debug("Configuration file read"); } else { g_warning(error->message); g_error_free(error); } debug_level = (debug_level) ? debug_level : DEFAULT_DEBUG_LEVEL; logpath = (logpath) ? logpath : LOGFILE; log_flags = G_LOG_FLAG_FATAL; if (!strcmp(debug_level, "DEBUG")) { log_flags |= G_LOG_LEVEL_MASK; } else if (!strcmp(debug_level, "INFO")) { log_flags |= G_LOG_LEVEL_MASK ^ (G_LOG_LEVEL_DEBUG); } else if (!strcmp(debug_level, "MESSAGE")) { log_flags |= G_LOG_LEVEL_MASK ^ (G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO); } else if (!strcmp(debug_level, "WARNING")) { log_flags |= G_LOG_LEVEL_MASK ^ (G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO | G_LOG_LEVEL_MESSAGE); } else if (!strcmp(debug_level, "CRITICAL")) { log_flags |= G_LOG_LEVEL_MASK ^ (G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_WARNING); } else if (!strcmp(debug_level, "ERROR")) { log_flags |= G_LOG_LEVEL_MASK ^ (G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL); } else { } /* initialize logging */ logfile = fopen(logpath, "a"); if (!logfile) { printf("Error creating the logfile (%s) !!!", logpath); } else { g_log_set_default_handler(_log_handler, NULL); } } static void _reload_config() { g_debug("reloading configuration"); _load_config(); } /* * _process_signals() * * Handle/Process linux signals for the whole multi-threaded application. * * Params: * sig -- current linux signal * * Returns/Affects: * returns current value of the atomic int gd_flag_exit * returns true (or current value) if nothing needs done * returns 0 or false if exit is required */ static gint _process_signals ( siginfo_t *signal_info) { int rval = g_atomic_int_get(&gd_flag_exit); /* use existing value */ gint sig = 0; gchar *pch = ""; g_return_val_if_fail (signal_info != NULL, 0); sig = signal_info->si_signo; /* look to see what signal has been caught */ switch ( sig ) { case SIGHUP: /* often used to reload configuration */ case SIGUSR1: /* Any user function */ switch (signal_info->si_code) { case SI_USER: pch="kill(2) or raise(3)"; break; case SI_KERNEL: pch="Sent by the kernel."; break; case SI_QUEUE: pch="sigqueue(2)"; break; case SI_TIMER: pch="POSIX timer expired"; break; case SI_MESGQ: pch="POSIX message queue state changed"; break; case SI_ASYNCIO: pch="AIO completed"; break; case SI_SIGIO: pch="queued SIGIO"; break; case SI_TKILL: pch="tkill(2) or tgkill(2)"; break; default: pch = ""; break; } g_debug("%s received from => %s ?[pid=%d, uid=%d]{Ignored}", g_strsignal(sig), pch, signal_info->si_pid,signal_info->si_uid); break; case SIGCHLD: /* some child ended */ switch (signal_info->si_code) { case CLD_EXITED: pch = "child has exited"; break; case CLD_KILLED: pch = "child was killed"; break; case CLD_DUMPED: pch = "child terminated abnormally"; break; case CLD_TRAPPED: pch = "traced child has trapped"; break; case CLD_STOPPED: pch = "child has stopped"; break; case CLD_CONTINUED: pch = "stopped child has continued"; break; default: pch = ""; break; } g_debug("%s received for pid => %d, w/rc => %d for this reason => %s {Ignored}", g_strsignal(sig), signal_info->si_pid, signal_info->si_status, pch); break; case SIGQUIT: /* often used to signal an orderly shutdown */ case SIGINT: /* often used to signal an orderly shutdown */ case SIGPWR: /* Power Failure */ case SIGKILL: /* Fatal Exit flag */ case SIGTERM: /* Immediately Fatal Exit flag */ switch (signal_info->si_code) { case SI_USER: pch="kill(2) or raise(3)"; break; case SI_KERNEL: pch="Sent by the kernel."; break; case SI_QUEUE: pch="sigqueue(2)"; break; case SI_TIMER: pch="POSIX timer expired"; break; case SI_MESGQ: pch="POSIX message queue state changed"; break; case SI_ASYNCIO: pch="AIO completed"; break; case SI_SIGIO: pch="queued SIGIO"; break; case SI_TKILL: pch="tkill(2) or tgkill(2)"; break; default: pch = ""; break; } g_debug("%s received from => %s ?[pid=%d, uid=%d]{Exiting}", g_strsignal(sig), pch, signal_info->si_pid, signal_info->si_uid); rval = 0; break; default: g_debug("%s received => {Ignored}", g_strsignal(sig)); break; } /* end switch */ return (rval); } /* * _thread_handle_signals() * * Trap linux signals for the whole multi-threaded application. * * Params: * main_loop -- closing this shuts down the app orderly * * Returns/Affects: * returns and/or set the atomic gint gd_flag_exit * returns last signal */ static gpointer _thread_handle_signals(gpointer main_loop) { sigset_t signal_set; siginfo_t signal_info; gint sig = 0; gint rval = 0; sigfillset (&signal_set); g_debug("signal handler: startup successful"); while (g_atomic_int_get(&gd_flag_exit)) { /* wait for any and all signals */ sig = sigwaitinfo (&signal_set, &signal_info); if (!sig) { g_message("signal handler: sigwaitinfo() returned an error => {%s}", g_strerror(errno)); continue; } /* when we get this far, we've caught a signal */ rval = _process_signals ( &signal_info ); g_atomic_int_set(&gd_flag_exit, rval); } /* end-while */ g_main_loop_quit(main_loop); pthread_sigmask (SIG_UNBLOCK, &signal_set, NULL); g_debug("signal handler: shutdown complete"); g_thread_exit ( GINT_TO_POINTER(sig) ); return (NULL); } /* * _handle_command_line() * * Parse out the command line options from argc,argv * gdaemon_glib [-u|--userid name] [-f|--forcepid] [-p|--pidfile fname] * [-d|--debug XX] [-v|--version] [-h|--help] * * Returns: TRUE if all params where handled * FALSE is any error occurs or an option required shutdown */ static gint _handle_command_line(int argc, char **argv, GOptionContext **context) { GError *gerror = NULL; GOptionEntry entries[] = { {"userid", 'u', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &gd_pch_effective_userid, "Runtime userid", "name"}, {"pidfile", 'p', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &gd_pch_pid_filename, "PID Filename", PACKAGE_PIDFILE}, {"debug", 'd', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT, &i_debug, "Turn on debug messages", "[0|1]"}, {"forcepid", 'f', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &gd_b_force, "Force overwite of pid file", "cleanup after prior errors"}, {"version", 'v', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &gd_b_version, "Program version info", NULL}, {NULL} }; /* Get command line parms */ *context = g_option_context_new (" => SHR Phone FSO Daemon"); g_option_context_add_main_entries(*context, entries, NULL); g_option_context_set_ignore_unknown_options(*context, FALSE); if (!(g_option_context_parse(*context, &argc, &argv, &gerror))) { g_warning ("Parse command line failed: %s", gerror->message); g_option_context_free(*context); g_error_free(gerror); g_atomic_int_set(&gd_flag_exit, 0); /* flag an exit */ return (EXIT_FAILURE); } if (gd_b_version) { g_print ("SHR PhoneFSO Daemon\n%s Version %s\n%s\n\n", PACKAGE_NAME, PACKAGE_VERSION, "GPLv2 (2009) the SHR Team"); g_option_context_free(*context); g_atomic_int_set(&gd_flag_exit, 0); /* flag an exit */ return (EXIT_FAILURE); } if (gd_pch_pid_filename == NULL) { gd_pch_pid_filename = PACKAGE_PIDFILE; } return (EXIT_SUCCESS); } /* * _daemonize() * * The single fork method of becoming a daemon, causes the process * to become a session leader and process group leader. * * Params: * gd_pch_pid_filename -- pid filename * gd_b_force -- global to control overwrite of pid file * * Returns: * returns integer which is passed back to the parent process * values - EXIT_FAILURE Parent and 1st Child * - EXIT_ERROR AnyPid or error * - EXIT_SUCCESS Only the Daemon or GrandChild */ static gint _daemonize (gchar *pidfilename) { gint pidfile = 0; pid_t pid = 0; pid_t sid = 0; gint len = 0; gchar ch_buff[16]; g_return_val_if_fail(pidfilename != NULL, EXIT_ERROR); /* Fork off the parent process */ switch (pid = fork()) { case -1: /* error -- all out */ g_warning("Shutting down as Pid[%d]: fork(error=%s)", getpid(), strerror(errno)); return (EXIT_ERROR); break; case 0: /* new process */ sleep(1); break; default: /* Normal exit, pid equals child real pid */ return (EXIT_FAILURE); } /* Change the file mode mask */ umask(0); /* Change the current working directory */ if ((g_chdir("/")) < 0) { g_warning("Child[%d] is exiting: chdir(error=%s)", getpid(), strerror(errno)); exit(EXIT_ERROR); } /* Close out the standard file descriptors */ close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); /* Create a new SID for the child process */ sid = setsid(); if (sid < 0) { g_warning("Child[%d] is exiting: setsid(error=%s)", getpid(), strerror(errno)); exit(EXIT_ERROR); } pidfile = g_open(pidfilename, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR |S_IWUSR|S_IRGRP|S_IROTH); if (pidfile == -1) { g_warning("Child Error: cannot open pidfile %s: %s", pidfilename, strerror(errno)); return (EXIT_ERROR); } len = snprintf(ch_buff, sizeof(ch_buff), "%d", getpid()); write(pidfile, ch_buff, len); if (close(pidfile) != 0) { g_error("Child Warning: cannot close pidfile %s: %s", pidfilename, strerror(errno)); } return (EXIT_SUCCESS); } /* Main Entry Point for this Daemon */ extern int main (int argc, char *argv[]) { sigset_t signal_set; GMainLoop *main_loop = NULL; GError *gerror = NULL; GThread *sig_thread = NULL; GOptionContext *context = NULL; gpointer trc = NULL; uid_t real_user_id = 0; uid_t effective_user_id = 0; gint rc = 0; struct passwd *userinfo = NULL; /* initialize threading and mainloop */ g_type_init(); main_loop = g_main_loop_new (NULL, FALSE); /* handle command line arguments */ if ((rc = _handle_command_line( argc, argv, &context)) != EXIT_SUCCESS) { g_main_loop_unref (main_loop); exit (rc); } /* remember real and effective userid to restore them on shutdown */ real_user_id = getuid (); if (gd_pch_effective_userid != NULL) { userinfo = getpwnam(gd_pch_effective_userid); effective_user_id = userinfo->pw_uid; } else { effective_user_id = geteuid(); userinfo = getpwuid(effective_user_id); gd_pch_effective_userid = userinfo->pw_name; } g_message("%s-%s is in startup mode as user(%s)", PACKAGE_NAME, PACKAGE_VERSION, gd_pch_effective_userid); /* daemonize */ if (!i_debug) { switch (_daemonize(gd_pch_pid_filename)) { case EXIT_SUCCESS: /* grandchild */ break; case EXIT_ERROR: /* any error */ exit (EXIT_FAILURE); break; default: /* parent or child pids */ exit (EXIT_SUCCESS); break; } } else { g_message("Skipping daemonizing process"); } /* become the requested user */ seteuid (effective_user_id); if (!i_debug) { /* block all signals */ sigfillset (&signal_set); pthread_sigmask (SIG_BLOCK, &signal_set, NULL); /* create the signal handling thread */ sig_thread = g_thread_create ((GThreadFunc)_thread_handle_signals, main_loop, TRUE, &gerror); if (gerror != NULL) { g_message("Create signal thread failed: %s", gerror->message); g_error_free(gerror); g_option_context_free(context); g_main_loop_unref (main_loop); exit (EXIT_FAILURE); } } _load_config(); if (!phonefsod_dbus_setup()) { g_option_context_free(context); g_main_loop_unref(main_loop); exit(EXIT_FAILURE); } //notify = inotify_init(); //inotify_add_watch(notify, PHONEFSOD_CONFIG, IN_MODIFY); /* Start glib main loop and run list_resources() */ g_debug("entering glib main loop"); g_timeout_add_seconds(1, fso_startup, NULL); g_main_loop_run(main_loop); phonefsod_dbus_shutdown(); /* Cleanup and exit */ if (!i_debug) { trc = g_thread_join(sig_thread); g_message("Signal thread was ended by a %s signal.", g_strsignal(GPOINTER_TO_INT(trc)) ); pthread_sigmask (SIG_UNBLOCK, &signal_set, NULL); g_option_context_free (context); } g_main_loop_unref (main_loop); // if (incoming_calls) // free(incoming_calls); // if (outgoing_calls) // free(outgoing_calls); if (sim_pin) free(sim_pin); if (pdp_apn) free(pdp_apn); if (pdp_user) free(pdp_user); if (pdp_password) free(pdp_password); /* become the privledged user again */ seteuid (real_user_id); /* Remove the PID File to show we are inactive */ if (!i_debug) { if (g_unlink(gd_pch_pid_filename) != 0) { g_warning("Main Error: cannot unlink/remove pidfile %s: %s", gd_pch_pid_filename, strerror(errno)); } } /* write shutdown messages */ g_message("%s-%s clean shutdown", PACKAGE_NAME, PACKAGE_VERSION); exit (EXIT_SUCCESS); }