aboutsummaryrefslogtreecommitdiffstats
path: root/cm
diff options
context:
space:
mode:
authorLuis Vidal <lvidal@cyngn.com>2016-06-06 13:10:00 -0700
committerGerrit Code Review <gerrit@cyanogenmod.org>2016-06-08 17:04:59 -0700
commitaa1f592e9feec75a1c2d05c2d60d5ef48a3956c0 (patch)
tree0399ba6f42033cacfba27496432d591ff92e98f4 /cm
parent19de84cd1bb7865cb6bc9ed5baf5d3e882583b63 (diff)
downloadvendor_cmsdk-aa1f592e9feec75a1c2d05c2d60d5ef48a3956c0.zip
vendor_cmsdk-aa1f592e9feec75a1c2d05c2d60d5ef48a3956c0.tar.gz
vendor_cmsdk-aa1f592e9feec75a1c2d05c2d60d5ef48a3956c0.tar.bz2
Ensures ProfileTrustAgent properly grants/revokes trust [2/2]
Notifies the ProfileTrustAgent when a WiFi/BT event was triggered even if no new profile was selected so the trust agent can grant/revoke trust Filters out the multiple network state change notifications to make sure we notify the trust agent only when the event that the profile is tracking actually happened Change-Id: I047861a8b145762fff24568e341373a89ee01de9 TICKET: CYNGNOS-2719
Diffstat (limited to 'cm')
-rw-r--r--cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileTriggerHelper.java67
1 files changed, 50 insertions, 17 deletions
diff --git a/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileTriggerHelper.java b/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileTriggerHelper.java
index 804117f..48110af 100644
--- a/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileTriggerHelper.java
+++ b/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileTriggerHelper.java
@@ -22,17 +22,18 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.ContentObserver;
+import android.net.NetworkInfo;
+import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiSsid;
-import android.net.wifi.WifiInfo;
+import android.os.Bundle;
import android.os.Handler;
-
+import android.os.UserHandle;
+import android.text.TextUtils;
import android.util.Log;
-
import cyanogenmod.app.Profile;
-
+import cyanogenmod.app.ProfileManager;
import cyanogenmod.providers.CMSettings;
-import org.cyanogenmod.platform.internal.ProfileManagerService;
import java.util.UUID;
@@ -103,16 +104,27 @@ public class ProfileTriggerHelper extends BroadcastReceiver {
String action = intent.getAction();
if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
- String activeSSID = getActiveSSID();
- int triggerState;
-
- if (activeSSID != null) {
- triggerState = Profile.TriggerState.ON_CONNECT;
- mLastConnectedSSID = activeSSID;
- } else {
- triggerState = Profile.TriggerState.ON_DISCONNECT;
+ Bundle extras = intent.getExtras();
+ WifiInfo wifiInfo = extras.getParcelable(WifiManager.EXTRA_WIFI_INFO);
+ if (wifiInfo != null) {
+ String ssid = wifiInfo.getSSID();
+ if (ssid != null) {
+ // SSID will be surrounded by double quotation marks if it can be decoded
+ // as UTF-8
+ if (ssid.startsWith("\"") && ssid.endsWith("\"")) {
+ ssid = ssid.substring(1, ssid.length()-1);
+ }
+ if (TextUtils.equals(ssid, WifiSsid.NONE)) {
+ checkTriggers(Profile.TriggerType.WIFI, mLastConnectedSSID,
+ Profile.TriggerState.ON_DISCONNECT);
+ mLastConnectedSSID = WifiSsid.NONE;
+ } else if (!TextUtils.equals(mLastConnectedSSID, ssid)) {
+ mLastConnectedSSID = ssid;
+ checkTriggers(Profile.TriggerType.WIFI, mLastConnectedSSID,
+ Profile.TriggerState.ON_CONNECT);
+ }
+ }
}
- checkTriggers(Profile.TriggerType.WIFI, mLastConnectedSSID, triggerState);
} else if (action.equals(BluetoothDevice.ACTION_ACL_CONNECTED)
|| action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) {
int triggerState = action.equals(BluetoothDevice.ACTION_ACL_CONNECTED)
@@ -133,16 +145,37 @@ public class ProfileTriggerHelper extends BroadcastReceiver {
}
private void checkTriggers(int type, String id, int newState) {
+ final Profile activeProfile = mManagerService.getActiveProfileInternal();
+ final UUID currentProfileUuid = activeProfile.getUuid();
+
+ boolean newProfileSelected = false;
for (Profile p : mManagerService.getProfileList()) {
- if (newState != p.getTriggerState(type, id)) {
- continue;
+ final int profileTriggerState = p.getTriggerState(type, id);
+ if (newState != profileTriggerState) {
+ continue;
}
- UUID currentProfileUuid = mManagerService.getActiveProfileInternal().getUuid();
if (!currentProfileUuid.equals(p.getUuid())) {
mManagerService.setActiveProfileInternal(p, true);
+ newProfileSelected = true;
}
}
+
+ if (!newProfileSelected) {
+ //Does the active profile actually cares about this event?
+ for (Profile.ProfileTrigger trigger : activeProfile.getTriggersFromType(type)) {
+ if (trigger.getId().equals(id)) {
+ Intent intent
+ = new Intent(ProfileManager.INTENT_ACTION_PROFILE_TRIGGER_STATE_CHANGED);
+ intent.putExtra(ProfileManager.EXTRA_TRIGGER_ID, id);
+ intent.putExtra(ProfileManager.EXTRA_TRIGGER_TYPE, type);
+ intent.putExtra(ProfileManager.EXTRA_TRIGGER_STATE, newState);
+ mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
+ break;
+ }
+ }
+
+ }
}
private String getActiveSSID() {