Skip to content

Commit

Permalink
Merge pull request #62 from hmatalonga/dev
Browse files Browse the repository at this point in the history
Release v1.0-RC.1
  • Loading branch information
hmatalonga authored May 28, 2017
2 parents 08c6158 + 4bbfda3 commit 35f4e00
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 21 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ build/

# Local configuration file (sdk path, etc)
local.properties
keystore.properties

# Proguard folder generated by Eclipse
proguard/
Expand Down Expand Up @@ -50,4 +51,9 @@ battery_class.txt
gradlelog.txt
app/src/release/google-services.json
app/src/debug/google-services.json
app/pepk.jar
app/pepk.jar

# Upload private keys
app/upload_certificate.pem
app/greenhub-private-key.keystore
app/greenhub-upload.jks
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 17 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
apply plugin: 'com.android.application'
apply plugin: 'realm-android'

def keystorePropertiesFile = rootProject.file("keystore.properties")
// Initialize a new Properties() object called keystoreProperties.
def keystoreProperties = new Properties()
// Load your keystore.properties file into the keystoreProperties object.
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
signingConfigs {
base {
debug {
keyAlias 'GreenHubKey'
keyPassword 'greenhub'
storeFile file('greenhub-key.jks')
storeFile file('greenhub-key-debug.jks')
storePassword 'greenhub'
}
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
defaultConfig {
applicationId 'com.hmatalonga.greenhub'
Expand All @@ -19,20 +31,20 @@ android {
versionCode 10
versionName 'v1.0-RC.1'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
signingConfig signingConfigs.base
signingConfig signingConfigs.debug
}
buildTypes {
debug {
applicationIdSuffix '.debug'
debuggable true
minifyEnabled false
signingConfig signingConfigs.base
signingConfig signingConfigs.debug
}
release {
debuggable false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.base
signingConfig signingConfigs.release
zipAlignEnabled true
}
}
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@
android:theme="@style/Theme.GreenHub">

<meta-data android:name="AA_DB_NAME" android:value="GreenHub.db" />
<meta-data android:name="AA_DB_VERSION" android:value="1" />

<activity
android:name=".ui.SplashActivity"
android:theme="@style/Theme.GreenHub.Splash">
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/hmatalonga/greenhub/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public final class Config {
public static final String SERVER_URL_DEFAULT = "none";
public static final String SERVER_URL_DEVELOPMENT = "http://192.168.1.117:8080";

public static final int DATABASE_VERSION = 2;

// Alarm event for sampling when battery has not changed for
// SAMPLE_INTERVAL_MS. Currently not used.
public static final String ACTION_GREENHUB_SAMPLE = "com.hmatalonga.greenhub.ACTION_SAMPLE";
Expand Down
30 changes: 29 additions & 1 deletion app/src/main/java/com/hmatalonga/greenhub/GreenHubApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@
import com.hmatalonga.greenhub.util.LogUtils;
import com.hmatalonga.greenhub.util.Notifier;
import com.hmatalonga.greenhub.util.SettingsUtils;

import io.realm.DynamicRealm;
import io.realm.FieldAttribute;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import io.realm.RealmMigration;
import io.realm.RealmSchema;

import static com.hmatalonga.greenhub.util.LogUtils.LOGI;
import static com.hmatalonga.greenhub.util.LogUtils.makeLogTag;
Expand Down Expand Up @@ -65,7 +70,10 @@ public void onCreate() {

// Database init
Realm.init(this);
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().build();
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder()
.schemaVersion(Config.DATABASE_VERSION)
.migration(buildMigration())
.build();
Realm.setDefaultConfiguration(realmConfiguration);

LOGI(TAG, "Estimator new instance");
Expand Down Expand Up @@ -145,4 +153,24 @@ public void stopStatusBarUpdater() {
mAlarmManager.cancel(mNotificationIntent);
}
}

private RealmMigration buildMigration() {
return new RealmMigration() {
@Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {

// DynamicRealm exposes an editable schema
RealmSchema schema = realm.getSchema();

// Migrate to version 1: Add a new field.
// public Sample extends RealmObject {
// public int version;
// }
if (oldVersion == 1) {
schema.get("Sample")
.addField("version", int.class);
}
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ static Sample getSample(final Context context, Intent intent, String lastBattery
newSample.triggeredBy = action;
newSample.timestamp = System.currentTimeMillis();
newSample.id = String.valueOf(newSample.timestamp).hashCode();
newSample.version = SettingsUtils.fetchAppVersion(context);

// Record first data point for CPU usage
long[] idleAndCpu1 = Cpu.readUsagePoint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class Sample extends RealmObject {
@Index
public long timestamp;

// Mobile app version of sample
public int version;

// State of the battery. ie. charging, discharging, etc.
public String batteryState;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ private JsonObject bundleSample(final Sample sample) {

root.addProperty("uuId", sample.uuId);
root.addProperty("timestamp", sample.timestamp);
root.addProperty("version", sample.version);
root.addProperty("batteryState", sample.batteryState);
root.addProperty("batteryLevel", sample.batteryLevel);
root.addProperty("memoryWired", sample.memoryWired);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ public void onResponse(Call<ServerStatus> call, Response<ServerStatus> response)
LOGI(TAG, "Server Status: { server: " + response.body().server + ", version: " + response.body().version + " }");

// Server url has changed so it is necessary to register device again
if (!SettingsUtils.fetchServerUrl(context).equals(response.body().server)) {
if (! SettingsUtils.fetchServerUrl(context).equals(response.body().server)) {
SettingsUtils.markDeviceAccepted(context, false);
}

// Save new server url
SettingsUtils.saveServerUrl(context, response.body().server);
// Save most recent app version
SettingsUtils.saveAppVersion(context, response.body().version);

// Register device on the web server
if (!SettingsUtils.isDeviceRegistered(context)) {
if (! SettingsUtils.isDeviceRegistered(context)) {
new RegisterDeviceTask().execute(context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.hmatalonga.greenhub.BuildConfig;
import com.hmatalonga.greenhub.Config;
import com.hmatalonga.greenhub.ui.TaskListActivity;
import com.hmatalonga.greenhub.ui.WelcomeActivity;
Expand Down Expand Up @@ -223,7 +224,6 @@ public static int fetchUploadRate(final Context context) {
);
}


public static int fetchNotificationsPriority(final Context context) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
return Integer.parseInt(
Expand Down Expand Up @@ -303,6 +303,27 @@ public static void markSystemAppsHidden(final Context context, boolean newValue)
sp.edit().putBoolean(PREF_HIDE_SYSTEM_APPS, newValue).apply();
}

/**
* Save the most recent app version {@code version}.
*
* @param context Context to be used to edit the {@link android.content.SharedPreferences}.
* @param version New value that will be set.
*/
public static void saveAppVersion(final Context context, int version) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
sp.edit().putInt(PREF_APP_VERSION, version).apply();
}

/**
* Fetch the most recent app version {@code version}.
*
* @param context Context to be used to edit the {@link android.content.SharedPreferences}.
*/
public static int fetchAppVersion(final Context context) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
return sp.getInt(PREF_APP_VERSION, BuildConfig.VERSION_CODE);
}

/**
* Helper method to register a settings_prefs listener. This method does not automatically handle
* {@code unregisterOnSharedPreferenceChangeListener() un-registering} the listener at the end
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'io.realm:realm-gradle-plugin:2.3.0'
classpath 'io.realm:realm-gradle-plugin:3.3.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
7 changes: 1 addition & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,10 @@ org.gradle.jvmargs=-Xmx1536M
# App variables.
###############################################################################
# The AndroidManifest.xml must also be updated currently.
build_tools_version = 25.0.2
build_tools_version = 25.0.3

version_code = 10
version_name = v1.0-RC.1

key_storefile = ../app/greenhub-key.jks
key_storePassword = greenhub
key_keyAlias = GreenHubKey
key_keyPassword = greenhub

# Using these variables to sync dependency version numbers across sub-projects.
android_support_lib_version = 25.3.1

0 comments on commit 35f4e00

Please sign in to comment.