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
This commit is contained in:
parent
19de84cd1b
commit
aa1f592e9f
@ -22,17 +22,18 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
|
import android.net.wifi.WifiInfo;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.net.wifi.WifiSsid;
|
import android.net.wifi.WifiSsid;
|
||||||
import android.net.wifi.WifiInfo;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import cyanogenmod.app.Profile;
|
import cyanogenmod.app.Profile;
|
||||||
|
import cyanogenmod.app.ProfileManager;
|
||||||
import cyanogenmod.providers.CMSettings;
|
import cyanogenmod.providers.CMSettings;
|
||||||
import org.cyanogenmod.platform.internal.ProfileManagerService;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -103,16 +104,27 @@ public class ProfileTriggerHelper extends BroadcastReceiver {
|
|||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
|
|
||||||
if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
|
if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
|
||||||
String activeSSID = getActiveSSID();
|
Bundle extras = intent.getExtras();
|
||||||
int triggerState;
|
WifiInfo wifiInfo = extras.getParcelable(WifiManager.EXTRA_WIFI_INFO);
|
||||||
|
if (wifiInfo != null) {
|
||||||
if (activeSSID != null) {
|
String ssid = wifiInfo.getSSID();
|
||||||
triggerState = Profile.TriggerState.ON_CONNECT;
|
if (ssid != null) {
|
||||||
mLastConnectedSSID = activeSSID;
|
// SSID will be surrounded by double quotation marks if it can be decoded
|
||||||
} else {
|
// as UTF-8
|
||||||
triggerState = Profile.TriggerState.ON_DISCONNECT;
|
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)
|
} else if (action.equals(BluetoothDevice.ACTION_ACL_CONNECTED)
|
||||||
|| action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) {
|
|| action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) {
|
||||||
int triggerState = action.equals(BluetoothDevice.ACTION_ACL_CONNECTED)
|
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) {
|
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()) {
|
for (Profile p : mManagerService.getProfileList()) {
|
||||||
if (newState != p.getTriggerState(type, id)) {
|
final int profileTriggerState = p.getTriggerState(type, id);
|
||||||
continue;
|
if (newState != profileTriggerState) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID currentProfileUuid = mManagerService.getActiveProfileInternal().getUuid();
|
|
||||||
if (!currentProfileUuid.equals(p.getUuid())) {
|
if (!currentProfileUuid.equals(p.getUuid())) {
|
||||||
mManagerService.setActiveProfileInternal(p, true);
|
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() {
|
private String getActiveSSID() {
|
||||||
|
@ -84,6 +84,29 @@ public class ProfileManager {
|
|||||||
public static final String INTENT_ACTION_PROFILE_UPDATED =
|
public static final String INTENT_ACTION_PROFILE_UPDATED =
|
||||||
"cyanogenmod.platform.intent.action.PROFILE_UPDATED";
|
"cyanogenmod.platform.intent.action.PROFILE_UPDATED";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final String INTENT_ACTION_PROFILE_TRIGGER_STATE_CHANGED =
|
||||||
|
"cyanogenmod.platform.intent.action.INTENT_ACTION_PROFILE_TRIGGER_STATE_CHANGED";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final String EXTRA_TRIGGER_ID = "trigger_id";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final String EXTRA_TRIGGER_TYPE = "trigger_type";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final String EXTRA_TRIGGER_STATE = "trigger_state";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extra for {@link #INTENT_ACTION_PROFILE_SELECTED} and {@link #INTENT_ACTION_PROFILE_UPDATED}:
|
* Extra for {@link #INTENT_ACTION_PROFILE_SELECTED} and {@link #INTENT_ACTION_PROFILE_UPDATED}:
|
||||||
* The name of the newly activated or updated profile
|
* The name of the newly activated or updated profile
|
||||||
|
Loading…
Reference in New Issue
Block a user