├── .gitignore
├── Android.mk
├── AndroidManifest.xml
├── NOTICE
├── NOTICE.cm
├── native
└── ss.cpp
├── res
├── values-cs
│ └── strings.xml
├── values-da
│ └── strings.xml
├── values-de
│ └── strings.xml
├── values-fr
│ └── strings.xml
├── values-hu
│ └── strings.xml
├── values-it
│ └── strings.xml
├── values-ja
│ └── strings.xml
├── values-ko
│ └── strings.xml
├── values-nl
│ └── strings.xml
├── values-pl
│ └── strings.xml
├── values-pt
│ └── strings.xml
├── values-ru
│ └── strings.xml
├── values-sk
│ └── strings.xml
├── values-sv
│ └── strings.xml
├── values-tr
│ └── strings.xml
├── values-uk
│ └── strings.xml
├── values-zh-rCN
│ └── strings.xml
├── values-zh-rTW
│ └── strings.xml
└── values
│ └── strings.xml
└── src
└── com
└── cyanogenmod
└── screenshot
├── ScreenshotActivity.java
└── ScreenshotReceiver.java
/.gitignore:
--------------------------------------------------------------------------------
1 | libs
2 |
--------------------------------------------------------------------------------
/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH:= $(call my-dir)
2 | include $(CLEAR_VARS)
3 |
4 | LOCAL_SRC_FILES := $(call all-java-files-under, src)
5 |
6 | LOCAL_PACKAGE_NAME := CMScreenshot
7 | LOCAL_CERTIFICATE := platform
8 |
9 | LOCAL_MODULE_TAGS := optional
10 |
11 | include $(BUILD_PACKAGE)
12 |
13 | include $(CLEAR_VARS)
14 |
15 | LOCAL_SHARED_LIBRARIES := \
16 | libcutils \
17 | libutils \
18 | libbinder \
19 | libui \
20 | libsurfaceflinger_client
21 |
22 | LOCAL_SRC_FILES:= native/ss.cpp
23 |
24 | LOCAL_MODULE:= screenshot
25 | LOCAL_MODULE_TAGS := optional
26 |
27 | include $(BUILD_EXECUTABLE)
28 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
10 |
11 |
12 |
13 |
14 |
15 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 |
2 | Copyright (c) 2011, The CyanogenMod Project
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 |
7 | Unless required by applicable law or agreed to in writing, software
8 | distributed under the License is distributed on an "AS IS" BASIS,
9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | See the License for the specific language governing permissions and
11 | limitations under the License.
12 |
13 |
14 | Apache License
15 | Version 2.0, January 2004
16 | http://www.apache.org/licenses/
17 |
18 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
19 |
20 | 1. Definitions.
21 |
22 | "License" shall mean the terms and conditions for use, reproduction,
23 | and distribution as defined by Sections 1 through 9 of this document.
24 |
25 | "Licensor" shall mean the copyright owner or entity authorized by
26 | the copyright owner that is granting the License.
27 |
28 | "Legal Entity" shall mean the union of the acting entity and all
29 | other entities that control, are controlled by, or are under common
30 | control with that entity. For the purposes of this definition,
31 | "control" means (i) the power, direct or indirect, to cause the
32 | direction or management of such entity, whether by contract or
33 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
34 | outstanding shares, or (iii) beneficial ownership of such entity.
35 |
36 | "You" (or "Your") shall mean an individual or Legal Entity
37 | exercising permissions granted by this License.
38 |
39 | "Source" form shall mean the preferred form for making modifications,
40 | including but not limited to software source code, documentation
41 | source, and configuration files.
42 |
43 | "Object" form shall mean any form resulting from mechanical
44 | transformation or translation of a Source form, including but
45 | not limited to compiled object code, generated documentation,
46 | and conversions to other media types.
47 |
48 | "Work" shall mean the work of authorship, whether in Source or
49 | Object form, made available under the License, as indicated by a
50 | copyright notice that is included in or attached to the work
51 | (an example is provided in the Appendix below).
52 |
53 | "Derivative Works" shall mean any work, whether in Source or Object
54 | form, that is based on (or derived from) the Work and for which the
55 | editorial revisions, annotations, elaborations, or other modifications
56 | represent, as a whole, an original work of authorship. For the purposes
57 | of this License, Derivative Works shall not include works that remain
58 | separable from, or merely link (or bind by name) to the interfaces of,
59 | the Work and Derivative Works thereof.
60 |
61 | "Contribution" shall mean any work of authorship, including
62 | the original version of the Work and any modifications or additions
63 | to that Work or Derivative Works thereof, that is intentionally
64 | submitted to Licensor for inclusion in the Work by the copyright owner
65 | or by an individual or Legal Entity authorized to submit on behalf of
66 | the copyright owner. For the purposes of this definition, "submitted"
67 | means any form of electronic, verbal, or written communication sent
68 | to the Licensor or its representatives, including but not limited to
69 | communication on electronic mailing lists, source code control systems,
70 | and issue tracking systems that are managed by, or on behalf of, the
71 | Licensor for the purpose of discussing and improving the Work, but
72 | excluding communication that is conspicuously marked or otherwise
73 | designated in writing by the copyright owner as "Not a Contribution."
74 |
75 | "Contributor" shall mean Licensor and any individual or Legal Entity
76 | on behalf of whom a Contribution has been received by Licensor and
77 | subsequently incorporated within the Work.
78 |
79 | 2. Grant of Copyright License. Subject to the terms and conditions of
80 | this License, each Contributor hereby grants to You a perpetual,
81 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
82 | copyright license to reproduce, prepare Derivative Works of,
83 | publicly display, publicly perform, sublicense, and distribute the
84 | Work and such Derivative Works in Source or Object form.
85 |
86 | 3. Grant of Patent License. Subject to the terms and conditions of
87 | this License, each Contributor hereby grants to You a perpetual,
88 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
89 | (except as stated in this section) patent license to make, have made,
90 | use, offer to sell, sell, import, and otherwise transfer the Work,
91 | where such license applies only to those patent claims licensable
92 | by such Contributor that are necessarily infringed by their
93 | Contribution(s) alone or by combination of their Contribution(s)
94 | with the Work to which such Contribution(s) was submitted. If You
95 | institute patent litigation against any entity (including a
96 | cross-claim or counterclaim in a lawsuit) alleging that the Work
97 | or a Contribution incorporated within the Work constitutes direct
98 | or contributory patent infringement, then any patent licenses
99 | granted to You under this License for that Work shall terminate
100 | as of the date such litigation is filed.
101 |
102 | 4. Redistribution. You may reproduce and distribute copies of the
103 | Work or Derivative Works thereof in any medium, with or without
104 | modifications, and in Source or Object form, provided that You
105 | meet the following conditions:
106 |
107 | (a) You must give any other recipients of the Work or
108 | Derivative Works a copy of this License; and
109 |
110 | (b) You must cause any modified files to carry prominent notices
111 | stating that You changed the files; and
112 |
113 | (c) You must retain, in the Source form of any Derivative Works
114 | that You distribute, all copyright, patent, trademark, and
115 | attribution notices from the Source form of the Work,
116 | excluding those notices that do not pertain to any part of
117 | the Derivative Works; and
118 |
119 | (d) If the Work includes a "NOTICE" text file as part of its
120 | distribution, then any Derivative Works that You distribute must
121 | include a readable copy of the attribution notices contained
122 | within such NOTICE file, excluding those notices that do not
123 | pertain to any part of the Derivative Works, in at least one
124 | of the following places: within a NOTICE text file distributed
125 | as part of the Derivative Works; within the Source form or
126 | documentation, if provided along with the Derivative Works; or,
127 | within a display generated by the Derivative Works, if and
128 | wherever such third-party notices normally appear. The contents
129 | of the NOTICE file are for informational purposes only and
130 | do not modify the License. You may add Your own attribution
131 | notices within Derivative Works that You distribute, alongside
132 | or as an addendum to the NOTICE text from the Work, provided
133 | that such additional attribution notices cannot be construed
134 | as modifying the License.
135 |
136 | You may add Your own copyright statement to Your modifications and
137 | may provide additional or different license terms and conditions
138 | for use, reproduction, or distribution of Your modifications, or
139 | for any such Derivative Works as a whole, provided Your use,
140 | reproduction, and distribution of the Work otherwise complies with
141 | the conditions stated in this License.
142 |
143 | 5. Submission of Contributions. Unless You explicitly state otherwise,
144 | any Contribution intentionally submitted for inclusion in the Work
145 | by You to the Licensor shall be under the terms and conditions of
146 | this License, without any additional terms or conditions.
147 | Notwithstanding the above, nothing herein shall supersede or modify
148 | the terms of any separate license agreement you may have executed
149 | with Licensor regarding such Contributions.
150 |
151 | 6. Trademarks. This License does not grant permission to use the trade
152 | names, trademarks, service marks, or product names of the Licensor,
153 | except as required for reasonable and customary use in describing the
154 | origin of the Work and reproducing the content of the NOTICE file.
155 |
156 | 7. Disclaimer of Warranty. Unless required by applicable law or
157 | agreed to in writing, Licensor provides the Work (and each
158 | Contributor provides its Contributions) on an "AS IS" BASIS,
159 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
160 | implied, including, without limitation, any warranties or conditions
161 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
162 | PARTICULAR PURPOSE. You are solely responsible for determining the
163 | appropriateness of using or redistributing the Work and assume any
164 | risks associated with Your exercise of permissions under this License.
165 |
166 | 8. Limitation of Liability. In no event and under no legal theory,
167 | whether in tort (including negligence), contract, or otherwise,
168 | unless required by applicable law (such as deliberate and grossly
169 | negligent acts) or agreed to in writing, shall any Contributor be
170 | liable to You for damages, including any direct, indirect, special,
171 | incidental, or consequential damages of any character arising as a
172 | result of this License or out of the use or inability to use the
173 | Work (including but not limited to damages for loss of goodwill,
174 | work stoppage, computer failure or malfunction, or any and all
175 | other commercial damages or losses), even if such Contributor
176 | has been advised of the possibility of such damages.
177 |
178 | 9. Accepting Warranty or Additional Liability. While redistributing
179 | the Work or Derivative Works thereof, You may choose to offer,
180 | and charge a fee for, acceptance of support, warranty, indemnity,
181 | or other liability obligations and/or rights consistent with this
182 | License. However, in accepting such obligations, You may act only
183 | on Your own behalf and on Your sole responsibility, not on behalf
184 | of any other Contributor, and only if You agree to indemnify,
185 | defend, and hold each Contributor harmless for any liability
186 | incurred by, or claims asserted against, such Contributor by reason
187 | of your accepting any such warranty or additional liability.
188 |
189 | END OF TERMS AND CONDITIONS
190 |
191 |
--------------------------------------------------------------------------------
/NOTICE.cm:
--------------------------------------------------------------------------------
1 |
2 | Copyright (c) 2011, The CyanogenMod Project
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 |
7 | Unless required by applicable law or agreed to in writing, software
8 | distributed under the License is distributed on an "AS IS" BASIS,
9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | See the License for the specific language governing permissions and
11 | limitations under the License.
12 |
13 |
14 | Apache License
15 | Version 2.0, January 2004
16 | http://www.apache.org/licenses/
17 |
18 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
19 |
20 | 1. Definitions.
21 |
22 | "License" shall mean the terms and conditions for use, reproduction,
23 | and distribution as defined by Sections 1 through 9 of this document.
24 |
25 | "Licensor" shall mean the copyright owner or entity authorized by
26 | the copyright owner that is granting the License.
27 |
28 | "Legal Entity" shall mean the union of the acting entity and all
29 | other entities that control, are controlled by, or are under common
30 | control with that entity. For the purposes of this definition,
31 | "control" means (i) the power, direct or indirect, to cause the
32 | direction or management of such entity, whether by contract or
33 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
34 | outstanding shares, or (iii) beneficial ownership of such entity.
35 |
36 | "You" (or "Your") shall mean an individual or Legal Entity
37 | exercising permissions granted by this License.
38 |
39 | "Source" form shall mean the preferred form for making modifications,
40 | including but not limited to software source code, documentation
41 | source, and configuration files.
42 |
43 | "Object" form shall mean any form resulting from mechanical
44 | transformation or translation of a Source form, including but
45 | not limited to compiled object code, generated documentation,
46 | and conversions to other media types.
47 |
48 | "Work" shall mean the work of authorship, whether in Source or
49 | Object form, made available under the License, as indicated by a
50 | copyright notice that is included in or attached to the work
51 | (an example is provided in the Appendix below).
52 |
53 | "Derivative Works" shall mean any work, whether in Source or Object
54 | form, that is based on (or derived from) the Work and for which the
55 | editorial revisions, annotations, elaborations, or other modifications
56 | represent, as a whole, an original work of authorship. For the purposes
57 | of this License, Derivative Works shall not include works that remain
58 | separable from, or merely link (or bind by name) to the interfaces of,
59 | the Work and Derivative Works thereof.
60 |
61 | "Contribution" shall mean any work of authorship, including
62 | the original version of the Work and any modifications or additions
63 | to that Work or Derivative Works thereof, that is intentionally
64 | submitted to Licensor for inclusion in the Work by the copyright owner
65 | or by an individual or Legal Entity authorized to submit on behalf of
66 | the copyright owner. For the purposes of this definition, "submitted"
67 | means any form of electronic, verbal, or written communication sent
68 | to the Licensor or its representatives, including but not limited to
69 | communication on electronic mailing lists, source code control systems,
70 | and issue tracking systems that are managed by, or on behalf of, the
71 | Licensor for the purpose of discussing and improving the Work, but
72 | excluding communication that is conspicuously marked or otherwise
73 | designated in writing by the copyright owner as "Not a Contribution."
74 |
75 | "Contributor" shall mean Licensor and any individual or Legal Entity
76 | on behalf of whom a Contribution has been received by Licensor and
77 | subsequently incorporated within the Work.
78 |
79 | 2. Grant of Copyright License. Subject to the terms and conditions of
80 | this License, each Contributor hereby grants to You a perpetual,
81 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
82 | copyright license to reproduce, prepare Derivative Works of,
83 | publicly display, publicly perform, sublicense, and distribute the
84 | Work and such Derivative Works in Source or Object form.
85 |
86 | 3. Grant of Patent License. Subject to the terms and conditions of
87 | this License, each Contributor hereby grants to You a perpetual,
88 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
89 | (except as stated in this section) patent license to make, have made,
90 | use, offer to sell, sell, import, and otherwise transfer the Work,
91 | where such license applies only to those patent claims licensable
92 | by such Contributor that are necessarily infringed by their
93 | Contribution(s) alone or by combination of their Contribution(s)
94 | with the Work to which such Contribution(s) was submitted. If You
95 | institute patent litigation against any entity (including a
96 | cross-claim or counterclaim in a lawsuit) alleging that the Work
97 | or a Contribution incorporated within the Work constitutes direct
98 | or contributory patent infringement, then any patent licenses
99 | granted to You under this License for that Work shall terminate
100 | as of the date such litigation is filed.
101 |
102 | 4. Redistribution. You may reproduce and distribute copies of the
103 | Work or Derivative Works thereof in any medium, with or without
104 | modifications, and in Source or Object form, provided that You
105 | meet the following conditions:
106 |
107 | (a) You must give any other recipients of the Work or
108 | Derivative Works a copy of this License; and
109 |
110 | (b) You must cause any modified files to carry prominent notices
111 | stating that You changed the files; and
112 |
113 | (c) You must retain, in the Source form of any Derivative Works
114 | that You distribute, all copyright, patent, trademark, and
115 | attribution notices from the Source form of the Work,
116 | excluding those notices that do not pertain to any part of
117 | the Derivative Works; and
118 |
119 | (d) If the Work includes a "NOTICE" text file as part of its
120 | distribution, then any Derivative Works that You distribute must
121 | include a readable copy of the attribution notices contained
122 | within such NOTICE file, excluding those notices that do not
123 | pertain to any part of the Derivative Works, in at least one
124 | of the following places: within a NOTICE text file distributed
125 | as part of the Derivative Works; within the Source form or
126 | documentation, if provided along with the Derivative Works; or,
127 | within a display generated by the Derivative Works, if and
128 | wherever such third-party notices normally appear. The contents
129 | of the NOTICE file are for informational purposes only and
130 | do not modify the License. You may add Your own attribution
131 | notices within Derivative Works that You distribute, alongside
132 | or as an addendum to the NOTICE text from the Work, provided
133 | that such additional attribution notices cannot be construed
134 | as modifying the License.
135 |
136 | You may add Your own copyright statement to Your modifications and
137 | may provide additional or different license terms and conditions
138 | for use, reproduction, or distribution of Your modifications, or
139 | for any such Derivative Works as a whole, provided Your use,
140 | reproduction, and distribution of the Work otherwise complies with
141 | the conditions stated in this License.
142 |
143 | 5. Submission of Contributions. Unless You explicitly state otherwise,
144 | any Contribution intentionally submitted for inclusion in the Work
145 | by You to the Licensor shall be under the terms and conditions of
146 | this License, without any additional terms or conditions.
147 | Notwithstanding the above, nothing herein shall supersede or modify
148 | the terms of any separate license agreement you may have executed
149 | with Licensor regarding such Contributions.
150 |
151 | 6. Trademarks. This License does not grant permission to use the trade
152 | names, trademarks, service marks, or product names of the Licensor,
153 | except as required for reasonable and customary use in describing the
154 | origin of the Work and reproducing the content of the NOTICE file.
155 |
156 | 7. Disclaimer of Warranty. Unless required by applicable law or
157 | agreed to in writing, Licensor provides the Work (and each
158 | Contributor provides its Contributions) on an "AS IS" BASIS,
159 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
160 | implied, including, without limitation, any warranties or conditions
161 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
162 | PARTICULAR PURPOSE. You are solely responsible for determining the
163 | appropriateness of using or redistributing the Work and assume any
164 | risks associated with Your exercise of permissions under this License.
165 |
166 | 8. Limitation of Liability. In no event and under no legal theory,
167 | whether in tort (including negligence), contract, or otherwise,
168 | unless required by applicable law (such as deliberate and grossly
169 | negligent acts) or agreed to in writing, shall any Contributor be
170 | liable to You for damages, including any direct, indirect, special,
171 | incidental, or consequential damages of any character arising as a
172 | result of this License or out of the use or inability to use the
173 | Work (including but not limited to damages for loss of goodwill,
174 | work stoppage, computer failure or malfunction, or any and all
175 | other commercial damages or losses), even if such Contributor
176 | has been advised of the possibility of such damages.
177 |
178 | 9. Accepting Warranty or Additional Liability. While redistributing
179 | the Work or Derivative Works thereof, You may choose to offer,
180 | and charge a fee for, acceptance of support, warranty, indemnity,
181 | or other liability obligations and/or rights consistent with this
182 | License. However, in accepting such obligations, You may act only
183 | on Your own behalf and on Your sole responsibility, not on behalf
184 | of any other Contributor, and only if You agree to indemnify,
185 | defend, and hold each Contributor harmless for any liability
186 | incurred by, or claims asserted against, such Contributor by reason
187 | of your accepting any such warranty or additional liability.
188 |
189 | END OF TERMS AND CONDITIONS
190 |
191 |
--------------------------------------------------------------------------------
/native/ss.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | **
3 | ** Copyright 2010, Koushik Dutta
4 | ** Copyright 2011, Paul Kocialkowski
5 | ** Copyright 2011, The CyanogenMod Project
6 | **
7 | ** Licensed under the Apache License, Version 2.0 (the "License");
8 | ** you may not use this file except in compliance with the License.
9 | ** You may obtain a copy of the License at
10 | **
11 | ** http://www.apache.org/licenses/LICENSE-2.0
12 | **
13 | ** Unless required by applicable law or agreed to in writing, software
14 | ** distributed under the License is distributed on an "AS IS" BASIS,
15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | ** See the License for the specific language governing permissions and
17 | ** limitations under the License.
18 | */
19 |
20 | #define LOG_TAG "CM Screenshot"
21 |
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 |
31 | #include
32 | #include
33 |
34 | #include
35 |
36 | #include
37 |
38 | #include
39 |
40 | #include
41 | #include
42 |
43 |
44 | using namespace android;
45 |
46 | struct bmpfile_magic {
47 | unsigned char magic[2];
48 | };
49 |
50 | struct bmpfile_header {
51 | uint32_t filesz;
52 | uint16_t creator1;
53 | uint16_t creator2;
54 | uint32_t bmp_offset;
55 | };
56 |
57 | struct bmpfile_dibheader {
58 | uint32_t header_sz;
59 | uint32_t width;
60 | uint32_t height;
61 | uint16_t nplanes;
62 | uint16_t bitspp;
63 | uint32_t compress_type;
64 | uint32_t bmp_bytesz;
65 | uint32_t hres;
66 | uint32_t vres;
67 | uint32_t ncolors;
68 | uint32_t nimpcolors;
69 | };
70 |
71 | typedef unsigned char byte;
72 |
73 | #define PIXEL_ORDER_RGBA 0x01
74 | #define PIXEL_ORDER_BGRA 0x02
75 | #define PIXEL_ORDER_UNKNOWN 0x03
76 |
77 | int get_pixel_order(struct fb_var_screeninfo *vinfo)
78 | {
79 | /* RGBA */
80 | if(vinfo->red.offset < vinfo->green.offset)
81 | {
82 | LOGD("RGBA");
83 | return PIXEL_ORDER_RGBA;
84 | }
85 | /* BGRA */
86 | else if(vinfo->blue.offset < vinfo->green.offset)
87 | {
88 | LOGD("BGRA");
89 | return PIXEL_ORDER_BGRA;
90 | }
91 | /* UNKNOWN */
92 | else
93 | {
94 | return PIXEL_ORDER_UNKNOWN;
95 | }
96 | }
97 |
98 | void sort_pixels(int pixel_order, void *buf, void *buf_end)
99 | {
100 | byte *pos;
101 | byte tmp;
102 | switch(pixel_order)
103 | {
104 | case PIXEL_ORDER_BGRA:
105 | break;
106 |
107 | case PIXEL_ORDER_RGBA:
108 | default:
109 | pos = (byte *)buf;
110 | while (pos < (byte *)buf_end)
111 | {
112 | tmp = pos[0];
113 | pos[0] = pos[2];
114 | pos[2] = tmp;
115 | pos += 4;
116 | }
117 | break;
118 | }
119 | }
120 |
121 | void* tryfbmap(int framebufferHandle, int size)
122 | {
123 | void *fbPixels = mmap(0, size, PROT_READ, MAP_SHARED, framebufferHandle, 0);
124 | if(fbPixels == MAP_FAILED)
125 | {
126 | LOGD("failed to map memory\n");
127 | return NULL;
128 | }
129 | return fbPixels;
130 | }
131 |
132 | static const int format_map[] = {0,32,32,24,16,32,16,16};
133 |
134 | int main(int argc, char **argv)
135 | {
136 | int framebufferHandle = -1;
137 | int mapSize = 0;
138 |
139 | int ret = 1;
140 |
141 | char ssPath[128];
142 | int screenshotHandle;
143 |
144 | void* base = NULL;
145 | uint32_t w = 0;
146 | uint32_t h = 0;
147 | uint32_t depth = 0;
148 | int totalPixels = 0;
149 | int pixelOrder = PIXEL_ORDER_RGBA;
150 |
151 | sprintf(ssPath,"%s/tmpshot.bmp",getenv("EXTERNAL_STORAGE"));
152 |
153 | ScreenshotClient screenshot;
154 |
155 | if (screenshot.update() != NO_ERROR) {
156 | struct fb_var_screeninfo vinfo;
157 |
158 | LOGD("surfaceflinger capture failed. Falling back to fb and hoping for the best");
159 | framebufferHandle = open("/dev/graphics/fb0", O_RDONLY);
160 | if(framebufferHandle < 0)
161 | return 0;
162 | if(ioctl(framebufferHandle, FBIOGET_VSCREENINFO, &vinfo) < 0) {
163 | close(framebufferHandle);
164 | return 0;
165 | }
166 | w = vinfo.xres;
167 | h = vinfo.yres;
168 | totalPixels = w * h;
169 | depth = vinfo.bits_per_pixel;
170 | mapSize = totalPixels * (depth/8);
171 | fcntl(framebufferHandle, F_SETFD, FD_CLOEXEC);
172 | LOGD("Got %dx%dx%d framebuffer",w,h,depth);
173 | base = tryfbmap(framebufferHandle, mapSize);
174 | pixelOrder = get_pixel_order(&vinfo);
175 | } else {
176 | uint32_t f = screenshot.getFormat();
177 | base = (void *)screenshot.getPixels();
178 | w = screenshot.getWidth();
179 | h = screenshot.getHeight();
180 | totalPixels = w * h;
181 | depth = format_map[f];
182 | }
183 |
184 |
185 | int totalMem8888 = totalPixels * 4;
186 | int *rgbaPixels = (int*)malloc(totalMem8888);
187 | int *endOfImage = rgbaPixels + h * w;
188 | int *rgbaPixelsCopy;
189 | int *curline;
190 | int lineSize;
191 | int *srcline;
192 |
193 | if (depth == 16)
194 | {
195 | short *baseCursor = (short*)base;
196 | int *rgbaPixelsCursor = rgbaPixels;
197 | int *rgbaLast = rgbaPixels + totalPixels;
198 |
199 | LOGV("Working with 16 depth and a mapsize of %d",mapSize);
200 |
201 | for(; rgbaPixelsCursor < rgbaLast; rgbaPixelsCursor++, baseCursor++)
202 | {
203 | short pixel = *baseCursor;
204 | int r = (pixel & 0xF800) << 8;
205 | int g = (pixel & 0x7E0) << 5;
206 | int b = (pixel & 0x1F) << 3;
207 | int color = 0xFF000000 | r | g | b;
208 | *rgbaPixelsCursor = color;
209 | }
210 | }
211 | else if (depth == 32)
212 | {
213 | memcpy(rgbaPixels, base, totalMem8888);
214 |
215 | sort_pixels(pixelOrder, rgbaPixels, endOfImage);
216 | }
217 | else
218 | {
219 | ret = 2;
220 | goto done;
221 | }
222 |
223 | // flip it upside down!
224 | rgbaPixelsCopy = (int*)malloc(totalMem8888);
225 | curline = rgbaPixelsCopy + (h - 1) * w;
226 | lineSize = 4 * w;
227 | srcline = rgbaPixels;
228 | for (; srcline < endOfImage; curline -= w, srcline += w)
229 | {
230 | memcpy(curline, srcline, lineSize);
231 | }
232 | memcpy(rgbaPixels, rgbaPixelsCopy, totalMem8888);
233 | free(rgbaPixelsCopy);
234 |
235 | struct bmpfile_magic magic;
236 | struct bmpfile_header header;
237 | struct bmpfile_dibheader dibheader;
238 |
239 | magic.magic[0] = 0x42;
240 | magic.magic[1] = 0x4D;
241 |
242 | header.bmp_offset = sizeof(magic) + sizeof(header) + sizeof(dibheader);
243 | header.creator1 = 0;
244 | header.creator2 = 0;
245 | header.filesz = sizeof(magic) + sizeof(header) + sizeof(dibheader) + totalMem8888;
246 |
247 | dibheader.header_sz = sizeof(dibheader);
248 | dibheader.width = w;
249 | dibheader.height = h;
250 | dibheader.nplanes = 1;
251 | dibheader.bitspp = 32;
252 | dibheader.compress_type = 0;
253 | dibheader.bmp_bytesz = totalMem8888;
254 | dibheader.hres = w;
255 | dibheader.vres = h;
256 | dibheader.ncolors = 0;
257 | dibheader.nimpcolors = 0;
258 |
259 |
260 | screenshotHandle = open(ssPath, O_WRONLY | O_CREAT);
261 | write(screenshotHandle, &magic, sizeof(magic));
262 | write(screenshotHandle, &header, sizeof(header));
263 | write(screenshotHandle, &dibheader, sizeof(dibheader));
264 | write(screenshotHandle, rgbaPixels, totalMem8888);
265 | close(screenshotHandle);
266 |
267 | ret = 0;
268 | done:
269 | if (rgbaPixels != NULL)
270 | free(rgbaPixels);
271 | if (framebufferHandle >= 0 && mapSize) {
272 | munmap(base, mapSize);
273 | close(framebufferHandle);
274 | }
275 | return ret;
276 | }
277 |
278 |
--------------------------------------------------------------------------------
/res/values-cs/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Snímek obrazovky
4 |
5 | Chyba:
6 | Obrazovka uložena jako
7 | Sdílet snímek obrazovky
8 | Nyní není možné sdílet snímek obrazovky
9 | Úložiště není připojeno
10 |
11 |
--------------------------------------------------------------------------------
/res/values-da/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Screenshot
4 |
5 |
6 | Fejl:
7 | Screenshot gemt i
8 |
9 |
10 |
--------------------------------------------------------------------------------
/res/values-de/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Bildschirmfoto
4 |
5 |
6 | Fehler:
7 | Bildschirmfoto gespeichert in
8 | Bildschirmfoto teilen
9 | Es gibt keine Möglichkeit, um das Bildschirmfoto zu teilen
10 | SD-Karte ist nicht eingehängt
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/values-fr/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Screenshot
4 |
5 |
6 | Erreur :
7 | Screenshot sauvegardé dans
8 |
9 |
10 |
--------------------------------------------------------------------------------
/res/values-hu/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Képmentés
4 |
5 |
6 | Hiba:
7 | Kép elmentve
8 | Kép megosztása
9 | Nincs lehetőség megosztásra
10 | Média nincs csatolva
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/values-it/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Screenshot
4 |
5 |
6 | Errore:
7 | Schermata salvata in
8 | Condividi Schermata
9 | Non è possibile condividere la schermata
10 |
11 |
12 |
--------------------------------------------------------------------------------
/res/values-ja/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | スクリーンショット
4 |
5 |
6 | エラー:
7 | スクリーンショットは次の場所に保存しました:
8 | スクリーンショットを共有
9 | スクリーンショットを共有する手段がありません
10 | メディアがマウントされてません
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/res/values-ko/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 스크린샷
4 |
5 |
6 | 오류:
7 | 스크린샷이 다음 경로에 저장되었습니다:
8 |
9 |
10 |
--------------------------------------------------------------------------------
/res/values-nl/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Beeldschermfoto
4 |
5 |
6 | Fout:
7 | Beeldschermfoto is opgeslagen in
8 |
9 |
10 |
--------------------------------------------------------------------------------
/res/values-pl/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Screenshot
4 |
5 |
6 | Błąd:
7 | Zrzut ekranu został zapisany na
8 | Udostępnij zrzut ekranu
9 | Brak możliwości udostępnienia
10 | Media niezamontowane
11 |
12 |
--------------------------------------------------------------------------------
/res/values-pt/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Screenshot
4 | Erro:
5 | Screenshot é gravado em
6 |
--------------------------------------------------------------------------------
/res/values-ru/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Screenshot
4 |
5 |
6 | Ошибка:
7 | Скриншот сохранён в
8 | Отправить скриншот
9 | Нет возможности отправить скриншот
10 | Носитель не подключен
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/values-sk/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Snímka obrazovky
4 |
5 | Chyba:
6 | Obrazovka uložená ako
7 |
8 |
--------------------------------------------------------------------------------
/res/values-sv/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Skärmdump
4 |
5 | Fel:
6 | Skärmdump sparades i
7 | Dela skärmdump
8 | Finns inget sätt att dela skärmdump
9 | Media avmonterat
10 |
11 |
--------------------------------------------------------------------------------
/res/values-tr/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Ekran Görüntüsü
4 |
5 | Hata:
6 | Ekran görüntüsü kaydedildi:
7 | Ekran Görüntüsü Paylaş
8 | Ekran görüntüsü paylaşılamaz
9 | Aygıt çıkartılmış
10 |
11 |
12 |
--------------------------------------------------------------------------------
/res/values-uk/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Скриншот
4 |
5 |
6 | Помилка:
7 | Знімок екрана збережено в
8 |
9 |
10 |
--------------------------------------------------------------------------------
/res/values-zh-rCN/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 屏幕截图
4 |
5 |
6 | 错误:
7 | 屏幕截图已经保存到
8 | 分享屏幕截图
9 | 无法分享屏幕截图
10 | 存储设备未挂载
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/values-zh-rTW/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 螢幕畫面擷取
4 |
5 |
6 | 錯誤:
7 | 螢幕擷取畫面已儲存到
8 | 分享螢幕擷取畫面
9 | 沒有途徑分享螢幕擷取畫面
10 | 儲存裝置尚未掛載
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Screenshot
4 |
5 |
6 | Error:
7 | Screenshot is saved at
8 | Share Screenshot
9 | No way to share screenshot
10 | Media unmounted
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/com/cyanogenmod/screenshot/ScreenshotActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | **
3 | ** Copyright 2010, Koushik Dutta
4 | ** Copyright 2011, The CyanogenMod Project
5 | **
6 | ** Licensed under the Apache License, Version 2.0 (the "License");
7 | ** you may not use this file except in compliance with the License.
8 | ** You may obtain a copy of the License at
9 | **
10 | ** http://www.apache.org/licenses/LICENSE-2.0
11 | **
12 | ** Unless required by applicable law or agreed to in writing, software
13 | ** distributed under the License is distributed on an "AS IS" BASIS,
14 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | ** See the License for the specific language governing permissions and
16 | ** limitations under the License.
17 | */
18 |
19 | package com.cyanogenmod.screenshot;
20 |
21 | import java.io.File;
22 | import java.io.FileOutputStream;
23 | import java.io.IOException;
24 |
25 | import android.app.Activity;
26 | import android.app.AlertDialog;
27 | import android.content.BroadcastReceiver;
28 | import android.content.Context;
29 | import android.content.Intent;
30 | import android.content.IntentFilter;
31 | import android.graphics.Bitmap;
32 | import android.graphics.BitmapFactory;
33 | import android.graphics.Bitmap.CompressFormat;
34 | import android.graphics.Matrix;
35 | import android.media.MediaScannerConnection;
36 | import android.net.Uri;
37 | import android.os.Bundle;
38 | import android.os.Handler;
39 | import android.os.Environment;
40 | import android.os.SystemProperties;
41 | import android.provider.Settings;
42 | import android.util.Log;
43 | import android.widget.Toast;
44 |
45 | import android.view.Display;
46 | import android.view.WindowManager;
47 |
48 | public class ScreenshotActivity extends Activity
49 | {
50 | static Bitmap mBitmap = null;
51 | Handler mHander = new Handler();
52 | String mScreenshotFile;
53 |
54 | private static final String SCREENSHOT_BUCKET_NAME =
55 | Environment.getExternalStorageDirectory().toString()
56 | + "/DCIM/Screenshots";
57 |
58 | /** Called when the activity is first created. */
59 | @Override
60 | public void onCreate(Bundle savedInstanceState)
61 | {
62 | super.onCreate(savedInstanceState);
63 | if (!(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))) {
64 | Toast toast = Toast.makeText(ScreenshotActivity.this, getString(R.string.not_mounted), Toast.LENGTH_LONG);
65 | toast.show();
66 | finish();
67 | }
68 | mConnection = new MediaScannerConnection(ScreenshotActivity.this, mMediaScannerConnectionClient);
69 | mConnection.connect();
70 | takeScreenshot(1);
71 | }
72 |
73 | void takeScreenshot()
74 | {
75 | String mRawScreenshot = String.format("%s/tmpshot.bmp", Environment.getExternalStorageDirectory().toString());
76 |
77 | try
78 | {
79 | Process p = Runtime.getRuntime().exec("/system/bin/screenshot");
80 | Log.d("CMScreenshot","Ran helper");
81 | p.waitFor();
82 | mBitmap = BitmapFactory.decodeFile(mRawScreenshot);
83 | File tmpshot = new File(mRawScreenshot);
84 | tmpshot.delete();
85 |
86 | if (mBitmap == null) {
87 | throw new Exception("Unable to save screenshot: mBitmap = "+mBitmap);
88 | }
89 |
90 | // valid values for ro.sf.hwrotation are 0, 90, 180 & 270
91 | int rot = 360-SystemProperties.getInt("ro.sf.hwrotation",0);
92 |
93 | Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
94 |
95 | // First round, natural device rotation
96 | if(rot > 0 && rot < 360){
97 | Log.d("CMScreenshot","rotation="+rot);
98 | Matrix matrix = new Matrix();
99 | matrix.postRotate(rot);
100 | mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true);
101 | }
102 |
103 | // Second round, device orientation:
104 | // getOrientation returns 0-3 for 0, 90, 180, 270, relative
105 | // to the natural position of the device
106 | rot = (display.getOrientation() * 90);
107 | rot %= 360;
108 | if(rot > 0){
109 | Log.d("CMScreenshot","rotation="+rot);
110 | Matrix matrix = new Matrix();
111 | matrix.postRotate((rot*-1));
112 | mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true);
113 | }
114 |
115 | try
116 | {
117 | File dir = new File(SCREENSHOT_BUCKET_NAME);
118 | if (!dir.exists()) dir.mkdirs();
119 | mScreenshotFile = String.format("%s/screenshot-%d.png", SCREENSHOT_BUCKET_NAME, System.currentTimeMillis());
120 | FileOutputStream fout = new FileOutputStream(mScreenshotFile);
121 | mBitmap.compress(CompressFormat.PNG, 100, fout);
122 | fout.close();
123 |
124 | boolean shareScreenshot = (Settings.System.getInt(getContentResolver(),
125 | Settings.System.SHARE_SCREENSHOT, 0)) == 1;
126 | if (shareScreenshot) {
127 | Intent intent = new Intent(Intent.ACTION_SEND);
128 | intent.setType("image/png");
129 |
130 | intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(mScreenshotFile)));
131 |
132 | startActivity(Intent.createChooser(intent, getString(R.string.share_message)));
133 | }
134 | }
135 | catch (android.content.ActivityNotFoundException ex) {
136 | Toast.makeText(ScreenshotActivity.this,
137 | R.string.no_way_to_share,
138 | Toast.LENGTH_SHORT).show();
139 | }
140 | catch (Exception ex)
141 | {
142 | finish();
143 | throw new Exception("Unable to save screenshot: "+ex);
144 | }
145 | }
146 | catch (Exception ex)
147 | {
148 | Toast toast = Toast.makeText(ScreenshotActivity.this, getString(R.string.toast_error) + " " + ex.getMessage(), Toast.LENGTH_LONG);
149 | toast.show();
150 | }
151 | Toast toast = Toast.makeText(ScreenshotActivity.this, getString(R.string.toast_save_location) + " " + mScreenshotFile,Toast.LENGTH_LONG);
152 | toast.show();
153 |
154 | mConnection.scanFile(mScreenshotFile, null);
155 | mConnection.disconnect();
156 | finish();
157 | }
158 |
159 | MediaScannerConnection mConnection;
160 | MediaScannerConnection.MediaScannerConnectionClient mMediaScannerConnectionClient = new MediaScannerConnection.MediaScannerConnectionClient() {
161 | public void onScanCompleted(String path, Uri uri) {
162 | mConnection.disconnect();
163 | finish();
164 | }
165 | public void onMediaScannerConnected() {
166 | }
167 | };
168 |
169 | void takeScreenshot(final int delay)
170 | {
171 | mHander.postDelayed(new Runnable()
172 | {
173 | public void run()
174 | {
175 | takeScreenshot();
176 | }
177 | }, delay * 1000);
178 | }
179 |
180 | }
181 |
--------------------------------------------------------------------------------
/src/com/cyanogenmod/screenshot/ScreenshotReceiver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The CyanogenMod Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.cyanogenmod.screenshot;
18 |
19 | import android.content.Context;
20 | import android.content.Intent;
21 | import android.util.Log;
22 |
23 | public class ScreenshotReceiver extends android.content.BroadcastReceiver {
24 |
25 | @Override
26 | public void onReceive(Context context, Intent changed_intent) {
27 | Intent intent = new Intent();
28 | intent.setClass(context, ScreenshotActivity.class);
29 | intent.setAction(ScreenshotActivity.class.getName());
30 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
31 | context.startActivity(intent);
32 | }
33 | }
34 |
35 |
--------------------------------------------------------------------------------