mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-12 10:55:49 +01:00
Search & replace: use slf4j for logging instead of Logcat directly
For a start, use android-logger as backend. Needs a better configuration but no time right now. For file-logging we will use logback as slf4j-implementation.
This commit is contained in:
parent
6fab01a3c2
commit
9a26769c3e
@ -23,4 +23,5 @@ dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
compile 'com.android.support:appcompat-v7:21.0.3'
|
||||
compile 'com.android.support:support-v4:21.0.3'
|
||||
compile 'com.noveogroup.android:android-logger:1.3.5'
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ import android.widget.ListView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAppAdapter;
|
||||
|
||||
@ -23,6 +25,7 @@ import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAppAdapter;
|
||||
public class AppManagerActivity extends Activity {
|
||||
public static final String ACTION_REFRESH_APPLIST
|
||||
= "nodomain.freeyourgadget.gadgetbride.appmanager.action.refresh_applist";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AppManagerActivity.class);
|
||||
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
@ -47,7 +50,6 @@ public class AppManagerActivity extends Activity {
|
||||
}
|
||||
};
|
||||
final List<GBDeviceApp> appList = new ArrayList<>();
|
||||
private final String TAG = this.getClass().getSimpleName();
|
||||
private ListView appListView;
|
||||
private GBDeviceAppAdapter mGBDeviceAppAdapter;
|
||||
private GBDeviceApp selectedApp = null;
|
||||
|
@ -16,9 +16,11 @@ import android.os.IBinder;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.ContactsContract;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBDevice.State;
|
||||
import nodomain.freeyourgadget.gadgetbridge.miband.MiBandSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.pebble.PebbleIoThread;
|
||||
@ -53,7 +55,7 @@ public class BluetoothCommunicationService extends Service {
|
||||
= "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.install_pebbbleapp";
|
||||
public static final String EXTRA_PERFORM_PAIR = "perform_pair";
|
||||
|
||||
private static final String TAG = "CommunicationService";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(BluetoothCommunicationService.class);
|
||||
public static final String EXTRA_DEVICE_ADDRESS = "device_address";
|
||||
private GBDeviceIoThread mGBDeviceIoThread = null;
|
||||
|
||||
@ -79,7 +81,7 @@ public class BluetoothCommunicationService extends Service {
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
Log.d(TAG, "BluetoothCommunicationService is being created");
|
||||
LOG.debug("BluetoothCommunicationService is being created");
|
||||
super.onCreate();
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, new IntentFilter(GBDevice.ACTION_DEVICE_CHANGED));
|
||||
}
|
||||
@ -88,7 +90,7 @@ public class BluetoothCommunicationService extends Service {
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
|
||||
if (intent == null) {
|
||||
Log.i(TAG, "no intent");
|
||||
LOG.info("no intent");
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
|
||||
@ -96,15 +98,15 @@ public class BluetoothCommunicationService extends Service {
|
||||
boolean pair = intent.getBooleanExtra(EXTRA_PERFORM_PAIR, false);
|
||||
|
||||
if (action == null) {
|
||||
Log.i(TAG, "no action");
|
||||
LOG.info("no action");
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
|
||||
Log.d(TAG, "Service startcommand: " + action);
|
||||
LOG.debug("Service startcommand: " + action);
|
||||
|
||||
if (!mStarted && !action.equals(ACTION_START)) {
|
||||
// using the service before issuing ACTION_START
|
||||
Log.i(TAG, "Must start service with " + ACTION_START + " before using it: " + action);
|
||||
LOG.info("Must start service with " + ACTION_START + " before using it: " + action);
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
|
||||
@ -226,7 +228,7 @@ public class BluetoothCommunicationService extends Service {
|
||||
case ACTION_INSTALL_PEBBLEAPP:
|
||||
String uriString = intent.getStringExtra("app_uri");
|
||||
if (uriString != null) {
|
||||
Log.i(TAG, "will try to install app");
|
||||
LOG.info("will try to install app");
|
||||
((PebbleIoThread) mGBDeviceIoThread).installApp(Uri.parse(uriString));
|
||||
}
|
||||
break;
|
||||
@ -249,7 +251,7 @@ public class BluetoothCommunicationService extends Service {
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
Log.d(TAG, "BluetoothCommunicationService is being destroyed");
|
||||
LOG.debug("BluetoothCommunicationService is being destroyed");
|
||||
super.onDestroy();
|
||||
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
||||
|
@ -9,7 +9,9 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.K9Receiver;
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.MusicPlaybackReceiver;
|
||||
@ -20,7 +22,7 @@ import nodomain.freeyourgadget.gadgetbridge.externalevents.TimeChangeReceiver;
|
||||
|
||||
public class GB {
|
||||
public static final int NOTIFICATION_ID = 1;
|
||||
private static final String TAG = "GB";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GB.class);
|
||||
|
||||
public static Notification createNotification(String text, Context context) {
|
||||
Intent notificationIntent = new Intent(context, ControlCenter.class);
|
||||
@ -46,7 +48,7 @@ public class GB {
|
||||
}
|
||||
|
||||
public static void setReceiversEnableState(boolean enable, Context context) {
|
||||
Log.i(TAG, "Setting broadcast receivers to: " + enable);
|
||||
LOG.info("Setting broadcast receivers to: " + enable);
|
||||
final Class<?>[] receiverClasses = {
|
||||
PhoneCallReceiver.class,
|
||||
SMSReceiver.class,
|
||||
|
@ -4,17 +4,18 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.telephony.ITelephony;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.android.internal.telephony.ITelephony;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandCallControl;
|
||||
|
||||
public class GBCallControlReceiver extends BroadcastReceiver {
|
||||
public static final String ACTION_CALLCONTROL = "nodomain.freeyourgadget.gadgetbridge.callcontrol";
|
||||
private final String TAG = this.getClass().getSimpleName();
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GBCallControlReceiver.class);
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
@ -34,7 +35,7 @@ public class GBCallControlReceiver extends BroadcastReceiver {
|
||||
telephonyService.answerRingingCall();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "could not start or hangup call");
|
||||
LOG.warn("could not start or hangup call");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -5,7 +5,9 @@ import android.content.Intent;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class GBDevice implements Parcelable {
|
||||
public static final String ACTION_DEVICE_CHANGED
|
||||
@ -21,7 +23,7 @@ public class GBDevice implements Parcelable {
|
||||
return new GBDevice[size];
|
||||
}
|
||||
};
|
||||
private static final String TAG = GBDevice.class.getSimpleName();
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GBDevice.class);
|
||||
public static final short RSSI_UNKNOWN = 0;
|
||||
public static final short BATTERY_UNKNOWN = -1;
|
||||
public static final String EXTRA_DEVICE = "device";
|
||||
@ -158,7 +160,7 @@ public class GBDevice implements Parcelable {
|
||||
|
||||
public void setRssi(short rssi) {
|
||||
if (rssi < 0) {
|
||||
Log.w(TAG, "illegal rssi value " + rssi + ", setting to RSSI_UNKNOWN");
|
||||
LOG.warn("illegal rssi value " + rssi + ", setting to RSSI_UNKNOWN");
|
||||
mRssi = RSSI_UNKNOWN;
|
||||
} else {
|
||||
mRssi = rssi;
|
||||
@ -216,7 +218,7 @@ public class GBDevice implements Parcelable {
|
||||
if (batteryLevel >= 0 && batteryLevel <= 100) {
|
||||
mBatteryLevel = batteryLevel;
|
||||
} else {
|
||||
Log.e(TAG, "Battery level musts be within range 0-100: " + batteryLevel);
|
||||
LOG.error("Battery level musts be within range 0-100: " + batteryLevel);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,10 +7,13 @@ import android.media.AudioManager;
|
||||
import android.os.SystemClock;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandMusicControl;
|
||||
|
||||
public class GBMusicControlReceiver extends BroadcastReceiver {
|
||||
private final String TAG = this.getClass().getSimpleName();
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GBMusicControlReceiver.class);
|
||||
|
||||
public static final String ACTION_MUSICCONTROL = "nodomain.freeyourgadget.gadgetbridge.musiccontrol";
|
||||
|
||||
|
@ -6,9 +6,11 @@ import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.NavUtils;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* A settings activity with support for preferences directly displaying their value.
|
||||
* If you combine such preferences with a custom OnPreferenceChangeListener, you have
|
||||
@ -17,7 +19,7 @@ import android.view.MenuItem;
|
||||
*/
|
||||
public class AbstractSettingsActivity extends PreferenceActivity {
|
||||
|
||||
private static final String TAG = "AbstractSettingsAct";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AbstractSettingsActivity.class);
|
||||
|
||||
/**
|
||||
* A preference value change listener that updates the preference's summary
|
||||
@ -83,7 +85,7 @@ public class AbstractSettingsActivity extends PreferenceActivity {
|
||||
if (pref != null) {
|
||||
bindPreferenceSummaryToValue(pref);
|
||||
} else {
|
||||
Log.e(TAG, "Unknown preference key: " + prefKey + ", unable to display value.");
|
||||
LOG.error("Unknown preference key: " + prefKey + ", unable to display value.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package nodomain.freeyourgadget.gadgetbridge.btle;
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.bluetooth.BluetoothGattService;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
@ -11,6 +10,8 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.AbstractDeviceSupport;
|
||||
|
||||
@ -19,7 +20,7 @@ import nodomain.freeyourgadget.gadgetbridge.AbstractDeviceSupport;
|
||||
* @see BtLEQueue
|
||||
*/
|
||||
public abstract class AbstractBTLEDeviceSupport extends AbstractDeviceSupport implements GattCallback {
|
||||
private static final String TAG = "AbstractBTLEDeviceSupp";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AbstractBTLEDeviceSupport.class);
|
||||
|
||||
private BtLEQueue mQueue;
|
||||
private HashMap<UUID, BluetoothGattCharacteristic> mAvailableCharacteristics;
|
||||
@ -130,7 +131,7 @@ public abstract class AbstractBTLEDeviceSupport extends AbstractDeviceSupport im
|
||||
if (supportedServices.contains(service.getUuid())) {
|
||||
List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics();
|
||||
if (characteristics == null || characteristics.isEmpty()) {
|
||||
Log.w(TAG, "Supported LE service " + service.getUuid() + "did not return any characteristics");
|
||||
LOG.warn("Supported LE service " + service.getUuid() + "did not return any characteristics");
|
||||
continue;
|
||||
}
|
||||
mAvailableCharacteristics = new HashMap<>(characteristics.size());
|
||||
|
@ -8,7 +8,9 @@ import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.bluetooth.BluetoothGattService;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -24,7 +26,7 @@ import nodomain.freeyourgadget.gadgetbridge.GBDevice.State;
|
||||
* One queue/thread per connectable device.
|
||||
*/
|
||||
public final class BtLEQueue {
|
||||
private static final String TAG = BtLEQueue.class.getSimpleName();
|
||||
private static final Logger LOG = LoggerFactory.getLogger(BtLEQueue.class);
|
||||
|
||||
private GBDevice mGbDevice;
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
@ -44,7 +46,7 @@ public final class BtLEQueue {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Log.d(TAG, "Queue Dispatch Thread started.");
|
||||
LOG.debug("Queue Dispatch Thread started.");
|
||||
|
||||
while (!mDisposed && !mCrashed) {
|
||||
try {
|
||||
@ -74,16 +76,16 @@ public final class BtLEQueue {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "Action returned false: " + action);
|
||||
LOG.error("Action returned false: " + action);
|
||||
break; // abort the transaction
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException ignored) {
|
||||
mWaitForActionResultLatch = null;
|
||||
mConnectionLatch = null;
|
||||
Log.d(TAG, "Thread interrupted");
|
||||
LOG.debug("Thread interrupted");
|
||||
} catch (Throwable ex) {
|
||||
Log.e(TAG, "Queue Dispatch Thread died: " + ex.getMessage());
|
||||
LOG.error("Queue Dispatch Thread died: " + ex.getMessage());
|
||||
mCrashed = true;
|
||||
mWaitForActionResultLatch = null;
|
||||
mConnectionLatch = null;
|
||||
@ -91,7 +93,7 @@ public final class BtLEQueue {
|
||||
mWaitCharacteristic = null;
|
||||
}
|
||||
}
|
||||
Log.i(TAG, "Queue Dispatch Thread terminated.");
|
||||
LOG.info("Queue Dispatch Thread terminated.");
|
||||
}
|
||||
};
|
||||
|
||||
@ -117,10 +119,10 @@ public final class BtLEQueue {
|
||||
*/
|
||||
public boolean connect() {
|
||||
if (isConnected()) {
|
||||
Log.w(TAG, "Ingoring connect() because already connected.");
|
||||
LOG.warn("Ingoring connect() because already connected.");
|
||||
return false;
|
||||
}
|
||||
Log.i(TAG, "Attempting to connect to " + mGbDevice.getName());
|
||||
LOG.info("Attempting to connect to " + mGbDevice.getName());
|
||||
BluetoothDevice remoteDevice = mBluetoothAdapter.getRemoteDevice(mGbDevice.getAddress());
|
||||
mBluetoothGatt = remoteDevice.connectGatt(mContext, false, internalGattCallback);
|
||||
boolean result = mBluetoothGatt.connect();
|
||||
@ -138,7 +140,7 @@ public final class BtLEQueue {
|
||||
|
||||
public void disconnect() {
|
||||
if (mBluetoothGatt != null) {
|
||||
Log.i(TAG, "Disconnecting BtLEQueue from GATT device");
|
||||
LOG.info("Disconnecting BtLEQueue from GATT device");
|
||||
mBluetoothGatt.disconnect();
|
||||
mBluetoothGatt.close();
|
||||
mBluetoothGatt = null;
|
||||
@ -164,7 +166,7 @@ public final class BtLEQueue {
|
||||
dispatchThread = null;
|
||||
// dispatchThread.join();
|
||||
// } catch (InterruptedException ex) {
|
||||
// Log.e(TAG, "Exception while disposing BtLEQueue", ex);
|
||||
// LOG.error("Exception while disposing BtLEQueue", ex);
|
||||
// }
|
||||
}
|
||||
|
||||
@ -174,11 +176,11 @@ public final class BtLEQueue {
|
||||
* @param transaction
|
||||
*/
|
||||
public void add(Transaction transaction) {
|
||||
Log.d(TAG, "about to add: " + transaction);
|
||||
LOG.debug("about to add: " + transaction);
|
||||
if (!transaction.isEmpty()) {
|
||||
mTransactions.add(transaction);
|
||||
}
|
||||
Log.d(TAG, "adding done: " + transaction);
|
||||
LOG.debug("adding done: " + transaction);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
@ -193,7 +195,7 @@ public final class BtLEQueue {
|
||||
*/
|
||||
public List<BluetoothGattService> getSupportedGattServices() {
|
||||
if (mBluetoothGatt == null) {
|
||||
Log.w(TAG, "BluetoothGatt is null => no services available.");
|
||||
LOG.warn("BluetoothGatt is null => no services available.");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return mBluetoothGatt.getServices();
|
||||
@ -206,18 +208,18 @@ public final class BtLEQueue {
|
||||
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
|
||||
switch (newState) {
|
||||
case BluetoothProfile.STATE_CONNECTED:
|
||||
Log.i(TAG, "Connected to GATT server.");
|
||||
LOG.info("Connected to GATT server.");
|
||||
setDeviceConnectionState(State.CONNECTED);
|
||||
// Attempts to discover services after successful connection.
|
||||
Log.i(TAG, "Attempting to start service discovery:" +
|
||||
LOG.info("Attempting to start service discovery:" +
|
||||
mBluetoothGatt.discoverServices());
|
||||
break;
|
||||
case BluetoothProfile.STATE_DISCONNECTED:
|
||||
Log.i(TAG, "Disconnected from GATT server.");
|
||||
LOG.info("Disconnected from GATT server.");
|
||||
handleDisconnected();
|
||||
break;
|
||||
case BluetoothProfile.STATE_CONNECTING:
|
||||
Log.i(TAG, "Connecting to GATT server...");
|
||||
LOG.info("Connecting to GATT server...");
|
||||
setDeviceConnectionState(State.CONNECTING);
|
||||
break;
|
||||
}
|
||||
@ -231,16 +233,16 @@ public final class BtLEQueue {
|
||||
mExternalGattCallback.onServicesDiscovered(gatt);
|
||||
}
|
||||
} else {
|
||||
Log.w(TAG, "onServicesDiscovered received: " + status);
|
||||
LOG.warn("onServicesDiscovered received: " + status);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
|
||||
if (status == BluetoothGatt.GATT_SUCCESS) {
|
||||
Log.i(TAG, "Writing characteristic " + characteristic.getUuid() + " succeeded.");
|
||||
LOG.info("Writing characteristic " + characteristic.getUuid() + " succeeded.");
|
||||
} else {
|
||||
Log.e(TAG, "Writing characteristic " + characteristic.getUuid() + " failed: " + status);
|
||||
LOG.error("Writing characteristic " + characteristic.getUuid() + " failed: " + status);
|
||||
}
|
||||
if (mExternalGattCallback != null) {
|
||||
mExternalGattCallback.onCharacteristicWrite(gatt, characteristic, status);
|
||||
@ -253,7 +255,7 @@ public final class BtLEQueue {
|
||||
BluetoothGattCharacteristic characteristic,
|
||||
int status) {
|
||||
if (status != BluetoothGatt.GATT_SUCCESS) {
|
||||
Log.e(TAG, "Reading characteristic " + characteristic.getUuid() + " failed: " + status);
|
||||
LOG.error("Reading characteristic " + characteristic.getUuid() + " failed: " + status);
|
||||
}
|
||||
if (mExternalGattCallback != null) {
|
||||
mExternalGattCallback.onCharacteristicRead(gatt, characteristic, status);
|
||||
|
@ -1,10 +1,12 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.btle;
|
||||
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.util.Log;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class TransactionBuilder {
|
||||
private static final String TAG = TransactionBuilder.class.getSimpleName();
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TransactionBuilder.class);
|
||||
|
||||
private Transaction mTransaction;
|
||||
|
||||
@ -14,7 +16,7 @@ public class TransactionBuilder {
|
||||
|
||||
public TransactionBuilder read(BluetoothGattCharacteristic characteristic) {
|
||||
if (characteristic == null) {
|
||||
Log.w(TAG, "Unable to read characteristic: null");
|
||||
LOG.warn("Unable to read characteristic: null");
|
||||
return this;
|
||||
}
|
||||
ReadAction action = new ReadAction(characteristic);
|
||||
@ -23,7 +25,7 @@ public class TransactionBuilder {
|
||||
|
||||
public TransactionBuilder write(BluetoothGattCharacteristic characteristic, byte[] data) {
|
||||
if (characteristic == null) {
|
||||
Log.w(TAG, "Unable to write characteristic: null");
|
||||
LOG.warn("Unable to write characteristic: null");
|
||||
return this;
|
||||
}
|
||||
WriteAction action = new WriteAction(characteristic, data);
|
||||
|
@ -12,7 +12,6 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.Parcelable;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Button;
|
||||
@ -21,6 +20,8 @@ import android.widget.ProgressBar;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.DeviceCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.DeviceHelper;
|
||||
@ -30,7 +31,7 @@ import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.adapter.DeviceCandidateAdapter;
|
||||
|
||||
public class DiscoveryActivity extends Activity implements AdapterView.OnItemClickListener {
|
||||
private static final String TAG = "DiscoveryAct";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DiscoveryActivity.class);
|
||||
private static final long SCAN_DURATION = 60000; // 60s
|
||||
|
||||
private Handler handler = new Handler();
|
||||
@ -66,7 +67,7 @@ public class DiscoveryActivity extends Activity implements AdapterView.OnItemCli
|
||||
if (device != null && device.getAddress().equals(bondingAddress)) {
|
||||
int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE);
|
||||
if (bondState == BluetoothDevice.BOND_BONDED) {
|
||||
Log.i(TAG, "Successfully bonded with: " + bondingAddress);
|
||||
LOG.info("Successfully bonded with: " + bondingAddress);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@ -158,7 +159,7 @@ public class DiscoveryActivity extends Activity implements AdapterView.OnItemCli
|
||||
}
|
||||
|
||||
public void onStartButtonClick(View button) {
|
||||
Log.d(TAG, "Start Button clicked");
|
||||
LOG.debug("Start Button clicked");
|
||||
if (isScanning()) {
|
||||
stopDiscovery();
|
||||
} else {
|
||||
@ -173,7 +174,7 @@ public class DiscoveryActivity extends Activity implements AdapterView.OnItemCli
|
||||
}
|
||||
|
||||
private void handleDeviceFound(BluetoothDevice device, short rssi) {
|
||||
DeviceCandidate candidate = new DeviceCandidate(device, (short) rssi);
|
||||
DeviceCandidate candidate = new DeviceCandidate(device, rssi);
|
||||
if (DeviceHelper.getInstance().isSupported(candidate)) {
|
||||
int index = deviceCandidates.indexOf(candidate);
|
||||
if (index >= 0) {
|
||||
@ -191,14 +192,14 @@ public class DiscoveryActivity extends Activity implements AdapterView.OnItemCli
|
||||
*/
|
||||
private void startDiscovery() {
|
||||
if (isScanning()) {
|
||||
Log.w(TAG, "Not starting discovery, because already scanning.");
|
||||
LOG.warn("Not starting discovery, because already scanning.");
|
||||
return;
|
||||
}
|
||||
startDiscovery(Scanning.SCANNING_BT);
|
||||
}
|
||||
|
||||
private void startDiscovery(Scanning what) {
|
||||
Log.i(TAG, "Starting discovery: " + what);
|
||||
LOG.info("Starting discovery: " + what);
|
||||
discoveryStarted(what); // just to make sure
|
||||
if (ensureBluetoothReady()) {
|
||||
if (what == Scanning.SCANNING_BT) {
|
||||
@ -221,7 +222,7 @@ public class DiscoveryActivity extends Activity implements AdapterView.OnItemCli
|
||||
}
|
||||
|
||||
private void stopDiscovery() {
|
||||
Log.i(TAG, "Stopping discovery");
|
||||
LOG.info("Stopping discovery");
|
||||
if (isScanning()) {
|
||||
Scanning wasScanning = isScanning;
|
||||
// unfortunately, we don't always get a call back when stopping the scan, so
|
||||
@ -277,13 +278,13 @@ public class DiscoveryActivity extends Activity implements AdapterView.OnItemCli
|
||||
private boolean checkBluetoothAvailable() {
|
||||
BluetoothManager bluetoothService = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
|
||||
if (bluetoothService == null) {
|
||||
Log.w(TAG, "No bluetooth available");
|
||||
LOG.warn("No bluetooth available");
|
||||
this.adapter = null;
|
||||
return false;
|
||||
}
|
||||
BluetoothAdapter adapter = bluetoothService.getAdapter();
|
||||
if (!adapter.isEnabled()) {
|
||||
Log.w(TAG, "Bluetooth not enabled");
|
||||
LOG.warn("Bluetooth not enabled");
|
||||
this.adapter = null;
|
||||
return false;
|
||||
}
|
||||
@ -292,14 +293,14 @@ public class DiscoveryActivity extends Activity implements AdapterView.OnItemCli
|
||||
}
|
||||
|
||||
private void startBTLEDiscovery() {
|
||||
Log.i(TAG, "Starting BTLE Discovery");
|
||||
LOG.info("Starting BTLE Discovery");
|
||||
handler.removeMessages(0, stopRunnable);
|
||||
handler.sendMessageDelayed(getPostMessage(stopRunnable), SCAN_DURATION);
|
||||
adapter.startLeScan(leScanCallback);
|
||||
}
|
||||
|
||||
private void startBTDiscovery() {
|
||||
Log.i(TAG, "Starting BT Discovery");
|
||||
LOG.info("Starting BT Discovery");
|
||||
handler.removeMessages(0, stopRunnable);
|
||||
handler.sendMessageDelayed(getPostMessage(stopRunnable), SCAN_DURATION);
|
||||
adapter.startDiscovery();
|
||||
@ -315,7 +316,7 @@ public class DiscoveryActivity extends Activity implements AdapterView.OnItemCli
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
DeviceCandidate deviceCandidate = deviceCandidates.get(position);
|
||||
if (deviceCandidate == null) {
|
||||
Log.e(TAG, "Device candidate clicked, but item not found");
|
||||
LOG.error("Device candidate clicked, but item not found");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -335,7 +336,7 @@ public class DiscoveryActivity extends Activity implements AdapterView.OnItemCli
|
||||
bondingAddress = btDevice.getAddress();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Error pairing device: " + deviceCandidate.getMacAddress());
|
||||
LOG.error("Error pairing device: " + deviceCandidate.getMacAddress());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,11 +9,14 @@ import android.net.Uri;
|
||||
import android.os.PowerManager;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.BluetoothCommunicationService;
|
||||
|
||||
public class K9Receiver extends BroadcastReceiver {
|
||||
|
||||
private final String TAG = this.getClass().getSimpleName();
|
||||
private static final Logger LOG = LoggerFactory.getLogger(K9Receiver.class);
|
||||
private final Uri k9Uri = Uri.parse("content://com.fsck.k9.messageprovider/inbox_messages");
|
||||
|
||||
@Override
|
||||
|
@ -3,12 +3,14 @@ package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.BluetoothCommunicationService;
|
||||
|
||||
public class MusicPlaybackReceiver extends BroadcastReceiver {
|
||||
private final String TAG = this.getClass().getSimpleName();
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MusicPlaybackReceiver.class);
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
@ -16,7 +18,7 @@ public class MusicPlaybackReceiver extends BroadcastReceiver {
|
||||
String album = intent.getStringExtra("album");
|
||||
String track = intent.getStringExtra("track");
|
||||
|
||||
Log.i(TAG, "Current track: " + artist + ", " + album + ", " + track);
|
||||
LOG.info("Current track: " + artist + ", " + album + ", " + track);
|
||||
|
||||
Intent startIntent = new Intent(context, BluetoothCommunicationService.class);
|
||||
startIntent.setAction(BluetoothCommunicationService.ACTION_SETMUSICINFO);
|
||||
|
@ -9,13 +9,15 @@ import android.os.PowerManager;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.util.Log;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.BluetoothCommunicationService;
|
||||
|
||||
public class NotificationListener extends NotificationListenerService {
|
||||
|
||||
private String TAG = this.getClass().getSimpleName();
|
||||
private static final Logger LOG = LoggerFactory.getLogger(NotificationListener.class);
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
@ -83,7 +85,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
}
|
||||
}
|
||||
|
||||
Log.i(TAG, "Processing notification from source " + source);
|
||||
LOG.info("Processing notification from source " + source);
|
||||
|
||||
Bundle extras = notification.extras;
|
||||
String title = extras.getCharSequence(Notification.EXTRA_TITLE).toString();
|
||||
|
@ -6,7 +6,9 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.PowerManager;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@ -15,7 +17,7 @@ import nodomain.freeyourgadget.gadgetbridge.BluetoothCommunicationService;
|
||||
|
||||
public class PebbleReceiver extends BroadcastReceiver {
|
||||
|
||||
private final String TAG = this.getClass().getSimpleName();
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PebbleReceiver.class);
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
@ -36,7 +38,7 @@ public class PebbleReceiver extends BroadcastReceiver {
|
||||
|
||||
String messageType = intent.getStringExtra("messageType");
|
||||
if (!messageType.equals("PEBBLE_ALERT")) {
|
||||
Log.i(TAG, "non PEBBLE_ALERT message type not supported");
|
||||
LOG.info("non PEBBLE_ALERT message type not supported");
|
||||
return;
|
||||
}
|
||||
String notificationData = intent.getStringExtra("notificationData");
|
||||
|
@ -5,14 +5,16 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.BluetoothCommunicationService;
|
||||
|
||||
|
||||
public class TimeChangeReceiver extends BroadcastReceiver {
|
||||
|
||||
private final String TAG = this.getClass().getSimpleName();
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TimeChangeReceiver.class);
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
@ -20,7 +22,7 @@ public class TimeChangeReceiver extends BroadcastReceiver {
|
||||
final String action = intent.getAction();
|
||||
|
||||
if (sharedPrefs.getBoolean("datetime_synconconnect", true) && (action.equals(Intent.ACTION_TIME_CHANGED) || action.equals(Intent.ACTION_TIMEZONE_CHANGED))) {
|
||||
Log.i(TAG, "Time or Timezone changed, syncing with device");
|
||||
LOG.info("Time or Timezone changed, syncing with device");
|
||||
Intent startIntent = new Intent(context, BluetoothCommunicationService.class);
|
||||
startIntent.setAction(BluetoothCommunicationService.ACTION_SETTIME);
|
||||
context.startService(startIntent);
|
||||
|
@ -3,9 +3,10 @@ package nodomain.freeyourgadget.gadgetbridge.miband;
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.Calendar;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.DeviceCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.DeviceType;
|
||||
@ -14,7 +15,7 @@ import nodomain.freeyourgadget.gadgetbridge.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.discovery.DeviceCandidate;
|
||||
|
||||
public class MiBandCoordinator implements DeviceCoordinator {
|
||||
private static final String TAG = "MiBandCoord";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MiBandCoordinator.class);
|
||||
|
||||
@Override
|
||||
public boolean supports(DeviceCandidate candidate) {
|
||||
@ -55,7 +56,7 @@ public class MiBandCoordinator implements DeviceCoordinator {
|
||||
try {
|
||||
return getConfiguredUserInfo(miBandAddress);
|
||||
} catch (Exception ex) {
|
||||
Log.e(TAG, "Error creating user info from settings, using default user instead: " + ex);
|
||||
LOG.error("Error creating user info from settings, using default user instead: " + ex);
|
||||
return UserInfo.getDefault(miBandAddress);
|
||||
}
|
||||
}
|
||||
|
@ -2,23 +2,21 @@ package nodomain.freeyourgadget.gadgetbridge.miband;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Calendar;
|
||||
import java.util.UUID;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBCommand;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBDevice.State;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.btle.AbstractBTLEDeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.btle.TransactionBuilder;
|
||||
|
||||
public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
private static final String TAG = MiBandSupport.class.getSimpleName();
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MiBandSupport.class);
|
||||
|
||||
public MiBandSupport() {
|
||||
addSupportedService(MiBandService.UUID_SERVICE_MIBAND_SERVICE);
|
||||
@ -57,7 +55,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
private void sendDefaultNotification(TransactionBuilder builder) {
|
||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
|
||||
Log.i(TAG, "Sending notification to MiBand: " + characteristic);
|
||||
LOG.info("Sending notification to MiBand: " + characteristic);
|
||||
builder.write(characteristic, getDefaultNotification()).queue(getQueue());
|
||||
}
|
||||
|
||||
@ -78,14 +76,14 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
* @return
|
||||
*/
|
||||
private MiBandSupport sendUserInfo(TransactionBuilder builder) {
|
||||
Log.d(TAG, "Writing User Info!");
|
||||
LOG.debug("Writing User Info!");
|
||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_USER_INFO);
|
||||
builder.write(characteristic, MiBandCoordinator.getAnyUserInfo(getDevice().getAddress()).getData());
|
||||
return this;
|
||||
}
|
||||
|
||||
private MiBandSupport requestBatteryInfo(TransactionBuilder builder) {
|
||||
Log.d(TAG, "Requesting Battery Info!");
|
||||
LOG.debug("Requesting Battery Info!");
|
||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_BATTERY);
|
||||
builder.read(characteristic);
|
||||
return this;
|
||||
@ -98,12 +96,12 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
* @return
|
||||
*/
|
||||
private MiBandSupport pair(TransactionBuilder transaction) {
|
||||
Log.i(TAG, "Attempting to pair MI device...");
|
||||
LOG.info("Attempting to pair MI device...");
|
||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_PAIR);
|
||||
if (characteristic != null) {
|
||||
transaction.write(characteristic, new byte[]{2});
|
||||
} else {
|
||||
Log.i(TAG, "Unable to pair MI device -- characteristic not available");
|
||||
LOG.info("Unable to pair MI device -- characteristic not available");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@ -113,7 +111,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
TransactionBuilder builder = performInitialized(task);
|
||||
sendDefaultNotification(builder);
|
||||
} catch (IOException ex) {
|
||||
Log.e(TAG, "Unable to send notification to MI device", ex);
|
||||
LOG.error("Unable to send notification to MI device", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,7 +132,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
setCurrentTime(builder);
|
||||
builder.queue(getQueue());
|
||||
} catch (IOException ex) {
|
||||
Log.e(TAG, "Unable to set time on MI device", ex);
|
||||
LOG.error("Unable to set time on MI device", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,7 +161,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
if (characteristic != null) {
|
||||
builder.write(characteristic, time);
|
||||
} else {
|
||||
Log.i(TAG, "Unable to set time -- characteristic not available");
|
||||
LOG.info("Unable to set time -- characteristic not available");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@ -187,7 +185,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_DEVICE_INFO);
|
||||
builder.read(characteristic).queue(getQueue());
|
||||
} catch (IOException ex) {
|
||||
Log.e(TAG, "Unable to read device info from MI", ex);
|
||||
LOG.error("Unable to read device info from MI", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -198,7 +196,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
requestBatteryInfo(builder);
|
||||
builder.queue(getQueue());
|
||||
} catch (IOException ex) {
|
||||
Log.e(TAG, "Unable to read battery info from MI", ex);
|
||||
LOG.error("Unable to read battery info from MI", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,7 +270,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
private void handlePairResult(byte[] pairResult, int status) {
|
||||
if (status != BluetoothGatt.GATT_SUCCESS) {
|
||||
Log.i(TAG, "Pairing MI device failed: " + status);
|
||||
LOG.info("Pairing MI device failed: " + status);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -283,16 +281,16 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
byte b = pairResult[0];
|
||||
Integer intValue = Integer.valueOf(b);
|
||||
if (intValue.intValue() == 2) {
|
||||
Log.i(TAG, "Successfully paired MI device");
|
||||
LOG.info("Successfully paired MI device");
|
||||
return;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Log.w(TAG, "Error identifying pairing result", ex);
|
||||
LOG.warn("Error identifying pairing result", ex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
value = pairResult.toString();
|
||||
}
|
||||
Log.i(TAG, "MI Band pairing result: " + value);
|
||||
LOG.info("MI Band pairing result: " + value);
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,6 @@ package nodomain.freeyourgadget.gadgetbridge.pebble;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -16,13 +12,18 @@ import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBDeviceApp;
|
||||
|
||||
public class PBWReader {
|
||||
private static final String TAG = PebbleIoThread.class.getSimpleName();
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PBWReader.class);
|
||||
private static final HashMap<String, Byte> appFileTypesMap;
|
||||
|
||||
static {
|
||||
@ -99,7 +100,7 @@ public class PBWReader {
|
||||
long crc = jo.getLong("crc");
|
||||
byte type = entry.getValue();
|
||||
pebbleInstallables.add(new PebbleInstallable(name, size, (int) crc, type));
|
||||
Log.i(TAG, "found file to install: " + name);
|
||||
LOG.info("found file to install: " + name);
|
||||
} catch (JSONException e) {
|
||||
// not fatal
|
||||
}
|
||||
|
@ -14,6 +14,9 @@ import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.BluetoothCommunicationService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.ControlCenter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
|
||||
@ -23,7 +26,7 @@ import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
|
||||
public class PebbleAppInstallerActivity extends Activity {
|
||||
|
||||
private final String TAG = this.getClass().getSimpleName();
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PebbleAppInstallerActivity.class);
|
||||
|
||||
TextView debugTextView;
|
||||
Button installButton;
|
||||
|
@ -14,13 +14,14 @@ import android.os.ParcelUuid;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.AppManagerActivity;
|
||||
@ -39,7 +40,7 @@ import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandVersionInfo;
|
||||
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceProtocol;
|
||||
|
||||
public class PebbleIoThread extends GBDeviceIoThread {
|
||||
private static final String TAG = PebbleIoThread.class.getSimpleName();
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PebbleIoThread.class);
|
||||
private static final int NOTIFICATION_ID = 2;
|
||||
|
||||
private enum PebbleAppInstallState {
|
||||
@ -140,7 +141,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
if (sharedPrefs.getBoolean("datetime_synconconnect", true)) {
|
||||
Log.i(TAG, "syncing time");
|
||||
LOG.info("syncing time");
|
||||
write(mPebbleProtocol.encodeSetTime(-1));
|
||||
}
|
||||
|
||||
@ -177,10 +178,10 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
if (mPBWReader.isFirmware()) {
|
||||
writeInstallApp(mPebbleProtocol.encodeInstallFirmwareStart());
|
||||
mInstallSlot = 0;
|
||||
Log.i(TAG, "starting firmware installation");
|
||||
LOG.info("starting firmware installation");
|
||||
}
|
||||
}
|
||||
Log.i(TAG, "start installing app binary");
|
||||
LOG.info("start installing app binary");
|
||||
PebbleInstallable pi = mPebbleInstallables[mCurrentInstallableIndex];
|
||||
mZis = mPBWReader.getInputStreamFile(pi.getFileName());
|
||||
mCRC = pi.getCRC();
|
||||
@ -191,7 +192,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
break;
|
||||
case APP_WAIT_TOKEN:
|
||||
if (mAppInstallToken != -1) {
|
||||
Log.i(TAG, "got token " + mAppInstallToken);
|
||||
LOG.info("got token " + mAppInstallToken);
|
||||
mInstallState = PebbleAppInstallState.APP_UPLOAD_CHUNK;
|
||||
continue;
|
||||
}
|
||||
@ -223,7 +224,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
break;
|
||||
case APP_WAIT_COMMIT:
|
||||
if (mAppInstallToken != -1) {
|
||||
Log.i(TAG, "got token " + mAppInstallToken);
|
||||
LOG.info("got token " + mAppInstallToken);
|
||||
mInstallState = PebbleAppInstallState.APP_UPLOAD_COMPLETE;
|
||||
continue;
|
||||
}
|
||||
@ -258,7 +259,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
short length = buf.getShort();
|
||||
short endpoint = buf.getShort();
|
||||
if (length < 0 || length > 8192) {
|
||||
Log.i(TAG, "invalid length " + length);
|
||||
LOG.info("invalid length " + length);
|
||||
while (mInStream.available() > 0) {
|
||||
mInStream.read(buffer); // read all
|
||||
}
|
||||
@ -277,7 +278,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
|
||||
GBDeviceCommand deviceCmd = mPebbleProtocol.decodeResponse(buffer);
|
||||
if (deviceCmd == null) {
|
||||
Log.i(TAG, "unhandled message to endpoint " + endpoint + " (" + length + " bytes)");
|
||||
LOG.info("unhandled message to endpoint " + endpoint + " (" + length + " bytes)");
|
||||
} else {
|
||||
evaluateGBDeviceCommand(deviceCmd);
|
||||
}
|
||||
@ -288,12 +289,12 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (e.getMessage().contains("socket closed")) { //FIXME: this does not feel right
|
||||
Log.i(TAG, e.getMessage());
|
||||
LOG.info(e.getMessage());
|
||||
gbDevice.setState(GBDevice.State.CONNECTING);
|
||||
gbDevice.sendDeviceUpdateIntent(getContext());
|
||||
|
||||
while (mConnectionAttempts++ < 10 && !mQuit) {
|
||||
Log.i(TAG, "Trying to reconnect (attempt " + mConnectionAttempts + ")");
|
||||
LOG.info("Trying to reconnect (attempt " + mConnectionAttempts + ")");
|
||||
mIsConnected = connect(gbDevice.getAddress());
|
||||
if (mIsConnected)
|
||||
break;
|
||||
@ -301,7 +302,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
mConnectionAttempts = 0;
|
||||
if (!mIsConnected) {
|
||||
mBtSocket = null;
|
||||
Log.i(TAG, "Bluetooth socket closed, will quit IO Thread");
|
||||
LOG.info("Bluetooth socket closed, will quit IO Thread");
|
||||
mQuit = true;
|
||||
}
|
||||
}
|
||||
@ -338,7 +339,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
|
||||
switch (deviceCmd.commandClass) {
|
||||
case MUSIC_CONTROL:
|
||||
Log.i(TAG, "Got command for MUSIC_CONTROL");
|
||||
LOG.info("Got command for MUSIC_CONTROL");
|
||||
GBDeviceCommandMusicControl musicCmd = (GBDeviceCommandMusicControl) deviceCmd;
|
||||
Intent musicIntent = new Intent(GBMusicControlReceiver.ACTION_MUSICCONTROL);
|
||||
musicIntent.putExtra("command", musicCmd.command.ordinal());
|
||||
@ -346,7 +347,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
context.sendBroadcast(musicIntent);
|
||||
break;
|
||||
case CALL_CONTROL:
|
||||
Log.i(TAG, "Got command for CALL_CONTROL");
|
||||
LOG.info("Got command for CALL_CONTROL");
|
||||
GBDeviceCommandCallControl callCmd = (GBDeviceCommandCallControl) deviceCmd;
|
||||
Intent callIntent = new Intent(GBCallControlReceiver.ACTION_CALLCONTROL);
|
||||
callIntent.putExtra("command", callCmd.command.ordinal());
|
||||
@ -354,7 +355,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
context.sendBroadcast(callIntent);
|
||||
break;
|
||||
case VERSION_INFO:
|
||||
Log.i(TAG, "Got command for VERSION_INFO");
|
||||
LOG.info("Got command for VERSION_INFO");
|
||||
if (gbDevice == null) {
|
||||
return;
|
||||
}
|
||||
@ -364,7 +365,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
gbDevice.sendDeviceUpdateIntent(context);
|
||||
break;
|
||||
case APP_INFO:
|
||||
Log.i(TAG, "Got command for APP_INFO");
|
||||
LOG.info("Got command for APP_INFO");
|
||||
GBDeviceCommandAppInfo appInfoCmd = (GBDeviceCommandAppInfo) deviceCmd;
|
||||
setInstallSlot(appInfoCmd.freeSlot);
|
||||
|
||||
@ -392,7 +393,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
// right now on the Pebble we also receive this on a failed/successful installation ;/
|
||||
switch (appMgmtRes.result) {
|
||||
case FAILURE:
|
||||
Log.i(TAG, "failure removing app"); // TODO: report to AppManager
|
||||
LOG.info("failure removing app"); // TODO: report to AppManager
|
||||
finishInstall(true);
|
||||
break;
|
||||
case SUCCESS:
|
||||
@ -407,7 +408,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
case INSTALL:
|
||||
switch (appMgmtRes.result) {
|
||||
case FAILURE:
|
||||
Log.i(TAG, "failure installing app"); // TODO: report to Installer
|
||||
LOG.info("failure installing app"); // TODO: report to Installer
|
||||
finishInstall(true);
|
||||
break;
|
||||
case SUCCESS:
|
||||
@ -440,7 +441,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
return;
|
||||
}
|
||||
int length = bytes.length;
|
||||
Log.i(TAG, "got " + length + "bytes for writeInstallApp()");
|
||||
LOG.info("got " + length + "bytes for writeInstallApp()");
|
||||
try {
|
||||
mOutStream.write(bytes);
|
||||
mOutStream.flush();
|
||||
|
@ -1,6 +1,5 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.pebble;
|
||||
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
@ -9,6 +8,8 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.SimpleTimeZone;
|
||||
import java.util.TimeZone;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBCommand;
|
||||
@ -24,7 +25,7 @@ import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceProtocol;
|
||||
|
||||
public class PebbleProtocol extends GBDeviceProtocol {
|
||||
|
||||
static private String TAG = "PebbleProtocol";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PebbleProtocol.class);
|
||||
|
||||
static final short ENDPOINT_FIRMWARE = 1;
|
||||
static final short ENDPOINT_TIME = 11;
|
||||
@ -119,7 +120,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
static final byte PHONEVERSION_APPVERSION_PATCH = 0;
|
||||
|
||||
|
||||
static final int PHONEVERSION_SESSION_CAPS_GAMMARAY = (int) 0x80000000;
|
||||
static final int PHONEVERSION_SESSION_CAPS_GAMMARAY = 0x80000000;
|
||||
|
||||
static final int PHONEVERSION_REMOTE_CAPS_TELEPHONY = 0x00000010;
|
||||
static final int PHONEVERSION_REMOTE_CAPS_SMS = 0x00000020;
|
||||
@ -201,6 +202,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
return buf.array();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeSMS(String from, String body) {
|
||||
Long ts = System.currentTimeMillis() / 1000;
|
||||
TimeZone tz = SimpleTimeZone.getDefault();
|
||||
@ -211,6 +213,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
return encodeMessage(ENDPOINT_NOTIFICATION, NOTIFICATION_SMS, 0, parts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeEmail(String from, String subject, String body) {
|
||||
Long ts = System.currentTimeMillis() / 1000;
|
||||
TimeZone tz = SimpleTimeZone.getDefault();
|
||||
@ -221,6 +224,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
return encodeMessage(ENDPOINT_NOTIFICATION, NOTIFICATION_EMAIL, 0, parts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeSetTime(long ts) {
|
||||
if (ts == -1) {
|
||||
ts = System.currentTimeMillis() / 1000;
|
||||
@ -247,6 +251,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
return buf.array();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeSetCallState(String number, String name, GBCommand command) {
|
||||
String[] parts = {number, name};
|
||||
byte pebbleCmd;
|
||||
@ -280,19 +285,23 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
return encodeMessage(ENDPOINT_PHONECONTROL, pebbleCmd, 0, parts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeSetMusicInfo(String artist, String album, String track) {
|
||||
String[] parts = {artist, album, track};
|
||||
return encodeMessage(ENDPOINT_MUSICCONTROL, MUSICCONTROL_SETMUSICINFO, 0, parts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeFirmwareVersionReq() {
|
||||
return encodeMessage(ENDPOINT_FIRMWAREVERSION, FIRMWAREVERSION_GETVERSION, 0, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeAppInfoReq() {
|
||||
return encodeMessage(ENDPOINT_APPMANAGER, APPMANAGER_GETAPPBANKSTATUS, 0, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeAppDelete(int id, int index) {
|
||||
ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_REMOVEAPP);
|
||||
buf.order(ByteOrder.BIG_ENDIAN);
|
||||
@ -305,6 +314,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
return buf.array();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodePhoneVersion(byte os) {
|
||||
ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_PHONEVERSION);
|
||||
buf.order(ByteOrder.BIG_ENDIAN);
|
||||
@ -493,6 +503,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
return buf.array();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GBDeviceCommand decodeResponse(byte[] responseData) {
|
||||
ByteBuffer buf = ByteBuffer.wrap(responseData);
|
||||
buf.order(ByteOrder.BIG_ENDIAN);
|
||||
@ -537,7 +548,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
callCmd.command = GBDeviceCommandCallControl.Command.END;
|
||||
break;
|
||||
default:
|
||||
Log.i(TAG, "Unknown PHONECONTROL command" + pebbleCmd);
|
||||
LOG.info("Unknown PHONECONTROL command" + pebbleCmd);
|
||||
break;
|
||||
}
|
||||
cmd = callCmd;
|
||||
@ -590,7 +601,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
for (int i = 0; i < slotCount; i++) {
|
||||
if (!slotInUse[i]) {
|
||||
appInfoCmd.freeSlot = (byte) i;
|
||||
Log.i(TAG, "found free slot " + i);
|
||||
LOG.info("found free slot " + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -612,7 +623,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
cmd = deleteRes;
|
||||
break;
|
||||
default:
|
||||
Log.i(TAG, "Unknown APPMANAGER command" + pebbleCmd);
|
||||
LOG.info("Unknown APPMANAGER command" + pebbleCmd);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -638,22 +649,22 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
byte dictSize = buf.get();
|
||||
switch (pebbleCmd) {
|
||||
case APPLICATIONMESSAGE_PUSH:
|
||||
Log.i(TAG, "got APPLICATIONMESSAGE PUSH from UUID " + GB.hexdump(uuid, 0, 16) + " , dict size " + dictSize);
|
||||
LOG.info("got APPLICATIONMESSAGE PUSH from UUID " + GB.hexdump(uuid, 0, 16) + " , dict size " + dictSize);
|
||||
if (Arrays.equals(uuid, WeatherNeatUUID)) {
|
||||
Log.i(TAG, "We know you, you are WeatherNeat");
|
||||
LOG.info("We know you, you are WeatherNeat");
|
||||
GBDeviceCommandSendBytes sendBytes = new GBDeviceCommandSendBytes();
|
||||
sendBytes.encodedBytes = encodeApplicationMessageTest();
|
||||
cmd = sendBytes;
|
||||
}
|
||||
break;
|
||||
case APPLICATIONMESSAGE_ACK:
|
||||
Log.i(TAG, "got APPLICATIONMESSAGE ACK");
|
||||
LOG.info("got APPLICATIONMESSAGE ACK");
|
||||
break;
|
||||
case APPLICATIONMESSAGE_NACK:
|
||||
Log.i(TAG, "got APPLICATIONMESSAGE NACK");
|
||||
LOG.info("got APPLICATIONMESSAGE NACK");
|
||||
break;
|
||||
case APPLICATIONMESSAGE_REQUEST:
|
||||
Log.i(TAG, "got APPLICATIONMESSAGE REQUEST");
|
||||
LOG.info("got APPLICATIONMESSAGE REQUEST");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -662,18 +673,18 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
case ENDPOINT_DATALOG:
|
||||
if (pebbleCmd != DATALOG_TIMEOUT) {
|
||||
byte id = buf.get();
|
||||
Log.i(TAG, "DATALOG id " + id + " - sending 0x85 (ACK?)");
|
||||
LOG.info("DATALOG id " + id + " - sending 0x85 (ACK?)");
|
||||
GBDeviceCommandSendBytes sendBytes = new GBDeviceCommandSendBytes();
|
||||
sendBytes.encodedBytes = encodeDatalog(id, (byte) 0x85);
|
||||
cmd = sendBytes;
|
||||
} else {
|
||||
Log.i(TAG, "DATALOG TIMEOUT - ignoring");
|
||||
LOG.info("DATALOG TIMEOUT - ignoring");
|
||||
}
|
||||
break;
|
||||
case ENDPOINT_PHONEVERSION:
|
||||
switch (pebbleCmd) {
|
||||
case PHONEVERSION_REQUEST:
|
||||
Log.i(TAG, "Pebble asked for Phone/App Version - repLYING!");
|
||||
LOG.info("Pebble asked for Phone/App Version - repLYING!");
|
||||
GBDeviceCommandSendBytes sendBytes = new GBDeviceCommandSendBytes();
|
||||
sendBytes.encodedBytes = encodePhoneVersion(PHONEVERSION_REMOTE_OS_ANDROID);
|
||||
cmd = sendBytes;
|
||||
|
28
app/src/main/res/android-logger.properties
Normal file
28
app/src/main/res/android-logger.properties
Normal file
@ -0,0 +1,28 @@
|
||||
# Android Logger configuration
|
||||
|
||||
# use VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT
|
||||
# By default logger will print only WARN(and higher) messages
|
||||
# with "Gadgetbridge" tag
|
||||
root=WARN:Gadgetbridge
|
||||
|
||||
# DEBUG (and higher) messages from classes of com.example.database
|
||||
# will be logged with "MyApplication-Database" tag
|
||||
#logger.com.example.database=DEBUG:MyApplication-Database
|
||||
|
||||
# All messages from classes of com.example.ui will be logged with
|
||||
# "MyApplication-UI" tag
|
||||
#logger.com.example.ui=MyApplication-UI
|
||||
#The configuration manages which log tag will be used to print messages and which logging level filter will be applied.
|
||||
|
||||
#logger.<package/classname>=<level>:<tag>:<message head>
|
||||
# or
|
||||
#logger.<package/classname>=<level>:<tag>
|
||||
# or
|
||||
#logger.<package/classname>=<tag>
|
||||
#The rest of messages will be managed by root logger:
|
||||
|
||||
#root=<level>:<tag>:<message head>
|
||||
# or
|
||||
#root=<level>:<tag>
|
||||
# or
|
||||
#root=<tag>
|
Loading…
Reference in New Issue
Block a user