diff options
author | Dianne Hackborn <hackbod@google.com> | 2015-05-20 18:18:46 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2015-05-21 16:45:29 -0700 |
commit | b5a380d409a1431a38db978864b9d85b689e3cce (patch) | |
tree | 5cd36c4c095331869e1019739500b517fbf516a6 /tests/ActivityTests | |
parent | aba3ecb976cacd7c92fe8f8afae20d112781d68e (diff) | |
download | frameworks_base-b5a380d409a1431a38db978864b9d85b689e3cce.zip frameworks_base-b5a380d409a1431a38db978864b9d85b689e3cce.tar.gz frameworks_base-b5a380d409a1431a38db978864b9d85b689e3cce.tar.bz2 |
Add API to track usage time of apps.
This adds a new ActivityOption for the caller to ask the
system to track the time the user is in the app it launches,
delivering the result when they are done.
The time interval tracked is from when the app launches the
activity until the user leaves that app's flow. They are
considered to stay in the flow as long as new activities
are being launched or returned to from the original flow,
even if they cross package or task boundaries. For example,
if the originator starts an activity to view an image, and
while there the user selects to share, which launches gmail
in a new task, and they complete the share, the time during
that entire operation will be included.
The user is considered to complete the operation once they
switch to another activity that is not part of the tracked
flow. For example, use the notification shade, launcher, or
recents to launch or switch to another app. Simply going
in to these navigation elements does not break the flow
(although the launcher and recents stops time tracking of
the session), it is the act of going somewhere else that
completes the tracking.
The data is delivered to the app through a PendingIntent,
which includes the total time the app was in the flow along
with a time break-down by app package.
Change-Id: If1cf8892d422c52ec5042eba0e15a8e7e8f83abf
Diffstat (limited to 'tests/ActivityTests')
3 files changed, 49 insertions, 0 deletions
diff --git a/tests/ActivityTests/AndroidManifest.xml b/tests/ActivityTests/AndroidManifest.xml index 33d40ad..c105491 100644 --- a/tests/ActivityTests/AndroidManifest.xml +++ b/tests/ActivityTests/AndroidManifest.xml @@ -75,5 +75,6 @@ <provider android:name="SingleUserProvider" android:authorities="com.google.android.test.activity.single_user" android:singleUser="true" android:exported="true" /> + <receiver android:name="TrackTimeReceiver" /> </application> </manifest> diff --git a/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java b/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java index 4281c68..fc66d6d 100644 --- a/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java +++ b/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java @@ -23,6 +23,7 @@ import android.app.Activity; import android.app.ActivityManager; import android.app.ActivityOptions; import android.app.AlertDialog; +import android.app.PendingIntent; import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; import android.content.ComponentName; @@ -412,6 +413,20 @@ public class ActivityTestMain extends Activity { return true; } }); + menu.add("Track time").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override public boolean onMenuItemClick(MenuItem item) { + Intent intent = new Intent(Intent.ACTION_SEND); + intent.setType("text/plain"); + intent.putExtra(Intent.EXTRA_TEXT, "We are sharing this with you!"); + ActivityOptions options = ActivityOptions.makeBasic(); + Intent receiveIntent = new Intent(ActivityTestMain.this, TrackTimeReceiver.class); + receiveIntent.putExtra("something", "yeah, this is us!"); + options.requestUsageTimeReport(PendingIntent.getBroadcast(ActivityTestMain.this, + 0, receiveIntent, PendingIntent.FLAG_CANCEL_CURRENT)); + startActivity(Intent.createChooser(intent, "Who do you love?"), options.toBundle()); + return true; + } + }); return true; } diff --git a/tests/ActivityTests/src/com/google/android/test/activity/TrackTimeReceiver.java b/tests/ActivityTests/src/com/google/android/test/activity/TrackTimeReceiver.java new file mode 100644 index 0000000..c30d33a --- /dev/null +++ b/tests/ActivityTests/src/com/google/android/test/activity/TrackTimeReceiver.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 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 com.google.android.test.activity; + +import android.app.ActivityOptions; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; + +public class TrackTimeReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + Bundle data = intent.getExtras(); + data.getLong(ActivityOptions.EXTRA_USAGE_REPORT_TIME); + Log.i("ActivityTest", "Received time: " + data); + } +} |