김예미

add Contact, CallLog, SMS, Wifi extraction

...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
4 <component name="GradleSettings"> 4 <component name="GradleSettings">
5 <option name="linkedExternalProjectsSettings"> 5 <option name="linkedExternalProjectsSettings">
6 <GradleProjectSettings> 6 <GradleProjectSettings>
7 + <compositeConfiguration>
8 + <compositeBuild compositeDefinitionSource="SCRIPT" />
9 + </compositeConfiguration>
7 <option name="delegatedBuild" value="false" /> 10 <option name="delegatedBuild" value="false" />
8 - <option name="testRunner" value="PLATFORM" />
9 <option name="distributionType" value="DEFAULT_WRAPPED" /> 11 <option name="distributionType" value="DEFAULT_WRAPPED" />
10 <option name="externalProjectPath" value="$PROJECT_DIR$" /> 12 <option name="externalProjectPath" value="$PROJECT_DIR$" />
11 <option name="modules"> 13 <option name="modules">
...@@ -15,6 +17,7 @@ ...@@ -15,6 +17,7 @@
15 </set> 17 </set>
16 </option> 18 </option>
17 <option name="resolveModulePerSourceSet" value="false" /> 19 <option name="resolveModulePerSourceSet" value="false" />
20 + <option name="testRunner" value="PLATFORM" />
18 </GradleProjectSettings> 21 </GradleProjectSettings>
19 </option> 22 </option>
20 </component> 23 </component>
......
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="JDK" project-jdk-type="JavaSDK"> 3 + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" 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 +<?xml version="1.0" encoding="UTF-8"?>
2 +<project version="4">
3 + <component name="VcsDirectoryMappings">
4 + <mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
5 + </component>
6 +</project>
...\ No newline at end of file ...\ No newline at end of file
...@@ -5,7 +5,7 @@ android { ...@@ -5,7 +5,7 @@ android {
5 buildToolsVersion "29.0.2" 5 buildToolsVersion "29.0.2"
6 defaultConfig { 6 defaultConfig {
7 applicationId "com.example.dataextraction" 7 applicationId "com.example.dataextraction"
8 - minSdkVersion 28 8 + minSdkVersion 23
9 targetSdkVersion 29 9 targetSdkVersion 29
10 versionCode 1 10 versionCode 1
11 versionName "1.0" 11 versionName "1.0"
......
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
7 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 7 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
8 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 8 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
9 <uses-permission android:name="android.permission.READ_CALENDAR" /> 9 <uses-permission android:name="android.permission.READ_CALENDAR" />
10 + <uses-permission android:name="android.permission.READ_CONTACTS" />
11 + <uses-permission android:name="android.permission.READ_CALL_LOG" />
12 + <uses-permission android:name="android.permission.READ_SMS" />
13 + <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
10 14
11 <application 15 <application
12 android:allowBackup="true" 16 android:allowBackup="true"
......
1 +package com.example.dataextraction;
2 +
3 +import android.provider.BaseColumns;
4 +
5 +public class CallLogDataBase {
6 + public static final class CreateDB implements BaseColumns {
7 + public static final String ID = "id";
8 + public static final String TYPE = "type";
9 + public static final String NAME = "name";
10 + public static final String NUMBER = "number";
11 + public static final String DURATION = "duration";
12 + public static final String DATE = "date";
13 + public static final String _TABLENAME0 = "calllog";
14 + public static final String _CREATE0 = "create table if not exists "+_TABLENAME0+"("
15 + +ID+" INTEGER PRIMARY KEY autoincrement, "
16 + +TYPE+" integer not null , "
17 + +NAME + " text not null,"
18 + +NUMBER + " text not null,"
19 + +DURATION + " inteter not null,"
20 + +DATE + " text);";
21 + }
22 +}
1 +package com.example.dataextraction;
2 +
3 +import android.provider.BaseColumns;
4 +
5 +public class ContactDataBase {
6 + public static final class CreateDB implements BaseColumns {
7 + public static final String NUMBER = "number";
8 + public static final String NAME = "name";
9 + public static final String PHOTO_ID = "photo_id";
10 + public static final String PERSON_ID = "person_id";
11 + public static final String _TABLENAME0 = "contact";
12 + public static final String _CREATE0 = "create table if not exists "+_TABLENAME0+"("
13 + +NUMBER+" text not null primary key, "
14 + +NAME+" text not null , "
15 + +PHOTO_ID + " integer,"
16 + +PERSON_ID + " integer);";
17 + }
18 +}
...@@ -27,6 +27,10 @@ public class DBHelper { ...@@ -27,6 +27,10 @@ public class DBHelper {
27 db.execSQL(VideoDataBase.CreateDB._CREATE0); 27 db.execSQL(VideoDataBase.CreateDB._CREATE0);
28 db.execSQL(AudioDataBase.CreateDB._CREATE0); 28 db.execSQL(AudioDataBase.CreateDB._CREATE0);
29 db.execSQL(CalendarDataBase.CreateDB._CREATE0); 29 db.execSQL(CalendarDataBase.CreateDB._CREATE0);
30 + db.execSQL(CallLogDataBase.CreateDB._CREATE0);
31 + db.execSQL(ContactDataBase.CreateDB._CREATE0);
32 + db.execSQL(SMSDataBase.CreateDB._CREATE0);
33 + db.execSQL(WifiDataBase.CreateDB._CREATE0);
30 } 34 }
31 35
32 @Override 36 @Override
...@@ -35,6 +39,10 @@ public class DBHelper { ...@@ -35,6 +39,10 @@ public class DBHelper {
35 db.execSQL("DROP TABLE IF EXISTS " + VideoDataBase.CreateDB._TABLENAME0); 39 db.execSQL("DROP TABLE IF EXISTS " + VideoDataBase.CreateDB._TABLENAME0);
36 db.execSQL("DROP TABLE IF EXISTS " + AudioDataBase.CreateDB._TABLENAME0); 40 db.execSQL("DROP TABLE IF EXISTS " + AudioDataBase.CreateDB._TABLENAME0);
37 db.execSQL("DROP TABLE IF EXISTS " + CalendarDataBase.CreateDB._TABLENAME0); 41 db.execSQL("DROP TABLE IF EXISTS " + CalendarDataBase.CreateDB._TABLENAME0);
42 + db.execSQL("DROP TABLE IF EXISTS " + CallLogDataBase.CreateDB._TABLENAME0);
43 + db.execSQL("DROP TABLE IF EXISTS " + ContactDataBase.CreateDB._TABLENAME0);
44 + db.execSQL("DROP TABLE IF EXISTS " + SMSDataBase.CreateDB._TABLENAME0);
45 + db.execSQL("DROP TABLE IF EXISTS " + WifiDataBase.CreateDB._TABLENAME0);
38 onCreate(db); 46 onCreate(db);
39 } 47 }
40 } 48 }
...@@ -122,4 +130,48 @@ public class DBHelper { ...@@ -122,4 +130,48 @@ public class DBHelper {
122 values.put(CalendarDataBase.CreateDB.RDATE, r_date); 130 values.put(CalendarDataBase.CreateDB.RDATE, r_date);
123 return mDB.insert(CalendarDataBase.CreateDB._TABLENAME0, null, values); 131 return mDB.insert(CalendarDataBase.CreateDB._TABLENAME0, null, values);
124 } 132 }
133 +
134 + public long insertCallLogColumn(String type, String name, String number, String duration
135 + , String date){
136 + ContentValues values = new ContentValues();
137 + values.put(CallLogDataBase.CreateDB.TYPE, type);
138 + values.put(CallLogDataBase.CreateDB.NAME, name);
139 + values.put(CallLogDataBase.CreateDB.NUMBER, number);
140 + values.put(CallLogDataBase.CreateDB.DURATION, duration);
141 + values.put(CallLogDataBase.CreateDB.DATE, date);
142 + return mDB.insert(CallLogDataBase.CreateDB._TABLENAME0, null, values);
143 + }
144 +
145 + public long insertContactColumn(String number, String name, String photo_id, String person_id){
146 + ContentValues values = new ContentValues();
147 + values.put(ContactDataBase.CreateDB.NUMBER, number);
148 + values.put(ContactDataBase.CreateDB.NAME, name);
149 + values.put(ContactDataBase.CreateDB.PHOTO_ID, photo_id);
150 + values.put(ContactDataBase.CreateDB.PERSON_ID, person_id);
151 + return mDB.insert(ContactDataBase.CreateDB._TABLENAME0, null, values);
152 + }
153 +
154 + public long insertSMSColumn(String mid, String tid, String type, String address, String person
155 + , String creator, String date, String body, String read){
156 + ContentValues values = new ContentValues();
157 + values.put(SMSDataBase.CreateDB.MID, mid);
158 + values.put(SMSDataBase.CreateDB.TID, tid);
159 + values.put(SMSDataBase.CreateDB.TYPE, type);
160 + values.put(SMSDataBase.CreateDB.ADDRESS, address);
161 + values.put(SMSDataBase.CreateDB.PERSON, person);
162 + values.put(SMSDataBase.CreateDB.CREATOR, creator);
163 + values.put(SMSDataBase.CreateDB.DATE, date);
164 + values.put(SMSDataBase.CreateDB.BODY, body);
165 + values.put(SMSDataBase.CreateDB.READ, read);
166 + return mDB.insert(SMSDataBase.CreateDB._TABLENAME0, null, values);
167 + }
168 +
169 + public long insertWifiColumn(String id, String ssid, String bssid, String wepkeys){
170 + ContentValues values = new ContentValues();
171 + values.put(WifiDataBase.CreateDB.ID, id);
172 + values.put(WifiDataBase.CreateDB.SSID, ssid);
173 + values.put(WifiDataBase.CreateDB.BSSID, bssid);
174 + values.put(WifiDataBase.CreateDB.WEPKEYS, wepkeys);
175 + return mDB.insert(WifiDataBase.CreateDB._TABLENAME0, null, values);
176 + }
125 } 177 }
......
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;
4 5
5 import android.Manifest; 6 import android.Manifest;
6 import android.content.ContentResolver; 7 import android.content.ContentResolver;
...@@ -16,10 +17,15 @@ import android.net.NetworkInfo; ...@@ -16,10 +17,15 @@ import android.net.NetworkInfo;
16 import android.net.ProxyInfo; 17 import android.net.ProxyInfo;
17 import android.net.RouteInfo; 18 import android.net.RouteInfo;
18 import android.net.Uri; 19 import android.net.Uri;
20 +import android.net.wifi.WifiConfiguration;
21 +import android.net.wifi.WifiManager;
19 import android.os.Build; 22 import android.os.Build;
20 import android.os.Bundle; 23 import android.os.Bundle;
21 import android.provider.CalendarContract; 24 import android.provider.CalendarContract;
25 +import android.provider.CallLog;
26 +import android.provider.ContactsContract;
22 import android.provider.MediaStore; 27 import android.provider.MediaStore;
28 +import android.provider.Telephony;
23 import android.view.View; 29 import android.view.View;
24 import android.widget.Toast; 30 import android.widget.Toast;
25 31
...@@ -29,15 +35,22 @@ import java.text.SimpleDateFormat; ...@@ -29,15 +35,22 @@ import java.text.SimpleDateFormat;
29 import java.util.ArrayList; 35 import java.util.ArrayList;
30 import java.util.Date; 36 import java.util.Date;
31 import java.util.List; 37 import java.util.List;
38 +import java.util.Locale;
32 39
33 public class MainActivity extends AppCompatActivity { 40 public class MainActivity extends AppCompatActivity {
34 41
42 + DBHelper dbHelper;
43 +
35 String[] permission_list = { 44 String[] permission_list = {
36 Manifest.permission.READ_EXTERNAL_STORAGE, 45 Manifest.permission.READ_EXTERNAL_STORAGE,
37 Manifest.permission.WRITE_EXTERNAL_STORAGE, 46 Manifest.permission.WRITE_EXTERNAL_STORAGE,
38 Manifest.permission.READ_CALENDAR, 47 Manifest.permission.READ_CALENDAR,
39 Manifest.permission.ACCESS_NETWORK_STATE, 48 Manifest.permission.ACCESS_NETWORK_STATE,
40 Manifest.permission.ACCESS_FINE_LOCATION, 49 Manifest.permission.ACCESS_FINE_LOCATION,
50 + Manifest.permission.READ_CONTACTS,
51 + Manifest.permission.READ_CALL_LOG,
52 + Manifest.permission.READ_SMS,
53 + Manifest.permission.ACCESS_WIFI_STATE
41 }; 54 };
42 55
43 @Override 56 @Override
...@@ -53,9 +66,9 @@ public class MainActivity extends AppCompatActivity { ...@@ -53,9 +66,9 @@ public class MainActivity extends AppCompatActivity {
53 ArrayList<videoItem> videos = getVideoList(); 66 ArrayList<videoItem> videos = getVideoList();
54 ArrayList<audioItem> audios = getAudioList(); 67 ArrayList<audioItem> audios = getAudioList();
55 ArrayList<calendarItem> calendars = getCalendarInfoList(); 68 ArrayList<calendarItem> calendars = getCalendarInfoList();
56 - getNetworkInfo(); 69 + //getNetworkInfo();
57 - DBHelper dbHelper = new DBHelper(getApplicationContext());
58 70
71 + dbHelper = new DBHelper(getApplicationContext());
59 dbHelper.open(); 72 dbHelper.open();
60 for(photoItem photo: photos){ 73 for(photoItem photo: photos){
61 dbHelper.insertPColumn(photo.getTitle(), photo.getId(), photo.getDate() 74 dbHelper.insertPColumn(photo.getTitle(), photo.getId(), photo.getDate()
...@@ -82,6 +95,10 @@ public class MainActivity extends AppCompatActivity { ...@@ -82,6 +95,10 @@ public class MainActivity extends AppCompatActivity {
82 , calendar.getAllday(), calendar.getDisplayName(), calendar.getAccountName() 95 , calendar.getAllday(), calendar.getDisplayName(), calendar.getAccountName()
83 , calendar.getOwnerName(), calendar.getRrule(), calendar.getRdate()); 96 , calendar.getOwnerName(), calendar.getRrule(), calendar.getRdate());
84 } 97 }
98 + getCallLog();
99 + getContact();
100 + getSMSMessage();
101 + getWIFI();
85 dbHelper.close(); 102 dbHelper.close();
86 } 103 }
87 104
...@@ -347,6 +364,127 @@ public class MainActivity extends AppCompatActivity { ...@@ -347,6 +364,127 @@ public class MainActivity extends AppCompatActivity {
347 dbHelper.close(); 364 dbHelper.close();
348 } 365 }
349 366
367 +
368 + public void getCallLog(){
369 +
370 + int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_CALL_LOG);
371 +
372 + Uri uri = CallLog.Calls.CONTENT_URI;
373 + if(permissionCheck == PackageManager.PERMISSION_GRANTED) {
374 + Cursor cursor = getBaseContext().getContentResolver().query(uri, null, null, null, CallLog.Calls.DEFAULT_SORT_ORDER);
375 +
376 + if(cursor.getCount() > 0){
377 + while(cursor.moveToNext()){
378 + //1:수신, 2:발신, 3:부재중
379 + String type = cursor.getString(cursor.getColumnIndex(CallLog.Calls.TYPE));
380 + //이름
381 + String name = cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME));
382 + //번호
383 + String number = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER));
384 + //통화시간
385 + String duration = cursor.getString(cursor.getColumnIndex(CallLog.Calls.DURATION));
386 + //날짜
387 + long date_long = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE));
388 + DateFormat timeFormat = new SimpleDateFormat("yyyy MMM dd HH:mm:ss");
389 + Date date = new Date(date_long);
390 +
391 + //db에 추가
392 + dbHelper.insertCallLogColumn(type, name, number, duration, timeFormat.format(date));
393 +
394 + }
395 + }
396 + }
397 + }
398 +
399 + public void getContact(){
400 + Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
401 +
402 + String[] projection = new String[]{
403 + ContactsContract.CommonDataKinds.Phone.NUMBER,
404 + ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
405 + ContactsContract.Contacts.PHOTO_ID,
406 + ContactsContract.Contacts._ID
407 + };
408 +
409 + String sortOrder = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
410 +
411 + Cursor cursor = getContentResolver().query(uri,projection,null,null,sortOrder);
412 +
413 + if(cursor.moveToFirst()){
414 + do{
415 + //전화번호
416 + String number = cursor.getString(0);
417 + //이름
418 + String name = cursor.getString(1);
419 + String photo_id = cursor.getString(2);
420 + String person_id = cursor.getString(3);
421 +
422 + //name, number 중복하는거 거르기
423 + //db에 추가
424 + dbHelper.insertContactColumn(number, name, photo_id, person_id);
425 +
426 + }while(cursor.moveToNext());
427 + }
428 + }
429 +
430 + public void getSMSMessage(){
431 + Uri uri = Telephony.Sms.CONTENT_URI;
432 + String[] projection = new String[]{
433 + "type","_id","thread_id","address","person","creator","date","body","read"
434 + };
435 + Cursor cursor = getContentResolver().query(uri,projection, null,null,"date DESC");
436 +
437 + while(cursor.moveToNext()){
438 + //Telephony.Sms.MESSAGE_TYPE_INBOX 받은 메시지/Telephony.Sms.MESSAGE_TYPE_SENT 보낸 메시지
439 + String type = cursor.getString(0);
440 + //메세지 id
441 + String mid = cursor.getString(1);
442 + //특정 사용자와 대화의 공통 id
443 + String tid = cursor.getString(2);
444 + //주소 번호
445 + String address = cursor.getString(3);
446 + //누가 보냈는지 contact
447 + //Telephony.Sms.MESSAGE_TYPE_INBOX only
448 + String person = cursor.getString(4);
449 + //Telephony.Sms.MESSAGE_TYPE_SENT only
450 + String creator = cursor.getString(5);
451 + //시간 ms
452 + Long date_long = cursor.getLong(6);
453 + DateFormat timeFormat = new SimpleDateFormat("yyyy MMM dd HH:mm:ss");
454 + String date = timeFormat.format(date_long);
455 + //내용
456 + String body = cursor.getString(7);
457 + //사용자가 메시지 읽었으면 1, 안 읽었으면 0
458 + String read = cursor.getString(8);
459 +
460 + //db에 추가
461 + dbHelper.insertSMSColumn(mid, tid, type, address, person, creator, date, body, read);
462 + }
463 + }
464 +
465 + public void getWIFI(){
466 + WifiManager wm = (WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);
467 + //네트워크 설정 목록 획득
468 + List<WifiConfiguration> configurations = wm.getConfiguredNetworks();
469 + if(configurations != null){
470 + for(final WifiConfiguration config : configurations){
471 + //network id
472 + int i_id = config.networkId;
473 + String id = Integer.toString(i_id);
474 + //wifi 이름
475 + String ssid = config.SSID;
476 + //mac 주소
477 + String bssid = config.BSSID;
478 + //신호강도 (level)
479 + //연결 password
480 + String[] wepkeys = config.wepKeys;
481 +
482 + //db에 추가
483 + dbHelper.insertWifiColumn(id, ssid, bssid, wepkeys[0]);
484 + }
485 + }
486 + }
487 +
350 public void checkPermission(){ 488 public void checkPermission(){
351 //현재 안드로이드 버전이 6.0미만이면 메서드를 종료한다. 489 //현재 안드로이드 버전이 6.0미만이면 메서드를 종료한다.
352 if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M) 490 if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
......
1 +package com.example.dataextraction;
2 +
3 +import android.provider.BaseColumns;
4 +
5 +public class SMSDataBase {
6 + public static final class CreateDB implements BaseColumns {
7 + public static final String MID = "mid";
8 + public static final String TID = "tid";
9 + public static final String TYPE = "type";
10 + public static final String ADDRESS = "address";
11 + public static final String PERSON = "person";
12 + public static final String CREATOR = "creator";
13 + public static final String DATE = "date";
14 + public static final String BODY = "body";
15 + public static final String READ = "read";
16 + public static final String _TABLENAME0 = "sms";
17 + public static final String _CREATE0 = "create table if not exists "+_TABLENAME0+"("
18 + +MID+" integer not null primary key, "
19 + +TID+" integer not null , "
20 + +TYPE + " integer not null,"
21 + +ADDRESS+" text not null , "
22 + +PERSON + " text,"
23 + +CREATOR+" text , "
24 + +DATE + " text not null,"
25 + +BODY + " text not null,"
26 + +READ + " integer);";
27 + }
28 +}
1 +package com.example.dataextraction;
2 +
3 +import android.provider.BaseColumns;
4 +
5 +public class WifiDataBase {
6 + public static final class CreateDB implements BaseColumns {
7 + public static final String ID = "id";
8 + public static final String SSID = "ssid";
9 + public static final String BSSID = "bssid";
10 + public static final String WEPKEYS = "wepkeys";
11 + public static final String _TABLENAME0 = "wifi";
12 + public static final String _CREATE0 = "create table if not exists "+_TABLENAME0+"("
13 + +ID+" integer not null primary key, "
14 + +SSID+" text not null , "
15 + +BSSID + " text not null,"
16 + +WEPKEYS + " text);";
17 + }
18 +}