-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Kaiserdragon2/rework
Hopfully service now runs stable in the Background
- Loading branch information
Showing
7 changed files
with
121 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/src/main/java/de/kaiserdragon/callforwardingstatus/PhoneStateWorker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package de.kaiserdragon.callforwardingstatus; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.work.ListenableWorker; | ||
import androidx.work.Worker; | ||
import androidx.work.WorkerParameters; | ||
|
||
public class PhoneStateWorker extends Worker { | ||
public PhoneStateWorker( | ||
@NonNull Context context, | ||
@NonNull WorkerParameters params) { | ||
super(context, params); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Result doWork() { | ||
return null; | ||
} | ||
|
||
|
||
} |
49 changes: 49 additions & 0 deletions
49
app/src/main/java/de/kaiserdragon/callforwardingstatus/helper/CallForwardingListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package de.kaiserdragon.callforwardingstatus.helper; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Build; | ||
import android.telephony.TelephonyCallback; | ||
import android.util.Log; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.RequiresApi; | ||
|
||
import java.lang.ref.WeakReference; | ||
|
||
import de.kaiserdragon.callforwardingstatus.BuildConfig; | ||
import de.kaiserdragon.callforwardingstatus.ForwardingStatusWidget; | ||
import de.kaiserdragon.callforwardingstatus.PhoneStateService; | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.S) | ||
public class CallForwardingListener extends TelephonyCallback implements TelephonyCallback.CallForwardingIndicatorListener { | ||
|
||
private static final String TAG = "CallForwardingListener"; | ||
private static WeakReference<Context> contextRef; | ||
|
||
public CallForwardingListener(@NonNull Context context) { | ||
contextRef = new WeakReference<>(context); | ||
} | ||
|
||
@Override | ||
public void onCallForwardingIndicatorChanged(boolean callForwardingIndicator) { | ||
|
||
if (BuildConfig.DEBUG) { | ||
Log.i(TAG, "onCallForwardingIndicatorChanged - New CFI (different from last): " + callForwardingIndicator); | ||
|
||
PhoneStateService.currentState = callForwardingIndicator; | ||
sendWidgetUpdateBroadcast(callForwardingIndicator); | ||
} | ||
|
||
} | ||
|
||
private void sendWidgetUpdateBroadcast(boolean callForwardingIndicator) { | ||
Context context = contextRef.get(); | ||
Intent intent = new Intent(context, ForwardingStatusWidget.class); | ||
intent.setAction("de.kaiserdragon.callforwardingstatus.APPWIDGET_UPDATE_CFI"); | ||
// Add the CFI value as an extra | ||
intent.putExtra("cfi", callForwardingIndicator); | ||
// Send the broadcast | ||
context.sendBroadcast(intent); | ||
} | ||
} |