2015-07-28 17:30:20 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.activities;
|
2015-04-06 20:58:35 +02:00
|
|
|
|
|
|
|
import android.app.Activity;
|
2015-04-20 20:49:14 +02:00
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
2015-04-06 20:58:35 +02:00
|
|
|
import android.content.Intent;
|
2015-04-20 20:49:14 +02:00
|
|
|
import android.content.IntentFilter;
|
2015-04-06 20:58:35 +02:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.support.v4.app.NavUtils;
|
2015-04-20 20:49:14 +02:00
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
2015-04-06 20:58:35 +02:00
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2015-05-12 06:28:11 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.BluetoothCommunicationService;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp;
|
2015-05-01 01:49:43 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandFWHelper;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PBWReader;
|
2015-05-01 01:49:43 +02:00
|
|
|
|
2015-04-06 20:58:35 +02:00
|
|
|
|
2015-07-28 17:30:20 +02:00
|
|
|
public class FwAppInstallerActivity extends Activity {
|
2015-04-06 20:58:35 +02:00
|
|
|
|
2015-07-28 17:30:20 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(FwAppInstallerActivity.class);
|
2015-04-06 20:58:35 +02:00
|
|
|
|
2015-07-28 17:30:20 +02:00
|
|
|
TextView fwAppInstallTextView;
|
2015-04-06 20:58:35 +02:00
|
|
|
Button installButton;
|
|
|
|
|
2015-07-28 17:30:20 +02:00
|
|
|
// FIXME: abstraction for these would make code cleaner in this class
|
2015-04-20 20:49:14 +02:00
|
|
|
private PBWReader mPBWReader = null;
|
2015-07-28 17:30:20 +02:00
|
|
|
private MiBandFWHelper mFwReader = null;
|
|
|
|
|
2015-04-20 20:49:14 +02:00
|
|
|
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
String action = intent.getAction();
|
|
|
|
if (action.equals(ControlCenter.ACTION_QUIT)) {
|
|
|
|
finish();
|
|
|
|
} else if (action.equals(GBDevice.ACTION_DEVICE_CHANGED)) {
|
|
|
|
GBDevice dev = intent.getParcelableExtra("device");
|
2015-07-28 17:30:20 +02:00
|
|
|
if (dev.getType() == DeviceType.PEBBLE && mPBWReader != null) {
|
2015-04-20 20:49:14 +02:00
|
|
|
if (mPBWReader.isFirmware()) {
|
|
|
|
String hwRevision = mPBWReader.getHWRevision();
|
|
|
|
if (hwRevision != null && hwRevision.equals(dev.getHardwareVersion()) && dev.isConnected()) {
|
|
|
|
installButton.setEnabled(true);
|
|
|
|
} else {
|
|
|
|
installButton.setEnabled(false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
installButton.setEnabled(dev.isConnected());
|
|
|
|
}
|
2015-07-28 17:30:20 +02:00
|
|
|
} else if (dev.getType() == DeviceType.MIBAND && mFwReader != null) {
|
|
|
|
installButton.setEnabled(dev.isInitialized());
|
2015-04-20 20:49:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-06 20:58:35 +02:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_appinstaller);
|
|
|
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
2015-07-28 17:30:20 +02:00
|
|
|
fwAppInstallTextView = (TextView) findViewById(R.id.debugTextView);
|
2015-04-06 20:58:35 +02:00
|
|
|
installButton = (Button) findViewById(R.id.installButton);
|
2015-04-20 20:49:14 +02:00
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
filter.addAction(ControlCenter.ACTION_QUIT);
|
|
|
|
filter.addAction(GBDevice.ACTION_DEVICE_CHANGED);
|
|
|
|
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
|
2015-04-06 20:58:35 +02:00
|
|
|
|
|
|
|
final Uri uri = getIntent().getData();
|
2015-04-20 20:49:14 +02:00
|
|
|
mPBWReader = new PBWReader(uri, getApplicationContext());
|
2015-07-28 17:30:20 +02:00
|
|
|
if (mPBWReader.isValid()) {
|
|
|
|
GBDeviceApp app = mPBWReader.getGBDeviceApp();
|
|
|
|
|
|
|
|
if (mPBWReader.isFirmware()) {
|
|
|
|
fwAppInstallTextView.setText(getString(R.string.firmware_install_warning, mPBWReader.getHWRevision()));
|
2015-04-07 19:33:23 +02:00
|
|
|
|
2015-07-28 17:30:20 +02:00
|
|
|
} else if (app != null) {
|
|
|
|
fwAppInstallTextView.setText(getString(R.string.app_install_info, app.getName(), app.getVersion(), app.getCreator()));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mPBWReader = null;
|
|
|
|
mFwReader = new MiBandFWHelper(uri, getApplicationContext());
|
2015-04-17 12:23:19 +02:00
|
|
|
|
2015-07-28 17:30:20 +02:00
|
|
|
fwAppInstallTextView.setText(getString(R.string.fw_upgrade_notice, mFwReader.getHumanFirmwareVersion()));
|
|
|
|
|
|
|
|
if (mFwReader.isFirmwareWhitelisted()) {
|
|
|
|
fwAppInstallTextView.append(" " + getString(R.string.miband_firmware_known));
|
|
|
|
} else {
|
|
|
|
fwAppInstallTextView.append(" " + getString(R.string.miband_firmware_unknown_warning) + " " +
|
|
|
|
getString(R.string.miband_firmware_suggest_whitelist, mFwReader.getFirmwareVersion()));
|
|
|
|
}
|
2015-04-06 20:58:35 +02:00
|
|
|
}
|
2015-04-20 20:49:14 +02:00
|
|
|
|
|
|
|
installButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-07-28 17:30:20 +02:00
|
|
|
Intent startIntent = new Intent(FwAppInstallerActivity.this, BluetoothCommunicationService.class);
|
2015-07-23 12:09:01 +02:00
|
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_INSTALL);
|
|
|
|
startIntent.putExtra("uri", uri.toString());
|
2015-04-20 20:49:14 +02:00
|
|
|
startService(startIntent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Intent versionInfoIntent = new Intent(this, BluetoothCommunicationService.class);
|
|
|
|
versionInfoIntent.setAction(BluetoothCommunicationService.ACTION_REQUEST_VERSIONINFO);
|
|
|
|
startService(versionInfoIntent);
|
2015-04-06 20:58:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case android.R.id.home:
|
|
|
|
NavUtils.navigateUpFromSameTask(this);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
2015-04-20 20:49:14 +02:00
|
|
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
2015-04-06 20:58:35 +02:00
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
}
|