Skip to content

Commit

Permalink
Fix crash on null creator package
Browse files Browse the repository at this point in the history
  • Loading branch information
Johboh committed Mar 26, 2023
1 parent ade7d03 commit 897e53c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
6 changes: 2 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "com.fjun.hassalarm"
minSdkVersion 23
targetSdkVersion 33
versionCode 22
versionName "1.22"
versionCode 23
versionName "1.23"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
Expand Down Expand Up @@ -47,8 +47,6 @@ dependencies {
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.6.1")
kapt "androidx.room:room-compiler:2.5.1"
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation "com.google.auto.value:auto-value-annotations:1.7"
kapt "com.google.auto.value:auto-value:1.7"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
Expand Down
22 changes: 4 additions & 18 deletions app/src/main/java/com/fjun/hassalarm/NextAlarmUpdaterJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.fjun.hassalarm.history.AppDatabase;
import com.fjun.hassalarm.history.Publish;
import com.fjun.hassalarm.history.PublishDao;
import com.google.auto.value.AutoValue;

import java.io.IOException;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -62,7 +61,7 @@ public boolean onStartJob(JobParameters jobParameters) {
final long triggerTimestamp;
final String creatorPackage;
try {
final Request request = createRequest(this);
final UpdateRequest request = createRequest(this);
triggerTimestamp = request.triggerTimestamp();
creatorPackage = request.creatorPackage();
mCall = request.call();
Expand Down Expand Up @@ -134,7 +133,7 @@ public boolean onStopJob(JobParameters jobParameters) {
return true;
}

public Request createRequest(Context context) throws IllegalArgumentException {
public UpdateRequest createRequest(Context context) throws IllegalArgumentException {
final SharedPreferences sharedPreferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
String host = sharedPreferences.getString(KEY_PREFS_HOST, "");
final String apiKeyOrToken = sharedPreferences.getString(KEY_PREFS_API_KEY, "");
Expand All @@ -149,7 +148,7 @@ public Request createRequest(Context context) throws IllegalArgumentException {
* Create a call that can be executed. Will throw an exception in case of any failure,
* like missing parameters etc.
*/
public static Request createRequest(Context context,
public static UpdateRequest createRequest(Context context,
String host,
String apiKeyOrToken,
String entityId,
Expand Down Expand Up @@ -234,7 +233,7 @@ public static Request createRequest(Context context,
call = hassApi.setInputDatetimeUsingApiKey(datetime, apiKeyOrToken);
}
}
return Request.create(call, triggerTimestamp, creatorPackage);
return new UpdateRequest(triggerTimestamp, call, creatorPackage);
}

/**
Expand Down Expand Up @@ -302,17 +301,4 @@ private static int deadline(Context context) {
return (int)Math.min(MAX_EXECUTION_DELAY_MS, halfDiff);
}
}

@AutoValue
static abstract class Request {
public abstract Call<ResponseBody> call();

public abstract long triggerTimestamp();

public abstract String creatorPackage();

static Request create(Call<ResponseBody> call, long triggerTimestamp, String creatorPackage) {
return new AutoValue_NextAlarmUpdaterJob_Request(call, triggerTimestamp, creatorPackage);
}
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/fjun/hassalarm/Request.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.fjun.hassalarm

import okhttp3.ResponseBody
import retrofit2.Call

data class UpdateRequest(
@get:JvmName("triggerTimestamp")
val triggerTimestamp: Long,
@get:JvmName("call")
val call: Call<ResponseBody>,
@get:JvmName("creatorPackage")
val creatorPackage: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public class TestConnectionActivity extends AppCompatActivity {
private static final String EXTRA_ENTITY_ID_IS_LEGACY = "entity_id_is_legacy";

private String mStrippedLog;
private UpdateRequest mRequest;
private Boolean mLastRunWasSuccessful;
private NextAlarmUpdaterJob.Request mRequest;
private ActivityTestConnectionBinding mBinding;

private String mHost;
Expand Down

0 comments on commit 897e53c

Please sign in to comment.