aboutsummaryrefslogtreecommitdiffstats
path: root/cm/lib/main
diff options
context:
space:
mode:
authorAdnan Begovic <adnan@cyngn.com>2015-06-30 15:57:24 -0700
committerAdnan Begovic <adnan@cyngn.com>2015-07-01 01:04:29 -0700
commitcc979035e78ff936f3ebf64dcbb316cd38c31f0f (patch)
tree6936c17855dffc89aa50a0501a904c8d2f354bf4 /cm/lib/main
parent4334b3d969ba557c33106f4894878cac2760c051 (diff)
downloadvendor_cmsdk-cc979035e78ff936f3ebf64dcbb316cd38c31f0f.zip
vendor_cmsdk-cc979035e78ff936f3ebf64dcbb316cd38c31f0f.tar.gz
vendor_cmsdk-cc979035e78ff936f3ebf64dcbb316cd38c31f0f.tar.bz2
CMSDK: Make sure to initialize ProfileTriggerHelper.
OSS-JIRA: NIGHTLIES-1480 Change-Id: I48fbb350d96424b593858aca1b2343a79f298b0c
Diffstat (limited to 'cm/lib/main')
-rw-r--r--cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileManagerService.java14
-rw-r--r--cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileTriggerHelper.java151
2 files changed, 161 insertions, 4 deletions
diff --git a/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileManagerService.java b/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileManagerService.java
index 08861ec..4ba0f3f 100644
--- a/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileManagerService.java
+++ b/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileManagerService.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011-2014 CyanogenMod Project
+ * Copyright (c) 2011-2015 CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -82,6 +82,7 @@ public class ProfileManagerService extends SystemService {
private Context mContext;
private boolean mDirty;
private BackupManager mBackupManager;
+ private ProfileTriggerHelper mTriggerHelper;
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
@@ -124,6 +125,7 @@ public class ProfileManagerService extends SystemService {
}
private void initialize(boolean skipFile) {
+ mTriggerHelper = new ProfileTriggerHelper(mContext, this);
mProfiles = new HashMap<UUID, Profile>();
mProfileNames = new HashMap<String, UUID>();
mGroups = new HashMap<UUID, NotificationGroup>();
@@ -221,7 +223,7 @@ public class ProfileManagerService extends SystemService {
@Override
public Profile getProfile(ParcelUuid profileParcelUuid) {
UUID profileUuid = profileParcelUuid.getUuid();
- return internalGetProfile(profileUuid);
+ return getProfileInternal(profileUuid);
}
@Override
@@ -233,7 +235,7 @@ public class ProfileManagerService extends SystemService {
@Override
public Profile getActiveProfile() {
- return mActiveProfile;
+ return getActiveProfileInternal();
}
@Override
@@ -394,7 +396,7 @@ public class ProfileManagerService extends SystemService {
profile.addProfileGroup(new ProfileGroup(group.getUuid(), defaultGroup));
}
- private Profile internalGetProfile(UUID profileUuid) {
+ private Profile getProfileInternal(UUID profileUuid) {
// use primary UUID first
if (mProfiles.containsKey(profileUuid)) {
return mProfiles.get(profileUuid);
@@ -556,6 +558,10 @@ public class ProfileManagerService extends SystemService {
return true;
}
+ /* package */ Profile getActiveProfileInternal() {
+ return mActiveProfile;
+ }
+
/* package */ void setActiveProfileInternal(Profile newActiveProfile, boolean doInit) {
/*
* NOTE: Since this is not a public function, and all public functions
diff --git a/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileTriggerHelper.java b/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileTriggerHelper.java
new file mode 100644
index 0000000..928a719
--- /dev/null
+++ b/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileTriggerHelper.java
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2013-2014 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.cyanogenmod.platform.internal;
+
+import android.bluetooth.BluetoothDevice;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.database.ContentObserver;
+import android.net.wifi.WifiManager;
+import android.net.wifi.WifiSsid;
+import android.net.wifi.WifiInfo;
+import android.os.Handler;
+import android.provider.Settings;
+import android.util.Log;
+
+import cyanogenmod.app.Profile;
+
+import org.cyanogenmod.platform.internal.ProfileManagerService;
+
+import java.util.UUID;
+
+/**
+ * @hide
+ */
+public class ProfileTriggerHelper extends BroadcastReceiver {
+ private static final String TAG = "ProfileTriggerHelper";
+
+ private Context mContext;
+ private ProfileManagerService mManagerService;
+
+ private WifiManager mWifiManager;
+ private String mLastConnectedSSID;
+
+ private IntentFilter mIntentFilter;
+ private boolean mFilterRegistered = false;
+
+ private ContentObserver mSettingsObserver = new ContentObserver(new Handler()) {
+ @Override
+ public void onChange(boolean selfChange) {
+ updateEnabled();
+ }
+ };
+
+ public ProfileTriggerHelper(Context context, ProfileManagerService profileManagerService) {
+ mContext = context;
+ mManagerService = profileManagerService;
+
+ mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
+ mLastConnectedSSID = getActiveSSID();
+
+ mIntentFilter = new IntentFilter();
+ mIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
+ mIntentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
+ mIntentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
+ // mIntentFilter.addAction(AudioManager.A2DP_ROUTE_CHANGED_ACTION);
+ updateEnabled();
+
+ mContext.getContentResolver().registerContentObserver(
+ Settings.System.getUriFor(Settings.System.SYSTEM_PROFILES_ENABLED), false,
+ mSettingsObserver);
+ }
+
+ public void updateEnabled() {
+ boolean enabled = Settings.System.getInt(mContext.getContentResolver(),
+ Settings.System.SYSTEM_PROFILES_ENABLED, 1) == 1;
+ if (enabled && !mFilterRegistered) {
+ Log.v(TAG, "Enabling");
+ mContext.registerReceiver(this, mIntentFilter);
+ mFilterRegistered = true;
+ } else if (!enabled && mFilterRegistered) {
+ Log.v(TAG, "Disabling");
+ mContext.unregisterReceiver(this);
+ mFilterRegistered = false;
+ }
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ 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;
+ }
+ 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)
+ ? Profile.TriggerState.ON_CONNECT : Profile.TriggerState.ON_DISCONNECT;
+ BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+
+ checkTriggers(Profile.TriggerType.BLUETOOTH, device.getAddress(), triggerState);
+/* } else if (action.equals(AudioManager.A2DP_ROUTE_CHANGED_ACTION)) {
+ BluetoothDevice device = intent
+ .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ int state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, 0);
+ int triggerState = (state == BluetoothProfile.STATE_CONNECTED)
+ ? Profile.TriggerState.ON_A2DP_CONNECT :
+ Profile.TriggerState.ON_A2DP_DISCONNECT;
+
+ checkTriggers(Profile.TriggerType.BLUETOOTH, device.getAddress(), triggerState);*/
+ }
+ }
+
+ private void checkTriggers(int type, String id, int newState) {
+ for (Profile p : mManagerService.getProfileList()) {
+ if (newState != p.getTrigger(type, id)) {
+ continue;
+ }
+
+ UUID currentProfileUuid = mManagerService.getActiveProfileInternal().getUuid();
+ if (!currentProfileUuid.equals(p.getUuid())) {
+ mManagerService.setActiveProfileInternal(p, true);
+ }
+ }
+ }
+
+ private String getActiveSSID() {
+ WifiInfo wifiinfo = mWifiManager.getConnectionInfo();
+ if (wifiinfo == null) {
+ return null;
+ }
+ WifiSsid ssid = wifiinfo.getWifiSsid();
+ if (ssid == null) {
+ return null;
+ }
+ return ssid.toString();
+ }
+}