summaryrefslogtreecommitdiffstats
path: root/core/java/android/app/UsageStatsManager.java
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2014-05-08 21:58:44 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-05-08 21:58:45 +0000
commit6af7d62df8dcf991d41b341ef196cdeddbc631a2 (patch)
tree2315ddb4e0d2516befb4f15990c92e8d3d16741d /core/java/android/app/UsageStatsManager.java
parent201f9b8d49108ca9ab8c98a4b3fa578aa0bbc217 (diff)
parente22b3b143240f0f18e3d6d3c06686ad3c23b131b (diff)
downloadframeworks_base-6af7d62df8dcf991d41b341ef196cdeddbc631a2.zip
frameworks_base-6af7d62df8dcf991d41b341ef196cdeddbc631a2.tar.gz
frameworks_base-6af7d62df8dcf991d41b341ef196cdeddbc631a2.tar.bz2
Merge "Usage stats!"
Diffstat (limited to 'core/java/android/app/UsageStatsManager.java')
-rw-r--r--core/java/android/app/UsageStatsManager.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/core/java/android/app/UsageStatsManager.java b/core/java/android/app/UsageStatsManager.java
new file mode 100644
index 0000000..fbf9c3b
--- /dev/null
+++ b/core/java/android/app/UsageStatsManager.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2014 The Android Open Source 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 android.app;
+
+import android.content.Context;
+import android.os.ParcelableParcel;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import com.android.internal.app.IUsageStats;
+
+/**
+ * Access to usage stats data.
+ * @hide
+ */
+public class UsageStatsManager {
+ final Context mContext;
+ final IUsageStats mService;
+
+ /** @hide */
+ public UsageStatsManager(Context context) {
+ mContext = context;
+ mService = IUsageStats.Stub.asInterface(ServiceManager.getService(
+ Context.USAGE_STATS_SERVICE));
+ }
+
+ public UsageStats getCurrentStats() {
+ try {
+ ParcelableParcel in = mService.getCurrentStats(mContext.getOpPackageName());
+ if (in != null) {
+ return new UsageStats(in.getParcel(), false);
+ }
+ } catch (RemoteException e) {
+ // About to die.
+ }
+ return new UsageStats();
+ }
+}