Skip to content

Commit

Permalink
Merge pull request #167 from tobykurien/master
Browse files Browse the repository at this point in the history
Updates and Fixes for #166
  • Loading branch information
SecUpwN committed Oct 26, 2014
2 parents 68c793f + 230e292 commit b06b791
Show file tree
Hide file tree
Showing 18 changed files with 101 additions and 12 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_LOGS" />

<application
android:allowBackup="false"
Expand Down
34 changes: 34 additions & 0 deletions app/src/main/java/com/SecUpwN/AIMSICD/AIMSICD.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -354,7 +358,35 @@ void selectItem(int position) {
Helpers.sendMsg(mContext,
"No OpenCellID API Key detected! \nPlease enter your key in settings first.");
}
} else if (selectedItem.getId() == 305) {
new Thread() {
@Override
public void run() {
// send bug log
// TODO - clear log using 'logcat -c' on app startup
try {
Process process = Runtime.getRuntime().exec("logcat -d");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));

StringBuilder log = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
log.append(line);
}

// show a share intent
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
intent.putExtra(Intent.EXTRA_EMAIL, "some@email.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "AIMSICD Error log");
intent.putExtra(Intent.EXTRA_TEXT, log.toString());
startActivity(Intent.createChooser(intent, "Send error log"));
} catch (IOException e) {
Log.e("main", "Error reading logs", e);
}
}
}.start();
} else if (selectedItem.getId() == 304) {
finish();
}
Expand Down Expand Up @@ -445,6 +477,8 @@ public DrawerMenuActivityConfiguration getNavDrawerConfiguration() {
(302, getString(R.string.cell_lookup), "stat_sys_download_anim0", false, this));
menu.add(DrawerMenuItem.create
(303, getString(R.string.about_aimsicd), "ic_action_about", true, this));
menu.add(DrawerMenuItem.create
(305, getString(R.string.send_logs), "ic_action_computer", false, this));
menu.add(DrawerMenuItem.create
(304, getString(R.string.quit), "ic_action_remove", false, this));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.database.Cursor;
import android.location.Location;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.LocalBroadcastManager;
import android.telephony.CellInfo;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Menu;
Expand Down Expand Up @@ -83,6 +85,18 @@ public class MapViewerOsmDroid extends FragmentActivity implements OnSharedPrefe
private MyLocationNewOverlay mMyLocationOverlay;
private CellTowerItemizedOverlay mOpenCellIdOverlay;

private PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
@Override
public void onServiceStateChanged(ServiceState serviceState) {
loadEntries();
}

@Override
public void onCellInfoChanged(List<CellInfo> cellInfo) {
loadEntries();
}
};

/**
* Called when the activity is first created.
*/
Expand All @@ -100,6 +114,10 @@ public void onCreate(Bundle savedInstanceState) {
// Bind to LocalService
Intent intent = new Intent(mContext, AimsicdService.class);
mContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);

TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CELL_LOCATION |
PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
}

@Override
Expand Down Expand Up @@ -134,6 +152,9 @@ protected void onDestroy() {
mBound = false;
}

TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);

LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
}

Expand Down Expand Up @@ -363,7 +384,7 @@ protected GeoPoint doInBackground(Void... voids) {
new MarkerData("" + cellID, "" + loc.getLatitude(),"" +
loc.getLongitude(), "" + lac, "" + mcc, "" + mnc, "", false));

ovm.setMarker(getResources().getDrawable(R.drawable.ic_map_pin_green));
ovm.setMarker(getResources().getDrawable(R.drawable.ic_map_pin_blue));
items.add(ovm);


Expand Down Expand Up @@ -410,6 +431,25 @@ public void run() {
c.close();
mDbHelper.close();

// plot neighbouring cells
while (mAimsicdService == null) try { Thread.sleep(100); } catch (Exception e) {};
List<Cell> nc = mAimsicdService.getCellTracker().updateNeighbouringCells();
for (Cell cell : nc) {
try {
loc = new GeoPoint(cell.getLat(), cell.getLon());
CellTowerOverlayItem ovm = new CellTowerOverlayItem("CellID - " + cell.getCID(),
"",
loc,
new MarkerData("" + cell.getCID(), "" + loc.getLatitude(),"" +
loc.getLongitude(), "" + cell.getLAC(), "" + cell.getMCC(), "" + cell.getMNC(), "", false));

ovm.setMarker(getResources().getDrawable(R.drawable.ic_map_pin_orange));
items.add(ovm);
} catch (Exception e) {
Log.e("map", "Error plotting neightbouring cells", e);
}
}

mMap.getOverlays().remove(mOpenCellIdOverlay);
mOpenCellIdOverlay.addItems(items);
mMap.getOverlays().add(mOpenCellIdOverlay);
Expand Down Expand Up @@ -475,9 +515,9 @@ private void loadOpenCellIDMarkers() {
"",
location,
new MarkerData("" + cellID, "" + location.getLatitude(),"" +
location.getLongitude(), "" + lac, "", "", "", false));
location.getLongitude(), "" + lac, "" + mcc, "" + mnc, "" + samples, false));

ovm.setMarker(getResources().getDrawable(R.drawable.ic_map_pin_blue));
ovm.setMarker(getResources().getDrawable(R.drawable.ic_map_pin_green));
items.add(ovm);
} while (c.moveToNext());
}
Expand Down
26 changes: 18 additions & 8 deletions app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@

package com.SecUpwN.AIMSICD.utils;

import com.SecUpwN.AIMSICD.R;
import com.SecUpwN.AIMSICD.service.AimsicdService;
import com.SecUpwN.AIMSICD.service.CellTracker;

import android.app.AlertDialog;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Environment;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;

import com.SecUpwN.AIMSICD.R;
import com.SecUpwN.AIMSICD.service.CellTracker;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
Expand All @@ -57,9 +57,14 @@ public class Helpers {
* @param context Application Context
* @param msg Message to send
*/
public static void msgLong(Context context, String msg) {
public static void msgLong(final Context context, final String msg) {
if (context != null && msg != null) {
Toast.makeText(context, msg.trim(), Toast.LENGTH_LONG).show();
new Handler(context.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, msg.trim(), Toast.LENGTH_LONG).show();
}
});
}
}

Expand All @@ -69,9 +74,14 @@ public static void msgLong(Context context, String msg) {
* @param context Application Context
* @param msg Message to send
*/
public static void msgShort(Context context, String msg) {
public static void msgShort(final Context context, final String msg) {
if (context != null && msg != null) {
Toast.makeText(context, msg.trim(), Toast.LENGTH_SHORT).show();
new Handler(context.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, msg.trim(), Toast.LENGTH_SHORT).show();
}
});
}
}

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/SecUpwN/AIMSICD/utils/RequestTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,13 @@ protected String doInBackground(String... commandString) {
try {
String error = Helpers
.convertStreamToString(urlConnection.getErrorStream());
Helpers.msgLong(mContext, "Download error: " + error);
Log.e("AIMSICD", "Download ocid data error: " + error);
} catch (Exception e) {
Helpers.msgLong(mContext, "Download error: " + e.getClass().getName() + " - " + e.getMessage());
Log.e("AIMSICD", "Download ocid - " + e);
}
return "Error";
} else {
total = urlConnection.getContentLength();
publishProgress(progress, total);
Expand Down
Binary file modified app/src/main/res/drawable-hdpi/ic_map_pin_green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_map_pin_orange.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_map_pin_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-mdpi/ic_map_pin_green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_map_pin_orange.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_map_pin_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-xhdpi/ic_map_pin_green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-xxhdpi/ic_map_pin_green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<string name="press_once_again_to_exit">Press again to exit.</string>
<string name="update_opencelldata">Update OpenCellID Data</string>
<string name="cell_lookup">Lookup Current Cell Details (OpenCellID)</string>
<string name="send_logs">Send bug log</string>

<string name="no_network_connection_title">No Internet Connection</string>
<string name="no_network_connection_message">Unable to download OpenCellID data without Internet
Expand Down

0 comments on commit b06b791

Please sign in to comment.