├── .gitignore
├── .project
├── .settings
└── org.eclipse.m2e.core.prefs
├── LICENSE
├── README.md
├── UtilSet
├── .checkstyle
├── .gitignore
├── LICENSE
├── pom.xml
├── project.properties
├── src
│ └── com
│ │ └── navercorp
│ │ └── utilset
│ │ ├── audio
│ │ └── VolumeUtils.java
│ │ ├── cipher
│ │ ├── AesCipher.java
│ │ ├── CipherMode.java
│ │ ├── CipherObject.java
│ │ ├── CipherObjectFactory.java
│ │ └── CipherUtils.java
│ │ ├── device
│ │ ├── DeviceType.java
│ │ ├── DeviceTypeDetector.java
│ │ ├── DeviceUtils.java
│ │ ├── LauncherInfo.java
│ │ ├── LauncherType.java
│ │ ├── LauncherTypeDetector.java
│ │ └── PhoneNumberUtils.java
│ │ ├── input
│ │ ├── KeyboardUtils.java
│ │ └── SoftwareKeyDetector.java
│ │ ├── network
│ │ └── NetworkMonitor.java
│ │ ├── storage
│ │ └── DiskUtils.java
│ │ ├── string
│ │ ├── CompressUtils.java
│ │ └── StringCompressor.java
│ │ ├── system
│ │ ├── ProcessorUtils.java
│ │ ├── RootChecker.java
│ │ └── SystemUtils.java
│ │ └── ui
│ │ ├── ActivityUtils.java
│ │ ├── PixelUtils.java
│ │ └── ScreenUtils.java
└── test
│ └── com
│ └── navercorp
│ └── utilset
│ ├── audio
│ └── VolumeUtilsTest.java
│ ├── cipher
│ ├── CipherObjectFactoryTest.java
│ └── CipherUtilsTest.java
│ ├── storage
│ └── DiskUtilsTest.java
│ ├── string
│ └── CompressUtilsTest.java
│ ├── system
│ └── SystemUtilsTest.java
│ └── ui
│ ├── ActivityUtilsTest.java
│ ├── PixelUtilsTest.java
│ └── ScreenUtilsTest.java
├── UtilSetInstrumentationTest
├── .checkstyle
├── .classpath
├── .gitignore
├── .project
├── AndroidManifest.xml
├── LICENSE
├── ic_launcher-web.png
├── lib
│ └── utilset-0.0.1-SNAPSHOT.jar
├── libs
│ ├── android-support-v4.jar
│ └── robotium-solo-4.3.jar
├── lint.xml
├── pom.xml
├── proguard-project.txt
├── project.properties
├── repo
│ └── utilset-0.0.1-SNAPSHOT.jar
├── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ │ └── ic_launcher.png
│ ├── menu
│ │ └── main.xml
│ ├── values-sw600dp
│ │ └── dimens.xml
│ ├── values-sw720dp-land
│ │ └── dimens.xml
│ ├── values-v11
│ │ └── styles.xml
│ ├── values-v14
│ │ └── styles.xml
│ └── values
│ │ ├── description.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
└── src
│ └── com
│ └── navercorp
│ └── utilsettest
│ ├── introduction
│ └── Introduction.java
│ └── test
│ ├── CipherUtilsTestCase.java
│ ├── KeyboardUtilsTestCase.java
│ ├── NetworkListenerTestCase.java
│ ├── ScreenUtilsTestCase.java
│ ├── StringUtilsTestCase.java
│ └── VolumeUpDownTestCase.java
├── UtilSetSampleApp
├── .checkstyle
├── .classpath
├── .gitignore
├── .project
├── AndroidManifest.xml
├── LICENSE
├── ic_launcher-web.png
├── lib
│ └── utilset-0.0.1-SNAPSHOT.jar
├── libs
│ ├── android-support-v4.jar
│ └── robotium-solo-4.3.jar
├── lint.xml
├── pom.xml
├── proguard-project.txt
├── project.properties
├── repo
│ └── utilset-0.0.1-SNAPSHOT.jar
├── res
│ ├── drawable-hdpi
│ │ ├── close_button.png
│ │ ├── ic_launcher.png
│ │ ├── progress_bg_holo_dark.9.png
│ │ ├── progress_horizontal_holo_dark.xml
│ │ ├── progress_primary_holo_dark.9.png
│ │ ├── progress_secondary_holo_dark.9.png
│ │ └── rounded_background.xml
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ │ └── ic_launcher.png
│ ├── layout
│ │ ├── acitivty_volumeutils.xml
│ │ ├── activity_activityutils.xml
│ │ ├── activity_cipher.xml
│ │ ├── activity_deviceutils.xml
│ │ ├── activity_diskutils.xml
│ │ ├── activity_keyboardutils.xml
│ │ ├── activity_main.xml
│ │ ├── activity_network_listener.xml
│ │ ├── activity_networkutils.xml
│ │ ├── activity_stringutils.xml
│ │ ├── activity_systemutils.xml
│ │ ├── dialog_introduction.xml
│ │ ├── fragment_keep_screen_on.xml
│ │ └── fragment_reset_screen_on.xml
│ ├── menu
│ │ └── main.xml
│ ├── values-sw600dp
│ │ └── dimens.xml
│ ├── values-sw720dp-land
│ │ └── dimens.xml
│ ├── values-v11
│ │ └── styles.xml
│ ├── values-v14
│ │ └── styles.xml
│ └── values
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
└── src
│ └── com
│ └── navercorp
│ └── utilsettest
│ ├── ButtonColor.java
│ ├── ButtonColorList.java
│ ├── MainActivity.java
│ ├── audio
│ └── VolumeUtilsTestActivity.java
│ ├── cipher
│ └── CipherTestActivity.java
│ ├── device
│ └── DeviceUtilsTestActivity.java
│ ├── dialog
│ ├── IntroductionDialogController.java
│ ├── IntroductionDialogFactory.java
│ └── IntroductionDialogFragment.java
│ ├── input
│ └── KeyboardUtilsTestActivity.java
│ ├── network
│ ├── NetworkListenerTestActivity.java
│ └── NetworkMonitorTestActivity.java
│ ├── storage
│ └── DiskUtilsTestAcitivity.java
│ ├── string
│ └── StringUtilsTestActivity.java
│ ├── system
│ └── SystemUtilsTestActivity.java
│ └── ui
│ ├── ActivityUtilsClearScreenOnFragment.java
│ ├── ActivityUtilsConstants.java
│ ├── ActivityUtilsKeepScreenOnFragment.java
│ ├── ActivityUtilsPagerAdapter.java
│ └── ActivityUtilsTestActivity.java
├── pom.xml
└── repo
└── utilset-0.0.1-SNAPSHOT.jar
/.gitignore:
--------------------------------------------------------------------------------
1 | bin
2 | gen
3 | target
4 | .settings
5 | .claspath
6 | .project
7 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | utilset-parent
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.m2e.core.maven2Builder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.m2e.core.maven2Nature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License, Version 2.0
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
13 |
14 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
15 |
16 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
17 |
18 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
19 |
20 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
21 |
22 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
23 |
24 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
25 |
26 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
27 |
28 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
29 |
30 | 2. Grant of Copyright License.
31 |
32 | Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
33 |
34 | 3. Grant of Patent License.
35 |
36 | Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
37 |
38 | 4. Redistribution.
39 |
40 | You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
41 |
42 | You must give any other recipients of the Work or Derivative Works a copy of this License; and
43 | You must cause any modified files to carry prominent notices stating that You changed the files; and
44 | You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
45 | If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
46 | You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
47 |
48 | 5. Submission of Contributions.
49 |
50 | Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
51 |
52 | 6. Trademarks.
53 |
54 | This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
55 |
56 | 7. Disclaimer of Warranty.
57 |
58 | Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
59 |
60 | 8. Limitation of Liability.
61 |
62 | In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
63 |
64 | 9. Accepting Warranty or Additional Liability.
65 |
66 | While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
67 |
68 | END OF TERMS AND CONDITIONS
69 |
70 | APPENDIX: How to apply the Apache License to your work
71 |
72 | To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
73 |
74 | Copyright [yyyy] [name of copyright owner]
75 |
76 | Licensed under the Apache License, Version 2.0 (the "License");
77 | you may not use this file except in compliance with the License.
78 | You may obtain a copy of the License at
79 |
80 | http://www.apache.org/licenses/LICENSE-2.0
81 |
82 | Unless required by applicable law or agreed to in writing, software
83 | distributed under the License is distributed on an "AS IS" BASIS,
84 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
85 | See the License for the specific language governing permissions and
86 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android Utilset
2 |
3 | ### Introduction
4 | Utilset is collections of useful functions to save your valuable time.
5 | Because there are a ton of different ways to implement a method,
6 | we often spend our valuable time to search and test those ways.
7 | Some may work, but some may not work.
8 | As such, we collected, tested and refined methods so as to prevent seeking code snippet.
9 |
10 | -------
11 | ### Overview
12 | Utilset includes:
13 |
14 | * DeviceUtils
15 | + determines whether the device is mobile phone or not
16 | + determines if the phone has SMS capability
17 | + etc...
18 |
19 | * ActivityUtils
20 | + checks if a user specified package is installed
21 | + gets information of base activity package name and class name
22 |
23 | * NetworkUtils
24 | + provides listeners which notify when network state changes, , receives a call, or a connection is made
25 | + checks if WiFi is enabled and if WiFi is connected
26 | + checks if Mobile Network (3G/4G) is connected
27 | + obtains IP Address in either v4 or v6 form
28 | + etc...
29 |
30 | * DiskUtils
31 | + obtains external storage path for caching
32 | + obtains external storage path for temporary files
33 | + obtains MicroSD Card path
34 |
35 | * KeyboardUtils
36 | + shows, hides, and toggles Software keyboards
37 | + checks if a device has software menu/home/back button
38 |
39 | * CipherUtils
40 | + provides simple AES based cryptographic methods
41 |
42 | * StringUtils
43 | + provides string compression/decompression methods
44 |
45 | * SystemUtils
46 | + checks if a device is rooted
47 | + counts the number of processors(more specifically the number of cores)
48 |
49 |
50 | -------
51 | ### Download
52 | The latest version can be downloaded in jar and referenced as a library.
53 | Link is here http://repo.nhncorp.com/maven2/com/navercorp/utilset/utilset/1.0/utilset-1.0.jar
54 | Just add downloaded jar file into libs folder in your android project.
55 |
56 | or
57 |
58 | You can also configure pom.xml if using Maven :
59 | ```xml
60 |
61 |
62 | com.navercorp
63 | utilset
64 | 1.0.2
65 |
66 | ```
67 |
68 | -------
69 | ### Usage
70 | Please, refer sample project
71 |
72 | -------
73 | ### How to run sample project
74 | (1) Download Utilset Maven Project from https://github.com/nhnopensource/android-utilset/releases/tag/v1.0.2
75 | (2) Import downloaded project as Maven project in Eclipse (Maven plug-in must be installed to run utilset test project)
76 | (3) Right click on utilset-parent in Package Explorer
77 | (4) Select Run As and then Maven Build
78 | (5) If you run utilset-parent for the first time, then Run Configuration will appear
79 | (6) Type clean install to the Goal tab
80 | (7) Click run button on the bottom
81 |
82 | -------
83 | ## License
84 |
85 | Copyright 2013 Navercorp
86 |
87 | Licensed under the Apache License, Version 2.0 (the "License");
88 | you may not use this file except in compliance with the License.
89 | You may obtain a copy of the License at
90 |
91 | http://www.apache.org/licenses/LICENSE-2.0
92 |
93 | Unless required by applicable law or agreed to in writing, software
94 | distributed under the License is distributed on an "AS IS" BASIS,
95 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
96 | See the License for the specific language governing permissions and
97 | limitations under the License.
--------------------------------------------------------------------------------
/UtilSet/.checkstyle:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/UtilSet/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | /.classpath
3 | /.project
4 | /target
5 | /target
6 | /target
7 |
--------------------------------------------------------------------------------
/UtilSet/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License, Version 2.0
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
13 |
14 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
15 |
16 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
17 |
18 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
19 |
20 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
21 |
22 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
23 |
24 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
25 |
26 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
27 |
28 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
29 |
30 | 2. Grant of Copyright License.
31 |
32 | Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
33 |
34 | 3. Grant of Patent License.
35 |
36 | Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
37 |
38 | 4. Redistribution.
39 |
40 | You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
41 |
42 | You must give any other recipients of the Work or Derivative Works a copy of this License; and
43 | You must cause any modified files to carry prominent notices stating that You changed the files; and
44 | You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
45 | If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
46 | You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
47 |
48 | 5. Submission of Contributions.
49 |
50 | Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
51 |
52 | 6. Trademarks.
53 |
54 | This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
55 |
56 | 7. Disclaimer of Warranty.
57 |
58 | Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
59 |
60 | 8. Limitation of Liability.
61 |
62 | In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
63 |
64 | 9. Accepting Warranty or Additional Liability.
65 |
66 | While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
67 |
68 | END OF TERMS AND CONDITIONS
69 |
70 | APPENDIX: How to apply the Apache License to your work
71 |
72 | To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
73 |
74 | Copyright [yyyy] [name of copyright owner]
75 |
76 | Licensed under the Apache License, Version 2.0 (the "License");
77 | you may not use this file except in compliance with the License.
78 | You may obtain a copy of the License at
79 |
80 | http://www.apache.org/licenses/LICENSE-2.0
81 |
82 | Unless required by applicable law or agreed to in writing, software
83 | distributed under the License is distributed on an "AS IS" BASIS,
84 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
85 | See the License for the specific language governing permissions and
86 | limitations under the License.
--------------------------------------------------------------------------------
/UtilSet/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | com.navercorp
6 | utilset-parent
7 | 1.0.3-SNAPSHOT
8 |
9 |
10 | utilset
11 | jar
12 | UtilSet
13 |
14 |
15 | UTF-8
16 | 4.1.1.4
17 | 17
18 | r7
19 | 1.6
20 |
21 |
22 |
23 |
24 | com.google.android
25 | android
26 | provided
27 |
28 |
29 |
30 | com.google.android
31 | annotations
32 |
33 |
34 |
35 | com.google.android
36 | support-v4
37 |
38 |
39 |
40 | junit
41 | junit
42 |
43 |
44 |
45 | org.robolectric
46 | robolectric
47 |
48 |
49 |
50 | org.hamcrest
51 | hamcrest-all
52 | provided
53 |
54 |
55 |
56 |
57 |
58 |
59 | maven-compiler-plugin
60 | 3.1
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/UtilSet/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-17
15 |
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/audio/VolumeUtils.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.audio;
2 |
3 | import android.content.Context;
4 | import android.media.AudioManager;
5 |
6 | /**
7 | * Controls Media Volume
8 | *
9 | * @author jaemin.woo
10 | *
11 | */
12 | public class VolumeUtils {
13 | private VolumeUtils() {}
14 |
15 | /**
16 | * Returns current media volume
17 | * @param context
18 | * @return current volume
19 | */
20 | public static int getCurrentVolume(Context context) {
21 | AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
22 | return mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
23 | }
24 |
25 | /**
26 | * Sets media volume.
27 | * When setting the value of parameter 'volume' greater than the maximum value of the media volume will not either cause error or throw exception but maximize the media volume.
28 | * Setting the value of volume lower than 0 will minimize the media volume.
29 | *
30 | * @param context Context
31 | * @param volume volume to be changed
32 | */
33 | public static void setVolume(Context context, int volume) {
34 | adjustMediaVolume(context, volume, 0);
35 | }
36 |
37 | /**
38 | * Sets media volume and displays volume level.
39 | * When setting the value of parameter 'volume' greater than the maximum value of the media volume will not either cause error or throw exception but maximize the media volume.
40 | * Setting the value of volume lower than 0 will minimize the media volume.
41 | *
42 | * @param context Context
43 | * @param volume volume to be changed
44 | */
45 | public static void setVolumeWithLevel(Context context, int volume) {
46 | adjustMediaVolume(context, volume, AudioManager.FLAG_SHOW_UI);
47 | }
48 |
49 | /**
50 | * Increases media volume
51 | *
52 | * @param context
53 | */
54 | public static void increaseVolume(Context context) {
55 | adjustMediaVolume(context, getCurrentVolume(context) + 1, 0);
56 | }
57 |
58 | /**
59 | * Increases media volume and displays volume level
60 | *
61 | * @param context
62 | */
63 | public static void increaseVolumeWithLevel(Context context) {
64 | adjustMediaVolume(context, getCurrentVolume(context) + 1, AudioManager.FLAG_SHOW_UI);
65 | }
66 |
67 | /**
68 | * Decreases media volume
69 | *
70 | * @param context
71 | */
72 | public static void decreaseVolume(Context context) {
73 | adjustMediaVolume(context, getCurrentVolume(context) - 1, 0);
74 | }
75 |
76 | /**
77 | * Decreases media volume and displays volume level
78 | *
79 | * @param context
80 | */
81 | public static void decreaseVolumeWithLevel(Context context) {
82 | adjustMediaVolume(context, getCurrentVolume(context) - 1, AudioManager.FLAG_SHOW_UI);
83 | }
84 |
85 | /** Returns maximum volume the media volume can have
86 | *
87 | * @param context Context
88 | * @return Maximum volume
89 | */
90 | public static int getMaximumVolume(Context context) {
91 | return ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE)).getStreamMaxVolume(AudioManager.STREAM_MUSIC);
92 | }
93 |
94 | /** Returns minimum volume the media volume can have
95 | *
96 | * @param context Context
97 | * @return Minimum volume
98 | */
99 | public static int getMinimumVolume(Context context) {
100 | return 0;
101 | }
102 |
103 | private static void adjustMediaVolume(Context context, int volume, int flag) {
104 | final int MAX_VOLUME = getMaximumVolume(context);
105 | final int MIN_VOLUME = 0;
106 |
107 | if( volume < MIN_VOLUME ) {
108 | volume = MIN_VOLUME;
109 | } else if( volume > MAX_VOLUME ) {
110 | volume = MAX_VOLUME;
111 | }
112 |
113 | AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
114 | if (audioManager != null) {
115 | audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, flag);
116 | }
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/cipher/AesCipher.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.cipher;
2 |
3 | import java.security.InvalidKeyException;
4 | import java.security.NoSuchAlgorithmException;
5 | import java.security.NoSuchProviderException;
6 | import java.security.SecureRandom;
7 |
8 | import javax.crypto.BadPaddingException;
9 | import javax.crypto.Cipher;
10 | import javax.crypto.IllegalBlockSizeException;
11 | import javax.crypto.KeyGenerator;
12 | import javax.crypto.NoSuchPaddingException;
13 | import javax.crypto.SecretKey;
14 | import javax.crypto.spec.SecretKeySpec;
15 |
16 | import android.util.Log;
17 |
18 | /**
19 | * @author jaemin.woo
20 | *
21 | */
22 | public class AesCipher implements CipherObject {
23 | private static final String TAG = AesCipher.class.getSimpleName();
24 | private final static int JELLY_BEAN_MR1 = 17;
25 |
26 | @Override
27 | public String encrypt(String seed, String plaintext) {
28 | byte[] rawKey = getRawKey(seed.getBytes());
29 | byte[] result = encrypt(rawKey, plaintext.getBytes());
30 | return toHex(result);
31 | }
32 |
33 | @Override
34 | public String decrypt(String seed, String ciphertext) {
35 | byte[] rawKey = getRawKey(seed.getBytes());
36 | byte[] enc = toByte(ciphertext);
37 | byte[] result = decrypt(rawKey, enc);
38 | return new String(result);
39 |
40 | }
41 |
42 | private static void handleGettingAesFailure() {
43 | Log.d(TAG, "Getting AES provider has failed but this can't be happened");
44 | }
45 |
46 | private static byte[] getRawKey(byte[] seed) {
47 | KeyGenerator kgen = null;
48 |
49 | try {
50 | kgen = KeyGenerator.getInstance("AES");
51 | SecureRandom sr = null;
52 | if (android.os.Build.VERSION.SDK_INT >= JELLY_BEAN_MR1) {
53 | sr = SecureRandom.getInstance("SHA1PRNG", "Crypto");
54 | } else {
55 | sr = SecureRandom.getInstance("SHA1PRNG");
56 | }
57 | if (sr == null) {
58 | Log.d(TAG, "Failed to get SecureRandom Crypto Algorithm");
59 | return null;
60 | }
61 | sr.setSeed(seed);
62 | kgen.init(128, sr); // 192 and 256 bits may not be available
63 | } catch (NoSuchAlgorithmException e) {
64 | // Impossible
65 | handleGettingAesFailure();
66 | } catch (NoSuchProviderException e) {
67 | // Android whose version is equal or above than JELLY_BEAN_MR1 provides Crypto provider
68 | // If it doesn't, this method can work as it is supposed to do
69 | throw new RuntimeException(e);
70 | }
71 |
72 | if (kgen != null) {
73 | SecretKey skey = kgen.generateKey();
74 | return skey.getEncoded();
75 | } else {
76 | return null;
77 | }
78 | }
79 |
80 | private byte[] encrypt(byte[] raw, byte[] clear) {
81 | SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
82 | Cipher cipher;
83 | byte [] encrypted = null;
84 | try {
85 | cipher = Cipher.getInstance("AES");
86 | cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
87 | encrypted = cipher.doFinal(clear);
88 | } catch (NoSuchAlgorithmException e) {
89 | // Android provides AES Encryption by default
90 | handleGettingAesFailure();
91 | }
92 | // Exceptions under here occurs because of programming error
93 | catch (NoSuchPaddingException e) {
94 | throw new RuntimeException(e);
95 | } catch (InvalidKeyException e) {
96 | throw new RuntimeException(e);
97 | } catch (IllegalBlockSizeException e) {
98 | throw new RuntimeException(e);
99 | } catch (BadPaddingException e) {
100 | throw new RuntimeException(e);
101 | }
102 |
103 | return encrypted;
104 | }
105 |
106 | private byte[] decrypt(byte[] raw, byte[] encrypted) {
107 | SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
108 | Cipher cipher;
109 | byte [] decrypted = null;
110 | try {
111 | cipher = Cipher.getInstance("AES");
112 | cipher.init(Cipher.DECRYPT_MODE, skeySpec);
113 | decrypted = cipher.doFinal(encrypted);
114 | } catch (NoSuchAlgorithmException e) {
115 | // Can't be happened
116 | handleGettingAesFailure();
117 | }
118 | // Exceptions under here occurs because of programming error
119 | catch (NoSuchPaddingException e) {
120 | throw new RuntimeException(e);
121 | } catch (InvalidKeyException e) {
122 | throw new RuntimeException(e);
123 | } catch (IllegalBlockSizeException e) {
124 | throw new RuntimeException(e);
125 | } catch (BadPaddingException e) {
126 | throw new RuntimeException(e);
127 | }
128 |
129 | return decrypted;
130 | }
131 |
132 | private byte[] toByte(String hexString) {
133 | int len = hexString.length() / 2;
134 | byte[] result = new byte[len];
135 | for (int i = 0; i < len; i++) {
136 | result[i] = Integer.valueOf(hexString.substring(2 * i, 2 * i + 2), 16).byteValue();
137 | }
138 | return result;
139 | }
140 |
141 | private String toHex(byte[] buf) {
142 | if (buf == null) {
143 | return "";
144 | }
145 | StringBuffer result = new StringBuffer(2 * buf.length);
146 | for (int i = 0; i < buf.length; i++) {
147 | appendHex(result, buf[i]);
148 | }
149 | return result.toString();
150 | }
151 |
152 | private final static String HEX = "0123456789ABCDEF";
153 |
154 | private static void appendHex(StringBuffer sb, byte bt) {
155 | sb.append(HEX.charAt((bt >> 4) & 0x0f)).append(HEX.charAt(bt & 0x0f));
156 | }
157 | }
158 |
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/cipher/CipherMode.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.cipher;
2 |
3 | /**
4 | * Cipher mode to be used for encryption
5 | * Currently, default cipher algorithm, AES, is solely provided
6 | *
7 | * @author jaemin.woo
8 | */
9 | public enum CipherMode {
10 | AES,
11 | }
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/cipher/CipherObject.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.cipher;
2 |
3 |
4 | /**
5 | * @author jaemin.woo
6 | */
7 | interface CipherObject {
8 |
9 | public String encrypt(String seed, String plainText);
10 |
11 |
12 | public String decrypt(String seed, String cipherText);
13 | }
14 |
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/cipher/CipherObjectFactory.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.cipher;
2 |
3 | /**
4 | * @author jaemin.woo
5 | */
6 | class CipherObjectFactory {
7 | private CipherObjectFactory() {}
8 |
9 | public static CipherObject getInstance(CipherMode mode) {
10 | if (CipherMode.AES == mode) {
11 | return new AesCipher();
12 | }
13 | return new AesCipher();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/cipher/CipherUtils.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.cipher;
2 |
3 |
4 | /**
5 | * Provides basic encryption and decryption methods
6 | * Default cipher algorithm is AES and currently algorithms other than AES are not provided
7 | *
8 | * @author jaemin.woo
9 | */
10 | public class CipherUtils {
11 | CipherMode cipherMode;
12 | CipherObject cipherObject;
13 |
14 | public CipherUtils() {
15 | this(CipherMode.AES);
16 | }
17 |
18 | public CipherUtils(CipherMode cipherMode) {
19 | this.cipherMode = cipherMode;
20 | cipherObject = CipherObjectFactory.getInstance(this.cipherMode);
21 | }
22 |
23 | /**
24 | *
25 | * @param seed Seed string which is used for encryption and decryption
26 | * @param plainText String to be encrypted
27 | * @return encrypted text
28 | */
29 | public String encrypt(String seed, String plainText) {
30 | return cipherObject.encrypt(seed, plainText);
31 | }
32 |
33 | /**
34 | *
35 | * @param seed Seed string which is used for encryption and decryption
36 | * @param cipherText String encrypted by encrypt method
37 | * @return plain text
38 | */
39 | public String decrypt(String seed, String cipherText) {
40 | return cipherObject.decrypt(seed, cipherText);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/device/DeviceType.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.device;
2 |
3 | /**
4 | * There are two types of android device, tablet and handset
5 | * In the near future, new type of devices such as glasses, watch and wearable stuff can be come up
6 | *
7 | */
8 | public enum DeviceType {
9 | Tablet, Handset
10 | }
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/device/DeviceTypeDetector.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.device;
2 | /*
3 | * DeviceInfoHelper.java
4 | *
5 | * Copyright 2011 NHN Corp. All rights Reserved.
6 | * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
7 | */
8 |
9 | import android.app.Activity;
10 | import android.content.Context;
11 | import android.content.res.Configuration;
12 | import android.util.DisplayMetrics;
13 |
14 | class DeviceTypeDetector {
15 | private static final int SCREENLAYOUT_SIZE_XLARGE = 4;
16 | private static final int DENSITY_TV = 213;
17 | private static final int DENSITY_XHIGH = 320;
18 |
19 | /**
20 | * Checks if the device is a tablet or a phone
21 | *
22 | * @param activityContext The Activity Context.
23 | * @return Returns true if the device is a Tablet
24 | */
25 | public DeviceType getDeviceType(Context activityContext) {
26 | // Verifies if the Generalized Size of the device is XLARGE to be
27 | // considered a Tablet
28 | boolean xlarge = ((activityContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == SCREENLAYOUT_SIZE_XLARGE);
29 |
30 | // If XLarge, checks if the Generalized Density is at least MDPI
31 | // (160dpi)
32 | if (xlarge) {
33 | DisplayMetrics metrics = new DisplayMetrics();
34 | Activity activity = (Activity)activityContext;
35 | activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
36 |
37 | // MDPI=160, DEFAULT=160, DENSITY_HIGH=240, DENSITY_MEDIUM=160,
38 | // DENSITY_TV=213, DENSITY_XHIGH=320
39 | if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT
40 | || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH
41 | || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM
42 | || metrics.densityDpi == DENSITY_TV
43 | || metrics.densityDpi == DENSITY_XHIGH) {
44 |
45 | // this is a tablet!
46 | return DeviceType.Tablet;
47 | }
48 | }
49 |
50 | // this is not a tablet!
51 | return DeviceType.Handset;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/device/DeviceUtils.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.device;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | *
7 | * @author jaemin.woo
8 | *
9 | */
10 | public class DeviceUtils {
11 | private static DeviceTypeDetector deviceTypeDetector;
12 | private static PhoneNumberUtils phoneNumberUtils;
13 |
14 | static {
15 | phoneNumberUtils = new PhoneNumberUtils();
16 | deviceTypeDetector = new DeviceTypeDetector();
17 | }
18 |
19 | /**
20 | * Gives type information of user device.
21 | *
22 | * According to the Google API guide,
23 | * devices whose screen size is less than 7 inches will be classified as a handset.
24 | * For example, Huge looking mobile phones like Samsung galaxy Note III will be sorted as a handset by this rule.
25 | * Among the rest, devices with 7 inch screen and LDPI will be classified as a handset too.
26 | * All other devices with 7 or larger screen will be classified as a tablet.
27 | *
28 | * @param context
29 | * Context derived from Activity. ApplicationContext can not be
30 | * used to take advantage of this function.
31 | *
32 | * @return DeviceType.Tablet if the screen size is equal to or larger than
33 | * XLarge, which is defined as display size from 7 to 10 inches;
34 | * DeviceType.Handset if the screen size is smaller than XLarge
35 | */
36 | public static DeviceType getDeviceType(Context context) {
37 | return deviceTypeDetector.getDeviceType(context);
38 | }
39 |
40 | /**
41 | * Returns launcher type.
42 | *
43 | * @param context
44 | * Context to provide package information
45 | * @return LauncherType
46 | */
47 | public static LauncherType getLauncherType(Context context) {
48 | return LauncherTypeDetector.getType(context);
49 | }
50 |
51 | /**
52 | * Determines if user device has capability of SMS.
53 | *
54 | * Requires READ_PHONE_STATE Permission must be set to use this function
55 | * @param context
56 | * Context to derive device information
57 | * @return true if user device has SMS capability; false otherwise
58 | */
59 | public static boolean hasSmsCapability(Context context) {
60 | return phoneNumberUtils.isAbleToReceiveSms(context);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/device/LauncherInfo.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.device;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.content.pm.PackageManager;
6 | import android.content.pm.ResolveInfo;
7 |
8 | class LauncherInfo {
9 | public static String getName(Context context) {
10 | PackageManager pm = context.getPackageManager();
11 | final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
12 | mainIntent.addCategory(Intent.CATEGORY_HOME);
13 | ResolveInfo resolveInfo = pm.resolveActivity(mainIntent, PackageManager.MATCH_DEFAULT_ONLY);
14 | if (resolveInfo.activityInfo.applicationInfo.className == null) {
15 | return "ANDROID";
16 | }
17 | return resolveInfo.activityInfo.applicationInfo.packageName + resolveInfo.activityInfo.applicationInfo.className;
18 | }
19 | }
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/device/LauncherType.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.device;
2 |
3 | public enum LauncherType {
4 | /** Samsung Default Home */
5 | SAMSUNG_SMALL("com.sec.android.app.twlauncher.LauncherApplication", 140),
6 |
7 | /** Samsung Large Text */
8 | SMASUNG_LARGE("com.sec.android.app.seniorlauncher.LauncherApplication", 140),
9 |
10 | /** Galaxy S3/S4 */
11 | SMASUNG_GALAXY3_4("com.sec.android.app.launchercom.android.launcher2.LauncherApplication", 200),
12 |
13 | /** ICS Default Launcher */
14 | ICS_JELLY_BEAN_DEFAULT("com.android.launcher2.LauncherApplication", 150),
15 |
16 | /** Gingerbread Default Launcher */
17 | GINGERBREAD_DEFAULT("com.android.launcher2.LauncherApplication", 125),
18 |
19 | /** GO Launcher */
20 | GO("com.jiubang.ggheart.launcher.GOLauncherApp", 115),
21 |
22 | /** Go Launcher */
23 | GO_EX("com.gau.go.launcherex", 115),
24 |
25 | /** Nova Launcher */
26 | NOVA("com.teslacoilsw.launcher.NovaApplication", 105),
27 |
28 | /** Apex Launcher */
29 | APEX("com.anddoes.launcher.LauncherApplication", 105),
30 |
31 | /** LG Default Launcher */
32 | LG_DEFUALT("com.lge.launcher.LauncherApplication", 95),
33 |
34 | /** If Launcher is not defined */
35 | ANDROID("android", 130);
36 |
37 | String packageName;
38 | float paddingDp;
39 |
40 | private LauncherType(String packageName, float paddingDp) {
41 | this.packageName = packageName;
42 | this.paddingDp = paddingDp;
43 | }
44 |
45 | public float getPaddingDp() {
46 | return paddingDp;
47 | }
48 | }
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/device/LauncherTypeDetector.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.device;
2 | import java.util.ArrayList;
3 | import java.util.List;
4 |
5 | import android.content.Context;
6 | import android.os.Build;
7 |
8 | /**
9 | * @author jaemin.woo
10 | */
11 | class LauncherTypeDetector {
12 | private static List EXCEPT_DEVICES = new ArrayList();
13 |
14 | static {
15 | // Galaxy S
16 | EXCEPT_DEVICES.add("SHW-M180S");
17 | }
18 |
19 | private static boolean containExceptDevices() {
20 | String device = android.os.Build.DEVICE;
21 | return EXCEPT_DEVICES.contains(device);
22 | }
23 |
24 | public static LauncherType getType(Context context) {
25 | String packageName = LauncherInfo.getName(context);
26 |
27 | if (packageName.length() == 0) {
28 | return LauncherType.ANDROID;
29 | }
30 |
31 | if (containExceptDevices()) {
32 | return LauncherType.ANDROID;
33 | }
34 |
35 | for (LauncherType type : LauncherType.values()) {
36 | if (packageName.contains(type.packageName)) {
37 | if (type == LauncherType.ICS_JELLY_BEAN_DEFAULT
38 | && !(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)) {
39 | return LauncherType.GINGERBREAD_DEFAULT;
40 | }
41 | return type;
42 | }
43 | }
44 | return LauncherType.ANDROID;
45 | }
46 | }
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/device/PhoneNumberUtils.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.device;
2 |
3 | import android.content.Context;
4 | import android.telephony.TelephonyManager;
5 |
6 | /**
7 | *
8 | * @author jaemin.woo
9 | *
10 | */
11 | class PhoneNumberUtils {
12 | public String getMobilePhoneNumber(Context context) {
13 | TelephonyManager telManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
14 | return telManager.getLine1Number();
15 | }
16 |
17 | public boolean isAbleToReceiveSms(Context context) {
18 | String phoneNumber = getMobilePhoneNumber(context);
19 |
20 | if (phoneNumber == null)
21 | return false;
22 |
23 | if (phoneNumber.length() != 0)
24 | return true;
25 |
26 | return false;
27 | }
28 | }
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/input/KeyboardUtils.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.input;
2 |
3 | import java.util.Timer;
4 | import java.util.TimerTask;
5 |
6 | import android.content.Context;
7 | import android.view.View;
8 | import android.view.inputmethod.InputMethodManager;
9 |
10 | /**
11 | *
12 | * @author jaemin.woo
13 | *
14 | */
15 | public class KeyboardUtils {
16 | private static SoftwareKeyDetector deviceKeyboardDetector;
17 |
18 | static {
19 | deviceKeyboardDetector = new SoftwareKeyDetector();
20 | }
21 |
22 | /**
23 | * Shows keypad
24 | *
25 | * @param context
26 | * @param view View to have keypad control
27 | */
28 | public static void showSoftKeyboard(Context context, View view) {
29 | InputMethodManager imm = (InputMethodManager) context
30 | .getSystemService(Context.INPUT_METHOD_SERVICE);
31 | imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
32 | }
33 |
34 | /**
35 | * Hides keypad
36 | *
37 | * @param context
38 | * @param view View holding keypad control
39 | */
40 | public static void hideSoftKeyboard(Context context, View view) {
41 | InputMethodManager imm = (InputMethodManager) context
42 | .getSystemService(Context.INPUT_METHOD_SERVICE);
43 | imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
44 | }
45 |
46 | /**
47 | * Toggles keypad
48 | *
49 | * @param context
50 | */
51 | public static void toggleKeyPad(Context context) {
52 | InputMethodManager imm = (InputMethodManager) context
53 | .getSystemService(Context.INPUT_METHOD_SERVICE);
54 | if (imm != null) {
55 | imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
56 | }
57 | }
58 |
59 | /**
60 | * Delayed version of {@link #hideSoftKeyboard(Context, View)
61 | * hideSoftKeyboard} method
62 | *
63 | * @param context
64 | * @param view View holding keypad control
65 | */
66 | public static void delayedHideSoftKeyboard(final Context context,
67 | final View view, int delay) {
68 | TimerTask task = new TimerTask() {
69 | @Override
70 | public void run() {
71 | hideSoftKeyboard(context, view);
72 | }
73 | };
74 |
75 | Timer timer = new Timer();
76 | timer.schedule(task, delay);
77 | }
78 |
79 | /**
80 | * Delayed version of {@link #showSoftKeyboard(Context, View)
81 | * showSoftKeyboard} method
82 | *
83 | * @param context
84 | * @param view View to have keypad control
85 | */
86 | public static void delayedShowSoftKeyboard(final Context context,
87 | final View view, int delay) {
88 | TimerTask task = new TimerTask() {
89 | @Override
90 | public void run() {
91 | showSoftKeyboard(context, view);
92 | }
93 | };
94 |
95 | Timer timer = new Timer();
96 | timer.schedule(task, delay);
97 | }
98 |
99 | /**
100 | * Determines if the device has software keys.
101 | *
102 | * @return true if device has software keys; false otherwise
103 | */
104 | public static boolean hasSoftwareKeys(Context context) {
105 | return deviceKeyboardDetector.hasSoftwareKeys(context);
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/input/SoftwareKeyDetector.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.input;
2 |
3 | import java.lang.reflect.Method;
4 |
5 | import android.annotation.TargetApi;
6 | import android.content.Context;
7 | import android.os.Build;
8 | import android.os.IBinder;
9 | import android.view.KeyCharacterMap;
10 | import android.view.KeyEvent;
11 | import android.view.ViewConfiguration;
12 |
13 | /**
14 | *
15 | * @author jaemin.woo
16 | *
17 | */
18 | class SoftwareKeyDetector {
19 | @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
20 | public boolean hasSoftwareKeys(Context context) {
21 | int sdkVersion = Build.VERSION.SDK_INT;
22 |
23 | // Gingerbread and below are considered to have physical buttons.
24 | if (sdkVersion <= Build.VERSION_CODES.GINGERBREAD_MR1)
25 | return false;
26 |
27 | // Honeycomb is dedicated to the tablets having no physical buttons.
28 | if (sdkVersion >= Build.VERSION_CODES.GINGERBREAD_MR1 && sdkVersion <= Build.VERSION_CODES.HONEYCOMB_MR2)
29 | return true;
30 |
31 | // ICS and above provide convenient function able to determine if the
32 | // device has
33 | // physical buttons or not.
34 | // This function is not available below ICS
35 |
36 | boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
37 | boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
38 |
39 | return !hasMenuKey && !hasBackKey;
40 | }
41 |
42 | private boolean softkeyNavigationCalled;
43 | private boolean softkeyNavigationBar;
44 | private Object lock = new Object();
45 |
46 | public boolean getHasSoftkeyNavigationBar() {
47 | // Prevent reflection from being called indefinitely
48 | if (softkeyNavigationCalled) {
49 | return softkeyNavigationBar;
50 | }
51 |
52 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
53 | return false;
54 | }
55 |
56 | try {
57 | Class> serviceManagerClass = Class.forName("android.os.ServiceManager");
58 | Method getService = serviceManagerClass.getDeclaredMethod("getService", String.class);
59 | Object ws = getService.invoke(null, "window");
60 | Class> wmClassStub = Class.forName("android.view.IWindowManager$Stub");
61 | Method asInterface = wmClassStub.getDeclaredMethod("asInterface", IBinder.class);
62 | Object iWindowManager = asInterface.invoke(null, (IBinder)ws);
63 | Method declaredMethod = iWindowManager.getClass().getDeclaredMethod("hasNavigationBar");
64 |
65 | synchronized (lock) {
66 | softkeyNavigationBar = (Boolean) declaredMethod.invoke(iWindowManager);
67 | }
68 | }
69 | catch (Exception e) {
70 | // If this method does not exist, then it may be thought that the device does not have one
71 | softkeyNavigationCalled = false;
72 | }
73 |
74 | synchronized (lock) {
75 | softkeyNavigationCalled = true;
76 | }
77 |
78 | return softkeyNavigationBar;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/storage/DiskUtils.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.storage;
2 |
3 | import java.io.File;
4 |
5 | import android.content.Context;
6 | import android.os.Environment;
7 |
8 | /**
9 | * Cautious!
10 | * External disk do not necessarily mean that it is a SD Card.
11 | *
12 | * Any large size of space can be external disk.
13 | * As such, do not make assumptions that you are working on SDCard.
14 | *
15 | * getMicroSDPath method that finds MicroSDCard path if it exists has been removed since it depends on /system/etc/vold.fstab file.
16 | * Because that file was removed as of JELLY_BEAN_MR2, this function could not work as solid as it should do.
17 | * For that reason, this method is excluded.
18 | *
19 | * @author jaemin.woo
20 | */
21 | public final class DiskUtils {
22 | private static final String DATA_FOLDER = "/Android/data";
23 | protected static final String TEMPORARY_FOLDER = "/temp";
24 | protected static final String CACHE_FOLDER = "/cache";
25 |
26 | /**
27 | * Checks if External storage is mounted
28 | * @return true if mounted; false otherwise
29 | */
30 | public static boolean isExternalStorageMounted() {
31 | return Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
32 | }
33 |
34 | /**
35 | * Returns directory name to save cache data in the external storage
36 | *
37 | * This method always returns path of external storage even if it does not exist.
38 | * As such, make sure to call isExternalStorageMounted method as state-testing method and then call this function only if state-testing method returns true.
39 | *
40 | * @param context Context to get external storage information
41 | * @return String containing cache directory name
42 | */
43 | public static String getExternalDirPath(Context context) {
44 | return Environment.getExternalStorageDirectory().getAbsolutePath() + DATA_FOLDER + File.separator + context.getPackageName() + CACHE_FOLDER;
45 | }
46 |
47 | /**
48 | * Returns directory name to save temporary files in the external storage for temporary
49 | *
50 | * This method always returns path of external storage even if it does not exist.
51 | * As such, make sure to call isExternalStorageMounted method as state-testing method and then call this function only if state-testing method returns true.
52 | *
53 | * @param context Context to get external storage information
54 | * @return String containing temporary directory name
55 | */
56 | public static String getExternalTemporaryDirPath(Context context) {
57 | return Environment.getExternalStorageDirectory().getAbsolutePath() + DATA_FOLDER + File.separator + context.getPackageName() + TEMPORARY_FOLDER;
58 | }
59 |
60 |
61 | /**
62 | * Returns root directory of the external storage.
63 | *
64 | * This method always returns path of external storage even if it does not exist.
65 | * As such, make sure to call isExternalStorageMounted method as state-testing method and then call this function only if state-testing method returns true.
66 | *
67 | * @param context Context to get external storage information
68 | * @return String containing external root directory name
69 | */
70 | public static String getExternalContextRootDir(Context context) {
71 | return Environment.getExternalStorageDirectory().getAbsolutePath() + DATA_FOLDER + File.separator + context.getPackageName();
72 | }
73 | }
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/string/CompressUtils.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.string;
2 |
3 |
4 | /**
5 | * StringUtils provides string related function
6 | * By using compressString and deompressString, string long and has repeated part can be shrunk
7 | *
8 | * @author jaemin.woo
9 | */
10 | public class CompressUtils {
11 | private static StringCompressor stringCompressor;
12 |
13 | static {
14 | stringCompressor = new StringCompressor();
15 | }
16 |
17 | public static String compressString(String stringToBeCompressed) {
18 | return stringCompressor.compress(stringToBeCompressed);
19 | }
20 |
21 | public static String decompressString(String stringToBeDecompressed) {
22 | return stringCompressor.decompress(stringToBeDecompressed);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/string/StringCompressor.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.string;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.ByteArrayInputStream;
5 | import java.io.ByteArrayOutputStream;
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 | import java.io.InputStreamReader;
9 | import java.io.UnsupportedEncodingException;
10 | import java.net.URLDecoder;
11 | import java.util.zip.GZIPInputStream;
12 | import java.util.zip.GZIPOutputStream;
13 |
14 | import android.net.Uri;
15 | import android.util.Base64;
16 | import android.util.Log;
17 |
18 | /**
19 | * It is easy to be confused by the result that the compressed string is not shorter than original one.
20 | * When string to be compressed neither lengthy nor repeated at all, then that is not the case for this method to be utilized.
21 | * Long repeated string is where this method really shines.
22 | * Look at these examples.
23 | * A long repeated string 'aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbcccccccccc' will be compressed into 'H4slAAAAAAAAAEtMxAKSslBkOAAA0lkFljMAAAA=' which is shorter than original one.
24 | * In contrast, A short but not repeated string 'abcdefghijklmnopqrstuvwxyz' will be compressed into 'H4slAAAAAAAAAEtMSk5JTUvPyMzKzsnNyy8oLCouKS0rr6isAgC9UCdMGgAAAA==' which is longer than original string.
25 | *
26 | * @author jaemin.woo
27 | *
28 | */
29 | public class StringCompressor {
30 | private static final int BUFFER_SIZE = 2 * 1024;
31 |
32 | public String compress(String str) {
33 | if (str == null || str.length() == 0) {
34 | return str;
35 | }
36 |
37 | String compressBase64EncodeStr = null;
38 | InputStream is = null;
39 | ByteArrayOutputStream baos = null;
40 | GZIPOutputStream gzos = null;
41 |
42 | try {
43 | is = new ByteArrayInputStream(str.getBytes("UTF-8"));
44 | baos = new ByteArrayOutputStream();
45 | gzos = new GZIPOutputStream(baos);
46 | byte buffer[] = new byte[BUFFER_SIZE];
47 | int count = -1;
48 | while ((count = is.read(buffer, 0, BUFFER_SIZE)) != -1) {
49 | gzos.write(buffer, 0, count);
50 | }
51 | gzos.finish();
52 | compressBase64EncodeStr = new String(Base64.encode(
53 | baos.toByteArray(), Base64.DEFAULT));
54 | } catch (UnsupportedEncodingException e1) {
55 | // This can't be happened
56 | throw new RuntimeException("This would never be happened");
57 | } catch (IOException e) {
58 | throw new RuntimeException(String.format("Exception occured while compressing String \"%s\"", str));
59 | } finally {
60 | if (is != null) {
61 | try {
62 | is.close();
63 | } catch (IOException e) {
64 | throw new RuntimeException("Exception occured while closing InputStream");
65 | }
66 | }
67 |
68 | if (gzos != null) {
69 | try {
70 | gzos.close();
71 | } catch (IOException e) {
72 | throw new RuntimeException("Exception occured while closing GZIPOutputStream");
73 | }
74 | }
75 | }
76 |
77 | return compressBase64EncodeStr;
78 | }
79 |
80 | private static String urlDecode(String src) {
81 | String dst = null;
82 | try {
83 | dst = URLDecoder.decode(src, "UTF-8");
84 | } catch (UnsupportedEncodingException e) {
85 | Log.e("UtilSet",
86 | "An UnsupportedEncodingException occured in "
87 | + StringCompressor.class
88 | + ".urlDecode. However, it does not terminate application and continues decode with default encoding character set.");
89 | dst = Uri.decode(src);
90 | }
91 |
92 | return dst;
93 | }
94 |
95 | public String decompress(String str) {
96 | if (str == null || str.length() == 0) {
97 | return str;
98 | }
99 |
100 | String decompressStr = null;
101 | InputStream is = null;
102 | GZIPInputStream gzis = null;
103 | ByteArrayOutputStream baos = null;
104 |
105 | try {
106 | is = new ByteArrayInputStream(Base64.decode(urlDecode(str)
107 | .getBytes(), Base64.DEFAULT));
108 | gzis = new GZIPInputStream(is);
109 | baos = new ByteArrayOutputStream();
110 |
111 | byte buffer[] = new byte[BUFFER_SIZE];
112 | int count = -1;
113 | while ((count = gzis.read(buffer, 0, BUFFER_SIZE)) != -1) {
114 | baos.write(buffer, 0, count);
115 | }
116 |
117 | decompressStr = new String(baos.toByteArray(), "UTF-8");
118 | } catch (IOException e) {
119 | throw new RuntimeException(String.format("Exception occured while decompressing string \"%s\""));
120 | }
121 | finally {
122 | if (baos != null) {
123 | try {
124 | baos.close();
125 | } catch (IOException e) {
126 | throw new RuntimeException("Exception occured while closing ByteArrayOutputStream");
127 | }
128 | }
129 |
130 | if (gzis != null) {
131 | try {
132 | gzis.close();
133 | } catch (IOException e) {
134 | throw new RuntimeException("Exception occured while closing GZIPInputStream");
135 | }
136 | }
137 | }
138 |
139 | return decompressStr;
140 | }
141 |
142 | public InputStream decompress(InputStream is) {
143 | if (is == null) {
144 | return is;
145 | }
146 |
147 | InputStream retIs = null;
148 | ByteArrayInputStream bais = null;
149 | GZIPInputStream gzis = null;
150 | ByteArrayOutputStream baos = null;
151 |
152 | try {
153 | bais = new ByteArrayInputStream(Base64.decode(
154 | convertStreamToByteArray(is), Base64.DEFAULT));
155 | gzis = new GZIPInputStream(bais);
156 | baos = new ByteArrayOutputStream();
157 |
158 | byte buffer[] = new byte[BUFFER_SIZE];
159 | int count = -1;
160 | while ((count = gzis.read(buffer, 0, BUFFER_SIZE)) != -1) {
161 | baos.write(buffer, 0, count);
162 | }
163 |
164 | retIs = new ByteArrayInputStream(baos.toByteArray());
165 | } catch (IOException e) {
166 | throw new RuntimeException("Exception occured while decompressing InputStream");
167 | } finally {
168 | if (baos != null) {
169 | try {
170 | baos.close();
171 | } catch (IOException e) {
172 | throw new RuntimeException("Exception occured while closing ByteArrayOutputStream");
173 | }
174 | }
175 |
176 | if (gzis != null) {
177 | try {
178 | gzis.close();
179 | } catch (IOException e) {
180 | throw new RuntimeException("Exception occured while closing GZIPInputStream");
181 | }
182 | }
183 | }
184 |
185 | return retIs;
186 | }
187 |
188 | private byte[] convertStreamToByteArray(InputStream is) throws IOException {
189 | BufferedReader reader = new BufferedReader(new InputStreamReader(is));
190 | StringBuilder sb = new StringBuilder();
191 | String line = null;
192 |
193 | try {
194 | while ((line = reader.readLine()) != null) {
195 | sb.append(line);
196 | }
197 | } catch (IOException e) {
198 | // Just bypasses exception so that the caller can handle finalization works or propagate exception
199 | throw e;
200 | } finally {
201 | try {
202 | is.close();
203 | } catch (IOException e) {
204 | // This barely happens.
205 | // Just bypasses exception so that the caller can handle finalization works or propagate exception
206 | throw e;
207 | }
208 | }
209 |
210 | return sb.toString().getBytes();
211 | }
212 | }
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/system/ProcessorUtils.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.system;
2 |
3 | import java.io.File;
4 | import java.io.FileFilter;
5 | import java.util.regex.Pattern;
6 |
7 | import android.util.Log;
8 |
9 | class ProcessorUtils {
10 | /**
11 | http://stackoverflow.com/questions/7962155/how-can-you-detect-a-dual-core-cpu-on-an-android-device-from-code
12 | * Gets the number of cores available in this device, across all processors.
13 | * Requires: Ability to peruse the file system at "/sys/devices/system/cpu"
14 | * @return The number of cores, or Runtime.getRuntime().availableProcessors() if failed to get result
15 | */
16 | public static int getNumCores() {
17 | //Private Class to display only CPU devices in the directory listing
18 | class CpuFilter implements FileFilter {
19 |
20 | @Override
21 | public boolean accept(File pathname) {
22 | //Check if filename is "cpu", followed by a single digit number
23 | if(Pattern.matches("cpu[0-9]", pathname.getName())) {
24 | return true;
25 | }
26 |
27 | return false;
28 | }
29 | }
30 |
31 | try {
32 | //Get directory containing CPU info
33 | File dir = new File("/sys/devices/system/cpu/");
34 |
35 | //Filter to only list the devices we care about
36 | File[] files = dir.listFiles(new CpuFilter());
37 |
38 | if (files == null)
39 | return Runtime.getRuntime().availableProcessors();
40 |
41 | //Return the number of cores (virtual CPU devices)
42 | return files.length;
43 | } catch(Exception e) {
44 | // The number of cores can vary with JVM status
45 | return Runtime.getRuntime().availableProcessors();
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/system/RootChecker.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.system;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.File;
5 | import java.io.IOException;
6 | import java.io.InputStreamReader;
7 |
8 | import android.util.Log;
9 |
10 | class RootChecker {
11 | private static final String TAG = "RootChecker";
12 | private static final String[] PLACES = { "/sbin/", "/system/bin/",
13 | "/system/xbin/", "/data/local/xbin/", "/data/local/bin/",
14 | "/system/sd/xbin/", "/system/bin/failsafe/", "/data/local/" };
15 |
16 | private static final String ROOT_CHECKING_BINARY_NAME = "su";
17 |
18 | public boolean isRootAvailable() {
19 | for (String where : PLACES) {
20 | if (hasFile(where + ROOT_CHECKING_BINARY_NAME)) {
21 | Log.d(TAG, where + ROOT_CHECKING_BINARY_NAME + " was found!");
22 | return true;
23 | }
24 | }
25 | Log.d(TAG, ROOT_CHECKING_BINARY_NAME + " was not found!");
26 | return false;
27 | }
28 |
29 | private boolean hasFile(String fullPath) {
30 | try {
31 | File file = new File(fullPath);
32 | return file.exists();
33 | } catch (Exception e) {
34 | Log.e(TAG, "An error occured while checking " + fullPath, e);
35 | return false;
36 | }
37 | }
38 |
39 |
40 | // Refer : http://lsit81.tistory.com/entry/Android-%EB%A3%A8%ED%8C%85-%EC%97%AC%EB%B6%80-%ED%99%95%EC%9D%B8%ED%95%98%EA%B8%B0
41 | public boolean checkRootingDevice() {
42 | boolean isRootingFlag = false;
43 | BufferedReader reader = null;
44 | try {
45 | Process process = Runtime.getRuntime().exec("find / -name su");
46 |
47 | reader = new BufferedReader(new InputStreamReader(
48 | process.getInputStream()));
49 |
50 | String result = reader.readLine();
51 | if (result == null) {
52 | Log.d(TAG, "Failed to execute find command to check if a file which is evidence of root exists");
53 | throw new RuntimeException("Unable to check if device is rooted");
54 | }
55 |
56 | if (result.contains("/su") == true) {
57 | isRootingFlag = true;
58 | }
59 |
60 | } catch (Exception e) {
61 | isRootingFlag = false;
62 | } finally {
63 | if (reader != null) {
64 | try {
65 | reader.close();
66 | } catch (IOException e) {
67 | Log.d(TAG, "Error occured while closing input stream");
68 | }
69 | }
70 | }
71 |
72 | if (!isRootingFlag) {
73 | isRootingFlag = checkRootingFiles(PLACES);
74 | }
75 |
76 | return isRootingFlag;
77 | }
78 |
79 | private boolean checkRootingFiles(String[] filePaths) {
80 | boolean result = false;
81 | File file;
82 |
83 | for (String path : filePaths) {
84 | file = new File(path + "su");
85 |
86 | if (file != null && file.exists() && file.isFile()) {
87 | result = true;
88 | break;
89 | } else {
90 | result = false;
91 | }
92 | }
93 |
94 | return result;
95 | }
96 | }
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/system/SystemUtils.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.system;
2 |
3 |
4 | /**
5 | *
6 | * @author jaemin.woo
7 | *
8 | */
9 | public class SystemUtils {
10 | private static RootChecker rootChecker;
11 |
12 | static {
13 | rootChecker = new RootChecker();
14 | }
15 |
16 | /**
17 | * Returns boolean that indicates whether current device is rooted or not.
18 | *
19 | *
This method is not guaranteed to cover all the root methods.
20 | * It takes simple approach;
21 | * It tries to finds 'su' command and then executes.
22 | * If 'su' command is not found or unable to execute then an exception will be thrown.
23 | * This indicates that device is rooted.
24 | * Because this is well known way to check root, Root tools today may not be detected by this method.
25 | * For more detailed implementation, refer to 'RootTools' library.
26 | *
27 | * @return true if the device is rooted; false otherwise
28 | * @throws RuntimeException if root check fails
29 | */
30 | public static boolean isRooted() {
31 | return rootChecker.checkRootingDevice();
32 | }
33 |
34 | /**
35 | * Returns the number of cores of device.
36 | * Until JELLY_BEAN_MR1, It is possible for processors to be off-line for power saving purpose and those off-line CPUs may not be counted.
37 | * Use this method if Runtime.availableProcessors() seems not to return exact core numbers.
38 | *
39 | * @return the number of cores
40 | */
41 | public static int getProcessorNumbers() {
42 | return ProcessorUtils.getNumCores();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/UtilSet/src/com/navercorp/utilset/ui/ActivityUtils.java:
--------------------------------------------------------------------------------
1 | package com.navercorp.utilset.ui;
2 |
3 | import java.util.List;
4 |
5 | import android.app.ActivityManager;
6 | import android.app.ActivityManager.RunningAppProcessInfo;
7 | import android.app.ActivityManager.RunningTaskInfo;
8 | import android.content.ComponentName;
9 | import android.content.Context;
10 | import android.content.Intent;
11 | import android.content.pm.PackageManager;
12 | import android.content.pm.ResolveInfo;
13 |
14 | /**
15 | *
16 | * @author jaemin.woo
17 | *
18 | */
19 | public class ActivityUtils {
20 | /** Checks if a package is installed.
21 | *
22 | * @param context Context to be used to verify the existence of the package.
23 | * @param packageName Package name to be searched.
24 | * @return true if the package is discovered; false otherwise
25 | */
26 | public static boolean isPackageInstalled(Context context, String packageName) {
27 | try {
28 | context.getPackageManager().getApplicationInfo(packageName, 0);
29 | return true;
30 | } catch (Exception e) {
31 | return false;
32 | }
33 | }
34 |
35 | /** Returns Package name of base activity.