summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3
diff options
context:
space:
mode:
authorArtem Shvadskiy <ashvadskiy@cyngn.com>2016-02-05 15:54:14 -0800
committerGerrit Code Review <gerrit@cyanogenmod.org>2016-02-08 10:49:39 -0800
commit0c71feed0b3156b25785d735ec0bf6ce0351e965 (patch)
treef3870423137a3bd903f72e40d3b682f217130538 /src/com/android/launcher3
parent3bb6c79ef674e51faf30cd680e21dace539dfcdd (diff)
downloadandroid_packages_apps_Trebuchet-0c71feed0b3156b25785d735ec0bf6ce0351e965.tar.gz
android_packages_apps_Trebuchet-0c71feed0b3156b25785d735ec0bf6ce0351e965.tar.bz2
android_packages_apps_Trebuchet-0c71feed0b3156b25785d735ec0bf6ce0351e965.zip
Add network/unlock receivers and additional metric event
Change-Id: Ifc6fa10fac09ab735e77b963d869b87007265fe4 issue-id: CYNGNOS-1788
Diffstat (limited to 'src/com/android/launcher3')
-rw-r--r--src/com/android/launcher3/DeviceUnlockedReceiver.java55
-rw-r--r--src/com/android/launcher3/Launcher.java11
-rw-r--r--src/com/android/launcher3/NetworkConnectionReceiver.java62
-rw-r--r--src/com/android/launcher3/stats/internal/model/TrackingEvent.java3
4 files changed, 130 insertions, 1 deletions
diff --git a/src/com/android/launcher3/DeviceUnlockedReceiver.java b/src/com/android/launcher3/DeviceUnlockedReceiver.java
new file mode 100644
index 000000000..6e800e338
--- /dev/null
+++ b/src/com/android/launcher3/DeviceUnlockedReceiver.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2016 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 com.android.launcher3;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class DeviceUnlockedReceiver extends BroadcastReceiver {
+ public static final String INTENT_ACTION = Intent.ACTION_USER_PRESENT;
+
+ private final Set<DeviceUnlockedListener> mListeners;
+
+ interface DeviceUnlockedListener {
+ void onDeviceUnlocked();
+ }
+
+ public DeviceUnlockedReceiver() {
+ mListeners = new HashSet<DeviceUnlockedListener>();
+ }
+
+ public void registerListener(final DeviceUnlockedListener listener) {
+ mListeners.add(listener);
+ }
+
+ public void deregisterListener(final DeviceUnlockedListener listener) {
+ mListeners.remove(listener);
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (!intent.getAction().equals(INTENT_ACTION)) return;
+
+ for (DeviceUnlockedListener listener: mListeners) {
+ listener.onDeviceUnlocked();
+ }
+ }
+}
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index bc7cb6290..bc1b5788c 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -254,6 +254,9 @@ public class Launcher extends Activity
private final BroadcastReceiver mCloseSystemDialogsReceiver
= new CloseSystemDialogsIntentReceiver();
+ @Thunk final NetworkConnectionReceiver mConnectionReceiver = new NetworkConnectionReceiver();
+ @Thunk final DeviceUnlockedReceiver mDeviceUnlockedReceiver = new DeviceUnlockedReceiver();
+
private LayoutInflater mInflater;
@Thunk Workspace mWorkspace;
@@ -569,6 +572,12 @@ public class Launcher extends Activity
IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
registerReceiver(mCloseSystemDialogsReceiver, filter);
+ filter = new IntentFilter(NetworkConnectionReceiver.INTENT_ACTION);
+ registerReceiver(mConnectionReceiver, filter);
+
+ filter = new IntentFilter(DeviceUnlockedReceiver.INTENT_ACTION);
+ registerReceiver(mDeviceUnlockedReceiver, filter);
+
mRotationEnabled = Utilities.isRotationAllowedForDevice(getApplicationContext());
// In case we are on a device with locked rotation, we should look at preferences to check
// if the user has specifically allowed rotation.
@@ -2361,6 +2370,8 @@ public class Launcher extends Activity
TextKeyListener.getInstance().release();
unregisterReceiver(mCloseSystemDialogsReceiver);
+ unregisterReceiver(mConnectionReceiver);
+ unregisterReceiver(mDeviceUnlockedReceiver);
mDragLayer.clearAllResizeFrames();
((ViewGroup) mWorkspace.getParent()).removeAllViews();
diff --git a/src/com/android/launcher3/NetworkConnectionReceiver.java b/src/com/android/launcher3/NetworkConnectionReceiver.java
new file mode 100644
index 000000000..0b49c208d
--- /dev/null
+++ b/src/com/android/launcher3/NetworkConnectionReceiver.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2016 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 com.android.launcher3;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.net.ConnectivityManager;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class NetworkConnectionReceiver extends BroadcastReceiver {
+ public static final String INTENT_ACTION = ConnectivityManager.CONNECTIVITY_ACTION;
+
+ private final Set<NetworkStateChangeListener> mListeners;
+
+ interface NetworkStateChangeListener {
+ void onNetworkConnected();
+ void onNetworkDisconnected();
+ }
+
+ public NetworkConnectionReceiver() {
+ mListeners = new HashSet<NetworkStateChangeListener>();
+ }
+
+ public void registerListener(final NetworkStateChangeListener listener) {
+ mListeners.add(listener);
+ }
+
+ public void deregisterListener(final NetworkStateChangeListener listener) {
+ mListeners.remove(listener);
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (!intent.getAction().equals(INTENT_ACTION)) return;
+
+ boolean connected = Utilities.isNetworkConnected(context);
+ for (NetworkStateChangeListener listener: mListeners) {
+ if (connected) {
+ listener.onNetworkConnected();
+ } else {
+ listener.onNetworkDisconnected();
+ }
+ }
+ }
+}
diff --git a/src/com/android/launcher3/stats/internal/model/TrackingEvent.java b/src/com/android/launcher3/stats/internal/model/TrackingEvent.java
index 6b18dfe9b..6c40e1b8a 100644
--- a/src/com/android/launcher3/stats/internal/model/TrackingEvent.java
+++ b/src/com/android/launcher3/stats/internal/model/TrackingEvent.java
@@ -60,7 +60,8 @@ public class TrackingEvent {
REMOTE_APP_OPENED,
REMOTE_APP_INSTALLED,
REMOTE_SYNC_TIME,
- REMOTE_SYNC_ERROR
+ REMOTE_SYNC_ERROR,
+ REMOTE_SYNC_UNFILLED
}
public static final String KEY_ORIGIN = TrackingBundle.KEY_METADATA_ORIGIN;