Commit 1804af43 authored by Румен Петров's avatar Румен Петров
Browse files

use "runtime" broadcast receiver for status of "TermOne Plus" applicatoon

This avoids restriction for implicit broadcasts on Android 8.0 (Oreo, API level 26) or newer.
parent a354b9f6
......@@ -55,14 +55,6 @@
<action android:name="com.termoneplus.broadcast.PREPEND_TO_PATH"/>
</intent-filter>
</receiver>
<receiver android:name=".TermOnePlusStatus">
<intent-filter android:priority="999">
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
<meta-data
android:name="android.max_aspect"
......
package com.termoneplus.securebox;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
......@@ -32,6 +33,7 @@ public class MainActivity extends AppCompatActivity {
private static final int REQUEST_PERMISSION_PREPEND_TO_PATH = 101;
public static Handler handler = null;
private BroadcastReceiver terminal_appstatus;
private View main_layout;
private Button install_terminal;
......@@ -108,10 +110,12 @@ public class MainActivity extends AppCompatActivity {
onTermOnePlusStatus();
handler = new MainHandler(this);
terminal_appstatus = TermOnePlusStatus.register(this, null);
}
@Override
protected void onPause() {
unregisterReceiver(terminal_appstatus);
handler = null;
super.onPause();
}
......
......@@ -3,6 +3,7 @@ package com.termoneplus.securebox;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
......@@ -10,6 +11,22 @@ import android.os.Message;
public class TermOnePlusStatus extends BroadcastReceiver {
public static BroadcastReceiver register(Context context, Handler scheduler) {
/*
* Quote from Android 8.0 (Oreo, API level 26), "Background Execution Limits":
* Application cannot use their manifest to register for implicit broadcasts.
* They can still register for these broadcasts at runtime.
*/
IntentFilter filter = new IntentFilter();
filter.setPriority(999);
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addDataScheme("package");
BroadcastReceiver receiver = new TermOnePlusStatus();
context.registerReceiver(receiver, filter, null, scheduler);
return receiver;
}
@Override
public void onReceive(Context context, Intent intent) {
Uri uri = intent.getData();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment