├── .github ├── Contributing.md ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── AndroidAgent.iml ├── COPYING ├── Changes ├── README.md ├── app ├── app.iml ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── org │ │ └── ocs │ │ └── android │ │ ├── actions │ │ ├── CoolSSLSocketFactory.java │ │ ├── Inventory.java │ │ ├── OCSFiles.java │ │ ├── OCSLog.java │ │ ├── OCSProtocol.java │ │ ├── OCSProtocolException.java │ │ ├── OCSSettings.java │ │ ├── PrefsParser.java │ │ ├── PrologReplyParser.java │ │ └── Utils.java │ │ ├── agent │ │ ├── AboutDialog.java │ │ ├── AsyncOperations.java │ │ ├── ExpandableSectionAdapter.java │ │ ├── OCSDownloadIdParams.java │ │ ├── OCSDownloadInfos.java │ │ ├── OCSPrologReply.java │ │ ├── activity │ │ │ ├── OCSAgentActivity.java │ │ │ ├── OCSInstallPackageActivity.java │ │ │ ├── OCSPrefsActivity.java │ │ │ └── OCSShowInventory.java │ │ ├── receiver │ │ │ ├── OCSBootReceiver.java │ │ │ ├── OCSEventReceiver.java │ │ │ └── OCSInstallReceiver.java │ │ └── service │ │ │ ├── OCSAgentService.java │ │ │ └── OCSDownloadService.java │ │ └── sections │ │ ├── OCSBios.java │ │ ├── OCSDrive.java │ │ ├── OCSDrives.java │ │ ├── OCSHardware.java │ │ ├── OCSInput.java │ │ ├── OCSInputs.java │ │ ├── OCSJavaInfos.java │ │ ├── OCSNetwork.java │ │ ├── OCSNetworks.java │ │ ├── OCSSection.java │ │ ├── OCSSectionInterface.java │ │ ├── OCSSims.java │ │ ├── OCSSoftware.java │ │ ├── OCSSoftwares.java │ │ ├── OCSStorage.java │ │ ├── OCSStorages.java │ │ ├── OCSVideos.java │ │ └── SystemInfos.java │ └── res │ ├── drawable-hdpi │ ├── ic_menu_goto.png │ ├── ic_menu_info_details.png │ ├── ic_menu_moreoverflow_normal_holo_dark.png │ ├── ic_menu_set_as.png │ └── ic_sysbar_quicksettings.png │ ├── drawable-ldpi │ ├── ic_menu_goto.png │ ├── ic_menu_info_details.png │ ├── ic_menu_moreoverflow_normal_holo_dark.png │ ├── ic_menu_set_as.png │ └── ic_sysbar_quicksettings.png │ ├── drawable-mdpi │ ├── ic_menu_goto.png │ ├── ic_menu_info_details.png │ ├── ic_menu_moreoverflow_normal_holo_dark.png │ ├── ic_menu_set_as.png │ └── ic_sysbar_quicksettings.png │ ├── drawable-xhdpi │ ├── ic_menu_goto.png │ ├── ic_menu_info_details.png │ ├── ic_menu_moreoverflow_normal_holo_dark.png │ ├── ic_menu_set_as.png │ └── ic_sysbar_quicksettings.png │ ├── drawable-xxhdpi │ ├── ic_menu_goto.png │ ├── ic_menu_info_details.png │ ├── ic_menu_moreoverflow_normal_holo_dark.png │ ├── ic_menu_set_as.png │ └── ic_sysbar_quicksettings.png │ ├── drawable-xxxhdpi │ ├── ic_menu_goto.png │ ├── ic_menu_info_details.png │ ├── ic_menu_moreoverflow_normal_holo_dark.png │ ├── ic_menu_set_as.png │ └── ic_sysbar_quicksettings.png │ ├── drawable │ ├── button_effect.xml │ ├── ic_notification.png │ ├── ic_ocs_android.png │ └── ocs_landscape.png │ ├── layout │ ├── about.xml │ ├── actvity_show_inventory.xml │ ├── list_header.xml │ ├── list_item.xml │ ├── ocs_agent.xml │ └── ocs_install_package.xml │ ├── menu │ └── activity_main.xml │ ├── values-de │ ├── strings.xml │ └── strings_prefs.xml │ ├── values-fr │ ├── strings.xml │ └── strings_prefs.xml │ ├── values │ ├── arrays.xml │ ├── colors.xml │ ├── strings.xml │ ├── strings_nt.xml │ └── strings_prefs.xml │ └── xml │ └── preferences.xml ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.github/Contributing.md: -------------------------------------------------------------------------------- 1 |

2 | Banner 3 |

4 | 5 |

OCS Inventory

6 |

7 | Some Links:
8 | Ask question | 9 | Installation | 10 | Website 11 |

12 | 13 | # OCS Inventory Contributing Guidelines 14 | 15 | ## Pull Request Process 16 | 17 | 1. Fork it! 18 | 2. Create your feature branch: `git checkout -b my-new-feature` 19 | 3. Add your changes: `git add folder/file1.php` 20 | 4. Commit your changes: `git commit -m 'Add some feature'` 21 | 5. Push to the branch: `git push origin my-new-feature` 22 | 6. Submit a pull request ! 23 | 24 | ## Pull Request Informations 25 | 26 | When contributing, please open an issue before or contact the team using mail. This will prevent all the duplicate of work. 27 | Also, check if your contribution is not already in the roadmap or affiliated to an issue. 28 | 29 | If you are contributing on a small scale (translation, a few line modification), you don't need open an issue or contact the team but you will need to explain what you've done in the Pull Request comment and provide as accurate commit messages as possible. 30 | Cf. Commits Messages Name Informations 31 | 32 | If you need to discuss about a big change or need some help of our team during the development of your contribution, 33 | we can use other communication method like Telegram, IRC, Skype. 34 | 35 | ## Commits Messages Name Informations 36 | 37 | Try to create as accurate as possible commit messages. 38 | This will help us to speed up the review process and to reduce the misunderstanding (which can lead to a Pull Request to be rejected) 39 | 40 | There is no commit messages convention but here are some examples : 41 | 1. Create as short as possible commit name 42 | 2. One commit for one modification 43 | 3. Always leave the second commit line blank 44 | 45 | If it seems difficult to summarize what your commit does, it may be because it includes several logical changes or bug fixes, and are better split up into several commits using `git add -p`. 46 | 47 | ## Code of Conduct 48 | 49 | ### Our Pledge 50 | 51 | In the interest of fostering an open and welcoming environment, we as 52 | contributors and maintainers pledge to making participation in our project and 53 | our community a harassment-free experience for everyone, regardless of age, body 54 | size, disability, ethnicity, gender identity and expression, level of experience, 55 | nationality, personal appearance, race, religion, or sexual identity and 56 | orientation. 57 | 58 | ### Our Standards 59 | 60 | Examples of behavior that contributes to creating a positive environment 61 | include: 62 | 63 | * Using welcoming and inclusive language 64 | * Being respectful of differing viewpoints and experiences 65 | * Gracefully accepting constructive criticism 66 | * Focusing on what is best for the community 67 | * Showing empathy towards other community members 68 | 69 | Examples of unacceptable behavior by participants include: 70 | 71 | * The use of sexualized language or imagery and unwelcome sexual attention or 72 | advances 73 | * Trolling, insulting/derogatory comments, and personal or political attacks 74 | * Public or private harassment 75 | * Publishing others' private information, such as a physical or electronic 76 | address, without explicit permission 77 | * Other conduct which could reasonably be considered inappropriate in a 78 | professional setting 79 | 80 | ### Our Responsibilities 81 | 82 | Project maintainers are responsible for clarifying the standards of acceptable 83 | behavior and are expected to take appropriate and fair corrective action in 84 | response to any instances of unacceptable behavior. 85 | 86 | Project maintainers have the right and responsibility to remove, edit, or 87 | reject comments, commits, code, wiki edits, issues, and other contributions 88 | that are not aligned to this Code of Conduct, or to ban temporarily or 89 | permanently any contributor for other behaviors that they deem inappropriate, 90 | threatening, offensive, or harmful. 91 | 92 | ### Scope 93 | 94 | This Code of Conduct applies both within project spaces and in public spaces 95 | when an individual is representing the project or its community. Examples of 96 | representing a project or community include using an official project e-mail 97 | address, posting via an official social media account, or acting as an appointed 98 | representative at an online or offline event. Representation of a project may be 99 | further defined and clarified by project maintainers. 100 | 101 | ### Enforcement 102 | 103 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 104 | reported by contacting the project team at `contact@ocsinventory-ng.org` . All 105 | complaints will be reviewed and investigated and will result in a response that 106 | is deemed necessary and appropriate to the circumstances. The project team is 107 | obligated to maintain confidentiality with regard to the reporter of an incident. 108 | Further details of specific enforcement policies may be posted separately. 109 | 110 | Project maintainers who do not follow or enforce the Code of Conduct in good 111 | faith may face temporary or permanent repercussions as determined by other 112 | members of the project's leadership. 113 | 114 | ### Attribution 115 | 116 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 117 | available at [http://contributor-covenant.org/version/1/4][version] 118 | 119 | [homepage]: http://contributor-covenant.org 120 | [version]: http://contributor-covenant.org/version/1/4/ 121 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | *It's hard to solve a problem when important details are missing, that why we added this template, to help you and us.* 2 | 3 | ### General informations 4 | Android version : 5 | 6 | ### OCS Inventory informations 7 | Android agent version : 8 | 9 | ### Problem's description 10 | *Describe your problem here* 11 | 12 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Must read before submitting 2 | Please, take a look to our contributing guidelines before submitting your pull request. 3 | There's some simple rules that will help us to speed up the review process and avoid any misunderstanding 4 | 5 | [Contributors GuideLines](https://github.com/OCSInventory-NG/OCSInventory-ocsreports/blob/master/.github/Contributing.md) 6 | 7 | ## Status 8 | **READY/IN DEVELOPMENT/HOLD** 9 | 10 | ## Description 11 | A few sentences describing the overall goals of the pull request's commits. 12 | 13 | ## Related Issues 14 | Put here all the related issues link 15 | 16 | ## Todos 17 | - [ ] Tests 18 | - [ ] Documentation 19 | 20 | ## Test environment 21 | If some tests has been already made, please give us your test environment' specs 22 | 23 | #### General informations 24 | Android version : 25 | 26 | #### OCS Inventory informations 27 | Android agent version : 28 | 29 | ## Deploy Notes 30 | Notes regarding deployment the contained body of work. These should note any dependencies changes, 31 | logical changes, etc. 32 | 33 | 1. 34 | 35 | ## Impacted Areas in Application 36 | List general components of the application that this PR will affect: 37 | 38 | * 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Built application files 3 | build/ 4 | 5 | # Crashlytics configuations 6 | com_crashlytics_export_strings.xml 7 | 8 | # Local configuration file (sdk path, etc) 9 | local.properties 10 | 11 | # Gradle generated files 12 | .gradle/ 13 | 14 | # Signing files 15 | .signing/ 16 | 17 | # User-specific configurations 18 | .idea 19 | *.iml 20 | 21 | # OS-specific files 22 | .DS_Store 23 | .DS_Store? 24 | ._* 25 | .Spotlight-V100 26 | .Trashes 27 | ehthumbs.db 28 | Thumbs.db 29 | -------------------------------------------------------------------------------- /AndroidAgent.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Changes: -------------------------------------------------------------------------------- 1 | Revision history for Ocsinventory NG Android Agent 2 | 3 | 2.7 4 | * Update gradle 5 | * Improve stability 6 | * Add phone number inventory (main sim only) 7 | 8 | 2.3.1 9 | * Fix permissions on android 6 and more 10 | 11 | 2.3.0 12 | * New graphics chart 13 | * App redesign 14 | * Update to new android API 15 | 16 | 2.1.7 17 | * Bug on proxy option corrected. The option was not applied. 18 | 19 | 2.1.6 20 | * Bugs correction on package installation managment notifications 21 | * Add InstallReceiver class 22 | 23 | 2.1.5 24 | * Package renamed to org.orcinventoryng.android 25 | * Import exported configuration file the name org.orcinventoryng.android.agent_preferences.xml OR org.orcinventory.android.agent_preferences.xml 26 | 27 | 2.1.4 28 | * Nicolas Ricquemaque contribution. 29 | * New settings : Automatic mode's networks behavior management. 30 | * New settings : Notifications hidding management 31 | * Load configuration from sdcard when start with a "force_update" extra. 32 | 33 | 2.1.3 34 | * On first start after installation, load automaticaly the configuration if present on the sdcard. 35 | 36 | 2.1.2 37 | * Change cpu number evaluation method to obtains correct value. 38 | 39 | 2.1.1.1 40 | * Correction OCSEventreceiver option force_update was always set to true 41 | 42 | 2.1.1 43 | * Add extra to OCSEventReceiver to save inventory on disk 44 | * Force inventory with OCSEventReceiver 45 | * Remove OCSFiles singleton 46 | * Fix unit conversion bug for cache 47 | * Change inventory file name (host + date) 48 | * Use OCSSettings instead of direct call to PreferenceManager 49 | * Change address detection 50 | * Do not force to enable wifi 51 | * Specify the same process name as service for activity in manifest for good settings share 52 | * Add DEVICEID in SIM section for phone id (IMEI) info 53 | * Java info returned in software section 54 | * Kernel version returned in Hardware/OSComments + tag "*ROOTED*" if device is rooted. 55 | 56 | 2.1.0.1 57 | * Cédric Cabessa contribution 58 | * Add permission RECEIVE_BOOT_COMPLETED into Manifest 59 | * Corrections about size image caps when multiples cameras 60 | * Move configuration strings to strings_nt.xml (no translatable strings) 61 | 62 | 2.1.0 63 | * Correct SIM XML section name. 64 | * 1st Publication version 65 | 66 | 0.9.9 67 | * Change launch and notification icon 68 | * Add SIMS section with check mask 0x80000 69 | 70 | 0.9.8 71 | * In hardware section : the field checksum is correctly calculated from sections changes since last successful upload. 72 | * New logo 73 | * Logo centred on main activity background. 74 | * Different layout in lanscape disposition. 75 | 76 | 0.9.7 77 | * Messages corrections in settings 78 | * Wifi speed information added 79 | * Correction : crash when camera already open 80 | 81 | 0.9.6 82 | * Messages corrections 83 | * device uid not exported with settings 84 | 85 | 0.9.5 86 | * Correction on Inputs sections (not exported) 87 | * Add camera in inputs 88 | 89 | 0.9.4 90 | * Device uid exclude of import settings operation 91 | * Change icon 92 | * Change default language to English 93 | * Translations corrections 94 | * On opening, Log file deleted if size > 100000 bytes 95 | * Add option hide system software ( true by default) 96 | 97 | 0.9.3 98 | * Bug deteted in android 4.x : network operation cant be executed in the main thread as do in service mode. Work in 2.x & 3 99 | .0 but exception in 4.1 => send inventory executed in an Async Task 100 | 101 | 0.9.2 102 | * Replace OCSShowActivity by a structured Listview activity 103 | * Add OCS section object to contain a section usable by a ListView adapter 104 | * Each section implement a getSection() meth. returning a such as object 105 | 106 | 0.9.1 107 | * Add service mode (automatic) 108 | * Many corrections 109 | * Add notifications 110 | * Use standard android settings menus 111 | * Lot of corrections 112 | 113 | 0.9 114 | * Initial version 115 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AndroidAgent 2 | 3 | OCS Inventory NG Android Agent 4 | Web site : https://ocsinventory-ng.org/ 5 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | buildToolsVersion '26.0.3' 6 | 7 | useLibrary 'org.apache.http.legacy' 8 | 9 | defaultConfig { 10 | applicationId "org.ocs.android.agent" 11 | minSdkVersion 26 12 | targetSdkVersion 26 13 | } 14 | 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' 19 | } 20 | } 21 | productFlavors { 22 | } 23 | } 24 | 25 | dependencies { 26 | implementation 'com.android.support:support-v4:26.1.0' 27 | implementation 'com.android.support:appcompat-v7:26.1.0' 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 23 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 50 | 54 | 55 | 56 | 57 | 58 | 59 | 63 | 64 | 69 | 72 | 73 | 78 | 81 | 82 | 83 | 86 | 87 | 90 | 91 | 92 | 96 | 97 | 100 | 101 | 102 | 103 | 104 | 105 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /app/src/main/java/org/ocs/android/actions/CoolSSLSocketFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2016 OCSInventory-NG/AndroidAgent contributors : mortheres, cdpointpoint, 3 | * Cédric Cabessa, Nicolas Ricquemaque, Anael Mobilia 4 | * 5 | * This file is part of OCSInventory-NG/AndroidAgent. 6 | * 7 | * OCSInventory-NG/AndroidAgent is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * OCSInventory-NG/AndroidAgent is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with OCSInventory-NG/AndroidAgent. if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | */ 21 | package org.ocs.android.actions; 22 | 23 | import android.util.Log; 24 | 25 | import org.apache.http.conn.ssl.SSLSocketFactory; 26 | 27 | import java.io.IOException; 28 | import java.net.Socket; 29 | import java.security.KeyManagementException; 30 | import java.security.KeyStore; 31 | import java.security.KeyStoreException; 32 | import java.security.NoSuchAlgorithmException; 33 | import java.security.UnrecoverableKeyException; 34 | import java.security.cert.CertificateException; 35 | import java.security.cert.X509Certificate; 36 | 37 | import javax.net.ssl.SSLContext; 38 | import javax.net.ssl.TrustManager; 39 | import javax.net.ssl.X509TrustManager; 40 | 41 | public class CoolSSLSocketFactory extends SSLSocketFactory { 42 | private SSLContext sslContext = SSLContext.getInstance("TLS"); 43 | 44 | public CoolSSLSocketFactory( 45 | KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, 46 | UnrecoverableKeyException { 47 | 48 | super(truststore); 49 | 50 | TrustManager tm = new X509TrustManager() { 51 | public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { 52 | } 53 | 54 | public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { 55 | for (X509Certificate aChain : chain) { 56 | Log.d("X509", aChain.getSubjectDN().toString()); 57 | } 58 | } 59 | 60 | public X509Certificate[] getAcceptedIssuers() { 61 | return null; 62 | } 63 | }; 64 | Log.d("X509", "CoolSSLSocketFactory"); 65 | sslContext.init(null, new TrustManager[]{ tm }, null); 66 | setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); 67 | } 68 | 69 | @Override 70 | public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException { 71 | return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose); 72 | } 73 | 74 | @Override 75 | public Socket createSocket() throws IOException { 76 | return sslContext.getSocketFactory().createSocket(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/org/ocs/android/actions/OCSLog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2016 OCSInventory-NG/AndroidAgent contributors : mortheres, cdpointpoint, 3 | * Cédric Cabessa, Nicolas Ricquemaque, Anael Mobilia 4 | * 5 | * This file is part of OCSInventory-NG/AndroidAgent. 6 | * 7 | * OCSInventory-NG/AndroidAgent is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * OCSInventory-NG/AndroidAgent is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with OCSInventory-NG/AndroidAgent. if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | */ 21 | package org.ocs.android.actions; 22 | 23 | import android.os.Environment; 24 | import android.util.Log; 25 | 26 | import java.io.File; 27 | import java.io.FileWriter; 28 | import java.io.IOException; 29 | import java.text.DateFormat; 30 | import java.util.Date; 31 | 32 | public class OCSLog { 33 | private static String TAG = "OCSLOG"; 34 | private static OCSLog instance; 35 | private File logFile; 36 | 37 | public OCSLog() { 38 | File rep = Environment.getExternalStoragePublicDirectory("ocs"); 39 | 40 | Log.d(TAG, Environment.getExternalStorageDirectory().getPath()); 41 | 42 | if (!rep.isDirectory()) { 43 | rep.delete(); 44 | } 45 | if (!rep.exists()) { 46 | if (!rep.mkdir()) { 47 | Log.e(TAG, "Cannot create directory : " + rep.getPath()); 48 | return; 49 | } else { 50 | Log.d(TAG, rep.getPath() + " created"); 51 | } 52 | } 53 | logFile = new File(rep, "ocslog.txt"); 54 | if (logFile.length() > 100000L) { 55 | logFile.delete(); 56 | } 57 | } 58 | 59 | public static OCSLog getInstance() { 60 | if (instance == null) { 61 | instance = new OCSLog(); 62 | } 63 | return instance; 64 | } 65 | 66 | public void debug(String paramString) { 67 | if (paramString != null && OCSSettings.getInstance() != null && OCSSettings.getInstance().getDebug() && logFile != null) { 68 | Log.d("OCSLOG", paramString); 69 | log(paramString); 70 | } 71 | } 72 | 73 | public void error(String paramString) { 74 | if (paramString != null && OCSSettings.getInstance() != null) { 75 | Log.e("OCSLOG", paramString); 76 | log(paramString); 77 | } 78 | } 79 | 80 | private void log(String paramString) { 81 | if (logFile == null) { 82 | return; 83 | } 84 | Date localDate = new Date(); 85 | String strDate = DateFormat.getInstance().format(localDate); 86 | try { 87 | FileWriter fileWriter = new FileWriter(logFile, true); 88 | fileWriter.append(strDate).append(":").append(paramString).append("\n"); 89 | fileWriter.close(); 90 | } catch (IOException e) { 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /app/src/main/java/org/ocs/android/actions/OCSProtocolException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2016 OCSInventory-NG/AndroidAgent contributors : mortheres, cdpointpoint, 3 | * Cédric Cabessa, Nicolas Ricquemaque, Anael Mobilia 4 | * 5 | * This file is part of OCSInventory-NG/AndroidAgent. 6 | * 7 | * OCSInventory-NG/AndroidAgent is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * OCSInventory-NG/AndroidAgent is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with OCSInventory-NG/AndroidAgent. if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | */ 21 | package org.ocs.android.actions; 22 | 23 | public class OCSProtocolException extends Exception { 24 | private static final long serialVersionUID = 8115364599391499226L; 25 | 26 | public OCSProtocolException(String s) { 27 | super(s); 28 | OCSLog ocslog = OCSLog.getInstance(); 29 | ocslog.error(s); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/org/ocs/android/actions/OCSSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2016 OCSInventory-NG/AndroidAgent contributors : mortheres, cdpointpoint, 3 | * Cédric Cabessa, Nicolas Ricquemaque, Anael Mobilia 4 | * 5 | * This file is part of OCSInventory-NG/AndroidAgent. 6 | * 7 | * OCSInventory-NG/AndroidAgent is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * OCSInventory-NG/AndroidAgent is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with OCSInventory-NG/AndroidAgent. if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | */ 21 | package org.ocs.android.actions; 22 | 23 | import android.content.Context; 24 | import android.content.SharedPreferences; 25 | import android.content.SharedPreferences.Editor; 26 | import android.preference.PreferenceManager; 27 | 28 | import org.ocs.android.agent.R; 29 | 30 | public class OCSSettings { 31 | private static OCSSettings instance = null; 32 | 33 | private Context ctx; 34 | private SharedPreferences prefs; 35 | 36 | private final String KLASTUPDT = "k_lastupdt"; 37 | private final String KDEVICEUID = "k_deviceUid"; 38 | 39 | private final String KSERVERURL = "k_serverurl"; 40 | private final String KDEVICETAG = "k_devicetag"; 41 | private final String KAUTOMODE = "k_automode"; 42 | private final String KAUTOMODENETWORK = "k_automodeNetwork"; 43 | private final String KFREQMAJ = "k_freqmaj"; 44 | private final String KFREQWAKE = "k_freqwake"; 45 | private final String KDEBUG = "k_debug"; 46 | private final String KGZIP = "k_gzip"; 47 | private final String KSTRICTSSL = "k_strictssl"; 48 | private final String KPROXY = "k_proxy"; 49 | private final String KPROXYADR = "k_proxyadr"; 50 | private final String KPROXYPORT = "k_proxyport"; 51 | private final String KCACHE = "k_cache"; 52 | private final String KCACHELEN = "k_cachelen"; 53 | 54 | private final String KAUTH = "k_auth"; 55 | private final String KLOGIN = "k_login"; 56 | private final String KPASSWD = "k_passwd"; 57 | private final String KSYSHIDE = "k_syshide"; 58 | private final String KCOMPUA = "k_compua"; 59 | private final String KHIDENOTIF = "k_hideNotif"; 60 | 61 | public OCSSettings(Context ctx) { 62 | prefs = PreferenceManager.getDefaultSharedPreferences(ctx); 63 | this.ctx = ctx; 64 | } 65 | 66 | public void logSettings() { 67 | OCSLog ocslog = OCSLog.getInstance(); 68 | if (ocslog == null) { 69 | return; 70 | } 71 | ocslog.debug("deviceUid : " + getDeviceUid()); 72 | ocslog.debug("debug : " + getDebug()); 73 | ocslog.debug("autostart : " + isAutoMode()); 74 | ocslog.debug("serverURL : " + getServerUrl()); 75 | ocslog.debug("gzip : " + getGzip()); 76 | ocslog.debug("TAG : " + getDeviceTag()); 77 | ocslog.debug("STRICTSSL : " + isSSLStrict()); 78 | } 79 | 80 | public static OCSSettings getInstance(Context ctx) { 81 | if (instance == null) { 82 | instance = new OCSSettings(ctx); 83 | } 84 | return instance; 85 | } 86 | 87 | public static OCSSettings getInstance() { 88 | return instance; 89 | } 90 | 91 | public void setDeviceUid(String uid) { 92 | Editor e = prefs.edit(); 93 | e.putString(KDEVICEUID, uid); 94 | e.apply(); 95 | } 96 | 97 | public void setLastUpdt(long l) { 98 | Editor e = prefs.edit(); 99 | e.putLong(KLASTUPDT, l); 100 | e.apply(); 101 | } 102 | 103 | public void setFreqMaj(String f) { 104 | Editor e = prefs.edit(); 105 | e.putString(KFREQMAJ, f); 106 | e.apply(); 107 | } 108 | 109 | 110 | public boolean isAutoMode() { 111 | return prefs.getBoolean(KAUTOMODE, false); 112 | } 113 | 114 | public int getAutoModeNetwork() { 115 | String p = prefs.getString(KAUTOMODENETWORK, ""); 116 | return Integer.parseInt(p); 117 | } 118 | 119 | public int getHiddenNotif() { 120 | String p = prefs.getString(KHIDENOTIF, ""); 121 | return Integer.parseInt(p); 122 | } 123 | 124 | public String getDeviceUid() { 125 | return prefs.getString(KDEVICEUID, null); 126 | } 127 | 128 | public boolean getDebug() { 129 | return prefs.getBoolean(KDEBUG, false); 130 | } 131 | 132 | public String getServerUrl() { 133 | return prefs.getString(KSERVERURL, ctx.getString(R.string.pref_default_serverurl)); 134 | } 135 | 136 | public boolean getGzip() { 137 | return prefs.getBoolean(KGZIP, false); 138 | } 139 | 140 | public String getDeviceTag() { 141 | 142 | return prefs.getString(KDEVICETAG, ctx.getString(R.string.pref_default_devicetag)); 143 | } 144 | 145 | public boolean isSSLStrict() { 146 | return prefs.getBoolean(KSTRICTSSL, true); 147 | } 148 | 149 | public boolean isProxy() { 150 | return prefs.getBoolean(KPROXY, false); 151 | } 152 | 153 | public boolean isAuth() { 154 | return prefs.getBoolean(KAUTH, false); 155 | } 156 | 157 | public String getProxyAdr() { 158 | return prefs.getString(KPROXYADR, ""); 159 | } 160 | 161 | public int getProxyPort() { 162 | String p = prefs.getString(KPROXYPORT, ""); 163 | return Integer.parseInt(p); 164 | } 165 | 166 | public String getLogin() { 167 | return prefs.getString(KLOGIN, ""); 168 | } 169 | 170 | public String getPasswd() { 171 | return prefs.getString(KPASSWD, ""); 172 | } 173 | 174 | public long getLastUpdt() { 175 | return prefs.getLong(KLASTUPDT, 0L); 176 | } 177 | 178 | public int getCacheLen() { 179 | int c = 0; // Return 0 if cache not enabled 180 | if (prefs.getBoolean(KCACHE, true)) { 181 | c = Integer.parseInt(prefs.getString(KCACHELEN, ctx.getString(R.string.pref_default_cachelen))); 182 | } 183 | return c; 184 | } 185 | 186 | public int getFreqWake() { 187 | int r = 60; 188 | if (prefs.getBoolean(KAUTOMODE, true)) { 189 | r = Integer.parseInt(prefs.getString(KFREQWAKE, ctx.getString(R.string.pref_default_freqwake))); 190 | } 191 | return r; 192 | } 193 | 194 | public int getFreqMaj() { 195 | return Integer.parseInt(prefs.getString(KFREQMAJ, ctx.getString(R.string.pref_default_freqmaj))); 196 | } 197 | 198 | public boolean isSysHide() { 199 | return prefs.getBoolean(KSYSHIDE, true); 200 | } 201 | 202 | public boolean isCompUAEnabled() { 203 | return prefs.getBoolean(KCOMPUA, false); 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /app/src/main/java/org/ocs/android/actions/PrefsParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2016 OCSInventory-NG/AndroidAgent contributors : mortheres, cdpointpoint, 3 | * Cédric Cabessa, Nicolas Ricquemaque, Anael Mobilia 4 | * 5 | * This file is part of OCSInventory-NG/AndroidAgent. 6 | * 7 | * OCSInventory-NG/AndroidAgent is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * OCSInventory-NG/AndroidAgent is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with OCSInventory-NG/AndroidAgent. if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | */ 21 | package org.ocs.android.actions; 22 | 23 | import android.content.SharedPreferences; 24 | import android.content.SharedPreferences.Editor; 25 | import android.util.Log; 26 | 27 | import org.xml.sax.Attributes; 28 | import org.xml.sax.SAXException; 29 | import org.xml.sax.helpers.DefaultHandler; 30 | 31 | import java.io.File; 32 | 33 | import javax.xml.parsers.SAXParser; 34 | import javax.xml.parsers.SAXParserFactory; 35 | 36 | public class PrefsParser extends DefaultHandler { 37 | private String keyName; 38 | private String keyValue; 39 | private Editor edit; 40 | 41 | public void parseDocument(File paramFile, SharedPreferences prefs) { 42 | Log.d("PARSE", "Start parseDocument "); 43 | edit = prefs.edit(); 44 | 45 | SAXParserFactory localSAXParserFactory = SAXParserFactory.newInstance(); 46 | try { 47 | SAXParser localSAXParser = localSAXParserFactory.newSAXParser(); 48 | localSAXParser.parse(paramFile, this); 49 | } catch (Exception e) { 50 | e.printStackTrace(); 51 | } 52 | } 53 | 54 | public void characters(char[] paramArrayOfChar, int paramInt1, int paramInt2) throws SAXException { 55 | String str = new String(paramArrayOfChar, paramInt1, paramInt2); 56 | keyValue = str; 57 | Log.d("PARSE", "characters" + str); 58 | } 59 | 60 | public void endElement(String uri, String localName, String qName) throws SAXException { 61 | Log.d("PARSE", "endElement"); 62 | Log.d("PARSE", "uri : " + uri); 63 | Log.d("PARSE", "lName : " + localName); 64 | Log.d("PARSE", "qName : " + qName); 65 | if ("map".equals(qName)) { 66 | edit.apply(); 67 | } else if ("string".equals(qName) && !"k_deviceUid".equals(keyName)) { 68 | Log.d("PARSE", keyName + "/" + keyValue); 69 | edit.putString(keyName, keyValue); 70 | } 71 | } 72 | 73 | public void startElement(String uri, String local, String qName, Attributes attributes) throws SAXException { 74 | keyName = attributes.getValue("", "name"); 75 | keyValue = attributes.getValue("", "value"); 76 | Log.d("PARSE", "startElement"); 77 | Log.d("PARSE", "uri : " + uri); 78 | Log.d("PARSE", "local : " + local); 79 | Log.d("PARSE", "qName : " + qName); 80 | if (qName.equalsIgnoreCase("boolean")) { 81 | Log.d("PARSE", keyName + "/" + keyValue); 82 | edit.putBoolean(keyName, "true".equals(keyValue)); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /app/src/main/java/org/ocs/android/actions/PrologReplyParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2016 OCSInventory-NG/AndroidAgent contributors : mortheres, cdpointpoint, 3 | * Cédric Cabessa, Nicolas Ricquemaque, Anael Mobilia 4 | * 5 | * This file is part of OCSInventory-NG/AndroidAgent. 6 | * 7 | * OCSInventory-NG/AndroidAgent is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * OCSInventory-NG/AndroidAgent is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with OCSInventory-NG/AndroidAgent. if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | */ 21 | package org.ocs.android.actions; 22 | 23 | import android.util.Log; 24 | 25 | import org.ocs.android.agent.OCSDownloadIdParams; 26 | import org.ocs.android.agent.OCSPrologReply; 27 | import org.xml.sax.Attributes; 28 | import org.xml.sax.SAXException; 29 | import org.xml.sax.helpers.DefaultHandler; 30 | 31 | import java.io.ByteArrayInputStream; 32 | import java.io.InputStream; 33 | 34 | import javax.xml.parsers.SAXParser; 35 | import javax.xml.parsers.SAXParserFactory; 36 | 37 | public class PrologReplyParser extends DefaultHandler { 38 | private String currentTag; 39 | private OCSPrologReply reply = new OCSPrologReply(); 40 | 41 | public OCSPrologReply parseDocument(String strReply) { 42 | Log.d("PrologReplyParser", strReply); 43 | ByteArrayInputStream bais = new ByteArrayInputStream(strReply.getBytes()); 44 | 45 | return parseDocument(bais); 46 | } 47 | 48 | public OCSPrologReply parseDocument(InputStream is) { 49 | Log.d("PrologReplyParser", ""); 50 | SAXParserFactory localSAXParserFactory = SAXParserFactory.newInstance(); 51 | try { 52 | SAXParser localSAXParser = localSAXParserFactory.newSAXParser(); 53 | localSAXParser.parse(is, this); 54 | } catch (Exception e) { 55 | e.printStackTrace(); 56 | } 57 | return reply; 58 | } 59 | 60 | 61 | public void startElement(String uri, String local, String qName, Attributes attributes) throws SAXException { 62 | if ("PARAM".equals(qName)) { 63 | String id = attributes.getValue("", "ID"); 64 | if (id != null) { 65 | OCSDownloadIdParams dip = new OCSDownloadIdParams(); 66 | dip.setId(id); 67 | dip.setSchedule(attributes.getValue("", "SCHEDULE")); 68 | dip.setCertFile(attributes.getValue("", "CERT_FILE")); 69 | dip.setType(attributes.getValue("", "TYPE")); 70 | dip.setInfoLoc(attributes.getValue("", "INFO_LOC")); 71 | dip.setCertPath(attributes.getValue("", "CERT_PATH")); 72 | dip.setPackLoc(attributes.getValue("", "PACK_LOC")); 73 | dip.setForce(attributes.getValue("", "FORCE")); 74 | dip.setPostcmd(attributes.getValue("", "POSTCMD")); 75 | reply.getIdList().add(dip); 76 | } else { 77 | String frag_lat = attributes.getValue("", "FRAG_LATENCY"); 78 | if (frag_lat != null) { 79 | reply.setFragLatency(frag_lat); 80 | reply.setPeriodLatency(attributes.getValue("", "PERIOD_LATENCY")); 81 | reply.setOn(attributes.getValue("", "ON")); 82 | reply.setType(attributes.getValue("", "TYPE")); 83 | reply.setCycleLatency(attributes.getValue("", "CYCLE_LATENCY")); 84 | reply.setTimeout(attributes.getValue("", "TIMEOUT")); 85 | reply.setPeriodeLength(attributes.getValue("", "PERIOD_LENGTH")); 86 | reply.setExecutionTimeout(attributes.getValue("", "EXECUTION_TIMEOUT")); 87 | } 88 | } 89 | } 90 | currentTag = qName; 91 | } 92 | 93 | public void characters(char[] paramArrayOfChar, int paramInt1, int paramInt2) throws SAXException { 94 | String str = new String(paramArrayOfChar, paramInt1, paramInt2); 95 | if ("RESPONSE".equals(currentTag)) { 96 | reply.setResponse(str); 97 | } else if ("PROLOG_FREQ".equals(currentTag)) { 98 | reply.setPrologFreq(str); 99 | } else if ("NAME".equals(currentTag) && reply.getOptName() == null) { 100 | reply.setOptName(str); 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /app/src/main/java/org/ocs/android/agent/AboutDialog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2016 OCSInventory-NG/AndroidAgent contributors : mortheres, cdpointpoint, 3 | * Cédric Cabessa, Nicolas Ricquemaque, Anael Mobilia 4 | * 5 | * This file is part of OCSInventory-NG/AndroidAgent. 6 | * 7 | * OCSInventory-NG/AndroidAgent is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * OCSInventory-NG/AndroidAgent is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with OCSInventory-NG/AndroidAgent. if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | */ 21 | package org.ocs.android.agent; 22 | 23 | import android.app.Dialog; 24 | import android.content.Context; 25 | import android.content.pm.PackageManager.NameNotFoundException; 26 | import android.os.Bundle; 27 | import android.widget.TextView; 28 | 29 | import org.ocs.android.actions.OCSSettings; 30 | 31 | import java.text.SimpleDateFormat; 32 | import java.util.Date; 33 | import java.util.Locale; 34 | 35 | public class AboutDialog extends Dialog { 36 | private static Context mContext; 37 | 38 | public AboutDialog(Context context) { 39 | super(context); 40 | mContext = context; 41 | } 42 | 43 | /** 44 | * Standard Android on create method that gets called when the activity initialized. 45 | */ 46 | @Override 47 | public void onCreate(Bundle savedInstanceState) { 48 | setContentView(R.layout.about); 49 | 50 | OCSSettings ocssettings = OCSSettings.getInstance(mContext); 51 | 52 | long lastUpdt = ocssettings.getLastUpdt(); 53 | 54 | StringBuilder sb = new StringBuilder("OCS Inventory NG android Agent \n"); 55 | sb.append("Version :"); 56 | try { 57 | sb.append(mContext.getPackageManager(). 58 | getPackageInfo(mContext.getPackageName(), 0).versionName); 59 | } catch (NameNotFoundException e) { 60 | } 61 | sb.append("\n"); 62 | if (lastUpdt > 0) { 63 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US); 64 | sb.append("Last upload : "); 65 | sb.append(sdf.format(new Date(lastUpdt))); 66 | sb.append("\n"); 67 | if (ocssettings.isAutoMode()) { 68 | int freq = ocssettings.getFreqMaj(); 69 | long nextUpdt = lastUpdt + freq * 3600000L; 70 | sb.append("Next upload : "); 71 | sb.append(sdf.format(new Date(nextUpdt))); 72 | } else { 73 | sb.append("Mode manuel"); 74 | } 75 | } 76 | 77 | TextView tv = (TextView) findViewById(R.id.test_about); 78 | tv.setText(sb.toString()); 79 | } 80 | } -------------------------------------------------------------------------------- /app/src/main/java/org/ocs/android/agent/AsyncOperations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2016 OCSInventory-NG/AndroidAgent contributors : mortheres, cdpointpoint, 3 | * Cédric Cabessa, Nicolas Ricquemaque, Anael Mobilia 4 | * 5 | * This file is part of OCSInventory-NG/AndroidAgent. 6 | * 7 | * OCSInventory-NG/AndroidAgent is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * OCSInventory-NG/AndroidAgent is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with OCSInventory-NG/AndroidAgent. if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | */ 21 | package org.ocs.android.agent; 22 | 23 | import android.app.Activity; 24 | import android.app.ProgressDialog; 25 | import android.content.Context; 26 | import android.content.Intent; 27 | import android.os.AsyncTask; 28 | import android.widget.TextView; 29 | import android.widget.Toast; 30 | 31 | import org.ocs.android.actions.Inventory; 32 | import org.ocs.android.actions.OCSFiles; 33 | import org.ocs.android.actions.OCSLog; 34 | import org.ocs.android.actions.OCSProtocol; 35 | import org.ocs.android.actions.OCSProtocolException; 36 | import org.ocs.android.agent.service.OCSDownloadService; 37 | 38 | public class AsyncOperations extends AsyncTask { 39 | private final Activity mActivity; 40 | private ProgressDialog mProgressDialog; 41 | private TextView mTvStatus; 42 | private Context mAppCtx; 43 | private boolean mSend; 44 | private boolean mDownload = false; 45 | 46 | public AsyncOperations(boolean send, ProgressDialog progressDialog, TextView status, Activity act, Context ctx) { 47 | mSend = send; 48 | mProgressDialog = progressDialog; 49 | mTvStatus = status; 50 | mAppCtx = ctx; 51 | mActivity = act; 52 | } 53 | 54 | @Override 55 | protected void onPreExecute() { 56 | mTvStatus.setText(R.string.state_build_inventory); 57 | } 58 | 59 | @Override 60 | protected void onPostExecute(String msg) { 61 | OCSLog.getInstance().debug("onPostExecute [" + msg + "]"); 62 | mProgressDialog.dismiss(); 63 | if (mDownload) { 64 | // Toast cant be build in the thread doInBackground 65 | Toast toast = Toast.makeText(mAppCtx, mAppCtx.getString(R.string.start_download_service), Toast.LENGTH_LONG); 66 | toast.show(); 67 | } 68 | 69 | mTvStatus.setText(msg); 70 | } 71 | 72 | @Override 73 | protected String doInBackground(Void... params) { 74 | Inventory inventory = Inventory.getInstance(mActivity); 75 | 76 | OCSProtocol ocsproto = new OCSProtocol(mAppCtx.getApplicationContext()); 77 | 78 | if (!mSend) { 79 | String status = new OCSFiles(mAppCtx).copyToExternal(inventory); 80 | if ("OK".equals(status)) { 81 | status = mAppCtx.getString(R.string.state_saved); 82 | } 83 | return status; 84 | } 85 | publishProgress(R.string.state_send_prolog); 86 | 87 | OCSPrologReply reply; 88 | String rep; 89 | try { 90 | reply = ocsproto.sendPrologueMessage(); 91 | } catch (OCSProtocolException e1) { 92 | return e1.getMessage(); 93 | } 94 | OCSLog.getInstance().debug("Retour send prolog [" + reply.getResponse() + "]"); 95 | OCSLog.getInstance().debug(reply.log()); 96 | if ("ERROR".equals(reply.getResponse())) { 97 | return reply.getResponse(); 98 | } else { 99 | publishProgress(R.string.state_send_inventory); 100 | try { 101 | rep = ocsproto.sendInventoryMessage(inventory); 102 | } catch (OCSProtocolException e) { 103 | return e.getMessage(); 104 | } 105 | 106 | 107 | OCSLog.getInstance().debug("Retour send inventory [" + rep + "]"); 108 | 109 | if (!reply.getIdList().isEmpty()) { 110 | OCSLog.getInstance().debug(mAppCtx.getString(R.string.start_download_service)); 111 | 112 | // Some downlowds requiered invoke download service 113 | Intent dldService = new Intent(mAppCtx, OCSDownloadService.class); 114 | mAppCtx.startService(dldService); 115 | mDownload = true; // Info for postexecute stage 116 | } 117 | 118 | if (rep == null) { 119 | return mAppCtx.getString(R.string.state_send_error); 120 | } else if (rep.length() == 0) { 121 | return mAppCtx.getString(R.string.state_sent_inventory); 122 | } else { 123 | return rep; 124 | } 125 | } 126 | } 127 | 128 | protected void onProgressUpdate(Integer... progress) { 129 | mProgressDialog.setMessage(mAppCtx.getString(progress[0])); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /app/src/main/java/org/ocs/android/agent/ExpandableSectionAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2016 OCSInventory-NG/AndroidAgent contributors : mortheres, cdpointpoint, 3 | * Cédric Cabessa, Nicolas Ricquemaque, Anael Mobilia 4 | * 5 | * This file is part of OCSInventory-NG/AndroidAgent. 6 | * 7 | * OCSInventory-NG/AndroidAgent is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * OCSInventory-NG/AndroidAgent is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with OCSInventory-NG/AndroidAgent. if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | */ 21 | package org.ocs.android.agent; 22 | 23 | import android.content.Context; 24 | import android.view.LayoutInflater; 25 | import android.view.View; 26 | import android.view.ViewGroup; 27 | import android.widget.BaseExpandableListAdapter; 28 | import android.widget.TextView; 29 | 30 | import org.ocs.android.sections.OCSSection; 31 | 32 | import java.util.HashMap; 33 | import java.util.List; 34 | 35 | public class ExpandableSectionAdapter extends BaseExpandableListAdapter { 36 | // Context 37 | private Context myContext; 38 | // 39 | private HashMap> myDatas; 40 | 41 | public ExpandableSectionAdapter(Context myContext, HashMap> myDatas) { 42 | this.myContext = myContext; 43 | this.myDatas = myDatas; 44 | } 45 | 46 | /** 47 | * Number of Sections 48 | * 49 | * @return int 50 | */ 51 | @Override 52 | public int getGroupCount() { 53 | return myDatas.size(); 54 | } 55 | 56 | /** 57 | * Number of details on a specific section 58 | */ 59 | @Override 60 | public int getChildrenCount(int groupPosition) { 61 | return myDatas.get(getGroup(groupPosition)).size(); 62 | } 63 | 64 | /** 65 | * Get section name 66 | * @return String 67 | */ 68 | @Override 69 | public Object getGroup(int groupPosition) { 70 | return myDatas.keySet().toArray()[groupPosition]; 71 | } 72 | 73 | /** 74 | * Get details of a Section 75 | * @return Section 76 | */ 77 | @Override 78 | public Object getChild(int groupPosition, int childPosition) { 79 | return myDatas.get(getGroup(groupPosition)).get(childPosition); 80 | } 81 | 82 | @Override 83 | public long getGroupId(int groupPosition) { 84 | return groupPosition; 85 | } 86 | 87 | @Override 88 | public long getChildId(int groupPosition, int childPosition) { 89 | return childPosition; 90 | } 91 | 92 | @Override 93 | public boolean hasStableIds() { 94 | return false; 95 | } 96 | 97 | /** 98 | * Display section title 99 | */ 100 | @Override 101 | public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { 102 | View maView = convertView; 103 | 104 | // Get this group title 105 | String headerTitle = (String) getGroup(groupPosition); 106 | 107 | if (maView == null) { 108 | LayoutInflater monLayoutInflater = (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 109 | maView = monLayoutInflater.inflate(R.layout.list_header, parent, false); 110 | } 111 | 112 | // Display it :-) 113 | TextView lblListHeader = (TextView) maView.findViewById(R.id.list_header_name); 114 | lblListHeader.setText(headerTitle); 115 | 116 | return maView; 117 | } 118 | 119 | /** 120 | * Display section details 121 | */ 122 | @Override 123 | public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { 124 | View maView = convertView; 125 | 126 | // Get part of details of this section 127 | final OCSSection maSection = (OCSSection) getChild(groupPosition, childPosition); 128 | 129 | if (maView == null) { 130 | LayoutInflater monLayoutInflater = (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 131 | maView = monLayoutInflater.inflate(R.layout.list_item, parent, false); 132 | } 133 | 134 | // Display it :-) 135 | TextView itemName = (TextView) maView.findViewById(R.id.list_item_name); 136 | TextView itemDetail = (TextView) maView.findViewById(R.id.list_item_detail); 137 | 138 | itemName.setText(maSection.getTitle()); 139 | itemDetail.setText(maSection.toString()); 140 | return maView; 141 | } 142 | 143 | @Override 144 | public boolean isChildSelectable(int groupPosition, int childPosition) { 145 | return false; 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /app/src/main/java/org/ocs/android/agent/OCSDownloadIdParams.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2016 OCSInventory-NG/AndroidAgent contributors : mortheres, cdpointpoint, 3 | * Cédric Cabessa, Nicolas Ricquemaque, Anael Mobilia 4 | * 5 | * This file is part of OCSInventory-NG/AndroidAgent. 6 | * 7 | * OCSInventory-NG/AndroidAgent is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * OCSInventory-NG/AndroidAgent is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with OCSInventory-NG/AndroidAgent. if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | */ 21 | package org.ocs.android.agent; 22 | 23 | 24 | /* 25 | * 27 | * 28 | */ 29 | public class OCSDownloadIdParams { 30 | private String id; 31 | private String schedule; 32 | private String certFile; 33 | private String type; 34 | private String infoLoc; 35 | private String certPath; 36 | private String packLoc; 37 | private boolean force; 38 | private String postcmd; 39 | 40 | private OCSDownloadInfos infos = null; 41 | private int downloaded = 0; 42 | 43 | 44 | public int getDownloaded() { 45 | return downloaded; 46 | } 47 | 48 | public void setDownloaded(int downloaded) { 49 | this.downloaded = downloaded; 50 | } 51 | 52 | public OCSDownloadInfos getInfos() { 53 | return infos; 54 | } 55 | 56 | public void setInfos(OCSDownloadInfos infos) { 57 | this.infos = infos; 58 | } 59 | 60 | public String getId() { 61 | return id; 62 | } 63 | 64 | public void setId(String str) { 65 | this.id = str; 66 | } 67 | 68 | public String getSchedule() { 69 | return schedule; 70 | } 71 | 72 | public void setSchedule(String schedule) { 73 | this.schedule = schedule; 74 | } 75 | 76 | public String getCertFile() { 77 | return certFile; 78 | } 79 | 80 | public void setCertFile(String certFile) { 81 | this.certFile = certFile; 82 | } 83 | 84 | public String getType() { 85 | return type; 86 | } 87 | 88 | public void setType(String type) { 89 | this.type = type; 90 | } 91 | 92 | public String getInfoLoc() { 93 | return infoLoc; 94 | } 95 | 96 | public void setInfoLoc(String infoLoc) { 97 | this.infoLoc = infoLoc; 98 | } 99 | 100 | public String getCertPath() { 101 | return certPath; 102 | } 103 | 104 | public void setCertPath(String certPath) { 105 | this.certPath = certPath; 106 | } 107 | 108 | public String getPackLoc() { 109 | return packLoc; 110 | } 111 | 112 | public void setPackLoc(String packLoc) { 113 | this.packLoc = packLoc; 114 | } 115 | 116 | public boolean isForce() { 117 | return force; 118 | } 119 | 120 | public void setForce(boolean force) { 121 | this.force = force; 122 | } 123 | 124 | public void setForce(String str) { 125 | if (str == null) { 126 | return; 127 | } 128 | this.force = "1".equals(str); 129 | } 130 | 131 | public String getPostcmd() { 132 | return postcmd; 133 | } 134 | 135 | public void setPostcmd(String postcmd) { 136 | this.postcmd = postcmd; 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /app/src/main/java/org/ocs/android/agent/OCSDownloadInfos.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2016 OCSInventory-NG/AndroidAgent contributors : mortheres, cdpointpoint, 3 | * Cédric Cabessa, Nicolas Ricquemaque, Anael Mobilia 4 | * 5 | * This file is part of OCSInventory-NG/AndroidAgent. 6 | * 7 | * OCSInventory-NG/AndroidAgent is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * OCSInventory-NG/AndroidAgent is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with OCSInventory-NG/AndroidAgent. if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | */ 21 | package org.ocs.android.agent; 22 | 23 | import android.util.Log; 24 | 25 | public class OCSDownloadInfos { 26 | private String id; 27 | private int pri; 28 | private String act; 29 | private String digest; 30 | private String proto; 31 | private int frags; 32 | private String digestAlgo; 33 | private String digestEncode; 34 | private String path; 35 | private String notifyText; 36 | private String notifyCountdown; 37 | private boolean notifyUser; 38 | private boolean notifyCanAbort; 39 | private boolean notifyCanDelay; 40 | private boolean needDoneAction; 41 | private String needDoneActionText; 42 | 43 | 44 | public OCSDownloadInfos(String strinfos) { 45 | id = extrAttr(strinfos, "ID"); 46 | act = extrAttr(strinfos, "ACT"); 47 | digest = extrAttr(strinfos, "DIGEST"); 48 | proto = extrAttr(strinfos, "PROTO"); 49 | digestAlgo = extrAttr(strinfos, "DIGEST_ALGO"); 50 | digestEncode = extrAttr(strinfos, "DIGEST_ENCODE"); 51 | path = extrAttr(strinfos, "PATH"); 52 | notifyCountdown = extrAttr(strinfos, "NOTIFY_COUNTDOWN"); 53 | notifyCanAbort = extrAttr(strinfos, "NOTIFY_CAN_ABORT").equals("1"); 54 | notifyCanDelay = extrAttr(strinfos, "NOTIFY_CAN_DELAY").equals("1"); 55 | needDoneAction = extrAttr(strinfos, "NEED_DONE_ACTION").equals("1"); 56 | needDoneActionText = extrAttr(strinfos, "NEED_DONE_ACTION_TEXT"); 57 | try { 58 | pri = Integer.parseInt(extrAttr(strinfos, "PRI")); 59 | } catch (NumberFormatException e) { 60 | } 61 | 62 | try { 63 | frags = Integer.parseInt(extrAttr(strinfos, "FRAGS")); 64 | } catch (NumberFormatException e) { 65 | } 66 | } 67 | 68 | private String extrAttr(String doc, String attrName) { 69 | int x = doc.indexOf(attrName); 70 | x = doc.indexOf("\"", x); 71 | int y = doc.indexOf("\"", x + 1); 72 | Log.i("extrattr", attrName + ":" + doc.substring(x + 1, y)); 73 | return doc.substring(x + 1, y); 74 | } 75 | 76 | public String getId() { 77 | return id; 78 | } 79 | 80 | public int getPri() { 81 | return pri; 82 | } 83 | 84 | /** 85 | * @return action requested 86 | */ 87 | public String getAct() { 88 | return act; 89 | } 90 | 91 | /** 92 | * @return digest value as string 93 | */ 94 | public String getDigest() { 95 | return digest; 96 | } 97 | 98 | /** 99 | * @return protocol to use (HTTP/HTTPS) 100 | */ 101 | public String getProto() { 102 | return proto; 103 | } 104 | 105 | /** 106 | * @return number of fragments 107 | */ 108 | public int getFrags() { 109 | return frags; 110 | } 111 | 112 | public String getNeedDoneActionText() { 113 | return needDoneActionText; 114 | } 115 | 116 | public String getDigestAlgo() { 117 | return digestAlgo; 118 | } 119 | 120 | public String getDigestEncode() { 121 | return digestEncode; 122 | } 123 | 124 | public String getPath() { 125 | return path; 126 | } 127 | 128 | public String getNotifyText() { 129 | return notifyText; 130 | } 131 | 132 | public String getNotifyCountdown() { 133 | return notifyCountdown; 134 | } 135 | 136 | public boolean isNotifyUser() { 137 | return notifyUser; 138 | } 139 | 140 | public boolean isNotifyCanAbort() { 141 | return notifyCanAbort; 142 | } 143 | 144 | public boolean isNotifyCanDelay() { 145 | return notifyCanDelay; 146 | } 147 | 148 | public boolean isNeedDoneAction() { 149 | return needDoneAction; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /app/src/main/java/org/ocs/android/agent/OCSPrologReply.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2016 OCSInventory-NG/AndroidAgent contributors : mortheres, cdpointpoint, 3 | * Cédric Cabessa, Nicolas Ricquemaque, Anael Mobilia 4 | * 5 | * This file is part of OCSInventory-NG/AndroidAgent. 6 | * 7 | * OCSInventory-NG/AndroidAgent is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * OCSInventory-NG/AndroidAgent is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with OCSInventory-NG/AndroidAgent. if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | */ 21 | package org.ocs.android.agent; 22 | 23 | import java.util.ArrayList; 24 | 25 | 26 | /* 27 | * 30 | * 31 | */ 32 | public class OCSPrologReply { 33 | final private int DEF_PERIODE_LENGTH = 10; 34 | 35 | private String type; 36 | private String response; 37 | private String prologFreq; 38 | private String optName; 39 | 40 | private int periodLatency; // Wait between 2 periods of deployment (def 1 sec) 41 | private int cycleLatency; // Wait between 2 cycles (def 60 sec ) 42 | private int fragLatency; // Wait between 2 fragment download ( def. 10 sec ) 43 | private int timeout; // Validity of a package from 1st consideration 44 | private int periodeLength; // Nombre de cycle dans la periode def 10 45 | private int executionTimeout; 46 | private boolean on; 47 | private ArrayList idList; 48 | 49 | public OCSPrologReply() { 50 | idList = new ArrayList<>(); 51 | optName = null; 52 | response = ""; 53 | } 54 | 55 | public String log() { 56 | StringBuilder sb = new StringBuilder(); 57 | sb.append("OPTION: ").append(getOptName()).append("\n"); 58 | sb.append("prologFreq: ").append(getPrologFreq()).append("\n"); 59 | sb.append("periodLatency: ").append(getPeriodLatency()).append("\n"); 60 | sb.append("cycleLatency: ").append(getCycleLatency()).append("\n"); 61 | for (OCSDownloadIdParams dip : getIdList()) { 62 | sb.append("PARAM ID: ").append(dip.getId()).append("TYPE:").append(dip.getType()).append("\n"); 63 | } 64 | return sb.toString(); 65 | } 66 | 67 | public String getResponse() { 68 | return response; 69 | } 70 | 71 | public void setResponse(String response) { 72 | this.response = response; 73 | } 74 | 75 | public String getPrologFreq() { 76 | return prologFreq; 77 | } 78 | 79 | public void setPrologFreq(String prologFreq) { 80 | this.prologFreq = prologFreq; 81 | } 82 | 83 | public String getOptName() { 84 | return optName; 85 | } 86 | 87 | public void setOptName(String optName) { 88 | this.optName = optName; 89 | } 90 | 91 | /** 92 | * Wait between 2 fragment download ( def. 10 sec ) 93 | */ 94 | public int getFragLatency() { 95 | return fragLatency; 96 | } 97 | 98 | public void setFragLatency(int fragLatency) { 99 | this.fragLatency = fragLatency; 100 | } 101 | 102 | public void setFragLatency(String str) { 103 | try { 104 | setFragLatency(Integer.parseInt(str)); 105 | } catch (NumberFormatException e) { 106 | } 107 | } 108 | 109 | /** 110 | * Wait between 2 periods of deployment (def 1 sec) 111 | */ 112 | public int getPeriodLatency() { 113 | return periodLatency; 114 | } 115 | 116 | public void setPeriodLatency(int periodLatency) { 117 | this.periodLatency = periodLatency; 118 | } 119 | 120 | public void setPeriodLatency(String str) { 121 | try { 122 | setPeriodLatency(Integer.parseInt(str)); 123 | } catch (NumberFormatException e) { 124 | } 125 | } 126 | 127 | /** 128 | * Wait between 2 cycles (def 60 sec ) 129 | */ 130 | public int getCycleLatency() { 131 | return cycleLatency; 132 | } 133 | 134 | public void setCycleLatency(int cycleLatency) { 135 | this.cycleLatency = cycleLatency; 136 | } 137 | 138 | public void setCycleLatency(String str) { 139 | try { 140 | setCycleLatency(Integer.parseInt(str)); 141 | } catch (NumberFormatException e) { 142 | } 143 | } 144 | 145 | public int getTimeout() { 146 | return timeout; 147 | } 148 | 149 | public void setTimeout(int timeout) { 150 | this.timeout = timeout; 151 | } 152 | 153 | public void setTimeout(String str) { 154 | try { 155 | this.timeout = Integer.parseInt(str); 156 | } catch (NumberFormatException e) { 157 | } 158 | } 159 | 160 | public int getPeriodeLength() { 161 | return periodeLength; 162 | } 163 | 164 | public void setPeriodeLength(int periodeLength) { 165 | this.periodeLength = periodeLength; 166 | } 167 | 168 | public void setPeriodeLength(String str) { 169 | try { 170 | setPeriodeLength(Integer.parseInt(str)); 171 | } catch (NumberFormatException e) { 172 | setPeriodeLength(DEF_PERIODE_LENGTH); 173 | } 174 | } 175 | 176 | public int getExecutionTimeout() { 177 | return executionTimeout; 178 | } 179 | 180 | public void setExecutionTimeout(int executionTimeout) { 181 | this.executionTimeout = executionTimeout; 182 | } 183 | 184 | public void setExecutionTimeout(String str) { 185 | try { 186 | setExecutionTimeout(Integer.parseInt(str)); 187 | } catch (NumberFormatException e) { 188 | } 189 | } 190 | 191 | public boolean isOn() { 192 | return on; 193 | } 194 | 195 | public void setOn(boolean on) { 196 | this.on = on; 197 | } 198 | 199 | public void setOn(String str) { 200 | if (str == null) { 201 | return; 202 | } 203 | this.on = "1".equals(str); 204 | } 205 | 206 | public String getType() { 207 | return type; 208 | } 209 | 210 | public void setType(String type) { 211 | this.type = type; 212 | } 213 | 214 | public ArrayList getIdList() { 215 | return idList; 216 | } 217 | 218 | public void setIdList(ArrayList idList) { 219 | this.idList = idList; 220 | } 221 | } 222 | -------------------------------------------------------------------------------- /app/src/main/java/org/ocs/android/agent/activity/OCSShowInventory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2016 OCSInventory-NG/AndroidAgent contributors : mortheres, cdpointpoint, 3 | * Cédric Cabessa, Nicolas Ricquemaque, Anael Mobilia 4 | * 5 | * This file is part of OCSInventory-NG/AndroidAgent. 6 | * 7 | * OCSInventory-NG/AndroidAgent is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * OCSInventory-NG/AndroidAgent is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with OCSInventory-NG/AndroidAgent. if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | */ 21 | package org.ocs.android.agent.activity; 22 | 23 | import android.os.Bundle; 24 | import android.support.annotation.Nullable; 25 | import android.support.v7.app.AppCompatActivity; 26 | import android.widget.ExpandableListAdapter; 27 | import android.widget.ExpandableListView; 28 | 29 | import org.ocs.android.actions.Inventory; 30 | import org.ocs.android.agent.ExpandableSectionAdapter; 31 | import org.ocs.android.agent.R; 32 | 33 | /** 34 | * Display inventory to the user 35 | */ 36 | public class OCSShowInventory extends AppCompatActivity { 37 | 38 | @Override 39 | protected void onCreate(@Nullable Bundle savedInstanceState) { 40 | super.onCreate(savedInstanceState); 41 | 42 | setContentView(R.layout.actvity_show_inventory); 43 | 44 | // Get the listview 45 | ExpandableListView maListView = (ExpandableListView) findViewById(R.id.myListView); 46 | 47 | // Set datas 48 | ExpandableListAdapter monListAdapter = new ExpandableSectionAdapter(this, Inventory.getInstance(this).getAllSections()); 49 | 50 | // Set list adapter 51 | maListView.setAdapter(monListAdapter); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/org/ocs/android/agent/receiver/OCSBootReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2016 OCSInventory-NG/AndroidAgent contributors : mortheres, cdpointpoint, 3 | * Cédric Cabessa, Nicolas Ricquemaque, Anael Mobilia 4 | * 5 | * This file is part of OCSInventory-NG/AndroidAgent. 6 | * 7 | * OCSInventory-NG/AndroidAgent is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * OCSInventory-NG/AndroidAgent is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with OCSInventory-NG/AndroidAgent. if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | */ 21 | package org.ocs.android.agent.receiver; 22 | 23 | import android.app.AlarmManager; 24 | import android.app.PendingIntent; 25 | import android.content.BroadcastReceiver; 26 | import android.content.Context; 27 | import android.content.Intent; 28 | import android.util.Log; 29 | 30 | import org.ocs.android.actions.OCSLog; 31 | import org.ocs.android.actions.OCSSettings; 32 | 33 | import java.util.Calendar; 34 | 35 | public class OCSBootReceiver extends BroadcastReceiver { 36 | 37 | @Override 38 | public void onReceive(final Context ctx, final Intent intent) { 39 | Log.d("OCSBOOT", "on Receive called"); 40 | OCSSettings ocssetting = OCSSettings.getInstance(ctx); 41 | OCSLog ocslog = OCSLog.getInstance(); 42 | ocslog.debug("OCSBootReceiver : " + intent.getAction()); 43 | if (ocssetting == null) { 44 | ocslog.error("NULL OSSETTING"); 45 | return; 46 | } 47 | 48 | if (!ocssetting.isAutoMode()) { 49 | return; 50 | } 51 | int interval = ocssetting.getFreqWake(); 52 | ocslog.debug("OCSBootReceiver interval : " + interval); 53 | 54 | AlarmManager alarmManager = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE); 55 | Intent i = new Intent(ctx, OCSEventReceiver.class); 56 | 57 | PendingIntent intentExecuted = PendingIntent.getBroadcast(ctx, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); 58 | Calendar start = Calendar.getInstance(); 59 | start.add(Calendar.SECOND, 5); 60 | alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, start.getTimeInMillis(), interval * 60000L, intentExecuted); 61 | } 62 | } -------------------------------------------------------------------------------- /app/src/main/java/org/ocs/android/agent/receiver/OCSEventReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2016 OCSInventory-NG/AndroidAgent contributors : mortheres, cdpointpoint, 3 | * Cédric Cabessa, Nicolas Ricquemaque, Anael Mobilia 4 | * 5 | * This file is part of OCSInventory-NG/AndroidAgent. 6 | * 7 | * OCSInventory-NG/AndroidAgent is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * OCSInventory-NG/AndroidAgent is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with OCSInventory-NG/AndroidAgent. if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | */ 21 | package org.ocs.android.agent.receiver; 22 | 23 | import android.content.BroadcastReceiver; 24 | import android.content.Context; 25 | import android.content.Intent; 26 | import android.util.Log; 27 | 28 | import org.ocs.android.agent.service.OCSAgentService; 29 | 30 | public class OCSEventReceiver extends BroadcastReceiver { 31 | private static final String LOGTAG = "OCSEventReceiver"; 32 | 33 | @Override 34 | public void onReceive(final Context ctx, final Intent intent) { 35 | Log.d(LOGTAG, "Called"); 36 | Intent eventService = new Intent(ctx, OCSAgentService.class); 37 | boolean forceUpdate = intent.getBooleanExtra(OCSAgentService.FORCE_UPDATE, false); 38 | eventService.putExtra(OCSAgentService.FORCE_UPDATE, forceUpdate); 39 | boolean saveInventory = intent.getBooleanExtra(OCSAgentService.SAVE_INVENTORY, false); 40 | eventService.putExtra(OCSAgentService.SAVE_INVENTORY, saveInventory); 41 | ctx.startService(eventService); 42 | Log.d(LOGTAG, "After start service"); 43 | } 44 | } -------------------------------------------------------------------------------- /app/src/main/java/org/ocs/android/agent/receiver/OCSInstallReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2016 OCSInventory-NG/AndroidAgent contributors : mortheres, cdpointpoint, 3 | * Cédric Cabessa, Nicolas Ricquemaque, Anael Mobilia 4 | * 5 | * This file is part of OCSInventory-NG/AndroidAgent. 6 | * 7 | * OCSInventory-NG/AndroidAgent is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * OCSInventory-NG/AndroidAgent is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with OCSInventory-NG/AndroidAgent. if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | */ 21 | package org.ocs.android.agent.receiver; 22 | 23 | import android.content.BroadcastReceiver; 24 | import android.content.Context; 25 | import android.content.Intent; 26 | import android.content.pm.PackageInfo; 27 | import android.content.pm.PackageManager; 28 | import android.content.pm.PackageManager.NameNotFoundException; 29 | import android.os.AsyncTask; 30 | import android.widget.Toast; 31 | 32 | import org.ocs.android.actions.OCSLog; 33 | import org.ocs.android.actions.OCSProtocol; 34 | import org.ocs.android.actions.OCSProtocolException; 35 | 36 | import java.io.File; 37 | import java.io.FileInputStream; 38 | 39 | public class OCSInstallReceiver extends BroadcastReceiver { 40 | private OCSLog mOCSlog; 41 | private String mStatus; 42 | private String mOCSid; 43 | 44 | @Override 45 | public void onReceive(final Context ctx, final Intent intent) { 46 | mOCSlog = OCSLog.getInstance(); 47 | byte buffer[] = new byte[80]; 48 | 49 | String data = intent.getData().toString(); 50 | mOCSlog.debug("OCSInstallReceiver : " + intent.getAction()); 51 | Toast.makeText(ctx, "OCSInstallReceiver : " + intent.getAction(), Toast.LENGTH_SHORT).show(); 52 | String packageName = data.split(":")[1]; 53 | mOCSlog.debug("Package : " + packageName); 54 | try { 55 | mOCSlog.debug("Lecture " + packageName + ".inst"); 56 | FileInputStream fis = ctx.openFileInput(packageName + ".inst"); 57 | // Read and store to buffer 58 | fis.read(buffer); 59 | String s = new String(buffer); 60 | String t[] = s.split(":"); 61 | mOCSid = t[0]; 62 | int version = Integer.parseInt(t[1]); 63 | fis.close(); 64 | 65 | if (isPkgInstalled(ctx, packageName, version)) { 66 | mOCSlog.debug("Package installed return success to OCS server"); 67 | mStatus = "SUCCESS"; 68 | } else { 69 | mOCSlog.debug("Package not installed return fail to OCS server"); 70 | mStatus = "ERR_ABORTED"; 71 | } 72 | 73 | AsyncSend task = new AsyncSend(ctx); 74 | task.execute(); 75 | 76 | // Clean download files 77 | File fapk = new File(ctx.getExternalCacheDir(), mOCSid + ".apk"); 78 | fapk.delete(); 79 | File finst = new File(ctx.getFilesDir(), packageName + ".inst"); 80 | finst.delete(); 81 | File finfo = new File(ctx.getFilesDir(), mOCSid + ".info"); 82 | finfo.delete(); 83 | } catch (Exception e) { 84 | mOCSlog.error(e.getMessage()); 85 | } 86 | } 87 | 88 | /** 89 | * Check if a package is installed with a given version code 90 | * 91 | * @param pkg Package name 92 | * @param version Version code 93 | * @return true if installed 94 | */ 95 | private boolean isPkgInstalled(Context ctx, String pkg, int version) { 96 | PackageManager pm = ctx.getPackageManager(); 97 | 98 | mOCSlog.debug("Check installation " + pkg + "/" + version); 99 | try { 100 | PackageInfo lpInfo = pm.getPackageInfo(pkg, PackageManager.GET_ACTIVITIES); 101 | return (lpInfo.versionCode == version); 102 | } catch (NameNotFoundException e) { 103 | mOCSlog.error("Package notfound"); 104 | return false; 105 | } 106 | } 107 | 108 | private class AsyncSend extends AsyncTask { 109 | private Context mContext; 110 | 111 | AsyncSend(Context ctx) { 112 | mContext = ctx; 113 | } 114 | 115 | @Override 116 | protected Void doInBackground(Void... params) { 117 | OCSProtocol ocsproto = new OCSProtocol(mContext.getApplicationContext()); 118 | try { 119 | ocsproto.sendRequestMessage("DOWNLOAD", mOCSid, mStatus); 120 | } catch (OCSProtocolException e) { 121 | mOCSlog.error(e.getMessage()); 122 | } 123 | return null; 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /app/src/main/java/org/ocs/android/sections/OCSBios.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2016 OCSInventory-NG/AndroidAgent contributors : mortheres, cdpointpoint, 3 | * Cédric Cabessa, Nicolas Ricquemaque, Anael Mobilia 4 | * 5 | * This file is part of OCSInventory-NG/AndroidAgent. 6 | * 7 | * OCSInventory-NG/AndroidAgent is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * OCSInventory-NG/AndroidAgent is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with OCSInventory-NG/AndroidAgent. if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | */ 21 | package org.ocs.android.sections; 22 | 23 | import android.Manifest; 24 | import android.content.Context; 25 | import android.content.pm.PackageManager; 26 | import android.os.Build; 27 | import android.support.v4.app.ActivityCompat; 28 | import android.text.format.DateFormat; 29 | 30 | import org.ocs.android.actions.OCSLog; 31 | 32 | import java.util.ArrayList; 33 | 34 | /* 35 | * 36 | Asset-1234567890 37 | 03/26/2008 38 | American Megatrends Inc. 39 | 0802 40 | ASUSTeK Computer INC. 41 | P5KPL-VM 42 | MT7084K06409125 43 | System manufacturer 44 | System Product Name 45 | System Serial Number 46 | * 47 | * 48 | 49 | BIOS (BDATE | BMANUFACTURER | BVERSION | SMANUFACTURER | SMODEL | SSN | TYPE | ASSETTAG) 50 | */ 51 | public class OCSBios implements OCSSectionInterface { 52 | 53 | final private String sectionTag = "BIOS"; 54 | 55 | private String assettag; 56 | private String date; 57 | private String manufacturer; 58 | private String version; 59 | private String serial; 60 | private String type; 61 | private String smodel; 62 | 63 | public OCSBios(Context mCtx) { 64 | type = "Mobile"; 65 | OCSLog ocslog = OCSLog.getInstance(); 66 | assettag = Build.ID + "-0123456789"; 67 | date = (String) DateFormat.format("MM/dd/yy", Build.TIME); 68 | manufacturer = Build.MANUFACTURER; 69 | version = Build.BOOTLOADER; 70 | ocslog.debug("BIOS version: " + version); 71 | try { 72 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 73 | serial = Build.getSerial(); 74 | } 75 | } catch (SecurityException e) { 76 | serial = SystemInfos.getInstance().getSerial(); 77 | } 78 | ocslog.debug("OCSBIOS serial " + serial); 79 | smodel = Build.MODEL; 80 | ocslog.debug("OCSBIOS model: " + smodel); 81 | } 82 | /* 83 | 84 | */ 85 | 86 | public OCSSection getSection() { 87 | OCSSection s = new OCSSection(sectionTag); 88 | s.setAttr("TYPE", type); 89 | s.setAttr("ASSETTAG", assettag); 90 | s.setAttr("BDATE", date); 91 | s.setAttr("BMANUFACTURER", manufacturer); 92 | s.setAttr("BVERSION", version); 93 | s.setAttr("MMANUFACTURER", manufacturer); 94 | s.setAttr("MSN", serial); 95 | s.setAttr("SMANUFACTURER", manufacturer); 96 | s.setAttr("SMODEL", smodel); 97 | s.setAttr("SSN", serial); 98 | s.setTitle(assettag); 99 | return s; 100 | } 101 | 102 | public ArrayList getSections() { 103 | ArrayList lst = new ArrayList<>(); 104 | lst.add(getSection()); 105 | return lst; 106 | } 107 | 108 | public String toString() { 109 | return getSection().toString(); 110 | } 111 | 112 | public String toXML() { 113 | return getSection().toXML(); 114 | } 115 | 116 | public String getSectionTag() { 117 | return sectionTag; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /app/src/main/java/org/ocs/android/sections/OCSDrive.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2016 OCSInventory-NG/AndroidAgent contributors : mortheres, cdpointpoint, 3 | * Cédric Cabessa, Nicolas Ricquemaque, Anael Mobilia 4 | * 5 | * This file is part of OCSInventory-NG/AndroidAgent. 6 | * 7 | * OCSInventory-NG/AndroidAgent is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * OCSInventory-NG/AndroidAgent is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with OCSInventory-NG/AndroidAgent. if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | */ 21 | package org.ocs.android.sections; 22 | 23 | import android.os.StatFs; 24 | import android.text.format.DateFormat; 25 | 26 | import java.io.File; 27 | 28 | public class OCSDrive { 29 | private String createdate; 30 | private String filesystem = null; 31 | private String type; 32 | private long free; 33 | private String label = null; 34 | private String serial; 35 | private long total; 36 | private String volumName = null; 37 | 38 | public OCSDrive(String fs) { 39 | File d = new File(fs); 40 | StatFs statfs = new StatFs(fs); 41 | long bs = statfs.getBlockSize(); 42 | long bc = statfs.getBlockCount(); 43 | long fb = statfs.getFreeBlocks(); 44 | 45 | total = bs * bc / 1048576L; 46 | free = bs * fb / 1048576L; 47 | type = fs; 48 | createdate = (String) DateFormat.format("MM/dd/yy mm:ss", d.lastModified()); 49 | } 50 | 51 | /* 52 | * 2011/11/17 20:47:06 53 | * ext4 29584