1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-26 10:35:50 +01:00

Pebble: make watchapp installation available on FW 3.x without the need for setting an option

This commit is contained in:
Andreas Shimokawa 2015-08-17 18:07:47 +02:00
parent 9dd2f039f2
commit 6fede31bdf
6 changed files with 11 additions and 24 deletions

View File

@ -5,9 +5,7 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.NavUtils; import android.support.v4.app.NavUtils;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.view.ContextMenu; import android.view.ContextMenu;
@ -25,7 +23,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAppAdapter; import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAppAdapter;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp;
@ -105,13 +102,9 @@ public class AppManagerActivity extends Activity {
registerForContextMenu(appListView); registerForContextMenu(appListView);
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext()); List<GBDeviceApp> cachedApps = getCachedApps();
for (GBDeviceApp app : cachedApps) {
if (sharedPrefs.getBoolean("pebble_force_untested", false)) { appList.add(app);
List<GBDeviceApp> cachedApps = getCachedApps();
for (GBDeviceApp app : cachedApps) {
appList.add(app);
}
} }
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();

View File

@ -101,7 +101,7 @@ public class FwAppInstallerActivity extends Activity implements InstallActivity
@Override @Override
public void onClick(View v) { public void onClick(View v) {
setInstallEnabled(false); setInstallEnabled(false);
installHandler.onStartInstall(); installHandler.onStartInstall(device);
Intent startIntent = new Intent(FwAppInstallerActivity.this, DeviceCommunicationService.class); Intent startIntent = new Intent(FwAppInstallerActivity.this, DeviceCommunicationService.class);
startIntent.setAction(DeviceCommunicationService.ACTION_INSTALL); startIntent.setAction(DeviceCommunicationService.ACTION_INSTALL);
startIntent.putExtra("uri", uri); startIntent.putExtra("uri", uri);

View File

@ -19,16 +19,16 @@ public interface InstallHandler {
* Checks whether the installation of the 'element' on the device is possible * Checks whether the installation of the 'element' on the device is possible
* and configures the InstallActivity accordingly (sets helpful texts, * and configures the InstallActivity accordingly (sets helpful texts,
* enables/disables the "Install" button, etc. * enables/disables the "Install" button, etc.
* * <p/>
* Note: may only be called if #isValid previously returned true. * Note: may only be called if #isValid previously returned true.
* *
* @param installActivity the activity to interact with * @param installActivity the activity to interact with
* @param device the device to which the element shall be installed * @param device the device to which the element shall be installed
*/ */
void validateInstallation(InstallActivity installActivity, GBDevice device); void validateInstallation(InstallActivity installActivity, GBDevice device);
/** /**
* Allows device specivic code to be execute just before the installation starts * Allows device specivic code to be execute just before the installation starts
*/ */
void onStartInstall(); void onStartInstall(GBDevice device);
} }

View File

@ -53,7 +53,7 @@ public class MiBandFWInstallHandler implements InstallHandler {
} }
@Override @Override
public void onStartInstall() { public void onStartInstall(GBDevice device) {
} }

View File

@ -1,14 +1,11 @@
package nodomain.freeyourgadget.gadgetbridge.devices.pebble; package nodomain.freeyourgadget.gadgetbridge.devices.pebble;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.preference.PreferenceManager;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.InstallActivity; import nodomain.freeyourgadget.gadgetbridge.activities.InstallActivity;
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
@ -59,13 +56,12 @@ public class PBWInstallHandler implements InstallHandler {
} }
@Override @Override
public void onStartInstall() { public void onStartInstall(GBDevice device) {
if (mPBWReader.isFirmware()) { if (mPBWReader.isFirmware()) {
return; return;
} }
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext()); if (!device.getFirmwareVersion().startsWith("v3")) {
if (!sharedPrefs.getBoolean("pebble_force_untested", false)) {
return; return;
} }

View File

@ -45,7 +45,6 @@ public class PebbleIoThread extends GBDeviceIoThread {
private boolean mIsConnected = false; private boolean mIsConnected = false;
private boolean mIsInstalling = false; private boolean mIsInstalling = false;
private int mConnectionAttempts = 0; private int mConnectionAttempts = 0;
private boolean mForceUntested = false;
private PBWReader mPBWReader = null; private PBWReader mPBWReader = null;
private int mAppInstallToken = -1; private int mAppInstallToken = -1;
private ZipInputStream mZis = null; private ZipInputStream mZis = null;
@ -86,7 +85,6 @@ public class PebbleIoThread extends GBDeviceIoThread {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
mPebbleProtocol.setForceProtocol(sharedPrefs.getBoolean("pebble_force_protocol", false)); mPebbleProtocol.setForceProtocol(sharedPrefs.getBoolean("pebble_force_protocol", false));
mForceUntested = sharedPrefs.getBoolean("pebble_force_untested", false);
gbDevice.setState(GBDevice.State.CONNECTED); gbDevice.setState(GBDevice.State.CONNECTED);
gbDevice.sendDeviceUpdateIntent(getContext()); gbDevice.sendDeviceUpdateIntent(getContext());
@ -409,7 +407,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
writeInstallApp(mPebbleProtocol.encodeGetTime()); writeInstallApp(mPebbleProtocol.encodeGetTime());
} else { } else {
GBDeviceApp app = mPBWReader.getGBDeviceApp(); GBDeviceApp app = mPBWReader.getGBDeviceApp();
if (mPebbleProtocol.isFw3x && mForceUntested) { if (mPebbleProtocol.isFw3x) {
if (appId == 0) { if (appId == 0) {
// only install metadata - not the binaries // only install metadata - not the binaries
write(mPebbleProtocol.encodeInstallMetadata(app.getUUID(), app.getName(), mPBWReader.getAppVersion(), mPBWReader.getSdkVersion(), mPBWReader.getIconId())); write(mPebbleProtocol.encodeInstallMetadata(app.getUUID(), app.getName(), mPBWReader.getAppVersion(), mPBWReader.getSdkVersion(), mPBWReader.getIconId()));