Skip to content

Commit 3ab60de

Browse files
committed
Default Location based on Mobile Country Code (MCC)
Map Viewer will now attempt a 3 step process to determine where to initially display the map: 1. Last location held in the location tracking database, 2. Last known location held by the device from either GPS or Network location service 3. **NEW** Based on current MCC the Map Viewer will move to the Capital City based on the MCC The default locations are provided through the default_mcc_locations.csv file which is found in the app/src/main/assets folder which lists Country, Mcc, Longitude and Latitude. These details are held within a database table and populated whenever the database is upgraded. This detail can also be viewed through the database viewer.
1 parent d94beca commit 3ab60de

File tree

10 files changed

+474
-37
lines changed

10 files changed

+474
-37
lines changed

app/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ android {
1818
keyAlias 'androiddebugkey'
1919
}
2020
}
21+
sourceSets {
22+
main {
23+
assets.srcDirs = ['src/main/assets']
24+
}
25+
}
26+
27+
2128
}
2229

2330
dependencies {
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
Country,Mcc,Longitude,Latitude
2+
Afghanistan,412,69.1833,34.5167
3+
Albania,276,19.8189,41.3275
4+
Algeria,603,3.05056,36.7631
5+
Andorra,213,1.51667,42.5
6+
Angola,631,13.2344,-8.83833
7+
Anguilla,365,-63.05,18.2167
8+
Antigua And Barbuda,344,-61.85,17.1167
9+
Argentina,722,-58.6725,-34.5875
10+
Armenia,283,44.5,40.1833
11+
Aruba,363,-70.0333,12.5167
12+
Australia,505,149.217,-35.2833
13+
Austria,232,16.3667,48.2
14+
Bahamas,364,-77.35,25.0833
15+
Bahrain,426,50.5831,26.2361
16+
Bangladesh,470,90.4086,23.7231
17+
Barbados,342,-59.6167,13.1
18+
Belarus,257,27.5667,53.9
19+
Belgium,206,4.33333,50.8333
20+
Belize,702,-88.7667,17.25
21+
Benin,616,2.61667,6.48333
22+
Bermuda,350,-64.7839,32.2942
23+
Bolivia,736,-65.2592,-19.0431
24+
Bosnia And Herzegovina,218,18.3833,43.85
25+
Botswana,652,25.9119,-24.6464
26+
Brazil,724,-44.4308,-16.2119
27+
British Virgin Islands,348,-64.6167,18.4167
28+
Brunei,528,114.933,4.88333
29+
Bulgaria,284,23.3167,42.6833
30+
Burkina Faso,613,-1.52472,12.3703
31+
Burundi,642,29.3667,-3.37778
32+
Cambodia,456,104.917,11.55
33+
Cameroon,624,11.5167,3.86667
34+
Canada,302,-75.7,45.4167
35+
Cape Verde,625,-23.5167,14.9167
36+
Cayman Islands,346,-81.3833,19.3
37+
Central African Republic,623,18.5833,4.36667
38+
Chad,622,15.05,12.1167
39+
Chile,730,-70.6667,-33.45
40+
China,460,116.388,39.9289
41+
Colombia,732,-74.0833,4.6
42+
Comoros,654,43.2403,-11.7042
43+
Congo,629,15.2847,-4.25917
44+
Cook Islands,548,-159.767,-21.2
45+
Costa Rica,712,-84.0833,9.93333
46+
Cote Divoire,612,-5.28333,6.81667
47+
Croatia,219,16,45.8
48+
Cuba,368,-82.3642,23.1319
49+
Cyprus,280,33.3667,35.1667
50+
Czech Republic,230,14.4667,50.0833
51+
Denmark,238,12.5833,55.6667
52+
Djibouti,638,43.1481,11.595
53+
Dominica,366,-61.4,15.3
54+
Dominican Republic,370,-69.9,18.4667
55+
Ecuador,740,-78.5,-0.216667
56+
Egypt,602,31.25,30.05
57+
El Salvador,706,-89.2,13.7
58+
Equatorial Guinea,627,8.66667,3.35
59+
Estonia,248,24.7281,59.4339
60+
Ethiopia,636,38.7,9.03333
61+
Faroe Islands,288,-6.76667,62.0167
62+
Fiji,542,178.417,-18.1333
63+
Finland,244,24.9342,60.1756
64+
France,208,2.33333,48.8667
65+
French Guiana,742,-52.3333,4.93333
66+
French Polynesia,547,-149.567,-17.5333
67+
Gabon,628,9.45,0.383333
68+
Gambia,607,-16.5775,13.4531
69+
Georgia,282,44.7844,41.7178
70+
Germany,262,13.4,52.5167
71+
Ghana,620,-0.216667,5.55
72+
Gibraltar,266,-5.35,36.1333
73+
Greece,202,23.7333,37.9833
74+
Greenland,290,-51.75,64.1833
75+
Grenada,352,-61.0833,14.6
76+
Guatemala,704,-90.5167,14.6333
77+
Guernsey,234,-2.53333,49.45
78+
Guinea,611,-13.7122,9.50917
79+
Guinea-Bissau,632,-15.5833,11.85
80+
Guyana,738,-58.1667,6.8
81+
Haiti,372,-72.335,18.5392
82+
Honduras,708,-87.2167,14.1
83+
Hong Kong,454,114.15,22.2833
84+
Hungary,216,19.0833,47.5
85+
Iceland,274,-21.95,64.15
86+
India,404,77.2,28.6
87+
Indonesia,510,106.822,-6.16889
88+
Iran,432,51.4244,35.6719
89+
Iraq,418,44.3939,33.3386
90+
Ireland,272,-6.24889,53.3331
91+
Isle Of Man,243,-4.48333,54.15
92+
Italy,222,12.4833,41.9
93+
Jamaica,338,-76.8,18
94+
Japan,440,139.753,35.6861
95+
Jersey,234,-2.1,49.1833
96+
Jordan,416,35.9333,31.95
97+
Kazakhstan,401,71.4278,51.1811
98+
Kenya,639,36.8167,-1.28333
99+
Kiribati,545,169.533,-0.883333
100+
Kuwait,419,47.9783,29.3697
101+
Laos,457,102.6,17.9667
102+
Latvia,247,24.1,56.95
103+
Lebanon,415,35.5097,33.8719
104+
Lesotho,651,27.4833,-29.3167
105+
Liberia,618,-10.8047,6.31056
106+
Libya,606,13.18,32.8925
107+
Liechtenstein,295,9.51667,47.1333
108+
Lithuania,246,25.3167,54.6833
109+
Luxembourg,270,6.13,49.6117
110+
Macau,455,113.55,22.2
111+
Macedonia,294,21.4333,42
112+
Madagascar,646,47.5167,-18.9167
113+
Malawi,650,33.7833,-13.9833
114+
Malaysia,502,101.7,3.16667
115+
Maldives,472,45.2272,-12.7794
116+
Mali,610,-8,12.65
117+
Malta,278,14.5147,35.8997
118+
Marshall Islands,551,171.383,7.1
119+
Mauritania,609,-15.95,18.1
120+
Mauritius,617,57.5,-20.1667
121+
Mexico,334,-99.1386,19.4342
122+
Micronesia,550,158.15,6.91667
123+
Moldova,259,28.8578,47.005
124+
Mongolia,428,106.917,47.9167
125+
Montserrat,354,-62.2167,16.7
126+
Morocco,604,-6.83333,34.0333
127+
Mozambique,643,32.5892,-25.9653
128+
Namibia,649,17.0836,-22.57
129+
Nepal,429,85.3167,27.7167
130+
Netherlands,204,4.3,52.0833
131+
New Caledonia,546,166.45,-22.2667
132+
New Zealand,530,174.783,-41.3
133+
Nicaragua,710,-86.2683,12.1508
134+
Niger,614,2.11667,13.5167
135+
Nigeria,621,7.53333,9.08333
136+
Niue,555,-169.917,-19.0167
137+
North Korea,467,125.755,39.0194
138+
Norway,242,10.75,59.9167
139+
Oman,422,58.5933,23.6133
140+
Pakistan,410,73.1667,33.7
141+
Palau,552,134.471,7.34056
142+
Panama,714,-79.5333,8.96667
143+
Papua New Guinea,537,147.193,-9.46472
144+
Paraguay,744,-57.6667,-25.2667
145+
Peru,716,-77.05,-12.05
146+
Philippines,515,121,14.5833
147+
Poland,260,21,52.25
148+
Portugal,268,-9.13333,38.7167
149+
Qatar,427,51.5333,25.2867
150+
Reunion,647,55.4667,-20.8667
151+
Romania,226,26.1,44.4333
152+
Russia,250,37.6156,55.7522
153+
Rwanda,635,30.0606,-1.95361
154+
Saint Kitts And Nevis,356,-62.7167,17.3
155+
Saint Lucia,358,-61,14
156+
Saint Pierre And Miquelon,308,-56.1833,46.7667
157+
Saint Vincent And The Grenadines,360,-61.2167,13.1333
158+
Samoa,549,-171.733,-13.8333
159+
Sao Tome And Principe,626,6.73333,0.333333
160+
Saudi Arabia,420,46.7728,24.6408
161+
Senegal,608,-17.4333,14.6667
162+
Seychelles,633,55.45,-4.61667
163+
Sierra Leone,619,-13.2342,8.49
164+
Singapore,525,103.856,1.29306
165+
Slovakia,231,17.1167,48.15
166+
Solomon Islands,540,159.95,-9.43333
167+
Somalia,637,45.3667,2.06667
168+
South Africa,655,18.4167,-33.9167
169+
South Korea,450,127,37.5664
170+
Spain,214,-3.68333,40.4
171+
Sri Lanka,413,79.9083,6.90278
172+
Sudan,634,32.5342,15.5881
173+
Suriname,746,-55.1667,5.83333
174+
Swaziland,653,31.1333,-26.3167
175+
Sweden,240,18.05,59.3333
176+
Switzerland,228,7.46667,46.9167
177+
Syria,417,36.3,33.5
178+
Taiwan,466,121.45,25.0167
179+
Tajikistan,436,68.7739,38.56
180+
Tanzania,640,39.2833,-6.8
181+
Thailand,520,100.517,13.75
182+
Togo,615,1.22278,6.13194
183+
Tonga,539,-175.2,-21.1333
184+
Trinidad And Tobago,374,-61.5167,10.65
185+
Tunisia,605,10.1797,36.8028
186+
Turkey,286,32.8642,39.935
187+
Turkmenistan,438,58.3833,37.95
188+
Turks And Caicos Islands,376,-71.1333,21.4667
189+
Tuvalu,553,179.217,-8.51667
190+
Uganda,641,32.5833,0.316667
191+
Ukraine,255,30.5167,50.4333
192+
United Arab Emirates,424,54.3667,24.4667
193+
United Kingdom,235,-0.116667,51.5
194+
Uruguay,748,-56.1708,-34.8581
195+
Uzbekistan,434,69.25,41.3167
196+
Vanuatu,541,168.317,-17.7333
197+
Venezuela,734,-66.9167,10.5
198+
Vietnam,452,105.85,21.0333
199+
Yemen,421,44.2067,15.3547
200+
Yugoslavia,220,20.4656,44.8119
201+
Zambia,645,28.2833,-15.4167
202+
Zimbabwe,648,31.05,-17.8333

app/src/main/java/com/SecUpwN/AIMSICD/AIMSICDDbAdapter.java

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.app.AlertDialog;
44
import android.content.ContentValues;
55
import android.content.Context;
6+
import android.content.res.AssetManager;
67
import android.database.Cursor;
78
import android.database.SQLException;
89
import android.database.sqlite.SQLiteDatabase;
@@ -11,9 +12,13 @@
1112
import android.util.Log;
1213

1314
import java.io.File;
15+
import java.io.FileOutputStream;
16+
import java.io.FileReader;
1417
import java.io.FileWriter;
15-
import java.util.ArrayList;
18+
import java.io.InputStream;
19+
import java.util.List;
1620

21+
import au.com.bytecode.opencsv.CSVReader;
1722
import au.com.bytecode.opencsv.CSVWriter;
1823

1924
public class AIMSICDDbAdapter {
@@ -23,12 +28,13 @@ public class AIMSICDDbAdapter {
2328
private final DbHelper mDbHelper;
2429
private SQLiteDatabase mDb;
2530
private Context mContext;
26-
private static final int DATABASE_VERSION = 2;
31+
private static final int DATABASE_VERSION = 3;
2732
private static final String COLUMN_ID = "_id";
2833
private final String LOCATION_TABLE = "locationinfo";
2934
private final String CELL_TABLE = "cellinfo";
3035
private final String SIGNAL_TABLE = "signalinfo";
3136
private final String OPENCELLID_TABLE = "opencellid";
37+
private final String DEFAULT_MCC_TABLE = "defaultlocation";
3238
private final String DB_NAME = "myCellInfo";
3339
private final String FOLDER = Environment.getExternalStorageDirectory() + "/AIMSICD/";
3440

@@ -83,6 +89,14 @@ public void close() {
8389
"Mnc INTEGER, Lac INTEGER, CellID INTEGER, AvgSigStr INTEGER, Samples INTEGER, " +
8490
"Timestamp TIMESTAMP NOT NULL DEFAULT current_timestamp);";
8591

92+
/**
93+
* Default MCC Location Database
94+
*/
95+
private final String DEFAULT_MCC_DATABASE_CREATE = "create table " +
96+
DEFAULT_MCC_TABLE + " (" + COLUMN_ID +
97+
" integer primary key autoincrement, Country VARCHAR, Mcc INTEGER, "
98+
+ "Lat VARCHAR, Lng VARCHAR);";
99+
86100
/**
87101
* Inserts Cell Details into Database
88102
*
@@ -231,6 +245,14 @@ public Cursor getOpenCellIDData() {
231245
null,null,null,null,null);
232246
}
233247

248+
/**
249+
* Returns Default MCC Locations database contents
250+
*/
251+
public Cursor getDefaultMccLocationData() {
252+
return mDb.query(DEFAULT_MCC_TABLE, new String[] {"Country", "Mcc", "Lat", "Lng"},
253+
null,null,null,null,null);
254+
}
255+
234256
/**
235257
* Checks to see if Location already exists in database
236258
*/
@@ -271,6 +293,67 @@ public boolean cellSignalExists(int cellID) {
271293
return cursor.getCount()>0;
272294
}
273295

296+
public double[] getDefaultLocation(int mcc) {
297+
double[] loc = new double[2];
298+
299+
Cursor cursor = mDb.rawQuery("SELECT Lat, Lng FROM " + DEFAULT_MCC_TABLE + " WHERE Mcc = " +
300+
mcc, null);
301+
302+
if (cursor.moveToFirst()) {
303+
loc[0] = Double.parseDouble(cursor.getString(0));
304+
loc[1] = Double.parseDouble(cursor.getString(1));
305+
} else {
306+
loc[0] = 0.0;
307+
loc[1] = 0.0;
308+
}
309+
310+
return loc;
311+
}
312+
313+
/**
314+
* Populates the Default Mcc Location table using the CSV file found in the
315+
* application ASSETS folder
316+
*/
317+
private void populateDefaultMCC(SQLiteDatabase db) {
318+
AssetManager mngr = mContext.getAssets();
319+
InputStream csvDefaultMcc;
320+
FileOutputStream fout;
321+
322+
try {
323+
csvDefaultMcc = mngr.open("default_mcc_locations.csv");
324+
File tempfile = File.createTempFile("tempFile", ".tmp");
325+
tempfile.deleteOnExit();
326+
327+
fout = new FileOutputStream(tempfile);
328+
byte[] buf = new byte[1024];
329+
int len;
330+
while ((len = csvDefaultMcc.read(buf)) != -1) {
331+
fout.write(buf, 0, len);
332+
}
333+
fout.close();
334+
csvDefaultMcc.close();
335+
336+
CSVReader csvReader = new CSVReader(new FileReader(tempfile));
337+
List<String[]> csvMcc = csvReader.readAll();
338+
//Populate Content Values for Insert or Update
339+
ContentValues defaultMccValues = new ContentValues();
340+
341+
for (int i=1; i < csvMcc.size(); i++)
342+
{
343+
defaultMccValues.put("Country", csvMcc.get(i)[0]);
344+
defaultMccValues.put("Mcc", csvMcc.get(i)[1]);
345+
defaultMccValues.put("Lng", csvMcc.get(i)[2]);
346+
defaultMccValues.put("Lat", csvMcc.get(i)[3]);
347+
348+
db.insert(DEFAULT_MCC_TABLE, null, defaultMccValues);
349+
}
350+
351+
352+
} catch (Exception e) {
353+
Log.e (TAG, "Error parsing OpenCellID data - " + e);
354+
}
355+
}
356+
274357
/**
275358
* Exports the database tables to CSV files
276359
*/
@@ -279,6 +362,7 @@ public void exportDB () {
279362
export(LOCATION_TABLE);
280363
export(CELL_TABLE);
281364
export(SIGNAL_TABLE);
365+
export(OPENCELLID_TABLE);
282366
final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
283367
builder.setTitle(R.string.database_export_successful)
284368
.setMessage("Database tables exported succesfully to:\n" + FOLDER);
@@ -288,6 +372,11 @@ public void exportDB () {
288372
}
289373
}
290374

375+
/**
376+
* Exports the database tables to CSV files
377+
*
378+
* @param tableName String representing table name to export
379+
*/
291380
private void export(String tableName) {
292381
Log.i(TAG, "exporting database - " + DB_NAME);
293382

@@ -339,6 +428,8 @@ public void onCreate(SQLiteDatabase database) {
339428
database.execSQL(CELL_DATABASE_CREATE);
340429
database.execSQL(SIG_DATABASE_CREATE);
341430
database.execSQL(OPENCELLID_DATABASE_CREATE);
431+
database.execSQL(DEFAULT_MCC_DATABASE_CREATE);
432+
populateDefaultMCC(database);
342433
}
343434

344435
@Override
@@ -351,6 +442,8 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
351442
db.execSQL("DROP TABLE IF EXISTS " + CELL_TABLE);
352443
db.execSQL("DROP TABLE IF EXISTS " + SIGNAL_TABLE);
353444
db.execSQL("DROP TABLE IF EXISTS " + OPENCELLID_TABLE);
445+
db.execSQL("DROP TABLE IF EXISTS " + DEFAULT_MCC_TABLE);
446+
354447
onCreate(db);
355448
}
356449
}

0 commit comments

Comments
 (0)