direct link from settings to huaweis protected apps

This commit is contained in:
Daniel Gultsch 2018-01-28 13:31:12 +01:00
parent 3e9224bde9
commit 4541ac8b7b
3 changed files with 28 additions and 1 deletions

View file

@ -7,6 +7,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@ -98,6 +99,15 @@ public class SettingsActivity extends XmppActivity implements
}
}
//this feature is only available on Huawei Android 6.
PreferenceScreen huaweiPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("huawei");
Intent intent = huaweiPreferenceScreen.getIntent();
//remove when Api version is above M (Version 6.0) or if the intent is not callable
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M || !isCallable(intent)) {
PreferenceCategory generalCategory = (PreferenceCategory) mSettingsFragment.findPreference("general");
generalCategory.removePreference(huaweiPreferenceScreen);
}
boolean removeLocation = new Intent("eu.siacs.conversations.location.request").resolveActivity(getPackageManager()) == null;
boolean removeVoice = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION).resolveActivity(getPackageManager()) == null;
@ -222,6 +232,11 @@ public class SettingsActivity extends XmppActivity implements
});
}
private boolean isCallable(Intent intent) {
return getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
}
private void cleanCache() {
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + getPackageName()));

View file

@ -733,4 +733,6 @@
<string name="message_copied_to_clipboard">Message copied to clipboard</string>
<string name="message">Message</string>
<string name="private_messages_are_disabled">Private messages are disabled</string>
<string name="huawei_protected_apps">Protected Apps</string>
<string name="huawei_protected_apps_summary">To keep receiving notifications, even when the screen is turned off, you need to add Conversations to the list of protected apps.</string>
</resources>

View file

@ -2,7 +2,8 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:background="?attr/color_background_secondary">
<PreferenceCategory android:title="@string/pref_general">
<PreferenceCategory android:title="@string/pref_general"
android:key="general">
<CheckBoxPreference
android:defaultValue="@bool/grant_new_contacts"
android:key="grant_new_contacts"
@ -16,6 +17,15 @@
android:key="resource"
android:summary="@string/pref_xmpp_resource_summary"
android:title="@string/pref_xmpp_resource"/>
<PreferenceScreen
android:key="huawei"
android:title="@string/huawei_protected_apps"
android:summary="@string/huawei_protected_apps_summary"
>
<intent
android:targetPackage="com.huawei.systemmanager"
android:targetClass="com.huawei.systemmanager.optimize.process.ProtectActivity"/>
</PreferenceScreen>
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_privacy">
<CheckBoxPreference