Pebble app installation: Only enable install button when device is connected, for firmware also check hardware revision
This commit is contained in:
parent
412c771d59
commit
5487dfd348
|
@ -45,6 +45,7 @@ public class PBWReader {
|
||||||
private GBDeviceApp app;
|
private GBDeviceApp app;
|
||||||
private ArrayList<PebbleInstallable> pebbleInstallables;
|
private ArrayList<PebbleInstallable> pebbleInstallables;
|
||||||
private boolean isFirmware = false;
|
private boolean isFirmware = false;
|
||||||
|
private String hwRevision = null;
|
||||||
|
|
||||||
public PBWReader(Uri uri, Context context) {
|
public PBWReader(Uri uri, Context context) {
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
|
@ -79,13 +80,13 @@ public class PBWReader {
|
||||||
String jsonString = baos.toString();
|
String jsonString = baos.toString();
|
||||||
try {
|
try {
|
||||||
JSONObject json = new JSONObject(jsonString);
|
JSONObject json = new JSONObject(jsonString);
|
||||||
String[] searchJSON;
|
|
||||||
HashMap<String, Byte> fileTypeMap;
|
HashMap<String, Byte> fileTypeMap;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
json.getJSONObject("firmware");
|
JSONObject firmware = json.getJSONObject("firmware");
|
||||||
fileTypeMap = fwFileTypesMap;
|
fileTypeMap = fwFileTypesMap;
|
||||||
isFirmware = true;
|
isFirmware = true;
|
||||||
|
hwRevision = firmware.getString("hwrev");
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
fileTypeMap = appFileTypesMap;
|
fileTypeMap = appFileTypesMap;
|
||||||
isFirmware = false;
|
isFirmware = false;
|
||||||
|
@ -179,4 +180,7 @@ public class PBWReader {
|
||||||
return pebbleInstallables.toArray(new PebbleInstallable[pebbleInstallables.size()]);
|
return pebbleInstallables.toArray(new PebbleInstallable[pebbleInstallables.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getHWRevision() {
|
||||||
|
return hwRevision;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,16 +1,22 @@
|
||||||
package nodomain.freeyourgadget.gadgetbridge.pebble;
|
package nodomain.freeyourgadget.gadgetbridge.pebble;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.NavUtils;
|
import android.support.v4.app.NavUtils;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.BluetoothCommunicationService;
|
import nodomain.freeyourgadget.gadgetbridge.BluetoothCommunicationService;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.ControlCenter;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBDeviceApp;
|
import nodomain.freeyourgadget.gadgetbridge.GBDeviceApp;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
|
|
||||||
|
@ -22,6 +28,31 @@ public class PebbleAppInstallerActivity extends Activity {
|
||||||
TextView debugTextView;
|
TextView debugTextView;
|
||||||
Button installButton;
|
Button installButton;
|
||||||
|
|
||||||
|
private PBWReader mPBWReader = null;
|
||||||
|
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");
|
||||||
|
if (mPBWReader != null) {
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -30,19 +61,22 @@ public class PebbleAppInstallerActivity extends Activity {
|
||||||
|
|
||||||
debugTextView = (TextView) findViewById(R.id.debugTextView);
|
debugTextView = (TextView) findViewById(R.id.debugTextView);
|
||||||
installButton = (Button) findViewById(R.id.installButton);
|
installButton = (Button) findViewById(R.id.installButton);
|
||||||
|
IntentFilter filter = new IntentFilter();
|
||||||
|
filter.addAction(ControlCenter.ACTION_QUIT);
|
||||||
|
filter.addAction(GBDevice.ACTION_DEVICE_CHANGED);
|
||||||
|
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
|
||||||
|
|
||||||
final Uri uri = getIntent().getData();
|
final Uri uri = getIntent().getData();
|
||||||
PBWReader pbwReader = new PBWReader(uri, getApplicationContext());
|
mPBWReader = new PBWReader(uri, getApplicationContext());
|
||||||
GBDeviceApp app = pbwReader.getGBDeviceApp();
|
GBDeviceApp app = mPBWReader.getGBDeviceApp();
|
||||||
|
|
||||||
if (pbwReader != null) {
|
if (mPBWReader.isFirmware()) {
|
||||||
if (pbwReader.isFirmware()) {
|
|
||||||
debugTextView.setText("YOUR ARE TRYING TO INSTALL A FIRMWARE, PROCEED AT YOUR OWN RISK, MAKE SURE THIS FIRMWARE IS FOR YOUR PEBBLE REVISION, THERE ARE NO CHECKS.\n\n\n");
|
debugTextView.setText("YOUR ARE TRYING TO INSTALL A FIRMWARE, PROCEED AT YOUR OWN RISK, MAKE SURE THIS FIRMWARE IS FOR YOUR PEBBLE REVISION, THERE ARE NO CHECKS.\n\n\n");
|
||||||
|
|
||||||
} else if (app != null) {
|
} else if (app != null) {
|
||||||
debugTextView.setText("You are about to install the following app:\n\n\n" + app.getName() + " Version " + app.getVersion() + " by " + app.getCreator() + "\n");
|
debugTextView.setText("You are about to install the following app:\n\n\n" + app.getName() + " Version " + app.getVersion() + " by " + app.getCreator() + "\n");
|
||||||
}
|
}
|
||||||
installButton.setEnabled(true);
|
|
||||||
installButton.setOnClickListener(new View.OnClickListener() {
|
installButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
@ -52,7 +86,9 @@ public class PebbleAppInstallerActivity extends Activity {
|
||||||
startService(startIntent);
|
startService(startIntent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
Intent versionInfoIntent = new Intent(this, BluetoothCommunicationService.class);
|
||||||
|
versionInfoIntent.setAction(BluetoothCommunicationService.ACTION_REQUEST_VERSIONINFO);
|
||||||
|
startService(versionInfoIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -67,6 +103,7 @@ public class PebbleAppInstallerActivity extends Activity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue