Skip to content

Commit

Permalink
Merge branch 'master' into android_production
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleVasya committed Mar 21, 2014
2 parents e4040d8 + f22c4a0 commit beecdfc
Show file tree
Hide file tree
Showing 44 changed files with 1,133 additions and 172 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ shell:
$(MANAGE) shell

test:
TESTING=1 $(MANAGE) test --noinput $(TEST_OPTIONS)
TESTING=1 $(TEST) --noinput $(TEST_OPTIONS)

testone:
$(TEST) $(MANAGE) test $(filter-out $@,$(MAKECMDGOALS))
$(TEST) $(filter-out $@,$(MAKECMDGOALS))

clean:
@echo Cleaning up...
Expand Down
1 change: 1 addition & 0 deletions Makefile.def.buildbot
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ BIND_PORT?=8000
MAILSERVER_PORT?=1025
DJANGO_SETTINGS=p2psafety.settings
MANAGE= DJANGO_SETTINGS_MODULE=$(DJANGO_SETTINGS) python p2psafety_django/manage.py
TEST= DJANGO_SETTINGS_MODULE=$(DJANGO_SETTINGS).test python $(PROJECT_DIR)/manage.py test
8 changes: 8 additions & 0 deletions p2psafety-android/p2psafety/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<uses-feature
android:glEsVersion="0x00020000"
Expand Down Expand Up @@ -72,6 +73,7 @@
android:anyDensity="true" />

<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
Expand Down Expand Up @@ -114,6 +116,12 @@
android:resource="@xml/wprovider"/>
</receiver>

<receiver android:name=".BootCompletedReceiver" android:enabled="true" android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>

<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/app_id" />
Expand Down
1 change: 1 addition & 0 deletions p2psafety-android/p2psafety/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies {

compile 'com.android.support:support-v4:19.0.0'
compile 'com.android.support:appcompat-v7:19.0.+'
compile "com.bugsense.trace:bugsense:3.6"

compile 'com.google.android.gms:play-services:4.2.42'
compile 'com.google.code.gson:gson:2.2.4'
Expand Down
2 changes: 2 additions & 0 deletions p2psafety-android/p2psafety/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

<string name="app_name">SOSMessage</string>

<string name="bugsense_key">46e31f4f</string>

<string name="action_settings">Settings</string>
<string-array name="items_array">
<item>Phones</item>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ua.p2psafety;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import ua.p2psafety.services.PowerButtonService;
import ua.p2psafety.services.XmppService;

/**
* Created by Taras Melon on 14.03.14.
*/
public class BootCompletedReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
context.startService(new Intent(context, PowerButtonService.class));
context.startService(new Intent(context, XmppService.class));
}
}
53 changes: 53 additions & 0 deletions p2psafety-android/p2psafety/src/ua/p2psafety/MyApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package ua.p2psafety;

import android.app.Application;

import com.bugsense.trace.BugSenseHandler;

import ua.p2psafety.data.Prefs;
import ua.p2psafety.util.Logs;
import ua.p2psafety.util.Utils;

/**
* Created by Taras Melon on 14.03.14.
*/
public class MyApplication extends Application {

private static Logs mLogs;

@Override
public void onCreate() {
super.onCreate();
BugSenseHandler.initAndStartSession(this, getString(R.string.bugsense_key));

if (Utils.isServerAuthenticated(this))
{
if (Utils.isFbAuthenticated(this))
{
String uid = Prefs.getUserIdentifier(this);
if (uid != null)
{
Utils.putUidToBugSense(uid);
}
else
{
Utils.getFbUserInfo(this);
}
}
else
{
BugSenseHandler.setUserIdentifier(Prefs.getApiUsername(this));
}
}

mLogs = new Logs(this);

Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
mLogs.error("UNCAUGHT EXCEPTION!!!", ex);
System.exit(0);
}
});
}
}
32 changes: 26 additions & 6 deletions p2psafety-android/p2psafety/src/ua/p2psafety/SosActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
Expand Down Expand Up @@ -36,6 +37,7 @@ public class SosActivity extends ActionBarActivity {

private UiLifecycleHelper mUiHelper;
public static Logs mLogs;
private EventManager mEventManager;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -47,17 +49,20 @@ public void onCreate(Bundle savedInstanceState) {
mUiHelper = new UiLifecycleHelper(this, null);
mUiHelper.onCreate(savedInstanceState);

mEventManager = EventManager.getInstance(this);

mLogs.info("SosActiviy. onCreate. Initiating NetworkManager");
NetworkManager.init(this);
mLogs.info("SosActiviy. onCreate. Starting PowerButtonService");
startService(new Intent(this, PowerButtonService.class));
startService(new Intent(this, LocationService.class));
if (!Utils.isServiceRunning(this, XmppService.class) &&
Utils.isServerAuthenticated(this) &&
!EventManager.getInstance(this).isEventActive())
!mEventManager.isEventActive())
{
startService(new Intent(this, XmppService.class));
}
Prefs.setProgramRunning(true, this);

}

@Override
Expand All @@ -70,6 +75,12 @@ public void onResume() {
showErrorDialog(result);
}

if (!(mEventManager.isEventActive() || mEventManager.isSosStarted()) &&
!Utils.isServiceRunning(this, LocationService.class))
{
startService(new Intent(this, LocationService.class));
}

Fragment fragment;

// normal start
Expand Down Expand Up @@ -129,6 +140,12 @@ public void onPause() {
super.onPause();
mLogs.info("SosActiviy.onPause");
mUiHelper.onPause();

if (!(mEventManager.isEventActive() || mEventManager.isSosStarted())
&& Utils.isServiceRunning(this, LocationService.class))
{
stopService(new Intent(this, LocationService.class));
}
}

@Override
Expand All @@ -138,6 +155,7 @@ public void onDestroy() {
mLogs.info("\n\n\n==========================\n==============================");
mUiHelper.onDestroy();
mLogs.close();
Prefs.setProgramRunning(false, this);
}

@Override
Expand All @@ -160,9 +178,8 @@ public void onBackPressed() {
protected void onStop() {
super.onStop();

if (!(Utils.isServerAuthenticated(this) &&
EventManager.getInstance(this).getEvent() != null &&
EventManager.getInstance(this).isEventActive()))
if (!(mEventManager.isEventActive() || mEventManager.isSosStarted())
&& Utils.isServiceRunning(this, LocationService.class))
{
stopService(new Intent(this, LocationService.class));
}
Expand All @@ -172,8 +189,11 @@ protected void onStop() {
protected void onStart() {
super.onStart();

if (!EventManager.getInstance(this).isSosStarted())
if (!((mEventManager.isEventActive() || mEventManager.isSosStarted())) &&
!Utils.isServiceRunning(this, LocationService.class))
{
startService(new Intent(this, LocationService.class));
}
}

@Override
Expand Down
50 changes: 44 additions & 6 deletions p2psafety-android/p2psafety/src/ua/p2psafety/data/Prefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import android.content.Context;
import android.content.SharedPreferences;

import ua.p2psafety.json.Event;
import ua.p2psafety.R;
import ua.p2psafety.json.Event;
import ua.p2psafety.json.User;

/**
Expand All @@ -30,6 +30,10 @@ public class Prefs {
private static final String IS_SUPPORTER_MODE = "IS_SUPPORTER_MODE";
private static final String SUPPORT_URL = "SUPPORT_URL";

private static final String USER_IDENTIFIER = "USER_IDENTIFIER";

private static final String IS_PROGRAM_RUNNING = "IS_PROGRAM_RUNNING";

private static SharedPreferences getPrefs(Context context) {
return context.getSharedPreferences("MobileExchange", 0);
}
Expand Down Expand Up @@ -62,6 +66,14 @@ public static void putMediaRecordLength(Context context, long val) {
getPrefs(context).edit().putLong(MEDIA_RECORD_LENGTH, val).commit();
}

public static String getUserIdentifier(Context context) {
return getPrefs(context).getString(USER_IDENTIFIER, null);
}

public static void putUserIdentifier(Context context, String uid) {
getPrefs(context).edit().putString(USER_IDENTIFIER, uid).commit();
}

public static void putSosStarted(Context context, boolean val) {
getPrefs(context).edit().putBoolean(SOS_STARTED_KEY, val).commit();
}
Expand Down Expand Up @@ -164,6 +176,15 @@ public static void putEvent(Context context, Event event) {
.commit();

putUser(context, event.getUser());
} else {
getPrefs(context).edit()
.putString(EVENT_ID, null)
.putString(EVENT_KEY, null)
.putString(EVENT_STATUS, null)
.putString(EVENT_URI, null)
.commit();

putUser(context, null);
}
}

Expand Down Expand Up @@ -198,11 +219,19 @@ public static Event getEvent(Context context) {
private static final String USER_URI = "USER_URI";

private static void putUser(Context context, User user) {
getPrefs(context).edit()
.putString(USER_ID, user.getId())
.putString(USER_FULL_NAME, user.getUsername())
.putString(USER_URI, user.getUri())
.commit();
if (user != null) {
getPrefs(context).edit()
.putString(USER_ID, user.getId())
.putString(USER_FULL_NAME, user.getUsername())
.putString(USER_URI, user.getUri())
.commit();
} else {
getPrefs(context).edit()
.putString(USER_ID, null)
.putString(USER_FULL_NAME, null)
.putString(USER_URI, null)
.commit();
}
}

private static User getUser(Context context) {
Expand All @@ -224,4 +253,13 @@ private static User getUser(Context context) {

return user;
}

public static boolean isProgramRunning(Context context) {
return getPrefs(context).getBoolean(IS_PROGRAM_RUNNING, false);
}

public static void setProgramRunning(boolean val, Context context)
{
getPrefs(context).edit().putBoolean(IS_PROGRAM_RUNNING, val).commit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,12 @@ public void run() {
Utils.setLoading(mActivity, false);
//mActivity.onBackPressed();
if (true) { // TODO: find out what is supposed to be here
EventManager.getInstance(mActivity).getEvent().setType(Event.TYPE_SUPPORT);
EventManager.getInstance(mActivity).getEvent().setStatus(Event.STATUS_ACTIVE);
try {
EventManager.getInstance(mActivity).getEvent().setType(Event.TYPE_SUPPORT);
EventManager.getInstance(mActivity).getEvent().setStatus(Event.STATUS_ACTIVE);
} catch (Exception e) {
// should never happen
}
XmppService.processing_event = false;

// open Supporter screen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,24 +185,29 @@ public void onResume() {
mSosBtn.setText(getString(R.string.sos));
}

if (EventManager.getInstance(mActivity).getEvent() == null
&& Utils.isServerAuthenticated(mActivity))
{
mLogs.info("SendMessageFragment.onResume() No event, trying to create one");
Utils.setLoading(mActivity, true);
NetworkManager.createEvent(mActivity,
new NetworkManager.DeliverResultRunnable<Event>() {
@Override
public void deliver(Event event) {
mLogs.info("SendMessageFragment.onResume() event created: " +
event.getId()); // TODO: make event.toString()
EventManager.getInstance(mActivity).setEvent(event);
Utils.setLoading(mActivity, false);
}
});
try { EventManager.getInstance(mActivity).getEvent(); }
catch (Exception e) {
if (Utils.isServerAuthenticated(mActivity)){
mLogs.info("SendMessageFragment.onResume() No event, trying to create one");
Utils.setLoading(mActivity, true);
NetworkManager.createEvent(mActivity,
new NetworkManager.DeliverResultRunnable<Event>() {
@Override
public void deliver(Event event) {
//sometimes event is null :\
if (event != null)
{
mLogs.info("SendMessageFragment.onResume() event created: " +
event.getId()); // TODO: make event.toString()
EventManager.getInstance(mActivity).setEvent(event);
}
Utils.setLoading(mActivity, false);
}
});

//NetworkManager.getEvents(mActivity, null);
}
//NetworkManager.getEvents(mActivity, null);
}
}
}

// builds dialog with password prompt
Expand Down
Loading

0 comments on commit beecdfc

Please sign in to comment.