2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.activities;
|
2015-02-07 12:58:18 +01:00
|
|
|
|
2015-03-07 15:32:34 +01:00
|
|
|
import android.app.Activity;
|
2015-02-07 12:58:18 +01:00
|
|
|
import android.app.NotificationManager;
|
2015-09-02 22:43:22 +02:00
|
|
|
import android.app.PendingIntent;
|
2015-02-07 12:58:18 +01:00
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
2015-08-03 01:17:02 +02:00
|
|
|
import android.database.sqlite.SQLiteOpenHelper;
|
2015-02-07 12:58:18 +01:00
|
|
|
import android.os.Bundle;
|
2015-03-27 11:23:30 +01:00
|
|
|
import android.support.v4.app.NavUtils;
|
2015-02-07 12:58:18 +01:00
|
|
|
import android.support.v4.app.NotificationCompat;
|
2015-03-27 11:23:30 +01:00
|
|
|
import android.view.MenuItem;
|
2015-02-07 12:58:18 +01:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.EditText;
|
2015-07-08 23:03:34 +02:00
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2015-08-03 01:17:02 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
2015-07-08 23:03:34 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
2015-08-21 00:58:18 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
2015-07-08 23:03:34 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
2015-08-21 00:58:18 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
2015-02-07 12:58:18 +01:00
|
|
|
|
2015-02-08 23:53:40 +01:00
|
|
|
|
2015-03-07 15:32:34 +01:00
|
|
|
public class DebugActivity extends Activity {
|
2015-07-08 23:03:34 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(DebugActivity.class);
|
|
|
|
|
|
|
|
private Button sendSMSButton;
|
|
|
|
private Button sendEmailButton;
|
|
|
|
private Button incomingCallButton;
|
|
|
|
private Button outgoingCallButton;
|
|
|
|
private Button startCallButton;
|
|
|
|
private Button endCallButton;
|
|
|
|
private Button testNotificationButton;
|
|
|
|
private Button setMusicInfoButton;
|
|
|
|
private Button setTimeButton;
|
|
|
|
private Button rebootButton;
|
|
|
|
private Button exportDBButton;
|
|
|
|
private Button importDBButton;
|
|
|
|
private EditText editContent;
|
2015-02-07 12:58:18 +01:00
|
|
|
|
|
|
|
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
if (intent.getAction().equals(ControlCenter.ACTION_QUIT)) {
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_debug);
|
2015-03-27 11:23:30 +01:00
|
|
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
2015-02-07 12:58:18 +01:00
|
|
|
|
|
|
|
registerReceiver(mReceiver, new IntentFilter(ControlCenter.ACTION_QUIT));
|
|
|
|
|
|
|
|
editContent = (EditText) findViewById(R.id.editContent);
|
|
|
|
sendSMSButton = (Button) findViewById(R.id.sendSMSButton);
|
|
|
|
sendSMSButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().onSMS(getResources().getText(R.string.app_name).toString(), editContent.getText().toString());
|
2015-02-07 12:58:18 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
sendEmailButton = (Button) findViewById(R.id.sendEmailButton);
|
|
|
|
sendEmailButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().onEmail(
|
|
|
|
getResources().getText(R.string.app_name).toString(),
|
|
|
|
getResources().getText(R.string.test).toString(),
|
|
|
|
editContent.getText().toString());
|
2015-02-07 12:58:18 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
incomingCallButton = (Button) findViewById(R.id.incomingCallButton);
|
|
|
|
incomingCallButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().onSetCallState(
|
|
|
|
editContent.getText().toString(),
|
|
|
|
null,
|
|
|
|
ServiceCommand.CALL_INCOMING);
|
2015-02-07 12:58:18 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
outgoingCallButton = (Button) findViewById(R.id.outgoingCallButton);
|
|
|
|
outgoingCallButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().onSetCallState(
|
|
|
|
editContent.getText().toString(),
|
|
|
|
null,
|
|
|
|
ServiceCommand.CALL_OUTGOING);
|
2015-02-07 12:58:18 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
startCallButton = (Button) findViewById(R.id.startCallButton);
|
|
|
|
startCallButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().onSetCallState(
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
ServiceCommand.CALL_START);
|
2015-02-07 12:58:18 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
endCallButton = (Button) findViewById(R.id.endCallButton);
|
|
|
|
endCallButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().onSetCallState(
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
ServiceCommand.CALL_END);
|
2015-02-07 12:58:18 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-07-08 23:03:34 +02:00
|
|
|
exportDBButton = (Button) findViewById(R.id.exportDBButton);
|
|
|
|
exportDBButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
exportDB();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
importDBButton = (Button) findViewById(R.id.importDBButton);
|
|
|
|
importDBButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
importDB();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-05-17 21:58:08 +02:00
|
|
|
rebootButton = (Button) findViewById(R.id.rebootButton);
|
|
|
|
rebootButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().onReboot();
|
2015-05-17 21:58:08 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-02-08 23:53:40 +01:00
|
|
|
setMusicInfoButton = (Button) findViewById(R.id.setMusicInfoButton);
|
|
|
|
setMusicInfoButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().onSetMusicInfo(
|
|
|
|
editContent.getText().toString() + "(artist)",
|
|
|
|
editContent.getText().toString() + "(album)",
|
|
|
|
editContent.getText().toString() + "(tracl)");
|
2015-02-08 23:53:40 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-02-07 12:58:18 +01:00
|
|
|
setTimeButton = (Button) findViewById(R.id.setTimeButton);
|
|
|
|
setTimeButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().onSetTime();
|
2015-02-07 12:58:18 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
testNotificationButton = (Button) findViewById(R.id.testNotificationButton);
|
|
|
|
testNotificationButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
testNotification();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-07-08 23:03:34 +02:00
|
|
|
private void exportDB() {
|
2015-08-03 01:17:02 +02:00
|
|
|
DBHandler dbHandler = null;
|
2015-07-08 23:03:34 +02:00
|
|
|
try {
|
2015-08-03 01:17:02 +02:00
|
|
|
dbHandler = GBApplication.acquireDB();
|
2015-07-08 23:03:34 +02:00
|
|
|
DBHelper helper = new DBHelper(this);
|
|
|
|
File dir = FileUtils.getExternalFilesDir();
|
2015-08-03 01:17:02 +02:00
|
|
|
File destFile = helper.exportDB(dbHandler.getHelper(), dir);
|
|
|
|
GB.toast(this, "Exported to: " + destFile.getAbsolutePath(), Toast.LENGTH_LONG, GB.INFO);
|
2015-07-08 23:03:34 +02:00
|
|
|
} catch (Exception ex) {
|
|
|
|
LOG.error("Unable to export db", ex);
|
|
|
|
Toast.makeText(this, "Error exporting DB: " + ex.getMessage(), Toast.LENGTH_LONG).show();
|
2015-08-03 01:17:02 +02:00
|
|
|
} finally {
|
|
|
|
if (dbHandler != null) {
|
|
|
|
dbHandler.release();
|
|
|
|
}
|
2015-07-08 23:03:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void importDB() {
|
2015-08-03 01:17:02 +02:00
|
|
|
DBHandler dbHandler = null;
|
2015-07-08 23:03:34 +02:00
|
|
|
try {
|
2015-08-03 01:17:02 +02:00
|
|
|
dbHandler = GBApplication.acquireDB();
|
2015-07-08 23:03:34 +02:00
|
|
|
DBHelper helper = new DBHelper(this);
|
|
|
|
File dir = FileUtils.getExternalFilesDir();
|
2015-08-03 01:17:02 +02:00
|
|
|
SQLiteOpenHelper sqLiteOpenHelper = dbHandler.getHelper();
|
|
|
|
File sourceFile = new File(dir, sqLiteOpenHelper.getDatabaseName());
|
|
|
|
helper.importDB(sqLiteOpenHelper, sourceFile);
|
|
|
|
helper.validateDB(sqLiteOpenHelper);
|
|
|
|
GB.toast(this, "Import successful.", Toast.LENGTH_LONG, GB.INFO);
|
2015-07-08 23:03:34 +02:00
|
|
|
} catch (Exception ex) {
|
2015-08-03 01:17:02 +02:00
|
|
|
GB.toast(this, "Error importing DB: " + ex.getMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
|
|
|
} finally {
|
|
|
|
if (dbHandler != null) {
|
|
|
|
dbHandler.release();
|
|
|
|
}
|
2015-07-08 23:03:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-07 12:58:18 +01:00
|
|
|
private void testNotification() {
|
2015-09-02 22:43:22 +02:00
|
|
|
Intent notificationIntent = new Intent(getApplicationContext(), DebugActivity.class);
|
|
|
|
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
|
|
|
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0,
|
|
|
|
notificationIntent, 0);
|
|
|
|
|
2015-02-07 12:58:18 +01:00
|
|
|
NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
|
|
|
NotificationCompat.Builder ncomp = new NotificationCompat.Builder(this);
|
2015-05-01 01:26:12 +02:00
|
|
|
ncomp.setContentTitle(getString(R.string.test_notification));
|
|
|
|
ncomp.setContentText(getString(R.string.this_is_a_test_notification_from_gadgetbridge));
|
|
|
|
ncomp.setTicker(getString(R.string.this_is_a_test_notification_from_gadgetbridge));
|
2015-04-03 22:39:25 +02:00
|
|
|
ncomp.setSmallIcon(R.drawable.ic_notification);
|
2015-02-07 12:58:18 +01:00
|
|
|
ncomp.setAutoCancel(true);
|
2015-09-02 22:43:22 +02:00
|
|
|
ncomp.setContentIntent(pendingIntent);
|
2015-02-07 12:58:18 +01:00
|
|
|
nManager.notify((int) System.currentTimeMillis(), ncomp.build());
|
|
|
|
}
|
|
|
|
|
2015-03-27 11:23:30 +01:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case android.R.id.home:
|
|
|
|
NavUtils.navigateUpFromSameTask(this);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
2015-02-07 12:58:18 +01:00
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
unregisterReceiver(mReceiver);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|