Make app direct boot aware
This commit is contained in:
parent
3dc63ee45b
commit
8179fd5e60
|
@ -62,6 +62,7 @@
|
||||||
<activity
|
<activity
|
||||||
android:name=".DummyDialerActivity"
|
android:name=".DummyDialerActivity"
|
||||||
android:autoRemoveFromRecents="true"
|
android:autoRemoveFromRecents="true"
|
||||||
|
android:directBootAware="true"
|
||||||
android:excludeFromRecents="true"
|
android:excludeFromRecents="true"
|
||||||
android:noHistory="true"
|
android:noHistory="true"
|
||||||
android:theme="@style/DialogBackgroundTheme">
|
android:theme="@style/DialogBackgroundTheme">
|
||||||
|
@ -82,6 +83,7 @@
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".CallReceiver"
|
android:name=".CallReceiver"
|
||||||
|
android:directBootAware="true"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
@ -93,6 +95,7 @@
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".CallScreeningServiceImpl"
|
android:name=".CallScreeningServiceImpl"
|
||||||
|
android:directBootAware="true"
|
||||||
android:permission="android.permission.BIND_SCREENING_SERVICE">
|
android:permission="android.permission.BIND_SCREENING_SERVICE">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.telecom.CallScreeningService" />
|
<action android:name="android.telecom.CallScreeningService" />
|
||||||
|
|
|
@ -2,6 +2,8 @@ package dummydomain.yetanothercallblocker;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
import org.conscrypt.Conscrypt;
|
import org.conscrypt.Conscrypt;
|
||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
@ -17,6 +19,14 @@ public class App extends Application {
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
private static Settings settings;
|
private static Settings settings;
|
||||||
|
|
||||||
|
public static App getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Settings getSettings() {
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
@ -25,7 +35,9 @@ public class App extends Application {
|
||||||
|
|
||||||
Security.insertProviderAt(Conscrypt.newProvider(), 1);
|
Security.insertProviderAt(Conscrypt.newProvider(), 1);
|
||||||
|
|
||||||
settings = new Settings(this);
|
new DeviceProtectedStorageMigrator().migrate(this);
|
||||||
|
|
||||||
|
settings = new Settings(getDeviceProtectedStorageContext());
|
||||||
settings.init();
|
settings.init();
|
||||||
|
|
||||||
EventBus.builder()
|
EventBus.builder()
|
||||||
|
@ -38,15 +50,15 @@ public class App extends Application {
|
||||||
|
|
||||||
NotificationHelper.createNotificationChannels(this);
|
NotificationHelper.createNotificationChannels(this);
|
||||||
|
|
||||||
Config.init(this, settings);
|
Config.init(getDeviceProtectedStorageContext(), settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static App getInstance() {
|
private Context getDeviceProtectedStorageContext() {
|
||||||
return instance;
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
return createDeviceProtectedStorageContext();
|
||||||
|
} else {
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Settings getSettings() {
|
|
||||||
return settings;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
package dummydomain.yetanothercallblocker;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.channels.FileChannel;
|
||||||
|
|
||||||
|
import dummydomain.yetanothercallblocker.data.SiaConstants;
|
||||||
|
import dummydomain.yetanothercallblocker.sia.utils.FileUtils;
|
||||||
|
|
||||||
|
public class DeviceProtectedStorageMigrator {
|
||||||
|
|
||||||
|
public void migrate(Context context) {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Context dpsContext = context.createDeviceProtectedStorageContext();
|
||||||
|
|
||||||
|
if (new Settings(dpsContext).getInt(Settings.SYS_PREFERENCES_VERSION, -1) != -1) return;
|
||||||
|
if (new Settings(context).getInt(Settings.SYS_PREFERENCES_VERSION, -1) == -1) return;
|
||||||
|
|
||||||
|
copyDir(context, dpsContext, SiaConstants.SIA_PATH_PREFIX);
|
||||||
|
copyDir(context, dpsContext, SiaConstants.SIA_SECONDARY_PATH_PREFIX);
|
||||||
|
|
||||||
|
dpsContext.moveSharedPreferencesFrom(context, SiaConstants.SIA_PROPERTIES);
|
||||||
|
dpsContext.moveSharedPreferencesFrom(context, context.getPackageName() + "_preferences");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void copyDir(Context srcContext, Context dstContext, String dir) throws IOException {
|
||||||
|
File srcDir = new File(srcContext.getFilesDir(), dir);
|
||||||
|
if (srcDir.exists()) {
|
||||||
|
File dstDir = new File(dstContext.getFilesDir(), dir);
|
||||||
|
|
||||||
|
dstDir.mkdir();
|
||||||
|
copyDirectoryContent(srcDir, dstDir);
|
||||||
|
|
||||||
|
FileUtils.delete(srcDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void copyDirectoryContent(File src, File dst) throws IOException {
|
||||||
|
for (String file : src.list()) {
|
||||||
|
File srcFile = new File(src, file);
|
||||||
|
File dstFile = new File(dst, file);
|
||||||
|
|
||||||
|
dstFile.createNewFile();
|
||||||
|
try (FileChannel source = new FileInputStream(srcFile).getChannel();
|
||||||
|
FileChannel destination = new FileOutputStream(dstFile).getChannel()) {
|
||||||
|
destination.transferFrom(source, 0, source.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -20,7 +20,7 @@ public class Settings extends GenericSettings {
|
||||||
public static final String PREF_COUNTRY_CODE_OVERRIDE = "countryCodeOverride";
|
public static final String PREF_COUNTRY_CODE_OVERRIDE = "countryCodeOverride";
|
||||||
public static final String PREF_COUNTRY_CODE_FOR_REVIEWS_OVERRIDE = "countryCodeForReviewsOverride";
|
public static final String PREF_COUNTRY_CODE_FOR_REVIEWS_OVERRIDE = "countryCodeForReviewsOverride";
|
||||||
|
|
||||||
private static final String SYS_PREFERENCES_VERSION = "__preferencesVersion";
|
static final String SYS_PREFERENCES_VERSION = "__preferencesVersion";
|
||||||
|
|
||||||
private static final int PREFERENCES_VERSION = 1;
|
private static final int PREFERENCES_VERSION = 1;
|
||||||
|
|
||||||
|
|
|
@ -99,6 +99,8 @@ public class SettingsActivity extends AppCompatActivity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||||
|
getPreferenceManager().setStorageDeviceProtected();
|
||||||
|
|
||||||
setPreferencesFromResource(R.xml.root_preferences, rootKey);
|
setPreferencesFromResource(R.xml.root_preferences, rootKey);
|
||||||
|
|
||||||
initRootScreen(rootKey);
|
initRootScreen(rootKey);
|
||||||
|
|
Loading…
Reference in New Issue