Skip to content

Commit

Permalink
Merge pull request #17 from lillialexis/52229
Browse files Browse the repository at this point in the history
[52229] Port the Bluetooth functionality from the Unlock demo to the Android RVI SDK
  • Loading branch information
lillialexis committed Nov 19, 2015
2 parents a169615 + 8333874 commit f4ae0b7
Show file tree
Hide file tree
Showing 16 changed files with 657 additions and 666 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/**
* Copyright (C) 2015, Jaguar Land Rover
*
* This program is licensed under the terms and conditions of the
* Mozilla Public License, version 2.0. The full text of the
* Mozilla Public License is at https://www.mozilla.org/MPL/2.0/
* Copyright (C) 2015, Jaguar Land Rover
*
* This program is licensed under the terms and conditions of the Mozilla Public License, version 2.0. The full text of the Mozilla Public License is at
* https://www.mozilla.org/MPL/2.0/
*/

package com.jaguarlandrover.auto.remote.vehicleentry;
Expand All @@ -24,44 +22,41 @@ public class BluetoothReceiver extends BroadcastReceiver
public static boolean BluetoothConnected;
private static final String TAG = "RVI";

public void onReceive(Context context, Intent intent)
{
public void onReceive(Context context, Intent intent) {

Log.d(TAG, "Bluetooth Intent Recieved");
//SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

String action = intent.getAction();
Log.d(TAG, "Bluetooth Called: Action: " + action);

if (action.equalsIgnoreCase("android.bluetooth.device.action.ACL_CONNECTED"))
{
if (action.equalsIgnoreCase("android.bluetooth.device.action.ACL_CONNECTED")) {
Log.d(TAG, "BLUETOOTH CONNECTED RECIEVED");
BluetoothConnected = true;

BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Log.d(TAG, "Device +"+device.getName()+" uu "+device.getUuids());
Log.d(TAG, "Device +" + device.getName() + " uu " + device.getUuids());

Parcelable[] uuidExtra =intent.getParcelableArrayExtra("android.bluetooth.device.extra.UUID");
if (BluetoothDevice.ACTION_UUID.equals(action)){
uuidExtra =intent.getParcelableArrayExtra("android.bluetooth.device.extra.UUID");
Parcelable[] uuidExtra = intent.getParcelableArrayExtra("android.bluetooth.device.extra.UUID");
if (BluetoothDevice.ACTION_UUID.equals(action)) {
uuidExtra = intent.getParcelableArrayExtra("android.bluetooth.device.extra.UUID");
}
Log.d(TAG,"SDP has no errors: = "+uuidExtra);
if( uuidExtra == null ) return;
Log.d(TAG, "SDP has no errors: = " + uuidExtra);
if (uuidExtra == null) return;
// if(found==false){
for(int i=0;i<uuidExtra.length;i++){
Log.d(TAG,"UUID: "+ uuidExtra[i]);
for (int i = 0; i < uuidExtra.length; i++) {
Log.d(TAG, "UUID: " + uuidExtra[i]);

if((uuidExtra[i].toString()).equals("00001101-0000-1000-8000-00805F9B34FB".toLowerCase())){
Log.d(TAG,"Match found in loop");
if ((uuidExtra[i].toString()).equals("00001101-0000-1000-8000-00805F9B34FB".toLowerCase())) {
Log.d(TAG, "Match found in loop");

}

}
//device.setPairingConfirmation(true);
}

if (action.equalsIgnoreCase("android.bluetooth.device.action.ACL_DISCONNECTED"))
{
if (action.equalsIgnoreCase("android.bluetooth.device.action.ACL_DISCONNECTED")) {
Log.d(TAG, "BLUETOOTH DISCONNECTED RECIEVED");
BluetoothConnected = false;
}
Expand All @@ -71,16 +66,16 @@ public void onReceive(Context context, Intent intent)
BluetoothAdapter.ERROR);
switch (state) {
case BluetoothAdapter.STATE_OFF:
Log.d(TAG,"Bluetooth off");
Log.d(TAG, "Bluetooth off");
Intent i = new Intent(context, RviService.class);
i.putExtra("bluetooth", state);
context.startService(i);
break;
case BluetoothAdapter.STATE_TURNING_OFF:
Log.d(TAG,"Turning Bluetooth off");
Log.d(TAG, "Turning Bluetooth off");
break;
case BluetoothAdapter.STATE_ON:
Log.d(TAG,"Bluetooth on");
Log.d(TAG, "Bluetooth on");
Intent j = new Intent(context, RviService.class);
j.putExtra("bluetooth", state);
context.startService(j);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/**
* Copyright (C) 2015, Jaguar Land Rover
*
* This program is licensed under the terms and conditions of the
* Mozilla Public License, version 2.0. The full text of the
* Mozilla Public License is at https://www.mozilla.org/MPL/2.0/
* Copyright (C) 2015, Jaguar Land Rover
*
* This program is licensed under the terms and conditions of the Mozilla Public License, version 2.0. The full text of the Mozilla Public License is at
* https://www.mozilla.org/MPL/2.0/
*/

package com.jaguarlandrover.auto.remote.vehicleentry;
Expand All @@ -16,7 +14,8 @@
import android.net.NetworkInfo;
import android.util.Log;

public class CloudReceiver extends BroadcastReceiver {
public class CloudReceiver extends BroadcastReceiver
{
private static final String TAG = "RVI";

@Override
Expand All @@ -25,13 +24,9 @@ public void onReceive(Context context, Intent intent) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
if (networkInfo == null || networkInfo.getDetailedState() == NetworkInfo.DetailedState.DISCONNECTED) {
// Wifi is disconnected
Log.i(TAG, "Network is disconnected: " + networkInfo);
} else if(networkInfo.getDetailedState() == NetworkInfo.DetailedState.CONNECTED) {
Log.i(TAG, "Network is connected: " + networkInfo+" type = "+networkInfo.getTypeName()+" : "+networkInfo.getSubtypeName());
// Intent i = new Intent(context, RviService.class);
// i.putExtra("networkinfo", networkInfo);
// context.startService(i);
} else if (networkInfo.getDetailedState() == NetworkInfo.DetailedState.CONNECTED) {
Log.i(TAG, "Network is connected: " + networkInfo + " type = " + networkInfo.getTypeName() + " : " + networkInfo.getSubtypeName());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.jaguarlandrover.auto.remote.vehicleentry;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright (c) 2015 Jaguar Land Rover.
*
* This program is licensed under the terms and conditions of the
* Mozilla Public License, version 2.0. The full text of the
* Mozilla Public License is at https://www.mozilla.org/MPL/2.0/
*
* File: FobParams.java
* Project: UnlockDemo
*
* Created by Lilli Szafranski on 11/16/15.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import com.google.gson.annotations.SerializedName;

public class FobParamsManager
{
private final static String TAG = "UnlockDemo:FobParams";

private static double lat = 0;
private static double lon = 0;

LocationManager mLocationManager = (LocationManager) UnlockApplication.getContext().getSystemService(Context.LOCATION_SERVICE);
private LocationListener mLocationListener = new LocationListener()
{
@Override
public void onLocationChanged(Location location) {
lat = location.getLatitude();
lon = location.getLongitude();

Log.d(TAG, "MY CURRENT LOCATION - Latitude = " + lat + " Longitude = " + lon);
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {

}

@Override
public void onProviderEnabled(String provider) {

}

@Override
public void onProviderDisabled(String provider) {

}
};

private static FobParamsManager ourInstance = new FobParamsManager();

private FobParamsManager() {
// mLocationManager = (LocationManager) UnlockApplication.getContext().getSystemService(Context.LOCATION_SERVICE);
}

public static void startUpdatingLocation() {
ourInstance.mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60, 1, ourInstance.mLocationListener);
}

public static void stopUpdatingLocation() {
ourInstance.mLocationManager.removeUpdates(ourInstance.mLocationListener);
}

static class FobParams
{
@SerializedName("latitude")
private double mLat = 0;

@SerializedName("longitude")
private double mLon = 0;

@SerializedName("username")
private String mUsername;

@SerializedName("vehicleVIN")
private String mVehicleVin;

public FobParams() {
UserCredentials userCredentials = ServerNode.getUserCredentials();
mLat = lat;
mLon = lon;
mUsername = userCredentials.getUserName();
mVehicleVin = userCredentials.getVehicleVin();
}
}

// public static FobParamsManager getSnapshot() {
// Log.d(TAG, "getSnapshot()");
// UserCredentials userCredentials = ServerNode.getUserCredentials();
// FobParamsManager copy = new FobParamsManager();
//
// copy.mLat = ourInstance.mLat;
// copy.mLon = ourInstance.mLon;
// copy.mUsername = userCredentials.getUserName();
// copy.mVehicleVin = userCredentials.getVehicleVin();
//
// return copy;
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "onCreate() Activity");

// sharedPref = PreferenceManager.getDefaultSharedPreferences(this);

handleExtra(getIntent());

keyCheck = new Handler();
Expand All @@ -54,7 +52,6 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_lock);
lock_fragment = (LockActivityFragment) getFragmentManager().findFragmentById(R.id.fragmentlock);
startRepeatingTask();
//doBindService();
}

Runnable StatusCheck = new Runnable()
Expand Down Expand Up @@ -191,8 +188,8 @@ public boolean onOptionsItemSelected(MenuItem item) {

@Override
public void onButtonCommand(String cmd) {
//TODO send to RVI service
RviService.service(cmd, LockActivity.this);
//RviService.triggerFobSignal(cmd, LockActivity.this);
VehicleNode.sendFobSignal(cmd);
}

public void keyUpdate(final UserCredentials userCredentials) {
Expand Down Expand Up @@ -234,7 +231,7 @@ public void keyShareCommand(String key) {
break;
case "keychange":
try {
ServerNode.requestRemoteCredentials();//RviService.requestAll(Request(), LockActivity.this);
ServerNode.requestRemoteCredentials();
requestProgress = ProgressDialog.show(LockActivity.this, "","Retrieving keys...",true);

requestProgress.setCancelable(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,32 +173,32 @@ public void onClick(View v) {
case R.id.lock:
Log.i(TAG, "LockBtn");
ed.putBoolean(LOCKED_LBL, true);
buttonListener.onButtonCommand("lock");
buttonListener.onButtonCommand(VehicleNode.FOB_SIGNAL_LOCK);
break;
case R.id.unlock:
Log.i(TAG, "UnlockBtn");
ed.putBoolean(LOCKED_LBL, false);
buttonListener.onButtonCommand("unlock");
buttonListener.onButtonCommand(VehicleNode.FOB_SIGNAL_UNLOCK);
break;
case R.id.trunk:
Log.i(TAG, "TrunkBtn");
ed.putBoolean("Gruka", false);
buttonListener.onButtonCommand("trunk");
buttonListener.onButtonCommand(VehicleNode.FOB_SIGNAL_TRUNK);
break;
case R.id.find:
Log.i(TAG, "FindBtn");
ed.putBoolean("77", false);
buttonListener.onButtonCommand("lights");
buttonListener.onButtonCommand(VehicleNode.FOB_SIGNAL_LIGHTS);
break;
case R.id.start:
Log.i(TAG, "StartBtn");
ed.putBoolean(STOPPED_LBL, true);
buttonListener.onButtonCommand("start");
buttonListener.onButtonCommand(VehicleNode.FOB_SIGNAL_START);
break;
case R.id.stop:
Log.i(TAG, "StopBtn");
ed.putBoolean(STOPPED_LBL, false);
buttonListener.onButtonCommand("stop");
buttonListener.onButtonCommand(VehicleNode.FOB_SIGNAL_STOP);
break;
case R.id.share:
Log.i(TAG, "ShareBtn");
Expand All @@ -216,7 +216,7 @@ public void onClick(View v) {
// isPanic = false;
//
// }
// buttonListener.onButtonCommand("panic");
// buttonListener.onButtonCommand(VehicleNode.FOB_SIGNAL_PANIC);
// Log.i(TAG, "PanicBtn swap 1 ");
// Handler handler = new Handler(Looper.getMainLooper());
// handler.postDelayed(new Runnable()
Expand Down
Loading

0 comments on commit f4ae0b7

Please sign in to comment.