summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Birg <roman@cyngn.com>2016-01-08 15:14:46 -0800
committerGerrit Code Review <gerrit@cyanogenmod.org>2016-01-11 11:45:46 -0800
commitb7827e7bb2729a03ea912ce9f1d6acf9e8858cf2 (patch)
treebf940b165ee1d1ab97e8e045233540b1e0dec6d4
parent8b9411e20cbce5f870cb836fb6eda7078e208337 (diff)
downloadpackages_apps_Settings-b7827e7bb2729a03ea912ce9f1d6acf9e8858cf2.tar.gz
packages_apps_Settings-b7827e7bb2729a03ea912ce9f1d6acf9e8858cf2.tar.bz2
packages_apps_Settings-b7827e7bb2729a03ea912ce9f1d6acf9e8858cf2.zip
Settings: request runtime permissions inside VoiceWakeup
If the user has selected a Direct dial shortcut for their voice wakeup action, then the app which launches this intent must hold the dangerous permission CALL_PHONE. So when the user picks an intent which would require this permission, make sure VoiceWakeup requests and grants the permission. Otherwise reset to default. Ref: CYNGNOS-1560 Change-Id: I02e2c7a7d9958a5b15f438687f509802e75db704 Signed-off-by: Roman Birg <roman@cyngn.com>
-rw-r--r--res/values/cm_strings.xml1
-rw-r--r--src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java6
-rw-r--r--src/com/android/settings/voicewakeup/VoiceWakeupSettings.java44
3 files changed, 39 insertions, 12 deletions
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index e2ac804fc..4610ca553 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -908,6 +908,7 @@
<string name="voice_wakeup_retrain_title">Retrain your voice</string>
<string name="voice_wakeup_activity_title">Activity to launch</string>
<string name="voice_wakeup_default_activity">Google Now</string>
+ <string name="voice_wakeup_needs_dial_permission_warning">Voice Wakeup needs to have phone call permissions to select a Direct Dial contact.</string>
<string name="picker_activities">Activities</string>
<string name="select_custom_app_title">Select custom app</string>
diff --git a/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java b/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java
index 912d6a5bf..604d75f7b 100644
--- a/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java
+++ b/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java
@@ -65,6 +65,7 @@ import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settings.search.SearchIndexableRaw;
+import com.android.settings.voicewakeup.VoiceWakeupSettings;
import cyanogenmod.hardware.CMHardwareManager;
import cyanogenmod.providers.CMSettings;
@@ -100,8 +101,6 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
private static final String KEY_VOICE_CATEGORY = "voice_category";
private static final String KEY_VOICE_WAKEUP = "voice_wakeup";
- private static final String VOICE_WAKEUP_PACKAGE = "com.cyanogenmod.voicewakeup";
-
// false: on ICS or later
private static final boolean SHOW_INPUT_METHOD_SWITCHER_SETTINGS = false;
@@ -276,7 +275,8 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
}
if (!Utils.isUserOwner() ||
- !Utils.isPackageInstalled(getActivity(), VOICE_WAKEUP_PACKAGE, false)) {
+ !Utils.isPackageInstalled(getActivity(),
+ VoiceWakeupSettings.VOICE_WAKEUP_PACKAGE, false)) {
PreferenceCategory voiceCategory = (PreferenceCategory)
findPreference(KEY_VOICE_CATEGORY);
if (voiceCategory != null) {
diff --git a/src/com/android/settings/voicewakeup/VoiceWakeupSettings.java b/src/com/android/settings/voicewakeup/VoiceWakeupSettings.java
index 3db55304a..645437af0 100644
--- a/src/com/android/settings/voicewakeup/VoiceWakeupSettings.java
+++ b/src/com/android/settings/voicewakeup/VoiceWakeupSettings.java
@@ -16,48 +16,50 @@
package com.android.settings.voicewakeup;
-import android.app.ActionBar;
+import android.Manifest;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.Intent.ShortcutIconResource;
-import android.database.ContentObserver;
-import android.net.Uri;
+import android.content.pm.PackageManager;
import android.os.Bundle;
-import android.os.Handler;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
-import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
-import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-
+import android.widget.Toast;
import com.android.internal.logging.MetricsLogger;
-
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.cyanogenmod.BaseSystemSettingSwitchBar;
import com.android.settings.cyanogenmod.ShortcutPickHelper;
-
import org.cyanogenmod.internal.util.ScreenType;
+import java.net.URISyntaxException;
+
public class VoiceWakeupSettings extends SettingsPreferenceFragment implements
OnPreferenceChangeListener, ShortcutPickHelper.OnPickListener,
BaseSystemSettingSwitchBar.SwitchBarChangeCallback {
private static final String TAG = "VoiceWakeupSettings";
+ public static final int REQUEST_CALL_PERMS = 111;
+
private static final String KEY_RETRAIN = "retrain";
private static final String KEY_SHORTCUT_PICKER = "voice_wakeup_launch_intent";
+
+ public static final String VOICE_WAKEUP_PACKAGE = "com.cyanogenmod.voicewakeup";
private static final ComponentName VOICE_TRAINING_COMPONENT = new ComponentName(
"com.cyanogenmod.voicewakeup", "com.cyanogenmod.voicewakeup.VoiceTrainingActivity");
private static final ComponentName VOICE_TRAINING_SERVICE = new ComponentName(
"com.cyanogenmod.voicewakeup", "com.cyanogenmod.voicewakeup.VoiceWakeupEngine");
+ private static final String ACTION_REQUEST_DIAL_PERMISSION
+ = "com.cyanogenmod.voicewakeup.ACTION_REQUEST_DIAL_PERMISSION";
private BaseSystemSettingSwitchBar mVoiceWakeupEnabler;
@@ -164,8 +166,22 @@ public class VoiceWakeupSettings extends SettingsPreferenceFragment implements
return super.onPreferenceTreeClick(preferenceScreen, preference);
};
+ private boolean voiceWakeupHasCallPerms() {
+ return getPackageManager().checkPermission(Manifest.permission.CALL_PHONE,
+ VOICE_WAKEUP_PACKAGE) == PackageManager.PERMISSION_GRANTED;
+ }
+
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == REQUEST_CALL_PERMS) {
+ if (resultCode != Activity.RESULT_OK || !voiceWakeupHasCallPerms()) {
+ Toast.makeText(getActivity(), R.string.voice_wakeup_needs_dial_permission_warning,
+ Toast.LENGTH_SHORT).show();
+ // reset to default
+ shortcutPicked("", mDefaultActivityString, true);
+ }
+ return;
+ }
String shortcutName = null;
if (data != null) {
shortcutName = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
@@ -181,6 +197,16 @@ public class VoiceWakeupSettings extends SettingsPreferenceFragment implements
@Override
public void shortcutPicked(String uri, String friendlyName, boolean isApplication) {
+ try {
+ final Intent intent = Intent.parseUri(uri, 0);
+ if (intent.getAction().equals(Intent.ACTION_CALL)) {
+ Intent requestCallPerms = new Intent(ACTION_REQUEST_DIAL_PERMISSION);
+ requestCallPerms.setPackage(VOICE_WAKEUP_PACKAGE);
+ startActivityForResult(requestCallPerms, REQUEST_CALL_PERMS);
+ }
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ }
Settings.System.putString(getContentResolver(), Settings.System.VOICE_LAUNCH_INTENT, uri);
}